changeset 1085:ec512e7992c6

Improved data initialization and axis range calculation in vertical profiles (scalar and vector). gnv-artifacts/trunk@1187 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 09 Jun 2010 17:11:54 +0000
parents 81ac8d2f6cb7
children f2127cd0fe31
files gnv-artifacts/ChangeLog gnv-artifacts/src/main/java/de/intevation/gnv/chart/VerticalProfileChart.java gnv-artifacts/src/main/java/de/intevation/gnv/chart/VerticalProfileVectorChart.java
diffstat 3 files changed, 62 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/gnv-artifacts/ChangeLog	Wed Jun 09 12:54:08 2010 +0000
+++ b/gnv-artifacts/ChangeLog	Wed Jun 09 17:11:54 2010 +0000
@@ -1,3 +1,11 @@
+2010-06-09  Ingo Weinzierl <ingo.weinzierl@intevation.de>
+
+	* src/main/java/de/intevation/gnv/chart/VerticalProfileVectorChart.java,
+	  src/main/java/de/intevation/gnv/chart/VerticalProfileChart.java: Improved
+	  data initialization and range calculation. Gap detection will be entered,
+	  if start and end position are valid indices for the array that contains
+	  the data. The x and y range for each axis is improved.
+
 2010-06-09  Ingo Weinzierl <ingo.weinzierl@intevation.de>
 
 	* doc/conf/products/timeseries/conf_mesh.xml,
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/chart/VerticalProfileChart.java	Wed Jun 09 12:54:08 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/chart/VerticalProfileChart.java	Wed Jun 09 17:11:54 2010 +0000
@@ -127,6 +127,9 @@
     protected void initData() {
         log.debug("init data for VerticalProfileChart");
 
+        int items = resultSet.size();
+        log.debug("Found " + items + " items for this chart.");
+
         String  breakPoint1       = null;
         String  breakPoint2       = null;
         String  breakPoint3       = null;
@@ -157,7 +160,9 @@
                 log.debug("prepare data/plot for next dataset");
 
                 if(series != null) {
-                    gapDetection(results, series, startPos, endPos);
+                    if (startPos >= 0 && endPos < items) {
+                        gapDetection(results, series, startPos, endPos);
+                    }
                     addSeries(series, parameter, idx);
 
                     startPos = endPos +1;
@@ -189,10 +194,12 @@
             endPos++;
         }
 
-        if (results.length == 0)
+        if (items == 0)
             return;
 
-        gapDetection(results, series, startPos, endPos);
+        if (startPos >= 0 && endPos < items) {
+            gapDetection(results, series, startPos, endPos);
+        }
         addSeries(series, parameter, idx);
 
         addDatasets();
@@ -244,51 +251,59 @@
         super.prepareAxis(seriesKey, idx);
 
         XYPlot plot = chart.getXYPlot();
-        NumberAxis domainAxis = (NumberAxis) plot.getRangeAxis();
-        NumberAxis rangeAxis  = (NumberAxis) plot.getDomainAxis();
+        NumberAxis domainAxis = (NumberAxis) plot.getRangeAxis(idx);
 
         Range domainRange = domainAxis.getRange();
-        Range rangeRange  = rangeAxis.getRange();
         log.debug("Domain axis range before: " + domainRange.toString());
-        log.debug("Range axis range before: " + rangeRange.toString());
 
         domainRange = Range.expand(domainRange, LOWER_MARGIN, UPPER_MARGIN);
-        rangeRange = Range.expand(rangeRange, LOWER_MARGIN, UPPER_MARGIN);
 
         double lower = domainRange.getLowerBound();
         double upper = domainRange.getUpperBound();
 
         if (lower == upper) {
-            domainRange = new Range(
-                lower - (lower * 0.05d),
-                upper + (upper * 0.05d));
+            double lo = lower > 0 ? lower - lower*0.05d : lower + lower*0.05d;
+            double up = upper > 0 ? upper + upper*0.05d : upper - upper*0.05d;
+
+            domainRange = new Range(lo, up);
         }
 
-        log.debug("Domain axis range after: " + domainRange.toString());
-        log.debug("Range axis range after: " + rangeRange.toString());
+        log.debug("Range axis range after: " + domainRange.toString());
         domainAxis.setRange(domainRange);
-        rangeAxis.setRange(rangeRange);
-
-        plot.setRangeAxis(domainAxis);
+        plot.setRangeAxis(idx, domainAxis);
     }
 
 
     /**
-     * Method to expand max range of a range axis identified by seriesKey.
+     * Method to expand max range of a range axis.
      * <code>LOWER_MARGIN</code> and <code>UPPER_MARGIN</code> are used to
      * expand the range.
-     *
-     * @param seriesKey Key to identify the series stored at the current
-     * Dataset.
-     * @param idx Currently not used.
      */
     protected void prepareRangeAxis(String seriesKey, int idx) {
+        log.debug("Adjust domain range now...");
         XYPlot plot      = chart.getXYPlot();
-        NumberAxis xAxis = (NumberAxis) plot.getDomainAxis();
+        NumberAxis yAxis = (NumberAxis) plot.getDomainAxis();
 
-        Range xRange     = (Range) values.get(seriesKey);
-        xAxis.setRange(Range.expand(xRange, LOWER_MARGIN, UPPER_MARGIN));
-        log.debug("Max X-Range of dataset is: " + xRange.toString());
+        Range yRange = yAxis.getRange();
+        double lo    = yRange.getLowerBound();
+        double hi    = yRange.getUpperBound();
+
+        Iterator iter = values.values().iterator();
+        while (iter.hasNext()) {
+            Range tmp = (Range) iter.next();
+            log.debug("Series range: " + tmp.toString());
+
+            lo = lo < tmp.getLowerBound() ? lo : tmp.getLowerBound();
+            hi = hi > tmp.getUpperBound() ? hi : tmp.getUpperBound();
+        }
+
+        Range merged = Range.expand(
+            new Range(lo, hi),
+            LOWER_MARGIN, UPPER_MARGIN);
+        log.debug("Calculated range for all series = " + merged.toString());
+
+        yAxis.setRange(merged);
+        plot.setDomainAxis(yAxis);
     }
 
 
