Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java @ 1935:5b51f5232661
Added handling of empty plots.
flys-artifacts/trunk@3316 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Fri, 25 Nov 2011 09:39:09 +0000 |
parents | e4a516ca2e86 |
children | 0d12e70766c8 |
comparison
equal
deleted
inserted
replaced
1934:e4a516ca2e86 | 1935:5b51f5232661 |
---|---|
173 addAnnotations(plot); | 173 addAnnotations(plot); |
174 addSubtitles(chart); | 174 addSubtitles(chart); |
175 adjustPlot(plot); | 175 adjustPlot(plot); |
176 localizeAxes(plot); | 176 localizeAxes(plot); |
177 | 177 |
178 removeEmptyRangeAxes(plot); | |
179 createAxes(plot); | 178 createAxes(plot); |
180 adjustAxes(plot); | 179 adjustAxes(plot); |
181 | 180 |
181 recoverEmptyPlot(plot); | |
182 | |
182 preparePointRanges(plot); | 183 preparePointRanges(plot); |
183 autoZoom(plot); | 184 autoZoom(plot); |
184 | 185 |
185 applyThemes(plot); | 186 applyThemes(plot); |
187 removeEmptyRangeAxes(plot); | |
186 | 188 |
187 return chart; | 189 return chart; |
188 } | 190 } |
189 | 191 |
190 | 192 |
205 } | 207 } |
206 } | 208 } |
207 | 209 |
208 | 210 |
209 /** | 211 /** |
210 * Add given series. | 212 * Add given series if visible, if not visible adjust ranges (such that |
213 * all points in data would be plotted once visible). | |
211 * @param series the dataseries to include in plot. | 214 * @param series the dataseries to include in plot. |
212 * @param index index of the series and of its axis. | 215 * @param index index of the series and of its axis. |
213 * @param visible whether or not the data should be plotted. | 216 * @param visible whether or not the data should be plotted. |
214 */ | 217 */ |
215 public void addAxisSeries(XYSeries series, int index, boolean visible) { | 218 public void addAxisSeries(XYSeries series, int index, boolean visible) { |
288 * Create y-axes, ensure that the first axis (with data) is on the left. | 291 * Create y-axes, ensure that the first axis (with data) is on the left. |
289 */ | 292 */ |
290 public void createAxes(XYPlot plot) { | 293 public void createAxes(XYPlot plot) { |
291 logger.debug("XYChartGenerator.createAxes"); | 294 logger.debug("XYChartGenerator.createAxes"); |
292 | 295 |
293 Integer last = datasets.lastKey(); | 296 if (datasets.isEmpty()) { |
294 int i = 0; | 297 plot.setRangeAxis(0, createYAxis(0)); |
295 int firstVisible = 0; | 298 } |
296 | 299 else { |
297 if (last != null) { | 300 Integer last = datasets.lastKey(); |
298 firstVisible = i = last; | 301 int i = 0; |
299 for (; i >= 0; --i) { | 302 int firstVisible = 0; |
300 if (datasets.containsKey(i)) { | 303 |
301 plot.setRangeAxis(i, createYAxis(i)); | 304 if (last != null) { |
302 firstVisible = i; | 305 firstVisible = i = last; |
306 for (; i >= 0; --i) { | |
307 if (datasets.containsKey(i)) { | |
308 plot.setRangeAxis(i, createYAxis(i)); | |
309 firstVisible = i; | |
310 } | |
303 } | 311 } |
304 } | 312 plot.setRangeAxisLocation(firstVisible, AxisLocation.TOP_OR_LEFT); |
305 plot.setRangeAxisLocation(firstVisible, AxisLocation.TOP_OR_LEFT); | 313 } |
306 } | 314 } |
307 } | 315 } |
316 | |
308 | 317 |
309 /** | 318 /** |
310 * Create Y (range) axis for given index. | 319 * Create Y (range) axis for given index. |
311 * Shall be overriden by subclasses. | 320 * Shall be overriden by subclasses. |
312 */ | 321 */ |
313 protected NumberAxis createYAxis(int index) { | 322 protected NumberAxis createYAxis(int index) { |
314 NumberAxis axis = new NumberAxis("default axis"); | 323 NumberAxis axis = new NumberAxis("default axis"); |
315 return axis; | 324 return axis; |
316 } | 325 } |
317 | 326 |
327 /** | |
328 * If no data is visible, draw at least empty axis. | |
329 */ | |
330 private void recoverEmptyPlot(XYPlot plot) { | |
331 if (plot.getRangeAxis() == null) { | |
332 logger.debug("debug: No range axis"); | |
333 plot.setRangeAxis(createYAxis(0)); | |
334 } | |
335 | |
336 } | |
337 | |
338 /** | |
339 * Remove Axes which do not have data on them. | |
340 */ | |
318 private void removeEmptyRangeAxes(XYPlot plot) { | 341 private void removeEmptyRangeAxes(XYPlot plot) { |
342 if (datasets.isEmpty()) { | |
343 return; | |
344 } | |
319 Integer last = datasets.lastKey(); | 345 Integer last = datasets.lastKey(); |
320 | 346 |
321 if (last != null) { | 347 if (last != null) { |
322 for (int i = last-1; i >= 0; --i) { | 348 for (int i = last-1; i >= 0; --i) { |
323 if (!datasets.containsKey(i)) { | 349 if (!datasets.containsKey(i)) { |