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