Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/exports/NormalizedReferenceCurveGenerator.java @ 2408:8e2ae8813a06
'Bezugslinien': normalized reference curve is now derived from reference curve.
flys-artifacts/trunk@4037 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Fri, 10 Feb 2012 16:25:27 +0000 |
parents | 1fcaeced48f2 |
children | 3dc26ec2558d |
comparison
equal
deleted
inserted
replaced
2407:dce0cc856357 | 2408:8e2ae8813a06 |
---|---|
1 package de.intevation.flys.exports; | 1 package de.intevation.flys.exports; |
2 | 2 |
3 import org.w3c.dom.Document; | |
4 | |
5 import java.awt.Font; | |
6 | |
7 import org.apache.log4j.Logger; | 3 import org.apache.log4j.Logger; |
8 | |
9 import org.jfree.chart.JFreeChart; | |
10 import org.jfree.chart.axis.NumberAxis; | |
11 import org.jfree.chart.title.TextTitle; | |
12 | |
13 import org.jfree.data.xy.XYSeries; | |
14 | |
15 import de.intevation.artifactdatabase.state.ArtifactAndFacet; | |
16 | |
17 import de.intevation.flys.artifacts.model.FacetTypes; | |
18 import de.intevation.flys.artifacts.model.WW; | |
19 import de.intevation.flys.artifacts.model.WW.ApplyFunctionIterator; | |
20 import de.intevation.flys.artifacts.model.WWAxisTypes; | |
21 | |
22 import de.intevation.flys.jfree.StyledXYSeries; | |
23 | |
24 | 4 |
25 /** | 5 /** |
26 * An OutGenerator that generates reference curves. | 6 * An OutGenerator that generates reference curves. |
27 */ | 7 */ |
28 public class NormalizedReferenceCurveGenerator | 8 public class NormalizedReferenceCurveGenerator |
29 extends XYChartGenerator | 9 extends ReferenceCurveGenerator |
30 implements FacetTypes | |
31 { | 10 { |
32 public static enum YAXIS { | |
33 W_M(0), | |
34 W_CM(1); | |
35 | |
36 public int idx; | |
37 private YAXIS(int c) { | |
38 idx = c; | |
39 } | |
40 } | |
41 | |
42 /** House logger. */ | 11 /** House logger. */ |
43 private static Logger logger = | 12 private static Logger logger = |
44 Logger.getLogger(NormalizedReferenceCurveGenerator.class); | 13 Logger.getLogger(NormalizedReferenceCurveGenerator.class); |
45 | 14 |
46 public static final String I18N_CHART_TITLE = | 15 public static final String I18N_NORMALIZED_CHART_TITLE = |
47 "chart.reference.curve.title"; | 16 "chart.normalized.reference.curve.title"; |
48 | 17 |
49 public static final String I18N_CHART_SUBTITLE = | 18 public static final String I18N_NORMALIZED_CHART_TITLE_DEFAULT = |
50 "chart.reference.curve.subtitle"; | 19 "Reduzierte Bezugslinie"; |
51 | |
52 public static final String W_CM_DEFAULT = | |
53 "chart.reference.curve.wcm"; | |
54 | |
55 public static final String W_NNM_DEFAULT = | |
56 "chart.reference.curve.wnn"; | |
57 | |
58 public static final String START_GAUGE = | |
59 "chart.reference.curve.start_at_gauge"; | |
60 | |
61 public static final String START_FREE = | |
62 "chart.reference.curve.start_free"; | |
63 | |
64 /* | |
65 | |
66 public static final String I18N_XAXIS_LABEL = | |
67 "chart.reference.curve.xaxis.label"; | |
68 | |
69 public static final String I18N_YAXIS_LABEL = | |
70 "chart.reference.curve.yaxis.label"; | |
71 */ | |
72 /* | |
73 public static final String I18N_XAXIS_LABEL_DEFAULT = | |
74 "W [NN + m]"; | |
75 | |
76 public static final String I18N_YAXIS_LABEL_DEFAULT = | |
77 "W [NN + m]"; | |
78 */ | |
79 | |
80 | |
81 public static final String I18N_CHART_TITLE_DEFAULT = | |
82 "Bezugslinie"; | |
83 | |
84 | 20 |
85 public NormalizedReferenceCurveGenerator() { | 21 public NormalizedReferenceCurveGenerator() { |
86 super(); | |
87 } | 22 } |
88 | |
89 | |
90 /** | |
91 * Create Axis for given index. | |
92 * @return axis with according internationalized label. | |
93 */ | |
94 @Override | |
95 protected NumberAxis createYAxis(int index) { | |
96 Font labelFont = new Font("Tahoma", Font.BOLD, 14); | |
97 String label = getYAxisLabel(index); | |
98 | |
99 NumberAxis axis = createNumberAxis(index, label); | |
100 // TODO aspect-ratio settings. | |
101 /* | |
102 if (index == YAXIS.W_M.idx) { | |
103 axis.setAutoRangeIncludesZero(false); | |
104 } | |
105 */ | |
106 axis.setAutoRangeIncludesZero(false); | |
107 axis.setLabelFont(labelFont); | |
108 return axis; | |
109 } | |
110 | |
111 | 23 |
112 /** Get default chart title. */ | 24 /** Get default chart title. */ |
113 @Override | 25 @Override |
114 protected String getDefaultChartTitle() { | 26 protected String getDefaultChartTitle() { |
115 return msg(I18N_CHART_TITLE, I18N_CHART_TITLE_DEFAULT); | 27 return msg( |
28 I18N_NORMALIZED_CHART_TITLE, | |
29 I18N_NORMALIZED_CHART_TITLE_DEFAULT); | |
116 } | 30 } |
117 | 31 |
118 @Override | 32 @Override |
119 protected String getDefaultChartSubtitle() { | 33 protected String facetName() { |
120 Object[] args = new Object[] { | 34 return REFERENCE_CURVE_NORMALIZED; |
121 getRiverName(), | |
122 }; | |
123 | |
124 return msg(I18N_CHART_SUBTITLE, "", args); | |
125 } | 35 } |
126 | 36 |
127 | |
128 @Override | 37 @Override |
129 protected void addSubtitles(JFreeChart chart) { | 38 protected boolean doNormalize() { |
130 String subtitle = getChartSubtitle(); | 39 return true; |
131 | |
132 if (subtitle != null && subtitle.length() > 0) { | |
133 chart.addSubtitle(new TextTitle(subtitle)); | |
134 } | |
135 } | |
136 | |
137 | |
138 /** Get Label for X-axis (W). */ | |
139 @Override | |
140 protected String getDefaultXAxisLabel() { | |
141 // TODO i18nreturn msg(I18N_XAXIS_LABEL, I18N_XAXIS_LABEL_DEFAULT); | |
142 // at_gauge + w_cm | |
143 return "W am Bezugsort- oder Pegel."; | |
144 } | |
145 | |
146 | |
147 /** | |
148 * Get Label for primary and other Y Axes. | |
149 * @param index Axis-Index (0-based). | |
150 */ | |
151 @Override | |
152 protected String getDefaultYAxisLabel(int index) { | |
153 String label = "default"; | |
154 if (index == YAXIS.W_M.idx) { | |
155 //label = msg(I18N_YAXIS_LABEL, I18N_YAXIS_LABEL_DEFAULT); | |
156 //TODO i18n | |
157 return "W am Zielort"; | |
158 } | |
159 else if (index == YAXIS.W_CM.idx) { | |
160 return "W am Zielpegel"; | |
161 } | |
162 | |
163 return label; | |
164 } | |
165 | |
166 | |
167 /** | |
168 * Called for each facet/them in the out mapped to this generator. | |
169 * @param artifactFacet artifact and facet for this theme. | |
170 * @param theme styling info. | |
171 * @param visible Whether or not the theme is visible. | |
172 */ | |
173 @Override | |
174 public void doOut( | |
175 ArtifactAndFacet artifactFacet, | |
176 Document theme, | |
177 boolean visible | |
178 ) { | |
179 String name = artifactFacet.getFacetName(); | |
180 | |
181 logger.debug("NormalizedReferenceCurveGenerator.doOut: " + name); | |
182 | |
183 if (name == null || name.length() == 0) { | |
184 logger.error("No facet given. Cannot create dataset."); | |
185 return; | |
186 } | |
187 | |
188 if (name.equals(REFERENCE_CURVE_NORMALIZED)) { | |
189 doReferenceOut(artifactFacet.getData(context), theme, visible); | |
190 } | |
191 else if (FacetTypes.IS.MANUALPOINTS(name)) { | |
192 doPoints( | |
193 artifactFacet.getData(context), | |
194 artifactFacet, | |
195 theme, | |
196 visible, YAXIS.W_M.idx); | |
197 } | |
198 else { | |
199 logger.warn("Unknown facet name: " + name); | |
200 return; | |
201 } | |
202 } | |
203 | |
204 | |
205 /** Register DataSeries with (maybe transformed) points. */ | |
206 public void doReferenceOut( | |
207 Object data, | |
208 Document theme, | |
209 boolean visible | |
210 ) { | |
211 WW ww = (WW)data; | |
212 | |
213 Object obj = context.getContextValue("reference.curve.axis.scale"); | |
214 | |
215 WWAxisTypes wwat = obj instanceof WWAxisTypes | |
216 ? (WWAxisTypes)obj | |
217 : new WWAxisTypes(ww); | |
218 | |
219 ApplyFunctionIterator iter = wwat.transform(ww, true); | |
220 | |
221 XYSeries series = new StyledXYSeries( | |
222 ww.getName(), false, theme); | |
223 | |
224 double [] values = new double[2]; | |
225 | |
226 while (iter.hasNext()) { | |
227 iter.next(values); | |
228 series.add(values[0], values[1], false); | |
229 } | |
230 | |
231 if (ww.endAtGauge()) { | |
232 addAxisSeries(series, YAXIS.W_M.idx, visible); | |
233 } | |
234 else { | |
235 addAxisSeries(series, YAXIS.W_CM.idx, visible); | |
236 } | |
237 } | |
238 | |
239 | |
240 /** Get Walker to iterate over all axes. */ | |
241 @Override | |
242 protected YAxisWalker getYAxisWalker() { | |
243 return new YAxisWalker() { | |
244 /** Get number of items. */ | |
245 @Override | |
246 public int length() { | |
247 return YAXIS.values().length; | |
248 } | |
249 | |
250 /** Get identifier for this index. */ | |
251 @Override | |
252 public String getId(int idx) { | |
253 YAXIS[] yaxes = YAXIS.values(); | |
254 return yaxes[idx].toString(); | |
255 } | |
256 }; | |
257 } | 40 } |
258 } | 41 } |
259 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | 42 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |