Mercurial > dive4elements > gnv-client
comparison gnv-artifacts/src/main/java/de/intevation/gnv/chart/TimeSeriesChart.java @ 767:79401c871da4
Added and repaired javadoc in de.intevation.gnv.chart package.
gnv-artifacts/trunk@823 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Wed, 24 Mar 2010 14:48:55 +0000 |
parents | b98d1adee7a6 |
children | 9a828e5a2390 |
comparison
equal
deleted
inserted
replaced
766:a23ce49423d5 | 767:79401c871da4 |
---|---|
39 import org.jfree.data.time.Minute; | 39 import org.jfree.data.time.Minute; |
40 import org.jfree.data.time.TimeSeries; | 40 import org.jfree.data.time.TimeSeries; |
41 import org.jfree.data.time.TimeSeriesCollection; | 41 import org.jfree.data.time.TimeSeriesCollection; |
42 | 42 |
43 /** | 43 /** |
44 * @author Ingo Weinzierl (ingo.weinzierl@intevation.de) | 44 * This class is used to create timeseries charts. The domain axis contains |
45 * multiple date/time objects. | |
46 * | |
47 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | |
45 */ | 48 */ |
46 public class TimeSeriesChart | 49 public class TimeSeriesChart |
47 extends AbstractXYLineChart | 50 extends AbstractXYLineChart |
48 { | 51 { |
49 | 52 |
50 private static final String DATE_FORMAT = "chart.timeseries.date.format"; | 53 /** |
51 | 54 * Constant format which can be useful to format date items. Value is |
55 * {@value}. | |
56 */ | |
52 public static final String DEFAULT_DATE_FORMAT = "dd-MMM-yyyy"; | 57 public static final String DEFAULT_DATE_FORMAT = "dd-MMM-yyyy"; |
53 | 58 |
59 /** | |
60 * Constant field used if no gap detection should be done here. This field | |
61 * is used in @see #getTimeGapValue. Value is {@value}. | |
62 */ | |
54 public static final long NO_TIME_GAP = Long.MAX_VALUE - 1000; | 63 public static final long NO_TIME_GAP = Long.MAX_VALUE - 1000; |
64 | |
65 /** | |
66 * Percentage used for gap detection. Its value is {@value}. | |
67 */ | |
55 public static final int GAP_SIZE = 5; // in percent | 68 public static final int GAP_SIZE = 5; // in percent |
56 | 69 |
70 /** | |
71 * Logger used for logging with log4j. | |
72 */ | |
57 private static Logger log = Logger.getLogger(TimeSeriesChart.class); | 73 private static Logger log = Logger.getLogger(TimeSeriesChart.class); |
58 | 74 |
59 | 75 |
76 /** | |
77 * Constructor used to create <code>TimeSeries</code> charts. | |
78 * | |
79 * @param labels Labels used to be displayed in title, subtitle and so on. | |
80 * @param theme ChartTheme used to adjust the rendering of this chart. | |
81 * @param parameters Collection containing a bunch of parameters. | |
82 * @param measurements Collection containing a bunch of measurements. | |
83 * @param dates Collection containing a bunch of date objects. | |
84 * @param result Collection containing a bunch of <code>Result</code> | |
85 * objects which contain the actual data items to be displayed. | |
86 * @param timeGaps Collection with timegap definitions. | |
87 * @param locale Locale used to specify the format of labels, numbers, ... | |
88 * @param linesVisible Render lines between data points if true, otherwise | |
89 * not. | |
90 * @param shapesVisible Render vertices as points if true, otherwise not. | |
91 */ | |
60 public TimeSeriesChart( | 92 public TimeSeriesChart( |
61 ChartLabels labels, | 93 ChartLabels labels, |
62 ChartTheme theme, | 94 ChartTheme theme, |
63 Collection parameters, | 95 Collection parameters, |
64 Collection measurements, | 96 Collection measurements, |
83 this.datasets = new HashMap(); | 115 this.datasets = new HashMap(); |
84 this.ranges = new HashMap(); | 116 this.ranges = new HashMap(); |
85 } | 117 } |
86 | 118 |
87 | 119 |
120 /** | |
121 * see de.intevation.gnv.chart.AbstractXYLineChart#initChart() | |
122 */ | |
88 protected void initChart() { | 123 protected void initChart() { |
89 chart = ChartFactory.createTimeSeriesChart( | 124 chart = ChartFactory.createTimeSeriesChart( |
90 labels.getTitle(), | 125 labels.getTitle(), |
91 labels.getDomainAxisLabel(), | 126 labels.getDomainAxisLabel(), |
92 null, | 127 null, |
100 plot.setDomainAxis(0, new DateAxis( | 135 plot.setDomainAxis(0, new DateAxis( |
101 labels.getDomainAxisLabel(), TimeZone.getDefault(), locale)); | 136 labels.getDomainAxisLabel(), TimeZone.getDefault(), locale)); |
102 } | 137 } |
103 | 138 |
104 | 139 |
140 /** | |
141 * @see de.intevation.gnv.chart.AbstractXYLineChart#initData() | |
142 */ | |
105 protected void initData() { | 143 protected void initData() { |
106 log.debug("init data for timeseries chart"); | 144 log.debug("init data for timeseries chart"); |
107 | 145 |
108 String breakPoint1 = null; | 146 String breakPoint1 = null; |
109 String breakPoint2 = null; | 147 String breakPoint2 = null; |
175 | 213 |
176 addDatasets(); | 214 addDatasets(); |
177 } | 215 } |
178 | 216 |
179 | 217 |
218 /** | |
219 * @see de.intevation.gnv.chart.AbstractXYLineChart#addValue(Result, Series) | |
220 */ | |
180 protected void addValue(Result row, Series series) { | 221 protected void addValue(Result row, Series series) { |
181 ((TimeSeries) series).addOrUpdate( | 222 ((TimeSeries) series).addOrUpdate( |
182 new Minute(row.getDate("XORDINATE")), | 223 new Minute(row.getDate("XORDINATE")), |
183 row.getDouble("YORDINATE") | 224 row.getDouble("YORDINATE") |
184 ); | 225 ); |
185 } | 226 } |
186 | 227 |
187 | 228 |
229 /** | |
230 * @see de.intevation.gnv.chart.AbstractXYLineChart#addSeries(Series, | |
231 * String, int) | |
232 */ | |
188 protected void addSeries(Series series, String parameter, int idx) { | 233 protected void addSeries(Series series, String parameter, int idx) { |
189 log.debug("add series (" + parameter + ")to timeseries chart"); | 234 log.debug("add series (" + parameter + ")to timeseries chart"); |
190 | 235 |
191 if (series == null) { | 236 if (series == null) { |
192 log.warn("no data to add"); | 237 log.warn("no data to add"); |
203 tsc.addSeries((TimeSeries) series); | 248 tsc.addSeries((TimeSeries) series); |
204 datasets.put(parameter, tsc); | 249 datasets.put(parameter, tsc); |
205 } | 250 } |
206 | 251 |
207 | 252 |
253 /** | |
254 * Method to add processed datasets to plot. Each dataset is adjusted using | |
255 * <code>prepareAxis</code> and <code>adjustRenderer</code> methods. | |
256 */ | |
208 protected void addDatasets() { | 257 protected void addDatasets() { |
209 Iterator iter = parameters.iterator(); | 258 Iterator iter = parameters.iterator(); |
210 XYPlot plot = chart.getXYPlot(); | 259 XYPlot plot = chart.getXYPlot(); |
211 int idx = 0; | 260 int idx = 0; |
212 | 261 |
231 } | 280 } |
232 } | 281 } |
233 } | 282 } |
234 | 283 |
235 | 284 |
285 /** | |
286 * @see de.intevation.gnv.chart.AbstractXYLineChart#localizeDomainAxis(Axis, | |
287 * Locale) | |
288 */ | |
236 protected void localizeDomainAxis(Axis axis, Locale locale) { | 289 protected void localizeDomainAxis(Axis axis, Locale locale) { |
237 ((ValueAxis)axis).setStandardTickUnits(createStandardDateTickUnits( | 290 ((ValueAxis)axis).setStandardTickUnits(createStandardDateTickUnits( |
238 TimeZone.getDefault(), | 291 TimeZone.getDefault(), |
239 locale)); | 292 locale)); |
240 } | 293 } |
241 | 294 |
242 | 295 |
296 /** | |
297 * @see org.jfree.chart.axis.DateAxis#createStandardDateTickUnits(TimeZone, | |
298 * Locale) | |
299 */ | |
243 public static TickUnitSource createStandardDateTickUnits( | 300 public static TickUnitSource createStandardDateTickUnits( |
244 TimeZone zone, | 301 TimeZone zone, |
245 Locale locale) | 302 Locale locale) |
246 { | 303 { |
247 /* | 304 /* |
368 | 425 |
369 return units; | 426 return units; |
370 } | 427 } |
371 | 428 |
372 | 429 |
430 /** | |
431 * Method to get a message from resource bundle. | |
432 * | |
433 * @param Locale Locale used to specify the resource bundle. | |
434 * @param def Key to specify the required message. | |
435 * | |
436 * @return Message | |
437 */ | |
373 protected String getMessage(Locale locale, String key, String def) { | 438 protected String getMessage(Locale locale, String key, String def) { |
374 return RessourceFactory.getInstance().getRessource(locale, key, def); | 439 return RessourceFactory.getInstance().getRessource(locale, key, def); |
375 } | 440 } |
376 | 441 |
377 | 442 |
443 /** | |
444 * @see de.intevation.gnv.chart.AbstractXYLineChart#createSeriesName(String, | |
445 * String, String) | |
446 */ | |
378 protected String createSeriesName( | 447 protected String createSeriesName( |
379 String breakPoint1, | 448 String breakPoint1, |
380 String breakPoint2, | 449 String breakPoint2, |
381 String breakPoint3 | 450 String breakPoint3 |
382 ) { | 451 ) { |
386 findValueTitle(measurements, breakPoint2) + | 455 findValueTitle(measurements, breakPoint2) + |
387 "m"; | 456 "m"; |
388 } | 457 } |
389 | 458 |
390 | 459 |
460 /** | |
461 * Method to add gaps between two data points. The max valid space between | |
462 * two data points is calculated by <code>calculateGapSize</code>. | |
463 * | |
464 * @param results All data points in this dataset. | |
465 * @param series Series to be processed. | |
466 * @param startDate Date item where the scan for gaps should begin. | |
467 * @param endDate Date item where the scan should end. | |
468 * @param startPos Start position of this series in <code>results</code>. | |
469 * @param endPos End position of a series in <code>results</code> | |
470 */ | |
391 protected void addGaps( | 471 protected void addGaps( |
392 Result[] results, | 472 Result[] results, |
393 Series series, | 473 Series series, |
394 Date startDate, | 474 Date startDate, |
395 Date endDate, | 475 Date endDate, |
433 last = now; | 513 last = now; |
434 } | 514 } |
435 } | 515 } |
436 | 516 |
437 | 517 |
518 /** | |
519 * Method to calculate the max space between two data points. | |
520 * | |
521 * @param start First date | |
522 * @param end Last date | |
523 * @param startPos Start position of the current series in the collection | |
524 * containing the bunch of series. | |
525 * @param endPos End position of the current series in the collection | |
526 * containing the bunch of series. | |
527 * @param gapID Gap id used to specify the time intervals. | |
528 * | |
529 * @return Min size of a gap. | |
530 */ | |
438 protected long calculateGapSize( | 531 protected long calculateGapSize( |
439 Date start, | 532 Date start, |
440 Date end, | 533 Date end, |
441 int startPos, | 534 int startPos, |
442 int endPos, | 535 int endPos, |
450 | 543 |
451 return maxGap; | 544 return maxGap; |
452 } | 545 } |
453 | 546 |
454 | 547 |
548 /** | |
549 * Determine the interval size between two data points. | |
550 * | |
551 * @param dStart Start date | |
552 * @param dEnd End date | |
553 * @param pStart Index of start point in series used to specify the total | |
554 * amount of date items. | |
555 * @param pEnd Index of end point in series used to specify the total amount | |
556 * of date items. | |
557 * @param gapID Gap id used to determine gaps configured in a xml document. | |
558 * | |
559 * @return Interval size between two data points. | |
560 */ | |
455 protected long getTimeGapValue( | 561 protected long getTimeGapValue( |
456 Date dStart, | 562 Date dStart, |
457 Date dEnd, | 563 Date dEnd, |
458 int pStart, | 564 int pStart, |
459 int pEnd, | 565 int pEnd, |