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

http://dive4elements.wald.intevation.org