comparison flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java @ 1686:e8d1e531687a

Bugfix: #114 Enabled rendering charts with a single data point. flys-artifacts/trunk@2904 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Fri, 07 Oct 2011 13:15:48 +0000
parents 022f62c75878
children 19c4cf5163e8
comparison
equal deleted inserted replaced
1685:022f62c75878 1686:e8d1e531687a
133 adjustAxes(plot); 133 adjustAxes(plot);
134 localizeAxes(plot); 134 localizeAxes(plot);
135 135
136 removeEmptyRangeAxes(plot); 136 removeEmptyRangeAxes(plot);
137 137
138 preparePointRanges(plot);
138 autoZoom(plot); 139 autoZoom(plot);
139 140
140 applyThemes(plot); 141 applyThemes(plot);
141 142
142 return chart; 143 return chart;
256 } 257 }
257 258
258 if (second == null) { 259 if (second == null) {
259 plot.setRangeAxis(1, null); 260 plot.setRangeAxis(1, null);
260 } 261 }
262 }
263
264
265 private void preparePointRanges(XYPlot plot) {
266 for (int i = 0, num = plot.getDomainAxisCount(); i < num; i++) {
267 Integer key = new Integer(i);
268
269 Range r = xRanges.get(key);
270 if (r.getLowerBound() == r.getUpperBound()) {
271 xRanges.put(key, expandRange(r, 5));
272 }
273 }
274
275 for (int i = 0, num = plot.getRangeAxisCount(); i < num; i++) {
276 Integer key = new Integer(i);
277
278 Range r = yRanges.get(key);
279 if (r.getLowerBound() == r.getUpperBound()) {
280 yRanges.put(key, expandRange(r, 5));
281 }
282 }
283 }
284
285
286 public static Range expandRange(Range range, double percent) {
287 if (range == null) {
288 return null;
289 }
290
291 double value = range.getLowerBound();
292 double expand = value / 100 * percent;
293
294 return expand != 0
295 ? new Range(value-expand, value+expand)
296 : new Range(-0.01 * percent, 0.01 * percent);
261 } 297 }
262 298
263 299
264 /** 300 /**
265 * This method zooms the plot to the specified ranges in the attribute 301 * This method zooms the plot to the specified ranges in the attribute
274 logger.debug("Zoom to specified ranges."); 310 logger.debug("Zoom to specified ranges.");
275 311
276 Range xrange = getDomainAxisRange(); 312 Range xrange = getDomainAxisRange();
277 Range yrange = getValueAxisRange(); 313 Range yrange = getValueAxisRange();
278 314
279 logger.debug("XXX: CLIENT X RANGE = " + xrange);
280 logger.debug("XXX: CLIENT Y RANGE = " + yrange);
281
282 for (int i = 0, num = plot.getRangeAxisCount(); i < num; i++) { 315 for (int i = 0, num = plot.getRangeAxisCount(); i < num; i++) {
283 Range[] ranges = new Range[] { 316 Range[] ranges = new Range[] {
284 xRanges.get(0), 317 xRanges.get(0),
285 yRanges.get(new Integer(i)) }; 318 yRanges.get(new Integer(i)) };
286 319
293 326
294 if (yaxis == null) { 327 if (yaxis == null) {
295 continue; 328 continue;
296 } 329 }
297 330
298 logger.debug("XXX Zoom y axis for index: " + i);
299 logger.debug("XXX Y MAX RANGE = " + ranges[1]);
300 zoomY(plot, yaxis, ranges[1], yrange); 331 zoomY(plot, yaxis, ranges[1], yrange);
301 } 332 }
302 } 333 }
303 334
304 335
524 555
525 if (series instanceof StyledXYSeries) { 556 if (series instanceof StyledXYSeries) {
526 ((StyledXYSeries) series).applyTheme(r, s); 557 ((StyledXYSeries) series).applyTheme(r, s);
527 } 558 }
528 559
560 // special case: if there is just one single item, we need to enable
561 // points for this series, otherwise we would not see anything in
562 // the chart area.
563 if (series.getItemCount() == 1) {
564 r.setSeriesShapesVisible(s, true);
565 }
566
529 lic.add(r.getLegendItem(i, s)); 567 lic.add(r.getLegendItem(i, s));
530 } 568 }
531 569
532 if (anno != null) { 570 if (anno != null) {
533 lic.addAll(anno); 571 lic.addAll(anno);

http://dive4elements.wald.intevation.org