diff --git a/pom.xml b/pom.xml index 68457b1..fc369ea 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 org.sameersingh.scalaplot scalaplot - 0.2-SNAPSHOT + 0.3-SNAPSHOT ${project.artifactId} Library for plotting the results of experiments http://www.sameersingh.org/scalaplot diff --git a/src/main/scala/org/sameersingh/scalaplot/BarChart.scala b/src/main/scala/org/sameersingh/scalaplot/BarChart.scala index a75c03a..9d5bc46 100644 --- a/src/main/scala/org/sameersingh/scalaplot/BarChart.scala +++ b/src/main/scala/org/sameersingh/scalaplot/BarChart.scala @@ -65,10 +65,14 @@ class BarData(val names: (Int) => String = _.toString, class BarChart(chartTitle: Option[String], val data: BarData, + val style: HistogramStyle.Type = HistogramStyle.Cluster, val x: DiscreteAxis = new DiscreteAxis, val y: NumericAxis = new NumericAxis) extends Chart { + def this(chartTitle: String, data: BarData) = this(Some(chartTitle), data) def this(data: BarData) = this(None, data) + + override def title = chartTitle } trait BarSeriesImplicits { @@ -192,9 +196,10 @@ trait BarChartImplicits extends BarDataImplicits { legendPosY: LegendPosY.Type = LegendPosY.Center, showLegend: Boolean = false, monochrome: Boolean = false, - size: Option[(Double, Double)] = None + size: Option[(Double, Double)] = None, + style: HistogramStyle.Type = HistogramStyle.Cluster ): BarChart = { - val c = new BarChart(GlobalImplicits.stringToOptionString(title), data, { + val c = new BarChart(GlobalImplicits.stringToOptionString(title), data, style, { val d = new DiscreteAxis(); d.label = xLabel; d diff --git a/src/main/scala/org/sameersingh/scalaplot/Style.scala b/src/main/scala/org/sameersingh/scalaplot/Style.scala index fa3032e..fe59e35 100644 --- a/src/main/scala/org/sameersingh/scalaplot/Style.scala +++ b/src/main/scala/org/sameersingh/scalaplot/Style.scala @@ -24,4 +24,9 @@ object Style { type Type = Value val Empty, Solid, Pattern = Value } + + object HistogramStyle extends Enumeration { + type Type = Value + val Cluster, RowStacked = Value + } } diff --git a/src/main/scala/org/sameersingh/scalaplot/gnuplot/GnuplotPlotter.scala b/src/main/scala/org/sameersingh/scalaplot/gnuplot/GnuplotPlotter.scala index c807589..9d12685 100644 --- a/src/main/scala/org/sameersingh/scalaplot/gnuplot/GnuplotPlotter.scala +++ b/src/main/scala/org/sameersingh/scalaplot/gnuplot/GnuplotPlotter.scala @@ -1,5 +1,6 @@ package org.sameersingh.scalaplot.gnuplot +import org.sameersingh.scalaplot.Style.HistogramStyle.{RowStacked, Cluster} import org.sameersingh.scalaplot._ import collection.mutable.ArrayBuffer import java.io.{InputStreamReader, BufferedReader, File, PrintWriter} @@ -112,6 +113,13 @@ class GnuplotPlotter(chart: Chart) extends Plotter(chart) { sb.toString } + protected def getHistogramStyle(s: HistogramStyle.Type): String = { + s match { + case Cluster => "cluster gap 1" + case RowStacked => "rowstacked" + } + } + def plotChart(chart: Chart, defaultTerminal: String = "dumb") { lines += "# Chart settings" chart.title.foreach(t => lines += "set title \"%s\"" format (t)) @@ -133,13 +141,13 @@ class GnuplotPlotter(chart: Chart) extends Plotter(chart) { lines += "set yr [%s:%s] %sreverse" format(yr1s, yr2s, if (chart.y.isBackward) "" else "no") lines += "set xlabel \"%s\"" format (chart.x.label) lines += "set ylabel \"%s\"" format (chart.y.label) + lines += "set style histogram %s" format (getHistogramStyle(chart.style)) plotBarData(chart.data) } def plotBarData(data: BarData) { lines += "# BarData Plotting" lines += "set style data histogram" - lines += "set style histogram cluster gap 1" lines += "set style fill solid border -1" lines += "plot \\" var index = 0