comparison flys-artifacts/src/main/java/de/intevation/flys/exports/ChartGenerator.java @ 2233:958a10e2e246

Added a new ChartGenerator for timeseries charts and refactored some code in XYChartGenerator. flys-artifacts/trunk@3877 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 02 Feb 2012 12:26:36 +0000
parents 79a94c4171cb
children 46ec09c7f578
comparison
equal deleted inserted replaced
2232:78ac5058da67 2233:958a10e2e246
9 import org.apache.log4j.Logger; 9 import org.apache.log4j.Logger;
10 10
11 import org.w3c.dom.Document; 11 import org.w3c.dom.Document;
12 import org.w3c.dom.Element; 12 import org.w3c.dom.Element;
13 13
14 import org.jfree.chart.JFreeChart;
15 import org.jfree.chart.axis.NumberAxis;
14 import org.jfree.data.Range; 16 import org.jfree.data.Range;
15 17
16 import de.intevation.artifacts.Artifact; 18 import de.intevation.artifacts.Artifact;
17 import de.intevation.artifacts.CallContext; 19 import de.intevation.artifacts.CallContext;
18 import de.intevation.artifacts.CallMeta; 20 import de.intevation.artifacts.CallMeta;
79 81
80 /** The settings that should be used during output creation.*/ 82 /** The settings that should be used during output creation.*/
81 protected Settings settings; 83 protected Settings settings;
82 84
83 85
86 /**
87 * A mini interface that allows to walk over the YAXIS enums defined in
88 * subclasses.
89 */
90 public interface YAxisWalker {
91 int length();
92 String getId(int idx);
93 }
94
95
96 protected abstract YAxisWalker getYAxisWalker();
97
98 protected abstract String getDefaultChartTitle();
99
100 protected abstract String getDefaultXAxisLabel();
101
102 protected abstract String getDefaultYAxisLabel(int pos);
103
104 protected abstract void addSubtitles(JFreeChart chart);
105
106
84 public void init(Document request, OutputStream out, CallContext context) { 107 public void init(Document request, OutputStream out, CallContext context) {
85 logger.debug("ChartGenerator.init"); 108 logger.debug("ChartGenerator.init");
86 109
87 this.request = request; 110 this.request = request;
88 this.out = out; 111 this.out = out;
182 * @throws NullPointerException if <i>settings</i> is null. 205 * @throws NullPointerException if <i>settings</i> is null.
183 */ 206 */
184 public Integer getLegendFontSize(ChartSettings settings) { 207 public Integer getLegendFontSize(ChartSettings settings) {
185 LegendSection ls = settings.getLegendSection(); 208 LegendSection ls = settings.getLegendSection();
186 return ls != null ? ls.getFontSize() : null; 209 return ls != null ? ls.getFontSize() : null;
210 }
211
212
213 /**
214 * Returns the Y-Axis label of a chart at position <i>pos</i>.
215 *
216 * @return the Y-Axis label of a chart at position <i>0</i>.
217 */
218 protected String getYAxisLabel(int pos) {
219 ChartSettings chartSettings = getChartSettings();
220 if (chartSettings == null) {
221 return getDefaultYAxisLabel(pos);
222 }
223
224 YAxisWalker walker = getYAxisWalker();
225 AxisSection as = chartSettings.getAxisSection(walker.getId(pos));
226 if (as != null) {
227 String label = as.getLabel();
228
229 if (label != null) {
230 return label;
231 }
232 }
233
234 return getDefaultYAxisLabel(pos);
187 } 235 }
188 236
189 237
190 protected Locale getLocale() { 238 protected Locale getLocale() {
191 CallMeta meta = context.getMeta(); 239 CallMeta meta = context.getMeta();
404 return (ChartSettings) settings; 452 return (ChartSettings) settings;
405 } 453 }
406 454
407 return null; 455 return null;
408 } 456 }
457
458
459 /**
460 * Creates a new instance of <i>IdentifiableNumberAxis</i>.
461 *
462 * @param idx The index of the new axis.
463 * @param label The label of the new axis.
464 *
465 * @return an instance of IdentifiableNumberAxis.
466 */
467 protected NumberAxis createNumberAxis(int idx, String label) {
468 YAxisWalker walker = getYAxisWalker();
469
470 return new IdentifiableNumberAxis(walker.getId(idx), label);
471 }
409 } 472 }
410 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 473 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org