Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rowstacked barchart #10

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.sameersingh.scalaplot</groupId>
<artifactId>scalaplot</artifactId>
<version>0.2-SNAPSHOT</version>
<version>0.3-SNAPSHOT</version>
<name>${project.artifactId}</name>
<description>Library for plotting the results of experiments</description>
<url>http://www.sameersingh.org/scalaplot</url>
Expand Down
9 changes: 7 additions & 2 deletions src/main/scala/org/sameersingh/scalaplot/BarChart.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions src/main/scala/org/sameersingh/scalaplot/Style.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Original file line number Diff line number Diff line change
@@ -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}
Expand Down Expand Up @@ -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))
Expand All @@ -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
Expand Down