Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/exports/StyledSeriesBuilder.java @ 6862:590d420ed382
StyledSeriesBuilder: Added new method to add points with a scane factor.
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Mon, 19 Aug 2013 12:42:27 +0200 |
parents | cbe9ac4380a5 |
children | 32af7e5cb00f |
comparison
equal
deleted
inserted
replaced
6861:fb9babfa2aa3 | 6862:590d420ed382 |
---|---|
38 private StyledSeriesBuilder() { | 38 private StyledSeriesBuilder() { |
39 } | 39 } |
40 | 40 |
41 | 41 |
42 /** | 42 /** |
43 * Add points to series, create gaps if certain distance between points is met. | 43 * Add points to series, create gaps if certain distance between |
44 * points is met and scale the Y value. | |
44 * | 45 * |
45 * @param series Series to add points to. | 46 * @param series Series to add points to. |
46 * @param points Points to add to series, points[0] to 1st dim, points[1] | 47 * @param points Points to add to series, points[0] to 1st dim, points[1] |
47 * to 2nd dim. | 48 * to 2nd dim. |
48 * @param skipNANs if true, skip NAN values in points parameter. Otherwise, | 49 * @param skipNANs if true, skip NAN values in points parameter. Otherwise, |
49 * the NaNs lead to gaps in graph. | 50 * the NaNs lead to gaps in graph. |
50 * @param distance if two consecutive entries in points[0] are more | 51 * @param distance if two consecutive entries in points[0] are more |
51 * than distance apart, create a NaN value to skip in display. | 52 * than distance apart, create a NaN value to skip in display. |
52 * Still, create a line segment. | 53 * Still, create a line segment. |
53 */ | 54 * @param factor Factor by which to scale the y value (points[1]). |
54 public static void addPoints(XYSeries series, double[][] points, boolean skipNANs, double distance) { | 55 */ |
56 public static void addPointsFactorY(XYSeries series, | |
57 double[][] points, | |
58 boolean skipNANs, | |
59 double distance, | |
60 double factor | |
61 ) { | |
55 if (points == null || points.length <= 1) { | 62 if (points == null || points.length <= 1) { |
56 return; | 63 return; |
57 } | 64 } |
58 double [] xPoints = points[0]; | 65 double [] xPoints = points[0]; |
59 double [] yPoints = points[1]; | 66 double [] yPoints = points[1]; |
65 } | 72 } |
66 // Create gap if distance >= distance. | 73 // Create gap if distance >= distance. |
67 if (i != 0 && Math.abs(xPoints[i-1] - xPoints[i]) >= distance) { | 74 if (i != 0 && Math.abs(xPoints[i-1] - xPoints[i]) >= distance) { |
68 // Create at least a small segment for last point. | 75 // Create at least a small segment for last point. |
69 if (!Double.isNaN(yPoints[i-1])) { | 76 if (!Double.isNaN(yPoints[i-1])) { |
70 series.add(xPoints[i-1]+0.99d*(distance)/2.d, yPoints[i-1], false); | 77 series.add(xPoints[i-1]+0.99d*(distance)/2.d, yPoints[i-1]*factor, false); |
71 } | 78 } |
72 | 79 |
73 if (!Double.isNaN(yPoints[i-1]) && !Double.isNaN(yPoints[i])) { | 80 if (!Double.isNaN(yPoints[i-1]) && !Double.isNaN(yPoints[i])) { |
74 series.add((xPoints[i-1]+xPoints[i])/2.d, Double.NaN, false); | 81 series.add((xPoints[i-1]+xPoints[i])/2.d, Double.NaN, false); |
75 } | 82 } |
76 } | 83 } |
77 series.add(xPoints[i], yPoints[i], false); | 84 series.add(xPoints[i], yPoints[i]*factor, false); |
78 } | 85 } |
79 } | 86 } |
80 | 87 |
81 /** | 88 |
82 * Add points to series. | 89 /** |
90 * Add points to series, create gaps if certain distance between points is met. | |
83 * | 91 * |
84 * @param series Series to add points to. | 92 * @param series Series to add points to. |
85 * @param points Points to add to series, points[0] to 1st dim, points[1] | 93 * @param points Points to add to series, points[0] to 1st dim, points[1] |
86 * to 2nd dim. | 94 * to 2nd dim. |
87 * @param skipNANs if true, skip NAN values in points parameter. | 95 * @param skipNANs if true, skip NAN values in points parameter. Otherwise, |
88 * @param transY translate y-values by this value (before scale). | 96 * the NaNs lead to gaps in graph. |
89 * @param factorY scale y-values by this value (after translation). | 97 * @param distance if two consecutive entries in points[0] are more |
90 */ | 98 * than distance apart, create a NaN value to skip in display. |
91 public static void addPoints(XYSeries series, double[][] points, | 99 * Still, create a line segment. |
92 boolean skipNANs, double transY, double factorY) { | 100 */ |
93 if (transY == 0d && factorY == 1d) { | 101 public static void addPoints(XYSeries series, double[][] points, boolean skipNANs, double distance) { |
94 addPoints(series, points, skipNANs); | |
95 return; | |
96 } | |
97 if (points == null || points.length <= 1) { | 102 if (points == null || points.length <= 1) { |
98 return; | 103 return; |
99 } | 104 } |
100 double [] xPoints = points[0]; | 105 double [] xPoints = points[0]; |
101 double [] yPoints = points[1]; | 106 double [] yPoints = points[1]; |
103 if (skipNANs && | 108 if (skipNANs && |
104 (Double.isNaN(xPoints[i]) || Double.isNaN(yPoints[i]))) { | 109 (Double.isNaN(xPoints[i]) || Double.isNaN(yPoints[i]))) { |
105 logger.warn ("Skipping NaN in StyledSeriesBuilder."); | 110 logger.warn ("Skipping NaN in StyledSeriesBuilder."); |
106 continue; | 111 continue; |
107 } | 112 } |
108 series.add(xPoints[i], factorY * (transY+yPoints[i]), false); | 113 // Create gap if distance >= distance. |
114 if (i != 0 && Math.abs(xPoints[i-1] - xPoints[i]) >= distance) { | |
115 // Create at least a small segment for last point. | |
116 if (!Double.isNaN(yPoints[i-1])) { | |
117 series.add(xPoints[i-1]+0.99d*(distance)/2.d, yPoints[i-1], false); | |
118 } | |
119 | |
120 if (!Double.isNaN(yPoints[i-1]) && !Double.isNaN(yPoints[i])) { | |
121 series.add((xPoints[i-1]+xPoints[i])/2.d, Double.NaN, false); | |
122 } | |
123 } | |
124 series.add(xPoints[i], yPoints[i], false); | |
109 } | 125 } |
110 } | 126 } |
111 | 127 |
112 /** | 128 /** |
113 * Add points to series. | 129 * Add points to series. |
114 * | 130 * |
115 * @param series Series to add points to. | 131 * @param series Series to add points to. |
116 * @param points Points to add to series, points[0] to 1st dim, points[1] | 132 * @param points Points to add to series, points[0] to 1st dim, points[1] |
117 * to 2nd dim. | 133 * to 2nd dim. |
118 * @param skipNANs if true, skip NAN values in points parameter. | 134 * @param skipNANs if true, skip NAN values in points parameter. |
119 */ | 135 * @param transY translate y-values by this value (before scale). |
120 public static void addPoints(XYSeries series, double[][] points, boolean skipNANs) { | 136 * @param factorY scale y-values by this value (after translation). |
137 */ | |
138 public static void addPoints(XYSeries series, double[][] points, | |
139 boolean skipNANs, double transY, double factorY) { | |
140 if (transY == 0d && factorY == 1d) { | |
141 addPoints(series, points, skipNANs); | |
142 return; | |
143 } | |
121 if (points == null || points.length <= 1) { | 144 if (points == null || points.length <= 1) { |
122 return; | 145 return; |
123 } | 146 } |
124 double [] xPoints = points[0]; | 147 double [] xPoints = points[0]; |
125 double [] yPoints = points[1]; | 148 double [] yPoints = points[1]; |
127 if (skipNANs && | 150 if (skipNANs && |
128 (Double.isNaN(xPoints[i]) || Double.isNaN(yPoints[i]))) { | 151 (Double.isNaN(xPoints[i]) || Double.isNaN(yPoints[i]))) { |
129 logger.warn ("Skipping NaN in StyledSeriesBuilder."); | 152 logger.warn ("Skipping NaN in StyledSeriesBuilder."); |
130 continue; | 153 continue; |
131 } | 154 } |
155 series.add(xPoints[i], factorY * (transY+yPoints[i]), false); | |
156 } | |
157 } | |
158 | |
159 /** | |
160 * Add points to series. | |
161 * | |
162 * @param series Series to add points to. | |
163 * @param points Points to add to series, points[0] to 1st dim, points[1] | |
164 * to 2nd dim. | |
165 * @param skipNANs if true, skip NAN values in points parameter. | |
166 */ | |
167 public static void addPoints(XYSeries series, double[][] points, boolean skipNANs) { | |
168 if (points == null || points.length <= 1) { | |
169 return; | |
170 } | |
171 double [] xPoints = points[0]; | |
172 double [] yPoints = points[1]; | |
173 for (int i = 0; i < xPoints.length; i++) { | |
174 if (skipNANs && | |
175 (Double.isNaN(xPoints[i]) || Double.isNaN(yPoints[i]))) { | |
176 logger.warn ("Skipping NaN in StyledSeriesBuilder."); | |
177 continue; | |
178 } | |
132 series.add(xPoints[i], yPoints[i], false); | 179 series.add(xPoints[i], yPoints[i], false); |
133 } | 180 } |
134 } | 181 } |
135 | 182 |
136 | 183 |