Mercurial > dive4elements > river
diff flys-artifacts/src/main/java/de/intevation/flys/exports/ChartHelper.java @ 2330:594885703687
Picked changes r4015:4026 from trunk.
flys-artifacts/tags/2.6@4028 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Fri, 10 Feb 2012 11:18:27 +0000 |
parents | 2b232871ba28 |
children | bece6f604899 |
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/ChartHelper.java Fri Feb 10 08:28:17 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/ChartHelper.java Fri Feb 10 11:18:27 2012 +0000 @@ -2,9 +2,16 @@ import org.jfree.data.Range; import org.jfree.data.xy.XYDataset; +import org.jfree.data.time.RegularTimePeriod; +import org.jfree.data.time.TimeSeriesCollection; +import org.jfree.data.time.TimeSeries; import org.apache.log4j.Logger; +import de.intevation.flys.jfree.Bounds; +import de.intevation.flys.jfree.DoubleBounds; +import de.intevation.flys.jfree.TimeBounds; + /** * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> @@ -73,6 +80,63 @@ } + public static Bounds[] getBounds(TimeSeriesCollection collection) { + int seriesCount = collection != null ? collection.getSeriesCount() : 0; + + if (seriesCount == 0) { + logger.warn("TimeSeriesCollection is empty or has no Series set."); + return null; + } + + boolean foundValue = false; + + long lowerX = Long.MAX_VALUE; + long upperX = -Long.MAX_VALUE; + + double lowerY = Double.MAX_VALUE; + double upperY = -Double.MAX_VALUE; + + for (int i = 0, m = seriesCount; i < m; i++) { + TimeSeries series = collection.getSeries(i); + + for (int j = 0, n = collection.getItemCount(i); j < n; j++) { + RegularTimePeriod rtp = series.getTimePeriod(j); + + if (rtp == null) { + continue; + } + + foundValue = true; + + long start = rtp.getFirstMillisecond(); + long end = rtp.getLastMillisecond(); + + if (start < lowerX) { + lowerX = start; + } + + if (end > upperX) { + upperX = end; + } + + double y = series.getValue(j).doubleValue(); + + lowerY = Math.min(lowerY, y); + upperY = Math.max(upperY, y); + } + } + + if (foundValue) { + return new Bounds[] { + new TimeBounds(lowerX, upperX), + new DoubleBounds(lowerY, upperY) + }; + } + + return null; + } + + /** * Expand range by percent. *