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