# HG changeset patch # User Felix Wolfsteller # Date 1346254010 0 # Node ID 5e505060a9bf9b624f92d19534cb08e62dcdc221 # Parent 6772e9f9b65f7f4a90fcd9a16dc4627ff54494c1 Enable logo rendering in timeseries charts. flys-artifacts/trunk@5298 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 6772e9f9b65f -r 5e505060a9bf flys-artifacts/ChangeLog --- a/flys-artifacts/ChangeLog Wed Aug 29 14:43:26 2012 +0000 +++ b/flys-artifacts/ChangeLog Wed Aug 29 15:26:50 2012 +0000 @@ -1,3 +1,8 @@ +2012-08-29 Felix Wolfsteller + + * src/main/java/de/intevation/flys/exports/TimeseriesChartGenerator.java: + Copy and slightly modified XYChartGenerators logo mechanism. + 2012-08-29 Felix Wolfsteller * src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java, diff -r 6772e9f9b65f -r 5e505060a9bf flys-artifacts/src/main/java/de/intevation/flys/exports/TimeseriesChartGenerator.java --- a/flys-artifacts/src/main/java/de/intevation/flys/exports/TimeseriesChartGenerator.java Wed Aug 29 14:43:26 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/TimeseriesChartGenerator.java Wed Aug 29 15:26:50 2012 +0000 @@ -16,9 +16,13 @@ import java.util.List; import java.util.Map; +import javax.swing.ImageIcon; + import org.apache.log4j.Logger; import org.jfree.chart.ChartFactory; import org.jfree.chart.JFreeChart; +import org.jfree.chart.annotations.XYAnnotation; +import org.jfree.chart.annotations.XYImageAnnotation; import org.jfree.chart.annotations.XYTextAnnotation; import org.jfree.chart.axis.ValueAxis; import org.jfree.chart.plot.Marker; @@ -172,16 +176,13 @@ private static final Logger logger = Logger.getLogger(TimeseriesChartGenerator.class); - public static final int AXIS_SPACE = 5; - protected Map xBounds; protected Map yBounds; - /** * The default constructor that initializes internal datastructures. */ @@ -225,11 +226,135 @@ applySeriesAttributes(plot); addAnnotationsToRenderer(plot); + addLogo(plot); aggregateLegendEntries(plot); return chart; } + /** + * Return left most data points x value (on first axis). + * Shortcut, especially to be overridden in (LS) charts where + * axis could be inverted. + */ + protected double getLeftX() { + return (Long)getXBounds(0).getLower(); + } + + + /** + * Return right most data points x value (on first axis). + * Shortcut, especially to be overridden in (LS) charts where + * axis could be inverted. + */ + protected double getRightX() { + return (Long)getXBounds(0).getUpper(); + } + + + /** + * Add a logo as background annotation to plot. + * Copy from XYChartGenerator. + */ + protected void addLogo(XYPlot plot) { + String logo = showLogo(); + if (logo == null) { + logger.debug("No logo to show chosen"); + return; + } + + ImageIcon imageIcon = null; + if (logo.equals("none")) { + return; + } + if (logo.equals("Intevation")) { + imageIcon = new ImageIcon("/home/felix/Downloads/intevation_logo_120.png"); + } + else { // TODO else if ... + imageIcon = new ImageIcon("/home/felix/Downloads/bfg_logo.gif"); + } + + double xPos = 0d, yPos = 0d; + + String placeh = logoHPlace(); + String placev = logoVPlace(); + + if (placev == null || placev.equals("none")) { + placev = "top"; + } + if (placev.equals("top")) { + yPos = (Double)getYBounds(0).getUpper(); + } + else if (placev.equals("bottom")) { + yPos = (Double)getYBounds(0).getLower(); + } + else if (placev.equals("center")) { + yPos = ((Double)getYBounds(0).getUpper() + (Double)getYBounds(0).getLower())/2d; + } + else { + logger.debug("Unknown place-v value: " + placev); + } + + if (placeh == null || placeh.equals("none")) { + placeh = "center"; + } + if (placeh.equals("left")) { + xPos = getLeftX(); + } + else if (placeh.equals("right")) { + xPos = getRightX(); + } + else if (placeh.equals("center")) { + xPos = ((Double)getXBounds(0).getUpper() + (Double)getXBounds(0).getLower())/2d; + } + else { + logger.debug("Unknown place-h value: " + placeh); + } + + logger.debug("logo position: " + xPos + "/" + yPos); + + org.jfree.ui.RectangleAnchor anchor + = org.jfree.ui.RectangleAnchor.TOP; + if (placev.equals("top")) { + if (placeh.equals("left")) { + anchor = org.jfree.ui.RectangleAnchor.TOP_LEFT; + } + else if (placeh.equals("right")) { + anchor = org.jfree.ui.RectangleAnchor.TOP_RIGHT; + } + else if (placeh.equals("center")) { + anchor = org.jfree.ui.RectangleAnchor.TOP; + } + } + else if (placev.equals("bottom")) { + if (placeh.equals("left")) { + anchor = org.jfree.ui.RectangleAnchor.BOTTOM_LEFT; + } + else if (placeh.equals("right")) { + anchor = org.jfree.ui.RectangleAnchor.BOTTOM_RIGHT; + } + else if (placeh.equals("center")) { + anchor = org.jfree.ui.RectangleAnchor.BOTTOM; + } + } + else if (placev.equals("center")) { + if (placeh.equals("left")) { + anchor = org.jfree.ui.RectangleAnchor.LEFT; + } + else if (placeh.equals("right")) { + anchor = org.jfree.ui.RectangleAnchor.RIGHT; + } + else if (placeh.equals("center")) { + anchor = org.jfree.ui.RectangleAnchor.CENTER; + } + } + + XYAnnotation xyannotation = + new XYImageAnnotation(xPos, yPos, imageIcon.getImage(), anchor); + plot.getRenderer().addAnnotation(xyannotation, org.jfree.ui.Layer.BACKGROUND); + } + + @Override protected Series getSeriesOf(XYDataset dataset, int idx) { return ((TimeSeriesCollection) dataset).getSeries(idx);