annotate artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowDepthChartExtender.java @ 9602:6b2496d71936

Reimplemented baseline for tkh. Extended area-dataset to be able to draw baseline.
author gernotbelger
date Tue, 12 Feb 2019 14:08:16 +0100
parents 8596f95673b1
children
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 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
13 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
14 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
15 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
16
ffebc94cf679 Flow-depth-axis and tkh-axis are now synchronized at 0. Show baseline for charts with tkhAxis
gernotbelger
parents:
diff changeset
17 /**
ffebc94cf679 Flow-depth-axis and tkh-axis are now synchronized at 0. Show baseline for charts with tkhAxis
gernotbelger
parents:
diff changeset
18 * @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
19 */
ffebc94cf679 Flow-depth-axis and tkh-axis are now synchronized at 0. Show baseline for charts with tkhAxis
gernotbelger
parents:
diff changeset
20 public class FlowDepthChartExtender implements ChartExtender {
8937
8596f95673b1 Tkh theme should only be pressed to bottom if other themes are present
gernotbelger
parents: 8893
diff changeset
21
8596f95673b1 Tkh theme should only be pressed to bottom if other themes are present
gernotbelger
parents: 8893
diff changeset
22 private static final String TKH_AXIS = "tkhAxis";
8596f95673b1 Tkh theme should only be pressed to bottom if other themes are present
gernotbelger
parents: 8893
diff changeset
23
8596f95673b1 Tkh theme should only be pressed to bottom if other themes are present
gernotbelger
parents: 8893
diff changeset
24 private static final String FLOWDEPTH_AXIS = "flowdepthAxis";
8596f95673b1 Tkh theme should only be pressed to bottom if other themes are present
gernotbelger
parents: 8893
diff changeset
25
8596f95673b1 Tkh theme should only be pressed to bottom if other themes are present
gernotbelger
parents: 8893
diff changeset
26 @Override
8596f95673b1 Tkh theme should only be pressed to bottom if other themes are present
gernotbelger
parents: 8893
diff changeset
27 public void beforeAutoZoom(final DiagramGenerator generator) {
8596f95673b1 Tkh theme should only be pressed to bottom if other themes are present
gernotbelger
parents: 8893
diff changeset
28 final ValueAxis tkhAxis = generator.getAxis(TKH_AXIS);
8596f95673b1 Tkh theme should only be pressed to bottom if other themes are present
gernotbelger
parents: 8893
diff changeset
29 if (tkhAxis != null) {
8596f95673b1 Tkh theme should only be pressed to bottom if other themes are present
gernotbelger
parents: 8893
diff changeset
30 /* If tkh is not the only dataset, we push it to the bottom */
8596f95673b1 Tkh theme should only be pressed to bottom if other themes are present
gernotbelger
parents: 8893
diff changeset
31 final int numYAxes = generator.getNumYAxes();
8596f95673b1 Tkh theme should only be pressed to bottom if other themes are present
gernotbelger
parents: 8893
diff changeset
32 if (numYAxes > 1)
8596f95673b1 Tkh theme should only be pressed to bottom if other themes are present
gernotbelger
parents: 8893
diff changeset
33 tkhAxis.setUpperMargin(4.0);
8596f95673b1 Tkh theme should only be pressed to bottom if other themes are present
gernotbelger
parents: 8893
diff changeset
34 }
8596f95673b1 Tkh theme should only be pressed to bottom if other themes are present
gernotbelger
parents: 8893
diff changeset
35 }
8596f95673b1 Tkh theme should only be pressed to bottom if other themes are present
gernotbelger
parents: 8893
diff changeset
36
8893
ffebc94cf679 Flow-depth-axis and tkh-axis are now synchronized at 0. Show baseline for charts with tkhAxis
gernotbelger
parents:
diff changeset
37 /**
ffebc94cf679 Flow-depth-axis and tkh-axis are now synchronized at 0. Show baseline for charts with tkhAxis
gernotbelger
parents:
diff changeset
38 * 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
39 * 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
40 */
ffebc94cf679 Flow-depth-axis and tkh-axis are now synchronized at 0. Show baseline for charts with tkhAxis
gernotbelger
parents:
diff changeset
41 @Override
ffebc94cf679 Flow-depth-axis and tkh-axis are now synchronized at 0. Show baseline for charts with tkhAxis
gernotbelger
parents:
diff changeset
42 public void afterAutoZoom(final DiagramGenerator generator) {
8937
8596f95673b1 Tkh theme should only be pressed to bottom if other themes are present
gernotbelger
parents: 8893
diff changeset
43 final ValueAxis axis1 = generator.getAxis(FLOWDEPTH_AXIS);
8596f95673b1 Tkh theme should only be pressed to bottom if other themes are present
gernotbelger
parents: 8893
diff changeset
44 final ValueAxis axis2 = generator.getAxis(TKH_AXIS);
8893
ffebc94cf679 Flow-depth-axis and tkh-axis are now synchronized at 0. Show baseline for charts with tkhAxis
gernotbelger
parents:
diff changeset
45 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
46 return;
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 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
49 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
50 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
51
ffebc94cf679 Flow-depth-axis and tkh-axis are now synchronized at 0. Show baseline for charts with tkhAxis
gernotbelger
parents:
diff changeset
52 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
53 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
54
ffebc94cf679 Flow-depth-axis and tkh-axis are now synchronized at 0. Show baseline for charts with tkhAxis
gernotbelger
parents:
diff changeset
55 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
56 }
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 @Override
ffebc94cf679 Flow-depth-axis and tkh-axis are now synchronized at 0. Show baseline for charts with tkhAxis
gernotbelger
parents:
diff changeset
59 public void afterGenerateChart(final DiagramGenerator generator, final XYPlot plot) {
9602
6b2496d71936 Reimplemented baseline for tkh. Extended area-dataset to be able to draw baseline.
gernotbelger
parents: 8937
diff changeset
60 /* nothing to do */
8893
ffebc94cf679 Flow-depth-axis and tkh-axis are now synchronized at 0. Show baseline for charts with tkhAxis
gernotbelger
parents:
diff changeset
61 }
ffebc94cf679 Flow-depth-axis and tkh-axis are now synchronized at 0. Show baseline for charts with tkhAxis
gernotbelger
parents:
diff changeset
62 }

http://dive4elements.wald.intevation.org