Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java @ 2138:59bb5c895be3
Improved HYK/Zones- handling.
flys-artifacts/trunk@3716 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Thu, 19 Jan 2012 11:00:27 +0000 |
parents | e8fc770d2f8c |
children | c5d24e0587ce |
comparison
equal
deleted
inserted
replaced
2137:04b6b6a4564d | 2138:59bb5c895be3 |
---|---|
28 | 28 |
29 import org.jfree.chart.ChartFactory; | 29 import org.jfree.chart.ChartFactory; |
30 import org.jfree.chart.JFreeChart; | 30 import org.jfree.chart.JFreeChart; |
31 import org.jfree.chart.LegendItem; | 31 import org.jfree.chart.LegendItem; |
32 import org.jfree.chart.LegendItemCollection; | 32 import org.jfree.chart.LegendItemCollection; |
33 import org.jfree.chart.annotations.XYBoxAnnotation; | |
33 import org.jfree.chart.annotations.XYTextAnnotation; | 34 import org.jfree.chart.annotations.XYTextAnnotation; |
34 import org.jfree.chart.axis.NumberAxis; | 35 import org.jfree.chart.axis.NumberAxis; |
35 import org.jfree.chart.axis.ValueAxis; | 36 import org.jfree.chart.axis.ValueAxis; |
36 import org.jfree.chart.plot.PlotOrientation; | 37 import org.jfree.chart.plot.PlotOrientation; |
37 import org.jfree.chart.plot.XYPlot; | 38 import org.jfree.chart.plot.XYPlot; |
57 import de.intevation.flys.jfree.StickyAxisAnnotation; | 58 import de.intevation.flys.jfree.StickyAxisAnnotation; |
58 import de.intevation.flys.jfree.StyledAreaSeriesCollection; | 59 import de.intevation.flys.jfree.StyledAreaSeriesCollection; |
59 import de.intevation.flys.jfree.StyledXYSeries; | 60 import de.intevation.flys.jfree.StyledXYSeries; |
60 | 61 |
61 import de.intevation.flys.utils.ThemeAccess; | 62 import de.intevation.flys.utils.ThemeAccess; |
63 | |
64 import de.intevation.flys.artifacts.model.HYKFactory; | |
62 | 65 |
63 /** | 66 /** |
64 * An abstract base class for creating XY charts. | 67 * An abstract base class for creating XY charts. |
65 * | 68 * |
66 * With respect to datasets, ranges and axis, there are following requirements: | 69 * With respect to datasets, ranges and axis, there are following requirements: |
510 | 513 |
511 localizeAxes(plot); | 514 localizeAxes(plot); |
512 adjustAxes(plot); | 515 adjustAxes(plot); |
513 autoZoom(plot); | 516 autoZoom(plot); |
514 | 517 |
518 // These have to go after the autozoom. | |
519 addBoxAnnotations(plot); | |
520 | |
515 return chart; | 521 return chart; |
516 } | 522 } |
517 | 523 |
518 | 524 |
519 protected void preparePDFContext(CallContext context) { | 525 protected void preparePDFContext(CallContext context) { |
996 LegendItem li = new LegendItem(fa.getLabel(), color); | 1002 LegendItem li = new LegendItem(fa.getLabel(), color); |
997 li.setLabelFont(labelFont); | 1003 li.setLabelFont(labelFont); |
998 | 1004 |
999 lic.add(li); | 1005 lic.add(li); |
1000 | 1006 |
1001 for (XYTextAnnotation ta: fa.getAnnotations()) { | 1007 for (XYTextAnnotation ta: fa.getTextAnnotations()) { |
1002 if(ta instanceof StickyAxisAnnotation) { | 1008 if(ta instanceof StickyAxisAnnotation) { |
1003 StickyAxisAnnotation sta = (StickyAxisAnnotation)ta; | 1009 StickyAxisAnnotation sta = (StickyAxisAnnotation)ta; |
1004 sta.applyTheme(themeAccess); | 1010 sta.applyTheme(themeAccess); |
1005 renderer.addAnnotation(sta); | 1011 renderer.addAnnotation(sta); |
1006 } | 1012 } |
1021 } | 1027 } |
1022 | 1028 |
1023 plot.setFixedLegendItems(old); | 1029 plot.setFixedLegendItems(old); |
1024 } | 1030 } |
1025 | 1031 |
1032 /** | |
1033 * Get "lowest" Y Value for first axis. This value is exactly at the | |
1034 * border of the plot. | |
1035 */ | |
1036 protected double getLowestYValue(XYPlot plot) { | |
1037 ValueAxis yaxis = plot.getRangeAxis(0); | |
1038 if (yaxis == null) { | |
1039 logger.warn("No first Y-Axis to find lowest value for."); | |
1040 } | |
1041 return yaxis.getRange().getLowerBound(); | |
1042 } | |
1043 | |
1044 | |
1045 /** | |
1046 * Get "lowest" Y Value for first axis. This value is exactly at the | |
1047 * border of the plot. | |
1048 */ | |
1049 protected double getUppestYValue(XYPlot plot) { | |
1050 ValueAxis yaxis = plot.getRangeAxis(0); | |
1051 if (yaxis == null) { | |
1052 logger.warn("No first Y-Axis to find uppest value for."); | |
1053 } | |
1054 return yaxis.getRange().getUpperBound(); | |
1055 } | |
1056 | |
1057 | |
1058 /** Get color for hyk zones by their type (which is the name). */ | |
1059 public Paint colorForHYKZone(String zoneName) { | |
1060 if (zoneName.startsWith("R")) { | |
1061 // Brownish. | |
1062 return new Color(153, 60, 0); | |
1063 } | |
1064 else if (zoneName.startsWith("V")) { | |
1065 // Greenish. | |
1066 return new Color(0, 255, 0); | |
1067 } | |
1068 else if (zoneName.startsWith("B")) { | |
1069 // Grayish. | |
1070 return new Color(128, 128, 128); | |
1071 } | |
1072 else if (zoneName.startsWith("H")) { | |
1073 // Blueish. | |
1074 return new Color(0, 0, 255); | |
1075 } | |
1076 else { | |
1077 // Default. | |
1078 logger.debug("Unknown zone type found."); | |
1079 return new Color(255, 0, 0); | |
1080 } | |
1081 } | |
1082 | |
1083 | |
1084 /** Add box annotations (currently, only hyk zones). */ | |
1085 public void addBoxAnnotations(XYPlot plot) { | |
1086 logger.debug("XYChartGenerator.addBoxAnnotations"); | |
1087 | |
1088 Stroke basicStroke = new BasicStroke(1.0f); | |
1089 | |
1090 Paint linePaint = new Color(255,0,0,60); | |
1091 Paint fillPaint = new Color(0,255,0,60); | |
1092 Paint tranPaint = new Color(0,0,0,0); | |
1093 | |
1094 double fillPercent = 0.05; | |
1095 double low = getLowestYValue(plot); | |
1096 double up = getUppestYValue(plot); | |
1097 double upb = low + (up - low) * fillPercent; | |
1098 double upt = low + (up - low) * fillPercent/2.0d; | |
1099 | |
1100 for (FLYSAnnotation fa: annotations) { | |
1101 for (HYKFactory.Zone zone: fa.getBoxes()) { | |
1102 fillPaint = colorForHYKZone(zone.getName()); | |
1103 | |
1104 XYBoxAnnotation boxA = new XYBoxAnnotation(zone.getFrom(), low, | |
1105 zone.getTo(), upb, basicStroke, tranPaint, fillPaint); | |
1106 XYBoxAnnotation boxB = new XYBoxAnnotation(zone.getFrom(), low, | |
1107 zone.getTo(), up, basicStroke, fillPaint, tranPaint); | |
1108 | |
1109 // TODO style text | |
1110 XYTextAnnotation tex = new XYTextAnnotation(zone.getName(), | |
1111 zone.getFrom() + (zone.getTo() - zone.getFrom()) / 2.0d, | |
1112 upt); | |
1113 | |
1114 plot.getRenderer().addAnnotation(boxA); | |
1115 plot.getRenderer().addAnnotation(boxB); | |
1116 plot.getRenderer().addAnnotation(tex); | |
1117 } | |
1118 } | |
1119 } | |
1026 | 1120 |
1027 /** | 1121 /** |
1028 * Adjusts the axes of a plot. This method sets the <i>labelFont</i> of the | 1122 * Adjusts the axes of a plot. This method sets the <i>labelFont</i> of the |
1029 * X axis. | 1123 * X axis. |
1030 * | 1124 * |