diff flys-artifacts/src/main/java/de/intevation/flys/exports/ChartGenerator.java @ 2587:bece6f604899

Removed references to Range and replaced those with references to Bounds in ChartGenerators. flys-artifacts/trunk@4143 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 15 Mar 2012 10:30:03 +0000
parents c7b0dfa6a52c
children d75b427da50a
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/ChartGenerator.java	Wed Mar 14 15:12:45 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/ChartGenerator.java	Thu Mar 15 10:30:03 2012 +0000
@@ -53,6 +53,7 @@
 import de.intevation.flys.artifacts.FLYSArtifact;
 import de.intevation.flys.artifacts.resources.Resources;
 import de.intevation.flys.jfree.Bounds;
+import de.intevation.flys.jfree.DoubleBounds;
 import de.intevation.flys.jfree.EnhancedLineAndShapeRenderer;
 import de.intevation.flys.jfree.StableXYDifferenceRenderer;
 import de.intevation.flys.jfree.StyledAreaSeriesCollection;
@@ -178,25 +179,6 @@
 
     protected abstract Series getSeriesOf(XYDataset dataset, int idx);
 
-
-    /**
-     * This method is used to set the range of the X axis at index <i>axis</i>.
-     *
-     * @param axis The index of an X axis.
-     * @param range The new range for the X axis at index <i>axis</i>.
-     */
-    protected abstract void setXRange(int axis, Range range);
-
-
-    /**
-     * This method is used to set the range of the Y axis at index <i>axis</i>.
-     *
-     * @param axis The index of an Y axis.
-     * @param range The new range for the Y axis at index <i>axis</i>.
-     */
-    protected abstract void setYRange(int axis, Range range);
-
-
     /**
      * Returns the default title of a chart.
      *
@@ -240,7 +222,17 @@
      * @param idx The index of the X axis that should be comined with
      * <i>range</i>.
      */
-    protected abstract void combineXRanges(Range range, int idx);
+    protected abstract void combineXBounds(Bounds bounds, int idx);
+
+
+    /**
+     * Combines the ranges of the Y axis at index <i>idx</i>.
+     *
+     * @param range A new range.
+     * @param idx The index of the Y axis that should be comined with
+     * <i>range</i>.
+     */
+    protected abstract void combineYBounds(Bounds bounds, int index);
 
 
     /**
@@ -861,9 +853,9 @@
 
         AxisDataset axisDataset = getAxisDataset(idx);
 
-        Range[] xyRanges = ChartHelper.getRanges(dataset);
+        Bounds[] xyBounds = ChartHelper.getBounds(dataset);
 
-        if (xyRanges == null) {
+        if (xyBounds == null) {
             logger.warn("Skip XYDataset for Axis (invalid ranges): " + idx);
             return;
         }
@@ -871,21 +863,15 @@
         if (visible) {
             if (logger.isDebugEnabled()) {
                 logger.debug("Add new AxisDataset at index: " + idx);
-                logger.debug("X extent: " + xyRanges[0]);
-                logger.debug("Y extent: " + xyRanges[1]);
+                logger.debug("X extent: " + xyBounds[0]);
+                logger.debug("Y extent: " + xyBounds[1]);
             }
 
             axisDataset.addDataset(dataset);
-            combineXRanges(xyRanges[0], 0);
         }
-        else {
-            combineXRanges(xyRanges[0], 0);
 
-            // TODO
-            // Expand y range provided by 'timeseries' to have a proper range
-            // set which includes all data.
-            // iw: I am not sure if we still need this
-        }
+        combineXBounds(xyBounds[0], 0);
+        combineYBounds(xyBounds[1], idx);
     }
 
 
@@ -1129,7 +1115,7 @@
                         Range.expandToInclude(axisDataset.getRange(), 0d));
                 }
 
-                setYRange(axisIndex, expandPointRange(axisDataset.getRange()));
+                setYBounds(axisIndex, expandPointRange(axisDataset.getRange()));
 
                 // Add contained datasets, mapping to axis.
                 for (XYDataset dataset: axisDataset.getDatasets()) {
@@ -1280,11 +1266,19 @@
      *
      * @param Range to be expanded if upper == lower bound.
      */
-    private Range expandPointRange(Range range) {
-        if (range != null && range.getLowerBound() == range.getUpperBound()) {
-            return ChartHelper.expandRange(range, 5);
+    private Bounds expandPointRange(Range range) {
+        if (range == null) {
+            return null;
         }
-        return range;
+        else if (range.getLowerBound() == range.getUpperBound()) {
+            double hi  = range.getUpperBound();
+            double lo  = range.getLowerBound();
+            double add = (hi - lo) / 100 * 5;
+
+            return new DoubleBounds(lo-add, hi+add);
+        }
+
+        return new DoubleBounds(range.getLowerBound(), range.getUpperBound());
     }
 
 

http://dive4elements.wald.intevation.org