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