# HG changeset patch # User Sascha L. Teichmann # Date 1262534222 0 # Node ID c7ca2fce041f75466f6ee36286e2f14c3ecfd85f # Parent 3cb2bea5045614fe2972ee5adf95bfc926c554c7 Add only color to scale of vertical cross section which are in the chart. gnv-artifacts/trunk@497 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 3cb2bea50456 -r c7ca2fce041f gnv-artifacts/ChangeLog --- 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 + + * 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 * 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 diff -r 3cb2bea50456 -r c7ca2fce041f gnv-artifacts/src/main/java/de/intevation/gnv/chart/VerticalCrossSectionChart.java --- 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 usedColors = new HashSet(); + + 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); diff -r 3cb2bea50456 -r c7ca2fce041f gnv-artifacts/src/main/java/de/intevation/gnv/raster/Palette.java --- 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) {