Mercurial > dive4elements > gnv-client
changeset 334:e37930705daa
Changed the way of adding data to charts. Same parameters have one axis - not each parameter its own one.
gnv-artifacts/trunk@400 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Mon, 07 Dec 2009 17:03:24 +0000 (2009-12-07) |
parents | 19571fd1d0e8 |
children | e964a3d8f7bc |
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 gnv-artifacts/src/main/java/de/intevation/gnv/transition/timeseries/TimeSeriesOutputTransition.java |
diffstat | 6 files changed, 167 insertions(+), 39 deletions(-) [+] |
line wrap: on
line diff
--- a/gnv-artifacts/ChangeLog Mon Dec 07 10:33:31 2009 +0000 +++ b/gnv-artifacts/ChangeLog Mon Dec 07 17:03:24 2009 +0000 @@ -1,3 +1,22 @@ +2009-12-07 Ingo Weinzierl <ingo.weinzierl@intevation.de> + + * src/main/java/de/intevation/gnv/transition/timeseries/TimeSeriesOutputTransition.java: + Remove unselected parameters from parameters list before initiating + charts. Parameter names are used as axis labels. + + * src/main/java/de/intevation/gnv/chart/TimeSeriesChart.java, + src/main/java/de/intevation/gnv/chart/VerticalProfileChart.java, + src/main/java/de/intevation/gnv/chart/HorizontalProfileChart.java: Changed + the way of adding data to charts: same parameters are stored in the same + dataset. Now, each parameter has only one axis. Axes and renderer are + adjusted one time after collecting data - not after creating every + single series. + + * src/main/java/de/intevation/gnv/chart/AbstractXYLineChart.java: Added some + more colors to distinguish between different parameters/attributes. + Changed method to adjust rendering options regarding the changes of + datasets described above. + 2009-12-07 Ingo Weinzierl <ingo.weinzierl@intevation.de> * src/main/java/de/intevation/gnv/chart/TimeSeriesChart.java: Changed method
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/chart/AbstractXYLineChart.java Mon Dec 07 10:33:31 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/chart/AbstractXYLineChart.java Mon Dec 07 17:03:24 2009 +0000 @@ -6,6 +6,7 @@ import java.util.Collection; import java.util.Iterator; import java.util.Locale; +import java.util.Map; import org.apache.log4j.Logger; @@ -34,14 +35,19 @@ private static Logger log = Logger.getLogger(AbstractXYLineChart.class); protected static Color[] COLOR = { - Color.black, Color.red, Color.green, Color.blue + Color.black, Color.red, Color.green, Color.blue, Color.yellow, + Color.gray, Color.orange, Color.pink, Color.cyan }; + protected static int nextColor = 0; + protected PlotOrientation PLOT_ORIENTATION = PlotOrientation.VERTICAL; + protected Map datasets; + protected abstract void initData(); protected abstract void addValue(Result row, Series series); - protected abstract void addSeries(Series series, int idx); + protected abstract void addSeries(Series series, String label, int idx); protected abstract void localizeDomainAxis(Axis axis, Locale locale); protected abstract String createSeriesName( String breakPoint1, @@ -114,9 +120,11 @@ protected void adjustRenderer( int idx, + int seriesCount, boolean renderLines, boolean renderShapes ) { + log.debug("Adjust render of series"); XYLineAndShapeRenderer renderer = null; XYPlot plot = chart.getXYPlot(); @@ -130,9 +138,13 @@ renderer.setBaseShape(new Ellipse2D.Double(-2,-2,4,4)); } - renderer.setSeriesPaint(0, COLOR[idx%COLOR.length]); - renderer.setSeriesShapesVisible(0, renderShapes); - renderer.setSeriesLinesVisible(0, renderLines); + for (int i = 0; i < seriesCount; i++) { + renderer.setSeriesShape(i, renderer.getSeriesShape(0)); + renderer.setSeriesPaint(i, COLOR[nextColor%COLOR.length]); + renderer.setSeriesShapesVisible(i, renderShapes); + renderer.setSeriesLinesVisible(i, renderLines); + nextColor++; + } plot.setRenderer(idx, renderer); } @@ -151,6 +163,21 @@ } + protected String findParameter(String label) { + Iterator iter = parameters.iterator(); + + while (iter.hasNext()) { + KeyValueDescibeData data = (KeyValueDescibeData) iter.next(); + String key = data.getValue(); + + if (label.indexOf(key) > -1) + return key; + } + + return label; + } + + protected String findValueTitle(Collection values, String id) { log.debug("find description of dataset");
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/chart/HorizontalProfileChart.java Mon Dec 07 10:33:31 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/chart/HorizontalProfileChart.java Mon Dec 07 17:03:24 2009 +0000 @@ -81,8 +81,8 @@ } - protected void addSeries(Series series, int idx) { - super.addSeries(series, idx); + protected void addSeries(Series series, String label, int idx) { + super.addSeries(series, label, idx); // reset values used by current series for next series lastPoint = null;
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/chart/TimeSeriesChart.java Mon Dec 07 10:33:31 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/chart/TimeSeriesChart.java Mon Dec 07 17:03:24 2009 +0000 @@ -4,6 +4,7 @@ import java.text.SimpleDateFormat; import java.util.Collection; import java.util.Date; +import java.util.HashMap; import java.util.Iterator; import java.util.Locale; @@ -22,6 +23,7 @@ import org.jfree.data.time.TimeSeriesCollection; import de.intevation.gnv.geobackend.base.Result; +import de.intevation.gnv.transition.describedata.KeyValueDescibeData; import de.intevation.gnv.timeseries.gap.TimeGap; @@ -62,6 +64,7 @@ this.PLOT_ORIENTATION = PlotOrientation.VERTICAL; this.linesVisible = linesVisible; this.shapesVisible = shapesVisible; + this.datasets = new HashMap(); } @@ -114,10 +117,8 @@ startDate = results[startPos].getDate("XORDINATE"); endDate = results[endPos-1].getDate("XORDINATE"); addGaps(results,series,startDate,endDate,startPos,endPos); - addSeries(series, idx); + addSeries(series, seriesName, idx); - prepareAxis(((String)series.getKey()), idx); - adjustRenderer(idx++, linesVisible, shapesVisible); startPos = endPos + 1; } @@ -134,9 +135,6 @@ log.debug("next dataset is '" + seriesName + "'"); series = new TimeSeries(seriesName, Minute.class); - - // set values of start date and start position in collection for - // next parameter } addValue(row, series); @@ -147,12 +145,9 @@ startDate = results[startPos].getDate("XORDINATE"); endDate = results[endPos-1].getDate("XORDINATE"); addGaps(results, series, startDate, endDate, startPos, endPos); - addSeries(series, idx); + addSeries(series, seriesName, idx); - if (series != null) { - prepareAxis(((String)series.getKey()), idx); - adjustRenderer(idx++, linesVisible, shapesVisible); - } + addDatasets(); } @@ -164,17 +159,52 @@ } - protected void addSeries(Series series, int idx) { - log.debug("add series to timeseries chart"); - XYPlot plot = chart.getXYPlot(); + protected void addSeries(Series series, String label, int idx) { + log.debug("add series (" + label + ")to timeseries chart"); if (series == null) { log.warn("no data to add"); return; } - TimeSeriesCollection tsc = new TimeSeriesCollection((TimeSeries)series); - plot.setDataset(idx, tsc); + TimeSeriesCollection tsc = null; + + String parameter = findParameter(label); + if (datasets.containsKey(parameter)) + tsc = (TimeSeriesCollection) datasets.get(parameter); + else + tsc = new TimeSeriesCollection(); + + tsc.addSeries((TimeSeries) series); + datasets.put(parameter, tsc); + } + + + protected void addDatasets() { + Iterator iter = parameters.iterator(); + XYPlot plot = chart.getXYPlot(); + int idx = 0; + + TimeSeriesCollection tsc = null; + KeyValueDescibeData data = null; + String key = null; + while (iter.hasNext()) { + data = (KeyValueDescibeData) iter.next(); + key = data.getValue(); + + if (datasets.containsKey(key)) { + tsc = (TimeSeriesCollection)datasets.get(key); + plot.setDataset(idx, tsc ); + log.debug("Added " + key + " parameter to plot."); + prepareAxis(key, idx); + adjustRenderer( + idx++, + tsc.getSeriesCount(), + linesVisible, + shapesVisible + ); + } + } }
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/chart/VerticalProfileChart.java Mon Dec 07 10:33:31 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/chart/VerticalProfileChart.java Mon Dec 07 17:03:24 2009 +0000 @@ -1,6 +1,7 @@ package de.intevation.gnv.chart; import java.util.Collection; +import java.util.HashMap; import java.util.Iterator; import java.util.Locale; @@ -16,6 +17,7 @@ import org.jfree.data.xy.XYSeriesCollection; import de.intevation.gnv.geobackend.base.Result; +import de.intevation.gnv.transition.describedata.KeyValueDescibeData; /** @@ -50,6 +52,7 @@ this.PLOT_ORIENTATION = PlotOrientation.HORIZONTAL; this.linesVisible = linesVisible; this.shapesVisible = shapesVisible; + this.datasets = new HashMap(); } @@ -78,9 +81,7 @@ log.debug("prepare data/plot for next dataset"); if(series != null) { - addSeries(series, idx); - prepareAxis(((String)series.getKey()), idx); - adjustRenderer(idx++, linesVisible, shapesVisible); + addSeries(series, seriesName, idx); } // prepare variables for next plot @@ -101,12 +102,9 @@ addValue(row, series); } - addSeries(series, idx); + addSeries(series, seriesName, idx); - if (series != null) { - prepareAxis(((String)series.getKey()), idx); - adjustRenderer(idx++, linesVisible, shapesVisible); - } + addDatasets(); } @@ -119,17 +117,52 @@ } - protected void addSeries(Series series, int idx) { - log.debug("add series to verticalprofile chart"); - XYPlot plot = chart.getXYPlot(); + protected void addSeries(Series series, String label, int idx) { + log.debug("add series (" + label + ")to chart"); if (series == null) { log.warn("no data to add"); return; } - XYSeriesCollection xysc = new XYSeriesCollection((XYSeries)series); - plot.setDataset(idx, xysc); + XYSeriesCollection xysc = null; + String parameter = findParameter(label); + + if (datasets.containsKey(parameter)) + xysc = (XYSeriesCollection) datasets.get(parameter); + else + xysc = new XYSeriesCollection(); + + xysc.addSeries((XYSeries) series); + datasets.put(parameter, xysc); + } + + + protected void addDatasets() { + Iterator iter = parameters.iterator(); + XYPlot plot = chart.getXYPlot(); + int idx = 0; + + XYSeriesCollection xysc = null; + KeyValueDescibeData data = null; + String key = null; + while (iter.hasNext()) { + data = (KeyValueDescibeData) iter.next(); + key = data.getValue(); + + if (datasets.containsKey(key)) { + xysc = (XYSeriesCollection)datasets.get(key); + plot.setDataset(idx, xysc ); + log.debug("Added " + key + " parameter to plot."); + prepareAxis(key, idx); + adjustRenderer( + idx++, + xysc.getSeriesCount(), + linesVisible, + shapesVisible + ); + } + } }
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/timeseries/TimeSeriesOutputTransition.java Mon Dec 07 10:33:31 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/transition/timeseries/TimeSeriesOutputTransition.java Mon Dec 07 17:03:24 2009 +0000 @@ -13,6 +13,7 @@ import java.util.Iterator; import java.util.List; import java.util.Locale; +import java.util.Vector; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerConfigurationException; @@ -222,7 +223,7 @@ "browser locales - is " + locale.toString() ); - Collection parameters = this.getParameters(uuid); + Collection parameters = this.getCleanedParameters(uuid); Collection measurements = this.getMeasurements(uuid); Collection dates = this.getDates(uuid); @@ -272,7 +273,7 @@ createPDF( outputStream, - getParameters(uuid), + getCleanedParameters(uuid), getMeasurements(uuid), getDates(uuid), new ChartLabels( @@ -308,7 +309,7 @@ createSVG( outputStream, - getParameters(uuid), + getCleanedParameters(uuid), getMeasurements(uuid), getDates(uuid), new ChartLabels( @@ -374,6 +375,24 @@ } + protected Collection getCleanedParameters(Collection parameters) { + Iterator iter = parameters.iterator(); + Collection parameter = new Vector(parameters); + while (iter.hasNext()) { + KeyValueDescibeData data = (KeyValueDescibeData)iter.next(); + if (!data.isSelected()) + parameter.remove(data); + } + + return parameter; + } + + + protected Collection getCleanedParameters(String uuid) { + return getCleanedParameters(getParameters(uuid)); + } + + /** * @param outputStream * @param chartResult