changeset 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 87a242425467
children a66f2a7c4f84
files artifacts/doc/conf/generators/longitudinal-diagram-defaults.xml artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowDepthChartExtender.java
diffstat 2 files changed, 63 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- 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 @@
     <axis name="Velocity"/>
     <axis name="Tau"/>
     <axis name="Q" include-zero="true"/>
-    <axis name="FlowdepthAxis" include-zero="true"/>
+    <axis name="flowdepthAxis" include-zero="false"  />
     <axis name="tkhAxis" include-zero="true" upperMargin="4.0" />
     <domain-axis key="chart.longitudinal.section.xaxis.label" default="Fluss-Km" inverted="org.dive4elements.river.exports.IsKmUpEvaluator()">
         <arg expr="artifact.river"/>
@@ -45,6 +45,8 @@
     <processor class="org.dive4elements.river.exports.process.BedHeightProcessor"          axis="W"/>
 
     <!-- S-INFO -->
-    <processor class="org.dive4elements.river.artifacts.sinfo.flowdepth.FlowDepthProcessor" axis="FlowdepthAxis"/>
+    <processor class="org.dive4elements.river.artifacts.sinfo.flowdepth.FlowDepthProcessor" axis="flowdepthAxis"/>
     <processor class="org.dive4elements.river.artifacts.sinfo.flowdepth.TkhProcessor" axis="tkhAxis"/>
+    
+    <chartextender class="org.dive4elements.river.artifacts.sinfo.flowdepth.FlowDepthChartExtender" />
 </longitudinal-defaults>
\ No newline at end of file
--- /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

http://dive4elements.wald.intevation.org