Mercurial > dive4elements > gnv-client
comparison gnv-artifacts/src/main/java/de/intevation/gnv/chart/VerticalProfileChart.java @ 656:b98d1adee7a6
Added an offset of five percent between values and chart border in vertical profile charts (issue186).
gnv-artifacts/trunk@749 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Mon, 08 Mar 2010 15:15:08 +0000 |
parents | 24a85678bd39 |
children | 79401c871da4 |
comparison
equal
deleted
inserted
replaced
655:6eccb68a8b99 | 656:b98d1adee7a6 |
---|---|
1 package de.intevation.gnv.chart; | 1 package de.intevation.gnv.chart; |
2 | 2 |
3 import java.util.Collection; | 3 import java.util.Collection; |
4 import java.util.HashMap; | 4 import java.util.HashMap; |
5 import java.util.Map; | |
5 import java.util.Iterator; | 6 import java.util.Iterator; |
6 import java.util.Locale; | 7 import java.util.Locale; |
7 | 8 |
8 import org.apache.log4j.Logger; | 9 import org.apache.log4j.Logger; |
9 | 10 |
10 import org.jfree.chart.ChartTheme; | 11 import org.jfree.chart.ChartTheme; |
11 import org.jfree.chart.axis.Axis; | 12 import org.jfree.chart.axis.Axis; |
13 import org.jfree.chart.axis.NumberAxis; | |
12 import org.jfree.chart.plot.XYPlot; | 14 import org.jfree.chart.plot.XYPlot; |
13 import org.jfree.chart.plot.PlotOrientation; | 15 import org.jfree.chart.plot.PlotOrientation; |
16 import org.jfree.data.Range; | |
17 import org.jfree.data.general.Series; | |
14 import org.jfree.data.xy.XYSeries; | 18 import org.jfree.data.xy.XYSeries; |
15 import org.jfree.data.general.Series; | |
16 import org.jfree.data.xy.XYSeriesCollection; | 19 import org.jfree.data.xy.XYSeriesCollection; |
17 | 20 |
18 import de.intevation.gnv.geobackend.base.Result; | 21 import de.intevation.gnv.geobackend.base.Result; |
19 import de.intevation.gnv.state.describedata.KeyValueDescibeData; | 22 import de.intevation.gnv.state.describedata.KeyValueDescibeData; |
20 | 23 |
30 private static Logger log = Logger.getLogger(VerticalProfileChart.class); | 33 private static Logger log = Logger.getLogger(VerticalProfileChart.class); |
31 | 34 |
32 protected final double PERCENTAGE = 5.0; | 35 protected final double PERCENTAGE = 5.0; |
33 protected final double GAP_MAX_LEVEL = Math.sqrt(2.0); | 36 protected final double GAP_MAX_LEVEL = Math.sqrt(2.0); |
34 protected final int GAP_MAX_VALUES = 60; | 37 protected final int GAP_MAX_VALUES = 60; |
38 | |
39 /** Map to store max ranges of each parameter (axis.setAutoRange(true) | |
40 * doesn't seem to work properly. */ | |
41 protected Map values; | |
35 | 42 |
36 | 43 |
37 public VerticalProfileChart( | 44 public VerticalProfileChart( |
38 ChartLabels labels, | 45 ChartLabels labels, |
39 ChartTheme theme, | 46 ChartTheme theme, |
57 this.PLOT_ORIENTATION = PlotOrientation.HORIZONTAL; | 64 this.PLOT_ORIENTATION = PlotOrientation.HORIZONTAL; |
58 this.linesVisible = linesVisible; | 65 this.linesVisible = linesVisible; |
59 this.shapesVisible = shapesVisible; | 66 this.shapesVisible = shapesVisible; |
60 this.datasets = new HashMap(); | 67 this.datasets = new HashMap(); |
61 this.ranges = new HashMap(); | 68 this.ranges = new HashMap(); |
69 this.values = new HashMap(); | |
62 } | 70 } |
63 | 71 |
64 | 72 |
65 protected void initData() { | 73 protected void initData() { |
66 log.debug("init data for VerticalProfileChart"); | 74 log.debug("init data for VerticalProfileChart"); |
116 log.debug("next dataset is '" + seriesName + "'"); | 124 log.debug("next dataset is '" + seriesName + "'"); |
117 series = new XYSeries(seriesName); | 125 series = new XYSeries(seriesName); |
118 } | 126 } |
119 | 127 |
120 addValue(row, series); | 128 addValue(row, series); |
121 Double value = row.getDouble("YORDINATE"); | 129 Object x = getValue(row); |
122 if (value != null) | 130 Double y = row.getDouble("YORDINATE"); |
123 storeMaxRange(value, parameter); | 131 if (x != null && y != null) { |
132 storeMaxRange(ranges, y, parameter); | |
133 storeMaxValue(values, x, parameter); | |
134 } | |
124 endPos++; | 135 endPos++; |
125 } | 136 } |
126 | 137 |
127 if (results.length == 0) | 138 if (results.length == 0) |
128 return; | 139 return; |
129 | 140 |
130 gapDetection(results, series, startPos, endPos); | 141 gapDetection(results, series, startPos, endPos); |
131 addSeries(series, parameter, idx); | 142 addSeries(series, parameter, idx); |
132 | 143 |
133 addDatasets(); | 144 addDatasets(); |
145 } | |
146 | |
147 | |
148 protected Object getValue(Result row) { | |
149 return row.getDouble("XORDINATE"); | |
134 } | 150 } |
135 | 151 |
136 | 152 |
137 protected void gapDetection( | 153 protected void gapDetection( |
138 Result[] results, | 154 Result[] results, |
147 else | 163 else |
148 addGaps(results, series, startValue, endValue, startPos, endPos); | 164 addGaps(results, series, startValue, endValue, startPos, endPos); |
149 } | 165 } |
150 | 166 |
151 | 167 |
168 protected void prepareRangeAxis(String seriesKey, int idx) { | |
169 XYPlot plot = chart.getXYPlot(); | |
170 NumberAxis xAxis = (NumberAxis) plot.getDomainAxis(); | |
171 | |
172 Range xRange = (Range) values.get(seriesKey); | |
173 xAxis.setRange(Range.expand(xRange, LOWER_MARGIN, UPPER_MARGIN)); | |
174 log.debug("Max X-Range of dataset is: " + xRange.toString()); | |
175 } | |
176 | |
177 | |
152 protected void addValue(Result row, Series series) { | 178 protected void addValue(Result row, Series series) { |
153 ((XYSeries) series).add( | 179 ((XYSeries) series).add( |
154 row.getDouble("XORDINATE"), | 180 row.getDouble("XORDINATE"), |
155 row.getDouble("YORDINATE") | 181 row.getDouble("YORDINATE") |
156 ); | 182 ); |
192 if (datasets.containsKey(key)) { | 218 if (datasets.containsKey(key)) { |
193 xysc = (XYSeriesCollection)datasets.get(key); | 219 xysc = (XYSeriesCollection)datasets.get(key); |
194 plot.setDataset(idx, xysc ); | 220 plot.setDataset(idx, xysc ); |
195 log.debug("Added " + key + " parameter to plot."); | 221 log.debug("Added " + key + " parameter to plot."); |
196 prepareAxis(key, idx); | 222 prepareAxis(key, idx); |
223 prepareRangeAxis(key, idx); | |
197 adjustRenderer( | 224 adjustRenderer( |
198 idx++, | 225 idx++, |
199 xysc.getSeriesCount(), | 226 xysc.getSeriesCount(), |
200 linesVisible, | 227 linesVisible, |
201 shapesVisible | 228 shapesVisible |
202 ); | 229 ); |
203 } | 230 } |
204 } | 231 } |
232 } | |
233 | |
234 | |
235 protected void storeMaxValue(Map values, Object val, String parameter) { | |
236 double value = ((Double) val).doubleValue(); | |
237 Range range = null; | |
238 | |
239 range = values.containsKey(parameter) | |
240 ? (Range) values.get(parameter) | |
241 : new Range(value, value); | |
242 | |
243 double lower = range.getLowerBound(); | |
244 double upper = range.getUpperBound(); | |
245 | |
246 lower = value < lower ? value : lower; | |
247 upper = value > upper ? value : upper; | |
248 | |
249 values.put(parameter, new Range(lower, upper)); | |
205 } | 250 } |
206 | 251 |
207 | 252 |
208 protected void localizeDomainAxis(Axis axis, Locale locale) { | 253 protected void localizeDomainAxis(Axis axis, Locale locale) { |
209 // call localizeRangeAxis from superclass which formats NumberAxis | 254 // call localizeRangeAxis from superclass which formats NumberAxis |