comparison flys-artifacts/src/main/java/org/dive4elements/river/exports/DurationCurveGenerator.java @ 5831:bd047b71ab37

Repaired internal references
author Sascha L. Teichmann <teichmann@intevation.de>
date Thu, 25 Apr 2013 12:06:39 +0200
parents flys-artifacts/src/main/java/de/intevation/flys/exports/DurationCurveGenerator.java@cd5eb8f5f6f1
children
comparison
equal deleted inserted replaced
5830:160f53ee0870 5831:bd047b71ab37
1 package org.dive4elements.river.exports;
2
3 import org.dive4elements.artifactdatabase.state.ArtifactAndFacet;
4 import org.dive4elements.river.artifacts.model.FacetTypes;
5 import org.dive4elements.river.artifacts.model.WQDay;
6 import org.dive4elements.river.jfree.Bounds;
7 import org.dive4elements.river.jfree.FLYSAnnotation;
8 import org.dive4elements.river.jfree.StyledXYSeries;
9
10 import java.awt.Font;
11 import java.awt.geom.Point2D;
12
13 import org.apache.log4j.Logger;
14 import org.jfree.chart.axis.NumberAxis;
15 import org.jfree.chart.axis.ValueAxis;
16 import org.jfree.chart.plot.XYPlot;
17 import org.jfree.data.Range;
18 import org.jfree.data.xy.XYSeries;
19 import org.w3c.dom.Document;
20
21
22 /**
23 * An OutGenerator that generates duration curves.
24 *
25 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
26 */
27 public class DurationCurveGenerator
28 extends XYChartGenerator
29 implements FacetTypes
30 {
31 public static enum YAXIS {
32 W(0),
33 Q(1);
34 public int idx;
35 private YAXIS(int c) {
36 idx = c;
37 }
38 }
39
40 /** Local logger. */
41 private static Logger logger =
42 Logger.getLogger(DurationCurveGenerator.class);
43
44 public static final String I18N_CHART_TITLE =
45 "chart.duration.curve.title";
46
47 public static final String I18N_CHART_SUBTITLE =
48 "chart.duration.curve.subtitle";
49
50 public static final String I18N_XAXIS_LABEL =
51 "chart.duration.curve.xaxis.label";
52
53 public static final String I18N_YAXIS_LABEL =
54 "chart.duration.curve.yaxis.label";
55
56 public static final String I18N_CHART_TITLE_DEFAULT =
57 "Dauerlinie";
58
59 public static final String I18N_XAXIS_LABEL_DEFAULT =
60 "Unterschreitungsdauer [Tage]";
61
62 public static final String I18N_YAXIS_LABEL_DEFAULT =
63 "W [NN + m]";
64
65
66 public DurationCurveGenerator() {
67 super();
68 }
69
70
71 /**
72 * Create Axis for given index.
73 * @return axis with according internationalized label.
74 */
75 @Override
76 protected NumberAxis createYAxis(int index) {
77 Font labelFont = new Font("Tahoma", Font.BOLD, 14);
78 String label = getYAxisLabel(index);
79
80 NumberAxis axis = createNumberAxis(index, label);
81 if (index == YAXIS.W.idx) {
82 axis.setAutoRangeIncludesZero(false);
83 }
84 axis.setLabelFont(labelFont);
85 return axis;
86 }
87
88
89 @Override
90 protected String getDefaultChartTitle() {
91 return msg(I18N_CHART_TITLE, I18N_CHART_TITLE_DEFAULT);
92 }
93
94
95 @Override
96 protected String getDefaultChartSubtitle() {
97 double[] dist = getRange();
98
99 Object[] args = new Object[] {
100 getRiverName(),
101 dist[0]
102 };
103
104 return msg(I18N_CHART_SUBTITLE, "", args);
105 }
106
107
108 @Override
109 protected String getDefaultXAxisLabel() {
110 return msg(I18N_XAXIS_LABEL, I18N_XAXIS_LABEL_DEFAULT);
111 }
112
113
114 @Override
115 protected String getDefaultYAxisLabel(int index) {
116 String label = "default";
117 if (index == YAXIS.W.idx) {
118 label = msg(I18N_YAXIS_LABEL, I18N_YAXIS_LABEL_DEFAULT);
119 }
120 else if (index == YAXIS.Q.idx) {
121 // TODO i18n for this label
122 label = "Q [m\u00b3/s]";
123 //label = msg(get2YAxisLabelKey(), get2YAxisDefaultLabel());
124 }
125
126 return label;
127 }
128
129
130 @Override
131 protected boolean zoomX(XYPlot plot, ValueAxis axis, Bounds bounds, Range x) {
132 boolean zoomin = super.zoom(plot, axis, bounds, x);
133
134 if (!zoomin) {
135 axis.setLowerBound(0d);
136 }
137
138 axis.setUpperBound(364);
139
140 return zoomin;
141 }
142
143
144 /**
145 * This method overrides the method in the parent class to set the lower
146 * bounds of the Q axis to 0. This axis should never display negative
147 * values on its own.
148 */
149 @Override
150 protected boolean zoomY(XYPlot plot, ValueAxis axis, Bounds bounds, Range x) {
151 boolean zoomin = super.zoom(plot, axis, bounds, x);
152
153 if (!zoomin && axis instanceof IdentifiableNumberAxis) {
154 String id = ((IdentifiableNumberAxis) axis).getId();
155
156 if (YAXIS.Q.toString().equals(id)) {
157 axis.setLowerBound(0d);
158 }
159 }
160
161 return zoomin;
162 }
163
164
165 @Override
166 public void doOut(
167 ArtifactAndFacet artifactFacet,
168 Document attr,
169 boolean visible
170 ) {
171 String name = artifactFacet.getFacetName();
172
173 logger.debug("DurationCurveGenerator.doOut: " + name);
174
175 if (name == null || name.length() == 0) {
176 logger.error("No facet given. Cannot create dataset.");
177 return;
178 }
179
180 if (name.equals(DURATION_W)) {
181 doWOut(
182 (WQDay) artifactFacet.getData(context),
183 artifactFacet,
184 attr,
185 visible);
186 }
187 else if (name.equals(DURATION_Q)) {
188 doQOut(
189 (WQDay) artifactFacet.getData(context),
190 artifactFacet,
191 attr,
192 visible);
193 }
194 else if (name.equals(DURATION_MAINVALUES_Q)
195 || name.equals(MAINVALUES_Q)
196 || name.equals(COMPUTED_DISCHARGE_MAINVALUES_W)
197 || name.equals(MAINVALUES_W)
198 ) {
199 doAnnotations(
200 (FLYSAnnotation) artifactFacet.getData(context),
201 artifactFacet,
202 attr,
203 visible);
204 }
205 else if (name.equals(RELATIVE_POINT)) {
206 doPointOut((Point2D) artifactFacet.getData(context),
207 artifactFacet,
208 attr,
209 visible);
210 }
211 else if (FacetTypes.IS.MANUALPOINTS(name)) {
212 doPoints(
213 artifactFacet.getData(context),
214 artifactFacet,
215 attr, visible, YAXIS.W.idx);
216 }
217 else {
218 logger.warn("Unknown facet name: " + name);
219 return;
220 }
221 }
222
223
224 /**
225 * Creates the series for a duration curve's W facet.
226 *
227 * @param wqdays The WQDay store that contains the Ws.
228 * @param theme
229 */
230 protected void doWOut(
231 WQDay wqdays,
232 ArtifactAndFacet aaf,
233 Document theme,
234 boolean visible
235 ) {
236 logger.debug("DurationCurveGenerator.doWOut");
237
238 XYSeries series = new StyledXYSeries(aaf.getFacetDescription(), theme);
239
240 int size = wqdays.size();
241 for (int i = 0; i < size; i++) {
242 int day = wqdays.getDay(i);
243 double w = wqdays.getW(i);
244
245 series.add(day, w);
246 }
247
248 addAxisSeries(series, YAXIS.W.idx, visible);
249 }
250
251 protected void doPointOut(
252 Point2D point,
253 ArtifactAndFacet aandf,
254 Document theme,
255 boolean visible
256 ){
257 logger.debug("DurationCurveGenerator.doPointOut");
258
259 XYSeries series = new StyledXYSeries(aandf.getFacetDescription(), theme);
260
261 series.add(point.getX(), point.getY());
262
263 addAxisSeries(series, YAXIS.W.idx, visible);
264 }
265
266
267 /**
268 * Creates the series for a duration curve's Q facet.
269 *
270 * @param wqdays The WQDay store that contains the Qs.
271 * @param theme
272 */
273 protected void doQOut(
274 WQDay wqdays,
275 ArtifactAndFacet aaf,
276 Document theme,
277 boolean visible
278 ) {
279 logger.debug("DurationCurveGenerator.doQOut");
280
281 XYSeries series = new StyledXYSeries(aaf.getFacetDescription(), theme);
282
283 int size = wqdays.size();
284 for (int i = 0; i < size; i++) {
285 int day = wqdays.getDay(i);
286 double q = wqdays.getQ(i);
287
288 series.add(day, q);
289 }
290
291 addAxisSeries(series, YAXIS.Q.idx, visible);
292 }
293
294
295 @Override
296 protected YAxisWalker getYAxisWalker() {
297 return new YAxisWalker() {
298 @Override
299 public int length() {
300 return YAXIS.values().length;
301 }
302
303 @Override
304 public String getId(int idx) {
305 YAXIS[] yaxes = YAXIS.values();
306 return yaxes[idx].toString();
307 }
308 };
309 }
310
311 // MainValue-Annotations should be visualized by a line that goes to the curve itself.
312 }
313 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org