# HG changeset patch # User Felix Wolfsteller # Date 1341568636 0 # Node ID f76cef888ee1b14327263e1b8bd19f7c02458684 # Parent 4eb91fb1e73e65b5bf4632bcf7fe7be511b8a2eb Fix issue710 - crashing one-point-diagrams. flys-artifacts/trunk@4882 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 4eb91fb1e73e -r f76cef888ee1 flys-artifacts/ChangeLog --- a/flys-artifacts/ChangeLog Fri Jul 06 09:37:24 2012 +0000 +++ b/flys-artifacts/ChangeLog Fri Jul 06 09:57:16 2012 +0000 @@ -1,3 +1,10 @@ +2012-07-07 Felix Wolfsteller + + Fix issue710 (crashing diagrams with only one point). + + * src/main/java/de/intevation/flys/exports/XYChartGenerator.java: + Expand the range/bounds where its added. + 2012-07-07 Felix Wolfsteller * src/main/java/de/intevation/flys/exports/ChartGenerator.java diff -r 4eb91fb1e73e -r f76cef888ee1 flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java --- a/flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java Fri Jul 06 09:37:24 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java Fri Jul 06 09:57:16 2012 +0000 @@ -9,6 +9,9 @@ import java.util.Map; import org.apache.log4j.Logger; +import org.json.JSONArray; +import org.json.JSONException; + import org.jfree.chart.ChartFactory; import org.jfree.chart.JFreeChart; import org.jfree.chart.LegendItem; @@ -223,6 +226,8 @@ adjustAxes(plot); autoZoom(plot); + //debugAxis(plot); + // These have to go after the autozoom. addAnnotationsToRenderer(plot); @@ -284,7 +289,16 @@ " " + plot.getRangeAxis(i).getRange().getUpperBound() + "]"); } - + } + for (int i = 0, P = plot.getDomainAxisCount(); i < P; i++) { + if (plot.getDomainAxis(i) == null) + logger.debug("Domain-Axis #" + i + " == null"); + else { + logger.debug("Domain-Axis " + i + " != null [" + + plot.getDomainAxis(i).getRange().getLowerBound() + + " " + plot.getDomainAxis(i).getRange().getUpperBound() + + "]"); + } } logger.debug("..............."); } @@ -447,17 +461,13 @@ */ private void preparePointRanges(XYPlot plot) { for (int i = 0, num = plot.getDomainAxisCount(); i < num; i++) { - logger.debug("Check whether to expand a x axis."); Integer key = Integer.valueOf(i); Bounds b = getXBounds(key); + logger.debug("Check whether to expand a x axis.i ("+b.getLower() + "-" + b.getUpper()+")"); - if (b != null && b.getLower() == b.getUpper()) { - double lo = (Double) b.getLower(); - double hi = (Double) b.getUpper(); - double add = (hi - lo) / 100 * 5; - - setXBounds(key, new DoubleBounds(lo-add, hi+add)); + if (b != null && b.getLower().equals(b.getUpper())) { + setXBounds(key, ChartHelper.expandBounds(b, 5)); } } } @@ -676,7 +686,12 @@ /** Set X (usually horizontal) extent for given axis. */ @Override protected void setXBounds(int axis, Bounds bounds) { - xBounds.put(axis, bounds); + if (bounds.getLower() == bounds.getUpper()) { + xBounds.put(axis, ChartHelper.expandBounds(bounds, 5d)); + } + else { + xBounds.put(axis, bounds); + } }