# HG changeset patch # User Ingo Weinzierl # Date 1304329282 0 # Node ID 60f63539d00494ea8f8107f2962374300155326c # Parent 91fbaa2744bfc09a6a17d166c0be802d3d607cd1 Ws and Qs of a longitudinal section chart are mapped to an own range axis now. flys-artifacts/trunk@1785 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 91fbaa2744bf -r 60f63539d004 flys-artifacts/ChangeLog --- a/flys-artifacts/ChangeLog Sun May 01 10:58:38 2011 +0000 +++ b/flys-artifacts/ChangeLog Mon May 02 09:41:22 2011 +0000 @@ -1,3 +1,17 @@ +2011-05-02 Ingo Weinzierl + + * src/main/java/de/intevation/flys/exports/XYChartGenerator.java: Removed + the getDataset() method and replaced it with a addDataset() method. + On this way, concrete subclasses of this OutGenerator can have multiple + datasets (e.g. different datasets for W and Q). This abstract method is + called after the chart generation is finished. + + * src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java, + src/main/java/de/intevation/flys/exports/DischargeCurveGenerator.java: + Both classes implement the addDataset() method. The + LongitudinalSectionGenerator has already multiple datasets for W and Q. + Both are added to the chart - both have an own range axis. + 2011-05-01 Sascha L. Teichmann * src/main/java/de/intevation/flys/artifacts/model/WstValueTable.java: diff -r 91fbaa2744bf -r 60f63539d004 flys-artifacts/src/main/java/de/intevation/flys/exports/DischargeCurveGenerator.java --- a/flys-artifacts/src/main/java/de/intevation/flys/exports/DischargeCurveGenerator.java Sun May 01 10:58:38 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/DischargeCurveGenerator.java Mon May 02 09:41:22 2011 +0000 @@ -8,8 +8,9 @@ import org.w3c.dom.Document; +import org.jfree.chart.JFreeChart; +import org.jfree.chart.plot.XYPlot; import org.jfree.data.xy.DefaultXYDataset; -import org.jfree.data.xy.XYDataset; import de.intevation.artifacts.Artifact; @@ -58,8 +59,9 @@ } - protected XYDataset getXYDataset() { - return dataset; + protected void addDatasets(JFreeChart chart) { + XYPlot plot = (XYPlot) chart.getPlot(); + plot.setDataset(0, dataset); } diff -r 91fbaa2744bf -r 60f63539d004 flys-artifacts/src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java --- a/flys-artifacts/src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java Sun May 01 10:58:38 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java Mon May 02 09:41:22 2011 +0000 @@ -2,7 +2,9 @@ import org.apache.log4j.Logger; -import org.jfree.data.xy.XYDataset; +import org.jfree.chart.JFreeChart; +import org.jfree.chart.axis.NumberAxis; +import org.jfree.chart.plot.XYPlot; import org.jfree.data.xy.XYSeries; import org.jfree.data.xy.XYSeriesCollection; @@ -33,14 +35,18 @@ "longitudinal_section.q"; - /** The storage for the series to be drawn in this chart.*/ - protected XYSeriesCollection dataset; + /** The storage for the W series to be drawn in this chart.*/ + protected XYSeriesCollection w; + + /** The storage for the Q series to be drawn in this chart.*/ + protected XYSeriesCollection q; public LongitudinalSectionGenerator() { super(); - this.dataset = new XYSeriesCollection(); + this.w = new XYSeriesCollection(); + this.q = new XYSeriesCollection(); } @@ -60,8 +66,21 @@ } - protected XYDataset getXYDataset() { - return dataset; + protected void addDatasets(JFreeChart chart) { + XYPlot plot = (XYPlot) chart.getPlot(); + + plot.setDataset(0, w); + plot.setDataset(1, q); + } + + + protected void adjustAxes(XYPlot plot) { + super.adjustAxes(plot); + + NumberAxis qAxis = new NumberAxis("Q [m³/s]"); + + plot.setRangeAxis(2, qAxis); + plot.mapDatasetToRangeAxis(1, 2); } @@ -133,7 +152,7 @@ series.add(target[2], target[0]); } - dataset.addSeries(series); + w.addSeries(series); } } @@ -168,7 +187,7 @@ series.add(target[2], target[1]); } - dataset.addSeries(series); + q.addSeries(series); } } diff -r 91fbaa2744bf -r 60f63539d004 flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java --- a/flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java Sun May 01 10:58:38 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java Mon May 02 09:41:22 2011 +0000 @@ -11,7 +11,6 @@ import org.jfree.chart.axis.NumberAxis; import org.jfree.chart.plot.PlotOrientation; import org.jfree.chart.plot.XYPlot; -import org.jfree.data.xy.XYDataset; import de.intevation.flys.exports.ChartExportHelper; @@ -49,11 +48,12 @@ protected abstract String getYAxisLabel(); /** - * Returns the XYDataset used to add curves to the chart. + * This method is called to add all datasets of a concrete XYChartGenerator + * to the JFreeChart. * - * @return the XYDataset used to add curves to the chart. + * @param chart The JFreeChart object. */ - protected abstract XYDataset getXYDataset(); + protected abstract void addDatasets(JFreeChart chart); public void generate() @@ -65,7 +65,7 @@ getChartTitle(), getXAxisLabel(), getYAxisLabel(), - getXYDataset(), + null, PlotOrientation.VERTICAL, true, false, @@ -74,6 +74,8 @@ chart.setBackgroundPaint(Color.WHITE); chart.getPlot().setBackgroundPaint(Color.WHITE); + addDatasets(chart); + adjustAxes((XYPlot) chart.getPlot()); ChartExportHelper.exportImage(