Mercurial > dive4elements > gnv-client
comparison 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 |
comparison
equal
deleted
inserted
replaced
448:3cb2bea50456 | 449:c7ca2fce041f |
---|---|
3 import java.util.Locale; | 3 import java.util.Locale; |
4 | 4 |
5 import java.awt.Color; | 5 import java.awt.Color; |
6 import java.awt.Paint; | 6 import java.awt.Paint; |
7 | 7 |
8 import java.util.HashSet; | |
9 | |
8 import de.intevation.gnv.math.AttributedXYColumns; | 10 import de.intevation.gnv.math.AttributedXYColumns; |
9 | 11 |
10 import de.intevation.gnv.jfreechart.PolygonDataset; | 12 import de.intevation.gnv.jfreechart.PolygonDataset; |
11 import de.intevation.gnv.jfreechart.PolygonPlot; | 13 import de.intevation.gnv.jfreechart.PolygonPlot; |
14 import de.intevation.gnv.jfreechart.PolygonSeries; | |
12 import de.intevation.gnv.jfreechart.PolygonRenderer; | 15 import de.intevation.gnv.jfreechart.PolygonRenderer; |
13 | 16 |
14 import de.intevation.gnv.raster.Palette; | 17 import de.intevation.gnv.raster.Palette; |
15 | 18 |
16 import org.jfree.chart.JFreeChart; | 19 import org.jfree.chart.JFreeChart; |
80 boolean urls = false; | 83 boolean urls = false; |
81 | 84 |
82 PlotOrientation po = PlotOrientation.HORIZONTAL; | 85 PlotOrientation po = PlotOrientation.HORIZONTAL; |
83 PolygonDataset data = columns.getPolygonDataset(); | 86 PolygonDataset data = columns.getPolygonDataset(); |
84 | 87 |
88 HashSet<Integer> usedColors = new HashSet<Integer>(); | |
89 | |
90 for (int i = data.getSeriesCount()-1; i >= 0; --i) { | |
91 PolygonSeries ps = data.getSeries(i); | |
92 Integer fill = (Integer)ps.getAttribute("fill"); | |
93 if (fill != null) { | |
94 usedColors.add(fill); | |
95 } | |
96 } | |
97 | |
85 PolygonRenderer renderer = new PolygonRenderer( | 98 PolygonRenderer renderer = new PolygonRenderer( |
86 new PalettePaintLookup(palette)); | 99 new PalettePaintLookup(palette)); |
87 | 100 |
88 ValueAxis domainAxis = new NumberAxis(xAxis); | 101 ValueAxis domainAxis = new NumberAxis(xAxis); |
89 ValueAxis rangeAxis = new NumberAxis(yAxis); | 102 ValueAxis rangeAxis = new NumberAxis(yAxis); |
93 renderer, | 106 renderer, |
94 domainAxis, | 107 domainAxis, |
95 rangeAxis, | 108 rangeAxis, |
96 null); | 109 null); |
97 | 110 |
111 String [] labels = new String[usedColors.size()]; | |
112 | |
98 int colors = palette.getSize(); | 113 int colors = palette.getSize(); |
99 LookupPaintScale lookupPaint = | 114 LookupPaintScale lookupPaint = |
100 new LookupPaintScale(-0.5d, colors-0.5d, Color.white); | 115 new LookupPaintScale(-0.5d, labels.length-0.5d, Color.white); |
101 | 116 |
102 Color color = null; | 117 Color color = null; |
103 | 118 |
104 String [] labels = new String[colors]; | 119 for (int i = 0, j = labels.length-1; i < colors && j >= 0; i++) { |
105 for (int i = 0; i < colors; i++) { | 120 if (usedColors.contains(i)) { |
106 color = palette.getColor(colors-1-i); | 121 Palette.Entry entry = palette.getEntryByIndex(i); |
107 labels[i] = palette.getEntryByIndex(colors-1-i).getDescription(); | 122 color = entry.getColor(); |
108 lookupPaint.add(i-0.5d, color); | 123 labels[j] = entry.getDescription(); |
124 lookupPaint.add(j-0.5d, color); | |
125 --j; | |
126 } | |
109 } | 127 } |
110 | 128 |
111 JFreeChart chart = new JFreeChart( | 129 JFreeChart chart = new JFreeChart( |
112 title, | 130 title, |
113 JFreeChart.DEFAULT_TITLE_FONT, | 131 JFreeChart.DEFAULT_TITLE_FONT, |
115 legendB); | 133 legendB); |
116 | 134 |
117 chart.removeLegend(); | 135 chart.removeLegend(); |
118 | 136 |
119 SymbolAxis scale = new SymbolAxis("Temperatur", labels); | 137 SymbolAxis scale = new SymbolAxis("Temperatur", labels); |
120 scale.setRange(-1.5d, colors+0.5d); | 138 scale.setRange(-1.5d, labels.length+0.5d); |
121 scale.setGridBandsVisible(false); | 139 scale.setGridBandsVisible(false); |
122 scale.setPlot(plot); | 140 scale.setPlot(plot); |
123 | 141 |
124 PaintScaleLegend legend = new PaintScaleLegend( | 142 PaintScaleLegend legend = new PaintScaleLegend( |
125 lookupPaint, scale); | 143 lookupPaint, scale); |