diff artifacts/src/main/java/org/dive4elements/river/exports/DischargeCurveGenerator.java @ 7691:fa4fbd66e752

(issue1579) Fix axes syncronisation at Gauges The SyncNumberAxis was completely broken. It only synced in one direction and even that did not work correctly when data was added to the axis (and the syncAxis rescaled but forgot the old axis) then there were lots of ways to bypass that scaling. And i also think the trans calculation was wrong. It has been replaced by a "mostly" simple method to just keep the W in M and W in CM+Datum axes in sync. I say "Mostly" because it had to deal with the Bounds interface.
author Andre Heinecke <aheinecke@intevation.de>
date Fri, 13 Dec 2013 19:03:00 +0100
parents 2fed93751ecb
children e47b1ea5baf4
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/exports/DischargeCurveGenerator.java	Fri Dec 13 17:44:57 2013 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/DischargeCurveGenerator.java	Fri Dec 13 19:03:00 2013 +0100
@@ -18,6 +18,7 @@
 import org.dive4elements.river.exports.process.DischargeProcessor;
 import org.dive4elements.river.jfree.CollisionFreeXYTextAnnotation;
 import org.dive4elements.river.jfree.Bounds;
+import org.dive4elements.river.jfree.DoubleBounds;
 import org.dive4elements.river.jfree.RiverAnnotation;
 import org.dive4elements.river.jfree.StickyAxisAnnotation;
 import org.dive4elements.river.jfree.StyledXYSeries;
@@ -109,9 +110,51 @@
         if (getCurrentGaugeDatum() != 0d) {
             // Show the W[*m] axis even if there is no data.
             plot.setRangeAxis(1, createYAxis(YAXIS.W.idx));
+            syncWAxisRanges();
         }
     }
 
+    protected void syncWAxisRanges() {
+        // Syncronizes the ranges of both W Axes to make sure
+        // that the Data matches for both axes.
+        Bounds boundsInMGauge = getYBounds(YAXIS.W.idx);
+        Bounds boundsInCM = getYBounds(YAXIS.WCm.idx);
+
+        // XXX Q-Symetry: I am assuming here that there can only
+        // be a fixed Range for WinM as this is currently the only
+        // thing that is configureable.
+        Range fixedWinMRange = getRangeForAxisFromSettings(
+                getYAxisWalker().getId(YAXIS.W.idx));
+
+        // The combination of Range and Bounds is crazy..
+        if (fixedWinMRange != null) {
+            boundsInMGauge = new DoubleBounds(fixedWinMRange.getLowerBound(),
+                    fixedWinMRange.getUpperBound());
+        }
+
+        logger.debug("Syncing Axis Bounds. Bounds W: " + boundsInMGauge.toString() +
+                " Bounds Wcm: " + boundsInCM.toString());
+
+        double datum = getCurrentGaugeDatum();
+
+        // Convert boundsInMGauge to Datum+cm
+        double convertedLower = ((Double)boundsInMGauge.getLower() - datum) * 100;
+        double convertedUpper = ((Double)boundsInMGauge.getUpper() - datum) * 100;
+        Bounds convertedBounds = new DoubleBounds(convertedLower, convertedUpper);
+
+        // Now combine both Ranges
+        boundsInCM = boundsInCM.combine(convertedBounds);
+
+        // Recalculate absolute bounds
+        boundsInMGauge = new DoubleBounds((Double)boundsInCM.getLower() / 100d + datum,
+                                          (Double)boundsInCM.getUpper() / 100d + datum);
+
+        // Set the new combined bounds
+        setYBounds(YAXIS.W.idx, boundsInMGauge);
+        setYBounds(YAXIS.WCm.idx, boundsInCM);
+        logger.debug("Synced Bounds W: " + boundsInMGauge.toString() +
+                " Bounds Wcm: " + boundsInCM.toString());
+    }
 
     public DischargeCurveGenerator() {
         super();

http://dive4elements.wald.intevation.org