Mercurial > dive4elements > gnv-client
comparison gnv-artifacts/src/main/java/de/intevation/gnv/chart/DefaultHistogram.java @ 1054:8430269ec73b
Removed the parsing for double/integer values specifying the bin width or the number of bins in DefaultHistogram, because these inserted values are no longer i18n strings (issue289).
gnv-artifacts/trunk@1128 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Wed, 26 May 2010 17:01:29 +0000 |
parents | 22c18083225e |
children | bb2679624c6a |
comparison
equal
deleted
inserted
replaced
1053:6169ddc827ac | 1054:8430269ec73b |
---|---|
49 * Default key to retrieve the chart width from {@link #requestParameter}. | 49 * Default key to retrieve the chart width from {@link #requestParameter}. |
50 */ | 50 */ |
51 public static final String REQUEST_KEY_CHART_WIDTH = "width"; | 51 public static final String REQUEST_KEY_CHART_WIDTH = "width"; |
52 | 52 |
53 /** | 53 /** |
54 * Default key to retrieve the <code>Locale</code> object from {@link | |
55 * #requestParameter} used for i18n support. | |
56 */ | |
57 public static final String REQUEST_KEY_LOCALE = "locale"; | |
58 | |
59 /** | |
60 * Default key to retrieve the object from {@link #requestParameter}. It | 54 * Default key to retrieve the object from {@link #requestParameter}. It |
61 * defines which value this chart has to be used for bin calculation. You | 55 * defines which value this chart has to be used for bin calculation. You |
62 * can either adjust the number of bins or the width of a single bin. | 56 * can either adjust the number of bins or the width of a single bin. |
63 */ | 57 */ |
64 public static final String REQUEST_KEY_BIN_CHOICE = "bintype"; | 58 public static final String REQUEST_KEY_BIN_CHOICE = "bintype"; |
210 * @return Number of bins | 204 * @return Number of bins |
211 */ | 205 */ |
212 protected int getBinCountByWidth(double[] values) { | 206 protected int getBinCountByWidth(double[] values) { |
213 int bins = -1; | 207 int bins = -1; |
214 String param = (String) requestParameter.get(REQUEST_KEY_BIN_WIDTH); | 208 String param = (String) requestParameter.get(REQUEST_KEY_BIN_WIDTH); |
215 Locale locale = (Locale) requestParameter.get(REQUEST_KEY_LOCALE); | 209 |
216 NumberFormat format = NumberFormat.getInstance(locale); | 210 double[] minmax = getMinMax(values); |
217 | 211 double totalWidth = minmax[1] - minmax[0]; |
218 try { | 212 double binWidth = Double.parseDouble(param); |
219 double[] minmax = getMinMax(values); | 213 |
220 double totalWidth = minmax[1] - minmax[0]; | 214 double tmpBins = totalWidth / binWidth; |
221 Number number = format.parse(param); | 215 |
222 double binWidth = -1d; | 216 bins = (int) Math.round(tmpBins); |
223 | 217 bins = bins <= 0 ? DEFAULT_BINS : bins; |
224 if (number instanceof Double) { | 218 bins = bins > MAXIMAL_BINS ? MAXIMAL_BINS : bins; |
225 binWidth = ((Double) number).doubleValue(); | 219 |
226 } | 220 return bins; |
227 else if (number instanceof Long) { | |
228 binWidth = ((Long) number).doubleValue(); | |
229 } | |
230 else if (number instanceof Integer) { | |
231 binWidth = ((Integer) number).doubleValue(); | |
232 } | |
233 else { | |
234 logger.warn("Invalid bin width for histogram chart: " + param); | |
235 logger.warn("Return default bins: " + DEFAULT_BINS); | |
236 | |
237 return DEFAULT_BINS; | |
238 } | |
239 | |
240 double tmpBins = totalWidth / binWidth; | |
241 | |
242 bins = (int) Math.round(tmpBins); | |
243 bins = bins <= 0 ? DEFAULT_BINS : bins; | |
244 bins = bins > MAXIMAL_BINS ? MAXIMAL_BINS : bins; | |
245 | |
246 return bins; | |
247 } | |
248 catch (ParseException pe) { | |
249 logger.warn("Invalid bin width for histogram chart: " + param); | |
250 logger.warn("Return default bins: " + DEFAULT_BINS); | |
251 | |
252 return DEFAULT_BINS; | |
253 } | |
254 catch (NumberFormatException nfe) { | |
255 logger.warn("Invalid bin width for histogram chart: " + param); | |
256 logger.warn("Return default bins: " + DEFAULT_BINS); | |
257 | |
258 return DEFAULT_BINS; | |
259 } | |
260 } | 221 } |
261 } | 222 } |
262 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : | 223 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |