changeset 1686:e8d1e531687a

Bugfix: #114 Enabled rendering charts with a single data point. flys-artifacts/trunk@2904 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Fri, 07 Oct 2011 13:15:48 +0000
parents 022f62c75878
children 19c4cf5163e8
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java
diffstat 2 files changed, 51 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Fri Oct 07 13:14:37 2011 +0000
+++ b/flys-artifacts/ChangeLog	Fri Oct 07 13:15:48 2011 +0000
@@ -1,3 +1,11 @@
+2011-10-07  Ingo Weinzierl <ingo@intevation.de>
+
+	flys/issue114 (W-INFO: Wasserspiegellagenberechnung / Ort (Spezialfall: Generierung eines Diagramms bei punkthafter Berechnung))
+
+	* src/main/java/de/intevation/flys/exports/XYChartGenerator.java: Expand
+	  ranges for x and y axes if there is just a single point in a series -
+	  JFreeChart requires a range where lower <> upper.
+
 2011-10-07  Felix Wolfsteller <felix.wolfsteller@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/states/ComputationRangeState.java,
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java	Fri Oct 07 13:14:37 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java	Fri Oct 07 13:15:48 2011 +0000
@@ -135,6 +135,7 @@
 
         removeEmptyRangeAxes(plot);
 
+        preparePointRanges(plot);
         autoZoom(plot);
 
         applyThemes(plot);
@@ -261,6 +262,41 @@
     }
 
 
+    private void preparePointRanges(XYPlot plot) {
+        for (int i = 0, num = plot.getDomainAxisCount(); i < num; i++) {
+            Integer key = new Integer(i);
+
+            Range r = xRanges.get(key);
+            if (r.getLowerBound() == r.getUpperBound()) {
+                xRanges.put(key, expandRange(r, 5));
+            }
+        }
+
+        for (int i = 0, num = plot.getRangeAxisCount(); i < num; i++) {
+            Integer key = new Integer(i);
+
+            Range r = yRanges.get(key);
+            if (r.getLowerBound() == r.getUpperBound()) {
+                yRanges.put(key, expandRange(r, 5));
+            }
+        }
+    }
+
+
+    public static Range expandRange(Range range, double percent) {
+        if (range == null) {
+            return null;
+        }
+
+        double value  = range.getLowerBound();
+        double expand = value / 100 * percent;
+
+        return expand != 0
+            ? new Range(value-expand, value+expand)
+            : new Range(-0.01 * percent, 0.01 * percent);
+    }
+
+
     /**
      * This method zooms the plot to the specified ranges in the attribute
      * document or to the ranges specified by the min/max values in the
@@ -276,9 +312,6 @@
         Range xrange = getDomainAxisRange();
         Range yrange = getValueAxisRange();
 
-        logger.debug("XXX: CLIENT X RANGE = " + xrange);
-        logger.debug("XXX: CLIENT Y RANGE = " + yrange);
-
         for (int i = 0, num = plot.getRangeAxisCount(); i < num; i++) {
             Range[] ranges = new Range[] {
                 xRanges.get(0),
@@ -295,8 +328,6 @@
                 continue;
             }
 
-            logger.debug("XXX Zoom y axis for index: " + i);
-            logger.debug("XXX    Y MAX RANGE = " + ranges[1]);
             zoomY(plot, yaxis, ranges[1], yrange);
         }
     }
@@ -526,6 +557,13 @@
                 ((StyledXYSeries) series).applyTheme(r, s);
             }
 
+            // special case: if there is just one single item, we need to enable
+            // points for this series, otherwise we would not see anything in
+            // the chart area.
+            if (series.getItemCount() == 1) {
+                r.setSeriesShapesVisible(s, true);
+            }
+
             lic.add(r.getLegendItem(i, s));
         }
 

http://dive4elements.wald.intevation.org