comparison flys-artifacts/src/main/java/de/intevation/flys/exports/TimeseriesChartGenerator.java @ 2587:bece6f604899

Removed references to Range and replaced those with references to Bounds in ChartGenerators. flys-artifacts/trunk@4143 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 15 Mar 2012 10:30:03 +0000
parents 8cd6358eb7f8
children d75b427da50a
comparison
equal deleted inserted replaced
2586:8cd6358eb7f8 2587:bece6f604899
128 128
129 129
130 public static final int AXIS_SPACE = 5; 130 public static final int AXIS_SPACE = 5;
131 131
132 132
133 protected Map<Integer, Bounds> xRanges; 133 protected Map<Integer, Bounds> xBounds;
134 134
135 protected Map<Integer, Bounds> yRanges; 135 protected Map<Integer, Bounds> yBounds;
136 136
137 137
138 138
139 /** 139 /**
140 * The default constructor that initializes internal datastructures. 140 * The default constructor that initializes internal datastructures.
141 */ 141 */
142 public TimeseriesChartGenerator() { 142 public TimeseriesChartGenerator() {
143 super(); 143 super();
144 144
145 xRanges = new HashMap<Integer, Bounds>(); 145 xBounds = new HashMap<Integer, Bounds>();
146 yRanges = new HashMap<Integer, Bounds>(); 146 yBounds = new HashMap<Integer, Bounds>();
147 } 147 }
148 148
149 149
150 150
151 @Override 151 @Override
181 protected Series getSeriesOf(XYDataset dataset, int idx) { 181 protected Series getSeriesOf(XYDataset dataset, int idx) {
182 return ((TimeSeriesCollection) dataset).getSeries(idx); 182 return ((TimeSeriesCollection) dataset).getSeries(idx);
183 } 183 }
184 184
185 185
186 // TODO DECLARE IN UPPER CLASS AND ADD OVERRIDE ANNOTATION
187 protected Bounds getXRange(int axis) {
188 return xRanges.get(Integer.valueOf(axis));
189 }
190
191
192 @Override
193 // TODO setXRange should always await a Bounds instance!
194 // TODO SHOULD BE REMOVED WHEN DEFINED IN UPPER CLASS
195 protected void setXRange(int axis, Range range) {
196 // do nothing here, we will use setXRange(int, Bounds) now
197 }
198
199
200 @Override
201 // TODO setYRange should always await a Bounds instance!
202 protected void setYRange(int axis, Range range) {
203 if (range == null) {
204 logger.warn("Range is null!");
205 return;
206 }
207
208 setYBounds(Integer.valueOf(axis), new DoubleBounds(
209 range.getLowerBound(),
210 range.getUpperBound()));
211 }
212
213
214 /** 186 /**
215 * This method creates new instances of TimeseriesAxisDataset. 187 * This method creates new instances of TimeseriesAxisDataset.
216 * 188 *
217 * @param idx The symbol for the new TimeseriesAxisDataset. 189 * @param idx The symbol for the new TimeseriesAxisDataset.
218 */ 190 */
221 logger.debug("Create a new AxisDataset for index: " + idx); 193 logger.debug("Create a new AxisDataset for index: " + idx);
222 return new TimeseriesAxisDataset(idx); 194 return new TimeseriesAxisDataset(idx);
223 } 195 }
224 196
225 197
226 // TODO THIS SHOULD BE DONE IN AN UPPER CLASS! 198 @Override
227 @Override 199 protected void combineXBounds(Bounds bounds, int index) {
228 public void addAxisDataset(XYDataset dataset, int idx, boolean visible) {
229 if (dataset == null || idx < 0) {
230 return;
231 }
232
233 AxisDataset axisDataset = getAxisDataset(idx);
234
235 Bounds[] bounds = ChartHelper.getBounds((TimeSeriesCollection)dataset);
236
237 if (bounds == null) {
238 logger.warn("Skip XYDataset for Axis (invalid ranges): " + idx);
239 return;
240 }
241
242 if (visible) {
243 if (logger.isDebugEnabled()) {
244 logger.debug("Add new AxisDataset at index: " + idx);
245 logger.debug("X extent: " + bounds[0]);
246 logger.debug("Y extent: " + bounds[1]);
247 }
248
249 axisDataset.addDataset(dataset);
250 }
251
252 combineXRanges(bounds[0], 0);
253 combineYRanges(bounds[1], idx);
254 }
255
256
257 /**
258 * Effect: extend range of x axis to include given limits.
259 * @param range the given ("minimal") range.
260 * @param index index of axis to be merged.
261 */
262 @Override
263 protected void combineXRanges(Range range, int index) {
264 throw new RuntimeException(
265 "TimeseriesChartGenerator.combineXRanges is not implemented!");
266 }
267
268
269 protected void combineXRanges(Bounds bounds, int index) {
270 if (bounds != null) { 200 if (bounds != null) {
271 Bounds old = getXRange(index); 201 Bounds old = getXBounds(index);
272 202
273 if (old != null) { 203 if (old != null) {
274 bounds = bounds.combine(old); 204 bounds = bounds.combine(old);
275 } 205 }
276 206
277 setXBounds(index, bounds); 207 setXBounds(index, bounds);
278 } 208 }
279 } 209 }
280 210
281 211
282 protected void combineYRanges(Bounds bounds, int index) { 212 @Override
213 protected void combineYBounds(Bounds bounds, int index) {
283 if (bounds != null) { 214 if (bounds != null) {
284 Bounds old = getYBounds(index); 215 Bounds old = getYBounds(index);
285 216
286 if (old != null) { 217 if (old != null) {
287 bounds = bounds.combine(old); 218 bounds = bounds.combine(old);
309 } 240 }
310 241
311 242
312 @Override 243 @Override
313 public Bounds getXBounds(int axis) { 244 public Bounds getXBounds(int axis) {
314 return xRanges.get(axis); 245 return xBounds.get(axis);
315 } 246 }
316 247
317 248
318 @Override 249 @Override
319 protected void setXBounds(int axis, Bounds bounds) { 250 protected void setXBounds(int axis, Bounds bounds) {
320 xRanges.put(axis, bounds); 251 xBounds.put(axis, bounds);
321 } 252 }
322 253
323 254
324 @Override 255 @Override
325 public Bounds getYBounds(int axis) { 256 public Bounds getYBounds(int axis) {
326 return yRanges.get(axis); 257 return yBounds.get(axis);
327 } 258 }
328 259
329 260
330 @Override 261 @Override
331 protected void setYBounds(int axis, Bounds bounds) { 262 protected void setYBounds(int axis, Bounds bounds) {
332 yRanges.put(axis, bounds); 263 if (bounds != null) {
264 yBounds.put(axis, bounds);
265 }
333 } 266 }
334 267
335 268
336 public Bounds[] getBoundsForAxis(int index) { 269 public Bounds[] getBoundsForAxis(int index) {
337 logger.debug("Return x and y bounds for axis at: " + index); 270 logger.debug("Return x and y bounds for axis at: " + index);
413 346
414 347
415 protected void adaptZoom(XYPlot plot) { 348 protected void adaptZoom(XYPlot plot) {
416 logger.debug("Adapt zoom of Timeseries chart."); 349 logger.debug("Adapt zoom of Timeseries chart.");
417 350
418 zoomX(plot, plot.getDomainAxis(), getXRange(0), getDomainAxisRange()); 351 zoomX(plot, plot.getDomainAxis(), getXBounds(0), getDomainAxisRange());
419 352
420 Bounds valueAxisBounds = getValueAxisRange(); 353 Bounds valueAxisBounds = getValueAxisRange();
421 354
422 for (int j = 0, n = plot.getRangeAxisCount(); j < n; j++) { 355 for (int j = 0, n = plot.getRangeAxisCount(); j < n; j++) {
423 zoomY( 356 zoomY(

http://dive4elements.wald.intevation.org