Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationCurveGenerator.java @ 9259:66b003701546
Added infrastructure height and Q annotation to S-Info flood duration curve chart
author | mschaefer |
---|---|
date | Mon, 16 Jul 2018 08:43:07 +0200 |
parents | ef7b65576d4b |
children | e5367900dd6d |
rev | line source |
---|---|
9252 | 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.artifacts.sinfo.flood_duration; | |
10 | |
11 import java.awt.Font; | |
12 import java.awt.geom.Point2D; | |
13 | |
14 import org.apache.log4j.Logger; | |
15 import org.dive4elements.artifactdatabase.state.ArtifactAndFacet; | |
16 import org.dive4elements.artifacts.CallContext; | |
17 import org.dive4elements.river.artifacts.model.CalculationResult; | |
18 import org.dive4elements.river.artifacts.model.FacetTypes; | |
19 import org.dive4elements.river.artifacts.model.WQDay; | |
20 import org.dive4elements.river.exports.IdentifiableNumberAxis; | |
21 import org.dive4elements.river.exports.XYChartGenerator; | |
22 import org.dive4elements.river.jfree.Bounds; | |
23 import org.dive4elements.river.jfree.RiverAnnotation; | |
24 import org.dive4elements.river.jfree.StyledXYSeries; | |
25 import org.dive4elements.river.themes.ThemeDocument; | |
26 import org.jfree.chart.axis.NumberAxis; | |
27 import org.jfree.chart.axis.ValueAxis; | |
28 import org.jfree.chart.plot.XYPlot; | |
29 import org.jfree.data.Range; | |
30 import org.jfree.data.xy.XYSeries; | |
31 | |
32 | |
33 /** | |
34 * An OutGenerator that generates duration curves. | |
35 * | |
36 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | |
37 */ | |
38 public class FloodDurationCurveGenerator | |
39 extends XYChartGenerator | |
40 implements FacetTypes | |
41 { | |
42 public static enum YAXIS { | |
43 W(0), | |
44 Q(1); | |
45 public int idx; | |
46 private YAXIS(final int c) { | |
47 this.idx = c; | |
48 } | |
49 } | |
50 | |
51 /** Local log. */ | |
52 private static Logger log = | |
53 Logger.getLogger(FloodDurationCurveGenerator.class); | |
54 | |
55 public static final String I18N_CHART_TITLE = "sinfo.chart.flood_duration.curve.section.title"; | |
56 | |
57 public static final String I18N_CHART_SUBTITLE = "chart.duration.curve.subtitle"; | |
58 | |
59 public static final String I18N_XAXIS_LABEL = "sinfo.chart.flood_duration.curve.xaxis.label"; | |
60 | |
61 public static final String I18N_YAXIS_LABEL_W = "chart.duration.curve.yaxis.label.w"; | |
62 | |
63 public static final String I18N_YAXIS_LABEL_Q = "chart.duration.curve.yaxis.label.q"; | |
64 | |
65 public static final String I18N_CHART_TITLE_DEFAULT = "Dauerlinie"; | |
66 | |
67 public static final String I18N_XAXIS_LABEL_DEFAULT = "Überflutungsdauer [d/a]"; | |
68 | |
69 | |
70 public FloodDurationCurveGenerator() { | |
71 super(); | |
72 } | |
73 | |
74 | |
75 /** | |
76 * Create Axis for given index. | |
77 * @return axis with according internationalized label. | |
78 */ | |
79 @Override | |
80 protected NumberAxis createYAxis(final int index) { | |
81 final Font labelFont = new Font("Tahoma", Font.BOLD, 14); | |
82 final String label = getYAxisLabel(index); | |
83 | |
84 final NumberAxis axis = createNumberAxis(index, label); | |
85 if (index == YAXIS.W.idx) { | |
86 axis.setAutoRangeIncludesZero(false); | |
87 } | |
88 axis.setLabelFont(labelFont); | |
89 return axis; | |
90 } | |
91 | |
92 | |
93 @Override | |
94 protected String getDefaultChartTitle(final CallContext context) { | |
95 return msg(I18N_CHART_TITLE, I18N_CHART_TITLE_DEFAULT); | |
96 } | |
97 | |
98 | |
99 @Override | |
100 protected String getDefaultChartSubtitle(final CallContext context) { | |
101 | |
102 final double[] dist = getRange(); | |
103 return msg(I18N_CHART_SUBTITLE, "", getRiverName(), dist[0]); | |
104 } | |
105 | |
106 | |
107 @Override | |
108 protected String getDefaultXAxisLabel(final CallContext context) { | |
109 return msg(I18N_XAXIS_LABEL, I18N_XAXIS_LABEL_DEFAULT); | |
110 } | |
111 | |
112 | |
113 @Override | |
114 protected String getDefaultYAxisLabel(final int index) { | |
115 | |
116 String label = "default"; | |
117 if (index == YAXIS.W.idx) { | |
118 label = msg(I18N_YAXIS_LABEL_W, I18N_YAXIS_LABEL_W, getRiverUnit()); | |
119 } | |
120 else if (index == YAXIS.Q.idx) { | |
121 label = msg(I18N_YAXIS_LABEL_Q); | |
122 } | |
123 return label; | |
124 } | |
125 | |
126 | |
127 @Override | |
128 protected boolean zoomX(final XYPlot plot, final ValueAxis axis, final Bounds bounds, final Range x) { | |
129 | |
130 final boolean zoomin = super.zoom(plot, axis, bounds, x); | |
131 if (!zoomin) | |
132 axis.setLowerBound(0d); | |
9257
ef7b65576d4b
Added W and Q main values to S-Info flood duration curve chart
mschaefer
parents:
9252
diff
changeset
|
133 axis.setUpperBound(364); |
9252 | 134 return zoomin; |
135 } | |
136 | |
137 | |
138 /** | |
139 * This method overrides the method in the parent class to set the lower | |
140 * bounds of the Q axis to 0. This axis should never display negative | |
141 * values on its own. | |
142 */ | |
143 @Override | |
144 protected boolean zoomY(final XYPlot plot, final ValueAxis axis, final Bounds bounds, final Range x) { | |
145 | |
146 final boolean zoomin = super.zoom(plot, axis, bounds, x); | |
147 if (!zoomin && axis instanceof IdentifiableNumberAxis) { | |
148 final String id = ((IdentifiableNumberAxis) axis).getId(); | |
149 if (YAXIS.Q.toString().equals(id)) | |
150 axis.setLowerBound(0d); | |
151 } | |
152 return zoomin; | |
153 } | |
154 | |
155 | |
156 @Override | |
157 public void doOut(final ArtifactAndFacet artifactFacet, final ThemeDocument attr, final boolean visible) { | |
158 | |
159 final String name = artifactFacet.getFacetName(); | |
160 | |
161 log.debug("FloodDurationCurveGenerator.doOut: " + name); | |
162 | |
163 if (name == null || name.length() == 0) { | |
164 log.error("No facet given. Cannot create dataset."); | |
165 return; | |
166 } | |
167 | |
168 final CallContext context = getContext(); | |
169 | |
170 if (name.equals(DURATION_W)) { | |
171 doWOut((WQDay) ((CalculationResult) artifactFacet.getData(context)).getData(), artifactFacet, attr, visible); | |
172 } | |
173 else if (name.equals(DURATION_Q)) { | |
174 doQOut((WQDay) ((CalculationResult) artifactFacet.getData(context)).getData(), artifactFacet, attr, visible); | |
175 } | |
9259
66b003701546
Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
9257
diff
changeset
|
176 else if (name.equals(FloodDurationCurveProcessor.FACET_FLOOD_DURATION_MAINVALUES_Q) |
66b003701546
Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
9257
diff
changeset
|
177 || name.equals(FloodDurationCurveProcessor.FACET_FLOOD_DURATION_MAINVALUES_W)) { |
9252 | 178 doAnnotations((RiverAnnotation) artifactFacet.getData(context), artifactFacet, attr, visible); |
179 } | |
9259
66b003701546
Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
9257
diff
changeset
|
180 else if (name.equals(FloodDurationCurveProcessor.FACET_FLOOD_DURATION_INFRASTRUCTURE) && (artifactFacet.getData(context) != null)) { |
66b003701546
Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
9257
diff
changeset
|
181 doAnnotations((RiverAnnotation) artifactFacet.getData(context), artifactFacet, attr, visible); |
9252 | 182 } |
9259
66b003701546
Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
9257
diff
changeset
|
183 // else if (name.equals(RELATIVE_POINT)) { |
66b003701546
Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
9257
diff
changeset
|
184 // doPointOut((Point2D) artifactFacet.getData(context), artifactFacet, attr, visible); |
66b003701546
Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
9257
diff
changeset
|
185 // } |
9252 | 186 else if (FacetTypes.IS.MANUALPOINTS(name)) { |
187 doPoints(artifactFacet.getData(context), artifactFacet, attr, visible, YAXIS.W.idx); | |
188 } | |
189 else { | |
190 log.warn("Unknown facet name: " + name); | |
191 return; | |
192 } | |
193 } | |
194 | |
195 /** | |
196 * Creates the series for a duration curve's W facet. | |
197 * | |
198 * @param wqdays The WQDay store that contains the Ws. | |
199 * @param theme | |
200 */ | |
201 protected void doWOut(final WQDay wqdays, final ArtifactAndFacet aaf, final ThemeDocument theme, final boolean visible) { | |
202 | |
203 // log.debug("DurationCurveGenerator.doWOut"); | |
204 final XYSeries series = new StyledXYSeries(aaf.getFacetDescription(), theme); | |
205 final int size = wqdays.size(); | |
206 for (int i = 0; i < size; i++) { | |
207 final int day = wqdays.getDay(i); | |
208 final double w = wqdays.getW(i); | |
209 series.add(day, w); | |
210 } | |
211 addAxisSeries(series, YAXIS.W.idx, visible); | |
212 } | |
213 | |
214 protected void doPointOut(final Point2D point, final ArtifactAndFacet aandf, final ThemeDocument theme, final boolean visible) { | |
215 | |
216 // log.debug("DurationCurveGenerator.doPointOut"); | |
217 final XYSeries series = new StyledXYSeries(aandf.getFacetDescription(), theme); | |
218 series.add(point.getX(), point.getY()); | |
219 addAxisSeries(series, YAXIS.W.idx, visible); | |
220 } | |
221 | |
222 | |
223 /** | |
224 * Creates the series for a duration curve's Q facet. | |
225 * | |
226 * @param wqdays The WQDay store that contains the Qs. | |
227 * @param theme | |
228 */ | |
229 protected void doQOut(final WQDay wqdays, final ArtifactAndFacet aaf, final ThemeDocument theme, final boolean visible) { | |
230 | |
231 // log.debug("DurationCurveGenerator.doQOut"); | |
232 final XYSeries series = new StyledXYSeries(aaf.getFacetDescription(), theme); | |
233 final int size = wqdays.size(); | |
234 for (int i = 0; i < size; i++) { | |
235 final int day = wqdays.getDay(i); | |
236 final double q = wqdays.getQ(i); | |
237 series.add(day, q); | |
238 } | |
239 addAxisSeries(series, YAXIS.Q.idx, visible); | |
240 } | |
241 | |
242 | |
243 @Override | |
244 protected YAxisWalker getYAxisWalker() { | |
245 return new YAxisWalker() { | |
246 @Override | |
247 public int length() { | |
248 return YAXIS.values().length; | |
249 } | |
250 | |
251 @Override | |
252 public String getId(final int idx) { | |
253 final YAXIS[] yaxes = YAXIS.values(); | |
254 return yaxes[idx].toString(); | |
255 } | |
256 }; | |
257 } | |
258 | |
259 // MainValue-Annotations should be visualized by | |
260 // a line that goes to the curve itself. | |
261 } | |
262 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |