Mercurial > dive4elements > gnv-client
changeset 327:22a6493e8460
New options in chart template: visibility of lines and points in charts and point's size.
gnv-artifacts/trunk@393 c6561f87-3c4e-4783-a992-168aeb5c3f6f
line wrap: on
line diff
--- a/gnv-artifacts/ChangeLog Tue Dec 01 16:27:56 2009 +0000 +++ b/gnv-artifacts/ChangeLog Wed Dec 02 10:50:12 2009 +0000 @@ -1,3 +1,36 @@ +2009-12-02 Ingo Weinzierl <ingo.weinzierl@intevation.de> + + * doc/conf/charttemplate.xml: Added lines to configure rendering of lines + and points in charts (visibility of lines/points and size of points). + + * src/main/java/de/intevation/gnv/chart/XMLChartTheme.java: Added method + parsing the rendering options for lines and points in charts. + + * src/main/java/de/intevation/gnv/chart/AbstractChart.java: Added boolean + member attributes which are used to control the visibility of lines and + points in charts. + + * src/main/java/de/intevation/gnv/chart/VerticalProfileChart.java, + src/main/java/de/intevation/gnv/chart/TimeSeriesChart.java, + src/main/java/de/intevation/gnv/chart/HorizontalProfileChart.java: + Constructor needs two further boolean parameter to control the visibility + of lines and points in charts. + + * src/main/java/de/intevation/gnv/chart/AbstractXYLineChart.java: The + renderer controlling the style of a series is adjusted after adding a + new series to the chart. + + * src/main/java/de/intevation/gnv/transition/profile/horizontalcrosssection/HorizontalCrossSectionMeshOutputTransition.java, + src/main/java/de/intevation/gnv/transition/profile/verticalcrosssection/VerticalCrossSectionOutputTransition.jav, + src/main/java/de/intevation/gnv/transition/profile/horizontal/HorizontalProfileOutputTransition.java, + src/main/java/de/intevation/gnv/transition/profile/vertical/VerticalProfileOutputTransition.java, + src/main/java/de/intevation/gnv/transition/timeseries/TimeSeriesOutputTransition.java: + Adjusted method calls regarding the constructor changes in *Chart classes. + + TODO: Lines and points in charts will both always be rendered at the + moment. This needs to be changed as soon as a new gui option is + implemented to control the visibility of lines/points. + 2009-12-01 Tim Englich <tim.englich@intevation.de> * src/test/java/de/intevation/gnv/artifacts/GNVArtifactsTestCase.java:
--- a/gnv-artifacts/doc/conf/charttemplate.xml Tue Dec 01 16:27:56 2009 +0000 +++ b/gnv-artifacts/doc/conf/charttemplate.xml Wed Dec 02 10:50:12 2009 +0000 @@ -61,6 +61,12 @@ <left>5</left> <right>5</right> </offset> + <itemrenderer> + <width value="4" /> + <height value="4" /> + <renderLines value="true" /> + <renderPoints value="true" /> + </itemrenderer> </plot> <!-- ========================= axis =======================!--> <axis>
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/chart/AbstractChart.java Tue Dec 01 16:27:56 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/chart/AbstractChart.java Wed Dec 02 10:50:12 2009 +0000 @@ -13,6 +13,8 @@ implements Chart { protected JFreeChart chart; + protected boolean linesVisible; + protected boolean shapesVisible; protected Locale locale;
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/chart/AbstractXYLineChart.java Tue Dec 01 16:27:56 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/chart/AbstractXYLineChart.java Wed Dec 02 10:50:12 2009 +0000 @@ -1,6 +1,7 @@ package de.intevation.gnv.chart; import java.awt.Color; +import java.awt.geom.Ellipse2D; import java.text.NumberFormat; import java.util.Collection; import java.util.Iterator; @@ -16,7 +17,7 @@ import org.jfree.chart.axis.AxisLocation; import org.jfree.chart.plot.PlotOrientation; import org.jfree.chart.plot.XYPlot; -import org.jfree.chart.renderer.xy.StandardXYItemRenderer; +import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer; import org.jfree.data.general.Series; import de.intevation.gnv.geobackend.base.Result; @@ -28,7 +29,7 @@ public abstract class AbstractXYLineChart extends AbstractChart { - private static Logger log = Logger.getLogger(AbstractXYLineChart.class); + private static Logger log = Logger.getLogger(AbstractXYLineChart.class); protected static Color[] COLOR = { Color.black, Color.red, Color.green, Color.blue @@ -99,9 +100,30 @@ else plot.setRangeAxisLocation(idx, AxisLocation.BOTTOM_OR_LEFT); plot.mapDatasetToRangeAxis(idx, idx); + } - StandardXYItemRenderer renderer = new StandardXYItemRenderer(); - renderer.setSeriesPaint(idx, COLOR[idx%COLOR.length]); + + protected void adjustRenderer( + int idx, + boolean renderLines, + boolean renderShapes + ) { + XYLineAndShapeRenderer renderer = null; + XYPlot plot = chart.getXYPlot(); + + try { + renderer = (XYLineAndShapeRenderer)((XYLineAndShapeRenderer) + (plot.getRenderer())).clone(); + } + catch (CloneNotSupportedException cnse) { + log.warn("Error while cloning renderer.", cnse); + renderer = new XYLineAndShapeRenderer(renderLines, renderShapes); + renderer.setBaseShape(new Ellipse2D.Double(-2,-2,4,4)); + } + + renderer.setSeriesPaint(0, COLOR[idx%COLOR.length]); + renderer.setSeriesShapesVisible(0, renderShapes); + renderer.setSeriesLinesVisible(0, renderLines); plot.setRenderer(idx, renderer); }
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/chart/HorizontalProfileChart.java Tue Dec 01 16:27:56 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/chart/HorizontalProfileChart.java Wed Dec 02 10:50:12 2009 +0000 @@ -39,7 +39,9 @@ Collection dates, Collection result, Collection timeGaps, - Locale locale + Locale locale, + boolean linesVisible, + boolean shapesVisible ) { super( labels, @@ -49,7 +51,9 @@ dates, result, timeGaps, - locale + locale, + linesVisible, + shapesVisible ); this.PLOT_ORIENTATION = PlotOrientation.VERTICAL; this.distance = 0; @@ -100,4 +104,4 @@ findValueTitle(dates, breakPoint3); } } -// vim:set ts=4 sw=4 si et sta sts=4 fenc=latin1 : +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/chart/TimeSeriesChart.java Tue Dec 01 16:27:56 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/chart/TimeSeriesChart.java Wed Dec 02 10:50:12 2009 +0000 @@ -43,7 +43,9 @@ Collection dates, Collection result, Collection timeGaps, - Locale locale + Locale locale, + boolean linesVisible, + boolean shapesVisible ) { this.labels = labels; this.theme = theme; @@ -54,6 +56,8 @@ this.timeGaps = timeGaps; this.locale = locale; this.PLOT_ORIENTATION = PlotOrientation.VERTICAL; + this.linesVisible = linesVisible; + this.shapesVisible = shapesVisible; } @@ -106,7 +110,8 @@ if(series != null) { addSeries(series, idx); - prepareAxis(((String)series.getKey()), idx++); + prepareAxis(((String)series.getKey()), idx); + adjustRenderer(idx++, linesVisible, shapesVisible); } // prepare variables for next plot @@ -130,8 +135,10 @@ // add the last dataset if existing to plot and prepare its axis addSeries(series, idx); - if (series != null) - prepareAxis(((String)series.getKey()), idx++); + if (series != null) { + prepareAxis(((String)series.getKey()), idx); + adjustRenderer(idx++, linesVisible, shapesVisible); + } }
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/chart/VerticalProfileChart.java Tue Dec 01 16:27:56 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/chart/VerticalProfileChart.java Wed Dec 02 10:50:12 2009 +0000 @@ -35,7 +35,9 @@ Collection dates, Collection result, Collection timeGaps, - Locale locale + Locale locale, + boolean linesVisible, + boolean shapesVisible ) { this.labels = labels; this.theme = theme; @@ -46,6 +48,8 @@ this.timeGaps = timeGaps; this.locale = locale; this.PLOT_ORIENTATION = PlotOrientation.HORIZONTAL; + this.linesVisible = linesVisible; + this.shapesVisible = shapesVisible; } @@ -75,7 +79,8 @@ if(series != null) { addSeries(series, idx); - prepareAxis(((String)series.getKey()), idx++); + prepareAxis(((String)series.getKey()), idx); + adjustRenderer(idx++, linesVisible, shapesVisible); } // prepare variables for next plot @@ -98,8 +103,10 @@ addSeries(series, idx); - if (series != null) - prepareAxis(((String)series.getKey()), idx++); + if (series != null) { + prepareAxis(((String)series.getKey()), idx); + adjustRenderer(idx++, linesVisible, shapesVisible); + } }
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/chart/XMLChartTheme.java Tue Dec 01 16:27:56 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/chart/XMLChartTheme.java Wed Dec 02 10:50:12 2009 +0000 @@ -2,12 +2,14 @@ import java.awt.Font; import java.awt.Color; +import java.awt.geom.Ellipse2D; import java.lang.NumberFormatException; import org.apache.log4j.Logger; import org.jfree.chart.StandardChartTheme; import org.jfree.chart.plot.XYPlot; +import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer; import org.jfree.ui.RectangleInsets; import org.jfree.util.UnitType; @@ -28,6 +30,11 @@ protected boolean domainCrosshairVisible; protected boolean rangeCrosshairVisible; + protected boolean renderLines; + protected boolean renderShapes; + + protected int pointWidth; + protected int pointHeight; public XMLChartTheme(String name) { @@ -71,6 +78,7 @@ initPlotParameters(document); initAxisParameters(document); initLegendParameters(document); + initRenderer(document); } @@ -189,6 +197,22 @@ } + private void initRenderer(Document document) { + log.debug("init renderer parameters."); + + pointWidth = getInt(document, "theme/plot/itemrenderer/width/@value"); + log.debug("Read point width of " + pointWidth); + pointHeight = getInt(document, "theme/plot/itemrenderer/height/@value"); + log.debug("Read point height of " + pointHeight); + renderLines = getBool( + document, "theme/plot/itemrenderer/renderLines/@value" + ); + renderShapes = getBool( + document, "theme/plot/itemrenderer/renderPoints/@value" + ); + } + + private static String getString(Document document, String xpath) { return Config.getStringXPath(document, xpath); } @@ -246,5 +270,26 @@ super.applyToXYPlot(plot); plot.setDomainCrosshairVisible(this.domainCrosshairVisible); plot.setRangeCrosshairVisible(this.rangeCrosshairVisible); + + applyToXYLineAndShapeRenderer(plot); + } + + + protected void applyToXYLineAndShapeRenderer(XYPlot plot) { + if (plot == null) + return; + + XYLineAndShapeRenderer renderer = + (XYLineAndShapeRenderer) plot.getRenderer(); + + Ellipse2D.Double point = new Ellipse2D.Double( + -(pointWidth/2), -(pointHeight/2), pointWidth, pointHeight + ); + + renderer.setSeriesShape(0, point); + renderer.setSeriesShapesVisible(0, renderShapes); + renderer.setSeriesLinesVisible(0, renderLines); + + plot.setRenderer(renderer); } }
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/profile/horizontal/HorizontalProfileOutputTransition.java Tue Dec 01 16:27:56 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/transition/profile/horizontal/HorizontalProfileOutputTransition.java Wed Dec 02 10:50:12 2009 +0000 @@ -73,7 +73,9 @@ Collection dates, Collection result, Locale locale, - String uuid + String uuid, + boolean linesVisible, + boolean shapesVisible ) { Chart chart = null; @@ -94,7 +96,9 @@ dates, result, null, - locale + locale, + linesVisible, + shapesVisible ); chart.generateChart();
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/profile/horizontalcrosssection/HorizontalCrossSectionMeshOutputTransition.java Tue Dec 01 16:27:56 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/transition/profile/horizontalcrosssection/HorizontalCrossSectionMeshOutputTransition.java Wed Dec 02 10:50:12 2009 +0000 @@ -52,7 +52,9 @@ Collection dates, Collection result, Locale locale, - String uuid + String uuid, + boolean linesVisible, + boolean shapesVisible ) { Chart chart = null;
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/profile/vertical/VerticalProfileOutputTransition.java Tue Dec 01 16:27:56 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/transition/profile/vertical/VerticalProfileOutputTransition.java Wed Dec 02 10:50:12 2009 +0000 @@ -45,7 +45,9 @@ Collection dates, Collection result, Locale locale, - String uuid + String uuid, + boolean linesVisible, + boolean shapesVisible ) { Chart chart = null; @@ -66,7 +68,9 @@ dates, result, null, - locale + locale, + linesVisible, + shapesVisible ); chart.generateChart();
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/profile/verticalcrosssection/VerticalCrossSectionOutputTransition.java Tue Dec 01 16:27:56 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/transition/profile/verticalcrosssection/VerticalCrossSectionOutputTransition.java Wed Dec 02 10:50:12 2009 +0000 @@ -61,7 +61,9 @@ Collection dates, Collection result, Locale locale, - String uuid + String uuid, + boolean linesVisible, + boolean shapesVisible ) { Chart chart = null;
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/timeseries/TimeSeriesOutputTransition.java Tue Dec 01 16:27:56 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/transition/timeseries/TimeSeriesOutputTransition.java Wed Dec 02 10:50:12 2009 +0000 @@ -218,6 +218,10 @@ String exportFormat = getExportFormat(mimeType); + // TODO Remove this and parse input data + boolean linesVisible = true; + boolean shapesVisible = true; + PreferredLocale[] locales = callMeta.getLanguages(); Locale[] serverLocales = RessourceFactory.getInstance().getLocales(); @@ -239,7 +243,9 @@ exportFormat, locale, chartWidth, - chartHeight + chartHeight, + linesVisible, + shapesVisible ); } else if (outputMode.equalsIgnoreCase("pdf")) { @@ -250,6 +256,10 @@ Locale locale = callMeta.getPreferredLocale(serverLocales); + // TODO Remove this and parse input data + boolean linesVisible = true; + boolean shapesVisible = true; + log.debug( "Best locale - regarding intersection of server and " + "browser locales - is " + locale.toString() @@ -267,7 +277,9 @@ uuid, "A4", true, - locale + locale, + linesVisible, + shapesVisible ); } else if (outputMode.equalsIgnoreCase("svg")) { @@ -275,6 +287,10 @@ int width = 600; int height = 400; + // TODO Remove this and parse input data + boolean linesVisible = true; + boolean shapesVisible = true; + Locale[] serverLocales = RessourceFactory.getInstance().getLocales(); Locale locale = @@ -297,7 +313,9 @@ uuid, locale, width, - height + height, + linesVisible, + shapesVisible ); } else if (outputMode.equalsIgnoreCase("csv")) { @@ -473,7 +491,9 @@ String exportFormat, Locale locale, int width, - int height + int height, + boolean linesVisible, + boolean shapesVisible ) throws IOException, TechnicalChartException { @@ -485,7 +505,9 @@ dates, getChartResult(uuid), locale, // Locale - uuid + uuid, + linesVisible, + shapesVisible ); if (chart == null) { @@ -517,7 +539,9 @@ String uuid, String exportFormat, boolean landscape, - Locale locale + Locale locale, + boolean linesVisible, + boolean shapesVisible ) { Chart chart = getChart( chartLables, @@ -526,7 +550,9 @@ dates, getChartResult(uuid), locale, - uuid + uuid, + linesVisible, + shapesVisible ); if (chart == null) { @@ -566,7 +592,9 @@ String uuid, Locale locale, int width, - int height + int height, + boolean linesVisible, + boolean shapesVisible ) { Chart chart = getChart( chartLables, @@ -575,7 +603,9 @@ dates, getChartResult(uuid), locale, - uuid + uuid, + linesVisible, + shapesVisible ); if (chart == null) { @@ -601,7 +631,9 @@ Collection dates, Collection result, Locale locale, - String uuid + String uuid, + boolean linesVisible, + boolean shapesVisible ) { Chart chart = null; @@ -622,7 +654,9 @@ dates, result, timeGapDefinitions, - locale + locale, + linesVisible, + shapesVisible ); chart.generateChart();