changeset 6453:f11165468f0a

issue1370: swap default axis (now in cm), translate annotations if in cm.
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Wed, 26 Jun 2013 22:06:15 +0200
parents 9cbe58704604
children e860fa106f56
files artifacts/src/main/java/org/dive4elements/river/exports/ComputedDischargeCurveGenerator.java artifacts/src/main/java/org/dive4elements/river/exports/DischargeCurveGenerator.java
diffstat 2 files changed, 43 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- 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(
--- 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)) {

http://dive4elements.wald.intevation.org