Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/exports/fixings/FixLongitudinalSectionGenerator.java @ 4377:512a3af69e18
Extract common generator method from FixLongitudinalSectionGenerator
The extracted methods and code can be reused for generating charts for bed
differences if fixanalysis data is loaded via the datacache.
author | Björn Ricks <bjoern.ricks@intevation.de> |
---|---|
date | Fri, 02 Nov 2012 15:47:15 +0100 |
parents | fc6c6f6039df |
children | 05a54b4d579d |
comparison
equal
deleted
inserted
replaced
4376:3c8964855270 | 4377:512a3af69e18 |
---|---|
5 | 5 |
6 import org.apache.log4j.Logger; | 6 import org.apache.log4j.Logger; |
7 import org.jfree.chart.plot.Marker; | 7 import org.jfree.chart.plot.Marker; |
8 import org.jfree.chart.plot.ValueMarker; | 8 import org.jfree.chart.plot.ValueMarker; |
9 import org.jfree.data.xy.XYSeries; | 9 import org.jfree.data.xy.XYSeries; |
10 import org.jfree.data.xy.XYSeriesCollection; | |
11 import org.w3c.dom.Document; | 10 import org.w3c.dom.Document; |
12 | 11 |
13 import de.intevation.artifactdatabase.state.ArtifactAndFacet; | 12 import de.intevation.artifactdatabase.state.ArtifactAndFacet; |
14 import de.intevation.flys.artifacts.model.FacetTypes; | 13 import de.intevation.flys.artifacts.model.FacetTypes; |
15 import de.intevation.flys.artifacts.model.fixings.AnalysisPeriod; | 14 import de.intevation.flys.artifacts.model.fixings.AnalysisPeriod; |
19 import de.intevation.flys.jfree.StyledAreaSeriesCollection; | 18 import de.intevation.flys.jfree.StyledAreaSeriesCollection; |
20 import de.intevation.flys.jfree.StyledXYSeries; | 19 import de.intevation.flys.jfree.StyledXYSeries; |
21 import de.intevation.flys.utils.KMIndex; | 20 import de.intevation.flys.utils.KMIndex; |
22 | 21 |
23 public class FixLongitudinalSectionGenerator | 22 public class FixLongitudinalSectionGenerator |
24 extends FixChartGenerator | 23 extends AbstractFixGenerator |
25 implements FacetTypes | 24 implements FacetTypes |
26 { | 25 { |
27 private static Logger logger = | 26 private static Logger logger = |
28 Logger.getLogger(FixLongitudinalSectionGenerator.class); | 27 Logger.getLogger(FixLongitudinalSectionGenerator.class); |
29 | 28 |
34 "chart.fixings.longitudinalsection.subtitle"; | 33 "chart.fixings.longitudinalsection.subtitle"; |
35 | 34 |
36 public static final String I18N_XAXIS_LABEL = | 35 public static final String I18N_XAXIS_LABEL = |
37 "chart.fixings.longitudinalsection.xaxis.label"; | 36 "chart.fixings.longitudinalsection.xaxis.label"; |
38 | 37 |
39 public static final String I18N_YAXIS_LABEL = | |
40 "chart.fixings.longitudinalsection.yaxis.label"; | |
41 | |
42 public static final String I18N_CHART_TITLE_DEFAULT = | 38 public static final String I18N_CHART_TITLE_DEFAULT = |
43 "Fixierungsanalyse"; | 39 "Fixierungsanalyse"; |
44 | 40 |
45 public static final String I18N_XAXIS_LABEL_DEFAULT = | 41 public static final String I18N_XAXIS_LABEL_DEFAULT = |
46 "[km]"; | 42 "[km]"; |
47 | 43 |
48 public static final String I18N_YAXIS_LABEL_DEFAULT = | |
49 "delta W [cm]"; | |
50 | 44 |
51 public static enum YAXIS { | 45 public static enum YAXIS { |
52 dW(0); | 46 dW(0); |
53 public int idx; | 47 public int idx; |
54 private YAXIS(int c) { | 48 private YAXIS(int c) { |
63 | 57 |
64 if (name.contains(FIX_SECTOR_AVERAGE_LS_DEVIATION)) { | 58 if (name.contains(FIX_SECTOR_AVERAGE_LS_DEVIATION)) { |
65 doSectorAverageDeviationOut(aaf, doc, visible); | 59 doSectorAverageDeviationOut(aaf, doc, visible); |
66 } | 60 } |
67 else if (name.contains(FIX_SECTOR_AVERAGE_LS)) { | 61 else if (name.contains(FIX_SECTOR_AVERAGE_LS)) { |
68 doSectorAverageOut(aaf, doc, visible); | 62 doSectorAverageOut(aaf, doc, visible, YAXIS.dW.idx); |
69 } | 63 } |
70 else if (name.equals(FIX_REFERENCE_EVENTS_LS)) { | 64 else if (name.equals(FIX_REFERENCE_EVENTS_LS)) { |
71 doReferenceEventsOut(aaf, doc, visible); | 65 doReferenceEventsOut(aaf, doc, visible, YAXIS.dW.idx); |
72 } | 66 } |
73 else if (name.equals(FIX_ANALYSIS_EVENTS_LS)) { | 67 else if (name.equals(FIX_ANALYSIS_EVENTS_LS)) { |
74 doAnalysisEventsOut(aaf, doc, visible); | 68 doAnalysisEventsOut(aaf, doc, visible, YAXIS.dW.idx); |
75 } | 69 } |
76 else if (name.equals(FIX_DEVIATION_LS)) { | 70 else if (name.equals(FIX_DEVIATION_LS)) { |
77 doReferenceDeviationOut(aaf, doc, visible); | 71 doReferenceDeviationOut(aaf, doc, visible); |
78 } | 72 } |
79 else if (name.equals(LONGITUDINAL_ANNOTATION)) { | 73 else if (name.equals(LONGITUDINAL_ANNOTATION)) { |
91 else { | 85 else { |
92 logger.warn("Unknown facet name " + name); | 86 logger.warn("Unknown facet name " + name); |
93 return; | 87 return; |
94 } | 88 } |
95 } | 89 } |
96 | |
97 @SuppressWarnings("unchecked") | |
98 protected void doSectorAverageOut( | |
99 ArtifactAndFacet aaf, | |
100 Document doc, | |
101 boolean visible) | |
102 { | |
103 logger.debug("doSectorAverageOut" + aaf.getFacet().getIndex()); | |
104 | |
105 int index = aaf.getFacet().getIndex(); | |
106 int sectorNdx = index & 3; | |
107 | |
108 KMIndex<AnalysisPeriod> kms = | |
109 (KMIndex<AnalysisPeriod>)aaf.getData(context); | |
110 | |
111 if(kms == null) { | |
112 return; | |
113 } | |
114 | |
115 XYSeries series = new StyledXYSeries(aaf.getFacetDescription(), doc); | |
116 | |
117 for (KMIndex.Entry<AnalysisPeriod> entry: kms) { | |
118 double km = entry.getKm(); | |
119 AnalysisPeriod ap = entry.getValue(); | |
120 QWD qwd = ap.getQSectorAverages()[sectorNdx]; | |
121 if (qwd == null) { | |
122 continue; | |
123 } | |
124 double deltaW = qwd.getDeltaW(); | |
125 series.add(km, deltaW); | |
126 } | |
127 | |
128 addAxisSeries(series, 0, visible); | |
129 | |
130 } | |
131 | |
132 | 90 |
133 @SuppressWarnings("unchecked") | 91 @SuppressWarnings("unchecked") |
134 protected void doSectorAverageDeviationOut( | 92 protected void doSectorAverageDeviationOut( |
135 ArtifactAndFacet aaf, | 93 ArtifactAndFacet aaf, |
136 Document doc, | 94 Document doc, |
218 marker.setPaint(Color.BLACK); | 176 marker.setPaint(Color.BLACK); |
219 addValueMarker(marker); | 177 addValueMarker(marker); |
220 addAreaSeries(area, 0, visible); | 178 addAreaSeries(area, 0, visible); |
221 } | 179 } |
222 | 180 |
223 @SuppressWarnings("unchecked") | |
224 protected void doAnalysisEventsOut( | |
225 ArtifactAndFacet aaf, | |
226 Document doc, | |
227 boolean visible) | |
228 { | |
229 logger.debug("doAnalysisEventsOut"); | |
230 | |
231 KMIndex<QWD> kms = | |
232 (KMIndex<QWD>)aaf.getData(context); | |
233 | |
234 if(kms == null) { | |
235 return; | |
236 } | |
237 | |
238 XYSeriesCollection col = new XYSeriesCollection(); | |
239 | |
240 StyledXYSeries series = new StyledXYSeries(aaf.getFacetDescription(), false, doc); | |
241 | |
242 for (KMIndex.Entry<QWD> entry: kms) { | |
243 double km = entry.getKm(); | |
244 QWD qwd = entry.getValue(); | |
245 | |
246 series.add(km, qwd.getDeltaW()); | |
247 } | |
248 col.addSeries(series); | |
249 | |
250 addAxisDataset(col, 0, visible); | |
251 } | |
252 | |
253 @SuppressWarnings("unchecked") | |
254 protected void doReferenceEventsOut( | |
255 ArtifactAndFacet aaf, | |
256 Document doc, | |
257 boolean visible) | |
258 { | |
259 logger.debug("doReferenceEventOut"); | |
260 | |
261 KMIndex<QWD> kms = | |
262 (KMIndex<QWD>)aaf.getData(context); | |
263 | |
264 if(kms == null) { | |
265 return; | |
266 } | |
267 | |
268 XYSeriesCollection col = new XYSeriesCollection(); | |
269 | |
270 StyledXYSeries series = new StyledXYSeries(aaf.getFacetDescription(), false, doc); | |
271 | |
272 for (KMIndex.Entry<QWD> entry: kms) { | |
273 double km = entry.getKm(); | |
274 QWD qwd = entry.getValue(); | |
275 | |
276 series.add(km, qwd.getDeltaW()); | |
277 } | |
278 col.addSeries(series); | |
279 | |
280 addAxisDataset(col, 0, visible); | |
281 } | |
282 | |
283 | |
284 @Override | 181 @Override |
285 protected String getDefaultChartTitle() { | 182 protected String getDefaultChartTitle() { |
286 return msg(I18N_CHART_TITLE, I18N_CHART_TITLE_DEFAULT); | 183 return msg(I18N_CHART_TITLE, I18N_CHART_TITLE_DEFAULT); |
287 } | 184 } |
288 | 185 |
291 return msg(I18N_XAXIS_LABEL, I18N_XAXIS_LABEL_DEFAULT); | 188 return msg(I18N_XAXIS_LABEL, I18N_XAXIS_LABEL_DEFAULT); |
292 } | 189 } |
293 | 190 |
294 @Override | 191 @Override |
295 protected String getDefaultYAxisLabel(int pos) { | 192 protected String getDefaultYAxisLabel(int pos) { |
296 return msg(I18N_YAXIS_LABEL, I18N_YAXIS_LABEL_DEFAULT); | 193 return msg(I18N_DW_YAXIS_LABEL, I18N_DW_YAXIS_LABEL_DEFAULT); |
297 } | 194 } |
298 | 195 |
299 @Override | 196 @Override |
300 protected ChartGenerator.YAxisWalker getYAxisWalker() { | 197 protected ChartGenerator.YAxisWalker getYAxisWalker() { |
301 return new YAxisWalker() { | 198 return new YAxisWalker() { |