comparison 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
comparison
equal deleted inserted replaced
8892:87a242425467 8893:ffebc94cf679
1 /** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde
2 * Software engineering by
3 * Björnsen Beratende Ingenieure GmbH
4 * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt
5 *
6 * This file is Free Software under the GNU AGPL (>=v3)
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the
8 * documentation coming with Dive4Elements River for details.
9 */
10 package org.dive4elements.river.artifacts.sinfo.flowdepth;
11
12 import java.awt.BasicStroke;
13 import java.awt.Stroke;
14
15 import org.dive4elements.river.exports.ChartExtender;
16 import org.dive4elements.river.exports.DiagramGenerator;
17 import org.jfree.chart.axis.ValueAxis;
18 import org.jfree.chart.plot.XYPlot;
19
20 /**
21 * @author Gernot Belger
22 */
23 public class FlowDepthChartExtender implements ChartExtender {
24 /**
25 * Synchronizes the location of '0' on the flow-depth-axis with the tkh-axis, by extending the lower bound of the
26 * flow-depth-axis.
27 */
28 @Override
29 public void afterAutoZoom(final DiagramGenerator generator) {
30 final ValueAxis axis1 = generator.getAxis("flowdepthAxis");
31 final ValueAxis axis2 = generator.getAxis("tkhAxis");
32 if (axis1 == null || axis2 == null)
33 return;
34
35 final double axis2lb = axis2.getLowerBound();
36 final double axis1ub = axis1.getUpperBound();
37 final double axis2ub = axis2.getUpperBound();
38
39 final double ratio = axis2lb / (axis2ub - axis2lb);
40 final double axis1lbNew = axis1ub / (1 / ratio + 1);
41
42 axis1.setLowerBound(axis1lbNew);
43 }
44
45 @Override
46 public void afterGenerateChart(final DiagramGenerator generator, final XYPlot plot) {
47
48 final ValueAxis tkhAxis = generator.getAxis("tkhAxis");
49 if (tkhAxis != null) {
50 /* show baseline if tkhAxis is present */
51
52 // TODO: it would probably better to configure this via the ChartSettings, but currently no chart settings are loaded,
53 // so it is unclear if that feature still works.
54 final Stroke baselineStroke = new BasicStroke(2, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER);
55 plot.setRangeZeroBaselineStroke(baselineStroke);
56 plot.setRangeZeroBaselineVisible(true);
57 }
58 }
59 }

http://dive4elements.wald.intevation.org