comparison flys-artifacts/src/main/java/de/intevation/flys/exports/FlowVelocityGenerator.java @ 2706:d8444fcb4e44

Create chart facets for flow velocity calculation and a chart generator for this. flys-artifacts/trunk@4424 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 16 May 2012 12:39:13 +0000
parents
children 4ac581062c40
comparison
equal deleted inserted replaced
2705:71f072d8b3d8 2706:d8444fcb4e44
1 package de.intevation.flys.exports;
2
3 import org.apache.log4j.Logger;
4
5 import org.jfree.data.xy.XYSeries;
6
7 import org.w3c.dom.Document;
8
9 import de.intevation.artifactdatabase.state.ArtifactAndFacet;
10 import de.intevation.artifactdatabase.state.Facet;
11
12 import de.intevation.flys.artifacts.FLYSArtifact;
13
14 import de.intevation.flys.artifacts.model.FacetTypes;
15 import de.intevation.flys.artifacts.model.FlowVelocityData;
16
17 import de.intevation.flys.jfree.FLYSAnnotation;
18 import de.intevation.flys.jfree.StyledXYSeries;
19
20 import de.intevation.flys.utils.FLYSUtils;
21
22
23
24 /**
25 * An OutGenerator that generates flow velocity curves.
26 *
27 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
28 */
29 public class FlowVelocityGenerator
30 extends XYChartGenerator
31 implements FacetTypes
32 {
33 public enum YAXIS {
34 V(0),
35 T(1);
36 protected int idx;
37 private YAXIS(int c) {
38 idx = c;
39 }
40 }
41
42 /** The logger that is used in this generator. */
43 private static Logger logger = Logger.getLogger(FlowVelocityGenerator.class);
44
45 /** Key to look up internationalized String for annotations label. */
46 public static final String I18N_ANNOTATIONS_LABEL =
47 "chart.flow_velocity.annotations.label";
48
49 /**
50 * Key to look up internationalized String for LongitudinalSection diagrams
51 * titles.
52 */
53 public static final String I18N_CHART_TITLE =
54 "chart.flow_velocity.section.title";
55
56 /**
57 * Key to look up internationalized String for LongitudinalSection diagrams
58 * subtitles.
59 */
60 public static final String I18N_CHART_SUBTITLE =
61 "chart.flow_velocity.section.subtitle";
62
63 /**
64 * Key to look up internationalized String for LongitudinalSection diagrams
65 * short subtitles.
66 */
67 public static final String I18N_CHART_SHORT_SUBTITLE =
68 "chart.flow_velocity.section.shortsubtitle";
69
70 public static final String I18N_XAXIS_LABEL =
71 "chart.flow_velocity.section.xaxis.label";
72
73 public static final String I18N_YAXIS_LABEL =
74 "chart.flow_velocity.section.yaxis.label";
75
76 public static final String I18N_2YAXIS_LABEL =
77 "chart.flow_velocity.section.yaxis.second.label";
78
79 public static final String I18N_CHART_TITLE_DEFAULT = "Geschwindigkeit- und Schubspannung";
80 public static final String I18N_XAXIS_LABEL_DEFAULT = "km";
81 public static final String I18N_YAXIS_LABEL_DEFAULT = "Geschwindigkeit v [m/s]";
82 public static final String I18N_2YAXIS_LABEL_DEFAULT = "Schubspannung Tau [N]";
83
84
85
86 @Override
87 protected YAxisWalker getYAxisWalker() {
88 return new YAxisWalker() {
89 @Override
90 public int length() {
91 return YAXIS.values().length;
92 }
93
94 @Override
95 public String getId(int idx) {
96 YAXIS[] yaxes = YAXIS.values();
97 return yaxes[idx].toString();
98 }
99 };
100 }
101
102
103 /**
104 * Returns the default title for this chart.
105 *
106 * @return the default title for this chart.
107 */
108 @Override
109 public String getDefaultChartTitle() {
110 Object[] args = new Object[] {
111 getRiverName()
112 };
113
114 return msg(I18N_CHART_TITLE, I18N_CHART_TITLE_DEFAULT, args);
115 }
116
117
118 /**
119 * Get internationalized label for the x axis.
120 */
121 @Override
122 protected String getDefaultXAxisLabel() {
123 FLYSArtifact flys = (FLYSArtifact) master;
124
125 return msg(
126 I18N_XAXIS_LABEL,
127 I18N_XAXIS_LABEL_DEFAULT,
128 new Object[] { FLYSUtils.getRiver(flys).getName() });
129 }
130
131
132 @Override
133 protected String getDefaultYAxisLabel(int index) {
134 String label = "default";
135
136 if (index == YAXIS.V.idx) {
137 label = getVAxisLabel();
138 }
139 else if (index == YAXIS.T.idx) {
140 label = getTAxisLabel();
141 }
142
143 return label;
144 }
145
146
147 /**
148 * Get internationalized label for the y axis.
149 */
150 protected String getVAxisLabel() {
151 FLYSArtifact flys = (FLYSArtifact) master;
152
153 return msg(I18N_YAXIS_LABEL, I18N_YAXIS_LABEL_DEFAULT);
154 }
155
156
157 /**
158 * Get internationalized label for the y axis.
159 */
160 protected String getTAxisLabel() {
161 FLYSArtifact flys = (FLYSArtifact) master;
162
163 return msg(I18N_2YAXIS_LABEL, I18N_2YAXIS_LABEL_DEFAULT);
164 }
165
166
167 /**
168 * Produce output.
169 * @param facet current facet.
170 * @param attr theme for facet
171 */
172 public void doOut(
173 ArtifactAndFacet artifactAndFacet,
174 Document attr,
175 boolean visible
176 ) {
177 String name = artifactAndFacet.getFacetName();
178
179 logger.debug("FlowVelocityGenerator.doOut: " + name);
180
181 if (name == null) {
182 logger.error("No facet name for doOut(). No output generated!");
183 return;
184 }
185
186 Facet facet = artifactAndFacet.getFacet();
187
188 if (facet == null) {
189 return;
190 }
191
192 if (name.equals(FLOW_VELOCITY_MAINCHANNEL)) {
193 doMainChannelOut(
194 (FlowVelocityData) artifactAndFacet.getData(context),
195 artifactAndFacet,
196 attr,
197 visible);
198 }
199 else if (name.equals(FLOW_VELOCITY_TOTALCHANNEL)) {
200 doTotalChannelOut(
201 (FlowVelocityData) artifactAndFacet.getData(context),
202 artifactAndFacet,
203 attr,
204 visible);
205 }
206 else if (name.equals(FLOW_VELOCITY_TAU)) {
207 doTauOut(
208 (FlowVelocityData) artifactAndFacet.getData(context),
209 artifactAndFacet,
210 attr,
211 visible);
212 }
213 else if (name.equals(FLOW_VELOCITY_ANNOTATION)) {
214 doAnnotations(
215 (FLYSAnnotation) artifactAndFacet.getData(context),
216 artifactAndFacet,
217 attr,
218 visible);
219 }
220 else if (FacetTypes.IS.AREA(name)) {
221 doArea(
222 artifactAndFacet.getData(context),
223 artifactAndFacet,
224 attr,
225 visible);
226 }
227 else if (FacetTypes.IS.MANUALPOINTS(name)) {
228 doPoints(
229 artifactAndFacet.getData(context),
230 artifactAndFacet,
231 attr,
232 visible,
233 YAXIS.V.idx);
234 }
235 else {
236 logger.warn("Unknown facet name: " + name);
237 return;
238 }
239 }
240
241
242 /**
243 * Process the output for W facets in a longitudinal section curve.
244 *
245 * @param data A FlowVelocityData object
246 * @param facet The facet. This facet does NOT support any data objects. Use
247 * FLYSArtifact.getNativeFacet() instead to retrieve a Facet which supports
248 * data.
249 * @param theme The theme that contains styling information.
250 * @param visible The visibility of the curve.
251 */
252 protected void doMainChannelOut(
253 FlowVelocityData data,
254 ArtifactAndFacet aandf,
255 Document theme,
256 boolean visible
257 ) {
258 logger.debug("FlowVelocityGenerator.doMainChannelOut");
259
260 XYSeries series = new StyledXYSeries(aandf.getFacetDescription(), theme);
261
262 StyledSeriesBuilder.addPoints(series, data.getMainChannelPoints(), true);
263
264 addAxisSeries(series, YAXIS.V.idx, visible);
265 }
266
267
268 /**
269 * Add items to dataseries which describes the differences.
270 */
271 protected void doTotalChannelOut(
272 FlowVelocityData data,
273 ArtifactAndFacet aandf,
274 Document theme,
275 boolean visible
276 ) {
277 logger.debug("FlowVelocityGenerator.doTotalChannelOut");
278
279 if (data == null) {
280 logger.warn("No data to add to FlowVelocity chart.");
281 return;
282 }
283
284 XYSeries series = new StyledXYSeries(aandf.getFacetDescription(), theme);
285
286 StyledSeriesBuilder.addPoints(series, data.getTotalChannelPoints(), true);
287
288 addAxisSeries(series, YAXIS.V.idx, visible);
289 }
290
291
292
293 /**
294 * @param data A FlowVelocityData object
295 * @param facet The facet. This facet does NOT support any data objects. Use
296 * FLYSArtifact.getNativeFacet() instead to retrieve a Facet which supports
297 * data.
298 * @param theme The theme that contains styling information.
299 * @param visible The visibility of the curve.
300 */
301 protected void doTauOut(
302 FlowVelocityData data,
303 ArtifactAndFacet aandf,
304 Document theme,
305 boolean visible
306 ) {
307 logger.debug("FlowVelocityGenerator.doTauOut");
308
309 XYSeries series = new StyledXYSeries(aandf.getFacetDescription(), theme);
310
311 StyledSeriesBuilder.addPoints(series, data.getTauPoints(), true);
312
313 addAxisSeries(series, YAXIS.T.idx, visible);
314 }
315
316
317 /** Look up the axis identifier for a given facet type. */
318 public int axisIdxForFacet(String facetName) {
319 if (FacetTypes.IS.V(facetName)) {
320 return YAXIS.V.idx;
321 }
322 else if (FacetTypes.IS.T(facetName)) {
323 return YAXIS.T.idx;
324 }
325 else {
326 logger.warn("Could not find axis for facet " + facetName);
327 return YAXIS.V.idx;
328 }
329 }
330
331
332 /**
333 * Do Area out.
334 * @param theme styling information.
335 * @param visible whether or not visible.
336 */
337 protected void doArea(
338 Object o,
339 ArtifactAndFacet aandf,
340 Document theme,
341 boolean visible
342 ) {
343 logger.debug("FlowVelocityGenerator.doArea");
344 logger.warn("TODO: Implement FlowVelocityGenerator.doArea");
345 }
346 }
347 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org