# HG changeset patch # User Ingo Weinzierl # Date 1267541312 0 # Node ID a94ed2755480fcc26095112d7d0dd2678e7cf57f # Parent c580666a843fd7a0493ce13975ef1816c7d50d81 Implemented SVG export for histograms. gnv-artifacts/trunk@724 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r c580666a843f -r a94ed2755480 gnv-artifacts/ChangeLog --- a/gnv-artifacts/ChangeLog Tue Mar 02 08:43:50 2010 +0000 +++ b/gnv-artifacts/ChangeLog Tue Mar 02 14:48:32 2010 +0000 @@ -1,3 +1,27 @@ +2010-03-02 Ingo Weinzierl + + * src/main/java/de/intevation/gnv/state/OutputStateBase.java: Added an xpath + expression for export modes. + + * src/main/java/de/intevation/gnv/state/timeseries/TimeSeriesOutputState.java: + Refactoring of 'out' to be able to add pdf and svg exports to histogram. + Now, there are just four output modes left (chart, histogram, csv, odv). + Export modes (pdf, svg, img) are part of these output modes. + Implemented svg export for histogram charts. + + * src/main/java/de/intevation/gnv/exports/ChartExportHelper.java: Helper + method to export histograms as svg via output stream. + + * doc/conf/products/timeseries/conf_mesh.xml, + doc/conf/products/timeseries/conf_timeseriespoint.xml, + doc/conf/products/horizontalprofile/conf_mesh.xml, + doc/conf/products/horizontalprofile/conf_instantaneouspoint.xml, + doc/conf/products/horizontalprofile/conf_mesh_cross.xml, + doc/conf/products/verticalprofile/conf_mesh.xml, + doc/conf/products/verticalprofile/conf_timeseriespoint.xml, + doc/conf/products/verticalprofile/conf_instantaneouspoint.xml: Added svg + as export mode to histogram output in configuration files. + 2010-03-02 Ingo Weinzierl Issue180 diff -r c580666a843f -r a94ed2755480 gnv-artifacts/doc/conf/products/horizontalprofile/conf_instantaneouspoint.xml --- a/gnv-artifacts/doc/conf/products/horizontalprofile/conf_instantaneouspoint.xml Tue Mar 02 08:43:50 2010 +0000 +++ b/gnv-artifacts/doc/conf/products/horizontalprofile/conf_instantaneouspoint.xml Tue Mar 02 14:48:32 2010 +0000 @@ -242,8 +242,8 @@ - --> diff -r c580666a843f -r a94ed2755480 gnv-artifacts/doc/conf/products/horizontalprofile/conf_mesh.xml --- a/gnv-artifacts/doc/conf/products/horizontalprofile/conf_mesh.xml Tue Mar 02 08:43:50 2010 +0000 +++ b/gnv-artifacts/doc/conf/products/horizontalprofile/conf_mesh.xml Tue Mar 02 14:48:32 2010 +0000 @@ -243,8 +243,8 @@ - --> diff -r c580666a843f -r a94ed2755480 gnv-artifacts/doc/conf/products/horizontalprofile/conf_mesh_cross.xml --- a/gnv-artifacts/doc/conf/products/horizontalprofile/conf_mesh_cross.xml Tue Mar 02 08:43:50 2010 +0000 +++ b/gnv-artifacts/doc/conf/products/horizontalprofile/conf_mesh_cross.xml Tue Mar 02 14:48:32 2010 +0000 @@ -209,8 +209,8 @@ - --> diff -r c580666a843f -r a94ed2755480 gnv-artifacts/doc/conf/products/timeseries/conf_mesh.xml --- a/gnv-artifacts/doc/conf/products/timeseries/conf_mesh.xml Tue Mar 02 08:43:50 2010 +0000 +++ b/gnv-artifacts/doc/conf/products/timeseries/conf_mesh.xml Tue Mar 02 14:48:32 2010 +0000 @@ -231,8 +231,8 @@ - --> diff -r c580666a843f -r a94ed2755480 gnv-artifacts/doc/conf/products/timeseries/conf_timeseriespoint.xml --- a/gnv-artifacts/doc/conf/products/timeseries/conf_timeseriespoint.xml Tue Mar 02 08:43:50 2010 +0000 +++ b/gnv-artifacts/doc/conf/products/timeseries/conf_timeseriespoint.xml Tue Mar 02 14:48:32 2010 +0000 @@ -214,8 +214,8 @@ - --> diff -r c580666a843f -r a94ed2755480 gnv-artifacts/doc/conf/products/verticalprofile/conf_instantaneouspoint.xml --- a/gnv-artifacts/doc/conf/products/verticalprofile/conf_instantaneouspoint.xml Tue Mar 02 08:43:50 2010 +0000 +++ b/gnv-artifacts/doc/conf/products/verticalprofile/conf_instantaneouspoint.xml Tue Mar 02 14:48:32 2010 +0000 @@ -112,8 +112,8 @@ - --> diff -r c580666a843f -r a94ed2755480 gnv-artifacts/doc/conf/products/verticalprofile/conf_mesh.xml --- a/gnv-artifacts/doc/conf/products/verticalprofile/conf_mesh.xml Tue Mar 02 08:43:50 2010 +0000 +++ b/gnv-artifacts/doc/conf/products/verticalprofile/conf_mesh.xml Tue Mar 02 14:48:32 2010 +0000 @@ -247,8 +247,8 @@ - --> diff -r c580666a843f -r a94ed2755480 gnv-artifacts/doc/conf/products/verticalprofile/conf_timeseriespoint.xml --- a/gnv-artifacts/doc/conf/products/verticalprofile/conf_timeseriespoint.xml Tue Mar 02 08:43:50 2010 +0000 +++ b/gnv-artifacts/doc/conf/products/verticalprofile/conf_timeseriespoint.xml Tue Mar 02 14:48:32 2010 +0000 @@ -185,8 +185,8 @@ - --> diff -r c580666a843f -r a94ed2755480 gnv-artifacts/src/main/java/de/intevation/gnv/exports/ChartExportHelper.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/exports/ChartExportHelper.java Tue Mar 02 08:43:50 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/exports/ChartExportHelper.java Tue Mar 02 14:48:32 2010 +0000 @@ -92,6 +92,41 @@ } + public static void exportHistogramsAsSVG( + OutputStream out, + Chart[] histograms, + String encoding, + int width, + int height + ) { + log.info("export histograms as svg"); + + if (encoding == null) + encoding = DEFAULT_ENCODING; + + org.w3c.dom.Document document = XMLUtils.newDocument(); + SVGGraphics2D graphics = new SVGGraphics2D(document); + + int size = histograms.length; + for (int i = 0; i < size; i++) { + JFreeChart chart = histograms[i].generateChart(); + chart.draw(graphics, new Rectangle2D.Double( + 0.0D, i*height,width,height)); + } + graphics.finalize(); + + try { + graphics.stream(new OutputStreamWriter(out, encoding)); + } + catch (SVGGraphics2DIOException svge) { + log.error("Error while writing svg export to output stream.", svge); + } + catch (UnsupportedEncodingException uee) { + log.error("Unsupported encoding: " + encoding, uee); + } + } + + public static void exportSVG( OutputStream out, JFreeChart chart, diff -r c580666a843f -r a94ed2755480 gnv-artifacts/src/main/java/de/intevation/gnv/state/OutputStateBase.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/OutputStateBase.java Tue Mar 02 08:43:50 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/OutputStateBase.java Tue Mar 02 14:48:32 2010 +0000 @@ -46,6 +46,9 @@ public static final String XPATH_OUTPUT_MODE = "/art:action/art:out/@name"; + public static final String XPATH_EXPORT_MODE = + "/art:action/art:out/art:export/@name"; + public static final String XPATH_MIME_TYPE = "/art:action/art:out/art:mime-type/@value"; diff -r c580666a843f -r a94ed2755480 gnv-artifacts/src/main/java/de/intevation/gnv/state/timeseries/TimeSeriesOutputState.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/timeseries/TimeSeriesOutputState.java Tue Mar 02 08:43:50 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/timeseries/TimeSeriesOutputState.java Tue Mar 02 14:48:32 2010 +0000 @@ -218,6 +218,13 @@ String outputMode = XMLUtils.xpathString( format, XPATH_OUTPUT_MODE, ArtifactNamespaceContext.INSTANCE); + String mode = XMLUtils.xpathString( + format, XPATH_EXPORT_MODE, ArtifactNamespaceContext.INSTANCE); + + if (mode == null || mode.equals("")) { + mode = "img"; + } + String mimeType = XMLUtils.xpathString( format, XPATH_MIME_TYPE, ArtifactNamespaceContext.INSTANCE); @@ -241,7 +248,6 @@ while (it.hasNext()) { InputData ip = it.next(); String optionName = ip.getName().trim(); - log.debug("FOUND [" + optionName + "] with value {"+ ip.getValue()+"}"); requestParameter.put(optionName, ip.getValue()); if (optionName.equals("width")) { @@ -261,65 +267,90 @@ } try { + Collection parameters = + getParameters(uuid); + Collection measurements = + getMeasurements(uuid); + Collection dates = + getDates(uuid); + + Locale[] serverLocales = + RessourceFactory.getInstance().getLocales(); + Locale locale = + callMeta.getPreferredLocale(serverLocales); + + ChartLabels chartLables = createChartLabels(locale, uuid); + + log.debug( + "Best locale - regarding intersection of server and " + + "browser locales - is " + locale.toString() + ); + + String exportFormat = getExportFormat(mimeType); + + // CHART if (outputMode.equalsIgnoreCase("chart")) { log.debug("Chart will be generated."); - PreferredLocale[] locales = callMeta.getLanguages(); - Locale[] serverLocales = - RessourceFactory.getInstance().getLocales(); - Locale locale = - callMeta.getPreferredLocale(serverLocales); - - log.debug( - "Best locale - regarding intersection of server and " + - "browser locales - is " + locale.toString() - ); - - Collection parameters = this.getParameters(uuid); - Collection measurements = this.getMeasurements(uuid); - Collection dates = this.getDates(uuid); - - ChartLabels chartLables = createChartLabels(locale, uuid); - - String exportFormat = getExportFormat(mimeType); + if (mode.equalsIgnoreCase("img")) { + createChart( + outputStream, + parameters, + measurements, + dates, + chartLables, + callContext, + uuid, + exportFormat, + locale, + chartWidth, + chartHeight, + lVisible, + sVisible, + callContext + ); + } + else if (mode.equalsIgnoreCase("pdf")) { + createPDF( + outputStream, + parameters, + measurements, + dates, + chartLables, + uuid, + "A4", + true, + lVisible, + sVisible, + locale, + callContext + ); + } + else if (mode.equalsIgnoreCase("svg")) { + createSVG( + outputStream, + getParameters(uuid), + getMeasurements(uuid), + getDates(uuid), + createChartLabels(locale, uuid), + uuid, + locale, + chartWidth, + chartHeight, + lVisible, + sVisible, + callContext + ); + } + } + // HISTOGRAM + else if (outputMode.equalsIgnoreCase("histogram")) { + Collection results = (Collection) getChartResult(uuid, callContext); + requestParameter.put("locale", locale); - this.createChart( - outputStream, - parameters, - measurements, - dates, - chartLables, - callContext, - uuid, - exportFormat, - locale, - chartWidth, - chartHeight, - lVisible, - sVisible, - callContext - ); - } - else if (outputMode.equalsIgnoreCase("histogram")) { - log.debug("Create histogram."); - - Collection results = (Collection) - getChartResult(uuid, callContext); - - String exportFormat = getExportFormat(mimeType); - Collection parameters = getParameters(uuid); - Collection measurements = getMeasurements(uuid); - Collection dates = getDates(uuid); Object[][] data = HistogramHelper.prepareHistogramData( results, parameters, measurements, dates); - PreferredLocale[] locales = callMeta.getLanguages(); - Locale[] serverLocales = - RessourceFactory.getInstance().getLocales(); - Locale locale = - callMeta.getPreferredLocale(serverLocales); - requestParameter.put("locale", locale); - int size = data.length; Chart[] histograms = new Chart[size]; @@ -333,69 +364,27 @@ labels, data[i], theme, requestParameter); } - ChartExportHelper.exportHistograms( - outputStream, - histograms, - exportFormat, - chartWidth, - chartHeight - ); - } - else if (outputMode.equalsIgnoreCase("pdf")) { - log.debug("Output mode == pdf"); - - Locale[] serverLocales = - RessourceFactory.getInstance().getLocales(); - Locale locale = - callMeta.getPreferredLocale(serverLocales); - - log.debug( - "Best locale - regarding intersection of server and " + - "browser locales - is " + locale.toString() - ); - - createPDF( - outputStream, - getParameters(uuid), - getMeasurements(uuid), - getDates(uuid), - createChartLabels(locale, uuid), - uuid, - "A4", - true, - lVisible, - sVisible, - locale, - callContext - ); - } - else if (outputMode.equalsIgnoreCase("svg")) { - log.debug("Output mode == svg"); - - Locale[] serverLocales = - RessourceFactory.getInstance().getLocales(); - Locale locale = - callMeta.getPreferredLocale(serverLocales); - - log.debug( - "Best locale - regarding intersection of server and " + - "browser locales - is " + locale.toString() - ); - - createSVG( - outputStream, - getParameters(uuid), - getMeasurements(uuid), - getDates(uuid), - createChartLabels(locale, uuid), - uuid, - locale, - chartWidth, - chartHeight, - lVisible, - sVisible, - callContext - ); + if (mode.equalsIgnoreCase("img")) { + ChartExportHelper.exportHistograms( + outputStream, + histograms, + exportFormat, + chartWidth, + chartHeight + ); + } + else if (mode.equalsIgnoreCase("pdf")) { + log.info("not implemented yet."); + } + else if (mode.equalsIgnoreCase("svg")) { + ChartExportHelper.exportHistogramsAsSVG( + outputStream, + histograms, + null, + chartWidth, + chartHeight + ); + } } else if (outputMode.equalsIgnoreCase("csv")) { log.debug("CSV-File will be generated."); @@ -414,15 +403,6 @@ Object result = getChartResult(uuid, callContext); if (result != null && s != null) { - Collection parameters = - getParameters(uuid); - - Collection measurements = - getMeasurements(uuid); - - Collection dates = - getDates(uuid); - statistics = s.calculateStatistics( result, parameters,