Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/exports/ChartArea.java @ 9445:ff0e5386de70
Variant for inverted y axis added
author | mschaefer |
---|---|
date | Tue, 21 Aug 2018 14:16:15 +0200 |
parents | c086b06b81e5 |
children |
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(); |
9445 | 29 if (axisY.isInverted()) { |
30 this.yLower = axisY.getRange().getUpperBound(); | |
31 this.yUpper = axisY.getRange().getLowerBound(); | |
32 this.yLength = -axisY.getRange().getLength(); | |
33 } | |
34 else { | |
35 this.yLower = axisY.getRange().getLowerBound(); | |
36 this.yUpper = axisY.getRange().getUpperBound(); | |
37 this.yLength = axisY.getRange().getLength(); | |
38 } | |
8316
c086b06b81e5
Make ChartArea and thus annotations sensible for logarithmic axes (plus some minor cleanup).
"Tom Gottfried <tom@intevation.de>"
parents:
5994
diff
changeset
|
39 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
|
40 this.yIsLog = axisY instanceof LogarithmicAxis; |
3257
2aca387333d6
Removed superfluous imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3242
diff
changeset
|
41 } |
3242
1dca41dba135
Move annotation code to base class ChartGenerator
Christian Lins <christian.lins@intevation.de>
parents:
diff
changeset
|
42 |
3257
2aca387333d6
Removed superfluous imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3242
diff
changeset
|
43 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
|
44 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
|
45 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
|
46 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
|
47 + 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
|
48 ); |
c086b06b81e5
Make ChartArea and thus annotations sensible for logarithmic axes (plus some minor cleanup).
"Tom Gottfried <tom@intevation.de>"
parents:
5994
diff
changeset
|
49 } |
c086b06b81e5
Make ChartArea and thus annotations sensible for logarithmic axes (plus some minor cleanup).
"Tom Gottfried <tom@intevation.de>"
parents:
5994
diff
changeset
|
50 return xLower + xLength * percent; |
3242
1dca41dba135
Move annotation code to base class ChartGenerator
Christian Lins <christian.lins@intevation.de>
parents:
diff
changeset
|
51 } |
3257
2aca387333d6
Removed superfluous imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3242
diff
changeset
|
52 |
2aca387333d6
Removed superfluous imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3242
diff
changeset
|
53 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
|
54 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
|
55 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
|
56 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
|
57 - 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
|
58 ); |
c086b06b81e5
Make ChartArea and thus annotations sensible for logarithmic axes (plus some minor cleanup).
"Tom Gottfried <tom@intevation.de>"
parents:
5994
diff
changeset
|
59 } |
c086b06b81e5
Make ChartArea and thus annotations sensible for logarithmic axes (plus some minor cleanup).
"Tom Gottfried <tom@intevation.de>"
parents:
5994
diff
changeset
|
60 return xUpper - xLength * percent; |
3257
2aca387333d6
Removed superfluous imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3242
diff
changeset
|
61 } |
2aca387333d6
Removed superfluous imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3242
diff
changeset
|
62 |
2aca387333d6
Removed superfluous imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3242
diff
changeset
|
63 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
|
64 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
|
65 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
|
66 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
|
67 + 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
|
68 ); |
c086b06b81e5
Make ChartArea and thus annotations sensible for logarithmic axes (plus some minor cleanup).
"Tom Gottfried <tom@intevation.de>"
parents:
5994
diff
changeset
|
69 } |
c086b06b81e5
Make ChartArea and thus annotations sensible for logarithmic axes (plus some minor cleanup).
"Tom Gottfried <tom@intevation.de>"
parents:
5994
diff
changeset
|
70 return yLower + yLength * percent; |
3257
2aca387333d6
Removed superfluous imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3242
diff
changeset
|
71 } |
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 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
|
74 return yUpper; |
3257
2aca387333d6
Removed superfluous imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3242
diff
changeset
|
75 } |
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 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
|
78 return yLower; |
3257
2aca387333d6
Removed superfluous imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3242
diff
changeset
|
79 } |
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 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
|
82 return xUpper; |
3257
2aca387333d6
Removed superfluous imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3242
diff
changeset
|
83 } |
2aca387333d6
Removed superfluous imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3242
diff
changeset
|
84 |
2aca387333d6
Removed superfluous imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3242
diff
changeset
|
85 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
|
86 return xLower; |
3257
2aca387333d6
Removed superfluous imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3242
diff
changeset
|
87 } |
2aca387333d6
Removed superfluous imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3242
diff
changeset
|
88 |
2aca387333d6
Removed superfluous imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3242
diff
changeset
|
89 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
|
90 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
|
91 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
|
92 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
|
93 + 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
|
94 ); |
c086b06b81e5
Make ChartArea and thus annotations sensible for logarithmic axes (plus some minor cleanup).
"Tom Gottfried <tom@intevation.de>"
parents:
5994
diff
changeset
|
95 } |
c086b06b81e5
Make ChartArea and thus annotations sensible for logarithmic axes (plus some minor cleanup).
"Tom Gottfried <tom@intevation.de>"
parents:
5994
diff
changeset
|
96 return base + yLength * percent; |
3257
2aca387333d6
Removed superfluous imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3242
diff
changeset
|
97 } |
2aca387333d6
Removed superfluous imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3242
diff
changeset
|
98 } |
3259
9422b559b2d5
Added vim lines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3257
diff
changeset
|
99 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |