annotate gnv-artifacts/src/main/java/de/intevation/gnv/chart/AdvancedHistogramDataset.java @ 1114:7e085bfb107b

Bugfix: Histogram width results in an IllegalArgumentException (issue320). gnv-artifacts/trunk@1253 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 30 Jun 2010 13:05:42 +0000
parents bb2679624c6a
children f953c9a559d8
rev   line source
1055
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
1 package de.intevation.gnv.chart;
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
2
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
3 import java.io.Serializable;
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
4 import java.util.ArrayList;
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
5 import java.util.HashMap;
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
6 import java.util.List;
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
7 import java.util.Map;
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
8
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
9 import org.apache.log4j.Logger;
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
10
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
11 import org.jfree.data.general.DatasetChangeEvent;
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
12 import org.jfree.data.xy.AbstractIntervalXYDataset;
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
13 import org.jfree.data.xy.IntervalXYDataset;
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
14
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
15 import org.jfree.data.statistics.HistogramType;
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
16 import org.jfree.data.statistics.HistogramBin;
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
17
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
18 import org.jfree.util.ObjectUtilities;
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
19 import org.jfree.util.PublicCloneable;
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
20
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
21 /**
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
22 * This class extends the functionality of the internal JFreeChart class
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
23 * <code>HistogramDataset</code>. <code>AdvancedHistogramDataset</code> takes
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
24 * the number of bins OR a bin width. It is mainly a copy of this class. The
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
25 * reason why there is no inheritance from JFreeChart's internal class is,
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
26 * that basic attributes have private access there.
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
27 *
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
28 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
29 */
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
30 public class AdvancedHistogramDataset
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
31 extends AbstractIntervalXYDataset
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
32 implements IntervalXYDataset, Cloneable, PublicCloneable, Serializable
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
33 {
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
34 /** A list of maps. */
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
35 protected List list;
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
36
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
37 /** The histogram type. */
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
38 protected HistogramType type;
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
39
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
40 /** The width of a single bin. */
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
41 protected double binWidth = -1;
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
42
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
43 /** The number of bins. */
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
44 protected int bins = -1;
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
45
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
46 /** The logger */
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
47 private static Logger logger =
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
48 Logger.getLogger(AdvancedHistogramDataset.class);
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
49
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
50
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
51 /**
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
52 * Creates a new (empty) dataset with a default type of
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
53 * {@link HistogramType}.FREQUENCY.
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
54 */
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
55 public AdvancedHistogramDataset() {
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
56 this.list = new ArrayList();
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
57 this.type = HistogramType.FREQUENCY;
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
58 }
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
59
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
60 /**
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
61 * Creates a new (empty) dataset with a default type of
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
62 * {@link HistogramType}.FREQUENCY.
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
63 */
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
64 public AdvancedHistogramDataset(int bins, double binWidth) {
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
65 this.list = new ArrayList();
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
66 this.type = HistogramType.FREQUENCY;
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
67 this.bins = bins;
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
68 this.binWidth = binWidth;
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
69 }
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
70
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
71 /**
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
72 * Returns the histogram type.
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
73 *
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
74 * @return The type (never <code>null</code>).
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
75 */
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
76 public HistogramType getType() {
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
77 return this.type;
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
78 }
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
79
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
80 /**
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
81 * Sets the histogram type and sends a {@link DatasetChangeEvent} to all
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
82 * registered listeners.
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
83 *
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
84 * @param type the type (<code>null</code> not permitted).
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
85 */
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
86 public void setType(HistogramType type) {
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
87 if (type == null) {
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
88 throw new IllegalArgumentException("Null 'type' argument");
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
89 }
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
90 this.type = type;
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
91 notifyListeners(new DatasetChangeEvent(this, this));
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
92 }
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
93
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
94 /**
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
95 * Adds a series to the dataset, using the specified number of bins.
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
96 *
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
97 * @param key the series key (<code>null</code> not permitted).
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
98 * @param values the values (<code>null</code> not permitted).
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
99 */
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
100 public void addSeries(Comparable key, double[] values) {
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
101 double minimum = getMinimum(values);
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
102 double maximum = getMaximum(values);
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
103 addSeries(key, values, minimum, maximum);
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
104 }
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
105
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
106 /**
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
107 * Adds a series to the dataset. Any data value less than minimum will be
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
108 * assigned to the first bin, and any data value greater than maximum will
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
109 * be assigned to the last bin. Values falling on the boundary of
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
110 * adjacent bins will be assigned to the higher indexed bin.
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
111 *
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
112 * @param key the series key (<code>null</code> not permitted).
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
113 * @param values the raw observations.
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
114 * @param bins the number of bins (must be at least 1).
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
115 * @param minimum the lower bound of the bin range.
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
116 * @param maximum the upper bound of the bin range.
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
117 */
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
118 public void addSeries(Comparable key,
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
119 double[] values,
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
120 double minimum,
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
121 double maximum) {
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
122
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
123 if (key == null) {
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
124 throw new IllegalArgumentException("Null 'key' argument.");
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
125 }
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
126 if (values == null) {
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
127 throw new IllegalArgumentException("Null 'values' argument.");
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
128 }
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
129 if (bins <= 0 && binWidth <= 0) {
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
130 throw new IllegalArgumentException(
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
131 "We need at least a bin width or the number of bins.");
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
132 }
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
133
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
134 // There is a binWidth given to calculate the number of bins in this
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
135 // case
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
136 if (bins <= 0) {
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
137 double tmp = (maximum - minimum) / binWidth;
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
138 bins = (int) tmp;
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
139 bins = tmp % 1 > 0 ? bins + 1 : bins;
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
140
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
141 double overlap = minimum + bins * binWidth - maximum;
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
142 tmp = minimum;
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
143 minimum -= overlap / 2;
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
144
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
145 logger.debug("There is an overlap of " + overlap);
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
146 logger.info("The lower bound is moved left from "
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
147 + tmp + " to " + minimum);
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
148
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
149 tmp = maximum;
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
150 maximum += overlap / 2;
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
151 logger.info("The upper bound is moved right from "
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
152 + tmp + " to " + maximum);
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
153 }
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
154
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
155 if (bins <= 0) {
1114
7e085bfb107b Bugfix: Histogram width results in an IllegalArgumentException (issue320).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1055
diff changeset
156 bins = 1;
1055
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
157 }
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
158
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
159 // in this case, there is a number of bins given, so we need to
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
160 // calculate the width of a single bin
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
161 if (binWidth <= 0)
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
162 binWidth = (maximum - minimum) / bins;
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
163
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
164 logger.info("bin width: " + binWidth);
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
165 logger.info("number of bins: " + bins);
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
166
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
167 double lower = minimum;
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
168 double upper;
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
169 List binList = new ArrayList(bins);
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
170 for (int i = 0; i < bins; i++) {
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
171 HistogramBin bin;
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
172 // make sure bins[bins.length]'s upper boundary ends at maximum
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
173 // to avoid the rounding issue. the bins[0] lower boundary is
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
174 // guaranteed start from min
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
175 if (i == bins - 1) {
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
176 bin = new HistogramBin(lower, maximum);
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
177 }
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
178 else {
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
179 upper = minimum + (i + 1) * binWidth;
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
180 bin = new HistogramBin(lower, upper);
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
181 lower = upper;
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
182 }
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
183 binList.add(bin);
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
184 }
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
185 // fill the bins
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
186 for (int i = 0; i < values.length; i++) {
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
187 int binIndex = bins - 1;
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
188 if (values[i] < maximum) {
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
189 double fraction = (values[i] - minimum) / (maximum - minimum);
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
190 if (fraction < 0.0) {
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
191 fraction = 0.0;
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
192 }
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
193 binIndex = (int) (fraction * bins);
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
194 // rounding could result in binIndex being equal to bins
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
195 // which will cause an IndexOutOfBoundsException - see bug
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
196 // report 1553088
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
197 if (binIndex >= bins) {
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
198 binIndex = bins - 1;
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
199 }
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
200 }
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
201 HistogramBin bin = (HistogramBin) binList.get(binIndex);
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
202 bin.incrementCount();
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
203 }
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
204 // generic map for each series
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
205 Map map = new HashMap();
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
206 map.put("key", key);
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
207 map.put("bins", binList);
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
208 map.put("values.length", new Integer(values.length));
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
209 map.put("bin width", new Double(binWidth));
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
210 this.list.add(map);
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
211 }
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
212
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
213 /**
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
214 * Returns the minimum value in an array of values.
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
215 *
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
216 * @param values the values (<code>null</code> not permitted and
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
217 * zero-length array not permitted).
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
218 *
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
219 * @return The minimum value.
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
220 */
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
221 private double getMinimum(double[] values) {
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
222 if (values == null || values.length < 1) {
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
223 throw new IllegalArgumentException(
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
224 "Null or zero length 'values' argument.");
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
225 }
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
226 double min = Double.MAX_VALUE;
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
227 for (int i = 0; i < values.length; i++) {
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
228 if (values[i] < min) {
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
229 min = values[i];
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
230 }
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
231 }
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
232 return min;
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
233 }
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
234
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
235 /**
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
236 * Returns the maximum value in an array of values.
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
237 *
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
238 * @param values the values (<code>null</code> not permitted and
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
239 * zero-length array not permitted).
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
240 *
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
241 * @return The maximum value.
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
242 */
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
243 private double getMaximum(double[] values) {
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
244 if (values == null || values.length < 1) {
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
245 throw new IllegalArgumentException(
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
246 "Null or zero length 'values' argument.");
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
247 }
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
248 double max = -Double.MAX_VALUE;
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
249 for (int i = 0; i < values.length; i++) {
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
250 if (values[i] > max) {
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
251 max = values[i];
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
252 }
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
253 }
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
254 return max;
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
255 }
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
256
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
257 /**
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
258 * Returns the bins for a series.
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
259 *
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
260 * @param series the series index (in the range <code>0</code> to
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
261 * <code>getSeriesCount() - 1</code>).
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
262 *
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
263 * @return A list of bins.
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
264 *
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
265 * @throws IndexOutOfBoundsException if <code>series</code> is outside the
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
266 * specified range.
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
267 */
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
268 List getBins(int series) {
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
269 Map map = (Map) this.list.get(series);
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
270 return (List) map.get("bins");
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
271 }
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
272
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
273 /**
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
274 * Returns the total number of observations for a series.
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
275 *
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
276 * @param series the series index.
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
277 *
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
278 * @return The total.
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
279 */
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
280 private int getTotal(int series) {
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
281 Map map = (Map) this.list.get(series);
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
282 return ((Integer) map.get("values.length")).intValue();
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
283 }
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
284
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
285 /**
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
286 * Returns the bin width for a series.
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
287 *
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
288 * @param series the series index (zero based).
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
289 *
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
290 * @return The bin width.
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
291 */
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
292 private double getBinWidth(int series) {
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
293 if (binWidth > 0)
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
294 return binWidth;
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
295
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
296 Map map = (Map) this.list.get(series);
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
297 return ((Double) map.get("bin width")).doubleValue();
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
298 }
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
299
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
300 /**
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
301 * Returns the number of series in the dataset.
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
302 *
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
303 * @return The series count.
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
304 */
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
305 public int getSeriesCount() {
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
306 return this.list.size();
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
307 }
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
308
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
309 /**
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
310 * Returns the key for a series.
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
311 *
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
312 * @param series the series index (in the range <code>0</code> to
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
313 * <code>getSeriesCount() - 1</code>).
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
314 *
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
315 * @return The series key.
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
316 *
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
317 * @throws IndexOutOfBoundsException if <code>series</code> is outside the
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
318 * specified range.
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
319 */
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
320 public Comparable getSeriesKey(int series) {
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
321 Map map = (Map) this.list.get(series);
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
322 return (Comparable) map.get("key");
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
323 }
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
324
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
325 /**
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
326 * Returns the number of data items for a series.
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
327 *
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
328 * @param series the series index (in the range <code>0</code> to
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
329 * <code>getSeriesCount() - 1</code>).
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
330 *
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
331 * @return The item count.
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
332 *
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
333 * @throws IndexOutOfBoundsException if <code>series</code> is outside the
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
334 * specified range.
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
335 */
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
336 public int getItemCount(int series) {
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
337 return getBins(series).size();
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
338 }
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
339
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
340 /**
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
341 * Returns the X value for a bin. This value won't be used for plotting
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
342 * histograms, since the renderer will ignore it. But other renderers can
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
343 * use it (for example, you could use the dataset to create a line
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
344 * chart).
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
345 *
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
346 * @param series the series index (in the range <code>0</code> to
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
347 * <code>getSeriesCount() - 1</code>).
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
348 * @param item the item index (zero based).
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
349 *
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
350 * @return The start value.
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
351 *
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
352 * @throws IndexOutOfBoundsException if <code>series</code> is outside the
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
353 * specified range.
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
354 */
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
355 public Number getX(int series, int item) {
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
356 List bins = getBins(series);
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
357 HistogramBin bin = (HistogramBin) bins.get(item);
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
358 double x = (bin.getStartBoundary() + bin.getEndBoundary()) / 2.;
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
359 return new Double(x);
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
360 }
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
361
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
362 /**
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
363 * Returns the y-value for a bin (calculated to take into account the
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
364 * histogram type).
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
365 *
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
366 * @param series the series index (in the range <code>0</code> to
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
367 * <code>getSeriesCount() - 1</code>).
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
368 * @param item the item index (zero based).
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
369 *
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
370 * @return The y-value.
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
371 *
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
372 * @throws IndexOutOfBoundsException if <code>series</code> is outside the
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
373 * specified range.
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
374 */
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
375 public Number getY(int series, int item) {
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
376 List bins = getBins(series);
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
377 HistogramBin bin = (HistogramBin) bins.get(item);
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
378 double total = getTotal(series);
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
379 double binWidth = getBinWidth(series);
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
380
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
381 if (this.type == HistogramType.FREQUENCY) {
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
382 return new Double(bin.getCount());
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
383 }
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
384 else if (this.type == HistogramType.RELATIVE_FREQUENCY) {
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
385 return new Double(bin.getCount() / total);
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
386 }
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
387 else if (this.type == HistogramType.SCALE_AREA_TO_1) {
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
388 return new Double(bin.getCount() / (binWidth * total));
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
389 }
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
390 else { // pretty sure this shouldn't ever happen
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
391 throw new IllegalStateException();
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
392 }
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
393 }
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
394
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
395 /**
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
396 * Returns the start value for a bin.
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
397 *
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
398 * @param series the series index (in the range <code>0</code> to
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
399 * <code>getSeriesCount() - 1</code>).
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
400 * @param item the item index (zero based).
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
401 *
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
402 * @return The start value.
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
403 *
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
404 * @throws IndexOutOfBoundsException if <code>series</code> is outside the
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
405 * specified range.
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
406 */
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
407 public Number getStartX(int series, int item) {
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
408 List bins = getBins(series);
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
409 HistogramBin bin = (HistogramBin) bins.get(item);
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
410 return new Double(bin.getStartBoundary());
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
411 }
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
412
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
413 /**
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
414 * Returns the end value for a bin.
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
415 *
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
416 * @param series the series index (in the range <code>0</code> to
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
417 * <code>getSeriesCount() - 1</code>).
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
418 * @param item the item index (zero based).
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
419 *
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
420 * @return The end value.
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
421 *
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
422 * @throws IndexOutOfBoundsException if <code>series</code> is outside the
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
423 * specified range.
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
424 */
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
425 public Number getEndX(int series, int item) {
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
426 List bins = getBins(series);
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
427 HistogramBin bin = (HistogramBin) bins.get(item);
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
428 return new Double(bin.getEndBoundary());
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
429 }
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
430
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
431 /**
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
432 * Returns the start y-value for a bin (which is the same as the y-value,
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
433 * this method exists only to support the general form of the
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
434 * {@link IntervalXYDataset} interface).
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
435 *
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
436 * @param series the series index (in the range <code>0</code> to
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
437 * <code>getSeriesCount() - 1</code>).
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
438 * @param item the item index (zero based).
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
439 *
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
440 * @return The y-value.
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
441 *
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
442 * @throws IndexOutOfBoundsException if <code>series</code> is outside the
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
443 * specified range.
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
444 */
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
445 public Number getStartY(int series, int item) {
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
446 return getY(series, item);
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
447 }
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
448
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
449 /**
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
450 * Returns the end y-value for a bin (which is the same as the y-value,
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
451 * this method exists only to support the general form of the
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
452 * {@link IntervalXYDataset} interface).
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
453 *
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
454 * @param series the series index (in the range <code>0</code> to
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
455 * <code>getSeriesCount() - 1</code>).
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
456 * @param item the item index (zero based).
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
457 *
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
458 * @return The Y value.
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
459 *
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
460 * @throws IndexOutOfBoundsException if <code>series</code> is outside the
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
461 * specified range.
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
462 */
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
463 public Number getEndY(int series, int item) {
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
464 return getY(series, item);
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
465 }
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
466
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
467 /**
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
468 * Tests this dataset for equality with an arbitrary object.
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
469 *
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
470 * @param obj the object to test against (<code>null</code> permitted).
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
471 *
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
472 * @return A boolean.
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
473 */
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
474 public boolean equals(Object obj) {
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
475 if (obj == this) {
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
476 return true;
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
477 }
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
478 if (!(obj instanceof AdvancedHistogramDataset)) {
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
479 return false;
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
480 }
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
481 AdvancedHistogramDataset that = (AdvancedHistogramDataset) obj;
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
482 if (!ObjectUtilities.equal(this.type, that.type)) {
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
483 return false;
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
484 }
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
485 if (!ObjectUtilities.equal(this.list, that.list)) {
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
486 return false;
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
487 }
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
488 return true;
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
489 }
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
490
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
491 /**
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
492 * Returns a clone of the dataset.
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
493 *
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
494 * @return A clone of the dataset.
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
495 *
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
496 * @throws CloneNotSupportedException if the object cannot be cloned.
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
497 */
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
498 public Object clone() throws CloneNotSupportedException {
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
499 AdvancedHistogramDataset clone = (AdvancedHistogramDataset) super.clone();
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
500 int seriesCount = getSeriesCount();
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
501 clone.list = new java.util.ArrayList(seriesCount);
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
502 for (int i = 0; i < seriesCount; i++) {
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
503 clone.list.add(new HashMap((Map) this.list.get(i)));
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
504 }
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
505 return clone;
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
506 }
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
507 }
bb2679624c6a Implemented a new histogram dataset that takes the width of a single bin as well as the number of bins for the histogram (issue288).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
508 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org