comparison flys-artifacts/src/main/java/de/intevation/flys/exports/WDifferencesCurveGenerator.java @ 3809:cc83b8e42dbe

Picked rev3347-rev3351 from trunk. flys-artifacts/tags/pre2.6-2011-12-05@3352 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Mon, 05 Dec 2011 09:48:44 +0000
parents 65f9d707caff
children 156304542edf
comparison
equal deleted inserted replaced
1950:37a7b3841565 3809:cc83b8e42dbe
4 4
5 import org.jfree.chart.title.TextTitle; 5 import org.jfree.chart.title.TextTitle;
6 6
7 import org.jfree.chart.JFreeChart; 7 import org.jfree.chart.JFreeChart;
8 import org.jfree.chart.plot.XYPlot; 8 import org.jfree.chart.plot.XYPlot;
9 import org.jfree.data.xy.XYSeries;
10 9
11 import org.w3c.dom.Document;
12
13 import de.intevation.flys.artifacts.FLYSArtifact;
14 import de.intevation.flys.artifacts.model.FacetTypes; 10 import de.intevation.flys.artifacts.model.FacetTypes;
15 import de.intevation.flys.artifacts.model.WKms; 11 import de.intevation.flys.artifacts.model.WKms;
16 12
17 import de.intevation.artifactdatabase.state.ArtifactAndFacet;
18
19 import de.intevation.flys.artifacts.model.WQKms;
20 import de.intevation.flys.utils.DataUtil;
21 import de.intevation.flys.utils.FLYSUtils;
22
23 import de.intevation.flys.jfree.FLYSAnnotation;
24 13
25 /** 14 /**
26 * An OutGenerator that generates w differences curves. 15 * An OutGenerator that generates w differences curves.
27 */ 16 */
28 public class WDifferencesCurveGenerator 17 public class WDifferencesCurveGenerator
29 extends LongitudinalSectionGenerator 18 extends LongitudinalSectionGenerator
30 implements FacetTypes 19 implements FacetTypes
31 { 20 {
32 public static enum YAXIS { 21 public enum YAXIS {
33 D(0), 22 W(0),
34 W(1), 23 D(1),
35 Q(2); 24 Q(2);
36 protected int idx; 25 protected int idx;
37 private YAXIS(int c) { 26 private YAXIS(int c) {
38 idx = c; 27 idx = c;
39 } 28 }
47 public final static String I18N_WDIFF_TITLE = "chart.w_differences.title"; 36 public final static String I18N_WDIFF_TITLE = "chart.w_differences.title";
48 37
49 /** Default for internationalized title (when no translation found). */ 38 /** Default for internationalized title (when no translation found). */
50 public final static String I18N_WDIFF_TITLE_DEFAULT = "Differences"; 39 public final static String I18N_WDIFF_TITLE_DEFAULT = "Differences";
51 40
52 /** Key for internationalized title of WDiff charts. */
53 public final static String I18N_WDIFF_2YAXIS_LABEL =
54 "chart.w_differences.yaxis.second.label";
55
56 /** Default for label for second Y-Axis when no translation found. */
57 public final static String I18N_WDIFF_2YAXIS_LABEL_DEFAULT = "W [NN + m]";
58
59 public final static String I18N_WDIFF_SUBTITLE = 41 public final static String I18N_WDIFF_SUBTITLE =
60 "chart.w_differences.subtitle"; 42 "chart.w_differences.subtitle";
61
62 public final static String I18N_WDIFF_YAXIS_LABEL =
63 "chart.w_differences.yaxis.label";
64
65 public final static String I18N_WDIFF_YAXIS_LABEL_DEFAULT = "m";
66 43
67 44
68 /** 45 /**
69 * Get internationalized title for chart. 46 * Get internationalized title for chart.
70 * @return internationalized Chart title. 47 * @return internationalized Chart title.
74 return msg(I18N_WDIFF_TITLE, I18N_WDIFF_TITLE_DEFAULT); 51 return msg(I18N_WDIFF_TITLE, I18N_WDIFF_TITLE_DEFAULT);
75 } 52 }
76 53
77 54
78 /** 55 /**
79 * Get default value for the second Y-Axis' label (if no translation was
80 * found).
81 * @return default value for second y-axis label.
82 */
83 @Override
84 protected String get2YAxisDefaultLabel() {
85 return I18N_WDIFF_2YAXIS_LABEL_DEFAULT;
86 }
87
88
89 /**
90 * Gets key to look up internationalized String for the charts subtitle. 56 * Gets key to look up internationalized String for the charts subtitle.
91 * @return key to look up translated subtitle. 57 * @return key to look up translated subtitle.
92 */ 58 */
93 @Override 59 @Override
94 protected String getChartSubtitleKey() { 60 protected String getChartSubtitleKey() {
95 return I18N_WDIFF_SUBTITLE; 61 return I18N_WDIFF_SUBTITLE;
96 } 62 }
97 63
98
99 /**
100 * Get key for internationalization of the second Y-Axis' label.
101 * @return internationalized second y-axis.
102 */
103 @Override
104 protected String get2YAxisLabelKey() {
105 return I18N_WDIFF_2YAXIS_LABEL;
106 }
107
108
109 /**
110 * Get internationalized label for the y axis.
111 * @return internationalized label for y axos.
112 */
113 @Override
114 protected String getYAxisLabel() {
115 FLYSArtifact flys = (FLYSArtifact) master;
116
117 String unit = FLYSUtils.getRiver(flys).getWstUnit().getName();
118
119 return msg(
120 I18N_WDIFF_YAXIS_LABEL,
121 I18N_WDIFF_YAXIS_LABEL_DEFAULT,
122 new Object[] { unit });
123 }
124
125
126 /**
127 * Add (themed) data for chart generation.
128 */
129 @Override
130 public void doOut(
131 ArtifactAndFacet artifactAndFacet,
132 Document attr,
133 boolean visible
134 ) {
135 String name = artifactAndFacet.getFacetName();
136
137 logger.debug("WDifferencesCurveGenerator.doOut: " + name);
138
139 if (name == null) {
140 logger.error("No facet name for doOut(). No output generated!");
141 return;
142 }
143
144 if (name.equals(W_DIFFERENCES)) {
145 doWDifferencesOut(
146 (WKms) artifactAndFacet.getData(context),
147 artifactAndFacet.getFacetDescription(),
148 attr,
149 visible);
150 }
151 else if (name.equals(LONGITUDINAL_W)) {
152 doWOut((WQKms) artifactAndFacet.getData(context),
153 artifactAndFacet.getFacetDescription(), attr, visible);
154 }
155 else if (name.equals(STATIC_WKMS) || name.equals(HEIGHTMARKS_POINTS)) {
156 doWOut((WKms) artifactAndFacet.getData(context),
157 artifactAndFacet.getFacetDescription(), attr, visible);
158 }
159 else if (name.equals(LONGITUDINAL_ANNOTATION)) {
160 doAnnotations((FLYSAnnotation) artifactAndFacet.getData(context),
161 artifactAndFacet.getFacet(), attr, visible);
162 }
163 else {
164 logger.warn("Unknown facet name: " + name);
165 return;
166 }
167 }
168
169
170 /**
171 * Add the waterlevel-curves (the "absolutes" from which
172 * differences were calculated).
173 *
174 * @param wqkms The wqkms to add to the diagram.
175 * @param theme The theme that contains styling information.
176 */
177 protected void doWOut(
178 WKms wkms,
179 String description,
180 Document theme,
181 boolean visible
182 ) {
183 logger.debug("WDifferencesCurveGenerator.doWOut");
184
185 XYSeries series = new StyledXYSeries(description, theme);
186
187 StyledSeriesBuilder.addPoints(series, wkms);
188
189 // Note: the only difference in the super-implementation
190 // (in LongitudinalSectionGenerator) is here (adds with
191 // addFirstAxisSeries() .
192 addAxisSeries(series, YAXIS.W.idx, visible);
193
194 if (wkms instanceof WQKms) {
195 if (needInvertAxis((WQKms) wkms)) {
196 setInverted(true);
197 }
198 }
199 }
200 64
201 /** 65 /**
202 * Add (internationalized) subtitle to chart. 66 * Add (internationalized) subtitle to chart.
203 * Overridden to avoid trying to access the range of masterartifact. 67 * Overridden to avoid trying to access the range of masterartifact.
204 * @see getChartSubtitleKey 68 * @see getChartSubtitleKey
212 getRiverName() 76 getRiverName()
213 }; 77 };
214 */ 78 */
215 String subtitle = getRiverName(); 79 String subtitle = getRiverName();
216 chart.addSubtitle(new TextTitle(subtitle)); 80 chart.addSubtitle(new TextTitle(subtitle));
217 }
218
219
220 /**
221 * Add items to dataseries which describes the differences.
222 */
223 protected void doWDifferencesOut(
224 WKms wkms,
225 String description,
226 Document theme,
227 boolean visible
228 ) {
229 logger.debug("WDifferencesCurveGenerator.doWDifferencesOut");
230 if (wkms == null) {
231 logger.warn("No data to add to WDifferencesChart.");
232 return;
233 }
234
235 XYSeries series = new StyledXYSeries(description, theme);
236
237 if (logger.isDebugEnabled()) {
238 if (wkms.size() > 0) {
239 logger.debug("Generate series: " + series.getKey());
240 logger.debug("Start km: " + wkms.getKm(0));
241 logger.debug("End km: " + wkms.getKm(wkms.size()-1));
242 logger.debug("Values : " + wkms.size());
243 }
244 }
245
246 StyledSeriesBuilder.addPoints(series, wkms);
247
248 addAxisSeries(series, YAXIS.D.idx, visible);
249 if (DataUtil.guessWaterIncreasing(wkms.allWs())) {
250 setInverted(true);
251 }
252 } 81 }
253 82
254 83
255 /** 84 /**
256 * 85 *

http://dive4elements.wald.intevation.org