Mercurial > dive4elements > gnv-client
comparison gnv-artifacts/src/main/java/de/intevation/gnv/chart/TimeSeriesVectorChart.java @ 1119:7c4f81f74c47
merged gnv-artifacts
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:14:00 +0200 |
parents | f953c9a559d8 |
children |
comparison
equal
deleted
inserted
replaced
1027:fca4b5eb8d2f | 1119:7c4f81f74c47 |
---|---|
1 /* | |
2 * Copyright (c) 2010 by Intevation GmbH | |
3 * | |
4 * This program is free software under the LGPL (>=v2.1) | |
5 * Read the file LGPL.txt coming with the software for details | |
6 * or visit http://www.gnu.org/licenses/ if it does not exist. | |
7 */ | |
8 | |
9 package de.intevation.gnv.chart; | |
10 | |
11 import de.intevation.gnv.geobackend.base.Result; | |
12 import de.intevation.gnv.geobackend.base.ResultDescriptor; | |
13 | |
14 import java.util.Collection; | |
15 import java.util.Date; | |
16 import java.util.Iterator; | |
17 import java.util.Locale; | |
18 | |
19 import org.apache.log4j.Logger; | |
20 | |
21 import org.jfree.chart.ChartTheme; | |
22 import org.jfree.chart.plot.XYPlot; | |
23 | |
24 import org.jfree.data.time.Minute; | |
25 import org.jfree.data.time.TimeSeries; | |
26 import org.jfree.data.time.TimeSeriesCollection; | |
27 | |
28 | |
29 /** | |
30 * This class is used to create timeseries charts that contain components of a | |
31 * vector parameter. The domain axis contains multiple date/time objects. | |
32 * | |
33 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | |
34 */ | |
35 public class TimeSeriesVectorChart extends TimeSeriesChart { | |
36 | |
37 private static Logger logger =Logger.getLogger(TimeSeriesVectorChart.class); | |
38 | |
39 public TimeSeriesVectorChart( | |
40 ChartLabels labels, | |
41 ChartTheme theme, | |
42 Collection parameters, | |
43 Collection measurements, | |
44 Collection dates, | |
45 Collection result, | |
46 Collection timeGaps, | |
47 Locale locale, | |
48 boolean linesVisible, | |
49 boolean shapesVisible | |
50 ) { | |
51 super(labels, theme, parameters, measurements, dates, result, | |
52 timeGaps, locale, linesVisible, shapesVisible); | |
53 } | |
54 | |
55 | |
56 @Override | |
57 protected void initData() { | |
58 logger.debug("init data for timeseries vector chart"); | |
59 | |
60 Iterator iter = resultSet.iterator(); | |
61 Result row = null; | |
62 String seriesName = null; | |
63 TimeSeries series = null; | |
64 | |
65 int idx = 0; | |
66 int startPos = 0; | |
67 int endPos = 0; | |
68 Date startDate = null; | |
69 Date endDate = null; | |
70 | |
71 ResultDescriptor rd = null; | |
72 int idxSeries = -1; | |
73 int idxX = -1; | |
74 int idxY = -1; | |
75 | |
76 Result[] results = | |
77 (Result[]) resultSet.toArray(new Result[resultSet.size()]); | |
78 | |
79 while (iter.hasNext()) { | |
80 row = (Result) iter.next(); | |
81 | |
82 if (rd == null) { | |
83 rd = row.getResultDescriptor(); | |
84 idxSeries = rd.getColumnIndex("SERIES"); | |
85 idxX = rd.getColumnIndex("XORDINATE"); | |
86 idxY = rd.getColumnIndex("YORDINATE"); | |
87 } | |
88 | |
89 // add current data to plot and prepare for next one | |
90 if (!row.getString(idxSeries).equals(seriesName)) { | |
91 logger.debug("prepare data/plot for next dataset"); | |
92 | |
93 if(series != null) { | |
94 // add gaps before adding series to chart | |
95 startDate = results[startPos].getDate(idxX); | |
96 endDate = results[endPos-1].getDate(idxX); | |
97 addGaps(results,series,startDate,endDate,startPos,endPos); | |
98 addSeries(series, seriesName, idx); | |
99 | |
100 startPos = endPos + 1; | |
101 } | |
102 | |
103 // prepare variables for next plot | |
104 seriesName = row.getString(idxSeries); | |
105 | |
106 logger.debug("next dataset is '" + seriesName + "'"); | |
107 series = new TimeSeries(seriesName, Minute.class); | |
108 } | |
109 | |
110 addValue(row, series); | |
111 storeMaxRange(ranges, row.getDouble(idxY), seriesName); | |
112 endPos++; | |
113 } | |
114 | |
115 if (startPos < results.length && endPos-1 < results.length) { | |
116 // add the last dataset if existing to plot and prepare its axis | |
117 startDate = results[startPos].getDate(idxX); | |
118 endDate = results[endPos-1].getDate(idxX); | |
119 addGaps(results, series, startDate, endDate, startPos, endPos); | |
120 addSeries(series, seriesName, idx); | |
121 } | |
122 | |
123 addDatasets(); | |
124 } | |
125 | |
126 | |
127 @Override | |
128 protected void addDatasets() { | |
129 XYPlot plot = chart.getXYPlot(); | |
130 int idx = 0; | |
131 | |
132 TimeSeriesCollection tsc = null; | |
133 Iterator iter = datasets.keySet().iterator(); | |
134 | |
135 while (iter.hasNext()) { | |
136 String key = (String) iter.next(); | |
137 tsc = (TimeSeriesCollection)datasets.get(key); | |
138 plot.setDataset(idx, tsc ); | |
139 logger.debug("Added " + key + " parameter to plot."); | |
140 prepareAxis(key, idx); | |
141 adjustRenderer( | |
142 idx++, | |
143 tsc.getSeriesCount(), | |
144 linesVisible, | |
145 shapesVisible | |
146 ); | |
147 } | |
148 } | |
149 } | |
150 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |