changeset 4044:7eebd9e58641

Add chart legend entries for interpolated series (#838).
author Christian Lins <christian.lins@intevation.de>
date Fri, 05 Oct 2012 23:21:18 +0200
parents eb5564662e19
children de6e2b933f33
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/exports/TimeseriesChartGenerator.java flys-artifacts/src/main/java/de/intevation/flys/jfree/FLYSAnnotation.java
diffstat 3 files changed, 52 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Fri Oct 05 15:36:42 2012 +0200
+++ b/flys-artifacts/ChangeLog	Fri Oct 05 23:21:18 2012 +0200
@@ -1,3 +1,8 @@
+2012-10-05	Christian Lins	<christian.lins@intevation.de>
+
+	* src/main/java/de/intevation/flys/exports/TimeseriesChartGenerator.java:
+	  Add chart legend entries for interpolated series (#838).
+
 2012-10-05	Felix Wolfsteller	<felix.wolfsteller@intevation.de>
 
 	* doc/conf/meta-data.xml: Fix typo.
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/TimeseriesChartGenerator.java	Fri Oct 05 15:36:42 2012 +0200
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/TimeseriesChartGenerator.java	Fri Oct 05 23:21:18 2012 +0200
@@ -16,6 +16,7 @@
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
@@ -24,6 +25,8 @@
 import org.apache.log4j.Logger;
 import org.jfree.chart.ChartFactory;
 import org.jfree.chart.JFreeChart;
+import org.jfree.chart.LegendItem;
+import org.jfree.chart.LegendItemCollection;
 import org.jfree.chart.annotations.XYAnnotation;
 import org.jfree.chart.annotations.XYImageAnnotation;
 import org.jfree.chart.annotations.XYTextAnnotation;
@@ -758,6 +761,18 @@
         attributes.put(seriesKey, name);
     }
 
+    private LegendItem getLegendItemFor(XYPlot plot, String interSeriesKey) {
+        LegendItemCollection litems = plot.getLegendItems();
+        Iterator<LegendItem> iter = litems.iterator();
+        while(iter.hasNext()) {
+            LegendItem item = iter.next();
+            if(interSeriesKey.startsWith(item.getSeriesKey().toString())) {
+                return item;
+            }
+        }
+        return null;
+    }
+
     protected void applySeriesAttributes(XYPlot plot) {
         int count  = plot.getDatasetCount();
         for (int i = 0; i < count; i++) {
@@ -765,22 +780,49 @@
             if (data == null) {
                 continue;
             }
+
             int seriesCount = data.getSeriesCount();
             for (int j = 0; j < seriesCount; j++) {
                 StyledTimeSeries series =
                     (StyledTimeSeries)getSeriesOf(data, j);
                 String key = series.getKey().toString();
+
                 if (attributes.containsKey(key)) {
                     // Interpolated points are drawn unfilled
                     if (attributes.get(key).equals("interpolate")) {
                         XYLineAndShapeRenderer renderer =
-                            series.getStyle().getRenderer();
+                                series.getStyle().getRenderer();
                         renderer.setSeriesPaint(
                             j,
                             renderer.getSeriesFillPaint(j));
                         renderer.setSeriesShapesFilled(j, false);
+
+                        LegendItem legendItem = getLegendItemFor(plot, key);
+                        if(legendItem != null) {
+                            LegendItem interLegend = new LegendItem(
+                                    legendItem.getLabel(),
+                                    legendItem.getDescription(),
+                                    legendItem.getToolTipText(),
+                                    legendItem.getURLText(),
+                                    legendItem.isShapeVisible(),
+                                    legendItem.getShape(),
+                                    false, // shapeFilled?
+                                    legendItem.getFillPaint(),
+                                    true,  // shapeOutlineVisible?
+                                    renderer.getSeriesFillPaint(j),
+                                    legendItem.getOutlineStroke(),
+                                    legendItem.isLineVisible(),
+                                    legendItem.getLine(),
+                                    legendItem.getLineStroke(),
+                                    legendItem.getLinePaint()
+                                    );
+                            interLegend.setSeriesKey(series.getKey());
+                            logger.debug("applySeriesAttributes: draw unfilled legend item");
+                            plot.getLegendItems().add(interLegend);
+                        }
                     }
                 }
+
                 if (attributes.containsKey(key)) {
                     if(attributes.get(key).equals("outline")) {
                         XYLineAndShapeRenderer renderer =
--- a/flys-artifacts/src/main/java/de/intevation/flys/jfree/FLYSAnnotation.java	Fri Oct 05 15:36:42 2012 +0200
+++ b/flys-artifacts/src/main/java/de/intevation/flys/jfree/FLYSAnnotation.java	Fri Oct 05 23:21:18 2012 +0200
@@ -1,20 +1,19 @@
 package de.intevation.flys.jfree;
 
+import de.intevation.flys.artifacts.model.HYKFactory;
+
 import java.util.Collections;
 import java.util.List;
 
+import org.jfree.chart.annotations.XYTextAnnotation;
 import org.w3c.dom.Document;
 
-import org.jfree.chart.annotations.XYTextAnnotation;
-
-import de.intevation.flys.artifacts.model.HYKFactory;
-
 /**
  * List of Text- Annotations with name and theme.
  */
 public class FLYSAnnotation {
 
-    /* 'Other' Text Annotations. */
+    /** 'Other' Text Annotations. */
     protected List<XYTextAnnotation> textAnnotations;
 
     /** Annotations at axis. */

http://dive4elements.wald.intevation.org