comparison artifacts/src/main/java/org/dive4elements/river/exports/LongitudinalSectionGenerator.java @ 9312:740d65e4aa14

Q [m³/s] one message
author gernotbelger
date Thu, 26 Jul 2018 15:54:20 +0200
parents 1cc7653ca84f
children 9b8e8fc1f408
comparison
equal deleted inserted replaced
9311:7c7f73e5e01e 9312:740d65e4aa14
6 * documentation coming with Dive4Elements River for details. 6 * documentation coming with Dive4Elements River for details.
7 */ 7 */
8 8
9 package org.dive4elements.river.exports; 9 package org.dive4elements.river.exports;
10 10
11 import org.apache.log4j.Logger;
11 import org.dive4elements.artifactdatabase.state.ArtifactAndFacet; 12 import org.dive4elements.artifactdatabase.state.ArtifactAndFacet;
12 import org.dive4elements.artifactdatabase.state.Facet; 13 import org.dive4elements.artifactdatabase.state.Facet;
13 import org.dive4elements.artifacts.CallContext; 14 import org.dive4elements.artifacts.CallContext;
14 import org.dive4elements.river.artifacts.D4EArtifact; 15 import org.dive4elements.river.artifacts.D4EArtifact;
15 import org.dive4elements.river.artifacts.geom.Lines; 16 import org.dive4elements.river.artifacts.geom.Lines;
16 import org.dive4elements.river.artifacts.model.AreaFacet; 17 import org.dive4elements.river.artifacts.model.AreaFacet;
17 import org.dive4elements.river.artifacts.model.FacetTypes; 18 import org.dive4elements.river.artifacts.model.FacetTypes;
18 import org.dive4elements.river.artifacts.model.WKms; 19 import org.dive4elements.river.artifacts.model.WKms;
19 import org.dive4elements.river.artifacts.model.WQKms; 20 import org.dive4elements.river.artifacts.model.WQKms;
20 21 import org.dive4elements.river.exports.process.AnnotationProcessor;
21 import org.dive4elements.river.exports.process.Processor;
22 import org.dive4elements.river.exports.process.BedDiffHeightYearProcessor; 22 import org.dive4elements.river.exports.process.BedDiffHeightYearProcessor;
23 import org.dive4elements.river.exports.process.BedDiffYearProcessor; 23 import org.dive4elements.river.exports.process.BedDiffYearProcessor;
24 import org.dive4elements.river.exports.process.Processor;
24 import org.dive4elements.river.exports.process.QOutProcessor; 25 import org.dive4elements.river.exports.process.QOutProcessor;
25 import org.dive4elements.river.exports.process.WOutProcessor; 26 import org.dive4elements.river.exports.process.WOutProcessor;
26 import org.dive4elements.river.exports.process.AnnotationProcessor;
27
28 import org.dive4elements.river.jfree.StyledAreaSeriesCollection; 27 import org.dive4elements.river.jfree.StyledAreaSeriesCollection;
29 import org.dive4elements.river.jfree.StyledXYSeries; 28 import org.dive4elements.river.jfree.StyledXYSeries;
30 import org.dive4elements.river.themes.ThemeDocument; 29 import org.dive4elements.river.themes.ThemeDocument;
31 import org.dive4elements.river.utils.RiverUtils; 30 import org.dive4elements.river.utils.RiverUtils;
32 import org.apache.log4j.Logger;
33 import org.jfree.chart.axis.NumberAxis; 31 import org.jfree.chart.axis.NumberAxis;
34 import org.jfree.chart.axis.ValueAxis; 32 import org.jfree.chart.axis.ValueAxis;
35 import org.jfree.chart.plot.XYPlot; 33 import org.jfree.chart.plot.XYPlot;
36 import org.jfree.data.xy.XYSeries; 34 import org.jfree.data.xy.XYSeries;
37
38 35
39 /** 36 /**
40 * An OutGenerator that generates longitudinal section curves. 37 * An OutGenerator that generates longitudinal section curves.
41 * 38 *
42 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> 39 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
43 */ 40 */
44 public class LongitudinalSectionGenerator 41 public class LongitudinalSectionGenerator extends XYChartGenerator implements FacetTypes {
45 extends XYChartGenerator
46 implements FacetTypes
47 {
48 public enum YAXIS { 42 public enum YAXIS {
49 W(0), 43 W(0), D(1), Q(2);
50 D(1),
51 Q(2);
52 protected int idx; 44 protected int idx;
53 private YAXIS(int c) { 45
54 idx = c; 46 private YAXIS(final int c) {
47 this.idx = c;
55 } 48 }
56 } 49 }
57 50
58 /** The log that is used in this generator. */ 51 /** The log that is used in this generator. */
59 private static Logger log = 52 private static Logger log = Logger.getLogger(LongitudinalSectionGenerator.class);
60 Logger.getLogger(LongitudinalSectionGenerator.class);
61 53
62 /** Key to look up internationalized String for annotations label. */ 54 /** Key to look up internationalized String for annotations label. */
63 public static final String I18N_ANNOTATIONS_LABEL = 55 public static final String I18N_ANNOTATIONS_LABEL = "chart.longitudinal.annotations.label";
64 "chart.longitudinal.annotations.label";
65 56
66 /** 57 /**
67 * Key to look up internationalized String for LongitudinalSection diagrams 58 * Key to look up internationalized String for LongitudinalSection diagrams
68 * titles. 59 * titles.
69 */ 60 */
70 public static final String I18N_CHART_TITLE = 61 public static final String I18N_CHART_TITLE = "chart.longitudinal.section.title";
71 "chart.longitudinal.section.title";
72 62
73 /** 63 /**
74 * Key to look up internationalized String for LongitudinalSection diagrams 64 * Key to look up internationalized String for LongitudinalSection diagrams
75 * subtitles. 65 * subtitles.
76 */ 66 */
77 public static final String I18N_CHART_SUBTITLE = 67 public static final String I18N_CHART_SUBTITLE = "chart.longitudinal.section.subtitle";
78 "chart.longitudinal.section.subtitle";
79 68
80 /** 69 /**
81 * Key to look up internationalized String for LongitudinalSection diagrams 70 * Key to look up internationalized String for LongitudinalSection diagrams
82 * short subtitles. 71 * short subtitles.
83 */ 72 */
84 public static final String I18N_CHART_SHORT_SUBTITLE = 73 public static final String I18N_CHART_SHORT_SUBTITLE = "chart.longitudinal.section.shortsubtitle";
85 "chart.longitudinal.section.shortsubtitle"; 74
86 75 public static final String I18N_XAXIS_LABEL = "chart.longitudinal.section.xaxis.label";
87 public static final String I18N_XAXIS_LABEL = 76
88 "chart.longitudinal.section.xaxis.label"; 77 public static final String I18N_YAXIS_LABEL = "chart.longitudinal.section.yaxis.label";
89 78
90 public static final String I18N_YAXIS_LABEL = 79 public static final String I18N_2YAXIS_LABEL = "common.export.csv.header.q";
91 "chart.longitudinal.section.yaxis.label"; 80
92 81 public static final String I18N_CHART_TITLE_DEFAULT = "W-L\u00e4ngsschnitt";
93 public static final String I18N_2YAXIS_LABEL = 82 public static final String I18N_XAXIS_LABEL_DEFAULT = "km";
94 "chart.longitudinal.section.yaxis.second.label"; 83 public static final String I18N_YAXIS_LABEL_DEFAULT = "W [NN + m]";
95
96 public static final String I18N_CHART_TITLE_DEFAULT =
97 "W-L\u00e4ngsschnitt";
98 public static final String I18N_XAXIS_LABEL_DEFAULT = "km";
99 public static final String I18N_YAXIS_LABEL_DEFAULT = "W [NN + m]";
100 public static final String I18N_2YAXIS_LABEL_DEFAULT = "Q [m\u00b3/s]"; 84 public static final String I18N_2YAXIS_LABEL_DEFAULT = "Q [m\u00b3/s]";
101 85
102 public final static String I18N_WDIFF_YAXIS_LABEL = 86 public final static String I18N_WDIFF_YAXIS_LABEL = "chart.w_differences.yaxis.label";
103 "chart.w_differences.yaxis.label";
104 87
105 public final static String I18N_WDIFF_YAXIS_LABEL_DEFAULT = "m"; 88 public final static String I18N_WDIFF_YAXIS_LABEL_DEFAULT = "m";
106 89
107 public LongitudinalSectionGenerator() { 90 public LongitudinalSectionGenerator() {
108 super(); 91 super();
109 } 92 }
110
111 93
112 @Override 94 @Override
113 protected YAxisWalker getYAxisWalker() { 95 protected YAxisWalker getYAxisWalker() {
114 return new YAxisWalker() { 96 return new YAxisWalker() {
115 @Override 97 @Override
116 public int length() { 98 public int length() {
117 return YAXIS.values().length; 99 return YAXIS.values().length;
118 } 100 }
119 101
120 @Override 102 @Override
121 public String getId(int idx) { 103 public String getId(final int idx) {
122 YAXIS[] yaxes = YAXIS.values(); 104 final YAXIS[] yaxes = YAXIS.values();
123 return yaxes[idx].toString(); 105 return yaxes[idx].toString();
124 } 106 }
125 }; 107 };
126 } 108 }
127
128 109
129 /** 110 /**
130 * Return left most data points x value (on first axis). 111 * Return left most data points x value (on first axis).
131 * Overridden because axis could be inverted. 112 * Overridden because axis could be inverted.
132 */ 113 */
133 @Override 114 @Override
134 protected double getLeftX() { 115 protected double getLeftX() {
135 if (isInverted()) { 116 if (isInverted()) {
136 return (Double)getXBounds(0).getUpper(); 117 return (Double) getXBounds(0).getUpper();
137 } 118 }
138 return (Double)getXBounds(0).getLower(); 119 return (Double) getXBounds(0).getLower();
139 } 120 }
140
141 121
142 /** 122 /**
143 * Return right most data points x value (on first axis). 123 * Return right most data points x value (on first axis).
144 * Overridden because axis could be inverted. 124 * Overridden because axis could be inverted.
145 */ 125 */
146 @Override 126 @Override
147 protected double getRightX() { 127 protected double getRightX() {
148 if (isInverted()) { 128 if (isInverted()) {
149 return (Double)getXBounds(0).getLower(); 129 return (Double) getXBounds(0).getLower();
150 } 130 }
151 return (Double)getXBounds(0).getUpper(); 131 return (Double) getXBounds(0).getUpper();
152 } 132 }
153
154 133
155 /** 134 /**
156 * Returns the default title for this chart. 135 * Returns the default title for this chart.
157 * 136 *
158 * @return the default title for this chart. 137 * @return the default title for this chart.
167 * 146 *
168 * @return the default subtitle for this chart. 147 * @return the default subtitle for this chart.
169 */ 148 */
170 @Override 149 @Override
171 protected String getDefaultChartSubtitle(final CallContext context) { 150 protected String getDefaultChartSubtitle(final CallContext context) {
172 double[] dist = getRange(); 151 final double[] dist = getRange();
173 152
174 Object[] args = null; 153 Object[] args = null;
175 if (dist == null) { 154 if (dist == null) {
176 args = new Object[] {getRiverName()}; 155 args = new Object[] { getRiverName() };
177 return msg(getChartShortSubtitleKey(), "", args); 156 return msg(getChartShortSubtitleKey(), "", args);
178 } 157 }
179 args = new Object[] { 158 args = new Object[] { getRiverName(), dist[0], dist[1] };
180 getRiverName(),
181 dist[0],
182 dist[1]
183 };
184 return msg(getChartSubtitleKey(), "", args); 159 return msg(getChartSubtitleKey(), "", args);
185 } 160 }
186 161
187
188 /** 162 /**
189 * Gets key to look up internationalized String for the charts subtitle. 163 * Gets key to look up internationalized String for the charts subtitle.
164 *
190 * @return key to look up translated subtitle. 165 * @return key to look up translated subtitle.
191 */ 166 */
192 protected String getChartSubtitleKey() { 167 protected String getChartSubtitleKey() {
193 return I18N_CHART_SUBTITLE; 168 return I18N_CHART_SUBTITLE;
194 } 169 }
195 170
196
197 /** 171 /**
198 * Gets key to look up internationalized String for the charts short 172 * Gets key to look up internationalized String for the charts short
199 * subtitle. 173 * subtitle.
174 *
200 * @return key to look up translated subtitle. 175 * @return key to look up translated subtitle.
201 */ 176 */
202 protected String getChartShortSubtitleKey() { 177 protected String getChartShortSubtitleKey() {
203 return I18N_CHART_SHORT_SUBTITLE; 178 return I18N_CHART_SHORT_SUBTITLE;
204 } 179 }
205 180
206
207 /** 181 /**
208 * Get internationalized label for the x axis. 182 * Get internationalized label for the x axis.
209 */ 183 */
210 @Override 184 @Override
211 protected String getDefaultXAxisLabel(CallContext context) { 185 protected String getDefaultXAxisLabel(final CallContext context) {
212 D4EArtifact flys = getArtifact(); 186 final D4EArtifact flys = getArtifact();
213 187
214 return msg( 188 return msg(I18N_XAXIS_LABEL, I18N_XAXIS_LABEL_DEFAULT, new Object[] { RiverUtils.getRiver(flys).getName() });
215 I18N_XAXIS_LABEL, 189 }
216 I18N_XAXIS_LABEL_DEFAULT, 190
217 new Object[] { RiverUtils.getRiver(flys).getName() }); 191 @Override
218 } 192 protected String getDefaultYAxisLabel(final int index) {
219
220
221 @Override
222 protected String getDefaultYAxisLabel(int index) {
223 String label = "default"; 193 String label = "default";
224 194
225 if (index == YAXIS.W.idx) { 195 if (index == YAXIS.W.idx) {
226 label = getWAxisLabel(); 196 label = getWAxisLabel();
227 } 197 } else if (index == YAXIS.Q.idx) {
228 else if (index == YAXIS.Q.idx) {
229 label = msg(getQAxisLabelKey(), getQAxisDefaultLabel()); 198 label = msg(getQAxisLabelKey(), getQAxisDefaultLabel());
230 } 199 } else if (index == YAXIS.D.idx) {
231 else if (index == YAXIS.D.idx) { 200 label = msg(I18N_WDIFF_YAXIS_LABEL, I18N_WDIFF_YAXIS_LABEL_DEFAULT);
232 label = msg(
233 I18N_WDIFF_YAXIS_LABEL, I18N_WDIFF_YAXIS_LABEL_DEFAULT);
234 } 201 }
235 202
236 return label; 203 return label;
237 } 204 }
238 205
239
240 /** 206 /**
241 * Get internationalized label for the y axis. 207 * Get internationalized label for the y axis.
242 */ 208 */
243 protected String getWAxisLabel() { 209 protected String getWAxisLabel() {
244 D4EArtifact flys = getArtifact(); 210 final D4EArtifact flys = getArtifact();
245 211
246 String unit = RiverUtils.getRiver(flys).getWstUnit().getName(); 212 final String unit = RiverUtils.getRiver(flys).getWstUnit().getName();
247 213
248 return msg( 214 return msg(I18N_YAXIS_LABEL, I18N_YAXIS_LABEL_DEFAULT, new Object[] { unit });
249 I18N_YAXIS_LABEL, 215 }
250 I18N_YAXIS_LABEL_DEFAULT,
251 new Object[] { unit });
252 }
253
254 216
255 /** 217 /**
256 * Create Axis for given index. 218 * Create Axis for given index.
219 *
257 * @return axis with according internationalized label. 220 * @return axis with according internationalized label.
258 */ 221 */
259 @Override 222 @Override
260 protected NumberAxis createYAxis(int index) { 223 protected NumberAxis createYAxis(final int index) {
261 NumberAxis axis = super.createYAxis(index); 224 final NumberAxis axis = super.createYAxis(index);
262 225
263 // "Q" Axis shall include 0. 226 // "Q" Axis shall include 0.
264 if (index == YAXIS.Q.idx) { 227 if (index == YAXIS.Q.idx) {
265 axis.setAutoRangeIncludesZero(true); 228 axis.setAutoRangeIncludesZero(true);
266 } 229 } else {
267 else {
268 axis.setAutoRangeIncludesZero(false); 230 axis.setAutoRangeIncludesZero(false);
269 } 231 }
270 232
271 return axis; 233 return axis;
272 } 234 }
273
274 235
275 /** 236 /**
276 * Get default value for the second Y-Axis' label (if no translation was 237 * Get default value for the second Y-Axis' label (if no translation was
277 * found). 238 * found).
278 */ 239 */
279 protected String getQAxisDefaultLabel() { 240 protected String getQAxisDefaultLabel() {
280 return I18N_2YAXIS_LABEL_DEFAULT; 241 return I18N_2YAXIS_LABEL_DEFAULT;
281 } 242 }
282 243
283
284 /** 244 /**
285 * Get key for internationalization of the second Y-Axis' label. 245 * Get key for internationalization of the second Y-Axis' label.
286 */ 246 */
287 protected String getQAxisLabelKey() { 247 protected String getQAxisLabelKey() {
288 return I18N_2YAXIS_LABEL; 248 return I18N_2YAXIS_LABEL;
289 } 249 }
290 250
291
292 /** 251 /**
293 * Trigger inversion. 252 * Trigger inversion.
294 */ 253 */
295 @Override 254 @Override
296 protected void adjustAxes(XYPlot plot) { 255 protected void adjustAxes(final XYPlot plot) {
297 super.adjustAxes(plot); 256 super.adjustAxes(plot);
298 invertXAxis(plot.getDomainAxis()); 257 invertXAxis(plot.getDomainAxis());
299 } 258 }
300
301 259
302 /** 260 /**
303 * This method inverts the x-axis based on the kilometer information of the 261 * This method inverts the x-axis based on the kilometer information of the
304 * selected river. If the head of the river is at kilometer 0, the axis is 262 * selected river. If the head of the river is at kilometer 0, the axis is
305 * not inverted, otherwise it is. 263 * not inverted, otherwise it is.
306 * 264 *
307 * @param xaxis The domain axis. 265 * @param xaxis
308 */ 266 * The domain axis.
309 protected void invertXAxis(ValueAxis xaxis) { 267 */
268 protected void invertXAxis(final ValueAxis xaxis) {
310 if (isInverted()) { 269 if (isInverted()) {
311 log.debug("X-Axis.setInverted(true)"); 270 log.debug("X-Axis.setInverted(true)");
312 xaxis.setInverted(true); 271 xaxis.setInverted(true);
313 } 272 }
314 } 273 }
315 274
316
317 /** 275 /**
318 * Produce output. 276 * Produce output.
319 * @param artifactAndFacet current facet and artifact. 277 *
320 * @param attr theme for facet 278 * @param artifactAndFacet
321 */ 279 * current facet and artifact.
322 @Override 280 * @param attr
323 public void doOut( 281 * theme for facet
324 ArtifactAndFacet artifactAndFacet, 282 */
325 ThemeDocument attr, 283 @Override
326 boolean visible 284 public void doOut(final ArtifactAndFacet artifactAndFacet, final ThemeDocument attr, final boolean visible) {
327 ) { 285 final String name = artifactAndFacet.getFacetName();
328 String name = artifactAndFacet.getFacetName();
329 286
330 log.debug("LongitudinalSectionGenerator.doOut: " + name); 287 log.debug("LongitudinalSectionGenerator.doOut: " + name);
331 288
332 if (name == null) { 289 if (name == null) {
333 log.error("No facet name for doOut(). No output generated!"); 290 log.error("No facet name for doOut(). No output generated!");
334 return; 291 return;
335 } 292 }
336 293
337 Facet facet = artifactAndFacet.getFacet(); 294 final Facet facet = artifactAndFacet.getFacet();
338 295
339 if (facet == null) { 296 if (facet == null) {
340 return; 297 return;
341 } 298 }
342 299
343 CallContext context = getContext(); 300 final CallContext context = getContext();
344 301
345 Processor wProcessor = new WOutProcessor(); 302 final Processor wProcessor = new WOutProcessor();
346 Processor qProcessor = new QOutProcessor(); 303 final Processor qProcessor = new QOutProcessor();
347 Processor bdyProcessor = new BedDiffYearProcessor(); 304 final Processor bdyProcessor = new BedDiffYearProcessor();
348 Processor bdhyProcessor = new BedDiffHeightYearProcessor(); 305 final Processor bdhyProcessor = new BedDiffHeightYearProcessor();
349 Processor annotationProcessor = new AnnotationProcessor(); 306 final Processor annotationProcessor = new AnnotationProcessor();
350 307
351 if (wProcessor.canHandle(name)) { 308 if (wProcessor.canHandle(name)) {
352 wProcessor.doOut( 309 wProcessor.doOut(this, artifactAndFacet, attr, visible, YAXIS.W.idx);
353 this, artifactAndFacet, attr, visible, YAXIS.W.idx);
354 } 310 }
355 if (qProcessor.canHandle(name)) { 311 if (qProcessor.canHandle(name)) {
356 qProcessor.doOut( 312 qProcessor.doOut(this, artifactAndFacet, attr, visible, YAXIS.Q.idx);
357 this, artifactAndFacet, attr, visible, YAXIS.Q.idx); 313 } else if (bdyProcessor.canHandle(name)) {
358 } 314 bdyProcessor.doOut(this, artifactAndFacet, attr, visible, YAXIS.W.idx);
359 else if (bdyProcessor.canHandle(name)) { 315 } else if (bdhyProcessor.canHandle(name)) {
360 bdyProcessor.doOut( 316 bdhyProcessor.doOut(this, artifactAndFacet, attr, visible, YAXIS.W.idx);
361 this, artifactAndFacet, attr, visible, YAXIS.W.idx); 317 } else if (annotationProcessor.canHandle(name)) {
362 } 318 annotationProcessor.doOut(this, artifactAndFacet, attr, visible, 0);
363 else if (bdhyProcessor.canHandle(name)) { 319 } else if (name.equals(W_DIFFERENCES)) {
364 bdhyProcessor.doOut( 320 doWDifferencesOut((WKms) artifactAndFacet.getData(context), artifactAndFacet, attr, visible);
365 this, artifactAndFacet, attr, visible, YAXIS.W.idx); 321 } else if (FacetTypes.IS.AREA(name)) {
366 } 322 doArea(artifactAndFacet.getData(context), artifactAndFacet, attr, visible);
367 else if (annotationProcessor.canHandle(name)) { 323 } else if (FacetTypes.IS.MANUALPOINTS(name)) {
368 annotationProcessor.doOut( 324 doPoints(artifactAndFacet.getData(context), artifactAndFacet, attr, visible, YAXIS.W.idx);
369 this, artifactAndFacet, attr, visible, 0); 325 } else {
370 }
371 else if (name.equals(W_DIFFERENCES)) {
372 doWDifferencesOut(
373 (WKms) artifactAndFacet.getData(context),
374 artifactAndFacet,
375 attr,
376 visible);
377 }
378 else if (FacetTypes.IS.AREA(name)) {
379 doArea(
380 artifactAndFacet.getData(context),
381 artifactAndFacet,
382 attr,
383 visible);
384 }
385 else if (FacetTypes.IS.MANUALPOINTS(name)) {
386 doPoints(
387 artifactAndFacet.getData(context),
388 artifactAndFacet,
389 attr,
390 visible,
391 YAXIS.W.idx);
392 }
393 else {
394 log.warn("Unknown facet name: " + name); 326 log.warn("Unknown facet name: " + name);
395 return; 327 return;
396 } 328 }
397 } 329 }
398 330
399 /** 331 /**
400 * Add items to dataseries which describes the differences. 332 * Add items to dataseries which describes the differences.
401 */ 333 */
402 protected void doWDifferencesOut( 334 protected void doWDifferencesOut(final WKms wkms, final ArtifactAndFacet aandf, final ThemeDocument theme, final boolean visible) {
403 WKms wkms,
404 ArtifactAndFacet aandf,
405 ThemeDocument theme,
406 boolean visible
407 ) {
408 log.debug("WDifferencesCurveGenerator.doWDifferencesOut"); 335 log.debug("WDifferencesCurveGenerator.doWDifferencesOut");
409 if (wkms == null) { 336 if (wkms == null) {
410 log.warn("No data to add to WDifferencesChart."); 337 log.warn("No data to add to WDifferencesChart.");
411 return; 338 return;
412 } 339 }
413 340
414 XYSeries series = 341 final XYSeries series = new StyledXYSeries(aandf.getFacetDescription(), theme);
415 new StyledXYSeries(aandf.getFacetDescription(), theme);
416 342
417 if (log.isDebugEnabled()) { 343 if (log.isDebugEnabled()) {
418 if (wkms.size() > 0) { 344 if (wkms.size() > 0) {
419 log.debug("Generate series: " + series.getKey()); 345 log.debug("Generate series: " + series.getKey());
420 log.debug("Start km: " + wkms.getKm(0)); 346 log.debug("Start km: " + wkms.getKm(0));
426 StyledSeriesBuilder.addPoints(series, wkms); 352 StyledSeriesBuilder.addPoints(series, wkms);
427 353
428 addAxisSeries(series, YAXIS.D.idx, visible); 354 addAxisSeries(series, YAXIS.D.idx, visible);
429 } 355 }
430 356
431
432 /** 357 /**
433 * Get name of series (displayed in legend). 358 * Get name of series (displayed in legend).
359 *
434 * @return name of the series. 360 * @return name of the series.
435 */ 361 */
436 protected String getSeriesName(WQKms wqkms, String mode) { 362 protected String getSeriesName(final WQKms wqkms, final String mode) {
437 String name = wqkms.getName(); 363 final String name = wqkms.getName();
438 String prefix = name != null && name.indexOf(mode) >= 0 ? null : mode; 364 final String prefix = name != null && name.indexOf(mode) >= 0 ? null : mode;
439 365
440 return prefix != null && prefix.length() > 0 366 return prefix != null && prefix.length() > 0 ? prefix + "(" + name + ")" : name;
441 ? prefix + "(" + name +")" 367 }
442 : name;
443 }
444
445 368
446 /** Look up the axis identifier for a given facet type. */ 369 /** Look up the axis identifier for a given facet type. */
447 public int axisIdxForFacet(String facetName) { 370 public int axisIdxForFacet(final String facetName) {
448 if (FacetTypes.IS.W(facetName)) { 371 if (FacetTypes.IS.W(facetName)) {
449 return YAXIS.W.idx; 372 return YAXIS.W.idx;
450 } 373 } else if (FacetTypes.IS.Q(facetName)) {
451 else if (FacetTypes.IS.Q(facetName)) {
452 return YAXIS.Q.idx; 374 return YAXIS.Q.idx;
453 } 375 } else {
454 else {
455 log.warn("Could not find axis for facet " + facetName); 376 log.warn("Could not find axis for facet " + facetName);
456 return YAXIS.W.idx; 377 return YAXIS.W.idx;
457 } 378 }
458 } 379 }
459 380
460
461 /** 381 /**
462 * Do Area out. 382 * Do Area out.
463 * @param theme styling information. 383 *
464 * @param visible whether or not visible. 384 * @param theme
465 */ 385 * styling information.
466 protected void doArea( 386 * @param visible
467 Object o, 387 * whether or not visible.
468 ArtifactAndFacet aandf, 388 */
469 ThemeDocument theme, 389 protected void doArea(final Object o, final ArtifactAndFacet aandf, final ThemeDocument theme, final boolean visible) {
470 boolean visible
471 ) {
472 log.debug("LongitudinalSectionGenerator.doArea"); 390 log.debug("LongitudinalSectionGenerator.doArea");
473 StyledAreaSeriesCollection area = new StyledAreaSeriesCollection(theme); 391 final StyledAreaSeriesCollection area = new StyledAreaSeriesCollection(theme);
474 392
475 String seriesName = aandf.getFacetDescription(); 393 final String seriesName = aandf.getFacetDescription();
476 394
477 AreaFacet.Data data = (AreaFacet.Data) o; 395 final AreaFacet.Data data = (AreaFacet.Data) o;
478 396
479 XYSeries up = null; 397 XYSeries up = null;
480 XYSeries down = null; 398 XYSeries down = null;
481 399
482 if (data.getUpperData() != null) { 400 if (data.getUpperData() != null) {
483 up = new StyledXYSeries(seriesName, false, theme); 401 up = new StyledXYSeries(seriesName, false, theme);
484 if (data.getUpperData() instanceof WQKms) { 402 if (data.getUpperData() instanceof WQKms) {
485 if (FacetTypes.IS.Q(data.getUpperFacetName())) { 403 if (FacetTypes.IS.Q(data.getUpperFacetName())) {
486 StyledSeriesBuilder.addPointsKmQ( 404 StyledSeriesBuilder.addPointsKmQ(up, (WQKms) data.getUpperData());
487 up, (WQKms)data.getUpperData()); 405 } else {
406 StyledSeriesBuilder.addPoints(up, (WKms) data.getUpperData());
488 } 407 }
489 else { 408 } else if (data.getUpperData() instanceof double[][]) {
490 StyledSeriesBuilder.addPoints( 409 StyledSeriesBuilder.addPoints(up, (double[][]) data.getUpperData(), false);
491 up, (WKms) data.getUpperData()); 410 } else if (data.getUpperData() instanceof WKms) {
492 }
493 }
494 else if (data.getUpperData() instanceof double[][]) {
495 StyledSeriesBuilder.addPoints(
496 up, (double [][]) data.getUpperData(), false);
497 }
498 else if (data.getUpperData() instanceof WKms) {
499 StyledSeriesBuilder.addPoints(up, (WKms) data.getUpperData()); 411 StyledSeriesBuilder.addPoints(up, (WKms) data.getUpperData());
500 } 412 } else if (data.getUpperData() instanceof Lines.LineData) {
501 else if (data.getUpperData() instanceof Lines.LineData) { 413 StyledSeriesBuilder.addPoints(up, ((Lines.LineData) data.getUpperData()).points, false);
502 StyledSeriesBuilder.addPoints( 414 } else {
503 up, ((Lines.LineData) data.getUpperData()).points, false); 415 log.error("Do not know how to deal with (up) area info from: " + data.getUpperData());
504 }
505 else {
506 log.error("Do not know how to deal with (up) area info from: "
507 + data.getUpperData());
508 } 416 }
509 } 417 }
510 418
511 // TODO Depending on style, the area (e.g. 20m^2) 419 // TODO Depending on style, the area (e.g. 20m^2)
512 // should be added as annotation. 420 // should be added as annotation.
515 // TODO: Sort this out: when the two series have the same name, 423 // TODO: Sort this out: when the two series have the same name,
516 // the renderer (or anything in between) will not work correctly. 424 // the renderer (or anything in between) will not work correctly.
517 down = new StyledXYSeries(seriesName + " ", false, theme); 425 down = new StyledXYSeries(seriesName + " ", false, theme);
518 if (data.getLowerData() instanceof WQKms) { 426 if (data.getLowerData() instanceof WQKms) {
519 if (FacetTypes.IS.Q(data.getLowerFacetName())) { 427 if (FacetTypes.IS.Q(data.getLowerFacetName())) {
520 StyledSeriesBuilder.addPointsKmQ( 428 StyledSeriesBuilder.addPointsKmQ(down, (WQKms) data.getLowerData());
521 down, (WQKms) data.getLowerData()); 429 } else {
430 StyledSeriesBuilder.addPoints(down, (WQKms) data.getLowerData());
522 } 431 }
523 else { 432 } else if (data.getLowerData() instanceof double[][]) {
524 StyledSeriesBuilder.addPoints( 433 StyledSeriesBuilder.addPoints(down, (double[][]) data.getLowerData(), false);
525 down, (WQKms) data.getLowerData()); 434 } else if (data.getLowerData() instanceof WKms) {
526 } 435 StyledSeriesBuilder.addPoints(down, (WKms) data.getLowerData());
527 } 436 } else if (data.getLowerData() instanceof Lines.LineData) {
528 else if (data.getLowerData() instanceof double[][]) { 437 StyledSeriesBuilder.addPoints(down, ((Lines.LineData) data.getLowerData()).points, false);
529 StyledSeriesBuilder.addPoints( 438 } else {
530 down, (double[][]) data.getLowerData(), false); 439 log.error("Do not know how to deal with (down) area info from: " + data.getLowerData());
531 }
532 else if (data.getLowerData() instanceof WKms) {
533 StyledSeriesBuilder.addPoints(
534 down, (WKms) data.getLowerData());
535 }
536 else if (data.getLowerData() instanceof Lines.LineData) {
537 StyledSeriesBuilder.addPoints(
538 down,
539 ((Lines.LineData) data.getLowerData()).points,
540 false);
541 }
542 else {
543 log.error(
544 "Do not know how to deal with (down) area info from: "
545 + data.getLowerData());
546 } 440 }
547 } 441 }
548 442
549 if (up == null && down != null) { 443 if (up == null && down != null) {
550 area.setMode(StyledAreaSeriesCollection.FILL_MODE.ABOVE); 444 area.setMode(StyledAreaSeriesCollection.FILL_MODE.ABOVE);
551 down.setKey(seriesName); 445 down.setKey(seriesName);
552 area.addSeries(down); 446 area.addSeries(down);
553 area.addSeries(StyledSeriesBuilder.createGroundAtInfinity(down)); 447 area.addSeries(StyledSeriesBuilder.createGroundAtInfinity(down));
554 } 448 } else if (up != null && down == null) {
555 else if (up != null && down == null) {
556 area.setMode(StyledAreaSeriesCollection.FILL_MODE.UNDER); 449 area.setMode(StyledAreaSeriesCollection.FILL_MODE.UNDER);
557 area.addSeries(up); 450 area.addSeries(up);
558 area.addSeries(StyledSeriesBuilder.createGroundAtInfinity(up)); 451 area.addSeries(StyledSeriesBuilder.createGroundAtInfinity(up));
559 } 452 } else if (up != null && down != null) {
560 else if (up != null && down != null) {
561 if (data.doPaintBetween()) { 453 if (data.doPaintBetween()) {
562 area.setMode(StyledAreaSeriesCollection.FILL_MODE.BETWEEN); 454 area.setMode(StyledAreaSeriesCollection.FILL_MODE.BETWEEN);
563 } 455 } else {
564 else {
565 area.setMode(StyledAreaSeriesCollection.FILL_MODE.ABOVE); 456 area.setMode(StyledAreaSeriesCollection.FILL_MODE.ABOVE);
566 } 457 }
567 area.addSeries(up); 458 area.addSeries(up);
568 area.addSeries(down); 459 area.addSeries(down);
569 } 460 }
570 // Add area to the respective axis. 461 // Add area to the respective axis.
571 String facetAxisName = data.getUpperFacetName() == null 462 final String facetAxisName = data.getUpperFacetName() == null ? data.getLowerFacetName() : data.getUpperFacetName();
572 ? data.getLowerFacetName()
573 : data.getUpperFacetName();
574 addAreaSeries(area, axisIdxForFacet(facetAxisName), visible); 463 addAreaSeries(area, axisIdxForFacet(facetAxisName), visible);
575 } 464 }
576 } 465 }
577 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 466 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org