Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.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 | 5d5457a1bd5f |
children | d75b427da50a |
comparison
equal
deleted
inserted
replaced
2586:8cd6358eb7f8 | 2587:bece6f604899 |
---|---|
40 | 40 |
41 import de.intevation.artifactdatabase.state.ArtifactAndFacet; | 41 import de.intevation.artifactdatabase.state.ArtifactAndFacet; |
42 import de.intevation.artifactdatabase.state.Facet; | 42 import de.intevation.artifactdatabase.state.Facet; |
43 | 43 |
44 import de.intevation.flys.jfree.Bounds; | 44 import de.intevation.flys.jfree.Bounds; |
45 import de.intevation.flys.jfree.DoubleBounds; | |
45 import de.intevation.flys.jfree.FLYSAnnotation; | 46 import de.intevation.flys.jfree.FLYSAnnotation; |
46 import de.intevation.flys.jfree.StickyAxisAnnotation; | 47 import de.intevation.flys.jfree.StickyAxisAnnotation; |
47 import de.intevation.flys.jfree.CollisionFreeXYTextAnnotation; | 48 import de.intevation.flys.jfree.CollisionFreeXYTextAnnotation; |
48 import de.intevation.flys.jfree.StyledAreaSeriesCollection; | 49 import de.intevation.flys.jfree.StyledAreaSeriesCollection; |
49 import de.intevation.flys.jfree.StyledXYSeries; | 50 import de.intevation.flys.jfree.StyledXYSeries; |
171 } | 172 } |
172 } // class AxisDataset | 173 } // class AxisDataset |
173 | 174 |
174 protected abstract YAxisWalker getYAxisWalker(); | 175 protected abstract YAxisWalker getYAxisWalker(); |
175 | 176 |
177 public static final int AXIS_SPACE = 5; | |
178 | |
176 /** The logger that is used in this generator. */ | 179 /** The logger that is used in this generator. */ |
177 private static Logger logger = Logger.getLogger(XYChartGenerator.class); | 180 private static Logger logger = Logger.getLogger(XYChartGenerator.class); |
178 | 181 |
179 /** List of annotations to insert in plot. */ | 182 /** List of annotations to insert in plot. */ |
180 protected List<FLYSAnnotation> annotations; | 183 protected List<FLYSAnnotation> annotations; |
181 | 184 |
182 /** The max X range to include all X values of all series for each axis. */ | 185 /** The max X range to include all X values of all series for each axis. */ |
183 protected Map<Integer, Range> xRanges; | 186 protected Map<Integer, Bounds> xBounds; |
184 | 187 |
185 /** The max Y range to include all Y values of all series for each axis. */ | 188 /** The max Y range to include all Y values of all series for each axis. */ |
186 protected Map<Integer, Range> yRanges; | 189 protected Map<Integer, Bounds> yBounds; |
187 | 190 |
188 | 191 |
189 public XYChartGenerator() { | 192 public XYChartGenerator() { |
190 super(); | 193 super(); |
191 | 194 |
192 xRanges = new HashMap<Integer, Range>(); | 195 xBounds = new HashMap<Integer, Bounds>(); |
193 yRanges = new HashMap<Integer, Range>(); | 196 yBounds = new HashMap<Integer, Bounds>(); |
194 } | 197 } |
195 | 198 |
196 | 199 |
197 /** | 200 /** |
198 * Generate the chart anew (including localized axis and all). | 201 * Generate the chart anew (including localized axis and all). |
241 | 244 |
242 | 245 |
243 @Override | 246 @Override |
244 protected Series getSeriesOf(XYDataset dataset, int idx) { | 247 protected Series getSeriesOf(XYDataset dataset, int idx) { |
245 return ((XYSeriesCollection) dataset).getSeries(idx); | 248 return ((XYSeriesCollection) dataset).getSeries(idx); |
246 } | |
247 | |
248 | |
249 @Override | |
250 protected void setXRange(int axis, Range range) { | |
251 xRanges.put(Integer.valueOf(axis), range); | |
252 } | |
253 | |
254 | |
255 @Override | |
256 protected void setYRange(int axis, Range range) { | |
257 yRanges.put(Integer.valueOf(axis), range); | |
258 } | 249 } |
259 | 250 |
260 | 251 |
261 @Override | 252 @Override |
262 protected AxisDataset createAxisDataset(int idx) { | 253 protected AxisDataset createAxisDataset(int idx) { |
356 } | 347 } |
357 | 348 |
358 | 349 |
359 /** | 350 /** |
360 * Effect: extend range of x axis to include given limits. | 351 * Effect: extend range of x axis to include given limits. |
352 * | |
361 * @param range the given ("minimal") range. | 353 * @param range the given ("minimal") range. |
362 * @param index index of axis to be merged. | 354 * @param index index of axis to be merged. |
363 */ | 355 */ |
364 protected void combineXRanges(Range range, int index) { | 356 @Override |
365 | 357 protected void combineXBounds(Bounds bounds, int index) { |
366 if (range == null | 358 if (!(bounds instanceof DoubleBounds)) { |
367 || Double.isNaN(range.getLowerBound()) | 359 logger.warn("Unsupported Bounds type: " + bounds.getClass()); |
368 || Double.isNaN(range.getUpperBound())) { | |
369 return; | 360 return; |
370 } | 361 } |
371 | 362 |
372 Range old = xRanges.get(index); | 363 DoubleBounds dBounds = (DoubleBounds) bounds; |
364 | |
365 if (dBounds == null | |
366 || Double.isNaN((Double) dBounds.getLower()) | |
367 || Double.isNaN((Double) dBounds.getUpper())) { | |
368 return; | |
369 } | |
370 | |
371 Bounds old = getXBounds(index); | |
373 | 372 |
374 if (old != null) { | 373 if (old != null) { |
375 range = Range.combine(old, range); | 374 dBounds = (DoubleBounds) dBounds.combine(old); |
376 } | 375 } |
377 | 376 |
378 xRanges.put(index, range); | 377 setXBounds(index, dBounds); |
378 } | |
379 | |
380 | |
381 @Override | |
382 protected void combineYBounds(Bounds bounds, int index) { | |
383 if (!(bounds instanceof DoubleBounds)) { | |
384 logger.warn("Unsupported Bounds type: " + bounds.getClass()); | |
385 return; | |
386 } | |
387 | |
388 DoubleBounds dBounds = (DoubleBounds) bounds; | |
389 | |
390 if (dBounds == null | |
391 || Double.isNaN((Double) dBounds.getLower()) | |
392 || Double.isNaN((Double) dBounds.getUpper())) { | |
393 return; | |
394 } | |
395 | |
396 Bounds old = getYBounds(index); | |
397 | |
398 if (old != null) { | |
399 dBounds = (DoubleBounds) dBounds.combine(old); | |
400 } | |
401 | |
402 setYBounds(index, dBounds); | |
379 } | 403 } |
380 | 404 |
381 | 405 |
382 /** | 406 /** |
383 * Adds annotations to list (if visible is true). | 407 * Adds annotations to list (if visible is true). |
410 * Expands X axes if only a point is shown. | 434 * Expands X axes if only a point is shown. |
411 */ | 435 */ |
412 private void preparePointRanges(XYPlot plot) { | 436 private void preparePointRanges(XYPlot plot) { |
413 for (int i = 0, num = plot.getDomainAxisCount(); i < num; i++) { | 437 for (int i = 0, num = plot.getDomainAxisCount(); i < num; i++) { |
414 logger.debug("Check whether to expand a x axis."); | 438 logger.debug("Check whether to expand a x axis."); |
439 | |
415 Integer key = Integer.valueOf(i); | 440 Integer key = Integer.valueOf(i); |
416 | 441 Bounds b = getXBounds(key); |
417 Range r = xRanges.get(key); | 442 |
418 if (r != null && r.getLowerBound() == r.getUpperBound()) { | 443 if (b != null && b.getLower() == b.getUpper()) { |
419 setXRange(key, ChartHelper.expandRange(r, 5)); | 444 double lo = (Double) b.getLower(); |
445 double hi = (Double) b.getUpper(); | |
446 double add = (hi - lo) / 100 * 5; | |
447 | |
448 setXBounds(key, new DoubleBounds(lo-add, hi+add)); | |
420 } | 449 } |
421 } | 450 } |
422 } | 451 } |
423 | 452 |
424 | 453 |
442 Range fixedXRange = getRangeForAxisFromSettings("X"); | 471 Range fixedXRange = getRangeForAxisFromSettings("X"); |
443 if (fixedXRange != null) { | 472 if (fixedXRange != null) { |
444 xAxis.setRange(fixedXRange); | 473 xAxis.setRange(fixedXRange); |
445 } | 474 } |
446 else { | 475 else { |
447 zoomX(plot, xAxis, xRanges.get(0), xrange); | 476 zoomX(plot, xAxis, getXBounds(0), xrange); |
448 } | 477 } |
449 | 478 |
450 for (int i = 0, num = plot.getRangeAxisCount(); i < num; i++) { | 479 for (int i = 0, num = plot.getRangeAxisCount(); i < num; i++) { |
451 ValueAxis yaxis = plot.getRangeAxis(i); | 480 ValueAxis yaxis = plot.getRangeAxis(i); |
452 | 481 |
464 logger.debug("Zoom problem: no Y Axis for index: " + i); | 493 logger.debug("Zoom problem: no Y Axis for index: " + i); |
465 continue; | 494 continue; |
466 } | 495 } |
467 | 496 |
468 logger.debug("Prepare zoom settings for y axis at index: " + i); | 497 logger.debug("Prepare zoom settings for y axis at index: " + i); |
469 zoomY(plot, yaxis, yRanges.get(Integer.valueOf(i)), yrange); | 498 zoomY(plot, yaxis, getYBounds(Integer.valueOf(i)), yrange); |
470 } | 499 } |
471 } | 500 } |
472 | 501 |
473 | 502 |
474 protected Range getDomainAxisRange() { | 503 protected Range getDomainAxisRange() { |
535 | 564 |
536 return null; | 565 return null; |
537 } | 566 } |
538 | 567 |
539 | 568 |
540 protected boolean zoomX(XYPlot plot, ValueAxis axis, Range range, Range x) { | 569 protected boolean zoomX(XYPlot plot, ValueAxis axis, Bounds bounds, Range x) { |
541 return zoom(plot, axis, range, x); | 570 return zoom(plot, axis, bounds, x); |
542 } | 571 } |
543 | 572 |
544 | 573 |
545 protected boolean zoomY(XYPlot plot, ValueAxis axis, Range range, Range x) { | 574 protected boolean zoomY(XYPlot plot, ValueAxis axis, Bounds bounds, Range x) { |
546 return zoom(plot, axis, range, x); | 575 return zoom(plot, axis, bounds, x); |
547 } | 576 } |
548 | 577 |
549 | 578 |
550 /** | 579 /** |
551 * Zooms the x axis to the range specified in the attribute document. | 580 * Zooms the x axis to the range specified in the attribute document. |
555 * @param range The whole range specified by a dataset. | 584 * @param range The whole range specified by a dataset. |
556 * @param x A user defined range (null permitted). | 585 * @param x A user defined range (null permitted). |
557 * | 586 * |
558 * @return true, if a zoom range was specified, otherwise false. | 587 * @return true, if a zoom range was specified, otherwise false. |
559 */ | 588 */ |
560 protected boolean zoom(XYPlot plot, ValueAxis axis, Range range, Range x) { | 589 protected boolean zoom(XYPlot plot, ValueAxis axis, Bounds bounds, Range x) { |
561 | 590 |
562 if (range == null) { | 591 if (bounds == null) { |
563 return false; | 592 return false; |
564 } | 593 } |
565 | 594 |
566 if (x != null) { | 595 if (x != null) { |
567 double min = range.getLowerBound(); | 596 double min = bounds.getLower().doubleValue(); |
568 double max = range.getUpperBound(); | 597 double max = bounds.getUpper().doubleValue(); |
598 | |
599 if (logger.isDebugEnabled()) { | |
600 logger.debug("Minimum is: " + min); | |
601 logger.debug("Maximum is: " + max); | |
602 logger.debug("Lower zoom is: " + x.getLowerBound()); | |
603 logger.debug("Upper zoom is: " + x.getUpperBound()); | |
604 } | |
605 | |
569 double diff = max > min ? max - min : min - max; | 606 double diff = max > min ? max - min : min - max; |
570 | 607 |
571 Range computed = new Range( | 608 DoubleBounds computed = new DoubleBounds( |
572 min + x.getLowerBound() * diff, | 609 min + x.getLowerBound() * diff, |
573 min + x.getUpperBound() * diff); | 610 min + x.getUpperBound() * diff); |
574 | 611 |
575 axis.setRangeWithMargins(computed); | 612 computed.applyBounds(axis, AXIS_SPACE); |
576 | 613 |
577 logger.debug("Zoom axis to: " + computed); | 614 logger.debug("Zoom axis to: " + computed); |
578 | 615 |
579 return true; | 616 return true; |
580 } | 617 } |
581 | 618 |
582 axis.setRangeWithMargins(range); | 619 bounds.applyBounds(axis, AXIS_SPACE); |
583 return false; | 620 return false; |
584 } | 621 } |
585 | 622 |
586 | 623 |
587 /** | 624 /** |
594 */ | 631 */ |
595 @Override | 632 @Override |
596 public Range[] getRangesForAxis(int index) { | 633 public Range[] getRangesForAxis(int index) { |
597 logger.debug("getRangesForAxis " + index); | 634 logger.debug("getRangesForAxis " + index); |
598 | 635 |
599 Range rx = xRanges.get(Integer.valueOf(0)); | 636 Bounds rx = getXBounds(Integer.valueOf(0)); |
600 Range ry = yRanges.get(Integer.valueOf(index)); | 637 Bounds ry = getYBounds(Integer.valueOf(index)); |
601 | 638 |
602 if (rx == null) { | 639 if (rx == null) { |
603 logger.warn("Range for x axis not set." + | 640 logger.warn("Range for x axis not set." + |
604 " Using default values: 0 - 1."); | 641 " Using default values: 0 - 1."); |
605 rx = new Range(0, 1); | 642 rx = new DoubleBounds(0, 1); |
606 } | 643 } |
607 if (ry == null) { | 644 if (ry == null) { |
608 logger.warn("Range for y" + index + | 645 logger.warn("Range for y" + index + |
609 " axis not set. Using default values: 0 - 1."); | 646 " axis not set. Using default values: 0 - 1."); |
610 ry = new Range(0, 1); | 647 ry = new DoubleBounds(0, 1); |
611 } | 648 } |
612 return new Range[] {rx, ry}; | 649 |
650 return new Range[] { | |
651 new Range(rx.getLower().doubleValue(), rx.getUpper().doubleValue()), | |
652 new Range(ry.getLower().doubleValue(), ry.getUpper().doubleValue()) | |
653 }; | |
613 } | 654 } |
614 | 655 |
615 | 656 |
616 @Override | 657 @Override |
617 public Bounds getXBounds(int axis) { | 658 public Bounds getXBounds(int axis) { |
618 // TODO IMPLEMENT ME | 659 return xBounds.get(axis); |
619 throw new RuntimeException( | |
620 "XYChartGenerator.getXBounds(int) not implemented"); | |
621 } | 660 } |
622 | 661 |
623 | 662 |
624 @Override | 663 @Override |
625 protected void setXBounds(int axis, Bounds bounds) { | 664 protected void setXBounds(int axis, Bounds bounds) { |
626 // TODO IMPLEMENT ME | 665 xBounds.put(axis, bounds); |
627 throw new RuntimeException( | |
628 "XYChartGenerator.setXBounds(int,Bounds) not implemented"); | |
629 } | 666 } |
630 | 667 |
631 | 668 |
632 @Override | 669 @Override |
633 public Bounds getYBounds(int axis) { | 670 public Bounds getYBounds(int axis) { |
634 // TODO IMPLEMENT ME | 671 return yBounds.get(axis); |
635 throw new RuntimeException( | |
636 "XYChartGenerator.getYBounds(int) not implemented"); | |
637 } | 672 } |
638 | 673 |
639 | 674 |
640 @Override | 675 @Override |
641 protected void setYBounds(int axis, Bounds bounds) { | 676 protected void setYBounds(int axis, Bounds bounds) { |
642 // TODO IMPLEMENT ME | 677 yBounds.put(axis, bounds); |
643 throw new RuntimeException( | |
644 "XYChartGenerator.setYBounds(int,Bounds) not implemented"); | |
645 } | 678 } |
646 | 679 |
647 | 680 |
648 /** Get color for hyk zones by their type (which is the name). */ | 681 /** Get color for hyk zones by their type (which is the name). */ |
649 public Paint colorForHYKZone(String zoneName) { | 682 public Paint colorForHYKZone(String zoneName) { |