# HG changeset patch # User Ingo Weinzierl # Date 1328185596 0 # Node ID 958a10e2e246556c97e91bb051d765d9a6d9df16 # Parent 78ac5058da677e508cda66e2bb58876bfb37266e Added a new ChartGenerator for timeseries charts and refactored some code in XYChartGenerator. flys-artifacts/trunk@3877 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 78ac5058da67 -r 958a10e2e246 flys-artifacts/ChangeLog --- a/flys-artifacts/ChangeLog Thu Feb 02 11:57:38 2012 +0000 +++ b/flys-artifacts/ChangeLog Thu Feb 02 12:26:36 2012 +0000 @@ -1,3 +1,17 @@ +2012-02-02 Ingo Weinzierl + + * src/main/java/de/intevation/flys/exports/TimeseriesChartGenerator.java: + New. This ChartGenerator should be used for timeseries charts. Currently, + this class is a stub only! WORK IS IN PROGRESS! + + * src/main/java/de/intevation/flys/exports/HistoricalDischargeCurveGenerator.java: + Subclasses TimeseriesChartGenerator now instead of XYChartGenerator, + because historical discharge curve charts will have a time x axis set. + + * src/main/java/de/intevation/flys/exports/XYChartGenerator.java, + src/main/java/de/intevation/flys/exports/ChartGenerator.java: Moved some + basic stuff from XYChartGenerator into ChartGenerator. + 2012-02-02 Ingo Weinzierl * src/main/java/de/intevation/flys/artifacts/charts/TimeseriesStepChart.java: diff -r 78ac5058da67 -r 958a10e2e246 flys-artifacts/src/main/java/de/intevation/flys/exports/ChartGenerator.java --- a/flys-artifacts/src/main/java/de/intevation/flys/exports/ChartGenerator.java Thu Feb 02 11:57:38 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/ChartGenerator.java Thu Feb 02 12:26:36 2012 +0000 @@ -11,6 +11,8 @@ import org.w3c.dom.Document; import org.w3c.dom.Element; +import org.jfree.chart.JFreeChart; +import org.jfree.chart.axis.NumberAxis; import org.jfree.data.Range; import de.intevation.artifacts.Artifact; @@ -81,6 +83,27 @@ protected Settings settings; + /** + * A mini interface that allows to walk over the YAXIS enums defined in + * subclasses. + */ + public interface YAxisWalker { + int length(); + String getId(int idx); + } + + + protected abstract YAxisWalker getYAxisWalker(); + + protected abstract String getDefaultChartTitle(); + + protected abstract String getDefaultXAxisLabel(); + + protected abstract String getDefaultYAxisLabel(int pos); + + protected abstract void addSubtitles(JFreeChart chart); + + public void init(Document request, OutputStream out, CallContext context) { logger.debug("ChartGenerator.init"); @@ -187,6 +210,31 @@ } + /** + * Returns the Y-Axis label of a chart at position pos. + * + * @return the Y-Axis label of a chart at position 0. + */ + protected String getYAxisLabel(int pos) { + ChartSettings chartSettings = getChartSettings(); + if (chartSettings == null) { + return getDefaultYAxisLabel(pos); + } + + YAxisWalker walker = getYAxisWalker(); + AxisSection as = chartSettings.getAxisSection(walker.getId(pos)); + if (as != null) { + String label = as.getLabel(); + + if (label != null) { + return label; + } + } + + return getDefaultYAxisLabel(pos); + } + + protected Locale getLocale() { CallMeta meta = context.getMeta(); PreferredLocale[] prefs = meta.getLanguages(); @@ -406,5 +454,20 @@ return null; } + + + /** + * Creates a new instance of IdentifiableNumberAxis. + * + * @param idx The index of the new axis. + * @param label The label of the new axis. + * + * @return an instance of IdentifiableNumberAxis. + */ + protected NumberAxis createNumberAxis(int idx, String label) { + YAxisWalker walker = getYAxisWalker(); + + return new IdentifiableNumberAxis(walker.getId(idx), label); + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 78ac5058da67 -r 958a10e2e246 flys-artifacts/src/main/java/de/intevation/flys/exports/HistoricalDischargeCurveGenerator.java --- a/flys-artifacts/src/main/java/de/intevation/flys/exports/HistoricalDischargeCurveGenerator.java Thu Feb 02 11:57:38 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/HistoricalDischargeCurveGenerator.java Thu Feb 02 12:26:36 2012 +0000 @@ -19,7 +19,7 @@ * @author Ingo Weinzierl */ public class HistoricalDischargeCurveGenerator -extends XYChartGenerator +extends TimeseriesChartGenerator implements FacetTypes { private static Logger logger = diff -r 78ac5058da67 -r 958a10e2e246 flys-artifacts/src/main/java/de/intevation/flys/exports/TimeseriesChartGenerator.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/TimeseriesChartGenerator.java Thu Feb 02 12:26:36 2012 +0000 @@ -0,0 +1,32 @@ +package de.intevation.flys.exports; + +import java.io.IOException; + +import org.apache.log4j.Logger; + +import org.jfree.chart.JFreeChart; +import org.jfree.chart.axis.NumberAxis; + + +/** + * @author Ingo Weinzierl + */ +public abstract class TimeseriesChartGenerator extends ChartGenerator { + + private static final Logger logger = + Logger.getLogger(TimeseriesChartGenerator.class); + + + protected abstract NumberAxis createYAxis(int index); + + + @Override + public void generate() + throws IOException + { + logger.info("Generate Timeseries Chart."); + + logger.warn("TODO: IMPLEMENT ME!"); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 78ac5058da67 -r 958a10e2e246 flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java --- a/flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java Thu Feb 02 11:57:38 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java Thu Feb 02 12:26:36 2012 +0000 @@ -155,16 +155,6 @@ } // class AxisDataset - /** - * A mini interface that allows to walk over the YAXIS enums defined in - * subclasses. - */ - public interface YAxisWalker { - int length(); - String getId(int idx); - } - - /** Override to make axis information available. */ protected YAxisWalker getYAxisWalker() { return new YAxisWalker() { @@ -346,31 +336,6 @@ /** - * Returns the Y-Axis label of a chart at position pos. - * - * @return the Y-Axis label of a chart at position 0. - */ - protected String getYAxisLabel(int pos) { - ChartSettings chartSettings = getChartSettings(); - if (chartSettings == null) { - return getDefaultYAxisLabel(pos); - } - - YAxisWalker walker = getYAxisWalker(); - AxisSection as = chartSettings.getAxisSection(walker.getId(pos)); - if (as != null) { - String label = as.getLabel(); - - if (label != null) { - return label; - } - } - - return getDefaultYAxisLabel(pos); - } - - - /** * This method is called to retrieve the default label for an Y axis at * position pos. * @@ -1486,21 +1451,6 @@ /** - * Creates a new instance of IdentifiableNumberAxis. - * - * @param idx The index of the new axis. - * @param label The label of the new axis. - * - * @return an instance of IdentifiableNumberAxis. - */ - protected NumberAxis createNumberAxis(int idx, String label) { - YAxisWalker walker = getYAxisWalker(); - - return new IdentifiableNumberAxis(walker.getId(idx), label); - } - - - /** * Returns an instance of ChartSettings with a chart specific section * but with no axes settings. *