Mercurial > dive4elements > gnv-client
diff gnv-artifacts/src/main/java/de/intevation/gnv/state/timeseries/TimeSeriesOutputState.java @ 639:a94ed2755480
Implemented SVG export for histograms.
gnv-artifacts/trunk@724 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Tue, 02 Mar 2010 14:48:32 +0000 |
parents | d08b9ba148c5 |
children | e5f1e868ee3e |
line wrap: on
line diff
--- 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<KeyValueDescibeData> parameters = + getParameters(uuid); + Collection<KeyValueDescibeData> measurements = + getMeasurements(uuid); + Collection<KeyValueDescibeData> 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<KeyValueDescibeData> parameters = getParameters(uuid); - Collection<KeyValueDescibeData> measurements = getMeasurements(uuid); - Collection<KeyValueDescibeData> 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<KeyValueDescibeData> parameters = - getParameters(uuid); - - Collection<KeyValueDescibeData> measurements = - getMeasurements(uuid); - - Collection<KeyValueDescibeData> dates = - getDates(uuid); - statistics = s.calculateStatistics( result, parameters,