comparison flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java @ 3249:f76cef888ee1

Fix issue710 - crashing one-point-diagrams. flys-artifacts/trunk@4882 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Fri, 06 Jul 2012 09:57:16 +0000
parents 1dca41dba135
children 2aca387333d6
comparison
equal deleted inserted replaced
3248:4eb91fb1e73e 3249:f76cef888ee1
7 import java.util.HashMap; 7 import java.util.HashMap;
8 import java.util.List; 8 import java.util.List;
9 import java.util.Map; 9 import java.util.Map;
10 10
11 import org.apache.log4j.Logger; 11 import org.apache.log4j.Logger;
12 import org.json.JSONArray;
13 import org.json.JSONException;
14
12 import org.jfree.chart.ChartFactory; 15 import org.jfree.chart.ChartFactory;
13 import org.jfree.chart.JFreeChart; 16 import org.jfree.chart.JFreeChart;
14 import org.jfree.chart.LegendItem; 17 import org.jfree.chart.LegendItem;
15 import org.jfree.chart.annotations.XYTextAnnotation; 18 import org.jfree.chart.annotations.XYTextAnnotation;
16 import org.jfree.chart.axis.NumberAxis; 19 import org.jfree.chart.axis.NumberAxis;
221 224
222 localizeAxes(plot); 225 localizeAxes(plot);
223 adjustAxes(plot); 226 adjustAxes(plot);
224 autoZoom(plot); 227 autoZoom(plot);
225 228
229 //debugAxis(plot);
230
226 // These have to go after the autozoom. 231 // These have to go after the autozoom.
227 addAnnotationsToRenderer(plot); 232 addAnnotationsToRenderer(plot);
228 233
229 aggregateLegendEntries(plot); 234 aggregateLegendEntries(plot);
230 235
282 logger.debug("Range-Axis " + i + " != null [" + 287 logger.debug("Range-Axis " + i + " != null [" +
283 plot.getRangeAxis(i).getRange().getLowerBound() + 288 plot.getRangeAxis(i).getRange().getLowerBound() +
284 " " + plot.getRangeAxis(i).getRange().getUpperBound() + 289 " " + plot.getRangeAxis(i).getRange().getUpperBound() +
285 "]"); 290 "]");
286 } 291 }
287 292 }
293 for (int i = 0, P = plot.getDomainAxisCount(); i < P; i++) {
294 if (plot.getDomainAxis(i) == null)
295 logger.debug("Domain-Axis #" + i + " == null");
296 else {
297 logger.debug("Domain-Axis " + i + " != null [" +
298 plot.getDomainAxis(i).getRange().getLowerBound() +
299 " " + plot.getDomainAxis(i).getRange().getUpperBound() +
300 "]");
301 }
288 } 302 }
289 logger.debug("..............."); 303 logger.debug("...............");
290 } 304 }
291 305
292 306
445 /** 459 /**
446 * Expands X axes if only a point is shown. 460 * Expands X axes if only a point is shown.
447 */ 461 */
448 private void preparePointRanges(XYPlot plot) { 462 private void preparePointRanges(XYPlot plot) {
449 for (int i = 0, num = plot.getDomainAxisCount(); i < num; i++) { 463 for (int i = 0, num = plot.getDomainAxisCount(); i < num; i++) {
450 logger.debug("Check whether to expand a x axis.");
451 464
452 Integer key = Integer.valueOf(i); 465 Integer key = Integer.valueOf(i);
453 Bounds b = getXBounds(key); 466 Bounds b = getXBounds(key);
454 467 logger.debug("Check whether to expand a x axis.i ("+b.getLower() + "-" + b.getUpper()+")");
455 if (b != null && b.getLower() == b.getUpper()) { 468
456 double lo = (Double) b.getLower(); 469 if (b != null && b.getLower().equals(b.getUpper())) {
457 double hi = (Double) b.getUpper(); 470 setXBounds(key, ChartHelper.expandBounds(b, 5));
458 double add = (hi - lo) / 100 * 5;
459
460 setXBounds(key, new DoubleBounds(lo-add, hi+add));
461 } 471 }
462 } 472 }
463 } 473 }
464 474
465 475
674 684
675 685
676 /** Set X (usually horizontal) extent for given axis. */ 686 /** Set X (usually horizontal) extent for given axis. */
677 @Override 687 @Override
678 protected void setXBounds(int axis, Bounds bounds) { 688 protected void setXBounds(int axis, Bounds bounds) {
679 xBounds.put(axis, bounds); 689 if (bounds.getLower() == bounds.getUpper()) {
690 xBounds.put(axis, ChartHelper.expandBounds(bounds, 5d));
691 }
692 else {
693 xBounds.put(axis, bounds);
694 }
680 } 695 }
681 696
682 697
683 /** Get Y (usually vertical) extent for given axis. */ 698 /** Get Y (usually vertical) extent for given axis. */
684 @Override 699 @Override

http://dive4elements.wald.intevation.org