annotate artifacts/src/main/java/org/dive4elements/river/exports/ChartArea.java @ 8316:c086b06b81e5

Make ChartArea and thus annotations sensible for logarithmic axes (plus some minor cleanup).
author "Tom Gottfried <tom@intevation.de>"
date Wed, 24 Sep 2014 13:29:34 +0200
parents af13ceeba52a
children ff0e5386de70
rev   line source
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
2 * Software engineering by Intevation GmbH
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
3 *
5994
af13ceeba52a Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
4 * This file is Free Software under the GNU AGPL (>=v3)
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the
5994
af13ceeba52a Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
6 * documentation coming with Dive4Elements River for details.
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
7 */
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
8
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3259
diff changeset
9 package org.dive4elements.river.exports;
3242
1dca41dba135 Move annotation code to base class ChartGenerator
Christian Lins <christian.lins@intevation.de>
parents:
diff changeset
10
1dca41dba135 Move annotation code to base class ChartGenerator
Christian Lins <christian.lins@intevation.de>
parents:
diff changeset
11 import org.jfree.chart.axis.ValueAxis;
8316
c086b06b81e5 Make ChartArea and thus annotations sensible for logarithmic axes (plus some minor cleanup).
"Tom Gottfried <tom@intevation.de>"
parents: 5994
diff changeset
12 import org.jfree.chart.axis.LogarithmicAxis;
3242
1dca41dba135 Move annotation code to base class ChartGenerator
Christian Lins <christian.lins@intevation.de>
parents:
diff changeset
13
3257
2aca387333d6 Removed superfluous imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3242
diff changeset
14 /** Two Ranges that span a rectangular area. */
2aca387333d6 Removed superfluous imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3242
diff changeset
15 public class ChartArea {
8316
c086b06b81e5 Make ChartArea and thus annotations sensible for logarithmic axes (plus some minor cleanup).
"Tom Gottfried <tom@intevation.de>"
parents: 5994
diff changeset
16 protected double xLower;
c086b06b81e5 Make ChartArea and thus annotations sensible for logarithmic axes (plus some minor cleanup).
"Tom Gottfried <tom@intevation.de>"
parents: 5994
diff changeset
17 protected double xUpper;
c086b06b81e5 Make ChartArea and thus annotations sensible for logarithmic axes (plus some minor cleanup).
"Tom Gottfried <tom@intevation.de>"
parents: 5994
diff changeset
18 protected double xLength;
c086b06b81e5 Make ChartArea and thus annotations sensible for logarithmic axes (plus some minor cleanup).
"Tom Gottfried <tom@intevation.de>"
parents: 5994
diff changeset
19 protected double yLower;
c086b06b81e5 Make ChartArea and thus annotations sensible for logarithmic axes (plus some minor cleanup).
"Tom Gottfried <tom@intevation.de>"
parents: 5994
diff changeset
20 protected double yUpper;
c086b06b81e5 Make ChartArea and thus annotations sensible for logarithmic axes (plus some minor cleanup).
"Tom Gottfried <tom@intevation.de>"
parents: 5994
diff changeset
21 protected double yLength;
c086b06b81e5 Make ChartArea and thus annotations sensible for logarithmic axes (plus some minor cleanup).
"Tom Gottfried <tom@intevation.de>"
parents: 5994
diff changeset
22 protected boolean xIsLog;
c086b06b81e5 Make ChartArea and thus annotations sensible for logarithmic axes (plus some minor cleanup).
"Tom Gottfried <tom@intevation.de>"
parents: 5994
diff changeset
23 protected boolean yIsLog;
3242
1dca41dba135 Move annotation code to base class ChartGenerator
Christian Lins <christian.lins@intevation.de>
parents:
diff changeset
24
3257
2aca387333d6 Removed superfluous imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3242
diff changeset
25 public ChartArea(ValueAxis axisX, ValueAxis axisY) {
8316
c086b06b81e5 Make ChartArea and thus annotations sensible for logarithmic axes (plus some minor cleanup).
"Tom Gottfried <tom@intevation.de>"
parents: 5994
diff changeset
26 this.xLower = axisX.getRange().getLowerBound();
c086b06b81e5 Make ChartArea and thus annotations sensible for logarithmic axes (plus some minor cleanup).
"Tom Gottfried <tom@intevation.de>"
parents: 5994
diff changeset
27 this.xUpper = axisX.getRange().getUpperBound();
c086b06b81e5 Make ChartArea and thus annotations sensible for logarithmic axes (plus some minor cleanup).
"Tom Gottfried <tom@intevation.de>"
parents: 5994
diff changeset
28 this.xLength= axisX.getRange().getLength();
c086b06b81e5 Make ChartArea and thus annotations sensible for logarithmic axes (plus some minor cleanup).
"Tom Gottfried <tom@intevation.de>"
parents: 5994
diff changeset
29 this.yLower = axisY.getRange().getLowerBound();
c086b06b81e5 Make ChartArea and thus annotations sensible for logarithmic axes (plus some minor cleanup).
"Tom Gottfried <tom@intevation.de>"
parents: 5994
diff changeset
30 this.yUpper = axisY.getRange().getUpperBound();
c086b06b81e5 Make ChartArea and thus annotations sensible for logarithmic axes (plus some minor cleanup).
"Tom Gottfried <tom@intevation.de>"
parents: 5994
diff changeset
31 this.yLength= axisY.getRange().getLength();
c086b06b81e5 Make ChartArea and thus annotations sensible for logarithmic axes (plus some minor cleanup).
"Tom Gottfried <tom@intevation.de>"
parents: 5994
diff changeset
32 this.xIsLog = axisX instanceof LogarithmicAxis;
c086b06b81e5 Make ChartArea and thus annotations sensible for logarithmic axes (plus some minor cleanup).
"Tom Gottfried <tom@intevation.de>"
parents: 5994
diff changeset
33 this.yIsLog = axisY instanceof LogarithmicAxis;
3257
2aca387333d6 Removed superfluous imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3242
diff changeset
34 }
3242
1dca41dba135 Move annotation code to base class ChartGenerator
Christian Lins <christian.lins@intevation.de>
parents:
diff changeset
35
3257
2aca387333d6 Removed superfluous imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3242
diff changeset
36 public double ofLeft(double percent) {
8316
c086b06b81e5 Make ChartArea and thus annotations sensible for logarithmic axes (plus some minor cleanup).
"Tom Gottfried <tom@intevation.de>"
parents: 5994
diff changeset
37 if (xIsLog) {
c086b06b81e5 Make ChartArea and thus annotations sensible for logarithmic axes (plus some minor cleanup).
"Tom Gottfried <tom@intevation.de>"
parents: 5994
diff changeset
38 return Math.pow(10,
c086b06b81e5 Make ChartArea and thus annotations sensible for logarithmic axes (plus some minor cleanup).
"Tom Gottfried <tom@intevation.de>"
parents: 5994
diff changeset
39 Math.log10(xLower)
c086b06b81e5 Make ChartArea and thus annotations sensible for logarithmic axes (plus some minor cleanup).
"Tom Gottfried <tom@intevation.de>"
parents: 5994
diff changeset
40 + Math.log10(xUpper / xLower) * percent
c086b06b81e5 Make ChartArea and thus annotations sensible for logarithmic axes (plus some minor cleanup).
"Tom Gottfried <tom@intevation.de>"
parents: 5994
diff changeset
41 );
c086b06b81e5 Make ChartArea and thus annotations sensible for logarithmic axes (plus some minor cleanup).
"Tom Gottfried <tom@intevation.de>"
parents: 5994
diff changeset
42 }
c086b06b81e5 Make ChartArea and thus annotations sensible for logarithmic axes (plus some minor cleanup).
"Tom Gottfried <tom@intevation.de>"
parents: 5994
diff changeset
43 return xLower + xLength * percent;
3242
1dca41dba135 Move annotation code to base class ChartGenerator
Christian Lins <christian.lins@intevation.de>
parents:
diff changeset
44 }
3257
2aca387333d6 Removed superfluous imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3242
diff changeset
45
2aca387333d6 Removed superfluous imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3242
diff changeset
46 public double ofRight(double percent) {
8316
c086b06b81e5 Make ChartArea and thus annotations sensible for logarithmic axes (plus some minor cleanup).
"Tom Gottfried <tom@intevation.de>"
parents: 5994
diff changeset
47 if (xIsLog) {
c086b06b81e5 Make ChartArea and thus annotations sensible for logarithmic axes (plus some minor cleanup).
"Tom Gottfried <tom@intevation.de>"
parents: 5994
diff changeset
48 return Math.pow(10,
c086b06b81e5 Make ChartArea and thus annotations sensible for logarithmic axes (plus some minor cleanup).
"Tom Gottfried <tom@intevation.de>"
parents: 5994
diff changeset
49 Math.log10(xUpper)
c086b06b81e5 Make ChartArea and thus annotations sensible for logarithmic axes (plus some minor cleanup).
"Tom Gottfried <tom@intevation.de>"
parents: 5994
diff changeset
50 - Math.log10(xUpper / xLower) * percent
c086b06b81e5 Make ChartArea and thus annotations sensible for logarithmic axes (plus some minor cleanup).
"Tom Gottfried <tom@intevation.de>"
parents: 5994
diff changeset
51 );
c086b06b81e5 Make ChartArea and thus annotations sensible for logarithmic axes (plus some minor cleanup).
"Tom Gottfried <tom@intevation.de>"
parents: 5994
diff changeset
52 }
c086b06b81e5 Make ChartArea and thus annotations sensible for logarithmic axes (plus some minor cleanup).
"Tom Gottfried <tom@intevation.de>"
parents: 5994
diff changeset
53 return xUpper - xLength * percent;
3257
2aca387333d6 Removed superfluous imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3242
diff changeset
54 }
2aca387333d6 Removed superfluous imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3242
diff changeset
55
2aca387333d6 Removed superfluous imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3242
diff changeset
56 public double ofGround(double percent) {
8316
c086b06b81e5 Make ChartArea and thus annotations sensible for logarithmic axes (plus some minor cleanup).
"Tom Gottfried <tom@intevation.de>"
parents: 5994
diff changeset
57 if (yIsLog) {
c086b06b81e5 Make ChartArea and thus annotations sensible for logarithmic axes (plus some minor cleanup).
"Tom Gottfried <tom@intevation.de>"
parents: 5994
diff changeset
58 return Math.pow(10,
c086b06b81e5 Make ChartArea and thus annotations sensible for logarithmic axes (plus some minor cleanup).
"Tom Gottfried <tom@intevation.de>"
parents: 5994
diff changeset
59 Math.log10(yLower)
c086b06b81e5 Make ChartArea and thus annotations sensible for logarithmic axes (plus some minor cleanup).
"Tom Gottfried <tom@intevation.de>"
parents: 5994
diff changeset
60 + Math.log10(yUpper / yLower) * percent
c086b06b81e5 Make ChartArea and thus annotations sensible for logarithmic axes (plus some minor cleanup).
"Tom Gottfried <tom@intevation.de>"
parents: 5994
diff changeset
61 );
c086b06b81e5 Make ChartArea and thus annotations sensible for logarithmic axes (plus some minor cleanup).
"Tom Gottfried <tom@intevation.de>"
parents: 5994
diff changeset
62 }
c086b06b81e5 Make ChartArea and thus annotations sensible for logarithmic axes (plus some minor cleanup).
"Tom Gottfried <tom@intevation.de>"
parents: 5994
diff changeset
63 return yLower + yLength * percent;
3257
2aca387333d6 Removed superfluous imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3242
diff changeset
64 }
2aca387333d6 Removed superfluous imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3242
diff changeset
65
2aca387333d6 Removed superfluous imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3242
diff changeset
66 public double atTop() {
8316
c086b06b81e5 Make ChartArea and thus annotations sensible for logarithmic axes (plus some minor cleanup).
"Tom Gottfried <tom@intevation.de>"
parents: 5994
diff changeset
67 return yUpper;
3257
2aca387333d6 Removed superfluous imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3242
diff changeset
68 }
2aca387333d6 Removed superfluous imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3242
diff changeset
69
2aca387333d6 Removed superfluous imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3242
diff changeset
70 public double atGround() {
8316
c086b06b81e5 Make ChartArea and thus annotations sensible for logarithmic axes (plus some minor cleanup).
"Tom Gottfried <tom@intevation.de>"
parents: 5994
diff changeset
71 return yLower;
3257
2aca387333d6 Removed superfluous imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3242
diff changeset
72 }
2aca387333d6 Removed superfluous imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3242
diff changeset
73
2aca387333d6 Removed superfluous imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3242
diff changeset
74 public double atRight() {
8316
c086b06b81e5 Make ChartArea and thus annotations sensible for logarithmic axes (plus some minor cleanup).
"Tom Gottfried <tom@intevation.de>"
parents: 5994
diff changeset
75 return xUpper;
3257
2aca387333d6 Removed superfluous imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3242
diff changeset
76 }
2aca387333d6 Removed superfluous imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3242
diff changeset
77
2aca387333d6 Removed superfluous imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3242
diff changeset
78 public double atLeft() {
8316
c086b06b81e5 Make ChartArea and thus annotations sensible for logarithmic axes (plus some minor cleanup).
"Tom Gottfried <tom@intevation.de>"
parents: 5994
diff changeset
79 return xLower;
3257
2aca387333d6 Removed superfluous imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3242
diff changeset
80 }
2aca387333d6 Removed superfluous imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3242
diff changeset
81
2aca387333d6 Removed superfluous imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3242
diff changeset
82 public double above(double percent, double base) {
8316
c086b06b81e5 Make ChartArea and thus annotations sensible for logarithmic axes (plus some minor cleanup).
"Tom Gottfried <tom@intevation.de>"
parents: 5994
diff changeset
83 if (yIsLog) {
c086b06b81e5 Make ChartArea and thus annotations sensible for logarithmic axes (plus some minor cleanup).
"Tom Gottfried <tom@intevation.de>"
parents: 5994
diff changeset
84 return Math.pow(10,
c086b06b81e5 Make ChartArea and thus annotations sensible for logarithmic axes (plus some minor cleanup).
"Tom Gottfried <tom@intevation.de>"
parents: 5994
diff changeset
85 Math.log10(base)
c086b06b81e5 Make ChartArea and thus annotations sensible for logarithmic axes (plus some minor cleanup).
"Tom Gottfried <tom@intevation.de>"
parents: 5994
diff changeset
86 + Math.log10(yUpper / yLower) * percent
c086b06b81e5 Make ChartArea and thus annotations sensible for logarithmic axes (plus some minor cleanup).
"Tom Gottfried <tom@intevation.de>"
parents: 5994
diff changeset
87 );
c086b06b81e5 Make ChartArea and thus annotations sensible for logarithmic axes (plus some minor cleanup).
"Tom Gottfried <tom@intevation.de>"
parents: 5994
diff changeset
88 }
c086b06b81e5 Make ChartArea and thus annotations sensible for logarithmic axes (plus some minor cleanup).
"Tom Gottfried <tom@intevation.de>"
parents: 5994
diff changeset
89 return base + yLength * percent;
3257
2aca387333d6 Removed superfluous imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3242
diff changeset
90 }
2aca387333d6 Removed superfluous imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3242
diff changeset
91 }
3259
9422b559b2d5 Added vim lines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3257
diff changeset
92 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org