Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/exports/process/WOutProcessor.java @ 4447:a5993b69439b
Add processor to be able to generate curves for WKms values
author | Björn Ricks <bjoern.ricks@intevation.de> |
---|---|
date | Wed, 07 Nov 2012 15:52:25 +0100 |
parents | |
children | 547041487266 |
comparison
equal
deleted
inserted
replaced
4446:05a54b4d579d | 4447:a5993b69439b |
---|---|
1 package de.intevation.flys.exports.process; | |
2 | |
3 import org.apache.log4j.Logger; | |
4 import org.jfree.data.xy.XYSeries; | |
5 import org.w3c.dom.Document; | |
6 | |
7 import de.intevation.artifactdatabase.state.ArtifactAndFacet; | |
8 import de.intevation.artifacts.CallContext; | |
9 import de.intevation.flys.artifacts.model.FacetTypes; | |
10 import de.intevation.flys.artifacts.model.WKms; | |
11 import de.intevation.flys.exports.StyledSeriesBuilder; | |
12 import de.intevation.flys.exports.XYChartGenerator; | |
13 import de.intevation.flys.jfree.StyledAreaSeriesCollection; | |
14 import de.intevation.flys.jfree.StyledXYSeries; | |
15 import de.intevation.flys.utils.DataUtil; | |
16 import de.intevation.flys.utils.ThemeUtil; | |
17 | |
18 /** | |
19 * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a> | |
20 */ | |
21 public class WOutProcessor implements Processor { | |
22 | |
23 private static final Logger logger = | |
24 Logger.getLogger(WOutProcessor.class); | |
25 | |
26 @Override | |
27 public void doOut( | |
28 XYChartGenerator generator, | |
29 ArtifactAndFacet aaf, | |
30 Document theme, | |
31 boolean visible, | |
32 int index) | |
33 { | |
34 CallContext context = generator.getCallContext(); | |
35 WKms wkms = (WKms) aaf.getData(context); | |
36 | |
37 logger.debug("doOut"); | |
38 | |
39 XYSeries series = new StyledXYSeries(aaf.getFacetDescription(), theme); | |
40 | |
41 StyledSeriesBuilder.addPoints(series, wkms); | |
42 generator.addAxisSeries(series, index, visible); | |
43 | |
44 // If a "band around the curve shall be drawn, add according area. | |
45 double bandWidth = ThemeUtil.parseBandWidth(theme); | |
46 if (bandWidth > 0 ) { | |
47 XYSeries seriesDown = new StyledXYSeries( | |
48 "band " + aaf.getFacetDescription(), false, theme); | |
49 XYSeries seriesUp = new StyledXYSeries( | |
50 aaf.getFacetDescription()+"+/-"+bandWidth, false, theme); | |
51 StyledSeriesBuilder.addUpperBand(seriesUp, wkms, bandWidth); | |
52 StyledSeriesBuilder.addLowerBand(seriesDown, wkms, bandWidth); | |
53 | |
54 StyledAreaSeriesCollection area = new StyledAreaSeriesCollection(theme); | |
55 area.addSeries(seriesUp); | |
56 area.addSeries(seriesDown); | |
57 area.setMode(StyledAreaSeriesCollection.FILL_MODE.BETWEEN); | |
58 generator.addAreaSeries(area, index, visible); | |
59 } | |
60 | |
61 invertAxis(generator, wkms); | |
62 } | |
63 | |
64 /** | |
65 * Returns true if facettype is longitutinal_section.w | |
66 */ | |
67 @Override | |
68 public boolean canHandle(String facettype) { | |
69 if (facettype == null) { | |
70 return false; | |
71 } | |
72 | |
73 if (facettype.equals(FacetTypes.LONGITUDINAL_W) | |
74 || facettype.equals(FacetTypes.STATIC_WKMS) | |
75 || facettype.equals(FacetTypes.HEIGHTMARKS_POINTS) | |
76 || facettype.equals(FacetTypes.STATIC_WQKMS) | |
77 || facettype.equals(FacetTypes.STATIC_WQKMS_W) | |
78 || facettype.equals(FacetTypes.DISCHARGE_LONGITUDINAL_W)) | |
79 { | |
80 return true; | |
81 } | |
82 return false; | |
83 } | |
84 | |
85 /** | |
86 * This method determines - taking JFreeCharts auto x value ordering into | |
87 * account - if the x axis need to be inverted. Waterlines in these charts | |
88 * should decrease. | |
89 * | |
90 * @param wkms The data object that stores the x and y values used for this | |
91 * chart. | |
92 */ | |
93 public void invertAxis(XYChartGenerator generator, WKms wkms) { | |
94 boolean wsUp = wkms.guessWaterIncreasing(); | |
95 boolean kmUp = DataUtil.guessWaterIncreasing(wkms.allKms()); | |
96 boolean inv = (wsUp && kmUp) || (!wsUp && !kmUp); | |
97 | |
98 int size = wkms.size(); | |
99 | |
100 if (logger.isDebugEnabled()) { | |
101 logger.debug("(Wkms)Values : " + size); | |
102 if (size > 0) { | |
103 logger.debug("Start km: " + wkms.getKm(0)); | |
104 logger.debug("End km: " + wkms.getKm(size-1)); | |
105 } | |
106 logger.debug("wsUp: " + wsUp); | |
107 logger.debug("kmUp: " + kmUp); | |
108 logger.debug("inv: " + inv); | |
109 } | |
110 generator.setInverted(inv); | |
111 } | |
112 | |
113 } |