changeset 1935:5b51f5232661

Added handling of empty plots. flys-artifacts/trunk@3316 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Fri, 25 Nov 2011 09:39:09 +0000
parents e4a516ca2e86
children 0ad05cb691fc
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java
diffstat 2 files changed, 48 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Fri Nov 25 08:42:44 2011 +0000
+++ b/flys-artifacts/ChangeLog	Fri Nov 25 09:39:09 2011 +0000
@@ -1,3 +1,12 @@
+2011-11-25  Felix Wolfsteller <felix.wolfsteller@intevation.de>
+
+	Added handling of empty plots.
+
+	* src/main/java/de/intevation/flys/exports/XYChartGenerator.java:
+	  (createAxes, removeEmptyRangeAxes): Survive empty datasets map, create
+					      primary axis.
+	  (recoverEmptyPlot): New.
+
 2011-11-25  Felix Wolfsteller <felix.wolfsteller@intevation.de>
 
 	Let first visible axis be always on the left.
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java	Fri Nov 25 08:42:44 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java	Fri Nov 25 09:39:09 2011 +0000
@@ -175,14 +175,16 @@
         adjustPlot(plot);
         localizeAxes(plot);
 
-        removeEmptyRangeAxes(plot);
         createAxes(plot);
         adjustAxes(plot);
 
+        recoverEmptyPlot(plot);
+
         preparePointRanges(plot);
         autoZoom(plot);
 
         applyThemes(plot);
+        removeEmptyRangeAxes(plot);
 
         return chart;
     }
@@ -207,7 +209,8 @@
 
 
     /**
-     * Add given series.
+     * 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.
      * @param index  index of the series and of its axis.
      * @param visible whether or not the data should be plotted.
@@ -290,22 +293,28 @@
     public void createAxes(XYPlot plot) {
         logger.debug("XYChartGenerator.createAxes");
 
-        Integer last = datasets.lastKey();
-        int i            = 0;
-        int firstVisible = 0;
-
-        if (last != null) {
-            firstVisible = i = last;
-            for (; i >= 0; --i) {
-                if (datasets.containsKey(i)) {
-                    plot.setRangeAxis(i, createYAxis(i));
-                    firstVisible = i;
+        if (datasets.isEmpty()) {
+            plot.setRangeAxis(0, createYAxis(0));
+        }
+        else {
+            Integer last = datasets.lastKey();
+            int i            = 0;
+            int firstVisible = 0;
+    
+            if (last != null) {
+                firstVisible = i = last;
+                for (; i >= 0; --i) {
+                    if (datasets.containsKey(i)) {
+                        plot.setRangeAxis(i, createYAxis(i));
+                        firstVisible = i;
+                    }
                 }
+                plot.setRangeAxisLocation(firstVisible, AxisLocation.TOP_OR_LEFT);
             }
-            plot.setRangeAxisLocation(firstVisible, AxisLocation.TOP_OR_LEFT);
         }
     }
 
+
     /**
      * Create Y (range) axis for given index.
      * Shall be overriden by subclasses.
@@ -315,7 +324,24 @@
         return axis;
     }
 
+    /**
+     * If no data is visible, draw at least empty axis.
+     */
+    private void recoverEmptyPlot(XYPlot plot) {
+        if (plot.getRangeAxis() == null) {
+            logger.debug("debug: No range axis");
+            plot.setRangeAxis(createYAxis(0));
+        }
+
+    }
+
+    /**
+     * Remove Axes which do not have data on them.
+     */
     private void removeEmptyRangeAxes(XYPlot plot) {
+        if (datasets.isEmpty()) {
+            return;
+        }
         Integer last = datasets.lastKey();
 
         if (last != null) {

http://dive4elements.wald.intevation.org