comparison artifacts/src/main/java/org/dive4elements/river/exports/process/QOutProcessor.java @ 6927:0288db5e90d5

issue1455: Extract QOutProcessor, use it in MiddleBedHeightGenerator and LongitudinalSectionGenerator.
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Tue, 27 Aug 2013 12:46:11 +0200
parents
children 35ecfd1a861a
comparison
equal deleted inserted replaced
6926:bf191baa37e7 6927:0288db5e90d5
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
2 * Software engineering by Intevation GmbH
3 *
4 * This file is Free Software under the GNU AGPL (>=v3)
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the
6 * documentation coming with Dive4Elements River for details.
7 */
8
9 package org.dive4elements.river.exports.process;
10
11 import org.apache.log4j.Logger;
12 import org.jfree.data.xy.XYSeries;
13
14 import org.dive4elements.artifactdatabase.state.ArtifactAndFacet;
15 import org.dive4elements.artifacts.CallContext;
16 import org.dive4elements.river.artifacts.model.FacetTypes;
17 import org.dive4elements.river.artifacts.model.WKms;
18 import org.dive4elements.river.artifacts.model.WQKms;
19
20 import org.dive4elements.river.exports.StyledSeriesBuilder;
21 import org.dive4elements.river.exports.XYChartGenerator;
22 import org.dive4elements.river.jfree.StyledXYSeries;
23 import org.dive4elements.river.themes.ThemeDocument;
24 import org.dive4elements.river.utils.DataUtil;
25
26 /**
27 * Add data to chart/generator.
28 *
29 * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a>
30 */
31 public class QOutProcessor implements Processor {
32
33 /** Private logger. */
34 private static final Logger logger =
35 Logger.getLogger(QOutProcessor.class);
36
37 @Override
38 public void doOut(
39 XYChartGenerator generator,
40 ArtifactAndFacet aaf,
41 ThemeDocument theme,
42 boolean visible,
43 int index)
44 {
45 CallContext context = generator.getCallContext();
46 WQKms wqkms = (WQKms) aaf.getData(context);
47
48 doQOut(generator, wqkms, aaf, theme, visible, index);
49 }
50
51 /**
52 * Returns true if facettype is q-type.
53 */
54 @Override
55 public boolean canHandle(String facetType) {
56 if (facetType == null) {
57 return false;
58 }
59
60 if (facetType.equals(FacetTypes.STATIC_WQKMS_Q)
61 || facetType.equals(FacetTypes.LONGITUDINAL_Q)) {
62 return true;
63 }
64 return false;
65 }
66
67
68 /**
69 * Process the output for Q facets in a longitudinal section curve.
70 *
71 * @param generator Generator to use.
72 * @param wqkms An array of WQKms values.
73 * @param aandf The facet and artifact. This facet does NOT support any data objects. Use
74 * D4EArtifact.getNativeFacet() instead to retrieve a Facet which supports
75 * data.
76 * @param theme The theme that contains styling information.
77 * @param visible The visibility of the curve.
78 * @param index Axis index to add data to.
79 */
80 protected void doQOut(
81 XYChartGenerator generator,
82 WQKms wqkms,
83 ArtifactAndFacet aaf,
84 ThemeDocument theme,
85 boolean visible,
86 int index
87 ) {
88 logger.debug("QProcessor.doOut");
89
90 XYSeries series = new StyledXYSeries(aaf.getFacetDescription(), theme);
91
92 StyledSeriesBuilder.addStepPointsKmQ(series, wqkms);
93
94 generator.addAxisSeries(series, index, visible);
95
96 invertAxis(generator, wqkms);
97 }
98
99 /**
100 * This method determines - taking JFreeCharts auto x value ordering into
101 * account - if the x axis need to be inverted. Waterlines in these charts
102 * should decrease.
103 *
104 * @param generator the generator to invert the axis or not.
105 * @param wkms The data object that stores the x and y values used for this
106 * chart.
107 */
108 public void invertAxis(XYChartGenerator generator, WKms wkms) {
109 boolean wsUp = wkms.guessWaterIncreasing();
110 boolean kmUp = DataUtil.guessWaterIncreasing(wkms.allKms());
111 int size = wkms.size();
112 boolean inv = ((wsUp && kmUp) || (!wsUp && !kmUp)) && size > 1;
113
114 if (logger.isDebugEnabled()) {
115 logger.debug("(Wkms)Values : " + size);
116 if (size > 0) {
117 logger.debug("Start km: " + wkms.getKm(0));
118 logger.debug("End km: " + wkms.getKm(size-1));
119 }
120 logger.debug("wsUp: " + wsUp);
121 logger.debug("kmUp: " + kmUp);
122 if (size == 1) {
123 logger.debug("InvertAxis not inverting because we have just one km");
124 }
125 logger.debug("inv: " + inv);
126 }
127 generator.setInverted(inv);
128 }
129 }
130 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org