diff flys-artifacts/src/main/java/de/intevation/flys/exports/ComputedDischargeCurveGenerator.java @ 1085:07878836ee0d

Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale. flys-artifacts/trunk@2588 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Fri, 26 Aug 2011 08:49:18 +0000
parents d0db31d1f64c
children e298c4d28927
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/ComputedDischargeCurveGenerator.java	Fri Aug 26 08:07:47 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/ComputedDischargeCurveGenerator.java	Fri Aug 26 08:49:18 2011 +0000
@@ -1,5 +1,4 @@
 package de.intevation.flys.exports;
-
 import org.apache.log4j.Logger;
 
 import java.util.ArrayList;
@@ -12,7 +11,6 @@
 import org.jfree.data.xy.XYSeries;
 import org.jfree.chart.axis.ValueAxis;
 import org.jfree.chart.plot.XYPlot;
-import org.jfree.ui.TextAnchor;
 
 import de.intevation.artifacts.Artifact;
 
@@ -21,6 +19,7 @@
 import de.intevation.flys.artifacts.FLYSArtifact;
 import de.intevation.flys.artifacts.model.FacetTypes;
 import de.intevation.flys.artifacts.model.WQKms;
+
 import de.intevation.flys.jfree.StickyAxisAnnotation;
 
 import de.intevation.flys.model.MainValue;
@@ -51,14 +50,21 @@
     public static final String I18N_CHART_TITLE_DEFAULT = "Abflusskurve";
     public static final String I18N_YAXIS_LABEL_DEFAULT = "W [NN + m]";
 
-    /** List of MainValues (Annotations in plot). */
-    protected static List<MainValue> mainValues;
+    /** List of W MainValues (Annotations in plot). */
+    protected static List<MainValue> mainValuesW;
+
+    /** List of Q MainValues (Annotations in plot). */
+    protected static List<MainValue> mainValuesQ;
+
+    // TODO Add pseudodataseries for having mainvalue-text in legend.
+    // TODO Let theme pass through to annotations-facets.
 
 
     /** Trivial Constructor. */
     public ComputedDischargeCurveGenerator () {
         super();
-        mainValues = new ArrayList<MainValue>();
+        mainValuesQ = new ArrayList<MainValue>();
+        mainValuesW = new ArrayList<MainValue>();
     }
 
 
@@ -94,14 +100,22 @@
 
         logger.debug("ComputedDischargeCurveGenerator.doOut: " + name);
 
+        if (name == null) {
+            logger.warn("Broken facet in computed discharge out generation.");
+            return;
+        }
+
         FLYSArtifact flys = (FLYSArtifact) artifact;
         Facet        f    = flys.getNativeFacet(facet);
 
         if (name.equals(COMPUTED_DISCHARGE_Q)) {
             doQOut((WQKms) f.getData(artifact, context), attr);
         }
-        else if (name.equals(COMPUTED_DISCHARGE_MAINVALUES)) {
-            doMainValueAnnotations(f.getData(artifact, context), attr);
+        else if (name.equals(COMPUTED_DISCHARGE_MAINVALUES_Q)) {
+            doMainValueWAnnotations(f.getData(artifact, context), attr);
+        }
+        else if (name.equals(COMPUTED_DISCHARGE_MAINVALUES_W)) {
+            doMainValueQAnnotations(f.getData(artifact, context), attr);
         }
         else {
             logger.warn("Unknown facet type for computed discharge: " + name);
@@ -111,10 +125,20 @@
 
 
     /**
-     * Add MainValues as annotations to plot.
+     * Store W MainValues as annotations for later plotting.
      */
-    protected void doMainValueAnnotations(Object o, Document theme) {
-        this.mainValues = (List<MainValue>) o;
+    protected void doMainValueWAnnotations(Object o, Document theme) {
+        logger.debug("ComputedDischargeCurveGenerator set W MainValues.");
+        this.mainValuesW = (List<MainValue>) o;
+    }
+
+    
+    /**
+     * Store Q MainValues as annotations for later plotting.
+     */
+    protected void doMainValueQAnnotations(Object o, Document theme) {
+        logger.debug("ComputedDischargeCurveGenerator set Q MainValues.");
+        this.mainValuesQ = (List<MainValue>) o;
     }
 
 
@@ -136,27 +160,19 @@
      */
     protected void redoAnnotations(XYPlot plot, ValueAxis axis) {
         plot.clearAnnotations();
-        ValueAxis yAxis = plot.getRangeAxis();
-        float posY = 140.f;
-        if (yAxis != null) {
-            posY = (float) yAxis.getRange().getLowerBound();
-            // Add some (2%) space between Text and axis.
-            // TODO have all the position logic in StickyAxisAnnotation
-            //      (then merge LongitudinalSectioNGenerator).
-            posY += 0.02f * (yAxis.getRange().getUpperBound()
-                        - yAxis.getRange().getLowerBound());
+        // Add all MainValues as annotations.
+        for (MainValue mv: mainValuesQ) {
+            float pos = mv.getValue().floatValue();
+            String text = mv.getMainValue().getName();
+            StickyAxisAnnotation ta = new StickyAxisAnnotation(text, pos,
+                    StickyAxisAnnotation.SimpleAxis.X_AXIS);
+            plot.getRenderer().addAnnotation(ta);
         }
-        // Add all MainValues as annotations.
-        // TODO Implement and handle second facet for annotations on
-        //      vertical axis.
-        for (MainValue mv: mainValues) {
-            if (mv.getMainValue().getType().getName() == "W") {
-                continue;
-            }
-            float posX = mv.getValue().floatValue();
-
+        for (MainValue mv: mainValuesW) {
+            float pos = mv.getValue().floatValue();
             String text = mv.getMainValue().getName();
-            StickyAxisAnnotation ta = new StickyAxisAnnotation(text, posX, posY);
+            StickyAxisAnnotation ta = new StickyAxisAnnotation(text, pos,
+                 StickyAxisAnnotation.SimpleAxis.Y_AXIS);
             plot.getRenderer().addAnnotation(ta);
         }
     }

http://dive4elements.wald.intevation.org