Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/exports/ChartHelper.java @ 2394:02ac373b6d69
Added chart helper function to determine the min and max bounds (x and y) for TimeSeriesCollections.
flys-artifacts/trunk@4016 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Fri, 10 Feb 2012 08:43:06 +0000 |
parents | 2b232871ba28 |
children | bece6f604899 |
comparison
equal
deleted
inserted
replaced
2393:d0e7afb3696b | 2394:02ac373b6d69 |
---|---|
1 package de.intevation.flys.exports; | 1 package de.intevation.flys.exports; |
2 | 2 |
3 import org.jfree.data.Range; | 3 import org.jfree.data.Range; |
4 import org.jfree.data.xy.XYDataset; | 4 import org.jfree.data.xy.XYDataset; |
5 import org.jfree.data.time.RegularTimePeriod; | |
6 import org.jfree.data.time.TimeSeriesCollection; | |
7 import org.jfree.data.time.TimeSeries; | |
5 | 8 |
6 import org.apache.log4j.Logger; | 9 import org.apache.log4j.Logger; |
10 | |
11 import de.intevation.flys.jfree.Bounds; | |
12 import de.intevation.flys.jfree.DoubleBounds; | |
13 import de.intevation.flys.jfree.TimeBounds; | |
7 | 14 |
8 | 15 |
9 /** | 16 /** |
10 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | 17 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
11 */ | 18 */ |
71 ? new Range[] { new Range(minX, maxX), new Range(minY, maxY) } | 78 ? new Range[] { new Range(minX, maxX), new Range(minY, maxY) } |
72 : null; | 79 : null; |
73 } | 80 } |
74 | 81 |
75 | 82 |
83 public static Bounds[] getBounds(TimeSeriesCollection collection) { | |
84 int seriesCount = collection != null ? collection.getSeriesCount() : 0; | |
85 | |
86 if (seriesCount == 0) { | |
87 logger.warn("TimeSeriesCollection is empty or has no Series set."); | |
88 return null; | |
89 } | |
90 | |
91 boolean foundValue = false; | |
92 | |
93 long lowerX = Long.MAX_VALUE; | |
94 long upperX = -Long.MAX_VALUE; | |
95 | |
96 double lowerY = Double.MAX_VALUE; | |
97 double upperY = -Double.MAX_VALUE; | |
98 | |
99 for (int i = 0, m = seriesCount; i < m; i++) { | |
100 TimeSeries series = collection.getSeries(i); | |
101 | |
102 for (int j = 0, n = collection.getItemCount(i); j < n; j++) { | |
103 RegularTimePeriod rtp = series.getTimePeriod(j); | |
104 | |
105 if (rtp == null) { | |
106 continue; | |
107 } | |
108 | |
109 foundValue = true; | |
110 | |
111 long start = rtp.getFirstMillisecond(); | |
112 long end = rtp.getLastMillisecond(); | |
113 | |
114 if (start < lowerX) { | |
115 lowerX = start; | |
116 } | |
117 | |
118 if (end > upperX) { | |
119 upperX = end; | |
120 } | |
121 | |
122 double y = series.getValue(j).doubleValue(); | |
123 | |
124 lowerY = Math.min(lowerY, y); | |
125 upperY = Math.max(upperY, y); | |
126 } | |
127 } | |
128 | |
129 if (foundValue) { | |
130 return new Bounds[] { | |
131 new TimeBounds(lowerX, upperX), | |
132 new DoubleBounds(lowerY, upperY) | |
133 }; | |
134 } | |
135 | |
136 return null; | |
137 } | |
138 | |
139 | |
76 /** | 140 /** |
77 * Expand range by percent. | 141 * Expand range by percent. |
78 * | 142 * |
79 * @param range The range to expand. | 143 * @param range The range to expand. |
80 * @param percent The percentage to expand. | 144 * @param percent The percentage to expand. |