Mercurial > dive4elements > river
diff artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowDepthChartExtender.java @ 8893:ffebc94cf679
Flow-depth-axis and tkh-axis are now synchronized at 0. Show baseline for charts with tkhAxis
author | gernotbelger |
---|---|
date | Thu, 15 Feb 2018 13:47:19 +0100 |
parents | |
children | 8596f95673b1 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowDepthChartExtender.java Thu Feb 15 13:47:19 2018 +0100 @@ -0,0 +1,59 @@ +/** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde + * Software engineering by + * Björnsen Beratende Ingenieure GmbH + * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt + * + * This file is Free Software under the GNU AGPL (>=v3) + * and comes with ABSOLUTELY NO WARRANTY! Check out the + * documentation coming with Dive4Elements River for details. + */ +package org.dive4elements.river.artifacts.sinfo.flowdepth; + +import java.awt.BasicStroke; +import java.awt.Stroke; + +import org.dive4elements.river.exports.ChartExtender; +import org.dive4elements.river.exports.DiagramGenerator; +import org.jfree.chart.axis.ValueAxis; +import org.jfree.chart.plot.XYPlot; + +/** + * @author Gernot Belger + */ +public class FlowDepthChartExtender implements ChartExtender { + /** + * Synchronizes the location of '0' on the flow-depth-axis with the tkh-axis, by extending the lower bound of the + * flow-depth-axis. + */ + @Override + public void afterAutoZoom(final DiagramGenerator generator) { + final ValueAxis axis1 = generator.getAxis("flowdepthAxis"); + final ValueAxis axis2 = generator.getAxis("tkhAxis"); + if (axis1 == null || axis2 == null) + return; + + final double axis2lb = axis2.getLowerBound(); + final double axis1ub = axis1.getUpperBound(); + final double axis2ub = axis2.getUpperBound(); + + final double ratio = axis2lb / (axis2ub - axis2lb); + final double axis1lbNew = axis1ub / (1 / ratio + 1); + + axis1.setLowerBound(axis1lbNew); + } + + @Override + public void afterGenerateChart(final DiagramGenerator generator, final XYPlot plot) { + + final ValueAxis tkhAxis = generator.getAxis("tkhAxis"); + if (tkhAxis != null) { + /* show baseline if tkhAxis is present */ + + // TODO: it would probably better to configure this via the ChartSettings, but currently no chart settings are loaded, + // so it is unclear if that feature still works. + final Stroke baselineStroke = new BasicStroke(2, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER); + plot.setRangeZeroBaselineStroke(baselineStroke); + plot.setRangeZeroBaselineVisible(true); + } + } +} \ No newline at end of file