comparison artifacts/src/main/java/org/dive4elements/river/exports/StyledSeriesBuilder.java @ 6465:126c76184c3e

StyledSeriesBuilder: More convenience methods to scale and translate values while adding.
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Thu, 27 Jun 2013 10:41:36 +0200
parents 39aba54a4c15
children 334db91c96dc
comparison
equal deleted inserted replaced
6464:2e850d56ae87 6465:126c76184c3e
76 * 76 *
77 * @param series Series to add points to. 77 * @param series Series to add points to.
78 * @param points Points to add to series, points[0] to 1st dim, points[1] 78 * @param points Points to add to series, points[0] to 1st dim, points[1]
79 * to 2nd dim. 79 * to 2nd dim.
80 * @param skipNANs if true, skip NAN values in points parameter. 80 * @param skipNANs if true, skip NAN values in points parameter.
81 */ 81 * @param transY translate y-values by this value (before scale).
82 public static void addPoints(XYSeries series, double[][] points, boolean skipNANs) { 82 * @param factorY scale y-values by this value (after translation).
83 */
84 public static void addPoints(XYSeries series, double[][] points,
85 boolean skipNANs, double transY, double factorY) {
86 if (transY == 0d && factorY == 1d) {
87 addPoints(series, points, skipNANs);
88 return;
89 }
83 if (points == null || points.length <= 1) { 90 if (points == null || points.length <= 1) {
84 return; 91 return;
85 } 92 }
86 double [] xPoints = points[0]; 93 double [] xPoints = points[0];
87 double [] yPoints = points[1]; 94 double [] yPoints = points[1];
89 if (skipNANs && 96 if (skipNANs &&
90 (Double.isNaN(xPoints[i]) || Double.isNaN(yPoints[i]))) { 97 (Double.isNaN(xPoints[i]) || Double.isNaN(yPoints[i]))) {
91 logger.warn ("Skipping NaN in StyledSeriesBuilder."); 98 logger.warn ("Skipping NaN in StyledSeriesBuilder.");
92 continue; 99 continue;
93 } 100 }
101 series.add(xPoints[i], factorY * (transY+yPoints[i]), false);
102 }
103 }
104
105 /**
106 * Add points to series.
107 *
108 * @param series Series to add points to.
109 * @param points Points to add to series, points[0] to 1st dim, points[1]
110 * to 2nd dim.
111 * @param skipNANs if true, skip NAN values in points parameter.
112 */
113 public static void addPoints(XYSeries series, double[][] points, boolean skipNANs) {
114 if (points == null || points.length <= 1) {
115 return;
116 }
117 double [] xPoints = points[0];
118 double [] yPoints = points[1];
119 for (int i = 0; i < xPoints.length; i++) {
120 if (skipNANs &&
121 (Double.isNaN(xPoints[i]) || Double.isNaN(yPoints[i]))) {
122 logger.warn ("Skipping NaN in StyledSeriesBuilder.");
123 continue;
124 }
94 series.add(xPoints[i], yPoints[i], false); 125 series.add(xPoints[i], yPoints[i], false);
95 } 126 }
96 } 127 }
97 128
98 129
252 for (int i = 0; i < size; i++) { 283 for (int i = 0; i < size; i++) {
253 series.add(qs[i], ws[i], false); 284 series.add(qs[i], ws[i], false);
254 } 285 }
255 } 286 }
256 287
288 /**
289 * Add points to series (q to 1st dim, w to 2nd dim), with
290 * scaling and translation.
291 *
292 * @param series Series to add points to.
293 * @param qs the Qs to add, assumed same length than ws.
294 * @param ws the Ws to add, assumed same length than qs.
295 */
296 public static void addPointsQW(XYSeries series, double[] qs, double ws[],
297 double wTrans, double wScale) {
298 if (ws == null || qs == null) {
299 return;
300 }
301
302 int size = qs.length;
303
304 for (int i = 0; i < size; i++) {
305 series.add(qs[i], wScale * (ws[i]+wTrans), false);
306 }
307 }
308
309
257 310
258 /** 311 /**
259 * Add points to series (q to 1st dim, w to 2nd dim). 312 * Add points to series (q to 1st dim, w to 2nd dim).
260 * 313 *
261 * @param series Series to add points to. 314 * @param series Series to add points to.

http://dive4elements.wald.intevation.org