Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/exports/fixings/FixDeltaWtGenerator.java @ 3746:7bc61f4ab26b
Fix for #837
flys-artifacts/trunk@5431 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Christian Lins <christian.lins@intevation.de> |
---|---|
date | Tue, 11 Sep 2012 12:08:08 +0000 |
parents | b81f328da582 |
children | 6a08f4dc790b |
comparison
equal
deleted
inserted
replaced
3745:e86cd5176678 | 3746:7bc61f4ab26b |
---|---|
1 package de.intevation.flys.exports.fixings; | 1 package de.intevation.flys.exports.fixings; |
2 | |
3 import java.io.OutputStream; | |
4 import java.util.ArrayList; | |
5 import java.util.HashMap; | |
6 import java.util.List; | |
7 import java.util.Map; | |
8 import java.util.Set; | |
9 | |
10 import org.apache.log4j.Logger; | |
11 import org.jfree.chart.annotations.XYTextAnnotation; | |
12 import org.jfree.data.time.Day; | |
13 import org.jfree.data.time.RegularTimePeriod; | |
14 import org.jfree.data.time.TimeSeries; | |
15 import org.jfree.data.time.TimeSeriesCollection; | |
16 import org.w3c.dom.Document; | |
2 | 17 |
3 import de.intevation.artifactdatabase.state.ArtifactAndFacet; | 18 import de.intevation.artifactdatabase.state.ArtifactAndFacet; |
4 import de.intevation.artifacts.CallContext; | 19 import de.intevation.artifacts.CallContext; |
5 import de.intevation.flys.artifacts.FLYSArtifact; | 20 import de.intevation.flys.artifacts.FLYSArtifact; |
6 import de.intevation.flys.artifacts.access.FixAnalysisAccess; | 21 import de.intevation.flys.artifacts.access.FixAnalysisAccess; |
15 import de.intevation.flys.jfree.StyledDomainMarker; | 30 import de.intevation.flys.jfree.StyledDomainMarker; |
16 import de.intevation.flys.jfree.StyledTimeSeries; | 31 import de.intevation.flys.jfree.StyledTimeSeries; |
17 import de.intevation.flys.jfree.StyledValueMarker; | 32 import de.intevation.flys.jfree.StyledValueMarker; |
18 import de.intevation.flys.utils.ThemeUtil; | 33 import de.intevation.flys.utils.ThemeUtil; |
19 | 34 |
20 import java.io.OutputStream; | |
21 import java.util.ArrayList; | |
22 import java.util.HashMap; | |
23 import java.util.List; | |
24 import java.util.Map; | |
25 import java.util.Set; | |
26 | |
27 import org.apache.log4j.Logger; | |
28 import org.jfree.chart.annotations.XYTextAnnotation; | |
29 import org.jfree.data.time.Day; | |
30 import org.jfree.data.time.RegularTimePeriod; | |
31 import org.jfree.data.time.TimeSeries; | |
32 import org.jfree.data.time.TimeSeriesCollection; | |
33 import org.w3c.dom.Document; | |
34 | |
35 | 35 |
36 /** | 36 /** |
37 * Generator for Delta W(t) charts. | 37 * Generator for Delta W(t) charts. |
38 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> | 38 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> |
39 */ | 39 */ |
41 extends TimeseriesChartGenerator | 41 extends TimeseriesChartGenerator |
42 implements FacetTypes | 42 implements FacetTypes |
43 { | 43 { |
44 /** Private logger. */ | 44 /** Private logger. */ |
45 private static Logger logger = | 45 private static Logger logger = |
46 Logger.getLogger(FixDeltaWtGenerator.class); | 46 Logger.getLogger(FixDeltaWtGenerator.class); |
47 | 47 |
48 public static final String I18N_CHART_TITLE = | 48 public static final String I18N_CHART_TITLE = |
49 "chart.fix.deltawt.title"; | 49 "chart.fix.deltawt.title"; |
50 | 50 |
51 public static final String I18N_CHART_SUBTITLE = | 51 public static final String I18N_CHART_SUBTITLE = |
52 "chart.fix.deltawt.subtitle"; | 52 "chart.fix.deltawt.subtitle"; |
53 | 53 |
54 public static final String I18N_XAXIS_LABEL = | 54 public static final String I18N_XAXIS_LABEL = |
55 "chart.fix.deltawt.xaxis.label"; | 55 "chart.fix.deltawt.xaxis.label"; |
56 | 56 |
57 public static final String I18N_YAXIS_LABEL = | 57 public static final String I18N_YAXIS_LABEL = |
58 "chart.fix.deltawt.yaxis.label"; | 58 "chart.fix.deltawt.yaxis.label"; |
59 | 59 |
60 public static final String I18N_YAXIS_SECOND_LABEL = | 60 public static final String I18N_YAXIS_SECOND_LABEL = |
61 "chart.fix.deltawt.yaxis.second.label"; | 61 "chart.fix.deltawt.yaxis.second.label"; |
62 | 62 |
63 | 63 |
64 public static enum YAXIS { | 64 public static enum YAXIS { |
65 dW(0); | 65 dW(0); |
66 protected int idx; | 66 protected int idx; |
101 return Resources.format( | 101 return Resources.format( |
102 context.getMeta(), | 102 context.getMeta(), |
103 I18N_CHART_TITLE, | 103 I18N_CHART_TITLE, |
104 "", | 104 "", |
105 FixChartGenerator | 105 FixChartGenerator |
106 .getCurrentKmFromRequest(request).doubleValue()); | 106 .getCurrentKmFromRequest(request).doubleValue()); |
107 } | 107 } |
108 | 108 |
109 | 109 |
110 @Override | 110 @Override |
111 protected String getDefaultChartSubtitle() { | 111 protected String getDefaultChartSubtitle() { |
143 } | 143 } |
144 | 144 |
145 | 145 |
146 @Override | 146 @Override |
147 public void doOut( | 147 public void doOut( |
148 ArtifactAndFacet artifactFacet, | 148 ArtifactAndFacet artifactFacet, |
149 Document theme, | 149 Document theme, |
150 boolean visible | 150 boolean visible |
151 ) { | 151 ) { |
152 String name = artifactFacet.getFacetName(); | 152 String name = artifactFacet.getFacetName(); |
153 logger.debug("FixDeltaWtGenerator.doOut: " + name); | 153 logger.debug("FixDeltaWtGenerator.doOut: " + name); |
154 logger.debug("Theme description is: " + artifactFacet.getFacetDescription()); | 154 logger.debug("Theme description is: " + artifactFacet.getFacetDescription()); |
155 | 155 |
156 this.artifact = (FLYSArtifact)artifactFacet.getArtifact(); | 156 this.artifact = (FLYSArtifact)artifactFacet.getArtifact(); |
157 | 157 |
158 if (name.contains(FIX_SECTOR_AVERAGE_DWT)) { | 158 if (name.contains(FIX_SECTOR_AVERAGE_DWT)) { |
159 doSectorAverageOut( | 159 doSectorAverageOut( |
160 (FLYSArtifact) artifactFacet.getArtifact(), | 160 (FLYSArtifact) artifactFacet.getArtifact(), |
161 artifactFacet.getData(context), | 161 artifactFacet.getData(context), |
162 artifactFacet.getFacetDescription(), | 162 artifactFacet.getFacetDescription(), |
163 theme, | 163 theme, |
164 visible); | 164 visible); |
165 } | 165 } |
166 else if (name.equals(FIX_REFERENCE_EVENTS_DWT)) { | 166 else if (name.equals(FIX_REFERENCE_EVENTS_DWT)) { |
167 doReferenceEventsOut( | 167 doReferenceEventsOut( |
168 (FLYSArtifact) artifactFacet.getArtifact(), | 168 (FLYSArtifact) artifactFacet.getArtifact(), |
169 artifactFacet.getData(context), | 169 artifactFacet.getData(context), |
170 artifactFacet.getFacetDescription(), | 170 artifactFacet.getFacetDescription(), |
171 theme, | 171 theme, |
172 visible); | 172 visible); |
173 } | 173 } |
174 else if (name.equals(FIX_ANALYSIS_EVENTS_DWT)) { | 174 else if (name.equals(FIX_ANALYSIS_EVENTS_DWT)) { |
175 doAnalysisEventsOut( | 175 doAnalysisEventsOut( |
176 (FLYSArtifact) artifactFacet.getArtifact(), | 176 (FLYSArtifact) artifactFacet.getArtifact(), |
177 artifactFacet.getData(context), | 177 artifactFacet.getData(context), |
178 artifactFacet.getFacetDescription(), | 178 artifactFacet.getFacetDescription(), |
179 theme, | 179 theme, |
180 visible); | 180 visible); |
181 } | 181 } |
182 else if (name.equals(FIX_DEVIATION_DWT)) { | 182 else if (name.equals(FIX_DEVIATION_DWT)) { |
183 doDeviationOut( | 183 doDeviationOut( |
184 (FLYSArtifact) artifactFacet.getArtifact(), | 184 (FLYSArtifact) artifactFacet.getArtifact(), |
185 artifactFacet.getData(context), | 185 artifactFacet.getData(context), |
186 artifactFacet.getFacetDescription(), | 186 artifactFacet.getFacetDescription(), |
187 theme, | 187 theme, |
188 visible); | 188 visible); |
189 } | 189 } |
190 else if (name.equals(FIX_ANALYSIS_PERIODS_DWT)) { | 190 else if (name.equals(FIX_ANALYSIS_PERIODS_DWT)) { |
191 doAnalysisPeriodsOut( | 191 doAnalysisPeriodsOut( |
192 (FLYSArtifact) artifactFacet.getArtifact(), | 192 (FLYSArtifact) artifactFacet.getArtifact(), |
193 artifactFacet.getData(context), | 193 artifactFacet.getData(context), |
194 artifactFacet.getFacetDescription(), | 194 artifactFacet.getFacetDescription(), |
195 theme, | 195 theme, |
196 visible); | 196 visible); |
197 } | 197 } |
198 else { | 198 else { |
199 logger.warn("doOut(): unknown facet name: " + name); | 199 logger.warn("doOut(): unknown facet name: " + name); |
200 return; | 200 return; |
201 } | 201 } |
202 } | 202 } |
203 | 203 |
204 | 204 |
205 protected void doSectorAverageOut( | 205 protected void doSectorAverageOut( |
206 FLYSArtifact artifact, | 206 FLYSArtifact artifact, |
207 Object data, | 207 Object data, |
208 String desc, | 208 String desc, |
209 Document theme, | 209 Document theme, |
210 boolean visible) | 210 boolean visible) |
211 { | 211 { |
212 logger.debug("doSectorAverageOut(): description = " + desc); | 212 logger.debug("doSectorAverageOut(): description = " + desc); |
213 | 213 |
214 QWDDateRange qwd = (QWDDateRange) data; | 214 QWDDateRange qwd = (QWDDateRange) data; |
215 TimeSeriesCollection tsc = new TimeSeriesCollection(); | 215 TimeSeriesCollection tsc = new TimeSeriesCollection(); |
229 series.addOrUpdate(rtp, value); | 229 series.addOrUpdate(rtp, value); |
230 | 230 |
231 tsc.addSeries(series); | 231 tsc.addSeries(series); |
232 | 232 |
233 addAxisDataset(tsc, 0, visible); | 233 addAxisDataset(tsc, 0, visible); |
234 Map<Integer, int[]> annoIdxMap = new HashMap<Integer, int[]>(); | 234 |
235 annoIdxMap.put (0, new int[]{0,0}); | 235 if (visible && ThemeUtil.parseShowLineLabel(theme)) { |
236 doQWDTextAnnotations(annoIdxMap, tsc, qwd.qwd, theme, visible); | 236 List<XYTextAnnotation> textAnnos = new ArrayList<XYTextAnnotation>(); |
237 XYTextAnnotation anno = new CollisionFreeXYTextAnnotation( | |
238 "\u0394 W(t) [cm] " + (float)Math.round(qwd.qwd.getDeltaW() * 10000) / 10000, | |
239 tsc.getXValue(0, 0), | |
240 qwd.qwd.getDeltaW()); | |
241 textAnnos.add(anno); | |
242 | |
243 FLYSAnnotation flysAnno = new FLYSAnnotation(null, null, null, theme); | |
244 flysAnno.setTextAnnotations(textAnnos); | |
245 addAnnotations(flysAnno); | |
246 } | |
237 } | 247 } |
238 | 248 |
239 | 249 |
240 protected void doAnalysisEventsOut( | 250 protected void doAnalysisEventsOut( |
241 FLYSArtifact artifact, | 251 FLYSArtifact artifact, |
242 Object data, | 252 Object data, |
243 String desc, | 253 String desc, |
244 Document theme, | 254 Document theme, |
245 boolean visible | 255 boolean visible |
246 ) { | 256 ) { |
247 logger.debug("doAnalysisEventsOut: desc = " + desc); | 257 logger.debug("doAnalysisEventsOut: desc = " + desc); |
248 | 258 |
249 QWD qwd = (QWD) data; | 259 QWD qwd = (QWD) data; |
250 doQWDEventsOut(qwd, desc, theme, visible); | 260 doQWDEventsOut(qwd, desc, theme, visible); |
251 } | 261 } |
315 | 325 |
316 for(Map.Entry<Integer, int[]> entry : entries) { | 326 for(Map.Entry<Integer, int[]> entry : entries) { |
317 int[] idxs = entry.getValue(); | 327 int[] idxs = entry.getValue(); |
318 double x = tsc.getXValue(idxs[0], idxs[1]); | 328 double x = tsc.getXValue(idxs[0], idxs[1]); |
319 XYTextAnnotation anno = new CollisionFreeXYTextAnnotation( | 329 XYTextAnnotation anno = new CollisionFreeXYTextAnnotation( |
320 qwd.getQ() + " m\u00B3/s", | 330 qwd.getQ() + " m\u00B3/s", |
321 x, | 331 x, |
322 qwd.getDeltaW()); | 332 qwd.getDeltaW()); |
323 textAnnos.add(anno); | 333 textAnnos.add(anno); |
324 } | 334 } |
325 | 335 |
326 FLYSAnnotation flysAnno = new FLYSAnnotation(null, null, null, theme); | 336 FLYSAnnotation flysAnno = new FLYSAnnotation(null, null, null, theme); |
327 flysAnno.setTextAnnotations(textAnnos); | 337 flysAnno.setTextAnnotations(textAnnos); |
328 addAnnotations(flysAnno); | 338 addAnnotations(flysAnno); |
329 } | 339 } |
330 | 340 |
331 | 341 |
332 protected void doReferenceEventsOut( | 342 protected void doReferenceEventsOut( |
333 FLYSArtifact artifact, | 343 FLYSArtifact artifact, |
334 Object data, | 344 Object data, |
335 String desc, | 345 String desc, |
336 Document theme, | 346 Document theme, |
337 boolean visible | 347 boolean visible |
338 ) { | 348 ) { |
339 logger.debug("doReferenceEventsOut: desc = " + desc); | 349 logger.debug("doReferenceEventsOut: desc = " + desc); |
340 | 350 |
341 QWD qwd = (QWD) data; | 351 QWD qwd = (QWD) data; |
342 doQWDEventsOut(qwd, desc, theme, visible); | 352 doQWDEventsOut(qwd, desc, theme, visible); |
343 } | 353 } |
344 | 354 |
345 | 355 |
346 protected void doDeviationOut( | 356 protected void doDeviationOut( |
347 FLYSArtifact artifact, | 357 FLYSArtifact artifact, |
348 Object data, | 358 Object data, |
349 String desc, | 359 String desc, |
350 Document theme, | 360 Document theme, |
351 boolean visible | 361 boolean visible |
352 ) { | 362 ) { |
353 logger.debug("doDeviationOut: desc = " + desc); | 363 logger.debug("doDeviationOut: desc = " + desc); |
354 | 364 |
355 if (data == null || !visible) { | 365 if (data == null || !visible) { |
356 logger.debug("no standard deviation"); | 366 logger.debug("no standard deviation"); |
357 return; | 367 return; |
364 valueMarker.add(upper); | 374 valueMarker.add(upper); |
365 } | 375 } |
366 | 376 |
367 | 377 |
368 protected void doAnalysisPeriodsOut( | 378 protected void doAnalysisPeriodsOut( |
369 FLYSArtifact artifact, | 379 FLYSArtifact artifact, |
370 Object data, | 380 Object data, |
371 String desc, | 381 String desc, |
372 Document theme, | 382 Document theme, |
373 boolean visible | 383 boolean visible |
374 ) { | 384 ) { |
375 logger.debug("doHistoricalDischargeDifferenceOut: desc = " + desc); | 385 logger.debug("doHistoricalDischargeDifferenceOut: desc = " + desc); |
376 | 386 |
377 DateRange[] ranges = (DateRange[]) data; | 387 DateRange[] ranges = (DateRange[]) data; |
378 if (ranges == null || !visible) { | 388 if (ranges == null || !visible) { |
379 return; | 389 return; |
381 for (int i = 0; i < ranges.length; i++) { | 391 for (int i = 0; i < ranges.length; i++) { |
382 logger.debug("creating domain marker"); | 392 logger.debug("creating domain marker"); |
383 RegularTimePeriod start = new Day(ranges[i].getFrom()); | 393 RegularTimePeriod start = new Day(ranges[i].getFrom()); |
384 RegularTimePeriod end = new Day(ranges[i].getTo()); | 394 RegularTimePeriod end = new Day(ranges[i].getTo()); |
385 StyledDomainMarker marker = | 395 StyledDomainMarker marker = |
386 new StyledDomainMarker(start.getMiddleMillisecond(), | 396 new StyledDomainMarker(start.getMiddleMillisecond(), |
387 end.getMiddleMillisecond(), theme); | 397 end.getMiddleMillisecond(), theme); |
388 marker.useSecondColor(i % 2 == 0); | 398 marker.useSecondColor(i % 2 == 0); |
389 domainMarker.add(marker); | 399 domainMarker.add(marker); |
390 } | 400 } |
391 logger.debug("domainmarkers: " + domainMarker.size()); | 401 logger.debug("domainmarkers: " + domainMarker.size()); |
392 } | 402 } |