changeset 1858:94871b7ce9e9

CrossSectionApp: split curves in separated datasets to make them renderable with different renderers. flys-artifacts/trunk@3207 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Thu, 10 Nov 2011 09:37:59 +0000
parents 7fc87a67e6f7
children 755d9763928f
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/CollectionMonitor.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/charts/CrossSectionApp.java
diffstat 3 files changed, 71 insertions(+), 40 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Wed Nov 09 16:49:58 2011 +0000
+++ b/flys-artifacts/ChangeLog	Thu Nov 10 09:37:59 2011 +0000
@@ -1,3 +1,13 @@
+2011-11-10	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/charts/CrossSectionApp.java:
+	  Use separate XYDataset for each curve. This is needed because 
+	  "Raum/Flaeche" needs specialized renderers, which are not compatible
+	  with the standard renderers.
+
+	* src/main/java/de/intevation/flys/artifacts/CollectionMonitor.java:
+	  Removed superfluous import.
+
 2011-11-09  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/WMSFloodplainArtifact.java: New
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/CollectionMonitor.java	Wed Nov 09 16:49:58 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/CollectionMonitor.java	Thu Nov 10 09:37:59 2011 +0000
@@ -20,7 +20,6 @@
 import de.intevation.artifacts.common.utils.XMLUtils;
 import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator;
 
-import de.intevation.artifactdatabase.state.State;
 import de.intevation.artifactdatabase.state.Output;
 
 import de.intevation.flys.artifacts.datacage.Recommendations;
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/charts/CrossSectionApp.java	Wed Nov 09 16:49:58 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/charts/CrossSectionApp.java	Thu Nov 10 09:37:59 2011 +0000
@@ -61,7 +61,9 @@
 import org.jfree.chart.plot.XYPlot;
 
 import org.jfree.data.xy.XYSeries;
+import org.jfree.data.xy.XYDataset;
 import org.jfree.data.xy.XYSeriesCollection;
+import org.jfree.chart.renderer.xy.XYItemRenderer;
 
 import org.jfree.ui.ApplicationFrame;
 import org.jfree.ui.RefineryUtilities;
@@ -334,9 +336,7 @@
         CrossSectionLineItem csli =
             (CrossSectionLineItem)crossSectionLinesCB.getSelectedItem();
 
-        JFreeChart chart = createChart(csli == null
-            ? new XYSeriesCollection()
-            : generateDataset());
+        JFreeChart chart = createChart();
 
         chartPanel.setChart(chart);
     }
@@ -345,9 +345,7 @@
         CrossSectionLineItem csli =
             (CrossSectionLineItem)crossSectionLinesCB.getSelectedItem();
 
-        JFreeChart chart = createChart(csli == null
-            ? new XYSeriesCollection()
-            : generateDataset());
+        JFreeChart chart = createChart();
 
         return new ChartPanel(chart);
     }
@@ -404,36 +402,32 @@
         }
     }
 
