# HG changeset patch
# User gernotbelger
# Date 1518698839 -3600
# Node ID ffebc94cf67938ef2616e6bbdbc3b0071c0b17a2
# Parent 87a2424254670dc889965fe987f22cf32091c986
Flow-depth-axis and tkh-axis are now synchronized at 0. Show baseline for charts with tkhAxis
diff -r 87a242425467 -r ffebc94cf679 artifacts/doc/conf/generators/longitudinal-diagram-defaults.xml
--- a/artifacts/doc/conf/generators/longitudinal-diagram-defaults.xml Thu Feb 15 13:46:35 2018 +0100
+++ b/artifacts/doc/conf/generators/longitudinal-diagram-defaults.xml Thu Feb 15 13:47:19 2018 +0100
@@ -14,7 +14,7 @@
-
+
@@ -45,6 +45,8 @@
-
+
+
+
\ No newline at end of file
diff -r 87a242425467 -r ffebc94cf679 artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowDepthChartExtender.java
--- /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