Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/FixingsKMChartService.java @ 3146:1edc17b0d79d
FixA: Draw domain markers for borders of Q sectors in helper diagram.
flys-artifacts/trunk@4754 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Fri, 22 Jun 2012 11:26:01 +0000 |
parents | 5642a83420f2 |
children | 08230c76cd92 |
comparison
equal
deleted
inserted
replaced
3145:be612065993e | 3146:1edc17b0d79d |
---|---|
12 | 12 |
13 import de.intevation.flys.artifacts.model.FixingsOverview.Fixing; | 13 import de.intevation.flys.artifacts.model.FixingsOverview.Fixing; |
14 | 14 |
15 import de.intevation.flys.artifacts.model.FixingsOverview; | 15 import de.intevation.flys.artifacts.model.FixingsOverview; |
16 import de.intevation.flys.artifacts.model.FixingsOverviewFactory; | 16 import de.intevation.flys.artifacts.model.FixingsOverviewFactory; |
17 import de.intevation.flys.artifacts.model.GaugeFinder; | |
18 import de.intevation.flys.artifacts.model.GaugeFinderFactory; | |
19 import de.intevation.flys.artifacts.model.GaugeRange; | |
17 | 20 |
18 import de.intevation.flys.backend.SessionHolder; | 21 import de.intevation.flys.backend.SessionHolder; |
19 | 22 |
20 import de.intevation.flys.utils.Pair; | 23 import de.intevation.flys.utils.Pair; |
21 | 24 |
22 import gnu.trove.TDoubleArrayList; | 25 import gnu.trove.TDoubleArrayList; |
23 | 26 |
27 import java.awt.BasicStroke; | |
28 import java.awt.Color; | |
24 import java.awt.Dimension; | 29 import java.awt.Dimension; |
25 import java.awt.Transparency; | 30 import java.awt.Transparency; |
26 | 31 |
27 import java.awt.image.BufferedImage; | 32 import java.awt.image.BufferedImage; |
28 | 33 |
38 | 43 |
39 import org.jfree.chart.ChartFactory; | 44 import org.jfree.chart.ChartFactory; |
40 import org.jfree.chart.ChartUtilities; | 45 import org.jfree.chart.ChartUtilities; |
41 import org.jfree.chart.JFreeChart; | 46 import org.jfree.chart.JFreeChart; |
42 | 47 |
48 import org.jfree.chart.plot.Marker; | |
43 import org.jfree.chart.plot.PlotOrientation; | 49 import org.jfree.chart.plot.PlotOrientation; |
50 import org.jfree.chart.plot.ValueMarker; | |
44 import org.jfree.chart.plot.XYPlot; | 51 import org.jfree.chart.plot.XYPlot; |
45 | 52 |
46 import org.jfree.data.xy.DefaultXYDataset; | 53 import org.jfree.data.xy.DefaultXYDataset; |
54 | |
55 import org.jfree.ui.RectangleAnchor; | |
56 import org.jfree.ui.TextAnchor; | |
47 | 57 |
48 import org.w3c.dom.Document; | 58 import org.w3c.dom.Document; |
49 import org.w3c.dom.Element; | 59 import org.w3c.dom.Element; |
50 import org.w3c.dom.NodeList; | 60 import org.w3c.dom.NodeList; |
51 | 61 |
55 private static final Logger log = | 65 private static final Logger log = |
56 Logger.getLogger(FixingsKMChartService.class); | 66 Logger.getLogger(FixingsKMChartService.class); |
57 | 67 |
58 public static final int DEFAULT_WIDTH = 240; | 68 public static final int DEFAULT_WIDTH = 240; |
59 public static final int DEFAULT_HEIGHT = 180; | 69 public static final int DEFAULT_HEIGHT = 180; |
70 | |
71 // TODO: i18n | |
72 public static final String [] Q_SECTOR_LABELS = { | |
73 "(MNQ + MQ)/2", | |
74 "(MQ + MHQ)/2", | |
75 "HQ5" | |
76 }; | |
60 | 77 |
61 public static final String DEFAULT_FORMAT = "png"; | 78 public static final String DEFAULT_FORMAT = "png"; |
62 | 79 |
63 // TODO: Load fancy image from resources. | 80 // TODO: Load fancy image from resources. |
64 public static final byte [] EMPTY = { | 81 public static final byte [] EMPTY = { |
223 PlotOrientation.VERTICAL, | 240 PlotOrientation.VERTICAL, |
224 true, | 241 true, |
225 false, | 242 false, |
226 false); | 243 false); |
227 | 244 |
228 //XYPlot plot = chart.getXYPlot(); | 245 applyQSectorMarkers(chart.getXYPlot(), river, km); |
229 | |
230 //plot.setDataset(dataset); | |
231 | 246 |
232 ChartUtilities.applyCurrentTheme(chart); | 247 ChartUtilities.applyCurrentTheme(chart); |
233 | 248 |
234 return chart; | 249 return chart; |
250 } | |
251 | |
252 protected static void applyQSectorMarkers( | |
253 XYPlot plot, | |
254 String river, | |
255 double km | |
256 ) { | |
257 GaugeFinderFactory ggf = GaugeFinderFactory.getInstance(); | |
258 GaugeFinder gf = ggf.getGaugeFinder(river); | |
259 | |
260 if (gf == null) { | |
261 log.warn("No gauge finder found for river '" + river + "'"); | |
262 return; | |
263 } | |
264 | |
265 GaugeRange gr = gf.find(km); | |
266 if (gr == null) { | |
267 log.debug("No gauge range found for km " | |
268 + km + " on river " + river + "."); | |
269 return; | |
270 } | |
271 | |
272 for (int i = 0; i < Q_SECTOR_LABELS.length; ++i) { | |
273 Marker m = createQSectorMarker( | |
274 gr.getSectorBorder(i), | |
275 Q_SECTOR_LABELS[i]); | |
276 if (m != null) { | |
277 plot.addDomainMarker(m); | |
278 } | |
279 } | |
280 } | |
281 | |
282 protected static Marker createQSectorMarker(double value, String label) { | |
283 if (Double.isNaN(value)) { | |
284 return null; | |
285 } | |
286 Marker m = new ValueMarker(value); | |
287 m.setPaint(Color.black); | |
288 m.setStroke(new BasicStroke()); | |
289 m.setLabel(label); | |
290 m.setLabelAnchor(RectangleAnchor.TOP_LEFT); | |
291 m.setLabelTextAnchor(TextAnchor.TOP_LEFT); | |
292 return m; | |
235 } | 293 } |
236 | 294 |
237 protected static String getRiverName(Document input) { | 295 protected static String getRiverName(Document input) { |
238 NodeList rivers = input.getElementsByTagName("river"); | 296 NodeList rivers = input.getElementsByTagName("river"); |
239 | 297 |