Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java @ 2152:2336927cb096
Add basic (text) styling for HYKS.
flys-artifacts/trunk@3734 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Fri, 20 Jan 2012 08:38:50 +0000 |
parents | c5d24e0587ce |
children | c68f4f227c09 |
comparison
equal
deleted
inserted
replaced
2151:eb1a676c0d6e | 2152:2336927cb096 |
---|---|
1027 } | 1027 } |
1028 | 1028 |
1029 plot.setFixedLegendItems(old); | 1029 plot.setFixedLegendItems(old); |
1030 } | 1030 } |
1031 | 1031 |
1032 | |
1032 /** | 1033 /** |
1033 * Get "lowest" Y Value for first axis. This value is exactly at the | 1034 * Get "lowest" Y Value for first axis. This value is exactly at the |
1034 * border of the plot. | 1035 * border of the plot. |
1036 * @return lowest value on first 'y'-axis. | |
1035 */ | 1037 */ |
1036 protected double getLowestYValue(XYPlot plot) { | 1038 protected double getLowestYValue(XYPlot plot) { |
1037 ValueAxis yaxis = plot.getRangeAxis(0); | 1039 ValueAxis yaxis = plot.getRangeAxis(0); |
1038 if (yaxis == null) { | 1040 if (yaxis == null) { |
1039 logger.warn("No first Y-Axis to find lowest value for."); | 1041 logger.warn("No first Y-Axis to find lowest value for."); |
1043 | 1045 |
1044 | 1046 |
1045 /** | 1047 /** |
1046 * Get "lowest" Y Value for first axis. This value is exactly at the | 1048 * Get "lowest" Y Value for first axis. This value is exactly at the |
1047 * border of the plot. | 1049 * border of the plot. |
1050 * @return highest value on first 'y'-axis. | |
1048 */ | 1051 */ |
1049 protected double getUppestYValue(XYPlot plot) { | 1052 protected double getUppestYValue(XYPlot plot) { |
1050 ValueAxis yaxis = plot.getRangeAxis(0); | 1053 ValueAxis yaxis = plot.getRangeAxis(0); |
1051 if (yaxis == null) { | 1054 if (yaxis == null) { |
1052 logger.warn("No first Y-Axis to find uppest value for."); | 1055 logger.warn("No first Y-Axis to find uppest value for."); |
1088 if (annotations == null) { | 1091 if (annotations == null) { |
1089 logger.debug("XYChartGenerator.addBoxAnnotations: no annotations."); | 1092 logger.debug("XYChartGenerator.addBoxAnnotations: no annotations."); |
1090 return; | 1093 return; |
1091 } | 1094 } |
1092 | 1095 |
1096 // Paints for the boxes/lines. | |
1093 Stroke basicStroke = new BasicStroke(1.0f); | 1097 Stroke basicStroke = new BasicStroke(1.0f); |
1094 | 1098 |
1095 Paint linePaint = new Color(255,0,0,60); | 1099 Paint linePaint = new Color(255,0,0,60); |
1096 Paint fillPaint = new Color(0,255,0,60); | 1100 Paint fillPaint = new Color(0,255,0,60); |
1097 Paint tranPaint = new Color(0,0,0,0); | 1101 Paint tranPaint = new Color(0,0,0,0); |
1098 | 1102 |
1103 // Pre-calculated positions on y axis. | |
1099 double fillPercent = 0.03; | 1104 double fillPercent = 0.03; |
1100 double low = getLowestYValue(plot); | 1105 double low = getLowestYValue(plot); |
1101 double up = getUppestYValue(plot); | 1106 double up = getUppestYValue(plot); |
1102 double upb = low + (up - low) * fillPercent; | 1107 double upb = low + (up - low) * fillPercent; |
1103 double upt = low + (up - low) * fillPercent/2.0d; | 1108 double upt = low + (up - low) * fillPercent/2.0d; |
1104 | 1109 |
1110 | |
1105 for (FLYSAnnotation fa: annotations) { | 1111 for (FLYSAnnotation fa: annotations) { |
1112 // Access text styling, if any. | |
1113 Document theme = fa.getTheme(); | |
1114 ThemeAccess.TextStyle textStyle = null; | |
1115 if (theme != null) { | |
1116 ThemeAccess themeAccess = new ThemeAccess(theme); | |
1117 textStyle = themeAccess.parseTextStyle(); | |
1118 } | |
1119 | |
1120 // For each zone, create a box to fill with color, a box to draw | |
1121 // the lines and a text to display the type. | |
1106 for (HYKFactory.Zone zone: fa.getBoxes()) { | 1122 for (HYKFactory.Zone zone: fa.getBoxes()) { |
1107 fillPaint = colorForHYKZone(zone.getName()); | 1123 fillPaint = colorForHYKZone(zone.getName()); |
1108 | 1124 |
1109 XYBoxAnnotation boxA = new XYBoxAnnotation(zone.getFrom(), low, | 1125 XYBoxAnnotation boxA = new XYBoxAnnotation(zone.getFrom(), low, |
1110 zone.getTo(), upb, basicStroke, tranPaint, fillPaint); | 1126 zone.getTo(), upb, basicStroke, tranPaint, fillPaint); |
1111 XYBoxAnnotation boxB = new XYBoxAnnotation(zone.getFrom(), low, | 1127 XYBoxAnnotation boxB = new XYBoxAnnotation(zone.getFrom(), low, |
1112 zone.getTo(), up, basicStroke, fillPaint, tranPaint); | 1128 zone.getTo(), up, basicStroke, fillPaint, tranPaint); |
1113 | 1129 |
1114 // TODO style text | |
1115 XYTextAnnotation tex = new XYTextAnnotation(zone.getName(), | 1130 XYTextAnnotation tex = new XYTextAnnotation(zone.getName(), |
1116 zone.getFrom() + (zone.getTo() - zone.getFrom()) / 2.0d, | 1131 zone.getFrom() + (zone.getTo() - zone.getFrom()) / 2.0d, |
1117 upt); | 1132 upt); |
1133 if (textStyle != null) { | |
1134 textStyle.apply(tex); | |
1135 } | |
1118 | 1136 |
1119 plot.getRenderer().addAnnotation(boxA); | 1137 plot.getRenderer().addAnnotation(boxA); |
1120 plot.getRenderer().addAnnotation(boxB); | 1138 plot.getRenderer().addAnnotation(boxB); |
1121 plot.getRenderer().addAnnotation(tex); | 1139 plot.getRenderer().addAnnotation(tex); |
1122 } | 1140 } |
1123 } | 1141 } |
1124 } | 1142 } |
1143 | |
1125 | 1144 |
1126 /** | 1145 /** |
1127 * Adjusts the axes of a plot. This method sets the <i>labelFont</i> of the | 1146 * Adjusts the axes of a plot. This method sets the <i>labelFont</i> of the |
1128 * X axis. | 1147 * X axis. |
1129 * | 1148 * |