# HG changeset patch # User Felix Wolfsteller # Date 1322213949 0 # Node ID 5b51f523266100ab204c5166fcbff8dc82773a50 # Parent e4a516ca2e8667de6adc7de46e64d16e7adeadf0 Added handling of empty plots. flys-artifacts/trunk@3316 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r e4a516ca2e86 -r 5b51f5232661 flys-artifacts/ChangeLog --- a/flys-artifacts/ChangeLog Fri Nov 25 08:42:44 2011 +0000 +++ b/flys-artifacts/ChangeLog Fri Nov 25 09:39:09 2011 +0000 @@ -1,3 +1,12 @@ +2011-11-25 Felix Wolfsteller + + Added handling of empty plots. + + * src/main/java/de/intevation/flys/exports/XYChartGenerator.java: + (createAxes, removeEmptyRangeAxes): Survive empty datasets map, create + primary axis. + (recoverEmptyPlot): New. + 2011-11-25 Felix Wolfsteller Let first visible axis be always on the left. diff -r e4a516ca2e86 -r 5b51f5232661 flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java --- a/flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java Fri Nov 25 08:42:44 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java Fri Nov 25 09:39:09 2011 +0000 @@ -175,14 +175,16 @@ adjustPlot(plot); localizeAxes(plot); - removeEmptyRangeAxes(plot); createAxes(plot); adjustAxes(plot); + recoverEmptyPlot(plot); + preparePointRanges(plot); autoZoom(plot); applyThemes(plot); + removeEmptyRangeAxes(plot); return chart; } @@ -207,7 +209,8 @@ /** - * Add given series. + * Add given series if visible, if not visible adjust ranges (such that + * all points in data would be plotted once visible). * @param series the dataseries to include in plot. * @param index index of the series and of its axis. * @param visible whether or not the data should be plotted. @@ -290,22 +293,28 @@ public void createAxes(XYPlot plot) { logger.debug("XYChartGenerator.createAxes"); - Integer last = datasets.lastKey(); - int i = 0; - int firstVisible = 0; - - if (last != null) { - firstVisible = i = last; - for (; i >= 0; --i) { - if (datasets.containsKey(i)) { - plot.setRangeAxis(i, createYAxis(i)); - firstVisible = i; + if (datasets.isEmpty()) { + plot.setRangeAxis(0, createYAxis(0)); + } + else { + Integer last = datasets.lastKey(); + int i = 0; + int firstVisible = 0; + + if (last != null) { + firstVisible = i = last; + for (; i >= 0; --i) { + if (datasets.containsKey(i)) { + plot.setRangeAxis(i, createYAxis(i)); + firstVisible = i; + } } + plot.setRangeAxisLocation(firstVisible, AxisLocation.TOP_OR_LEFT); } - plot.setRangeAxisLocation(firstVisible, AxisLocation.TOP_OR_LEFT); } } + /** * Create Y (range) axis for given index. * Shall be overriden by subclasses. @@ -315,7 +324,24 @@ return axis; } + /** + * If no data is visible, draw at least empty axis. + */ + private void recoverEmptyPlot(XYPlot plot) { + if (plot.getRangeAxis() == null) { + logger.debug("debug: No range axis"); + plot.setRangeAxis(createYAxis(0)); + } + + } + + /** + * Remove Axes which do not have data on them. + */ private void removeEmptyRangeAxes(XYPlot plot) { + if (datasets.isEmpty()) { + return; + } Integer last = datasets.lastKey(); if (last != null) {