[Dive4elements-commits] [PATCH 03 of 11] Extracted method to calculate the zoomed bound of a chart

Wald Commits scm-commit at wald.intevation.org
Mon Dec 3 17:27:23 CET 2012


# HG changeset patch
# User Raimund Renkert <rrenkert at intevation.de>
# Date 1354550145 -3600
# Node ID 4a30d1d62cafe383f88aa4e3a8e4320cfcbccf71
# Parent  05c9902c761d051b50e2b3af2dab912b14c0f1ce
Extracted method to calculate the zoomed bound of a chart.

diff -r 05c9902c761d -r 4a30d1d62caf flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java
--- 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


More information about the Dive4elements-commits mailing list