-    public void generateWaterLevels(
-        List<Point2D>      points,
-        XYSeriesCollection collection
+    public XYDataset generateWaterLevels(
+        List<Point2D>      points
     ) {
-        if (points == null || points.isEmpty()) {
-            return;
+        if (points == null || points.isEmpty() || lastWaterLevel == null) {
+            return null;
         }
 
-        if (lastWaterLevel != null) {
-            double [][] data = Lines.createWaterLines(points, lastWaterLevel);
-            XYSeries series =
-                new XYSeries(String.valueOf(lastWaterLevel), false);
+        double [][] data = Lines.createWaterLines(points, lastWaterLevel);
+        XYSeries series =
+            new XYSeries(String.valueOf(lastWaterLevel), false);
 
-            double [] x = data[0];
-            double [] y = data[1];
-            for (int i = 0; i < x.length; ++i) {
-                series.add(x[i], y[i], false);
-            }
+        double [] x = data[0];
+        double [] y = data[1];
+        for (int i = 0; i < x.length; ++i) {
+            series.add(x[i], y[i], false);
+        }
 
-            collection.addSeries(series);
-        }
+        return new XYSeriesCollection(series);
     }
 
-    public void generateProfile(
+    public XYDataset generateProfile(
         List<Point2D>      points,
-        String             legend,
-        XYSeriesCollection collection
+        String             legend
     ) {
         if (points == null || points.isEmpty()) {
-            return;
+            return null;
         }
 
         double [][] values = CrossSectionLine.fetchCrossSectionProfile(points);
@@ -446,11 +440,20 @@
             series.add(x[i], y[i], false);
         }
 
-        collection.addSeries(series);
+        return new XYSeriesCollection(series);
     }
 
-    public XYSeriesCollection generateDataset() {
-        XYSeriesCollection collection = new XYSeriesCollection();
+    public List<Pair<XYDataset, XYItemRenderer>> generateDatasets() {
+        List<Pair<XYDataset, XYItemRenderer>> pairs =
+            new ArrayList<Pair<XYDataset, XYItemRenderer>>();
+
+        return pairs;
+    }
+
+    public List<Pair<XYDataset, XYItemRenderer>> generateDataset() {
+
+        List<Pair<XYDataset, XYItemRenderer>> datasets =
+            new ArrayList<Pair<XYDataset, XYItemRenderer>>();
 
         CrossSectionLineItem csli =
             (CrossSectionLineItem)crossSectionLinesCB.getSelectedItem();
@@ -463,10 +466,13 @@
                 for (Pair<CrossSection, CrossSectionLine> csl: csli.lines) {
                     if (csl.getA() == cs) {
                         points = csl.getB().fetchCrossSectionLinesPoints();
-                        generateProfile(
-                            points,
-                            cs.getDescription(),
-                            collection);
+
+                        XYDataset dataset = generateProfile(
+                            points, cs.getDescription());
+                        if (dataset != null) {
+                            datasets.add(new Pair<XYDataset, XYItemRenderer>(
+                                dataset, null));
+                        }
                         break;
                     }
                 }
@@ -479,9 +485,11 @@
                         if (points != null) {
                             points = csl.getB().fetchCrossSectionLinesPoints();
                         }
-                        generateWaterLevels(
-                            points,
-                            collection);
+                        XYDataset dataset = generateWaterLevels(points);
+                        if (dataset != null) {
+                            datasets.add(new Pair<XYDataset, XYItemRenderer>(
+                                dataset, null));
+                        }
                         break;
                     }
                 }
@@ -489,7 +497,7 @@
 
         }
 
-        return collection;
+        return datasets;
     }
 
     protected Object [] createCrossSectionLineItems(
@@ -507,18 +515,32 @@
     }
 
 
-    public static JFreeChart createChart(XYSeriesCollection collection) {
+    public JFreeChart createChart() {
         JFreeChart chart = ChartFactory.createXYLineChart(
             null,
             "Abstand [m]",
             "H\u00f6he [m]",
-            collection,
+            null,
             PlotOrientation.VERTICAL,
             true,
             true,
             false);
 
+        List<Pair<XYDataset, XYItemRenderer>> datasets =
+            generateDataset();
+
         XYPlot plot = chart.getXYPlot();
+
+        for (int i = 0, N = datasets.size(); i < N; ++i) {
+            Pair<XYDataset, XYItemRenderer> p = datasets.get(i);
+            plot.setDataset(i, p.getA());
+            plot.mapDatasetToRangeAxis(i, 0);
+            XYItemRenderer renderer = p.getB();
+            if (renderer != null) {
+                plot.setRenderer(i, renderer);
+            }
+        }
+
         NumberAxis yAxis = (NumberAxis)plot.getRangeAxis();
         yAxis.setAutoRangeIncludesZero(false);
 

http://dive4elements.wald.intevation.org