Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/exports/ReferenceCurveGenerator.java @ 2407:dce0cc856357
'Bezugslinien': Added axis labels matching the displayed data.
flys-artifacts/trunk@4036 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Fri, 10 Feb 2012 16:00:57 +0000 |
parents | 1fcaeced48f2 |
children | 8e2ae8813a06 |
comparison
equal
deleted
inserted
replaced
2406:84cdde4bc482 | 2407:dce0cc856357 |
---|---|
1 package de.intevation.flys.exports; | 1 package de.intevation.flys.exports; |
2 | 2 |
3 import org.w3c.dom.Document; | 3 import org.w3c.dom.Document; |
4 | |
5 import java.awt.Font; | |
6 | 4 |
7 import org.apache.log4j.Logger; | 5 import org.apache.log4j.Logger; |
8 | 6 |
9 import org.jfree.chart.JFreeChart; | 7 import org.jfree.chart.JFreeChart; |
10 import org.jfree.chart.axis.NumberAxis; | 8 import org.jfree.chart.axis.NumberAxis; |
28 public class ReferenceCurveGenerator | 26 public class ReferenceCurveGenerator |
29 extends XYChartGenerator | 27 extends XYChartGenerator |
30 implements FacetTypes | 28 implements FacetTypes |
31 { | 29 { |
32 public static enum YAXIS { | 30 public static enum YAXIS { |
33 W_M(0), | 31 W(0); |
34 W_CM(1); | |
35 | 32 |
36 public int idx; | 33 public int idx; |
37 private YAXIS(int c) { | 34 private YAXIS(int c) { |
38 idx = c; | 35 idx = c; |
39 } | 36 } |
47 "chart.reference.curve.title"; | 44 "chart.reference.curve.title"; |
48 | 45 |
49 public static final String I18N_CHART_SUBTITLE = | 46 public static final String I18N_CHART_SUBTITLE = |
50 "chart.reference.curve.subtitle"; | 47 "chart.reference.curve.subtitle"; |
51 | 48 |
52 public static final String W_CM_DEFAULT = | 49 public static final String I18N_X_AXIS_IN_CM = |
53 "chart.reference.curve.wcm"; | 50 "chart.reference.curve.x.axis.in.cm"; |
54 | 51 |
55 public static final String W_NNM_DEFAULT = | 52 public static final String I18N_X_AXIS_IN_M = |
56 "chart.reference.curve.wnn"; | 53 "chart.reference.curve.x.axis.in.m"; |
57 | 54 |
58 public static final String START_GAUGE = | 55 public static final String I18N_Y_AXIS_IN_CM = |
59 "chart.reference.curve.start_at_gauge"; | 56 "chart.reference.curve.y.axis.in.cm"; |
60 | 57 |
61 public static final String START_FREE = | 58 public static final String I18N_Y_AXIS_IN_M = |
62 "chart.reference.curve.start_free"; | 59 "chart.reference.curve.y.axis.in.m"; |
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 | 60 |
81 public static final String I18N_CHART_TITLE_DEFAULT = | 61 public static final String I18N_CHART_TITLE_DEFAULT = |
82 "Bezugslinie"; | 62 "Bezugslinie"; |
83 | 63 |
84 | 64 |
85 public ReferenceCurveGenerator() { | 65 public ReferenceCurveGenerator() { |
86 super(); | 66 } |
87 } | |
88 | |
89 | 67 |
90 /** | 68 /** |
91 * Create Axis for given index. | 69 * Create Axis for given index. |
92 * @return axis with according internationalized label. | 70 * @return axis with according internationalized label. |
93 */ | 71 */ |
94 @Override | 72 @Override |
95 protected NumberAxis createYAxis(int index) { | 73 protected NumberAxis createYAxis(int index) { |
96 Font labelFont = new Font("Tahoma", Font.BOLD, 14); | 74 NumberAxis axis = super.createYAxis(index); |
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); | 75 axis.setAutoRangeIncludesZero(false); |
107 axis.setLabelFont(labelFont); | |
108 return axis; | 76 return axis; |
109 } | 77 } |
110 | 78 |
111 | 79 |
112 /** Get default chart title. */ | 80 /** Get default chart title. */ |
132 if (subtitle != null && subtitle.length() > 0) { | 100 if (subtitle != null && subtitle.length() > 0) { |
133 chart.addSubtitle(new TextTitle(subtitle)); | 101 chart.addSubtitle(new TextTitle(subtitle)); |
134 } | 102 } |
135 } | 103 } |
136 | 104 |
105 protected boolean getInCm(int index) { | |
106 Object obj = context.getContextValue("reference.curve.axis.scale"); | |
107 return obj instanceof WWAxisTypes && ((WWAxisTypes)obj).getInCm(index); | |
108 } | |
109 | |
137 | 110 |
138 /** Get Label for X-axis (W). */ | 111 /** Get Label for X-axis (W). */ |
139 @Override | 112 @Override |
140 protected String getDefaultXAxisLabel() { | 113 protected String getDefaultXAxisLabel() { |
141 // TODO i18nreturn msg(I18N_XAXIS_LABEL, I18N_XAXIS_LABEL_DEFAULT); | 114 return msg(getInCm(0) ? I18N_X_AXIS_IN_CM : I18N_X_AXIS_IN_M); |
142 // at_gauge + w_cm | |
143 return "W am Bezugsort- oder Pegel."; | |
144 } | 115 } |
145 | 116 |
146 | 117 |
147 /** | 118 /** |
148 * Get Label for primary and other Y Axes. | 119 * Get Label for primary and other Y Axes. |
149 * @param index Axis-Index (0-based). | 120 * @param index Axis-Index (0-based). |
150 */ | 121 */ |
151 @Override | 122 @Override |
152 protected String getDefaultYAxisLabel(int index) { | 123 protected String getDefaultYAxisLabel(int index) { |
153 String label = "default"; | 124 return msg(getInCm(1) ? I18N_Y_AXIS_IN_CM : I18N_Y_AXIS_IN_M); |
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 } | 125 } |
165 | 126 |
166 | 127 |
167 /** | 128 /** |
168 * Called for each facet/them in the out mapped to this generator. | 129 * Called for each facet/them in the out mapped to this generator. |
192 doPoints( | 153 doPoints( |
193 artifactFacet.getData(context), | 154 artifactFacet.getData(context), |
194 artifactFacet, | 155 artifactFacet, |
195 theme, | 156 theme, |
196 visible, | 157 visible, |
197 YAXIS.W_M.idx); | 158 YAXIS.W.idx); |
198 } | 159 } |
199 else { | 160 else { |
200 logger.warn("Unknown facet name: " + name); | 161 logger.warn("Unknown facet name: " + name); |
201 return; | |
202 } | 162 } |
203 } | 163 } |
204 | 164 |
205 | 165 |
206 /** Register DataSeries with (maybe transformed) points. */ | 166 /** Register DataSeries with (maybe transformed) points. */ |
227 while (iter.hasNext()) { | 187 while (iter.hasNext()) { |
228 iter.next(values); | 188 iter.next(values); |
229 series.add(values[0], values[1], false); | 189 series.add(values[0], values[1], false); |
230 } | 190 } |
231 | 191 |
232 if (ww.endAtGauge()) { | 192 addAxisSeries(series, YAXIS.W.idx, visible); |
233 addAxisSeries(series, YAXIS.W_M.idx, visible); | |
234 } | |
235 else { | |
236 addAxisSeries(series, YAXIS.W_CM.idx, visible); | |
237 } | |
238 } | 193 } |
239 | 194 |
240 | 195 |
241 /** Get Walker to iterate over all axes. */ | 196 /** Get Walker to iterate over all axes. */ |
242 @Override | 197 @Override |