changeset 1089:e298c4d28927

Improved mainvalues rendering. flys-artifacts/trunk@2592 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Fri, 26 Aug 2011 11:15:24 +0000
parents 1f5b92531f72
children 9324839684a4
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/MainValuesArtifact.java flys-artifacts/src/main/java/de/intevation/flys/exports/ComputedDischargeCurveGenerator.java flys-artifacts/src/main/java/de/intevation/flys/jfree/StickyAxisAnnotation.java
diffstat 4 files changed, 93 insertions(+), 37 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Fri Aug 26 11:11:46 2011 +0000
+++ b/flys-artifacts/ChangeLog	Fri Aug 26 11:15:24 2011 +0000
@@ -1,3 +1,15 @@
+2011-08-26  Felix Wolfsteller <felix.wolfsteller@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/MainValuesArtifact.java:
+	  Use NamedDoubles instead of MainValues, try to adjust scale of Ws.
+
+	* src/main/java/de/intevation/flys/exports/ComputedDischargeCurveGenerator.java:
+	  Use NamedDoubles instead of MainValues, generalize annotation handling, to
+	  allow easier reusability and themeing.
+
+	* src/main/java/de/intevation/flys/jfree/StickyAxisAnnotation.java:
+	  Added convenience constructor, exemplary switch on bordered text.
+
 2011-08-26  Felix Wolfsteller <felix.wolfsteller@intevation.de>
 
 	* doc/conf/meta-data.xml:
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/MainValuesArtifact.java	Fri Aug 26 11:11:46 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/MainValuesArtifact.java	Fri Aug 26 11:15:24 2011 +0000
@@ -17,8 +17,9 @@
 import de.intevation.artifacts.CallMeta;
 import de.intevation.flys.artifacts.model.RiverFactory;
 
+import de.intevation.flys.artifacts.model.MainValuesQFacet;
 import de.intevation.flys.artifacts.model.MainValuesWFacet;
-import de.intevation.flys.artifacts.model.MainValuesQFacet;
+import de.intevation.flys.artifacts.model.NamedDouble;
 import de.intevation.artifactdatabase.data.DefaultStateData;
 import de.intevation.flys.artifacts.states.StaticState;
 
@@ -166,6 +167,11 @@
             : null;
     }
 
+    /**
+     * Access the Gauge that the mainvalues are taken from.
+     * @return Gauge that main values are taken from or null in case of
+     *         invalid parameterization.
+     */
     protected Gauge getGauge() {
         River river = getRiver();
 
@@ -179,28 +185,57 @@
         return river.determineGaugeByPosition(location);
     }
 
