Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationCurveGenerator.java @ 9556:9b8e8fc1f408
Use facetName in all processors as themeType for legend aggregation.
author | gernotbelger |
---|---|
date | Tue, 23 Oct 2018 16:26:58 +0200 |
parents | 929d645691ae |
children | 9b39cfd39e59 |
rev | line source |
---|---|
9398
929d645691ae
Fixed: sinfo flood duration: no w/q problem report with unchecked wspl option
mschaefer
parents:
9376
diff
changeset
|
1 /** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde |
929d645691ae
Fixed: sinfo flood duration: no w/q problem report with unchecked wspl option
mschaefer
parents:
9376
diff
changeset
|
2 * Software engineering by |
929d645691ae
Fixed: sinfo flood duration: no w/q problem report with unchecked wspl option
mschaefer
parents:
9376
diff
changeset
|
3 * Björnsen Beratende Ingenieure GmbH |
929d645691ae
Fixed: sinfo flood duration: no w/q problem report with unchecked wspl option
mschaefer
parents:
9376
diff
changeset
|
4 * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt |
9252 | 5 * |
6 * This file is Free Software under the GNU AGPL (>=v3) | |
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the | |
8 * documentation coming with Dive4Elements River for details. | |
9 */ | |
10 package org.dive4elements.river.artifacts.sinfo.flood_duration; | |
11 | |
12 import java.awt.Font; | |
13 import java.awt.geom.Point2D; | |
9268
ae9dee74e43e
Fixed: current station of duration chart was not changed
gernotbelger
parents:
9265
diff
changeset
|
14 import java.io.OutputStream; |
9252 | 15 |
16 import org.apache.log4j.Logger; | |
17 import org.dive4elements.artifactdatabase.state.ArtifactAndFacet; | |
18 import org.dive4elements.artifacts.CallContext; | |
19 import org.dive4elements.river.artifacts.model.FacetTypes; | |
20 import org.dive4elements.river.artifacts.model.WQDay; | |
21 import org.dive4elements.river.exports.IdentifiableNumberAxis; | |
22 import org.dive4elements.river.exports.XYChartGenerator; | |
9268
ae9dee74e43e
Fixed: current station of duration chart was not changed
gernotbelger
parents:
9265
diff
changeset
|
23 import org.dive4elements.river.exports.fixings.FixChartGenerator; |
9252 | 24 import org.dive4elements.river.jfree.Bounds; |
25 import org.dive4elements.river.jfree.RiverAnnotation; | |
26 import org.dive4elements.river.jfree.StyledXYSeries; | |
27 import org.dive4elements.river.themes.ThemeDocument; | |
28 import org.jfree.chart.axis.NumberAxis; | |
29 import org.jfree.chart.axis.ValueAxis; | |
30 import org.jfree.chart.plot.XYPlot; | |
31 import org.jfree.data.Range; | |
32 import org.jfree.data.xy.XYSeries; | |
9268
ae9dee74e43e
Fixed: current station of duration chart was not changed
gernotbelger
parents:
9265
diff
changeset
|
33 import org.w3c.dom.Document; |
9252 | 34 |
35 /** | |
9398
929d645691ae
Fixed: sinfo flood duration: no w/q problem report with unchecked wspl option
mschaefer
parents:
9376
diff
changeset
|
36 * An OutGenerator that generates flood duration curves. |
929d645691ae
Fixed: sinfo flood duration: no w/q problem report with unchecked wspl option
mschaefer
parents:
9376
diff
changeset
|
37 * (based upon a copy of DurationCurveGenerator) |
9252 | 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 |
9312 | 60 private static final String I18N_YAXIS_LABEL_Q = "common.export.csv.header.q"; |
9265 | 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 | |
9556
9b8e8fc1f408
Use facetName in all processors as themeType for legend aggregation.
gernotbelger
parents:
9398
diff
changeset
|
166 // TODO: mainvalues.q |
9b8e8fc1f408
Use facetName in all processors as themeType for legend aggregation.
gernotbelger
parents:
9398
diff
changeset
|
167 // TODO: mainvalues.w |
9b8e8fc1f408
Use facetName in all processors as themeType for legend aggregation.
gernotbelger
parents:
9398
diff
changeset
|
168 // } else if (name.equals(MAINVALUES_Q) || name.equals(MAINVALUES_W)) { |
9b8e8fc1f408
Use facetName in all processors as themeType for legend aggregation.
gernotbelger
parents:
9398
diff
changeset
|
169 // doAnnotations((RiverAnnotation) artifactFacet.getData(context), artifactFacet, attr, visible); |
9b8e8fc1f408
Use facetName in all processors as themeType for legend aggregation.
gernotbelger
parents:
9398
diff
changeset
|
170 |
9252 | 171 if (name.equals(DURATION_W)) { |
9265 | 172 doWOut((WQDay) (artifactFacet.getData(context)), artifactFacet, attr, visible); |
9312 | 173 } else if (name.equals(DURATION_Q)) { |
9265 | 174 doQOut((WQDay) artifactFacet.getData(context), artifactFacet, attr, visible); |
9312 | 175 } else if (name.equals(FloodDurationCurveProcessor.FACET_FLOOD_DURATION_MAINVALUES_Q) |
9259
66b003701546
Added infrastructure height and Q annotation to S-Info flood duration curve chart
mschaefer
parents:
9257
diff
changeset
|
176 || name.equals(FloodDurationCurveProcessor.FACET_FLOOD_DURATION_MAINVALUES_W)) { |
9252 | 177 doAnnotations((RiverAnnotation) artifactFacet.getData(context), artifactFacet, attr, visible); |
9556
9b8e8fc1f408
Use facetName in all processors as themeType for legend aggregation.
gernotbelger
parents:
9398
diff
changeset
|
178 } else if (FloodDurationCurveProcessor.isInfrastructureFacet(name) && (artifactFacet.getData(context) != null)) { |
9b8e8fc1f408
Use facetName in all processors as themeType for legend aggregation.
gernotbelger
parents:
9398
diff
changeset
|
179 doAnnotations((RiverAnnotation) artifactFacet.getData(context), artifactFacet, attr, visible); |
9b8e8fc1f408
Use facetName in all processors as themeType for legend aggregation.
gernotbelger
parents:
9398
diff
changeset
|
180 } else if (name.equals(MAINVALUES_Q) || name.equals(MAINVALUES_W)) { |
9259
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); | |
9312 | 188 } else { |
9252 | 189 log.warn("Unknown facet name: " + name); |
190 return; | |
191 } | |
192 } | |
193 | |
194 /** | |
195 * Creates the series for a duration curve's W facet. | |
196 * | |
9265 | 197 * @param wqdays |
198 * The WQDay store that contains the Ws. | |
9252 | 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"); | |
9556
9b8e8fc1f408
Use facetName in all processors as themeType for legend aggregation.
gernotbelger
parents:
9398
diff
changeset
|
204 final XYSeries series = new StyledXYSeries(aaf.getFacetName(), aaf.getFacetDescription(), theme); |
9252 | 205 final int size = wqdays.size(); |
206 for (int i = 0; i < size; i++) { | |
9265 | 207 final int day = wqdays.getDay(i); |
9252 | 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"); | |
9556
9b8e8fc1f408
Use facetName in all processors as themeType for legend aggregation.
gernotbelger
parents:
9398
diff
changeset
|
217 final XYSeries series = new StyledXYSeries(aandf.getFacetName(), aandf.getFacetDescription(), theme); |
9252 | 218 series.add(point.getX(), point.getY()); |
219 addAxisSeries(series, YAXIS.W.idx, visible); | |
220 } | |
221 | |
222 /** | |
223 * Creates the series for a duration curve's Q facet. | |
224 * | |
9265 | 225 * @param wqdays |
226 * The WQDay store that contains the Qs. | |
9252 | 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"); | |
9556
9b8e8fc1f408
Use facetName in all processors as themeType for legend aggregation.
gernotbelger
parents:
9398
diff
changeset
|
232 final XYSeries series = new StyledXYSeries(aaf.getFacetName(), aaf.getFacetDescription(), theme); |
9252 | 233 final int size = wqdays.size(); |
234 for (int i = 0; i < size; i++) { | |
9265 | 235 final int day = wqdays.getDay(i); |
9252 | 236 final double q = wqdays.getQ(i); |
237 series.add(day, q); | |
238 } | |
239 addAxisSeries(series, YAXIS.Q.idx, visible); | |
240 } | |
241 | |
242 @Override | |
243 protected YAxisWalker getYAxisWalker() { | |
244 return new YAxisWalker() { | |
245 @Override | |
246 public int length() { | |
247 return YAXIS.values().length; | |
248 } | |
249 | |
250 @Override | |
251 public String getId(final int idx) { | |
252 final YAXIS[] yaxes = YAXIS.values(); | |
253 return yaxes[idx].toString(); | |
254 } | |
255 }; | |
256 } | |
257 | |
258 // MainValue-Annotations should be visualized by | |
259 // a line that goes to the curve itself. | |
9265 | 260 } |