diff artifacts/src/main/java/org/dive4elements/river/exports/DiagramGenerator.java @ 7068:726d998dce29 generator-refactoring

Remove Axis Walker, unabstract Diagram generator Diagram generator can now be used as an instance configured in the out-generators config
author Andre Heinecke <aheinecke@intevation.de>
date Fri, 20 Sep 2013 14:55:44 +0200
parents f9d5020af0af
children 7f600001c807
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/exports/DiagramGenerator.java	Fri Sep 20 14:54:26 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/DiagramGenerator.java	Fri Sep 20 14:55:44 2013 +0200
@@ -41,6 +41,7 @@
 
 import org.dive4elements.artifactdatabase.state.ArtifactAndFacet;
 import org.dive4elements.artifactdatabase.state.Facet;
+import org.dive4elements.river.artifacts.D4EArtifact;
 import org.dive4elements.river.exports.process.Processor;
 import org.dive4elements.river.jfree.AxisDataset;
 import org.dive4elements.river.jfree.AnnotationHelper;
@@ -71,11 +72,7 @@
  *   <li> There should always be a Y-Axis on the "left". </li>
  * </ul>
  */
-public abstract class DiagramGenerator extends ChartGenerator2 {
-
-    /** Enumerator over existing axes. */
-    @Override
-    protected abstract YAxisWalker getYAxisWalker();
+public class DiagramGenerator extends ChartGenerator2 {
 
     public static final int AXIS_SPACE = 5;
 
@@ -110,7 +107,6 @@
         diagramAttributes = new DiagramAttributes(config);
     }
 
-
     /**
      * Generate the chart anew (including localized axis and all).
      */
@@ -375,6 +371,15 @@
         logger.debug("...............");
     }
 
+    /**
+     * Registers an area to be drawn.
+     * @param area Area to be drawn.
+     * @param axisName Name of the axis.
+     * @param visible Whether or not to be visible (important for range calculations).
+     */
+    public void addAreaSeries(StyledAreaSeriesCollection area, String axisName, boolean visible) {
+        addAreaSeries(area, diagramAttributes.getAxisIndex(axisName), visible);
+    }
 
     /**
      * Registers an area to be drawn.
@@ -399,13 +404,12 @@
         }
     }
 
-
     /**
      * Add given series if visible, if not visible adjust ranges (such that
      * all points in data would be plotted once visible).
-     * @param series the data series to include in plot.
-     * @param index  ('symbolic') index of the series and of its axis.
-     * @param visible whether or not the data should be plotted.
+     * @param series   the data series to include in plot.
+     * @param index    index of the axis.
+     * @param visible  whether or not the data should be plotted.
      */
     public void addAxisSeries(XYSeries series, int index, boolean visible) {
         if (series == null) {
@@ -416,8 +420,17 @@
             series.getMinY() + " | " + series.getMaxY());
 
         addAxisDataset(new XYSeriesCollection(series), index, visible);
+    }
 
-        AxisDataset axisDataset = (AxisDataset) getAxisDataset(index);
+    /**
+     * Add given series if visible, if not visible adjust ranges (such that
+     * all points in data would be plotted once visible).
+     * @param series   the data series to include in plot.
+     * @param axisName name of the axis.
+     * @param visible  whether or not the data should be plotted.
+     */
+    public void addAxisSeries(XYSeries series, String axisName, boolean visible) {
+        addAxisSeries(series, diagramAttributes.getAxisIndex(axisName), visible);
     }
 
 
@@ -981,6 +994,93 @@
         this.inverted = inverted;
     }
 
+    @Override
+    public String getDefaultChartTitle() {
+        DiagramAttributes.Title dTitle = diagramAttributes.getTitle();
+        if (dTitle == null) {
+            return "Title not configured in conf.xml";
+        }
+
+        return dTitle.evaluate((D4EArtifact)getMaster(), context);
+    }
+
+    @Override
+    public String getDefaultChartSubtitle() {
+        DiagramAttributes.Title dTitle = diagramAttributes.getSubtitle();
+        if (dTitle == null) {
+            return "Subtitle not configured in conf.xml";
+        }
+
+        return dTitle.evaluate((D4EArtifact)getMaster(), context);
+    }
+
+    /**
+     * Get internationalized label for the x axis.
+     */
+    @Override
+    protected String getDefaultXAxisLabel() {
+        return "TODO X axis label";
+/*        D4EArtifact flys = (D4EArtifact) master;
+
+        return msg(
+            I18N_XAXIS_LABEL,
+            I18N_XAXIS_LABEL_DEFAULT,
+            new Object[] { RiverUtils.getRiver(flys).getName() }); */
+    }
+
+    @Override
+    protected String getDefaultYAxisLabel(int index) {
+        return "TODO Y Axis label";
+/*        String label = "default";
+
+        if (index == YAXIS.W.idx) {
+            label = getWAxisLabel();
+        }
+        else if (index == YAXIS.Q.idx) {
+            label = msg(getQAxisLabelKey(), getQAxisDefaultLabel());
+        }
+        else if (index == YAXIS.D.idx) {
+            label = msg(I18N_WDIFF_YAXIS_LABEL, I18N_WDIFF_YAXIS_LABEL_DEFAULT);
+        }
+
+        return label;*/
+    }
+
+
+    /**
+     * Creates a list of Section for the chart's Y axes.
+     *
+     * @return a list of Y axis sections.
+     */
+    protected List<AxisSection> buildYAxisSections() {
+        List<AxisSection> axisSections = new ArrayList<AxisSection>();
+
+        List<DiagramAttributes.AxisAttributes> axesAttrs = diagramAttributes.getAxesAttributes();
+
+        for (int i = 0, n = axesAttrs.size(); i < n; i++) {
+            AxisSection ySection = new AxisSection();
+            ySection.setIdentifier(diagramAttributes.getAxisName(i));
+            ySection.setLabel(getYAxisLabel(i));
+            ySection.setFontSize(14);
+            ySection.setFixed(false);
+
+            // XXX We are able to find better default ranges that [0,0], the
+            // only problem is, that we do NOT have a better range than [0,0]
+            // for each axis, because the initial chart will not have a dataset
+            // for each axis set!
+            ySection.setUpperRange(0d);
+            ySection.setLowerRange(0d);
+
+            axisSections.add(ySection);
+        }
+
+        return axisSections;
+    }
+
+    protected String axisIndexToName(int index) {
+        return diagramAttributes.getAxisName(index);
+    }
+
     /** Add the acutal data to the diagram according to the processors.
      * For every outable facets, this function is
      * called and handles the data accordingly. */
@@ -1004,7 +1104,7 @@
 
         for (Processor pr: diagramAttributes.getProcessors()) {
             if (pr.canHandle(facetName)) {
-//                pr.doOut(this, bundle, theme, visible, 0);
+                pr.doOut(this, bundle, theme, visible);
             }
         }
     }

http://dive4elements.wald.intevation.org