changeset 1932:17e18948fe5e

Fix legend and themeing with new multiaxis feature. flys-artifacts/trunk@3313 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Thu, 24 Nov 2011 10:59:40 +0000
parents 7c52e9cb2a72
children 9e9cfc036a3f
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java
diffstat 2 files changed, 41 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Thu Nov 24 07:20:46 2011 +0000
+++ b/flys-artifacts/ChangeLog	Thu Nov 24 10:59:40 2011 +0000
@@ -1,3 +1,12 @@
+2011-11-24  Felix Wolfsteller <felix.wolfsteller@intevation.de>
+
+	Fix theming and legend items for plot with multiaxis feature.
+	Decouple renderer index from dataset index.
+
+	* src/main/java/de/intevation/flys/exports/XYChartGenerator.java:
+	  (applyThemes): Do not get renderer based on dataset/axis-index but
+			 count.
+
 2011-11-24  Felix Wolfsteller <felix.wolfsteller@intevation.de>
 
 	In XYChartGenerators allow more than two datasets.
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java	Thu Nov 24 07:20:46 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java	Thu Nov 24 10:59:40 2011 +0000
@@ -480,7 +480,6 @@
 
             Color color   = themeAccess.parseLineColorField();
             int lineWidth = themeAccess.parseLineWidth();
-
             lic.add(new LegendItem(fa.getLabel(), color));
 
             for (XYTextAnnotation ta: fa.getAnnotations()) {
@@ -496,6 +495,7 @@
                 }
             }
 
+            // TODO Do after loop?
             plot.setFixedLegendItems(lic);
         }
     }
@@ -600,39 +600,53 @@
 
 
     protected void applyThemes(XYPlot plot) {
+        int idx = 0;
 
         for (Map.Entry<Integer, List<XYDataset>> entry: datasets.entrySet()) {
-            int axis = entry.getKey();
             for (XYDataset dataset: entry.getValue()) {
                 if (dataset instanceof XYSeriesCollection) {
-                    applyThemes(plot, (XYSeriesCollection)dataset, axis);
+                    idx = applyThemes(plot, (XYSeriesCollection)dataset, idx);
                 }
             }
         }
     }
 
 
-    protected void applyThemes(XYPlot plot, XYSeriesCollection dataset, int i) {
+    /**
+     * @param idx "index" of dataset/series (first dataset to be drawn has
+     *            index 0), correlates with renderer index.
+     * @return idx increased by number of items addded.
+     */
+    protected int applyThemes(XYPlot plot, XYSeriesCollection series, int idx) {
         LegendItemCollection lic  = new LegendItemCollection();
         LegendItemCollection anno = plot.getFixedLegendItems();
 
-        XYLineAndShapeRenderer r = getRenderer(plot, i);
+        XYLineAndShapeRenderer renderer = getRenderer(plot, idx);
+        int retidx = idx;
 
-        for (int s = 0, num = dataset.getSeriesCount(); s < num; s++) {
-            XYSeries series = dataset.getSeries(s);
+        for (int s = 0, num = series.getSeriesCount(); s < num; s++) {
+            XYSeries serie = series.getSeries(s);
 
-            if (series instanceof StyledXYSeries) {
-                ((StyledXYSeries) series).applyTheme(r, s);
+            if (serie instanceof StyledXYSeries) {
+                ((StyledXYSeries) serie).applyTheme(renderer, s);
             }
 
             // special case: if there is just one single item, we need to enable
             // points for this series, otherwise we would not see anything in
             // the chart area.
-            if (series.getItemCount() == 1) {
-                r.setSeriesShapesVisible(s, true);
+            if (serie.getItemCount() == 1) {
+                renderer.setSeriesShapesVisible(s, true);
             }
 
-            lic.add(r.getLegendItem(i, s));
+            LegendItem li = renderer.getLegendItem(idx, s);
+            if (li != null) {
+                lic.add(li);
+            }
+            else {
+                logger.warn("Could not get LegentItem for renderer: "
+                     + idx + ", series-idx " + s);
+            }
+            retidx++;
         }
 
         if (anno != null) {
@@ -641,10 +655,15 @@
 
         plot.setFixedLegendItems(lic);
 
-        plot.setRenderer(i, r);
+        plot.setRenderer(idx, renderer);
+
+        return retidx;
     }
 
 
+    /**
+     * Get renderer, from plot or cloned default renderer otherwise.
+     */
     protected XYLineAndShapeRenderer getRenderer(XYPlot plot, int idx) {
         XYLineAndShapeRenderer r =
             (XYLineAndShapeRenderer) plot.getRenderer(idx);

http://dive4elements.wald.intevation.org