All Downloads are FREE. Search and download functionalities are using the official Maven repository.

at.iem.sysson.gui.impl.ChartUtils.scala Maven / Gradle / Ivy

The newest version!
/*
 *  ChartUtils.scala
 *  (SysSon)
 *
 *  Copyright (c) 2013-2017 Institute of Electronic Music and Acoustics, Graz.
 *  Copyright (c) 2014-2019 Hanns Holger Rutz. All rights reserved.
 *
 *	This software is published under the GNU General Public License v3+
 *
 *
 *	For further information, please contact Hanns Holger Rutz at
 *	[email protected]
 */

package at.iem.sysson.gui.impl

import java.awt.{Color, Font}

import de.sciss.chart.Chart
import org.jfree.chart.plot.{CategoryPlot, XYPlot}
import org.jfree.chart.renderer.xy.{StandardXYBarPainter, XYBarRenderer}

object ChartUtils {
  private lazy val defaultFontFace  = "Liberation Sans" // "Helvetica"  // "Arial"

  def printableLook(chart: Chart): Unit = {
    val plot      = chart.plot
    // val titleText = chart.title
    // chart.peer.setTitle(new TextTitle(titleText, new Font(titleFontFace, Font.BOLD, 22)))

    val (xAxis, yAxis) = plot match {  // shitty Plot / Renderer interfaces do not have common super types
      case p: XYPlot       =>
        p.setBackgroundPaint           (Color.white    )
        p.setDomainGridlinePaint       (Color.lightGray)
        p.setRangeGridlinePaint        (Color.lightGray)
        p.getRenderer.setSeriesPaint(0, Color.darkGray )
        // undo the crappy "3D" look
        p.getRenderer match {
          case r: XYBarRenderer => r.setBarPainter(new StandardXYBarPainter())
          case _ =>
        }
        (p.getDomainAxis, p.getRangeAxis)
      case p: CategoryPlot =>
        p.setBackgroundPaint           (Color.white    )
        p.setDomainGridlinePaint       (Color.lightGray)
        p.setRangeGridlinePaint        (Color.lightGray)
        p.getRenderer.setSeriesPaint(0, Color.darkGray )
        // undo the crappy "3D" look
        p.getRenderer match {
          case r: XYBarRenderer => r.setBarPainter(new StandardXYBarPainter())
          case _ =>
        }
        (p.getDomainAxis, p.getRangeAxis)
    }

    //      val xAxis         = plot.getDomainAxis
    //      val yAxis         = plot.getRangeAxis
    val fnt1          = new Font(defaultFontFace, Font.BOLD , 14)
    val fnt2          = new Font(defaultFontFace, Font.PLAIN, 12)
    xAxis.setLabelFont(fnt1)
    xAxis.setTickLabelFont(fnt2)
    yAxis.setLabelFont(fnt1)
    yAxis.setTickLabelFont(fnt2)
    // chart.peer.getTitle.setFont(new Font(titleFontFace, Font.BOLD, 22))
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy