comparison flys-artifacts/src/main/java/org/dive4elements/river/exports/StyledSeriesBuilder.java @ 5831:bd047b71ab37

Repaired internal references
author Sascha L. Teichmann <teichmann@intevation.de>
date Thu, 25 Apr 2013 12:06:39 +0200
parents flys-artifacts/src/main/java/de/intevation/flys/exports/StyledSeriesBuilder.java@919d4939ebe6
children
comparison
equal deleted inserted replaced
5830:160f53ee0870 5831:bd047b71ab37
1 package org.dive4elements.river.exports;
2
3 import org.apache.log4j.Logger;
4
5 import org.jfree.data.xy.XYSeries;
6
7 import org.dive4elements.river.artifacts.model.WKms;
8 import org.dive4elements.river.artifacts.model.WQKms;
9 import org.dive4elements.river.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), false);
150 series.add(halveX, wqkms.getQ(i), false);
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), false);
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 qs the Qs to add, assumed same length than ws.
183 * @param ws the Ws to add, assumed same length than qs.
184 */
185 public static void addPointsQW(XYSeries series, double[] qs, double ws[]) {
186 if (ws == null || qs == null) {
187 return;
188 }
189
190 int size = qs.length;
191
192 for (int i = 0; i < size; i++) {
193 series.add(qs[i], ws[i], false);
194 }
195 }
196
197
198 /**
199 * Add points to series (q to 1st dim, w to 2nd dim).
200 *
201 * @param series Series to add points to.
202 * @param wwqq WWQQ to add to series.
203 */
204 public static void addPoints(XYSeries series, WWQQ wwqq) {
205 if (wwqq == null) {
206 return;
207 }
208
209 int size = wwqq.size();
210
211 for (int i = 0; i < size; i++) {
212 series.add(wwqq.getW1(i), wwqq.getW2(i), false);
213 }
214 }
215
216
217 /**
218 * Create a Series such that an infinitely big area can be filled
219 * between the newly created and the given series.
220 */
221 public static XYSeries createGroundAtInfinity(XYSeries series) {
222 XYSeries ground = new XYSeries(series.getKey() + /** TODO rand + */ "INF");
223 ground.add(series.getMinX(), -BIG_DOUBLE_VALUE);
224 ground.add(series.getMaxX(), -BIG_DOUBLE_VALUE);
225 return ground;
226 }
227
228
229 /**
230 * Create a Series such that an infinitely big area can be filled
231 * between the newly created and the given series.
232 */
233 public static XYSeries createCeilingAtInfinity(XYSeries series) {
234 XYSeries ground = new XYSeries(series.getKey() + /** TODO rand + */ "INF");
235 ground.add(series.getMinX(), BIG_DOUBLE_VALUE);
236 ground.add(series.getMaxX(), BIG_DOUBLE_VALUE);
237 return ground;
238 }
239 }
240 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org