comparison gnv-artifacts/src/main/java/de/intevation/gnv/jfreechart/PolygonDataset.java @ 875:5e9efdda6894

merged gnv-artifacts/1.0
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 28 Sep 2012 12:13:56 +0200
parents 05bf8534a35a
children f953c9a559d8
comparison
equal deleted inserted replaced
722:bb3ffe7d719e 875:5e9efdda6894
1 package de.intevation.gnv.jfreechart;
2
3 import java.util.ArrayList;
4 import java.util.Collection;
5 import java.util.List;
6
7 import org.jfree.data.Range;
8
9 import org.jfree.data.general.AbstractSeriesDataset;
10
11 /**
12 * An implementation of {@link org.jfree.data.xy.XYDataset} to create 2D charts.
13 * This dataset contains several <code>PolygonSeries</code> and is used by
14 * <code>PolygonRenderer</code> to draw its items into a 2D chart.
15 *
16 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
17 */
18 public class PolygonDataset
19 extends AbstractSeriesDataset
20 {
21 /**
22 * PolygonSeries included in this Dataset
23 */
24 private List data;
25
26
27 /**
28 * Constructor.
29 */
30 public PolygonDataset() {
31 data = new ArrayList();
32 }
33
34 /**
35 * Constructs a new PolygonDataset containing multiple PolygonSeries.
36 *
37 * @param series A collection containing some PolygonSeries.
38 */
39 public PolygonDataset(Collection series) {
40 data = new ArrayList(series);
41 }
42
43 /**
44 * Constructs a PolygonDataset with a single PolygonSeries.
45 *
46 * @param series A PolygonSeries.
47 */
48 public PolygonDataset(PolygonSeries series) {
49 this();
50
51 if (series != null) {
52 data.add(series);
53 }
54 }
55
56
57 /**
58 *
59 * @param series
60 */
61 public void addSeries(PolygonSeries series) {
62 if (series == null)
63 throw new IllegalArgumentException("Null 'series' argument.");
64
65 data.add(series);
66 }
67
68 /**
69 *
70 * @param series
71 */
72 public void addAllSeries(Collection<PolygonSeries> series) {
73 data.addAll(series);
74 }
75
76 /**
77 * Retrieves the x-axis range of all PolygonSeries in this dataset.
78 *
79 * @return range of the x-axis.
80 */
81 public Range getDomainBounds() {
82 double lower = Double.POSITIVE_INFINITY;
83 double upper = Double.NEGATIVE_INFINITY;
84 int seriesCount = getSeriesCount();
85
86 for (int s = 0; s < seriesCount; s++) {
87 PolygonSeries series = getSeries(s);
88
89 Range domainRange = series.getDomainBounds();
90 double minX = domainRange.getLowerBound();
91 if (!Double.isNaN(minX)) {
92 lower = Math.min(lower, minX);
93 }
94
95 double maxX = domainRange.getUpperBound();
96 if (!Double.isNaN(maxX)) {
97 upper = Math.max(upper, maxX);
98 }
99 }
100
101 return new Range(lower, upper);
102 }
103
104
105 /**
106 * Retrieves the y-axis range of all PolygonSeries in this dataset.
107 *
108 * @return the y-axis range.
109 */
110 public Range getRangeBounds() {
111 double lower = Double.POSITIVE_INFINITY;
112 double upper = Double.NEGATIVE_INFINITY;
113 int seriesCount = getSeriesCount();
114
115 for (int i = 0; i < seriesCount; i++) {
116 PolygonSeries series = getSeries(i);
117
118 Range range = series.getRangeBounds();
119 double minX = range.getLowerBound();
120 if (!Double.isNaN(minX)) {
121 lower = Math.min(lower, minX);
122 }
123
124 double maxX = range.getUpperBound();
125 if (!Double.isNaN(maxX)) {
126 upper = Math.max(upper, maxX);
127 }
128 }
129
130 return new Range(lower, upper);
131 }
132
133
134 /**
135 * Returns the number of series in this dataset.
136 *
137 * @return the number of series in this dataset.
138 */
139 public int getSeriesCount() {
140 return data.size();
141 }
142
143
144 /**
145 * Returns the key for a series.
146 *
147 * @param index Index of a specific series.
148 * @return the series key of the series with the given index.
149 */
150 public Comparable getSeriesKey(int index) {
151 return ((PolygonSeries)data.get(index)).getKey();
152 }
153
154
155 /**
156 *
157 * @param idx Index.
158 * @return the series with the given index.
159 */
160 public PolygonSeries getSeries(int idx) {
161 return (PolygonSeries)data.get(idx);
162 }
163 }
164 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org