diff gnv-artifacts/src/main/java/de/intevation/gnv/chart/VerticalCrossSectionChart.java @ 449:c7ca2fce041f

Add only color to scale of vertical cross section which are in the chart. gnv-artifacts/trunk@497 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Sun, 03 Jan 2010 15:57:02 +0000
parents f5a041000357
children 20a480753ff9
line wrap: on
line diff
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/chart/VerticalCrossSectionChart.java	Sun Jan 03 12:16:55 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/chart/VerticalCrossSectionChart.java	Sun Jan 03 15:57:02 2010 +0000
@@ -5,10 +5,13 @@
 import java.awt.Color;
 import java.awt.Paint;
 
+import java.util.HashSet;
+
 import de.intevation.gnv.math.AttributedXYColumns;
 
 import de.intevation.gnv.jfreechart.PolygonDataset;
 import de.intevation.gnv.jfreechart.PolygonPlot;
+import de.intevation.gnv.jfreechart.PolygonSeries;
 import de.intevation.gnv.jfreechart.PolygonRenderer;
 
 import de.intevation.gnv.raster.Palette;
@@ -82,6 +85,16 @@
         PlotOrientation po  = PlotOrientation.HORIZONTAL;
         PolygonDataset data = columns.getPolygonDataset();
 
+        HashSet<Integer> usedColors = new HashSet<Integer>();
+
+        for (int i = data.getSeriesCount()-1; i >= 0; --i) {
+            PolygonSeries ps = data.getSeries(i);
+            Integer fill = (Integer)ps.getAttribute("fill");
+            if (fill != null) {
+                usedColors.add(fill);
+            }
+        }
+
         PolygonRenderer renderer = new PolygonRenderer(
             new PalettePaintLookup(palette));
 
@@ -95,17 +108,22 @@
             rangeAxis,
             null);
 
+        String [] labels = new String[usedColors.size()];
+
         int colors = palette.getSize();
         LookupPaintScale lookupPaint =
-            new LookupPaintScale(-0.5d, colors-0.5d, Color.white);
+            new LookupPaintScale(-0.5d, labels.length-0.5d, Color.white);
 
         Color color = null;
 
-        String [] labels = new String[colors];
-        for (int i = 0; i < colors; i++) {
-            color     = palette.getColor(colors-1-i);
-            labels[i] = palette.getEntryByIndex(colors-1-i).getDescription();
-            lookupPaint.add(i-0.5d, color);
+        for (int i = 0, j = labels.length-1; i < colors && j >= 0; i++) {
+            if (usedColors.contains(i)) {
+                Palette.Entry entry = palette.getEntryByIndex(i);
+                color     = entry.getColor();
+                labels[j] = entry.getDescription();
+                lookupPaint.add(j-0.5d, color);
+                --j;
+            }
         }
 
         JFreeChart chart = new JFreeChart(
@@ -117,7 +135,7 @@
         chart.removeLegend();
 
         SymbolAxis scale = new SymbolAxis("Temperatur", labels);
-        scale.setRange(-1.5d, colors+0.5d);
+        scale.setRange(-1.5d, labels.length+0.5d);
         scale.setGridBandsVisible(false);
         scale.setPlot(plot);
 

http://dive4elements.wald.intevation.org