Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/exports/ComputedDischargeCurveGenerator.java @ 1089:e298c4d28927
Improved mainvalues rendering.
flys-artifacts/trunk@2592 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Fri, 26 Aug 2011 11:15:24 +0000 |
parents | 07878836ee0d |
children | 0eb585cd3882 |
comparison
equal
deleted
inserted
replaced
1088:1f5b92531f72 | 1089:e298c4d28927 |
---|---|
9 import org.jfree.chart.JFreeChart; | 9 import org.jfree.chart.JFreeChart; |
10 import org.jfree.chart.title.TextTitle; | 10 import org.jfree.chart.title.TextTitle; |
11 import org.jfree.data.xy.XYSeries; | 11 import org.jfree.data.xy.XYSeries; |
12 import org.jfree.chart.axis.ValueAxis; | 12 import org.jfree.chart.axis.ValueAxis; |
13 import org.jfree.chart.plot.XYPlot; | 13 import org.jfree.chart.plot.XYPlot; |
14 import org.jfree.chart.annotations.XYAnnotation; | |
14 | 15 |
15 import de.intevation.artifacts.Artifact; | 16 import de.intevation.artifacts.Artifact; |
16 | 17 |
17 import de.intevation.artifactdatabase.state.Facet; | 18 import de.intevation.artifactdatabase.state.Facet; |
18 | 19 |
19 import de.intevation.flys.artifacts.FLYSArtifact; | 20 import de.intevation.flys.artifacts.FLYSArtifact; |
21 import de.intevation.flys.artifacts.model.NamedDouble; | |
20 import de.intevation.flys.artifacts.model.FacetTypes; | 22 import de.intevation.flys.artifacts.model.FacetTypes; |
21 import de.intevation.flys.artifacts.model.WQKms; | 23 import de.intevation.flys.artifacts.model.WQKms; |
22 | 24 |
23 import de.intevation.flys.jfree.StickyAxisAnnotation; | 25 import de.intevation.flys.jfree.StickyAxisAnnotation; |
24 | 26 |
25 import de.intevation.flys.model.MainValue; | |
26 | 27 |
27 /** | 28 /** |
28 * An OutGenerator that generates discharge curves. | 29 * An OutGenerator that generates discharge curves. |
29 * | 30 * |
30 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | 31 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
48 "chart.computed.discharge.curve.yaxis.label"; | 49 "chart.computed.discharge.curve.yaxis.label"; |
49 | 50 |
50 public static final String I18N_CHART_TITLE_DEFAULT = "Abflusskurve"; | 51 public static final String I18N_CHART_TITLE_DEFAULT = "Abflusskurve"; |
51 public static final String I18N_YAXIS_LABEL_DEFAULT = "W [NN + m]"; | 52 public static final String I18N_YAXIS_LABEL_DEFAULT = "W [NN + m]"; |
52 | 53 |
53 /** List of W MainValues (Annotations in plot). */ | 54 /** List of Annotations (specifically, Main Values). */ |
54 protected static List<MainValue> mainValuesW; | 55 protected List<XYAnnotation> annotations; |
55 | |
56 /** List of Q MainValues (Annotations in plot). */ | |
57 protected static List<MainValue> mainValuesQ; | |
58 | 56 |
59 // TODO Add pseudodataseries for having mainvalue-text in legend. | 57 // TODO Add pseudodataseries for having mainvalue-text in legend. |
60 // TODO Let theme pass through to annotations-facets. | 58 // TODO Let theme pass through to annotations-facets. |
61 | 59 |
62 | 60 |
63 /** Trivial Constructor. */ | 61 /** Trivial Constructor. */ |
64 public ComputedDischargeCurveGenerator () { | 62 public ComputedDischargeCurveGenerator () { |
65 super(); | 63 super(); |
66 mainValuesQ = new ArrayList<MainValue>(); | 64 annotations= new ArrayList<XYAnnotation>(); |
67 mainValuesW = new ArrayList<MainValue>(); | |
68 } | 65 } |
69 | 66 |
70 | 67 |
71 @Override | 68 @Override |
72 protected String getChartTitle() { | 69 protected String getChartTitle() { |
110 | 107 |
111 if (name.equals(COMPUTED_DISCHARGE_Q)) { | 108 if (name.equals(COMPUTED_DISCHARGE_Q)) { |
112 doQOut((WQKms) f.getData(artifact, context), attr); | 109 doQOut((WQKms) f.getData(artifact, context), attr); |
113 } | 110 } |
114 else if (name.equals(COMPUTED_DISCHARGE_MAINVALUES_Q)) { | 111 else if (name.equals(COMPUTED_DISCHARGE_MAINVALUES_Q)) { |
112 doMainValueQAnnotations(f.getData(artifact, context), attr); | |
113 } | |
114 else if (name.equals(COMPUTED_DISCHARGE_MAINVALUES_W)) { | |
115 doMainValueWAnnotations(f.getData(artifact, context), attr); | 115 doMainValueWAnnotations(f.getData(artifact, context), attr); |
116 } | |
117 else if (name.equals(COMPUTED_DISCHARGE_MAINVALUES_W)) { | |
118 doMainValueQAnnotations(f.getData(artifact, context), attr); | |
119 } | 116 } |
120 else { | 117 else { |
121 logger.warn("Unknown facet type for computed discharge: " + name); | 118 logger.warn("Unknown facet type for computed discharge: " + name); |
122 return; | 119 return; |
123 } | 120 } |
127 /** | 124 /** |
128 * Store W MainValues as annotations for later plotting. | 125 * Store W MainValues as annotations for later plotting. |
129 */ | 126 */ |
130 protected void doMainValueWAnnotations(Object o, Document theme) { | 127 protected void doMainValueWAnnotations(Object o, Document theme) { |
131 logger.debug("ComputedDischargeCurveGenerator set W MainValues."); | 128 logger.debug("ComputedDischargeCurveGenerator set W MainValues."); |
132 this.mainValuesW = (List<MainValue>) o; | 129 List<NamedDouble> mainValuesW = (List<NamedDouble>) o; |
130 for (NamedDouble mv: mainValuesW) { | |
131 float pos = (float) mv.getValue(); | |
132 String text = mv.getName(); | |
133 StickyAxisAnnotation ta = new StickyAxisAnnotation(text, pos, | |
134 StickyAxisAnnotation.SimpleAxis.Y_AXIS); | |
135 logger.debug("Adding W: " + text + " : " + pos); | |
136 this.annotations.add(ta); | |
137 } | |
133 } | 138 } |
134 | 139 |
135 | 140 |
136 /** | 141 /** |
137 * Store Q MainValues as annotations for later plotting. | 142 * Store Q MainValues as annotations for later plotting. |
138 */ | 143 */ |
139 protected void doMainValueQAnnotations(Object o, Document theme) { | 144 protected void doMainValueQAnnotations(Object o, Document theme) { |
140 logger.debug("ComputedDischargeCurveGenerator set Q MainValues."); | 145 logger.debug("ComputedDischargeCurveGenerator set Q MainValues."); |
141 this.mainValuesQ = (List<MainValue>) o; | 146 List<NamedDouble> mainValuesQ = (List<NamedDouble>) o; |
147 for (NamedDouble mv: mainValuesQ) { | |
148 float pos = (float) mv.getValue(); | |
149 String text = mv.getName(); | |
150 StickyAxisAnnotation ta = new StickyAxisAnnotation(text, pos); | |
151 this.annotations.add(ta); | |
152 } | |
142 } | 153 } |
143 | 154 |
144 | 155 |
145 /** Generate Chart with annotations. */ | 156 /** Generate Chart with annotations. */ |
146 @Override | 157 @Override |
147 public JFreeChart generateChart() { | 158 public JFreeChart generateChart() { |
148 JFreeChart c = super.generateChart(); | 159 JFreeChart c = super.generateChart(); |
149 XYPlot p = (XYPlot) c.getPlot(); | 160 XYPlot p = (XYPlot) c.getPlot(); |
150 redoAnnotations(p, p.getDomainAxis()); | 161 redoAnnotations(p); |
151 return c; | 162 return c; |
152 } | 163 } |
153 | 164 |
154 | 165 |
155 /** | 166 /** |
156 * Recalculate some annotation positions and add them to plot. | 167 * Recalculate some annotation positions and add them to plot. |
157 * Annotations represent MainValues. | 168 * Annotations represent MainValues. |
158 * @param plot Plot to add annotations to. | 169 * @param plot Plot to add annotations to. |
159 * @param valueAxis ignored. | 170 */ |
160 */ | 171 protected void redoAnnotations(XYPlot plot) { |
161 protected void redoAnnotations(XYPlot plot, ValueAxis axis) { | |
162 plot.clearAnnotations(); | 172 plot.clearAnnotations(); |
163 // Add all MainValues as annotations. | 173 |
164 for (MainValue mv: mainValuesQ) { | 174 for (XYAnnotation a: annotations) { |
165 float pos = mv.getValue().floatValue(); | 175 plot.addAnnotation(a, false); |
166 String text = mv.getMainValue().getName(); | |
167 StickyAxisAnnotation ta = new StickyAxisAnnotation(text, pos, | |
168 StickyAxisAnnotation.SimpleAxis.X_AXIS); | |
169 plot.getRenderer().addAnnotation(ta); | |
170 } | |
171 for (MainValue mv: mainValuesW) { | |
172 float pos = mv.getValue().floatValue(); | |
173 String text = mv.getMainValue().getName(); | |
174 StickyAxisAnnotation ta = new StickyAxisAnnotation(text, pos, | |
175 StickyAxisAnnotation.SimpleAxis.Y_AXIS); | |
176 plot.getRenderer().addAnnotation(ta); | |
177 } | 176 } |
178 } | 177 } |
179 | 178 |
180 | 179 |
181 /** | 180 /** |