comparison 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
comparison
equal deleted inserted replaced
8315:d4c501d2c098 8316:c086b06b81e5
7 */ 7 */
8 8
9 package org.dive4elements.river.exports; 9 package org.dive4elements.river.exports;
10 10
11 import org.jfree.chart.axis.ValueAxis; 11 import org.jfree.chart.axis.ValueAxis;
12 12 import org.jfree.chart.axis.LogarithmicAxis;
13 import org.jfree.data.Range;
14 13
15 /** Two Ranges that span a rectangular area. */ 14 /** Two Ranges that span a rectangular area. */
16 public class ChartArea { 15 public class ChartArea {
17 protected Range xRange; 16 protected double xLower;
18 protected Range yRange; 17 protected double xUpper;
19 18 protected double xLength;
20 public ChartArea(Range rangeX, Range rangeY) { 19 protected double yLower;
21 this.xRange = rangeX; 20 protected double yUpper;
22 this.yRange = rangeY; 21 protected double yLength;
23 } 22 protected boolean xIsLog;
23 protected boolean yIsLog;
24 24
25 public ChartArea(ValueAxis axisX, ValueAxis axisY) { 25 public ChartArea(ValueAxis axisX, ValueAxis axisY) {
26 this.xRange = axisX.getRange(); 26 this.xLower = axisX.getRange().getLowerBound();
27 this.yRange = axisY.getRange(); 27 this.xUpper = axisX.getRange().getUpperBound();
28 this.xLength= axisX.getRange().getLength();
29 this.yLower = axisY.getRange().getLowerBound();
30 this.yUpper = axisY.getRange().getUpperBound();
31 this.yLength= axisY.getRange().getLength();
32 this.xIsLog = axisX instanceof LogarithmicAxis;
33 this.yIsLog = axisY instanceof LogarithmicAxis;
28 } 34 }
29 35
30 public double ofLeft(double percent) { 36 public double ofLeft(double percent) {
31 return xRange.getLowerBound() 37 if (xIsLog) {
32 + xRange.getLength() * percent; 38 return Math.pow(10,
39 Math.log10(xLower)
40 + Math.log10(xUpper / xLower) * percent
41 );
42 }
43 return xLower + xLength * percent;
33 } 44 }
34 45
35 public double ofRight(double percent) { 46 public double ofRight(double percent) {
36 return xRange.getUpperBound() 47 if (xIsLog) {
37 - xRange.getLength() * percent; 48 return Math.pow(10,
49 Math.log10(xUpper)
50 - Math.log10(xUpper / xLower) * percent
51 );
52 }
53 return xUpper - xLength * percent;
38 } 54 }
39 55
40 public double ofGround(double percent) { 56 public double ofGround(double percent) {
41 return yRange.getLowerBound() 57 if (yIsLog) {
42 + yRange.getLength() * percent; 58 return Math.pow(10,
59 Math.log10(yLower)
60 + Math.log10(yUpper / yLower) * percent
61 );
62 }
63 return yLower + yLength * percent;
43 } 64 }
44 65
45 public double atTop() { 66 public double atTop() {
46 return yRange.getUpperBound(); 67 return yUpper;
47 } 68 }
48 69
49 public double atGround() { 70 public double atGround() {
50 return yRange.getLowerBound(); 71 return yLower;
51 } 72 }
52 73
53 public double atRight() { 74 public double atRight() {
54 return xRange.getUpperBound(); 75 return xUpper;
55 } 76 }
56 77
57 public double atLeft() { 78 public double atLeft() {
58 return xRange.getLowerBound(); 79 return xLower;
59 } 80 }
60 81
61 public double above(double percent, double base) { 82 public double above(double percent, double base) {
62 return base + yRange.getLength() * percent; 83 if (yIsLog) {
84 return Math.pow(10,
85 Math.log10(base)
86 + Math.log10(yUpper / yLower) * percent
87 );
88 }
89 return base + yLength * percent;
63 } 90 }
64 } 91 }
65 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 92 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org