changeset 1812:dd084cf3f284

Refactored to allow mainvalues in discharge curve diagrams, too. flys-artifacts/trunk@3141 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Wed, 02 Nov 2011 12:12:48 +0000
parents 4ee833095e75
children b3a67d946568
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/exports/ComputedDischargeCurveGenerator.java flys-artifacts/src/main/java/de/intevation/flys/exports/DischargeCurveGenerator.java flys-artifacts/src/main/java/de/intevation/flys/exports/StyledSeriesBuilder.java
diffstat 4 files changed, 128 insertions(+), 57 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Wed Nov 02 11:30:26 2011 +0000
+++ b/flys-artifacts/ChangeLog	Wed Nov 02 12:12:48 2011 +0000
@@ -1,3 +1,17 @@
+2011-11-02	Felix Wolfsteller	<felix.wolfsteller@intevation.de>
+
+	Refactoring to allow mainvalues in both discharge and computed
+	discharge curve diagrams.
+
+	* src/main/java/de/intevation/flys/exports/StyledSeriesBuilder.java
+	(addPointsQW): New helper function.
+
+	* src/main/java/de/intevation/flys/exports/DischargeCurveGenerator.java,
+	  src/main/java/de/intevation/flys/exports/ComputedDischargeCurveGenerator.java:
+	  Moved doMainValueQAnnotations, doMainValueWAnnotations from child-
+	  to parent-class, extracetd doDischargeOut. Use
+	  StyledSeriesBuilder.addPointsQW .
+
 2011-11-02	Felix Wolfsteller	<felix.wolfsteller@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/MainValuesArtifact.java:
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/ComputedDischargeCurveGenerator.java	Wed Nov 02 11:30:26 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/ComputedDischargeCurveGenerator.java	Wed Nov 02 12:12:48 2011 +0000
@@ -101,11 +101,13 @@
         if (name.equals(COMPUTED_DISCHARGE_Q)) {
             doQOut((WQKms) f.getData(artifact, context), facet, attr, visible);
         }
