annotate artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowDepthChartExtender.java @ 8937:8596f95673b1

Tkh theme should only be pressed to bottom if other themes are present
author gernotbelger
date Tue, 06 Mar 2018 17:08:51 +0100
parents ffebc94cf679
children 6b2496d71936
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 {
8937
8596f95673b1 Tkh theme should only be pressed to bottom if other themes are present
gernotbelger
parents: 8893
diff changeset
24
8596f95673b1 Tkh theme should only be pressed to bottom if other themes are present
gernotbelger
parents: 8893
diff changeset
25 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
26
8596f95673b1 Tkh theme should only be pressed to bottom if other themes are present
gernotbelger
parents: 8893
diff changeset
27 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
28
8596f95673b1 Tkh theme should only be pressed to bottom if other themes are present
gernotbelger
parents: 8893
diff changeset
29 @Override
8596f95673b1 Tkh theme should only be pressed to bottom if other themes are present
gernotbelger
parents: 8893
diff changeset
30 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
31 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
32 if (tkhAxis != null) {
8596f95673b1 Tkh theme should only be pressed to bottom if other themes are present
gernotbelger
parents: 8893
diff changeset
33 /* 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
34 final int numYAxes = generator.getNumYAxes();
8596f95673b1 Tkh theme should only be pressed to bottom if other themes are present
gernotbelger
parents: 8893
diff changeset
35 if (numYAxes > 1)
8596f95673b1 Tkh theme should only be pressed to bottom if other themes are present
gernotbelger
parents: 8893
diff changeset
36 tkhAxis.setUpperMargin(4.0);
8596f95673b1 Tkh theme should only be pressed to bottom if other themes are present
gernotbelger
parents: 8893
diff changeset
37 }
8596f95673b1 Tkh theme should only be pressed to bottom if other themes are present
gernotbelger
parents: 8893
diff changeset
38 }
8596f95673b1 Tkh theme should only be pressed to bottom if other themes are present
gernotbelger
parents: 8893
diff changeset
39
8893
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 * 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
42 * 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
43 */
ffebc94cf679 Flow-depth-axis and tkh-axis are now synchronized at 0. Show baseline for charts with tkhAxis
gernotbelger
parents:
diff changeset
44 @Override
ffebc94cf679 Flow-depth-axis and tkh-axis are now synchronized at 0. Show baseline for charts with tkhAxis
gernotbelger
parents:
diff changeset
45 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
46 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
47 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
48 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
49 return;
ffebc94cf679 Flow-depth-axis and tkh-axis are now synchronized at 0. Show baseline for charts with tkhAxis
gernotbelger
parents:
diff changeset
50
ffebc94cf679 Flow-depth-axis and tkh-axis are now synchronized at 0. Show baseline for charts with tkhAxis
gernotbelger
parents:
diff changeset
51 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
52 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
53 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
54
ffebc94cf679 Flow-depth-axis and tkh-axis are now synchronized at 0. Show baseline for charts with tkhAxis
gernotbelger
parents:
diff changeset
55 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
56 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
57
ffebc94cf679 Flow-depth-axis and tkh-axis are now synchronized at 0. Show baseline for charts with tkhAxis
gernotbelger
parents:
diff changeset
58 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
59 }
ffebc94cf679 Flow-depth-axis and tkh-axis are now synchronized at 0. Show baseline for charts with tkhAxis
gernotbelger
parents:
diff changeset
60
ffebc94cf679 Flow-depth-axis and tkh-axis are now synchronized at 0. Show baseline for charts with tkhAxis
gernotbelger
parents:
diff changeset
61 @Override
ffebc94cf679 Flow-depth-axis and tkh-axis are now synchronized at 0. Show baseline for charts with tkhAxis
gernotbelger
parents:
diff changeset
62 public void afterGenerateChart(final DiagramGenerator generator, final XYPlot plot) {
8937
8596f95673b1 Tkh theme should only be pressed to bottom if other themes are present
gernotbelger
parents: 8893
diff changeset
63 final ValueAxis tkhAxis = 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
64 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
65 /* 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
66
ffebc94cf679 Flow-depth-axis and tkh-axis are now synchronized at 0. Show baseline for charts with tkhAxis
gernotbelger
parents:
diff changeset
67 // 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
68 // 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
69 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
70 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
71 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
72 }
ffebc94cf679 Flow-depth-axis and tkh-axis are now synchronized at 0. Show baseline for charts with tkhAxis
gernotbelger
parents:
diff changeset
73 }
ffebc94cf679 Flow-depth-axis and tkh-axis are now synchronized at 0. Show baseline for charts with tkhAxis
gernotbelger
parents:
diff changeset
74 }

http://dive4elements.wald.intevation.org