# HG changeset patch # User Ingo Weinzierl # Date 1328261746 0 # Node ID 2b232871ba28c3133053348a1bb64c87fff1091d # Parent e9173de1026cd59afd056830c24e985ba552a093 New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer. flys-artifacts/trunk@3889 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r e9173de1026c -r 2b232871ba28 flys-artifacts/ChangeLog --- 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 + + * 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 * src/main/java/de/intevation/flys/exports/HistoricalDischargeCurveGenerator.java: diff -r e9173de1026c -r 2b232871ba28 flys-artifacts/src/main/java/de/intevation/flys/exports/ChartHelper.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 Ingo Weinzierl */ public class ChartHelper { + private static final Logger logger = Logger.getLogger(ChartHelper.class); + + /** * This method returns the ranges of the XYDataset dataset 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 : diff -r e9173de1026c -r 2b232871ba28 flys-artifacts/src/main/java/de/intevation/flys/jfree/EnhancedLineAndShapeRenderer.java --- 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); }