changeset 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 3cb2bea50456
children 20a480753ff9
files gnv-artifacts/ChangeLog gnv-artifacts/src/main/java/de/intevation/gnv/chart/VerticalCrossSectionChart.java gnv-artifacts/src/main/java/de/intevation/gnv/raster/Palette.java
diffstat 3 files changed, 38 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/gnv-artifacts/ChangeLog	Sun Jan 03 12:16:55 2010 +0000
+++ b/gnv-artifacts/ChangeLog	Sun Jan 03 15:57:02 2010 +0000
@@ -1,3 +1,11 @@
+2010-01-03	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
+	* src/main/java/de/intevation/gnv/chart/VerticalCrossSectionChart.java:
+	  Only add colors to scale which are in the chart.
+
+	* src/main/java/de/intevation/gnv/raster/Palette.java: Added
+	  getter for 'color' field of palette entry.
+
 2010-01-03	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	* src/main/java/de/intevation/gnv/state/profile/verticalcrosssection/VerticalCrossSectionOutputState.java:
@@ -340,7 +348,7 @@
 	  neighbor values at the respective depth.
 
 	  The result is stored into a double valued raster. NaN values
-	  indicates interpolation gaps.
+	  indicate interpolation gaps.
 
 2009-12-23	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
--- 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);
 
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/raster/Palette.java	Sun Jan 03 12:16:55 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/raster/Palette.java	Sun Jan 03 15:57:02 2010 +0000
@@ -75,6 +75,10 @@
             return to;
         }
 
+        public Color getColor() {
+            return color;
+        }
+
         public Entry locateEntry(double value) {
             Entry current = this;
             while (current != null) {

http://dive4elements.wald.intevation.org