[Swift-commit] r8295 - usertools/plotter/src/plotter
wozniak at ci.uchicago.edu
wozniak at ci.uchicago.edu
Fri Oct 31 15:56:51 CDT 2014
Author: wozniak
Date: 2014-10-31 15:56:50 -0500 (Fri, 31 Oct 2014)
New Revision: 8295
Modified:
usertools/plotter/src/plotter/Lines.java
Log:
Features for legend position
Modified: usertools/plotter/src/plotter/Lines.java
===================================================================
--- usertools/plotter/src/plotter/Lines.java 2014-10-31 20:56:33 UTC (rev 8294)
+++ usertools/plotter/src/plotter/Lines.java 2014-10-31 20:56:50 UTC (rev 8295)
@@ -23,10 +23,12 @@
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
+import org.jfree.chart.title.LegendTitle;
import org.jfree.data.Range;
import org.jfree.data.general.Series;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
+import org.jfree.ui.RectangleEdge;
/**
* See main() for command-line arguments
@@ -54,7 +56,8 @@
static Double ymin = null;
static Double ymax = null;
- static boolean withLegend = true;
+ static boolean legendEnabled = true;
+ static String legendPosition = null;
static List<XYTextAnnotation> notes =
new ArrayList<XYTextAnnotation>();
@@ -195,7 +198,7 @@
JFreeChart chart =
ChartFactory.createXYLineChart
(title, xlabel, ylabel, collection,
- PlotOrientation.VERTICAL, withLegend, false, false);
+ PlotOrientation.VERTICAL, legendEnabled, false, false);
setupPlot(chart, collection);
@@ -254,7 +257,7 @@
}
private static void setupPlot(JFreeChart chart,
- XYSeriesCollection collection)
+ XYSeriesCollection collection)
throws UserInputException
{
XYPlot plot = chart.getXYPlot();
@@ -280,6 +283,8 @@
for (XYTextAnnotation note : notes)
plot.addAnnotation(note);
+
+ placeLegend(chart);
}
static void setAxes(XYPlot plot)
@@ -353,6 +358,27 @@
("Invalid axis.y type: " + axis_y_type);
}
+ static void placeLegend(JFreeChart chart)
+ throws UserInputException
+ {
+ if (legendPosition == null) return;
+
+ LegendTitle legend = chart.getLegend();
+
+ if (legendPosition.equals("right"))
+ legend.setPosition(RectangleEdge.RIGHT);
+ else if (legendPosition.equals("left"))
+ legend.setPosition(RectangleEdge.LEFT);
+ else if (legendPosition.equals("top"))
+ legend.setPosition(RectangleEdge.TOP);
+ else if (legendPosition.equals("bottom"))
+ legend.setPosition(RectangleEdge.BOTTOM);
+ else
+ throw new UserInputException
+ ("Invalid legend position: " + legendPosition);
+
+ }
+
/**
Various plot properties. All are currently optional
@@ -403,7 +429,8 @@
bw = Boolean.parseBoolean(tmp);
tmp = properties.getProperty("legend.enabled");
if (tmp != null)
- withLegend = Boolean.parseBoolean(tmp);
+ legendEnabled = Boolean.parseBoolean(tmp);
+ legendPosition = properties.getProperty("legend.position");
tmp = properties.getProperty("axis.x");
if (tmp != null)
axis_x_type = tmp;
More information about the Swift-commit
mailing list