-    public List<MainValue> getMainValuesQ() {
-        List<MainValue> filteredList = new ArrayList<MainValue>();
+
+    /**
+     * Get datum of Gauge.
+     * @return datum of gauge.
+     */
+    public double getGaugeDatum() {
+        Gauge gauge = getGauge();
+        if (gauge == null) { return 0.0f; }
+        return gauge.getDatum().doubleValue();
+    }
+
+
+    /**
+     * Get a list of "Q" main values.
+     * @return list of Q main values.
+     */
+    public List<NamedDouble> getMainValuesQ() {
+        List<NamedDouble> filteredList = new ArrayList<NamedDouble>();
         Gauge gauge = getGauge();
         if (gauge != null) {
             List<MainValue> orig = gauge.getMainValues();
             for (MainValue mv : orig) {
                 if (mv.getMainValue().getType().getName().equals("Q")) {
-                    filteredList.add(mv);
+                    filteredList.add(new NamedDouble(
+                                mv.getMainValue().getName(),
+                                mv.getValue().doubleValue()
+                                ));
                 }
             }
         }
         return filteredList;
     }
 
-    public List<MainValue> getMainValuesW() {
-        List<MainValue> filteredList = new ArrayList<MainValue>();
+
+    /**
+     * Get a list of "W" main values.
+     * @return list of W main values.
+     */
+    public List<NamedDouble> getMainValuesW() {
+        List<NamedDouble> filteredList = new ArrayList<NamedDouble>();
         Gauge gauge = getGauge();
+        double datum = gauge.getDatum().doubleValue();
+        logger.debug("DATUM:: " + datum);
         if (gauge != null) {
             List<MainValue> orig = gauge.getMainValues();
             for (MainValue mv : orig) {
                 if (mv.getMainValue().getType().getName().equals("W")) {
-                    filteredList.add(mv);
+                    filteredList.add(new NamedDouble(
+                                mv.getMainValue().getName(),
+                                mv.getValue().doubleValue()/100.f + datum
+                                ));
                 }
             }
         }
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/ComputedDischargeCurveGenerator.java	Fri Aug 26 11:11:46 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/ComputedDischargeCurveGenerator.java	Fri Aug 26 11:15:24 2011 +0000
@@ -11,18 +11,19 @@
 import org.jfree.data.xy.XYSeries;
 import org.jfree.chart.axis.ValueAxis;
 import org.jfree.chart.plot.XYPlot;
+import org.jfree.chart.annotations.XYAnnotation;
 
 import de.intevation.artifacts.Artifact;
 
 import de.intevation.artifactdatabase.state.Facet;
 
 import de.intevation.flys.artifacts.FLYSArtifact;
+import de.intevation.flys.artifacts.model.NamedDouble;
 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;
 
 /**
  * An OutGenerator that generates discharge curves.
@@ -50,11 +51,8 @@
     public static final String I18N_CHART_TITLE_DEFAULT = "Abflusskurve";
     public static final String I18N_YAXIS_LABEL_DEFAULT = "W [NN + m]";
 
-    /** List of W MainValues (Annotations in plot). */
-    protected static List<MainValue> mainValuesW;
-
-    /** List of Q MainValues (Annotations in plot). */
-    protected static List<MainValue> mainValuesQ;
+    /** List of Annotations (specifically, Main Values). */
+    protected List<XYAnnotation> annotations;
 
     // TODO Add pseudodataseries for having mainvalue-text in legend.
     // TODO Let theme pass through to annotations-facets.
@@ -63,8 +61,7 @@
     /** Trivial Constructor. */
     public ComputedDischargeCurveGenerator () {
         super();
-        mainValuesQ = new ArrayList<MainValue>();
-        mainValuesW = new ArrayList<MainValue>();
+        annotations= new ArrayList<XYAnnotation>();
     }
 
 
@@ -112,10 +109,10 @@
             doQOut((WQKms) f.getData(artifact, context), attr);
         }
         else if (name.equals(COMPUTED_DISCHARGE_MAINVALUES_Q)) {
-            doMainValueWAnnotations(f.getData(artifact, context), attr);
+            doMainValueQAnnotations(f.getData(artifact, context), attr);
         }
         else if (name.equals(COMPUTED_DISCHARGE_MAINVALUES_W)) {
-            doMainValueQAnnotations(f.getData(artifact, context), attr);
+            doMainValueWAnnotations(f.getData(artifact, context), attr);
         }
         else {
             logger.warn("Unknown facet type for computed discharge: " + name);
@@ -129,7 +126,15 @@
      */
     protected void doMainValueWAnnotations(Object o, Document theme) {
         logger.debug("ComputedDischargeCurveGenerator set W MainValues.");
-        this.mainValuesW = (List<MainValue>) o;
+        List<NamedDouble> mainValuesW = (List<NamedDouble>) o;
+        for (NamedDouble mv: mainValuesW) {
+            float pos = (float) mv.getValue();
+            String text = mv.getName();
+            StickyAxisAnnotation ta = new StickyAxisAnnotation(text, pos,
+                    StickyAxisAnnotation.SimpleAxis.Y_AXIS);
+            logger.debug("Adding W: " + text + " : " + pos);
+            this.annotations.add(ta);
+        }
     }
 
     
@@ -138,7 +143,13 @@
      */
     protected void doMainValueQAnnotations(Object o, Document theme) {
         logger.debug("ComputedDischargeCurveGenerator set Q MainValues.");
-        this.mainValuesQ = (List<MainValue>) o;
+        List<NamedDouble> mainValuesQ = (List<NamedDouble>) o;
+        for (NamedDouble mv: mainValuesQ) {
+            float pos = (float) mv.getValue();
+            String text = mv.getName();
+            StickyAxisAnnotation ta = new StickyAxisAnnotation(text, pos);
+            this.annotations.add(ta);
+        }
     }
 
 
@@ -147,7 +158,7 @@
     public JFreeChart generateChart() {
         JFreeChart c = super.generateChart();
         XYPlot p = (XYPlot) c.getPlot();
-        redoAnnotations(p, p.getDomainAxis());
+        redoAnnotations(p);
         return c;
     }
 
@@ -156,24 +167,12 @@
      * Recalculate some annotation positions and add them to plot.
      * Annotations represent MainValues.
      * @param plot      Plot to add annotations to.
-     * @param valueAxis ignored.
      */
-    protected void redoAnnotations(XYPlot plot, ValueAxis axis) {
+    protected void redoAnnotations(XYPlot plot) {
         plot.clearAnnotations();
-        // 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);
-        }
-        for (MainValue mv: mainValuesW) {
-            float pos = mv.getValue().floatValue();
-            String text = mv.getMainValue().getName();
-            StickyAxisAnnotation ta = new StickyAxisAnnotation(text, pos,
-                 StickyAxisAnnotation.SimpleAxis.Y_AXIS);
-            plot.getRenderer().addAnnotation(ta);
+
+        for (XYAnnotation a: annotations) {
+            plot.addAnnotation(a, false);
         }
     }
 
--- a/flys-artifacts/src/main/java/de/intevation/flys/jfree/StickyAxisAnnotation.java	Fri Aug 26 11:11:46 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/jfree/StickyAxisAnnotation.java	Fri Aug 26 11:15:24 2011 +0000
@@ -65,6 +65,16 @@
 
 
     /**
+     * Constructor with implicit sticky x-axis.
+     * @param text       the text to display.
+     * @param pos        the position at which to draw the text and mark.
+     */
+    public StickyAxisAnnotation(String text, float pos) {
+        this(text, pos, pos, SimpleAxis.X_AXIS);
+    }
+
+
+    /**
      * Constructor with given explicit axis.
      * @param text       the text to display.
      * @param pos        the position at which to draw the text and mark.
@@ -290,7 +300,7 @@
         TextUtilities.drawRotatedString(getText(), g2, anchorX, anchorY,
                 getTextAnchor(), getRotationAngle(), getRotationAnchor());
         // Draw outline.
-        if (false) {
+        if (true) {
             g2.setStroke(getOutlineStroke());
             g2.setPaint(getOutlinePaint());
             g2.draw(hotspot);

http://dive4elements.wald.intevation.org