changeset 4620:4a30d1d62caf

Extracted method to calculate the zoomed bound of a chart.
author Raimund Renkert <rrenkert@intevation.de>
date Mon, 03 Dec 2012 16:55:45 +0100
parents 05c9902c761d
children 25c5e344733e
files flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java
diffstat 1 files changed, 26 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java	Mon Dec 03 16:54:32 2012 +0100
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java	Mon Dec 03 16:55:45 2012 +0100
@@ -781,22 +781,7 @@
         }
 
         if (x != null) {
-            double min  = bounds.getLower().doubleValue();
-            double max  = bounds.getUpper().doubleValue();
-
-            if (logger.isDebugEnabled()) {
-                logger.debug("Minimum is: " + min);
-                logger.debug("Maximum is: " + max);
-                logger.debug("Lower zoom is: " + x.getLowerBound());
-                logger.debug("Upper zoom is: " + x.getUpperBound());
-            }
-
-            double diff = max > min ? max - min : min - max;
-
-            DoubleBounds computed = new DoubleBounds(
-                min + x.getLowerBound() * diff,
-                min + x.getUpperBound() * diff);
-
+            Bounds computed = calculateZoom(bounds, x);
             computed.applyBounds(axis, AXIS_SPACE);
 
             logger.debug("Zoom axis to: " + computed);
@@ -808,6 +793,31 @@
         return false;
     }
 
+    /**
+     * Calculates the start and end km for zoomed charts.
+     * @param bounds    The given total bounds (unzoomed).
+     * @param range     The range specifying the zoom.
+     * 
+     * @return The start and end km for the zoomed chart.
+     */
+    protected Bounds calculateZoom(Bounds bounds, Range range) {
+        double min  = bounds.getLower().doubleValue();
+        double max  = bounds.getUpper().doubleValue();
+
+        if (logger.isDebugEnabled()) {
+            logger.debug("Minimum is: " + min);
+            logger.debug("Maximum is: " + max);
+            logger.debug("Lower zoom is: " + range.getLowerBound());
+            logger.debug("Upper zoom is: " + range.getUpperBound());
+        }
+
+        double diff = max > min ? max - min : min - max;
+
+        DoubleBounds computed = new DoubleBounds(
+            min + range.getLowerBound() * diff,
+            min + range.getUpperBound() * diff);
+        return computed;
+    }
 
     /**
      * Extract the minimum and maximum values for x and y axes

http://dive4elements.wald.intevation.org