changeset 2644:0a84313efe60

Stub for labeling dataseries in EnhancedLineAndShapeRenerer. flys-artifacts/trunk@4299 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Wed, 25 Apr 2012 15:15:39 +0000
parents d6794864a4b8
children 4f7d1ea38404
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/jfree/EnhancedLineAndShapeRenderer.java
diffstat 2 files changed, 50 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Wed Apr 25 14:41:01 2012 +0000
+++ b/flys-artifacts/ChangeLog	Wed Apr 25 15:15:39 2012 +0000
@@ -1,3 +1,9 @@
+2012-04-25	Felix Wolfsteller	<felix.wolfsteller@intevation.de>
+
+	* src/main/java/de/intevation/flys/jfree/EnhancedLineAndShapeRenderer.java
+	  (isMinimumX): Implemented minimum finding for x in analogy to the ones for
+          y values. Stub to label dataset curves in plot.
+
 2012-04-25	Felix Wolfsteller	<felix.wolfsteller@intevation.de>
 
 	* src/main/java/de/intevation/flys/jfree/EnhancedLineAndShapeRenderer.java:
--- a/flys-artifacts/src/main/java/de/intevation/flys/jfree/EnhancedLineAndShapeRenderer.java	Wed Apr 25 14:41:01 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/jfree/EnhancedLineAndShapeRenderer.java	Wed Apr 25 15:15:39 2012 +0000
@@ -33,6 +33,7 @@
     protected BooleanList isMaximumShapeVisible;
 
     protected Map<Integer, Double> seriesMinimum;
+    protected Map<Integer, Double> seriesMinimumX;
     protected Map<Integer, Double> seriesMaximum;
 
 
@@ -42,6 +43,7 @@
         this.isMaximumShapeVisible = new BooleanList();
         this.seriesMinimum         = new HashMap<Integer, Double>();
         this.seriesMaximum         = new HashMap<Integer, Double>();
+        this.seriesMinimumX        = new HashMap<Integer, Double>();
     }
 
 
@@ -147,9 +149,10 @@
         if (getItemShapeVisible(dataset, series, item)) {
             Shape shape = null;
 
-            // OPTIMIZE instead of calculating minimum and maximum for every
-            //          point, calculate it just once (assume that dataset
-            //          content does not change during rendering).
+            // OPTIMIZE: instead of calculating minimum and maximum for every
+            //           point, calculate it just once (assume that dataset
+            //           content does not change during rendering).
+            // NOTE:     Above OPTIMIZE might already be fulfilled to most extend.
             boolean isMinimum = isMinimumShapeVisible(series)
                 && isMinimum(dataset, series, item);
 
@@ -214,7 +217,7 @@
                 }
             }
             // TODO labeling of waterlevels could happen here, too.
-        }
+        } // if (getItemShapeVisible(dataset, series, item))
 
         double xx = transX1;
         double yy = transY1;
@@ -229,6 +232,13 @@
                     (y1 < 0.0));
         }
 
+        boolean doWaterlevelLabel = false;
+        if (isMinimumX (dataset, series, item)) {
+            String waterlevelLabel = "label";
+            // TODO Force water of some German rivers to flow direction mountains.
+            g2.drawString("waterlevel label", (float)xx, (float)yy-3f);
+        }
+
         int domainAxisIndex = plot.getDomainAxisIndex(domainAxis);
         int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis);
         updateCrosshairValues(crosshairState, x1, y1, domainAxisIndex,
@@ -270,6 +280,35 @@
     }
 
 
+    public boolean isMinimumX(XYDataset dataset, int series, int item) {
+        return dataset.getXValue(series, item) == getMinimumX(dataset, series);
+    }
+
+    public double getMinimumX(XYDataset dataset, int series) {
+        Integer key = Integer.valueOf(series);
+        Double  old = seriesMinimumX.get(key);
+
+        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++) {
+            double tmpValue = dataset.getXValue(series, i);
+
+            if (tmpValue < min) {
+                min = tmpValue;
+            }
+        }
+
+        seriesMinimumX.put(key, Double.valueOf(min));
+
+        return min;
+    }
+
     public boolean isMinimum(XYDataset dataset, int series, int item) {
         return dataset.getYValue(series, item) == getMinimum(dataset, series);
     }
@@ -306,6 +345,7 @@
     }
 
 
+    //
     public double getMaximum(XYDataset dataset, int series) {
         Integer key = Integer.valueOf(series);
         Double  old = seriesMaximum.get(key);

http://dive4elements.wald.intevation.org