@@ -359,6 +374,8 @@
                 );
             }
         }
+
+        prepareRangeAxis(null, -1);
     }
 
 
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/chart/VerticalProfileVectorChart.java	Wed Jun 09 12:54:08 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/chart/VerticalProfileVectorChart.java	Wed Jun 09 17:11:54 2010 +0000
@@ -48,6 +48,9 @@
     protected void initData() {
         logger.debug("init data for verticalprofile chart with vector data.");
 
+        int items = resultSet.size();
+        logger.debug("Found " + items + " items for this chart.");
+
         Iterator iter         = resultSet.iterator();
         Result     row        = null;
         String     seriesName = null;
@@ -82,7 +85,10 @@
                 logger.debug("prepare data/plot for next dataset.");
 
                 if (series != null) {
-                    gapDetection(results, series, startPos, endPos);
+                    if (startPos >= 0 && endPos < items) {
+                        gapDetection(results, series, startPos, endPos);
+                    }
+
                     addSeries(series, seriesName, idx);
 
                     startPos = endPos + 1;
@@ -108,7 +114,9 @@
         if (results.length == 0)
             return;
 
-        gapDetection(results, series, startPos, endPos);
+        if (startPos >= 0 && endPos < items) {
+            gapDetection(results, series, startPos, endPos);
+        }
         addSeries(series, seriesName, idx);
 
         addDatasets();
@@ -136,6 +144,8 @@
                 shapesVisible
             );
         }
+
+        prepareRangeAxis(null, -1);
     }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org