changeset 849:38c8cc586a85

Expand the range of a horizontalprofile chart manually if there is only a single data point or more data points with all the same value in this chart (issue233). gnv-artifacts/trunk@965 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 21 Apr 2010 10:35:04 +0000
parents 47280aff0eb7
children 39d06d01825a
files gnv-artifacts/ChangeLog gnv-artifacts/src/main/java/de/intevation/gnv/chart/HorizontalProfileChart.java
diffstat 2 files changed, 23 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/gnv-artifacts/ChangeLog	Wed Apr 21 09:43:46 2010 +0000
+++ b/gnv-artifacts/ChangeLog	Wed Apr 21 10:35:04 2010 +0000
@@ -1,3 +1,11 @@
+2010-04-21  Ingo Weinzierl <ingo.weinzierl@intevation.de>
+
+	  Issue233
+
+	* src/main/java/de/intevation/gnv/chart/HorizontalProfileChart.java: Expand
+	  the range of the range axis (y-axis) manually if there is only one data
+	  point or more data points with the same value.
+
 2010-04-21  Ingo Weinzierl <ingo.weinzierl@intevation.de>
 
 	  Issue243
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/chart/HorizontalProfileChart.java	Wed Apr 21 09:43:46 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/chart/HorizontalProfileChart.java	Wed Apr 21 10:35:04 2010 +0000
@@ -194,7 +194,21 @@
         // litte workarround to adjust the max range of axes.
         // NumberAxis.setAutoRange(true) doesn't seem to work properly.
         Range yRange = (Range) ranges.get(seriesKey);
-        yAxis.setRange(Range.expand(yRange, LOWER_MARGIN, UPPER_MARGIN));
+        double lo    = yRange.getLowerBound();
+        double hi    = yRange.getUpperBound();
+
+        // XXX Special case: only a single value in this chart.
+        // JFreeChart doesn't expand this range, because its length is 0.
+        if (lo == hi) {
+            yRange = new Range(
+                lo - (lo / 100 * LOWER_MARGIN),
+                hi + (hi / 100 * UPPER_MARGIN));
+        }
+        else {
+            yRange = Range.expand(yRange, LOWER_MARGIN, UPPER_MARGIN);
+        }
+
+        yAxis.setRange(yRange);
         log.debug("Max Range of dataset is: " + yRange.toString());
 
         if (seriesKey.contains("richtung")) {

http://dive4elements.wald.intevation.org