Mercurial > dive4elements > gnv-client
changeset 656:b98d1adee7a6
Added an offset of five percent between values and chart border in vertical profile charts (issue186).
gnv-artifacts/trunk@749 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Mon, 08 Mar 2010 15:15:08 +0000 |
parents | 6eccb68a8b99 |
children | af3f56758f59 199982e8866e |
files | gnv-artifacts/ChangeLog gnv-artifacts/src/main/java/de/intevation/gnv/chart/AbstractXYLineChart.java gnv-artifacts/src/main/java/de/intevation/gnv/chart/HorizontalProfileChart.java gnv-artifacts/src/main/java/de/intevation/gnv/chart/TimeSeriesChart.java gnv-artifacts/src/main/java/de/intevation/gnv/chart/VerticalProfileChart.java |
diffstat | 5 files changed, 99 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/gnv-artifacts/ChangeLog Mon Mar 08 14:04:28 2010 +0000 +++ b/gnv-artifacts/ChangeLog Mon Mar 08 15:15:08 2010 +0000 @@ -1,3 +1,23 @@ +2010-03-08 Ingo Weinzierl <ingo.weinzierl@intevation.de> + + Issue186 + + * src/main/java/de/intevation/gnv/chart/AbstractXYLineChart.java: Adjusted + signature of method to store min/max ranges in x and y direction in + charts. + + * src/main/java/de/intevation/gnv/chart/TimeSeriesChart.java: Adjusted + method call to signature which has been changed in AbstractXYLineChart. + + * src/main/java/de/intevation/gnv/chart/HorizontalProfileChart.java: Added + some empty methods which overrides methods from parent which should not be + called on this class. + + * src/main/java/de/intevation/gnv/chart/VerticalProfileChart.java: Added + methods to store vertical min/max ranges in charts. After adding a new + series to this chart, we call prepareRangeAxis() to add an offset (5 + percent) between values and chart border. + 2010-03-08 Tim Englich <tim.englich@intevation.de> * doc/conf/maptemplates/layer*.vm:
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/chart/AbstractXYLineChart.java Mon Mar 08 14:04:28 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/chart/AbstractXYLineChart.java Mon Mar 08 15:15:08 2010 +0000 @@ -112,7 +112,7 @@ // litte workarround to adjust the max range of axes. // NumberAxis.setAutoRange(true) doesn't seem to work properly. - Range yRange = (Range) ranges.get(seriesKey); + Range yRange = (Range) ranges.get(seriesKey); yAxis.setRange(Range.expand(yRange, LOWER_MARGIN, UPPER_MARGIN)); log.debug("Max Range of dataset is: " + yRange.toString()); @@ -256,7 +256,7 @@ } - protected void storeMaxRange(double value, String parameter) { + protected void storeMaxRange(Map ranges, double value, String parameter) { Range range = null; range = ranges.containsKey(parameter)
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/chart/HorizontalProfileChart.java Mon Mar 08 14:04:28 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/chart/HorizontalProfileChart.java Mon Mar 08 15:15:08 2010 +0000 @@ -2,6 +2,7 @@ import java.util.Collection; import java.util.Locale; +import java.util.Map; import com.vividsolutions.jts.geom.Point; import com.vividsolutions.jts.io.WKTReader; @@ -57,6 +58,18 @@ } + @Override + protected Object getValue(Result row) { + try { + return (Point) wktReader.read(row.getString("SHAPE")); + } + catch(ParseException pe) { + log.warn("No data found while parsing."); + return null; + } + } + + protected void gapDetection( Result[] results, Series series, @@ -123,6 +136,20 @@ } + @Override + protected void prepareRangeAxis(String seriesKey, int idx) { + return; + // do nothing here + } + + + @Override + protected void storeMaxValue(Map values, Object value, String parameter) { + return; + // do nothing here + } + + protected String createSeriesName( String breakPoint1, String breakPoint2,
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/chart/TimeSeriesChart.java Mon Mar 08 14:04:28 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/chart/TimeSeriesChart.java Mon Mar 08 15:15:08 2010 +0000 @@ -161,7 +161,7 @@ } addValue(row, series); - storeMaxRange(row.getDouble("YORDINATE"), parameter); + storeMaxRange(ranges, row.getDouble("YORDINATE"), parameter); endPos++; }
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/chart/VerticalProfileChart.java Mon Mar 08 14:04:28 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/chart/VerticalProfileChart.java Mon Mar 08 15:15:08 2010 +0000 @@ -2,6 +2,7 @@ import java.util.Collection; import java.util.HashMap; +import java.util.Map; import java.util.Iterator; import java.util.Locale; @@ -9,10 +10,12 @@ import org.jfree.chart.ChartTheme; import org.jfree.chart.axis.Axis; +import org.jfree.chart.axis.NumberAxis; import org.jfree.chart.plot.XYPlot; import org.jfree.chart.plot.PlotOrientation; +import org.jfree.data.Range; +import org.jfree.data.general.Series; import org.jfree.data.xy.XYSeries; -import org.jfree.data.general.Series; import org.jfree.data.xy.XYSeriesCollection; import de.intevation.gnv.geobackend.base.Result; @@ -33,6 +36,10 @@ protected final double GAP_MAX_LEVEL = Math.sqrt(2.0); protected final int GAP_MAX_VALUES = 60; + /** Map to store max ranges of each parameter (axis.setAutoRange(true) + * doesn't seem to work properly. */ + protected Map values; + public VerticalProfileChart( ChartLabels labels, @@ -59,6 +66,7 @@ this.shapesVisible = shapesVisible; this.datasets = new HashMap(); this.ranges = new HashMap(); + this.values = new HashMap(); } @@ -118,9 +126,12 @@ } addValue(row, series); - Double value = row.getDouble("YORDINATE"); - if (value != null) - storeMaxRange(value, parameter); + Object x = getValue(row); + Double y = row.getDouble("YORDINATE"); + if (x != null && y != null) { + storeMaxRange(ranges, y, parameter); + storeMaxValue(values, x, parameter); + } endPos++; } @@ -134,6 +145,11 @@ } + protected Object getValue(Result row) { + return row.getDouble("XORDINATE"); + } + + protected void gapDetection( Result[] results, Series series, @@ -149,6 +165,16 @@ } + protected void prepareRangeAxis(String seriesKey, int idx) { + XYPlot plot = chart.getXYPlot(); + NumberAxis xAxis = (NumberAxis) plot.getDomainAxis(); + + Range xRange = (Range) values.get(seriesKey); + xAxis.setRange(Range.expand(xRange, LOWER_MARGIN, UPPER_MARGIN)); + log.debug("Max X-Range of dataset is: " + xRange.toString()); + } + + protected void addValue(Result row, Series series) { ((XYSeries) series).add( row.getDouble("XORDINATE"), @@ -194,6 +220,7 @@ plot.setDataset(idx, xysc ); log.debug("Added " + key + " parameter to plot."); prepareAxis(key, idx); + prepareRangeAxis(key, idx); adjustRenderer( idx++, xysc.getSeriesCount(), @@ -205,6 +232,24 @@ } + protected void storeMaxValue(Map values, Object val, String parameter) { + double value = ((Double) val).doubleValue(); + Range range = null; + + range = values.containsKey(parameter) + ? (Range) values.get(parameter) + : new Range(value, value); + + double lower = range.getLowerBound(); + double upper = range.getUpperBound(); + + lower = value < lower ? value : lower; + upper = value > upper ? value : upper; + + values.put(parameter, new Range(lower, upper)); + } + + protected void localizeDomainAxis(Axis axis, Locale locale) { // call localizeRangeAxis from superclass which formats NumberAxis super.localizeRangeAxis(axis, locale);