annotate 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
rev   line source
617
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
1 package de.intevation.gnv.chart;
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
2
629
d08b9ba148c5 Implemented logic to adjust number of bins corresponding to user input.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 623
diff changeset
3 import java.text.NumberFormat;
d08b9ba148c5 Implemented logic to adjust number of bins corresponding to user input.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 623
diff changeset
4 import java.text.ParseException;
779
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
5
629
d08b9ba148c5 Implemented logic to adjust number of bins corresponding to user input.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 623
diff changeset
6 import java.util.Locale;
d08b9ba148c5 Implemented logic to adjust number of bins corresponding to user input.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 623
diff changeset
7 import java.util.Map;
d08b9ba148c5 Implemented logic to adjust number of bins corresponding to user input.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 623
diff changeset
8
617
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
9 import org.apache.log4j.Logger;
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
10
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
11 import org.jfree.chart.ChartTheme;
623
65f09139e9b3 Fixed file handle leak when writing meta data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 617
diff changeset
12
617
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
13 import org.jfree.chart.plot.XYPlot;
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
14
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
15 import org.jfree.data.statistics.HistogramDataset;
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
16
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
17 /**
767
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
18 * Default implementation of {@link de.intevation.gnv.chart.AbstractHistogram}.
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
19 *
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
20 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
617
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
21 */
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
22 public class DefaultHistogram
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
23 extends AbstractHistogram
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
24 {
767
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
25 /**
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
26 * Default bin count.
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
27 * TODO find a better default value
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
28 */
617
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
29 public static final int DEFAULT_BINS = 15;
767
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
30
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
31 /**
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
32 * Constant field for limitating the number of bin in a single histogram.
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
33 */
629
d08b9ba148c5 Implemented logic to adjust number of bins corresponding to user input.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 623
diff changeset
34 public static final int MAXIMAL_BINS = 20;
767
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
35
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
36 /**
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
37 * Default key to retrieve the number of bins from {@link
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
38 * #requestParameter}.
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
39 */
629
d08b9ba148c5 Implemented logic to adjust number of bins corresponding to user input.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 623
diff changeset
40 public static final String REQUEST_KEY_BIN_COUNT = "bincount";
767
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
41
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
42 /**
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
43 * Default key to retrieve the width of a single bin from {@link
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
44 * #requestParameter}.
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
45 */
629
d08b9ba148c5 Implemented logic to adjust number of bins corresponding to user input.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 623
diff changeset
46 public static final String REQUEST_KEY_BIN_WIDTH = "binwidth";
767
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
47
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
48 /**
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
49 * Default key to retrieve the chart width from {@link #requestParameter}.
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
50 */
629
d08b9ba148c5 Implemented logic to adjust number of bins corresponding to user input.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 623
diff changeset
51 public static final String REQUEST_KEY_CHART_WIDTH = "width";
767
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
52
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
53 /**
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 767
diff changeset
54 * Default key to retrieve the object from {@link #requestParameter}. It
767
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
55 * defines which value this chart has to be used for bin calculation. You
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
56 * can either adjust the number of bins or the width of a single bin.
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
57 */
629
d08b9ba148c5 Implemented logic to adjust number of bins corresponding to user input.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 623
diff changeset
58 public static final String REQUEST_KEY_BIN_CHOICE = "bintype";
617
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
59
767
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
60 /**
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
61 * Logger used for logging with log4j.
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
62 */
617
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
63 private static Logger logger = Logger.getLogger(DefaultHistogram.class);
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
64
767
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
65 /**
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
66 * Object storing some further parameter used for chart settings.
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
67 */
629
d08b9ba148c5 Implemented logic to adjust number of bins corresponding to user input.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 623
diff changeset
68 protected Map requestParameter;
d08b9ba148c5 Implemented logic to adjust number of bins corresponding to user input.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 623
diff changeset
69
617
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
70
767
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
71 /**
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
72 * Constructor to create DefaultHistogram objects.
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
73 *
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
74 * @param labels Labels to decorate this chart.
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
75 * @param data Raw data to be displayed in histogram.
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
76 * @param theme Theme used to adjust the chart look.
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
77 * @param requestParameter Object which serves some further settings.
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
78 */
617
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
79 public DefaultHistogram(
629
d08b9ba148c5 Implemented logic to adjust number of bins corresponding to user input.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 623
diff changeset
80 ChartLabels labels, Object[] data, ChartTheme theme, Map requestParameter
617
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
81 ) {
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
82 super(labels, data, theme);
629
d08b9ba148c5 Implemented logic to adjust number of bins corresponding to user input.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 623
diff changeset
83 this.requestParameter = requestParameter;
617
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
84 }
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
85
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
86
767
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
87 @Override
617
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
88 protected void applyDatasets() {
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
89 XYPlot plot = (XYPlot) chart.getPlot();
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
90
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
91 // prepare data and create add them to histogram dataset
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
92 String name = (String) data[0];
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
93 double[] values = toDouble((Double[]) data[1]);
629
d08b9ba148c5 Implemented logic to adjust number of bins corresponding to user input.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 623
diff changeset
94 int bins = getBinCount(values);
617
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
95
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
96 HistogramDataset dataset = new HistogramDataset();
629
d08b9ba148c5 Implemented logic to adjust number of bins corresponding to user input.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 623
diff changeset
97 dataset.addSeries(name, values, bins);
617
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
98
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
99 plot.setDataset(0, dataset);
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
100 }
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
101
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
102
767
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
103 /**
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
104 * Method which scans the hole bunch of values and returns an array with
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
105 * contains min and max value. Min value is stored at position 0, max value
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
106 * is stored at position 1 in that array.
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
107 *
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
108 * @param values Array which contains all values
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
109 *
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
110 * @return Array which contains min and max value
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
111 */
629
d08b9ba148c5 Implemented logic to adjust number of bins corresponding to user input.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 623
diff changeset
112 protected double[] getMinMax(double[] values) {
d08b9ba148c5 Implemented logic to adjust number of bins corresponding to user input.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 623
diff changeset
113 double[] minmax = new double[2];
d08b9ba148c5 Implemented logic to adjust number of bins corresponding to user input.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 623
diff changeset
114 minmax[0] = Double.MAX_VALUE;
d08b9ba148c5 Implemented logic to adjust number of bins corresponding to user input.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 623
diff changeset
115 minmax[1] = Double.MIN_VALUE;
d08b9ba148c5 Implemented logic to adjust number of bins corresponding to user input.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 623
diff changeset
116
d08b9ba148c5 Implemented logic to adjust number of bins corresponding to user input.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 623
diff changeset
117 int length = values.length;
d08b9ba148c5 Implemented logic to adjust number of bins corresponding to user input.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 623
diff changeset
118 for (int i = 0; i < length; i++) {
d08b9ba148c5 Implemented logic to adjust number of bins corresponding to user input.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 623
diff changeset
119 minmax[0] = values[i] < minmax[0] ? values[i] : minmax[0];
d08b9ba148c5 Implemented logic to adjust number of bins corresponding to user input.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 623
diff changeset
120 minmax[1] = values[i] > minmax[1] ? values[i] : minmax[1];
d08b9ba148c5 Implemented logic to adjust number of bins corresponding to user input.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 623
diff changeset
121 }
d08b9ba148c5 Implemented logic to adjust number of bins corresponding to user input.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 623
diff changeset
122
d08b9ba148c5 Implemented logic to adjust number of bins corresponding to user input.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 623
diff changeset
123 return minmax;
d08b9ba148c5 Implemented logic to adjust number of bins corresponding to user input.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 623
diff changeset
124 }
d08b9ba148c5 Implemented logic to adjust number of bins corresponding to user input.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 623
diff changeset
125
d08b9ba148c5 Implemented logic to adjust number of bins corresponding to user input.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 623
diff changeset
126
767
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
127 /**
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
128 * Turn a Double[] into a double[].
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
129 *
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
130 * @param array Doube[]
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
131 *
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
132 * @return double[]
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
133 */
617
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
134 protected double[] toDouble(Double[] array) {
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
135 int length = array.length;
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
136 double[] values = new double[length];
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
137
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
138 for(int i = 0; i < length; i++) {
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
139 values[i] = array[i].doubleValue();
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
140 }
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
141
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
142 return values;
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
143 }
629
d08b9ba148c5 Implemented logic to adjust number of bins corresponding to user input.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 623
diff changeset
144
d08b9ba148c5 Implemented logic to adjust number of bins corresponding to user input.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 623
diff changeset
145
767
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
146 /**
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
147 * Method to calculate the number of bins this chart should be parted into.
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
148 * The real calculation takes place in {@link #getBinCountByNumber} and
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
149 * {@link #getBinCountByWidth}. This method switches between these methods
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
150 * depending on the object stored in {@link #requestParameter}.
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
151 *
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
152 * @param values All values used in this histogram
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
153 *
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
154 * @return Number of bins
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
155 */
629
d08b9ba148c5 Implemented logic to adjust number of bins corresponding to user input.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 623
diff changeset
156 protected int getBinCount(double[] values) {
d08b9ba148c5 Implemented logic to adjust number of bins corresponding to user input.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 623
diff changeset
157 String param = (String) requestParameter.get(REQUEST_KEY_BIN_CHOICE);
d08b9ba148c5 Implemented logic to adjust number of bins corresponding to user input.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 623
diff changeset
158
d08b9ba148c5 Implemented logic to adjust number of bins corresponding to user input.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 623
diff changeset
159 if (param != null && param.equalsIgnoreCase(REQUEST_KEY_BIN_WIDTH)) {
d08b9ba148c5 Implemented logic to adjust number of bins corresponding to user input.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 623
diff changeset
160 return getBinCountByWidth(values);
d08b9ba148c5 Implemented logic to adjust number of bins corresponding to user input.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 623
diff changeset
161 }
d08b9ba148c5 Implemented logic to adjust number of bins corresponding to user input.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 623
diff changeset
162 else {
d08b9ba148c5 Implemented logic to adjust number of bins corresponding to user input.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 623
diff changeset
163 return getBinCountByNumber();
d08b9ba148c5 Implemented logic to adjust number of bins corresponding to user input.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 623
diff changeset
164 }
d08b9ba148c5 Implemented logic to adjust number of bins corresponding to user input.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 623
diff changeset
165 }
d08b9ba148c5 Implemented logic to adjust number of bins corresponding to user input.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 623
diff changeset
166
d08b9ba148c5 Implemented logic to adjust number of bins corresponding to user input.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 623
diff changeset
167
767
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
168 /**
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
169 * Method to retrieve the number of bins. If {@link #requestParameter}
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
170 * contains a valid <code>Integer</code> at
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 767
diff changeset
171 * <code>REQUEST_KEY_BIN_COUNT</code> and this is smaller than or equal
767
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
172 * {@link #MAXIMAL_BINS}, this value is used. If no valid
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
173 * <code>Integer</code> is given or if the value in {@link #requestParameter}
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
174 * is bigger than {@link #MAXIMAL_BINS}, {@link #DEFAULT_BINS} is used.
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
175 *
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
176 * @return Number of bins
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
177 */
629
d08b9ba148c5 Implemented logic to adjust number of bins corresponding to user input.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 623
diff changeset
178 protected int getBinCountByNumber() {
d08b9ba148c5 Implemented logic to adjust number of bins corresponding to user input.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 623
diff changeset
179 int bins = -1;
d08b9ba148c5 Implemented logic to adjust number of bins corresponding to user input.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 623
diff changeset
180 String param = (String) requestParameter.get(REQUEST_KEY_BIN_COUNT);
d08b9ba148c5 Implemented logic to adjust number of bins corresponding to user input.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 623
diff changeset
181
d08b9ba148c5 Implemented logic to adjust number of bins corresponding to user input.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 623
diff changeset
182 try {
d08b9ba148c5 Implemented logic to adjust number of bins corresponding to user input.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 623
diff changeset
183 bins = Integer.parseInt(param);
d08b9ba148c5 Implemented logic to adjust number of bins corresponding to user input.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 623
diff changeset
184 bins = bins <= 0 ? DEFAULT_BINS : bins;
d08b9ba148c5 Implemented logic to adjust number of bins corresponding to user input.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 623
diff changeset
185 bins = bins > MAXIMAL_BINS ? MAXIMAL_BINS : bins;
d08b9ba148c5 Implemented logic to adjust number of bins corresponding to user input.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 623
diff changeset
186
d08b9ba148c5 Implemented logic to adjust number of bins corresponding to user input.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 623
diff changeset
187 return bins;
d08b9ba148c5 Implemented logic to adjust number of bins corresponding to user input.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 623
diff changeset
188 }
d08b9ba148c5 Implemented logic to adjust number of bins corresponding to user input.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 623
diff changeset
189 catch (NumberFormatException nfe) {
d08b9ba148c5 Implemented logic to adjust number of bins corresponding to user input.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 623
diff changeset
190 logger.warn("Invalid number of bins for histogram chart: " + param);
d08b9ba148c5 Implemented logic to adjust number of bins corresponding to user input.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 623
diff changeset
191 logger.warn("Return default bins: " + DEFAULT_BINS);
d08b9ba148c5 Implemented logic to adjust number of bins corresponding to user input.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 623
diff changeset
192
d08b9ba148c5 Implemented logic to adjust number of bins corresponding to user input.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 623
diff changeset
193 return DEFAULT_BINS;
d08b9ba148c5 Implemented logic to adjust number of bins corresponding to user input.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 623
diff changeset
194 }
d08b9ba148c5 Implemented logic to adjust number of bins corresponding to user input.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 623
diff changeset
195 }
d08b9ba148c5 Implemented logic to adjust number of bins corresponding to user input.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 623
diff changeset
196
d08b9ba148c5 Implemented logic to adjust number of bins corresponding to user input.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 623
diff changeset
197
767
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
198 /**
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
199 * Serves the number of bins depending on a given width for each bin, but
815
22c18083225e Removed compiler warnings while JavaDoc generation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 779
diff changeset
200 * maximum bin count is limited by {@link #MAXIMAL_BINS}.
767
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
201 *
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
202 * @param values All values in this histogram
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
203 *
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
204 * @return Number of bins
79401c871da4 Added and repaired javadoc in de.intevation.gnv.chart package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 629
diff changeset
205 */
629
d08b9ba148c5 Implemented logic to adjust number of bins corresponding to user input.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 623
diff changeset
206 protected int getBinCountByWidth(double[] values) {
d08b9ba148c5 Implemented logic to adjust number of bins corresponding to user input.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 623
diff changeset
207 int bins = -1;
d08b9ba148c5 Implemented logic to adjust number of bins corresponding to user input.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 623
diff changeset
208 String param = (String) requestParameter.get(REQUEST_KEY_BIN_WIDTH);
d08b9ba148c5 Implemented logic to adjust number of bins corresponding to user input.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 623
diff changeset
209
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).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 815
diff changeset
210 double[] minmax = getMinMax(values);
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).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 815
diff changeset
211 double totalWidth = minmax[1] - minmax[0];
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).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 815
diff changeset
212 double binWidth = Double.parseDouble(param);
629
d08b9ba148c5 Implemented logic to adjust number of bins corresponding to user input.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 623
diff changeset
213
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).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 815
diff changeset
214 double tmpBins = totalWidth / binWidth;
629
d08b9ba148c5 Implemented logic to adjust number of bins corresponding to user input.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 623
diff changeset
215
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).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 815
diff changeset
216 bins = (int) Math.round(tmpBins);
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).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 815
diff changeset
217 bins = bins <= 0 ? DEFAULT_BINS : bins;
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).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 815
diff changeset
218 bins = bins > MAXIMAL_BINS ? MAXIMAL_BINS : bins;
629
d08b9ba148c5 Implemented logic to adjust number of bins corresponding to user input.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 623
diff changeset
219
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).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 815
diff changeset
220 return bins;
629
d08b9ba148c5 Implemented logic to adjust number of bins corresponding to user input.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 623
diff changeset
221 }
617
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
222 }
3d13fa281a7e Added new ouput mode: histogram.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
223 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org