changeset 8571:bc803f4b6784

(issue1798) Adjust WinCM according to W in NHN axis on explicit zoom
author Andre Heinecke <andre.heinecke@intevation.de>
date Fri, 27 Feb 2015 19:07:25 +0100
parents 1655588ed479
children 321d6e50aebe
files artifacts/src/main/java/org/dive4elements/river/exports/DischargeGenerator.java
diffstat 1 files changed, 26 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/exports/DischargeGenerator.java	Thu Feb 26 15:53:28 2015 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/DischargeGenerator.java	Fri Feb 27 19:07:25 2015 +0100
@@ -26,6 +26,10 @@
 
     private String I18N_AXIS_LABEL = "chart.discharge.curve.yaxis.cm.label";
 
+    private int wAxisIndex;
+    private int wInCmAxisIndex;
+    double pnpValue;
+
     public DischargeGenerator() {
     }
 
@@ -38,9 +42,9 @@
             return;
         }
 
-        double pnpValue = ((Number)pnp).doubleValue();
+        pnpValue = ((Number)pnp).doubleValue();
 
-        int wAxisIndex = diagramAttributes.getAxisIndex("W");
+        wAxisIndex = diagramAttributes.getAxisIndex("W");
         if (wAxisIndex == -1) {
             log.warn("No W axis found.");
             return;
@@ -67,7 +71,7 @@
         NumberAxis wInCmAxis = createWinCMAxis(wAxisIndex);
         wInCmAxis.setRange(axisRange);
 
-        int wInCmAxisIndex = plot.getRangeAxisCount();
+        wInCmAxisIndex = plot.getRangeAxisCount();
         plot.setRangeAxis(wInCmAxisIndex, wInCmAxis);
         combineYBounds(new DoubleBounds(dataRange), wInCmAxisIndex);
     }
@@ -100,5 +104,24 @@
 
         return axis;
     }
+
+     /** We need to override this to keep both axis synced. */
+    @Override
+    protected void autoZoom(XYPlot plot) {
+        super.autoZoom(plot);
+        IdentifiableNumberAxis idA = (IdentifiableNumberAxis) plot.getRangeAxis(wAxisIndex);
+        Range fixedRange = getRangeForAxisFromSettings(idA.getId());
+        if (fixedRange == null) {
+            return;
+        }
+        log.debug("Adjusting helper centimeter axis to fixed range.");
+        Range adjustedRange = inCm(
+            fixedRange,
+            pnpValue
+        );
+        IdentifiableNumberAxis wInCmAxis=
+            (IdentifiableNumberAxis) plot.getRangeAxis(wInCmAxisIndex);
+        wInCmAxis.setRange(adjustedRange);
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org