comparison flys-artifacts/src/main/java/de/intevation/flys/exports/StyledSeriesBuilder.java @ 3468:f37e7e8907cb

merged flys-artifacts/2.8.1
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 28 Sep 2012 12:14:39 +0200
parents 2a8919e0ed28
children e62f70c2213d
comparison
equal deleted inserted replaced
3387:5ffad8bde8ad 3468:f37e7e8907cb
1 package de.intevation.flys.exports;
2
3 import org.apache.log4j.Logger;
4
5 import org.jfree.data.xy.XYSeries;
6
7 import de.intevation.flys.artifacts.model.WKms;
8 import de.intevation.flys.artifacts.model.WQKms;
9 import de.intevation.flys.artifacts.model.WWQQ;
10
11 /**
12 * Helper to create and modify StyledXYSeries.
13 */
14 public class StyledSeriesBuilder {
15
16 /**
17 * JFreeChart and the area calculation will fail if we use Double.INFINITY
18 * or Double.MAX_VALUE (probably because these are really used in
19 * calculations). We define and use a more handy value instead.
20 */
21 final static double BIG_DOUBLE_VALUE = 1234567d;
22
23 private static final Logger logger = Logger.getLogger
24 (StyledSeriesBuilder.class);
25
26
27 /**
28 * Trivial, hidden constructor.
29 */
30 private StyledSeriesBuilder() {
31 }
32
33
34 /**
35 * Add points to series.
36 *
37 * @param series Series to add points to.
38 * @param points Points to add to series, points[0] to 1st dim, points[1]
39 * to 2nd dim.
40 * @param skipNANs if true, skip NAN values in points parameter.
41 */
42 public static void addPoints(XYSeries series, double[][] points, boolean skipNANs) {
43 if (points == null || points.length <= 1) {
44 return;
45 }
46 double [] xPoints = points[0];
47 double [] yPoints = points[1];
48 for (int i = 0; i < xPoints.length; i++) {
49 if (skipNANs &&
50 (Double.isNaN(xPoints[i]) || Double.isNaN(yPoints[i]))) {
51 logger.warn ("Skipping NaN in StyledSeriesBuilder.");
52 continue;
53 }
54 series.add(xPoints[i], yPoints[i], false);
55 }
56 }
57
58
59 /**
60 * Add points to series (km to 1st dim, w to 2nd dim).
61 *
62 * @param series Series to add points to.
63 * @param wkms WKms to add to series.
64 */
65 public static void addPoints(XYSeries series, WKms wkms) {
66 if (wkms == null) {
67 return;
68 }
69
70 int size = wkms.size();
71
72 for (int i = 0; i < size; i++) {
73 series.add(wkms.getKm(i), wkms.getW(i), false);
74 }
75 }
76
77
78 /**
79 * Add points to dataset with an offset (shift all points by given amount).
80 * @param series series to add data to.
81 * @param wkms WKms of which the Ws will be shifted.
82 * @param off the offset.
83 */
84 public static void addUpperBand(XYSeries series, WKms wkms, double off) {
85 if (wkms == null) {
86 return;
87 }
88
89 int size = wkms.size();
90
91 for (int i = 0; i < size; i++) {
92 series.add(wkms.getKm(i), wkms.getW(i)+off, false);
93 }
94 }
95
96
97 /**
98 * Add points to dataset with an offset (shift all points 'down' by given
99 * amount).
100 * @param series series to add data to.
101 * @param wkms WKms of which the Ws will be shifted.
102 * @param off the offset.
103 */
104 public static void addLowerBand(XYSeries series, WKms wkms, double off) {
105 addUpperBand(series, wkms, -off);
106 }
107
108
109 /**
110 * Add points to series (km to 1st dim, q to 2nd dim).
111 *
112 * @param series Series to add points to.
113 * @param wqkms WQKms to add to series.
114 */
115 public static void addPointsKmQ(XYSeries series, WQKms wqkms) {
116 if (wqkms == null) {
117 return;
118 }
119
120 int size = wqkms.size();
121
122 for (int i = 0; i < size; i++) {
123 series.add(wqkms.getKm(i), wqkms.getQ(i), false);
124 }
125 }
126
127
128 /**
129 * Add points to series (km to 1st dim, q to 2nd dim), adding points
130 * to achieve a step-like curve.
131 *
132 * @param series Series to add points to.
133 * @param wqkms WQKms to add to series.
134 */
135 public static void addStepPointsKmQ(XYSeries series, WQKms wqkms) {
136 if (wqkms == null) {
137 return;
138 }
139
140 int size = wqkms.size();
141
142 for (int i = 0; i < size; i++) {
143 if (i==0) {
144 series.add(wqkms.getKm(i), wqkms.getQ(i), false);
145 }
146 else {
147 //Add two points.
148 double halveX = (wqkms.getKm(i-1) + wqkms.getKm(i)) / 2d;
149 series.add(halveX, wqkms.getQ(i-1));
150 series.add(halveX, wqkms.getQ(i));
151 }
152 if (i == size-1) {
153 series.add(wqkms.getKm(i), wqkms.getQ(i), false);
154 }
155 }
156 }
157
158
159 /**
160 * Add points to series (q to 1st dim, w to 2nd dim).
161 *
162 * @param series Series to add points to.
163 * @param wqkms WQKms to add to series.
164 */
165 public static void addPointsQW(XYSeries series, WQKms wqkms) {
166 if (wqkms == null) {
167 return;
168 }
169
170 int size = wqkms.size();
171
172 for (int i = 0; i < size; i++) {
173 series.add(wqkms.getQ(i), wqkms.getW(i));
174 }
175 }
176
177
178 /**
179 * Add points to series (q to 1st dim, w to 2nd dim).
180 *
181 * @param series Series to add points to.
182 * @param wwqq WWQQ to add to series.
183 */
184 public static void addPoints(XYSeries series, WWQQ wwqq) {
185 if (wwqq == null) {
186 return;
187 }
188
189 int size = wwqq.size();
190
191 for (int i = 0; i < size; i++) {
192 series.add(wwqq.getW1(i), wwqq.getW2(i));
193 }
194 }
195
196
197 /**
198 * Create a Series such that an infinitely big area can be filled
199 * between the newly created and the given series.
200 */
201 public static XYSeries createGroundAtInfinity(XYSeries series) {
202 XYSeries ground = new XYSeries(series.getKey() + /** TODO rand + */ "INF");
203 ground.add(series.getMinX(), -BIG_DOUBLE_VALUE);
204 ground.add(series.getMaxX(), -BIG_DOUBLE_VALUE);
205 return ground;
206 }
207
208
209 /**
210 * Create a Series such that an infinitely big area can be filled
211 * between the newly created and the given series.
212 */
213 public static XYSeries createCeilingAtInfinity(XYSeries series) {
214 XYSeries ground = new XYSeries(series.getKey() + /** TODO rand + */ "INF");
215 ground.add(series.getMinX(), BIG_DOUBLE_VALUE);
216 ground.add(series.getMaxX(), BIG_DOUBLE_VALUE);
217 return ground;
218 }
219 }
220 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org