Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/exports/StyledSeriesBuilder.java @ 3318:dbe2f85bf160
merged flys-artifacts/2.8
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:14:35 +0200 |
parents | d9af29a4bb85 |
children | f091f2f55f88 |
comparison
equal
deleted
inserted
replaced
2987:98c7a46ec5ae | 3318:dbe2f85bf160 |
---|---|
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 series (km to 1st dim, q to 2nd dim). | |
80 * | |
81 * @param series Series to add points to. | |
82 * @param wqkms WQKms to add to series. | |
83 */ | |
84 public static void addPointsKmQ(XYSeries series, WQKms wqkms) { | |
85 if (wqkms == null) { | |
86 return; | |
87 } | |
88 | |
89 int size = wqkms.size(); | |
90 | |
91 for (int i = 0; i < size; i++) { | |
92 series.add(wqkms.getKm(i), wqkms.getQ(i), false); | |
93 } | |
94 } | |
95 | |
96 | |
97 /** | |
98 * Add points to series (km to 1st dim, q to 2nd dim), adding points | |
99 * to achieve a step-like curve. | |
100 * | |
101 * @param series Series to add points to. | |
102 * @param wqkms WQKms to add to series. | |
103 */ | |
104 public static void addStepPointsKmQ(XYSeries series, WQKms wqkms) { | |
105 if (wqkms == null) { | |
106 return; | |
107 } | |
108 | |
109 int size = wqkms.size(); | |
110 | |
111 for (int i = 0; i < size; i++) { | |
112 if (i==0) { | |
113 series.add(wqkms.getKm(i), wqkms.getQ(i), false); | |
114 } | |
115 else { | |
116 //Add two points. | |
117 double halveX = (wqkms.getKm(i-1) + wqkms.getKm(i)) / 2d; | |
118 series.add(halveX, wqkms.getQ(i-1)); | |
119 series.add(halveX, wqkms.getQ(i)); | |
120 } | |
121 if (i == size-1) { | |
122 series.add(wqkms.getKm(i), wqkms.getQ(i), false); | |
123 } | |
124 } | |
125 } | |
126 | |
127 | |
128 /** | |
129 * Add points to series (q to 1st dim, w to 2nd dim). | |
130 * | |
131 * @param series Series to add points to. | |
132 * @param wqkms WQKms to add to series. | |
133 */ | |
134 public static void addPointsQW(XYSeries series, WQKms wqkms) { | |
135 if (wqkms == null) { | |
136 return; | |
137 } | |
138 | |
139 int size = wqkms.size(); | |
140 | |
141 for (int i = 0; i < size; i++) { | |
142 series.add(wqkms.getQ(i), wqkms.getW(i)); | |
143 } | |
144 } | |
145 | |
146 | |
147 /** | |
148 * Add points to series (q to 1st dim, w to 2nd dim). | |
149 * | |
150 * @param series Series to add points to. | |
151 * @param wwqq WWQQ to add to series. | |
152 */ | |
153 public static void addPoints(XYSeries series, WWQQ wwqq) { | |
154 if (wwqq == null) { | |
155 return; | |
156 } | |
157 | |
158 int size = wwqq.size(); | |
159 | |
160 for (int i = 0; i < size; i++) { | |
161 series.add(wwqq.getW1(i), wwqq.getW2(i)); | |
162 } | |
163 } | |
164 | |
165 | |
166 /** | |
167 * Create a Series such that an infinitely big area can be filled | |
168 * between the newly created and the given series. | |
169 */ | |
170 public static XYSeries createGroundAtInfinity(XYSeries series) { | |
171 XYSeries ground = new XYSeries(series.getKey() + /** TODO rand + */ "INF"); | |
172 ground.add(series.getMinX(), -BIG_DOUBLE_VALUE); | |
173 ground.add(series.getMaxX(), -BIG_DOUBLE_VALUE); | |
174 return ground; | |
175 } | |
176 | |
177 | |
178 /** | |
179 * Create a Series such that an infinitely big area can be filled | |
180 * between the newly created and the given series. | |
181 */ | |
182 public static XYSeries createCeilingAtInfinity(XYSeries series) { | |
183 XYSeries ground = new XYSeries(series.getKey() + /** TODO rand + */ "INF"); | |
184 ground.add(series.getMinX(), BIG_DOUBLE_VALUE); | |
185 ground.add(series.getMaxX(), BIG_DOUBLE_VALUE); | |
186 return ground; | |
187 } | |
188 } | |
189 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |