changeset 375:60f63539d004

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
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Mon, 02 May 2011 09:41:22 +0000
parents 91fbaa2744bf
children aa0889141b15
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/exports/DischargeCurveGenerator.java flys-artifacts/src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java
diffstat 4 files changed, 53 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- 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 <ingo@intevation.de>
+
+	* 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	<sascha.teichmann@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/model/WstValueTable.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);
     }
 
 
--- 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);
         }
     }
 
--- 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(

http://dive4elements.wald.intevation.org