# HG changeset patch # User Ingo Weinzierl # Date 1271839583 0 # Node ID 8b6ef091d38cc6406ab9aee1b6c38d6bde98c2c5 # Parent 797a6264b89b67cadc58d20ea5998608129ff100 It is possible to draw VerticalProfileCharts with just one single data point (issue229). gnv-artifacts/trunk@962 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 797a6264b89b -r 8b6ef091d38c gnv-artifacts/ChangeLog --- a/gnv-artifacts/ChangeLog Tue Apr 20 18:38:22 2010 +0000 +++ b/gnv-artifacts/ChangeLog Wed Apr 21 08:46:23 2010 +0000 @@ -1,3 +1,18 @@ +2010-04-21 Ingo Weinzierl + + Issue229 + JFreeChart needs at least a lower and a different upper bounds to + calculate the range of the domain axis automatically. + + * src/main/java/de/intevation/gnv/chart/VerticalProfileChart.java: Override + method that adjusts the range of domain and range axes. + + * src/main/java/de/intevation/gnv/chart/HorizontalProfileChart.java: + Override method that adjusts the range of domain and range axes. If there + are more changes to be done in the future, caused by inheritance from + VerticalProfileChart, we should stop that and derive this class from + AbstractXYLineChart! + 2010-04-20 Tim Englich * src/main/java/de/intevation/gnv/artifacts/cache/CacheFactory.java (initializeCache): diff -r 797a6264b89b -r 8b6ef091d38c gnv-artifacts/src/main/java/de/intevation/gnv/chart/HorizontalProfileChart.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/chart/HorizontalProfileChart.java Tue Apr 20 18:38:22 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/chart/HorizontalProfileChart.java Wed Apr 21 08:46:23 2010 +0000 @@ -17,7 +17,15 @@ import org.jfree.chart.ChartTheme; +import org.jfree.chart.axis.Axis; +import org.jfree.chart.axis.AxisLocation; +import org.jfree.chart.axis.NumberAxis; +import org.jfree.chart.axis.NumberTickUnit; + import org.jfree.chart.plot.PlotOrientation; +import org.jfree.chart.plot.XYPlot; + +import org.jfree.data.Range; import org.jfree.data.general.Series; @@ -173,6 +181,45 @@ @Override + protected void prepareAxis(String seriesKey,int idx) { + log.debug("prepare axis of xychart"); + + XYPlot plot = chart.getXYPlot(); + Axis xAxis = plot.getDomainAxis(); + NumberAxis yAxis = new NumberAxis(seriesKey); + + localizeDomainAxis(xAxis, locale); + localizeRangeAxis(yAxis, locale); + + // litte workarround to adjust the max range of axes. + // NumberAxis.setAutoRange(true) doesn't seem to work properly. + Range yRange = (Range) ranges.get(seriesKey); + yAxis.setRange(Range.expand(yRange, LOWER_MARGIN, UPPER_MARGIN)); + log.debug("Max Range of dataset is: " + yRange.toString()); + + if (seriesKey.contains("richtung")) { + yAxis.setTickUnit(new NumberTickUnit(30.0)); + yAxis.setUpperBound(360.0); + yAxis.setLowerBound(0.0); + } + else { + yAxis.setFixedDimension(10.0); + yAxis.setAutoRangeIncludesZero(false); + } + + plot.setRangeAxis(idx, yAxis); + yAxis.configure(); + + if (idx % 2 != 0) + plot.setRangeAxisLocation(idx, AxisLocation.BOTTOM_OR_RIGHT); + else + plot.setRangeAxisLocation(idx, AxisLocation.BOTTOM_OR_LEFT); + + plot.mapDatasetToRangeAxis(idx, idx); + } + + + @Override protected void prepareRangeAxis(String seriesKey, int idx) { return; // do nothing here diff -r 797a6264b89b -r 8b6ef091d38c gnv-artifacts/src/main/java/de/intevation/gnv/chart/VerticalProfileChart.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/chart/VerticalProfileChart.java Tue Apr 20 18:38:22 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/chart/VerticalProfileChart.java Wed Apr 21 08:46:23 2010 +0000 @@ -239,6 +239,39 @@ addGaps(results, series, startValue, endValue, startPos, endPos); } + @Override + protected void prepareAxis(String seriesKey, int idx) { + super.prepareAxis(seriesKey, idx); + + XYPlot plot = chart.getXYPlot(); + NumberAxis domainAxis = (NumberAxis) plot.getRangeAxis(); + NumberAxis rangeAxis = (NumberAxis) plot.getDomainAxis(); + + Range domainRange = domainAxis.getRange(); + Range rangeRange = rangeAxis.getRange(); + log.debug("Domain axis range before: " + domainRange.toString()); + log.debug("Range axis range before: " + rangeRange.toString()); + + domainRange = Range.expand(domainRange, LOWER_MARGIN, UPPER_MARGIN); + rangeRange = Range.expand(rangeRange, LOWER_MARGIN, UPPER_MARGIN); + + double lower = domainRange.getLowerBound(); + double upper = domainRange.getUpperBound(); + + if (lower == upper) { + domainRange = new Range( + lower - (lower * 0.05d), + upper + (upper * 0.05d)); + } + + log.debug("Domain axis range after: " + domainRange.toString()); + log.debug("Range axis range after: " + rangeRange.toString()); + domainAxis.setRange(domainRange); + rangeAxis.setRange(rangeRange); + + plot.setRangeAxis(domainAxis); + } + /** * Method to expand max range of a range axis identified by seriesKey. @@ -318,7 +351,6 @@ plot.setDataset(idx, xysc ); log.debug("Added " + key + " parameter to plot."); prepareAxis(key, idx); - prepareRangeAxis(key, idx); adjustRenderer( idx++, xysc.getSeriesCount(),