Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/exports/TimeseriesChartGenerator.java @ 3622:5e505060a9bf
Enable logo rendering in timeseries charts.
flys-artifacts/trunk@5298 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Wed, 29 Aug 2012 15:26:50 +0000 |
parents | 66f539df4e8b |
children | 119b8ba2b77f |
comparison
equal
deleted
inserted
replaced
3621:6772e9f9b65f | 3622:5e505060a9bf |
---|---|
14 import java.util.Date; | 14 import java.util.Date; |
15 import java.util.HashMap; | 15 import java.util.HashMap; |
16 import java.util.List; | 16 import java.util.List; |
17 import java.util.Map; | 17 import java.util.Map; |
18 | 18 |
19 import javax.swing.ImageIcon; | |
20 | |
19 import org.apache.log4j.Logger; | 21 import org.apache.log4j.Logger; |
20 import org.jfree.chart.ChartFactory; | 22 import org.jfree.chart.ChartFactory; |
21 import org.jfree.chart.JFreeChart; | 23 import org.jfree.chart.JFreeChart; |
24 import org.jfree.chart.annotations.XYAnnotation; | |
25 import org.jfree.chart.annotations.XYImageAnnotation; | |
22 import org.jfree.chart.annotations.XYTextAnnotation; | 26 import org.jfree.chart.annotations.XYTextAnnotation; |
23 import org.jfree.chart.axis.ValueAxis; | 27 import org.jfree.chart.axis.ValueAxis; |
24 import org.jfree.chart.plot.Marker; | 28 import org.jfree.chart.plot.Marker; |
25 import org.jfree.chart.plot.XYPlot; | 29 import org.jfree.chart.plot.XYPlot; |
26 import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer; | 30 import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer; |
170 protected boolean domainZeroLineVisible; | 174 protected boolean domainZeroLineVisible; |
171 | 175 |
172 private static final Logger logger = | 176 private static final Logger logger = |
173 Logger.getLogger(TimeseriesChartGenerator.class); | 177 Logger.getLogger(TimeseriesChartGenerator.class); |
174 | 178 |
175 | |
176 public static final int AXIS_SPACE = 5; | 179 public static final int AXIS_SPACE = 5; |
177 | 180 |
178 | |
179 protected Map<Integer, Bounds> xBounds; | 181 protected Map<Integer, Bounds> xBounds; |
180 | 182 |
181 protected Map<Integer, Bounds> yBounds; | 183 protected Map<Integer, Bounds> yBounds; |
182 | |
183 | 184 |
184 | 185 |
185 /** | 186 /** |
186 * The default constructor that initializes internal datastructures. | 187 * The default constructor that initializes internal datastructures. |
187 */ | 188 */ |
223 addValueAxisMarker(plot); | 224 addValueAxisMarker(plot); |
224 adaptZoom(plot); | 225 adaptZoom(plot); |
225 | 226 |
226 applySeriesAttributes(plot); | 227 applySeriesAttributes(plot); |
227 addAnnotationsToRenderer(plot); | 228 addAnnotationsToRenderer(plot); |
229 addLogo(plot); | |
228 aggregateLegendEntries(plot); | 230 aggregateLegendEntries(plot); |
229 return chart; | 231 return chart; |
232 } | |
233 | |
234 | |
235 /** | |
236 * Return left most data points x value (on first axis). | |
237 * Shortcut, especially to be overridden in (LS) charts where | |
238 * axis could be inverted. | |
239 */ | |
240 protected double getLeftX() { | |
241 return (Long)getXBounds(0).getLower(); | |
242 } | |
243 | |
244 | |
245 /** | |
246 * Return right most data points x value (on first axis). | |
247 * Shortcut, especially to be overridden in (LS) charts where | |
248 * axis could be inverted. | |
249 */ | |
250 protected double getRightX() { | |
251 return (Long)getXBounds(0).getUpper(); | |
252 } | |
253 | |
254 | |
255 /** | |
256 * Add a logo as background annotation to plot. | |
257 * Copy from XYChartGenerator. | |
258 */ | |
259 protected void addLogo(XYPlot plot) { | |
260 String logo = showLogo(); | |
261 if (logo == null) { | |
262 logger.debug("No logo to show chosen"); | |
263 return; | |
264 } | |
265 | |
266 ImageIcon imageIcon = null; | |
267 if (logo.equals("none")) { | |
268 return; | |
269 } | |
270 if (logo.equals("Intevation")) { | |
271 imageIcon = new ImageIcon("/home/felix/Downloads/intevation_logo_120.png"); | |
272 } | |
273 else { // TODO else if ... | |
274 imageIcon = new ImageIcon("/home/felix/Downloads/bfg_logo.gif"); | |
275 } | |
276 | |
277 double xPos = 0d, yPos = 0d; | |
278 | |
279 String placeh = logoHPlace(); | |
280 String placev = logoVPlace(); | |
281 | |
282 if (placev == null || placev.equals("none")) { | |
283 placev = "top"; | |
284 } | |
285 if (placev.equals("top")) { | |
286 yPos = (Double)getYBounds(0).getUpper(); | |
287 } | |
288 else if (placev.equals("bottom")) { | |
289 yPos = (Double)getYBounds(0).getLower(); | |
290 } | |
291 else if (placev.equals("center")) { | |
292 yPos = ((Double)getYBounds(0).getUpper() + (Double)getYBounds(0).getLower())/2d; | |
293 } | |
294 else { | |
295 logger.debug("Unknown place-v value: " + placev); | |
296 } | |
297 | |
298 if (placeh == null || placeh.equals("none")) { | |
299 placeh = "center"; | |
300 } | |
301 if (placeh.equals("left")) { | |
302 xPos = getLeftX(); | |
303 } | |
304 else if (placeh.equals("right")) { | |
305 xPos = getRightX(); | |
306 } | |
307 else if (placeh.equals("center")) { | |
308 xPos = ((Double)getXBounds(0).getUpper() + (Double)getXBounds(0).getLower())/2d; | |
309 } | |
310 else { | |
311 logger.debug("Unknown place-h value: " + placeh); | |
312 } | |
313 | |
314 logger.debug("logo position: " + xPos + "/" + yPos); | |
315 | |
316 org.jfree.ui.RectangleAnchor anchor | |
317 = org.jfree.ui.RectangleAnchor.TOP; | |
318 if (placev.equals("top")) { | |
319 if (placeh.equals("left")) { | |
320 anchor = org.jfree.ui.RectangleAnchor.TOP_LEFT; | |
321 } | |
322 else if (placeh.equals("right")) { | |
323 anchor = org.jfree.ui.RectangleAnchor.TOP_RIGHT; | |
324 } | |
325 else if (placeh.equals("center")) { | |
326 anchor = org.jfree.ui.RectangleAnchor.TOP; | |
327 } | |
328 } | |
329 else if (placev.equals("bottom")) { | |
330 if (placeh.equals("left")) { | |
331 anchor = org.jfree.ui.RectangleAnchor.BOTTOM_LEFT; | |
332 } | |
333 else if (placeh.equals("right")) { | |
334 anchor = org.jfree.ui.RectangleAnchor.BOTTOM_RIGHT; | |
335 } | |
336 else if (placeh.equals("center")) { | |
337 anchor = org.jfree.ui.RectangleAnchor.BOTTOM; | |
338 } | |
339 } | |
340 else if (placev.equals("center")) { | |
341 if (placeh.equals("left")) { | |
342 anchor = org.jfree.ui.RectangleAnchor.LEFT; | |
343 } | |
344 else if (placeh.equals("right")) { | |
345 anchor = org.jfree.ui.RectangleAnchor.RIGHT; | |
346 } | |
347 else if (placeh.equals("center")) { | |
348 anchor = org.jfree.ui.RectangleAnchor.CENTER; | |
349 } | |
350 } | |
351 | |
352 XYAnnotation xyannotation = | |
353 new XYImageAnnotation(xPos, yPos, imageIcon.getImage(), anchor); | |
354 plot.getRenderer().addAnnotation(xyannotation, org.jfree.ui.Layer.BACKGROUND); | |
230 } | 355 } |
231 | 356 |
232 | 357 |
233 @Override | 358 @Override |
234 protected Series getSeriesOf(XYDataset dataset, int idx) { | 359 protected Series getSeriesOf(XYDataset dataset, int idx) { |