changeset 3249:f76cef888ee1

Fix issue710 - crashing one-point-diagrams. flys-artifacts/trunk@4882 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Fri, 06 Jul 2012 09:57:16 +0000
parents 4eb91fb1e73e
children 7613cfb037f5
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java
diffstat 2 files changed, 31 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Fri Jul 06 09:37:24 2012 +0000
+++ b/flys-artifacts/ChangeLog	Fri Jul 06 09:57:16 2012 +0000
@@ -1,3 +1,10 @@
+2012-07-07	Felix Wolfsteller	<felix.wolfsteller@intevation.de>
+
+	Fix issue710 (crashing diagrams with only one point).
+
+	* src/main/java/de/intevation/flys/exports/XYChartGenerator.java:
+	  Expand the range/bounds where its added. 
+
 2012-07-07	Felix Wolfsteller	<felix.wolfsteller@intevation.de>
 
 	* src/main/java/de/intevation/flys/exports/ChartGenerator.java
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java	Fri Jul 06 09:37:24 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java	Fri Jul 06 09:57:16 2012 +0000
@@ -9,6 +9,9 @@
 import java.util.Map;
 
 import org.apache.log4j.Logger;
+import org.json.JSONArray;
+import org.json.JSONException;
+
 import org.jfree.chart.ChartFactory;
 import org.jfree.chart.JFreeChart;
 import org.jfree.chart.LegendItem;
@@ -223,6 +226,8 @@
         adjustAxes(plot);
         autoZoom(plot);
 
+        //debugAxis(plot);
+
         // These have to go after the autozoom.
         addAnnotationsToRenderer(plot);
 
@@ -284,7 +289,16 @@
                     "  " + plot.getRangeAxis(i).getRange().getUpperBound() +
                     "]");
             }
-
+        }
+        for (int i = 0, P =  plot.getDomainAxisCount(); i < P; i++) {
+            if (plot.getDomainAxis(i) == null)
+                logger.debug("Domain-Axis #" + i + " == null");
+            else {
+                logger.debug("Domain-Axis " + i + " != null [" +
+                    plot.getDomainAxis(i).getRange().getLowerBound() +
+                    "  " + plot.getDomainAxis(i).getRange().getUpperBound() +
+                    "]");
+            }
         }
         logger.debug("...............");
     }
@@ -447,17 +461,13 @@
      */
     private void preparePointRanges(XYPlot plot) {
         for (int i = 0, num = plot.getDomainAxisCount(); i < num; i++) {
-            logger.debug("Check whether to expand a x axis.");
 
             Integer key = Integer.valueOf(i);
             Bounds  b   = getXBounds(key);
+            logger.debug("Check whether to expand a x axis.i ("+b.getLower() + "-" + b.getUpper()+")");
 
-            if (b != null && b.getLower() == b.getUpper()) {
-                double lo  = (Double) b.getLower();
-                double hi  = (Double) b.getUpper();
-                double add = (hi - lo) / 100 * 5;
-
-                setXBounds(key, new DoubleBounds(lo-add, hi+add));
+            if (b != null && b.getLower().equals(b.getUpper())) {
+                setXBounds(key, ChartHelper.expandBounds(b, 5));
             }
         }
     }
@@ -676,7 +686,12 @@
     /** Set X (usually horizontal) extent for given axis. */
     @Override
     protected void setXBounds(int axis, Bounds bounds) {
-        xBounds.put(axis, bounds);
+        if (bounds.getLower() == bounds.getUpper()) {
+            xBounds.put(axis, ChartHelper.expandBounds(bounds, 5d));
+        }
+        else {
+            xBounds.put(axis, bounds);
+        }
     }
 
 

http://dive4elements.wald.intevation.org