diff gnv-artifacts/src/main/java/de/intevation/gnv/chart/AbstractXYLineChart.java @ 327:22a6493e8460

New options in chart template: visibility of lines and points in charts and point's size. gnv-artifacts/trunk@393 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 02 Dec 2009 10:50:12 +0000
parents 63f8b3fb7d9a
children 1c427acb6c76
line wrap: on
line diff
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/chart/AbstractXYLineChart.java	Tue Dec 01 16:27:56 2009 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/chart/AbstractXYLineChart.java	Wed Dec 02 10:50:12 2009 +0000
@@ -1,6 +1,7 @@
 package de.intevation.gnv.chart;
 
 import java.awt.Color;
+import java.awt.geom.Ellipse2D;
 import java.text.NumberFormat;
 import java.util.Collection;
 import java.util.Iterator;
@@ -16,7 +17,7 @@
 import org.jfree.chart.axis.AxisLocation;
 import org.jfree.chart.plot.PlotOrientation;
 import org.jfree.chart.plot.XYPlot;
-import org.jfree.chart.renderer.xy.StandardXYItemRenderer;
+import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
 import org.jfree.data.general.Series;
 
 import de.intevation.gnv.geobackend.base.Result;
@@ -28,7 +29,7 @@
 public abstract class AbstractXYLineChart
 extends               AbstractChart
 {
-    private static Logger log    = Logger.getLogger(AbstractXYLineChart.class);
+    private static Logger log      = Logger.getLogger(AbstractXYLineChart.class);
 
     protected static Color[] COLOR = {
         Color.black, Color.red, Color.green, Color.blue
@@ -99,9 +100,30 @@
         else
             plot.setRangeAxisLocation(idx, AxisLocation.BOTTOM_OR_LEFT);
         plot.mapDatasetToRangeAxis(idx, idx);
+    }
 
-        StandardXYItemRenderer renderer = new StandardXYItemRenderer();
-        renderer.setSeriesPaint(idx, COLOR[idx%COLOR.length]);
+
+    protected void adjustRenderer(
+        int     idx,
+        boolean renderLines,
+        boolean renderShapes
+    ) {
+        XYLineAndShapeRenderer renderer = null;
+        XYPlot                 plot     = chart.getXYPlot();
+
+        try {
+            renderer = (XYLineAndShapeRenderer)((XYLineAndShapeRenderer)
+                (plot.getRenderer())).clone();
+        }
+        catch (CloneNotSupportedException cnse) {
+            log.warn("Error while cloning renderer.", cnse);
+            renderer = new XYLineAndShapeRenderer(renderLines, renderShapes);
+            renderer.setBaseShape(new Ellipse2D.Double(-2,-2,4,4));
+        }
+
+        renderer.setSeriesPaint(0, COLOR[idx%COLOR.length]);
+        renderer.setSeriesShapesVisible(0, renderShapes);
+        renderer.setSeriesLinesVisible(0, renderLines);
         plot.setRenderer(idx, renderer);
     }
 

http://dive4elements.wald.intevation.org