comparison gnv-artifacts/src/main/java/de/intevation/gnv/jfreechart/CompactXYItems.java @ 422:f426f55d4f7a

Added Ingo Weinzierl's special JFreeChart classes. gnv-artifacts/trunk@470 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Mon, 21 Dec 2009 16:47:45 +0000
parents
children c4156275c1e1
comparison
equal deleted inserted replaced
421:fd71ee76fa58 422:f426f55d4f7a
1 package de.intevation.gnv.jfreechart;
2
3 import java.io.Serializable;
4
5 /**
6 * @author Sascha Teichmann <sascha.teichmann@intevation.de>
7 * @author Ingo Weinzierl <ingo.weinzierl@intevation.de>
8 */
9 public class CompactXYItems
10 implements Serializable
11 {
12 protected double [] data;
13
14 public CompactXYItems(double [] data) {
15 this.data = data;
16 }
17
18 public double getX(int index) {
19 return data[index << 1];
20 }
21
22 public double getY(int index) {
23 return data[(index << 1)+1];
24 }
25
26 public void get(int index, double [] xy) {
27 xy[0] = data[index = (index << 1) + 1];
28 xy[1] = data[index + 1];
29 }
30
31 public double [] getData() {
32 return data;
33 }
34
35 public void setData(double [] data) {
36 this.data = data;
37 }
38
39 public int size() {
40 return data.length >> 1;
41 }
42
43 public double [] calculateBoundingBox(double [] bbox) {
44 for (int i = 0; i < data.length;) {
45 double x = data[i++];
46 double y = data[i++];
47 if (x < bbox[0]) bbox[0] = x;
48 if (y < bbox[1]) bbox[1] = y;
49 if (x > bbox[2]) bbox[2] = x;
50 if (y > bbox[3]) bbox[3] = y;
51 }
52 return bbox;
53 }
54
55 public String toString() {
56 StringBuilder sb = new StringBuilder();
57 for (int i = 0; i < data.length;) {
58 if (i > 0) sb.append("; ");
59 sb.append('(');
60 sb.append(data[i++]);
61 sb.append(", ");
62 sb.append(data[i++]);
63 sb.append(')');
64 }
65 return sb.toString();
66 }
67
68
69 public double getMinX() {
70 double lower = Double.POSITIVE_INFINITY;
71
72 for (int i = 0; i < data.length; i += 2) {
73 double x = data[i];
74
75 if (!Double.isNaN(x)) {
76 lower = Math.min(lower, x);
77 }
78 }
79
80 return lower;
81 }
82
83
84 public double getMaxX() {
85 double upper = Double.NEGATIVE_INFINITY;
86
87 for (int i = 0; i < data.length; i += 2) {
88 double x = data[i];
89
90 if (!Double.isNaN(x)) {
91 upper = Math.max(upper, x);
92 }
93 }
94
95 return upper;
96 }
97
98
99 public double getMinY() {
100 double lower = Double.POSITIVE_INFINITY;
101
102 for (int i = 1; i < data.length; i += 2) {
103 double y = data[i];
104
105 if (!Double.isNaN(y)) {
106 lower = Math.min(lower, y);
107 }
108 }
109
110 return lower;
111 }
112
113
114 public double getMaxY() {
115 double upper = Double.NEGATIVE_INFINITY;
116
117 for (int i = 1; i < data.length; i += 2) {
118 double y = data[i];
119
120 if (!Double.isNaN(y)) {
121 upper = Math.max(upper, y);
122 }
123 }
124
125 return upper;
126 }
127 }
128 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org