changeset 2073:27ada2e4243d

Performance improvements for EnhancedLineAndShapeRenderer: buffer minimum and maximum for each series. flys-artifacts/trunk@3584 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 04 Jan 2012 14:25:10 +0000
parents 4cdd9c4896f6
children a026d005accd
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/exports/EnhancedLineAndShapeRenderer.java
diffstat 2 files changed, 38 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Wed Jan 04 12:24:35 2012 +0000
+++ b/flys-artifacts/ChangeLog	Wed Jan 04 14:25:10 2012 +0000
@@ -1,3 +1,8 @@
+2012-01-04  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/exports/EnhancedLineAndShapeRenderer.java:
+	  Buffered the computation results of getMinimum() and getMaximum().
+
 2012-01-04  Ingo Weinzierl <ingo@intevation.de>
 
 	flys/issue393 (Themenstileditor: Minimum anzeigen / Beschriftung anzeigen)
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/EnhancedLineAndShapeRenderer.java	Wed Jan 04 12:24:35 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/EnhancedLineAndShapeRenderer.java	Wed Jan 04 14:25:10 2012 +0000
@@ -3,6 +3,8 @@
 import java.awt.Graphics2D;
 import java.awt.Shape;
 import java.awt.geom.Rectangle2D;
+import java.util.HashMap;
+import java.util.Map;
 
 import org.apache.log4j.Logger;
 
@@ -26,32 +28,32 @@
     protected BooleanList isMinimumShapeVisible;
     protected BooleanList isMaximumShapeVisible;
 
+    protected Map<Integer, Double> seriesMinimum;
+    protected Map<Integer, Double> seriesMaximum;
+
 
     public EnhancedLineAndShapeRenderer(boolean lines, boolean shapes) {
         super(lines, shapes);
         this.isMinimumShapeVisible = new BooleanList();
         this.isMaximumShapeVisible = new BooleanList();
+        this.seriesMinimum         = new HashMap<Integer, Double>();
+        this.seriesMaximum         = new HashMap<Integer, Double>();
     }
 
 
     public boolean getItemShapeVisible(XYDataset dataset, int series, int item){
         if (super.getItemShapeVisible(series, item)) {
-            logger.debug("Items are visible.");
             return true;
         }
 
         if (isMinimumShapeVisible(series) && isMinimum(dataset, series, item)) {
-            logger.debug("Minimum is visible for series: " + series);
             return true;
         }
 
         if (isMaximumShapeVisible(series) && isMaximum(dataset, series, item)) {
-            logger.debug("Maximum is visible for series: " + series);
             return true;
         }
 
-        logger.debug("Nothing is visible at all.");
-
         return false;
     }
 
@@ -75,7 +77,6 @@
         CrosshairState   crosshairState,
         EntityCollection entities
     ) {
-        logger.debug("Draw secondary pass");
         Shape entityArea = null;
 
         // get the data point...
@@ -171,12 +172,21 @@
     }
 
 
-    public static boolean isMinimum(XYDataset dataset, int series, int item) {
+    public boolean isMinimum(XYDataset dataset, int series, int item) {
         return dataset.getYValue(series, item) == getMinimum(dataset, series);
     }
 
 
-    public static double getMinimum(XYDataset dataset, int series) {
+    public double getMinimum(XYDataset dataset, int series) {
+        Integer key = Integer.valueOf(series);
+        Double  old = seriesMinimum.get(Integer.valueOf(series));
+
+        if (old != null) {
+            return old.doubleValue();
+        }
+
+        logger.debug("Compute minimum of Series: " + series);
+
         double min = Double.MAX_VALUE;
 
         for (int i = 0, n = dataset.getItemCount(series); i < n; i++) {
@@ -187,16 +197,27 @@
             }
         }
 
+        seriesMinimum.put(key, Double.valueOf(min));
+
         return min;
     }
 
 
-    public static boolean isMaximum(XYDataset dataset, int series, int item) {
+    public boolean isMaximum(XYDataset dataset, int series, int item) {
         return dataset.getYValue(series, item) == getMaximum(dataset, series);
     }
 
 
-    public static double getMaximum(XYDataset dataset, int series) {
+    public double getMaximum(XYDataset dataset, int series) {
+        Integer key = Integer.valueOf(series);
+        Double  old = seriesMaximum.get(Integer.valueOf(series));
+
+        if (old != null) {
+            return old.doubleValue();
+        }
+
+        logger.debug("Compute maximum of Series: " + series);
+
         double max = -Double.MAX_VALUE;
 
         for (int i = 0, n = dataset.getItemCount(series); i < n; i++) {
@@ -207,6 +228,8 @@
             }
         }
 
+        seriesMaximum.put(key, Double.valueOf(max));
+
         return max;
     }
 }

http://dive4elements.wald.intevation.org