comparison flys-artifacts/src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java @ 1931:7c52e9cb2a72

Allow more than two datasets and more flexibility with axes in plots. Based on patch by S. Teichmann. flys-artifacts/trunk@3312 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Thu, 24 Nov 2011 07:20:46 +0000
parents 11c4b1429117
children 0ad05cb691fc
comparison
equal deleted inserted replaced
1930:de0c2bbb27f9 1931:7c52e9cb2a72
37 */ 37 */
38 public class LongitudinalSectionGenerator 38 public class LongitudinalSectionGenerator
39 extends XYChartGenerator 39 extends XYChartGenerator
40 implements FacetTypes 40 implements FacetTypes
41 { 41 {
42 public static enum YAXIS {
43 W(0),
44 Q(1),
45 D(2);
46 protected int idx;
47 private YAXIS(int c) {
48 idx = c;
49 }
50 }
51
42 /** The logger that is used in this generator. */ 52 /** The logger that is used in this generator. */
43 private static Logger logger = 53 private static Logger logger =
44 Logger.getLogger(LongitudinalSectionGenerator.class); 54 Logger.getLogger(LongitudinalSectionGenerator.class);
45 55
46 /** Key to look up internationalized String for annotations label. */ 56 /** Key to look up internationalized String for annotations label. */
159 new Object[] { unit }); 169 new Object[] { unit });
160 } 170 }
161 171
162 172
163 /** 173 /**
174 * Create Axis for given index.
175 * @return axis with according internationalized label.
176 */
177 @Override
178 protected NumberAxis createYAxis(int index) {
179 Font labelFont = new Font("Tahoma", Font.BOLD, 14);
180 String label = "default";
181 if (index == YAXIS.W.idx) {
182 label = getYAxisLabel();
183 }
184 else if (index == YAXIS.Q.idx) {
185 label = msg(get2YAxisLabelKey(), get2YAxisDefaultLabel());
186 }
187 else if (index == YAXIS.D.idx) {
188 // TODO: diff label
189 label = "TODO: diff";
190 }
191 NumberAxis axis = new NumberAxis(label);
192 axis.setLabelFont(labelFont);
193 return axis;
194 }
195
196 /**
164 * Get default value for the second Y-Axis' label (if no translation was 197 * Get default value for the second Y-Axis' label (if no translation was
165 * found). 198 * found).
166 */ 199 */
167 protected String get2YAxisDefaultLabel() { 200 protected String get2YAxisDefaultLabel() {
168 return I18N_2YAXIS_LABEL_DEFAULT; 201 return I18N_2YAXIS_LABEL_DEFAULT;
176 return I18N_2YAXIS_LABEL; 209 return I18N_2YAXIS_LABEL;
177 } 210 }
178 211
179 212
180 /** 213 /**
181 * Adjust the axis to meet LongitudinalSection diagram demands. 214 * Trigger inversion.
182 * (e.g. add second Y-axis with internationalized label, trigger
183 * inversion).
184 * @param see get2YAxisLabelKey, get2YAxisDefaultLabel
185 */ 215 */
186 @Override 216 @Override
187 protected void adjustAxes(XYPlot plot) { 217 protected void adjustAxes(XYPlot plot) {
188 super.adjustAxes(plot); 218 super.adjustAxes(plot);
189
190 NumberAxis qAxis = new NumberAxis(
191 msg(get2YAxisLabelKey(), get2YAxisDefaultLabel()));
192
193 plot.setRangeAxis(1, qAxis);
194
195 Font font = plot.getRangeAxis(0).getLabelFont();
196 qAxis.setLabelFont(font);
197
198 invertXAxis(plot.getDomainAxis()); 219 invertXAxis(plot.getDomainAxis());
199 } 220 }
200 221
201 222
202 /** 223 /**
319 340
320 XYSeries series = new StyledXYSeries(facet.getDescription(), theme); 341 XYSeries series = new StyledXYSeries(facet.getDescription(), theme);
321 342
322 StyledSeriesBuilder.addPoints(series, wkms); 343 StyledSeriesBuilder.addPoints(series, wkms);
323 344
324 addFirstAxisSeries(series, visible); 345 addAxisSeries(series, YAXIS.W.idx, visible);
325 346
326 if (wkms instanceof WQKms) { 347 if (wkms instanceof WQKms) {
327 if (needInvertAxis((WQKms) wkms)) { 348 if (needInvertAxis((WQKms) wkms)) {
328 setInverted(true); 349 setInverted(true);
329 } 350 }
357 } 378 }
358 } 379 }
359 380
360 StyledSeriesBuilder.addPoints(series, wkms); 381 StyledSeriesBuilder.addPoints(series, wkms);
361 382
362 addSecondAxisSeries(series, visible); 383 addAxisSeries(series, YAXIS.D.idx, visible);
363 if (DataUtil.guessWaterIncreasing(wkms.allWs())) { 384 if (DataUtil.guessWaterIncreasing(wkms.allWs())) {
364 setInverted(true); 385 setInverted(true);
365 } 386 }
366 } 387 }
367 388
387 408
388 XYSeries series = new StyledXYSeries(facet.getDescription(), theme); 409 XYSeries series = new StyledXYSeries(facet.getDescription(), theme);
389 410
390 StyledSeriesBuilder.addPoints(series, wqkms); 411 StyledSeriesBuilder.addPoints(series, wqkms);
391 412
392 addSecondAxisSeries(series, visible); 413 addAxisSeries(series, YAXIS.Q.idx, visible);
393 414
394 if (needInvertAxis(wqkms)) { 415 if (needInvertAxis(wqkms)) {
395 setInverted(true); 416 setInverted(true);
396 } 417 }
397 } 418 }

http://dive4elements.wald.intevation.org