changeset 2005:79b15491177a

Added simple area registering functions. flys-artifacts/trunk@3447 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Fri, 16 Dec 2011 14:42:10 +0000
parents 94c4dd5aaf20
children 5aecebcc4698
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java
diffstat 2 files changed, 81 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Fri Dec 16 14:11:50 2011 +0000
+++ b/flys-artifacts/ChangeLog	Fri Dec 16 14:42:10 2011 +0000
@@ -1,3 +1,14 @@
+2011-12-16	Felix Wolfsteller	<felix.wolfsteller@intevation.de>
+
+	Add simple area registerig functions.
+
+	* src/main/java/de/intevation/flys/exports/XYChartGenerator.java:
+	  (AxisDataset.addAreaDataset): New, add an area dataset.
+	  (AxisDataset.isArea): New.
+	  (addAreaSeries): New. Add Area Dataset.
+	  (applyThemes): Pass info if we have an area, to set different
+			 renderer.
+
 2011-12-16	Felix Wolfsteller	<felix.wolfsteller@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/states/StaticState.java:
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java	Fri Dec 16 14:11:50 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java	Fri Dec 16 14:42:10 2011 +0000
@@ -38,9 +38,11 @@
 import org.jfree.ui.RectangleInsets;
 
 import de.intevation.artifactdatabase.state.Facet;
+import de.intevation.flys.jfree.StableXYDifferenceRenderer;
 import de.intevation.artifactdatabase.state.Section;
 import de.intevation.artifactdatabase.state.Settings;
 
+
 import de.intevation.flys.exports.ChartExportHelper;
 import de.intevation.flys.jfree.FLYSAnnotation;
 import de.intevation.flys.jfree.StickyAxisAnnotation;
@@ -71,11 +73,15 @@
         protected List<XYDataset> datasets;
         /** Range to use to include all given datasets. */
         protected Range range;
+        /** List of datasets that are "area datasets" (these will be also
+         * present in the datasets list). */
+        List<XYDataset> areaDatasets;
 
         /** Create AxisDataset. */
         public AxisDataset(int symb) {
             this.axisSymbol = symb;
             datasets        = new ArrayList<XYDataset>();
+            areaDatasets    = new ArrayList<XYDataset>();
         }
 
         /** Merge (or create given range with range so far (if any). */
@@ -99,6 +105,21 @@
             includeYRange(dataset);
         }
 
+        /** Add an area dataset. */
+        public void addAreaDataset(XYSeries series1, XYSeries series2) {
+            XYSeriesCollection collection = new XYSeriesCollection();
+            collection.addSeries(series1);
+            collection.addSeries(series2);
+            this.datasets.add(collection);
+            this.areaDatasets.add(collection);
+            // TODO include Range ...
+        }
+
+        /** True if to be renedered as area. */
+        public boolean isArea(XYSeriesCollection series) {
+            return areaDatasets.contains(series);
+        }
+
         /** Adjust range to include given dataset. */
         public void includeYRange(XYSeries dataset) {
             mergeRanges(new Range(dataset.getMinY(), dataset.getMaxY()));
@@ -108,8 +129,7 @@
         public boolean isEmpty() {
             return this.datasets.isEmpty();
         }
-
-    }
+    } // class AxisDataset
 
 
     /**
@@ -362,9 +382,9 @@
         logger.debug("...............");
         for (int i = 0; i < plot.getRangeAxisCount(); i++) {
             if (plot.getRangeAxis(i) == null)
-                logger.debug("Axis #" + i + " == null");
+                logger.debug("Range-Axis #" + i + " == null");
             else {
-                logger.debug("Axis " + i + " != null [" +
+                logger.debug("Range-Axis " + i + " != null [" +
                     plot.getRangeAxis(i).getRange().getLowerBound() +
                     "  " + plot.getRangeAxis(i).getRange().getUpperBound() +
                     "]");
@@ -400,7 +420,9 @@
                 for (XYDataset dataset: axisDataset.datasets) {
                     plot.setDataset(datasetIndex, dataset);
                     plot.mapDatasetToRangeAxis(datasetIndex, axisIndex);
-                    applyThemes(plot, (XYSeriesCollection) dataset, datasetIndex);
+                    applyThemes(plot, (XYSeriesCollection) dataset,
+                        datasetIndex,
+                        axisDataset.isArea((XYSeriesCollection)dataset));
                     datasetIndex++;
                 }
                 axisIndex++;
@@ -410,6 +432,31 @@
 
 
     /**
+     * Registers an area to be drawn.
+     * @param lower the lower curve to draw the area from.
+     * @param upper the upper curve to draw the ara from.
+     */
+    public void addAreaSeries(Object lower, Object upper, int index, boolean visible) {
+        if (lower == null && upper == null) {
+            logger.warn("Cannot yet render above/under curve.");
+            return;
+        }
+        AxisDataset axisDataset = datasets.get(index);
+
+        if (axisDataset == null) {
+            axisDataset = new AxisDataset(index);
+            datasets.put(index, axisDataset);
+        }
+
+        if (visible)
+            axisDataset.addAreaDataset((XYSeries) lower, (XYSeries) upper);
+        else {
+            // TODO only range merging.
+        }
+        //TODO range merging.
+    }
+
+    /**
      * Add given series if visible, if not visible adjust ranges (such that
      * all points in data would be plotted once visible).
      * @param series the dataseries to include in plot.
@@ -428,8 +475,8 @@
             datasets.put(index, axisDataset);
         }
 
-        logger.debug("Series-extent x " + series.getMinX() + " : " + series.getMaxX()
-            + " extend y " + series.getMinY() + " : " + series.getMaxY());
+        logger.debug("addAxisSeries: extent X " + series.getMinX() + " : " + series.getMaxX()
+            + " extent y " + series.getMinY() + " : " + series.getMaxY());
 
         if (visible) {
             axisDataset.addDataset(series);
@@ -803,15 +850,30 @@
     /**
      * @param idx "index" of dataset/series (first dataset to be drawn has
      *            index 0), correlates with renderer index.
+     * @param isArea true if the series describes an area and shall be rendered
+     *                as such.
      * @return idx increased by number of items addded.
      */
-    protected int applyThemes(XYPlot plot, XYSeriesCollection series, int idx) {
+    protected int applyThemes(
+        XYPlot plot,
+        XYSeriesCollection series,
+        int idx,
+        boolean isArea
+    ) {
         LegendItemCollection lic  = new LegendItemCollection();
         LegendItemCollection anno = plot.getFixedLegendItems();
 
         XYLineAndShapeRenderer renderer = getRenderer(plot, idx);
         int retidx = idx;
 
+        if (isArea) {
+            logger.debug("Registering an 'area'renderer.");
+            plot.setRenderer(retidx, new StableXYDifferenceRenderer());
+            // TODO to legend entry
+            // TODO to styling
+            return retidx +1;
+        }
+
         for (int s = 0, num = series.getSeriesCount(); s < num; s++) {
             XYSeries serie = series.getSeries(s);
 

http://dive4elements.wald.intevation.org