Mercurial > dive4elements > river
diff artifacts/src/main/java/org/dive4elements/river/exports/fixings/FixWQCurveGenerator.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 | 4dbbdf0c8b2c |
children | 75ef6963f1c9 |
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/exports/fixings/FixWQCurveGenerator.java Fri Dec 13 17:44:57 2013 +0100 +++ b/artifacts/src/main/java/org/dive4elements/river/exports/fixings/FixWQCurveGenerator.java Fri Dec 13 19:03:00 2013 +0100 @@ -47,7 +47,6 @@ import org.dive4elements.river.artifacts.resources.Resources; import org.dive4elements.river.exports.ChartGenerator; import org.dive4elements.river.exports.DischargeCurveGenerator; -import org.dive4elements.river.exports.SyncNumberAxis; import org.dive4elements.river.exports.StyledSeriesBuilder; import org.dive4elements.river.jfree.CollisionFreeXYTextAnnotation; import org.dive4elements.river.jfree.RiverAnnotation; @@ -60,6 +59,11 @@ import org.dive4elements.river.utils.RiverUtils; import org.dive4elements.river.java2d.ShapeUtils; +import org.dive4elements.river.jfree.Bounds; +import org.dive4elements.river.jfree.DoubleBounds; + +import org.jfree.data.Range; + /** * Generator for WQ fixing charts. * @author <a href="mailto:christian.lins@intevation.de">Christian Lins</a> @@ -111,49 +115,6 @@ /** Needed to access data to create subtitle. */ protected D4EArtifact artifact; - // TODO dupe of ComputedDischargeCurveGenerator - protected SyncNumberAxis secondYAxis; - // TODO dupe of ComputedDischargeCurveGenerator - protected NumberAxis firstYAxis; - - - /** - * Create Y (range) axis for given index, here with a special axis - * that depends on other axis (does translation and scaling for - * special case at gauge in cm). - */ - // TODO dupe of ComputedDischargeCurveGenerator - @Override - protected NumberAxis createYAxis(int index) { - logger.debug("createYAxis: " + index); - if (index == 1) { - firstYAxis = super.createYAxis(1); - if (secondYAxis != null) { - secondYAxis.setProxyAxis(firstYAxis); - } - return firstYAxis; - } - YAxisWalker walker = getYAxisWalker(); - - Font labelFont = new Font( - DEFAULT_FONT_NAME, - Font.BOLD, - getYAxisFontSize(index)); - - SyncNumberAxis axis = new SyncNumberAxis( - walker.getId(index), - getYAxisLabel(index), - firstYAxis); - - axis.setAutoRangeIncludesZero(false); - axis.setLabelFont(labelFont); - axis.setTickLabelFont(labelFont); - axis.setShift((double)-getCurrentGaugeDatum()); - - secondYAxis = axis; - return axis; - } - /** Returns value != 0 if the current km is not at a gauge. */ public double getCurrentGaugeDatum() { Object ckm = context.getContextValue(CURRENT_KM); @@ -172,9 +133,55 @@ if (getCurrentGaugeDatum() != 0d) { // Show the W[*m] axis even if there is no data. plot.setRangeAxis(1, createYAxis(YAXIS.W.idx)); + syncWAxisRanges(); } } + // XXX This is a copy of DischargeCurveGenerator syncWAxisRanges + // even without fancy Q Symetry this class should inherit + // from there.. + 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()); + } + @Override public void doOut(ArtifactAndFacet aaf, ThemeDocument doc, boolean visible) { logger.debug("doOut: " + aaf.getFacetName());