Mercurial > dive4elements > gnv-client
comparison gnv-artifacts/src/main/java/de/intevation/gnv/chart/VerticalCrossSectionChart.java @ 446:f5a041000357
Connected vertical cross section with chart generation.
gnv-artifacts/trunk@494 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Fri, 01 Jan 2010 12:08:05 +0000 |
parents | |
children | c7ca2fce041f |
comparison
equal
deleted
inserted
replaced
445:f42ed4f10b79 | 446:f5a041000357 |
---|---|
1 package de.intevation.gnv.chart; | |
2 | |
3 import java.util.Locale; | |
4 | |
5 import java.awt.Color; | |
6 import java.awt.Paint; | |
7 | |
8 import de.intevation.gnv.math.AttributedXYColumns; | |
9 | |
10 import de.intevation.gnv.jfreechart.PolygonDataset; | |
11 import de.intevation.gnv.jfreechart.PolygonPlot; | |
12 import de.intevation.gnv.jfreechart.PolygonRenderer; | |
13 | |
14 import de.intevation.gnv.raster.Palette; | |
15 | |
16 import org.jfree.chart.JFreeChart; | |
17 | |
18 import org.jfree.chart.plot.PlotOrientation; | |
19 | |
20 import org.jfree.chart.axis.ValueAxis; | |
21 import org.jfree.chart.axis.NumberAxis; | |
22 import org.jfree.chart.axis.SymbolAxis; | |
23 | |
24 import org.jfree.chart.title.PaintScaleLegend; | |
25 | |
26 import org.jfree.chart.renderer.LookupPaintScale; | |
27 | |
28 import org.jfree.ui.RectangleEdge; | |
29 import org.jfree.ui.RectangleInsets; | |
30 | |
31 /** | |
32 * @author Ingo Weinzierl (ingo.weinzierl@intevation.de) | |
33 * @author Sascha L. Teichmann (sascha.teichmann@intevation.de) | |
34 */ | |
35 public class VerticalCrossSectionChart | |
36 implements Chart | |
37 { | |
38 public static final class PalettePaintLookup | |
39 implements PolygonRenderer.PaintLookup | |
40 { | |
41 private Palette palette; | |
42 | |
43 public PalettePaintLookup(Palette palette) { | |
44 this.palette = palette; | |
45 } | |
46 | |
47 public Paint getPaint(int index) { | |
48 return index < 0 | |
49 ? Color.black | |
50 : palette.getColor(index); | |
51 } | |
52 } // class PalettePaintLookup | |
53 | |
54 protected JFreeChart chart; | |
55 | |
56 protected AttributedXYColumns columns; | |
57 protected Palette palette; | |
58 protected Locale locale; | |
59 | |
60 public VerticalCrossSectionChart() { | |
61 } | |
62 | |
63 public VerticalCrossSectionChart( | |
64 AttributedXYColumns columns, | |
65 Palette palette, | |
66 Locale locale | |
67 ) { | |
68 this.columns = columns; | |
69 this.palette = palette; | |
70 this.locale = locale; | |
71 } | |
72 | |
73 protected JFreeChart createChart() { | |
74 | |
75 String title = "Neues 2D-Diagramm"; | |
76 String xAxis = "x-Achse des Diagramms"; | |
77 String yAxis = "y-Achse des Diagramms"; | |
78 boolean legendB = false; | |
79 boolean tooltips = false; | |
80 boolean urls = false; | |
81 | |
82 PlotOrientation po = PlotOrientation.HORIZONTAL; | |
83 PolygonDataset data = columns.getPolygonDataset(); | |
84 | |
85 PolygonRenderer renderer = new PolygonRenderer( | |
86 new PalettePaintLookup(palette)); | |
87 | |
88 ValueAxis domainAxis = new NumberAxis(xAxis); | |
89 ValueAxis rangeAxis = new NumberAxis(yAxis); | |
90 | |
91 PolygonPlot plot = new PolygonPlot( | |
92 data, | |
93 renderer, | |
94 domainAxis, | |
95 rangeAxis, | |
96 null); | |
97 | |
98 int colors = palette.getSize(); | |
99 LookupPaintScale lookupPaint = | |
100 new LookupPaintScale(-0.5d, colors-0.5d, Color.white); | |
101 | |
102 Color color = null; | |
103 | |
104 String [] labels = new String[colors]; | |
105 for (int i = 0; i < colors; i++) { | |
106 color = palette.getColor(colors-1-i); | |
107 labels[i] = palette.getEntryByIndex(colors-1-i).getDescription(); | |
108 lookupPaint.add(i-0.5d, color); | |
109 } | |
110 | |
111 JFreeChart chart = new JFreeChart( | |
112 title, | |
113 JFreeChart.DEFAULT_TITLE_FONT, | |
114 plot, | |
115 legendB); | |
116 | |
117 chart.removeLegend(); | |
118 | |
119 SymbolAxis scale = new SymbolAxis("Temperatur", labels); | |
120 scale.setRange(-1.5d, colors+0.5d); | |
121 scale.setGridBandsVisible(false); | |
122 scale.setPlot(plot); | |
123 | |
124 PaintScaleLegend legend = new PaintScaleLegend( | |
125 lookupPaint, scale); | |
126 legend.setMargin(new RectangleInsets(3d, 10d, 3d, 10d)); | |
127 legend.setPosition(RectangleEdge.LEFT); | |
128 legend.setAxisOffset(5d); | |
129 | |
130 chart.addSubtitle(legend); | |
131 | |
132 return chart; | |
133 } | |
134 | |
135 public JFreeChart generateChart() { | |
136 if (chart == null) { | |
137 chart = createChart(); | |
138 } | |
139 return chart; | |
140 } | |
141 } | |
142 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |