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