[Dive4elements-commits] [PATCH 2 of 2] issue1370: swap default axis (now in cm), translate annotations if in cm

Wald Commits scm-commit at wald.intevation.org
Wed Jun 26 21:57:37 CEST 2013


# HG changeset patch
# User Felix Wolfsteller <felix.wolfsteller at intevation.de>
# Date 1372277175 -7200
# Node ID f11165468f0af6e046538868464a330c7e88d22d
# Parent  9cbe58704604b26c8c8e3e3cb5296aab9b0c4358
issue1370: swap default axis (now in cm), translate annotations if in cm.

diff -r 9cbe58704604 -r f11165468f0a artifacts/src/main/java/org/dive4elements/river/exports/ComputedDischargeCurveGenerator.java
--- a/artifacts/src/main/java/org/dive4elements/river/exports/ComputedDischargeCurveGenerator.java	Wed Jun 26 21:13:43 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/ComputedDischargeCurveGenerator.java	Wed Jun 26 22:06:15 2013 +0200
@@ -102,6 +102,18 @@
         return msg(I18N_YAXIS_LABEL, I18N_YAXIS_LABEL_DEFAULT, new Object[] { unit });
     }
 
+    /**
+     * Generate a ForceAxisDataset for the second y axis, if requested,
+     * to force display of second Y axis.
+    @Override
+    protected AxisDataset createAxisDataset(int idx) {
+        logger.debug("Create new ForceAxisDataset for index: " + idx);
+        if (true || idx == 1) {
+            return new ForceAxisDataset(1);
+        }
+        return new XYAxisDataset(idx);
+    }
+     */
 
     /**
      * Create Y (range) axis for given index, here with a special axis
@@ -173,8 +185,11 @@
                 || name.equals(COMPUTED_DISCHARGE_MAINVALUES_W)
                 || name.equals(MAINVALUES_W)
         ) {
-            doAnnotations((RiverAnnotation)
-                artifactFacet.getData(context), artifactFacet, attr, visible);
+            RiverAnnotation mainValues = (RiverAnnotation) artifactFacet.getData(context);
+            translateRiverAnnotation(mainValues);
+            doAnnotations(
+                mainValues,
+                artifactFacet, attr, visible);
         }
         else if (name.equals(STATIC_WKMS_INTERPOL) || name.equals(HEIGHTMARKS_POINTS)) {
             doWAnnotations(
diff -r 9cbe58704604 -r f11165468f0a artifacts/src/main/java/org/dive4elements/river/exports/DischargeCurveGenerator.java
--- a/artifacts/src/main/java/org/dive4elements/river/exports/DischargeCurveGenerator.java	Wed Jun 26 21:13:43 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/DischargeCurveGenerator.java	Wed Jun 26 22:06:15 2013 +0200
@@ -14,12 +14,14 @@
 import org.dive4elements.river.artifacts.model.WQKms;
 import org.dive4elements.river.jfree.Bounds;
 import org.dive4elements.river.jfree.RiverAnnotation;
+import org.dive4elements.river.jfree.StickyAxisAnnotation;
 import org.dive4elements.river.jfree.StyledXYSeries;
 import org.dive4elements.river.model.Gauge;
 import org.dive4elements.river.model.River;
 import org.dive4elements.river.utils.RiverUtils;
 
 import org.apache.log4j.Logger;
+import org.jfree.chart.annotations.XYTextAnnotation;
 import org.jfree.chart.axis.ValueAxis;
 import org.jfree.chart.plot.XYPlot;
 import org.jfree.data.Range;
@@ -37,8 +39,8 @@
 implements   FacetTypes {
 
     public static enum YAXIS {
-        W(0),
-        WCm(1);
+        WCm(0),
+        W(1);
         protected int idx;
         private YAXIS(int c) {
             idx = c;
@@ -79,6 +81,7 @@
         return subtractPNP;
     }
 
+
     public double getCurrentGaugeDatum() {
         return getCurrentGaugeDatum(getRange()[0], (D4EArtifact) getMaster());
     }
@@ -138,6 +141,23 @@
         return zoomin;
     }
 
+    public void translateRiverAnnotation(RiverAnnotation riverAnnotation) {
+        if (getCurrentGaugeDatum() == 0d) {
+            return;
+        }
+        logger.debug("Translate some river annotation.");
+        double translate = getCurrentGaugeDatum();
+        double factor    = 100d;
+        for (StickyAxisAnnotation annotation: riverAnnotation.getAxisTextAnnotations()){
+            if (!annotation.atX()) {
+                annotation.setPos((annotation.getPos() - translate)*factor);
+            }
+        }
+        for (XYTextAnnotation annotation: riverAnnotation.getTextAnnotations()) {
+            annotation.setY((annotation.getY() - translate)*factor);
+        }
+    }
+
 
     @Override
     public void doOut(
@@ -162,7 +182,10 @@
                 || name.equals(COMPUTED_DISCHARGE_MAINVALUES_W)
                 || name.equals(MAINVALUES_W))
         {
-            doAnnotations((RiverAnnotation) artifactFacet.getData(context),
+            RiverAnnotation mainValues = (RiverAnnotation) artifactFacet.getData(context);
+            translateRiverAnnotation(mainValues);
+            doAnnotations(
+                mainValues,
                 artifactFacet, theme, visible);
         }
         else if (FacetTypes.IS.MANUALPOINTS(name)) {


More information about the Dive4elements-commits mailing list