changeset 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 78ac5058da67
children 46ec09c7f578
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/exports/ChartGenerator.java flys-artifacts/src/main/java/de/intevation/flys/exports/HistoricalDischargeCurveGenerator.java flys-artifacts/src/main/java/de/intevation/flys/exports/TimeseriesChartGenerator.java flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java
diffstat 5 files changed, 110 insertions(+), 51 deletions(-) [+]
line wrap: on
line diff
--- 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 <ingo@intevation.de>
+
+	* 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 <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/charts/TimeseriesStepChart.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 <i>pos</i>.
+     *
+     * @return the Y-Axis label of a chart at position <i>0</i>.
+     */
+    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 <i>IdentifiableNumberAxis</i>.
+     *
+     * @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 :
--- 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 <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
  */
 public class HistoricalDischargeCurveGenerator
-extends      XYChartGenerator
+extends      TimeseriesChartGenerator
 implements   FacetTypes
 {
     private static Logger logger =
--- /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 <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+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 :
--- 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 <i>pos</i>.
-     *
-     * @return the Y-Axis label of a chart at position <i>0</i>.
-     */
-    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 <i>pos</i>.
      *
@@ -1486,21 +1451,6 @@
 
 
     /**
-     * Creates a new instance of <i>IdentifiableNumberAxis</i>.
-     *
-     * @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 <i>ChartSettings</i> with a chart specific section
      * but with no axes settings.
      *

http://dive4elements.wald.intevation.org