comparison flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java @ 1932:17e18948fe5e

Fix legend and themeing with new multiaxis feature. flys-artifacts/trunk@3313 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Thu, 24 Nov 2011 10:59:40 +0000
parents 7c52e9cb2a72
children e4a516ca2e86
comparison
equal deleted inserted replaced
1931:7c52e9cb2a72 1932:17e18948fe5e
478 478
479 ThemeAccess themeAccess = new ThemeAccess(theme); 479 ThemeAccess themeAccess = new ThemeAccess(theme);
480 480
481 Color color = themeAccess.parseLineColorField(); 481 Color color = themeAccess.parseLineColorField();
482 int lineWidth = themeAccess.parseLineWidth(); 482 int lineWidth = themeAccess.parseLineWidth();
483
484 lic.add(new LegendItem(fa.getLabel(), color)); 483 lic.add(new LegendItem(fa.getLabel(), color));
485 484
486 for (XYTextAnnotation ta: fa.getAnnotations()) { 485 for (XYTextAnnotation ta: fa.getAnnotations()) {
487 if(ta instanceof StickyAxisAnnotation) { 486 if(ta instanceof StickyAxisAnnotation) {
488 StickyAxisAnnotation sta = (StickyAxisAnnotation)ta; 487 StickyAxisAnnotation sta = (StickyAxisAnnotation)ta;
494 ta.setOutlineStroke(new BasicStroke((float) lineWidth)); 493 ta.setOutlineStroke(new BasicStroke((float) lineWidth));
495 renderer.addAnnotation(ta); 494 renderer.addAnnotation(ta);
496 } 495 }
497 } 496 }
498 497
498 // TODO Do after loop?
499 plot.setFixedLegendItems(lic); 499 plot.setFixedLegendItems(lic);
500 } 500 }
501 } 501 }
502 502
503 503
598 ((NumberAxis) rangeAxis).setNumberFormatOverride(nf); 598 ((NumberAxis) rangeAxis).setNumberFormatOverride(nf);
599 } 599 }
600 600
601 601
602 protected void applyThemes(XYPlot plot) { 602 protected void applyThemes(XYPlot plot) {
603 int idx = 0;
603 604
604 for (Map.Entry<Integer, List<XYDataset>> entry: datasets.entrySet()) { 605 for (Map.Entry<Integer, List<XYDataset>> entry: datasets.entrySet()) {
605 int axis = entry.getKey();
606 for (XYDataset dataset: entry.getValue()) { 606 for (XYDataset dataset: entry.getValue()) {
607 if (dataset instanceof XYSeriesCollection) { 607 if (dataset instanceof XYSeriesCollection) {
608 applyThemes(plot, (XYSeriesCollection)dataset, axis); 608 idx = applyThemes(plot, (XYSeriesCollection)dataset, idx);
609 } 609 }
610 } 610 }
611 } 611 }
612 } 612 }
613 613
614 614
615 protected void applyThemes(XYPlot plot, XYSeriesCollection dataset, int i) { 615 /**
616 * @param idx "index" of dataset/series (first dataset to be drawn has
617 * index 0), correlates with renderer index.
618 * @return idx increased by number of items addded.
619 */
620 protected int applyThemes(XYPlot plot, XYSeriesCollection series, int idx) {
616 LegendItemCollection lic = new LegendItemCollection(); 621 LegendItemCollection lic = new LegendItemCollection();
617 LegendItemCollection anno = plot.getFixedLegendItems(); 622 LegendItemCollection anno = plot.getFixedLegendItems();
618 623
619 XYLineAndShapeRenderer r = getRenderer(plot, i); 624 XYLineAndShapeRenderer renderer = getRenderer(plot, idx);
620 625 int retidx = idx;
621 for (int s = 0, num = dataset.getSeriesCount(); s < num; s++) { 626
622 XYSeries series = dataset.getSeries(s); 627 for (int s = 0, num = series.getSeriesCount(); s < num; s++) {
623 628 XYSeries serie = series.getSeries(s);
624 if (series instanceof StyledXYSeries) { 629
625 ((StyledXYSeries) series).applyTheme(r, s); 630 if (serie instanceof StyledXYSeries) {
631 ((StyledXYSeries) serie).applyTheme(renderer, s);
626 } 632 }
627 633
628 // special case: if there is just one single item, we need to enable 634 // special case: if there is just one single item, we need to enable
629 // points for this series, otherwise we would not see anything in 635 // points for this series, otherwise we would not see anything in
630 // the chart area. 636 // the chart area.
631 if (series.getItemCount() == 1) { 637 if (serie.getItemCount() == 1) {
632 r.setSeriesShapesVisible(s, true); 638 renderer.setSeriesShapesVisible(s, true);
633 } 639 }
634 640
635 lic.add(r.getLegendItem(i, s)); 641 LegendItem li = renderer.getLegendItem(idx, s);
642 if (li != null) {
643 lic.add(li);
644 }
645 else {
646 logger.warn("Could not get LegentItem for renderer: "
647 + idx + ", series-idx " + s);
648 }
649 retidx++;
636 } 650 }
637 651
638 if (anno != null) { 652 if (anno != null) {
639 lic.addAll(anno); 653 lic.addAll(anno);
640 } 654 }
641 655
642 plot.setFixedLegendItems(lic); 656 plot.setFixedLegendItems(lic);
643 657
644 plot.setRenderer(i, r); 658 plot.setRenderer(idx, renderer);
645 } 659
646 660 return retidx;
647 661 }
662
663
664 /**
665 * Get renderer, from plot or cloned default renderer otherwise.
666 */
648 protected XYLineAndShapeRenderer getRenderer(XYPlot plot, int idx) { 667 protected XYLineAndShapeRenderer getRenderer(XYPlot plot, int idx) {
649 XYLineAndShapeRenderer r = 668 XYLineAndShapeRenderer r =
650 (XYLineAndShapeRenderer) plot.getRenderer(idx); 669 (XYLineAndShapeRenderer) plot.getRenderer(idx);
651 670
652 if (r != null) { 671 if (r != null) {

http://dive4elements.wald.intevation.org