Mercurial > dive4elements > river
changeset 2241:2b232871ba28
New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
flys-artifacts/trunk@3889 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Fri, 03 Feb 2012 09:35:46 +0000 |
parents | e9173de1026c |
children | 7e8e1d5384c0 |
files | flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/exports/ChartHelper.java flys-artifacts/src/main/java/de/intevation/flys/jfree/EnhancedLineAndShapeRenderer.java |
diffstat | 3 files changed, 61 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Thu Feb 02 16:39:50 2012 +0000 +++ b/flys-artifacts/ChangeLog Fri Feb 03 09:35:46 2012 +0000 @@ -1,3 +1,12 @@ +2012-02-03 Ingo Weinzierl <ingo@intevation.de> + + * src/main/java/de/intevation/flys/exports/ChartHelper.java: Added a + function that expands a given range. Take care on NaN in getRanges(). + + * src/main/java/de/intevation/flys/jfree/EnhancedLineAndShapeRenderer.java: + Prevent of NullPointerExceptions in isMinimumShapeVisible() and + isMaximumShapeVisible(). + 2012-02-02 Ingo Weinzierl <ingo@intevation.de> * src/main/java/de/intevation/flys/exports/HistoricalDischargeCurveGenerator.java:
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/ChartHelper.java Thu Feb 02 16:39:50 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/ChartHelper.java Fri Feb 03 09:35:46 2012 +0000 @@ -3,12 +3,17 @@ import org.jfree.data.Range; import org.jfree.data.xy.XYDataset; +import org.apache.log4j.Logger; + /** * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> */ public class ChartHelper { + private static final Logger logger = Logger.getLogger(ChartHelper.class); + + /** * This method returns the ranges of the XYDataset <i>dataset</i> as array * with [xrange, yrange]. @@ -18,20 +23,32 @@ * @return an array with x and y ranges. */ public static Range[] getRanges(XYDataset dataset) { - if (dataset == null) { + int seriesCount = dataset != null ? dataset.getSeriesCount() : 0; + + if (seriesCount == 0) { + logger.warn("Dataset is empty or has no Series set."); return null; } + boolean foundValue = false; + double minX = Double.MAX_VALUE; double maxX = -Double.MAX_VALUE; double minY = Double.MAX_VALUE; double maxY = -Double.MAX_VALUE; - for (int i = 0, m = dataset.getSeriesCount(); i < m; i++) { + for (int i = 0, m = seriesCount; i < m; i++) { for (int j = 0, n = dataset.getItemCount(i); j < n; j++) { double x = dataset.getXValue(i, j); double y = dataset.getYValue(i, j); + if (Double.isNaN(x) || Double.isNaN(y)) { + logger.warn("Item " + j + " in Series " + i + " is broken"); + continue; + } + + foundValue = true; + if (x < minX) { minX = x; } @@ -50,7 +67,31 @@ } } - return new Range[] { new Range(minX, maxX), new Range(minY, maxY) }; + return foundValue + ? new Range[] { new Range(minX, maxX), new Range(minY, maxY) } + : null; + } + + + /** + * Expand range by percent. + * + * @param range The range to expand. + * @param percent The percentage to expand. + * + * @param an expanded range. + */ + public static Range expandRange(Range range, double percent) { + if (range == null) { + return null; + } + + double value = range.getLowerBound(); + double expand = Math.abs(value / 100 * percent); + + return expand != 0 + ? new Range(value-expand, value+expand) + : new Range(-0.01 * percent, 0.01 * percent); } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/jfree/EnhancedLineAndShapeRenderer.java Thu Feb 02 16:39:50 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/jfree/EnhancedLineAndShapeRenderer.java Fri Feb 03 09:35:46 2012 +0000 @@ -158,6 +158,10 @@ public boolean isMinimumShapeVisible(int series) { + if (this.isMinimumShapeVisible.size() <= series) { + return false; + } + return isMinimumShapeVisible.getBoolean(series); } @@ -168,6 +172,10 @@ public boolean isMaximumShapeVisible(int series) { + if (this.isMaximumShapeVisible.size() <= series) { + return false; + } + return isMaximumShapeVisible.getBoolean(series); }