-        else if (name.equals(COMPUTED_DISCHARGE_MAINVALUES_Q)) {
+        else if (name.equals(COMPUTED_DISCHARGE_MAINVALUES_Q)
+                || name.equals(MAINVALUES_Q)) {
             doMainValueQAnnotations(
                 f.getData(artifact, context), facet, attr, visible);
         }
-        else if (name.equals(COMPUTED_DISCHARGE_MAINVALUES_W)) {
+        else if (name.equals(COMPUTED_DISCHARGE_MAINVALUES_W)
+                || name.equals(MAINVALUES_W)) {
             doMainValueWAnnotations(
                 f.getData(artifact, context), facet, attr, visible);
         }
@@ -117,42 +119,6 @@
 
 
     /**
-     * Store W MainValues as annotations for later plotting.
-     */
-    protected void doMainValueWAnnotations(
-        Object   o,
-        Facet    facet,
-        Document theme,
-        boolean  visible
-    ) {
-        logger.debug("ComputedDischargeCurveGenerator set W MainValues.");
-
-        FLYSAnnotation fa = (FLYSAnnotation) o;
-        fa.setTheme(theme);
-        fa.setLabel(facet.getDescription());
-        addAnnotations(fa, visible);
-    }
-
-
-    /**
-     * Store Q MainValues as annotations for later plotting.
-     */
-    protected void doMainValueQAnnotations(
-        Object   o,
-        Facet    facet,
-        Document theme,
-        boolean  visible
-    ) {
-        logger.debug("ComputedDischargeCurveGenerator set Q MainValues.");
-
-        FLYSAnnotation fa = (FLYSAnnotation) o;
-        fa.setTheme(theme);
-        fa.setLabel(facet.getDescription());
-        addAnnotations(fa, visible);
-    }
-
-
-    /**
      * Add Q-Series to plot.
      * @param wqkms actual data
      * @param theme theme to use.
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/DischargeCurveGenerator.java	Wed Nov 02 11:30:26 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/DischargeCurveGenerator.java	Wed Nov 02 12:12:48 2011 +0000
@@ -14,21 +14,26 @@
 
 import de.intevation.artifactdatabase.state.Facet;
 
+import de.intevation.flys.artifacts.model.FacetTypes;
 import de.intevation.flys.model.Gauge;
 import de.intevation.flys.model.River;
 
+import de.intevation.flys.artifacts.FLYSArtifact;
 import de.intevation.flys.artifacts.WINFOArtifact;
 
 import de.intevation.flys.artifacts.model.WQKms;
 
 import de.intevation.flys.utils.FLYSUtils;
+import de.intevation.flys.jfree.FLYSAnnotation;
 
 /**
  * An OutGenerator that generates discharge curves.
  *
  * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
  */
-public class DischargeCurveGenerator extends XYChartGenerator {
+public class DischargeCurveGenerator
+extends      XYChartGenerator
+implements   FacetTypes {
 
     /** The logger used in this generator. */
     private static Logger logger =
@@ -62,9 +67,12 @@
     }
 
 
+    /**
+     * Empty (suppress subtitle).
+     */
     @Override
     protected void addSubtitles(JFreeChart chart) {
-
+        ;
     }
 
 
@@ -93,17 +101,14 @@
     public void doOut(
         Artifact artifact,
         Facet    facet,
-        Document attr,
+        Document theme,
         boolean  visible
     ) {
         logger.debug("DischargeCurveGenerator.doOut: " + facet.getName());
 
-        if (!(artifact instanceof WINFOArtifact)) {
-            logger.debug("Artifact is no instance of WINFOArtifact.");
-            return;
-        }
+        String name = facet.getName();
 
-        WINFOArtifact flysArtifact = (WINFOArtifact) artifact;
+        FLYSArtifact flysArtifact = (FLYSArtifact) artifact;
 
         Facet nativeFacet = flysArtifact.getNativeFacet(facet);
 
@@ -112,11 +117,48 @@
             return;
         }
 
-        WQKms wqkms = (WQKms)nativeFacet.getData(flysArtifact, context);
+        if (name.equals(DISCHARGE_CURVE)) {
+            doDischargeOut(
+                (WINFOArtifact) flysArtifact,
+                nativeFacet.getData(flysArtifact, context),
+                nativeFacet.getDescription(),
+                theme,
+                visible);
+        }
+        else if (name.equals(COMPUTED_DISCHARGE_MAINVALUES_Q)
+                || name.equals(MAINVALUES_Q))
+        {
+            doMainValueQAnnotations(
+                nativeFacet.getData(artifact, context), facet, theme, visible);
+        }
+        else if (name.equals(COMPUTED_DISCHARGE_MAINVALUES_W)
+                || name.equals(MAINVALUES_W))
+        {
+            doMainValueWAnnotations(
+                nativeFacet.getData(artifact, context), facet, theme, visible);
+        }
+        else {
+           logger.warn("DischargeCurveGenerator.doOut: Unknown facet name: " + name);
+           return;
+        }
+    }
+
+
+    /**
+     * Add series with discharge curve to diagram.
+     */
+    protected void doDischargeOut(
+        WINFOArtifact artifact,
+        Object o,
+        String description,
+        Document theme,
+        boolean visible)
+    {
+        WQKms wqkms = (WQKms) o;
 
         String gaugeName = wqkms.getName();
 
-        River river = FLYSUtils.getRiver(flysArtifact);
+        River river = FLYSUtils.getRiver(artifact);
 
         if (river == null) {
             logger.debug("no river found");
@@ -130,18 +172,51 @@
             return;
         }
 
-        double [][] values = new double [][] {
-            wqkms.getQs(), wqkms.getWs() };
-
-        int size = values != null ? values[0].length : 0;
+        XYSeries series = new StyledXYSeries(description, theme);
 
-        XYSeries series = new StyledXYSeries(facet.getDescription(), attr);
-
-        for (int i = 0; i < size; i++) {
-            series.add(values[0][i], values[1][i]);
-        }
+        StyledSeriesBuilder.addPointsQW(series, wqkms);
 
         addFirstAxisSeries(series, visible);
     }
+
+            
+
+    /**
+     * Store W MainValues as annotations for later plotting.
+     */
+    protected void doMainValueWAnnotations(
+        Object   o,
+        Facet    facet,
+        Document theme,
+        boolean  visible
+    ) {
+        logger.debug("ComputedDischargeCurveGenerator set W MainValues.");
+
+        FLYSAnnotation fa = (FLYSAnnotation) o;
+        fa.setTheme(theme);
+        fa.setLabel(facet.getDescription());
+        addAnnotations(fa, visible);
+    }
+
+
+    /**
+     * Store Q MainValues as annotations for later plotting.
+     */
+    protected void doMainValueQAnnotations(
+        Object   o,
+        Facet    facet,
+        Document theme,
+        boolean  visible
+    ) {
+        logger.debug("ComputedDischargeCurveGenerator set Q MainValues.");
+
+        FLYSAnnotation fa = (FLYSAnnotation) o;
+        fa.setTheme(theme);
+        fa.setLabel(facet.getDescription());
+        addAnnotations(fa, visible);
+    }
+
+
+
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/StyledSeriesBuilder.java	Wed Nov 02 11:30:26 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/StyledSeriesBuilder.java	Wed Nov 02 12:12:48 2011 +0000
@@ -51,6 +51,7 @@
         }
     }
 
+
     /**
      * Add points to series (w to 1st dim, km to 2nd dim).
      *
@@ -64,5 +65,20 @@
            series.add(wqkms.getKm(i), wqkms.getQ(i), false);
        }
     }
+
+
+    /**
+     * Add points to series (q to 1st dim, w to 2nd dim).
+     *
+     * @param series Series to add points to.
+     * @param points Points to add to series.
+     */
+    public static void addPointsQW(XYSeries series, WQKms wqkms) {
+        int size = wqkms.size();
+
+        for (int i = 0; i < size; i++) {
+            series.add(wqkms.getQ(i), wqkms.getW(i));
+        }
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org