comparison flys-artifacts/src/main/java/de/intevation/flys/exports/TimeseriesChartGenerator.java @ 3212:abc2db630815

Work in generalized annotations for chart generators flys-artifacts/trunk@4835 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Christian Lins <christian.lins@intevation.de>
date Fri, 29 Jun 2012 12:35:06 +0000
parents f1e4b37dcb60
children 3287019ad04b
comparison
equal deleted inserted replaced
3211:a1a434c163a4 3212:abc2db630815
4 import de.intevation.artifactdatabase.state.Facet; 4 import de.intevation.artifactdatabase.state.Facet;
5 5
6 import de.intevation.flys.jfree.Bounds; 6 import de.intevation.flys.jfree.Bounds;
7 import de.intevation.flys.jfree.CollisionFreeXYTextAnnotation; 7 import de.intevation.flys.jfree.CollisionFreeXYTextAnnotation;
8 import de.intevation.flys.jfree.DoubleBounds; 8 import de.intevation.flys.jfree.DoubleBounds;
9 import de.intevation.flys.jfree.StickyAxisAnnotation;
9 import de.intevation.flys.jfree.FLYSAnnotation; 10 import de.intevation.flys.jfree.FLYSAnnotation;
10 import de.intevation.flys.jfree.StyledTimeSeries; 11 import de.intevation.flys.jfree.StyledTimeSeries;
11 import de.intevation.flys.jfree.TimeBounds; 12 import de.intevation.flys.jfree.TimeBounds;
12 13
13 import de.intevation.flys.utils.ThemeAccess; 14 import de.intevation.flys.utils.ThemeAccess;
15
16 import de.intevation.flys.artifacts.model.HYKFactory;
14 17
15 import java.awt.BasicStroke; 18 import java.awt.BasicStroke;
16 import java.awt.Color; 19 import java.awt.Color;
17 import java.awt.Font; 20 import java.awt.Font;
18 import java.awt.Paint; 21 import java.awt.Paint;
28 31
29 import org.jfree.chart.ChartFactory; 32 import org.jfree.chart.ChartFactory;
30 import org.jfree.chart.JFreeChart; 33 import org.jfree.chart.JFreeChart;
31 import org.jfree.chart.LegendItemCollection; 34 import org.jfree.chart.LegendItemCollection;
32 35
36 import org.jfree.chart.annotations.XYBoxAnnotation;
37 import org.jfree.chart.annotations.XYLineAnnotation;
33 import org.jfree.chart.annotations.XYTextAnnotation; 38 import org.jfree.chart.annotations.XYTextAnnotation;
34 39
35 import org.jfree.chart.axis.ValueAxis; 40 import org.jfree.chart.axis.ValueAxis;
36 41
37 import org.jfree.chart.plot.Marker; 42 import org.jfree.chart.plot.Marker;
612 annotations.add(annotation); 617 annotations.add(annotation);
613 } 618 }
614 619
615 620
616 /** Add annotations (Sticky, Text and hyk zones). */ 621 /** Add annotations (Sticky, Text and hyk zones). */
617 public void addAnnotationsToRenderer(XYPlot plot) { 622 /* public void addAnnotationsToRenderer(XYPlot plot) {
618 logger.debug("XYChartGenerator.addAnnotationsToRenderer"); 623 logger.debug("addAnnotationsToRenderer");
619 624
620 if (annotations == null) { 625 if (annotations == null) {
621 logger.debug("XYChartGenerator.addBoxAnnotations: no annotations."); 626 logger.debug("addAnnotationsToRenderer: no annotations.");
622 return; 627 return;
623 } 628 }
624 629
625 // Paints for the boxes/lines. 630 // Paints for the boxes/lines.
626 Stroke basicStroke = new BasicStroke(1.0f); 631 Stroke basicStroke = new BasicStroke(1.0f);
669 textStyle.apply(ta); 674 textStyle.apply(ta);
670 } 675 }
671 ta.setY(area.above(0.05d, ta.getY())); 676 ta.setY(area.above(0.05d, ta.getY()));
672 plot.getRenderer().addAnnotation(ta, org.jfree.ui.Layer.FOREGROUND); 677 plot.getRenderer().addAnnotation(ta, org.jfree.ui.Layer.FOREGROUND);
673 } 678 }
679 }
680 }*/
681
682 /**
683 * Add the annotations (Sticky, Text and hyk zones) stored
684 * in the annotations field.
685 */
686 public void addAnnotationsToRenderer(XYPlot plot) {
687 logger.debug("addAnnotationsToRenderer");
688
689 if (annotations == null) {
690 logger.debug("addAnnotationsToRenderer: no annotations.");
691 return;
692 }
693
694 // Paints for the boxes/lines.
695 Stroke basicStroke = new BasicStroke(1.0f);
696
697 Paint linePaint = new Color(255, 0,0,60);
698 Paint fillPaint = new Color(0, 255,0,60);
699 Paint tranPaint = new Color(0, 0,0, 0);
700
701 // OPTMIMIZE: Pre-calculate positions
702 Area area = new Area(
703 plot.getDomainAxis(0).getRange(),
704 plot.getRangeAxis().getRange());
705
706 // Walk over all Annotation sets.
707 for (FLYSAnnotation fa: annotations) {
708
709 // Access text styling, if any.
710 Document theme = fa.getTheme();
711 ThemeAccess.TextStyle textStyle = null;
712 ThemeAccess.LineStyle lineStyle = null;
713
714 // Get Themeing information and add legend item.
715 if (theme != null) {
716 ThemeAccess themeAccess = new ThemeAccess(theme);
717 textStyle = themeAccess.parseTextStyle();
718 lineStyle = themeAccess.parseLineStyle();
719 if (fa.getLabel() != null) {
720 LegendItemCollection lic = new LegendItemCollection();
721 LegendItemCollection old = plot.getFixedLegendItems();
722 lic.add(createLegendItem(theme, fa.getLabel()));
723 // (Re-)Add prior legend entries.
724 if (old != null) {
725 old.addAll(lic);
726 }
727 else {
728 old = lic;
729 }
730 plot.setFixedLegendItems(old);
731 }
732 }
733
734 // The 'Sticky' Annotations (at axis, with line and text).
735 /* for (StickyAxisAnnotation sta: fa.getAxisTextAnnotations()) {
736 addStickyAnnotation(
737 sta, plot, area, lineStyle, textStyle, theme);
738 }*/
739
740 // Other Text Annotations (e.g. labels of manual points).
741 for (XYTextAnnotation ta: fa.getTextAnnotations()) {
742 // Style the text.
743 if (textStyle != null) {
744 textStyle.apply(ta);
745 }
746 ta.setY(area.above(0.05d, ta.getY()));
747 plot.getRenderer().addAnnotation(ta, org.jfree.ui.Layer.FOREGROUND);
748 }
749
750 // Hyks.
751 for (HYKFactory.Zone zone: fa.getBoxes()) {
752 // For each zone, create a box to fill with color, a box to draw
753 // the lines and a text to display the type.
754 fillPaint = colorForHYKZone(zone.getName());
755
756 XYBoxAnnotation boxA = new XYBoxAnnotation(zone.getFrom(), area.atGround(),
757 zone.getTo(), area.ofGround(0.03f), basicStroke, tranPaint, fillPaint);
758 XYBoxAnnotation boxB = new XYBoxAnnotation(zone.getFrom(), area.atGround(),
759 zone.getTo(), area.atTop(), basicStroke, fillPaint, tranPaint);
760
761 XYTextAnnotation tex = new XYTextAnnotation(zone.getName(),
762 zone.getFrom() + (zone.getTo() - zone.getFrom()) / 1.0d,
763 area.ofGround(0.015f));
764 if (textStyle != null) {
765 textStyle.apply(tex);
766 }
767
768 plot.getRenderer().addAnnotation(boxA, org.jfree.ui.Layer.BACKGROUND);
769 plot.getRenderer().addAnnotation(boxB, org.jfree.ui.Layer.BACKGROUND);
770 plot.getRenderer().addAnnotation(tex, org.jfree.ui.Layer.BACKGROUND);
771 }
772 }
773 }
774
775 /** Get color for hyk zones by their type (which is the name). */
776 public Paint colorForHYKZone(String zoneName) {
777 if (zoneName.startsWith("R")) {
778 // Brownish.
779 return new Color(153, 60, 0);
780 }
781 else if (zoneName.startsWith("V")) {
782 // Greenish.
783 return new Color(0, 255, 0);
784 }
785 else if (zoneName.startsWith("B")) {
786 // Grayish.
787 return new Color(128, 128, 128);
788 }
789 else if (zoneName.startsWith("H")) {
790 // Blueish.
791 return new Color(0, 0, 255);
792 }
793 else {
794 // Default.
795 logger.debug("Unknown zone type found.");
796 return new Color(255, 0, 0);
674 } 797 }
675 } 798 }
676 799
677 public void addDomainAxisMarker(XYPlot plot) { 800 public void addDomainAxisMarker(XYPlot plot) {
678 logger.debug("domainmarkers: " + domainMarker.size()); 801 logger.debug("domainmarkers: " + domainMarker.size());

http://dive4elements.wald.intevation.org