Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/org/dive4elements/river/exports/ReferenceCurveGenerator.java @ 5831:bd047b71ab37
Repaired internal references
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 25 Apr 2013 12:06:39 +0200 |
parents | flys-artifacts/src/main/java/de/intevation/flys/exports/ReferenceCurveGenerator.java@5b8919ef601d |
children |
comparison
equal
deleted
inserted
replaced
5830:160f53ee0870 | 5831:bd047b71ab37 |
---|---|
1 package org.dive4elements.river.exports; | |
2 | |
3 import org.dive4elements.artifactdatabase.state.ArtifactAndFacet; | |
4 import org.dive4elements.river.artifacts.model.FacetTypes; | |
5 import org.dive4elements.river.artifacts.model.WW; | |
6 import org.dive4elements.river.artifacts.model.WW.ApplyFunctionIterator; | |
7 import org.dive4elements.river.artifacts.model.WWAxisTypes; | |
8 import org.dive4elements.river.jfree.FLYSAnnotation; | |
9 import org.dive4elements.river.jfree.StyledXYSeries; | |
10 import org.dive4elements.river.utils.Formatter; | |
11 | |
12 import java.awt.geom.Point2D; | |
13 | |
14 import org.apache.log4j.Logger; | |
15 import org.jfree.chart.axis.NumberAxis; | |
16 import org.jfree.chart.axis.NumberTickUnit; | |
17 import org.jfree.chart.axis.TickUnits; | |
18 import org.jfree.chart.axis.ValueAxis; | |
19 import org.jfree.data.xy.XYSeries; | |
20 import org.w3c.dom.Document; | |
21 | |
22 /** | |
23 * An OutGenerator that generates reference curves. | |
24 */ | |
25 public class ReferenceCurveGenerator | |
26 extends XYChartGenerator | |
27 implements FacetTypes | |
28 { | |
29 public static enum YAXIS { | |
30 W(0); | |
31 | |
32 public int idx; | |
33 private YAXIS(int c) { | |
34 idx = c; | |
35 } | |
36 } | |
37 | |
38 /** House logger. */ | |
39 private static Logger logger = | |
40 Logger.getLogger(ReferenceCurveGenerator.class); | |
41 | |
42 public static final String I18N_CHART_TITLE = | |
43 "chart.reference.curve.title"; | |
44 | |
45 public static final String I18N_CHART_SUBTITLE = | |
46 "chart.reference.curve.subtitle"; | |
47 | |
48 public static final String I18N_X_AXIS_IN_CM = | |
49 "chart.reference.curve.x.axis.in.cm"; | |
50 | |
51 public static final String I18N_X_AXIS_IN_M = | |
52 "chart.reference.curve.x.axis.in.m"; | |
53 | |
54 public static final String I18N_Y_AXIS_IN_CM = | |
55 "chart.reference.curve.y.axis.in.cm"; | |
56 | |
57 public static final String I18N_Y_AXIS_IN_M = | |
58 "chart.reference.curve.y.axis.in.m"; | |
59 | |
60 public static final String I18N_CHART_TITLE_DEFAULT = | |
61 "Bezugslinie"; | |
62 | |
63 | |
64 public ReferenceCurveGenerator() { | |
65 } | |
66 | |
67 /** | |
68 * Create Axis for given index. | |
69 * @return axis with according internationalized label. | |
70 */ | |
71 @Override | |
72 protected NumberAxis createYAxis(int index) { | |
73 NumberAxis axis = super.createYAxis(index); | |
74 axis.setAutoRangeIncludesZero(false); | |
75 return axis; | |
76 } | |
77 | |
78 | |
79 /** Get default chart title. */ | |
80 @Override | |
81 protected String getDefaultChartTitle() { | |
82 return msg(I18N_CHART_TITLE, I18N_CHART_TITLE_DEFAULT); | |
83 } | |
84 | |
85 @Override | |
86 protected String getDefaultChartSubtitle() { | |
87 Object[] args = new Object[] { | |
88 getRiverName(), | |
89 }; | |
90 | |
91 return msg(I18N_CHART_SUBTITLE, "", args); | |
92 } | |
93 | |
94 | |
95 /** True if axis is in cm (because at gauge). */ | |
96 protected boolean getInCm(int index) { | |
97 Object obj = context.getContextValue("reference.curve.axis.scale"); | |
98 return obj instanceof WWAxisTypes && ((WWAxisTypes)obj).getInCm(index); | |
99 } | |
100 | |
101 | |
102 /** Get Label for X-axis (W). */ | |
103 @Override | |
104 protected String getDefaultXAxisLabel() { | |
105 return msg(getInCm(0) ? I18N_X_AXIS_IN_CM : I18N_X_AXIS_IN_M); | |
106 } | |
107 | |
108 | |
109 /** | |
110 * Get Label for primary and other Y Axes. | |
111 * @param index Axis-Index (0-based). | |
112 */ | |
113 @Override | |
114 protected String getDefaultYAxisLabel(int index) { | |
115 return msg(getInCm(1) ? I18N_Y_AXIS_IN_CM : I18N_Y_AXIS_IN_M); | |
116 } | |
117 | |
118 protected String facetName() { | |
119 return REFERENCE_CURVE; | |
120 } | |
121 | |
122 | |
123 /** | |
124 * Called for each facet/them in the out mapped to this generator. | |
125 * @param artifactFacet artifact and facet for this theme. | |
126 * @param theme styling info. | |
127 * @param visible Whether or not the theme is visible. | |
128 */ | |
129 @Override | |
130 public void doOut( | |
131 ArtifactAndFacet artifactFacet, | |
132 Document theme, | |
133 boolean visible | |
134 ) { | |
135 String name = artifactFacet.getFacetName(); | |
136 | |
137 logger.debug("ReferenceCurveGenerator.doOut: " + name); | |
138 | |
139 if (name == null || name.length() == 0) { | |
140 logger.error("No facet given. Cannot create dataset."); | |
141 return; | |
142 } | |
143 | |
144 if (name.equals(facetName())) { | |
145 doReferenceOut(artifactFacet.getData(context), theme, visible); | |
146 } | |
147 else if (FacetTypes.IS.MANUALPOINTS(name)) { | |
148 doPoints( | |
149 artifactFacet.getData(context), | |
150 artifactFacet, | |
151 theme, | |
152 visible, | |
153 YAXIS.W.idx); | |
154 } | |
155 else if (name.equals(RELATIVE_POINT)) { | |
156 doPointOut( | |
157 (Point2D) artifactFacet.getData(context), | |
158 artifactFacet, | |
159 theme, | |
160 visible); | |
161 } | |
162 else if (name.equals(MAINVALUES_W)) { | |
163 doAnnotations( | |
164 ((FLYSAnnotation) artifactFacet.getData(context)).flipStickyAxis(), | |
165 artifactFacet, | |
166 theme, | |
167 visible); | |
168 | |
169 } | |
170 else { | |
171 logger.warn("Unknown facet name: " + name); | |
172 } | |
173 } | |
174 | |
175 protected boolean doNormalize() { | |
176 return false; | |
177 } | |
178 | |
179 | |
180 /** Register DataSeries with (maybe transformed) points. */ | |
181 public void doReferenceOut( | |
182 Object data, | |
183 Document theme, | |
184 boolean visible | |
185 ) { | |
186 WW ww = (WW)data; | |
187 | |
188 Object obj = context.getContextValue("reference.curve.axis.scale"); | |
189 | |
190 WWAxisTypes wwat = obj instanceof WWAxisTypes | |
191 ? (WWAxisTypes)obj | |
192 : new WWAxisTypes(ww); | |
193 | |
194 ApplyFunctionIterator iter = wwat.transform(ww, doNormalize()); | |
195 | |
196 XYSeries series = new StyledXYSeries( | |
197 ww.getName(), false, theme); | |
198 | |
199 double [] values = new double[2]; | |
200 | |
201 while (iter.hasNext()) { | |
202 iter.next(values); | |
203 series.add(values[0], values[1], false); | |
204 } | |
205 | |
206 addAxisSeries(series, YAXIS.W.idx, visible); | |
207 } | |
208 | |
209 // TODO resolve duplicate in DurationCurveGenerator | |
210 protected void doPointOut( | |
211 Point2D point, | |
212 ArtifactAndFacet aandf, | |
213 Document theme, | |
214 boolean visible | |
215 ){ | |
216 logger.debug("ReferenceCurveGenerator.doPointOut"); | |
217 | |
218 XYSeries series = new StyledXYSeries(aandf.getFacetDescription(), theme); | |
219 | |
220 series.add(point.getX(), point.getY()); | |
221 | |
222 addAxisSeries(series, YAXIS.W.idx, visible); | |
223 } | |
224 | |
225 | |
226 /** Set the tick units for given axis. */ | |
227 protected void setAxisTickUnit(double tick, ValueAxis axis) { | |
228 TickUnits units = new TickUnits(); | |
229 units.add(new NumberTickUnit(tick, Formatter.getWaterlevelW(context))); | |
230 axis.setStandardTickUnits(units); | |
231 axis.setAutoTickUnitSelection(true); | |
232 } | |
233 | |
234 @Override | |
235 protected void localizeDomainAxis(ValueAxis domainAxis) { | |
236 super.localizeDomainAxis(domainAxis); | |
237 if (getInCm(0)) { | |
238 setAxisTickUnit(100d, domainAxis); | |
239 } | |
240 else { | |
241 setAxisTickUnit(1d, domainAxis); | |
242 } | |
243 } | |
244 | |
245 | |
246 @Override | |
247 protected void localizeRangeAxis(ValueAxis rangeAxis) { | |
248 super.localizeRangeAxis(rangeAxis); | |
249 setAxisTickUnit(1d, rangeAxis); | |
250 } | |
251 | |
252 /** Get Walker to iterate over all axes. */ | |
253 @Override | |
254 protected YAxisWalker getYAxisWalker() { | |
255 return new YAxisWalker() { | |
256 /** Get number of items. */ | |
257 @Override | |
258 public int length() { | |
259 return YAXIS.values().length; | |
260 } | |
261 | |
262 /** Get identifier for this index. */ | |
263 @Override | |
264 public String getId(int idx) { | |
265 YAXIS[] yaxes = YAXIS.values(); | |
266 return yaxes[idx].toString(); | |
267 } | |
268 }; | |
269 } | |
270 } | |
271 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |