Mercurial > dive4elements > gnv-client
comparison 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 |
comparison
equal
deleted
inserted
replaced
638:c580666a843f | 639:a94ed2755480 |
---|---|
216 log.debug("TimeSeriesOutputTransition.out"); | 216 log.debug("TimeSeriesOutputTransition.out"); |
217 | 217 |
218 String outputMode = XMLUtils.xpathString( | 218 String outputMode = XMLUtils.xpathString( |
219 format, XPATH_OUTPUT_MODE, ArtifactNamespaceContext.INSTANCE); | 219 format, XPATH_OUTPUT_MODE, ArtifactNamespaceContext.INSTANCE); |
220 | 220 |
221 String mode = XMLUtils.xpathString( | |
222 format, XPATH_EXPORT_MODE, ArtifactNamespaceContext.INSTANCE); | |
223 | |
224 if (mode == null || mode.equals("")) { | |
225 mode = "img"; | |
226 } | |
227 | |
221 String mimeType = XMLUtils.xpathString( | 228 String mimeType = XMLUtils.xpathString( |
222 format, XPATH_MIME_TYPE, ArtifactNamespaceContext.INSTANCE); | 229 format, XPATH_MIME_TYPE, ArtifactNamespaceContext.INSTANCE); |
223 | 230 |
224 CallMeta callMeta = callContext.getMeta(); | 231 CallMeta callMeta = callContext.getMeta(); |
225 | 232 |
239 if (inputData != null) { | 246 if (inputData != null) { |
240 Iterator<InputData> it = inputData.iterator(); | 247 Iterator<InputData> it = inputData.iterator(); |
241 while (it.hasNext()) { | 248 while (it.hasNext()) { |
242 InputData ip = it.next(); | 249 InputData ip = it.next(); |
243 String optionName = ip.getName().trim(); | 250 String optionName = ip.getName().trim(); |
244 log.debug("FOUND [" + optionName + "] with value {"+ ip.getValue()+"}"); | |
245 requestParameter.put(optionName, ip.getValue()); | 251 requestParameter.put(optionName, ip.getValue()); |
246 | 252 |
247 if (optionName.equals("width")) { | 253 if (optionName.equals("width")) { |
248 chartWidth = Integer.parseInt(ip.getValue()); | 254 chartWidth = Integer.parseInt(ip.getValue()); |
249 } | 255 } |
259 log.error(e, e); | 265 log.error(e, e); |
260 throw new StateException(e); | 266 throw new StateException(e); |
261 } | 267 } |
262 | 268 |
263 try { | 269 try { |
270 Collection<KeyValueDescibeData> parameters = | |
271 getParameters(uuid); | |
272 Collection<KeyValueDescibeData> measurements = | |
273 getMeasurements(uuid); | |
274 Collection<KeyValueDescibeData> dates = | |
275 getDates(uuid); | |
276 | |
277 Locale[] serverLocales = | |
278 RessourceFactory.getInstance().getLocales(); | |
279 Locale locale = | |
280 callMeta.getPreferredLocale(serverLocales); | |
281 | |
282 ChartLabels chartLables = createChartLabels(locale, uuid); | |
283 | |
284 log.debug( | |
285 "Best locale - regarding intersection of server and " + | |
286 "browser locales - is " + locale.toString() | |
287 ); | |
288 | |
289 String exportFormat = getExportFormat(mimeType); | |
290 | |
291 // CHART | |
264 if (outputMode.equalsIgnoreCase("chart")) { | 292 if (outputMode.equalsIgnoreCase("chart")) { |
265 log.debug("Chart will be generated."); | 293 log.debug("Chart will be generated."); |
266 | 294 |
267 PreferredLocale[] locales = callMeta.getLanguages(); | 295 if (mode.equalsIgnoreCase("img")) { |
268 Locale[] serverLocales = | 296 createChart( |
269 RessourceFactory.getInstance().getLocales(); | 297 outputStream, |
270 Locale locale = | 298 parameters, |
271 callMeta.getPreferredLocale(serverLocales); | 299 measurements, |
272 | 300 dates, |
273 log.debug( | 301 chartLables, |
274 "Best locale - regarding intersection of server and " + | 302 callContext, |
275 "browser locales - is " + locale.toString() | 303 uuid, |
276 ); | 304 exportFormat, |
277 | 305 locale, |
278 Collection parameters = this.getParameters(uuid); | 306 chartWidth, |
279 Collection measurements = this.getMeasurements(uuid); | 307 chartHeight, |
280 Collection dates = this.getDates(uuid); | 308 lVisible, |
281 | 309 sVisible, |
282 ChartLabels chartLables = createChartLabels(locale, uuid); | 310 callContext |
283 | 311 ); |
284 String exportFormat = getExportFormat(mimeType); | 312 } |
285 | 313 else if (mode.equalsIgnoreCase("pdf")) { |
286 this.createChart( | 314 createPDF( |
287 outputStream, | 315 outputStream, |
288 parameters, | 316 parameters, |
289 measurements, | 317 measurements, |
290 dates, | 318 dates, |
291 chartLables, | 319 chartLables, |
292 callContext, | 320 uuid, |
293 uuid, | 321 "A4", |
294 exportFormat, | 322 true, |
295 locale, | 323 lVisible, |
296 chartWidth, | 324 sVisible, |
297 chartHeight, | 325 locale, |
298 lVisible, | 326 callContext |
299 sVisible, | 327 ); |
300 callContext | 328 } |
301 ); | 329 else if (mode.equalsIgnoreCase("svg")) { |
330 createSVG( | |
331 outputStream, | |
332 getParameters(uuid), | |
333 getMeasurements(uuid), | |
334 getDates(uuid), | |
335 createChartLabels(locale, uuid), | |
336 uuid, | |
337 locale, | |
338 chartWidth, | |
339 chartHeight, | |
340 lVisible, | |
341 sVisible, | |
342 callContext | |
343 ); | |
344 } | |
302 } | 345 } |
346 // HISTOGRAM | |
303 else if (outputMode.equalsIgnoreCase("histogram")) { | 347 else if (outputMode.equalsIgnoreCase("histogram")) { |
304 log.debug("Create histogram."); | 348 Collection results = (Collection) getChartResult(uuid, callContext); |
305 | 349 requestParameter.put("locale", locale); |
306 Collection results = (Collection) | 350 |
307 getChartResult(uuid, callContext); | |
308 | |
309 String exportFormat = getExportFormat(mimeType); | |
310 Collection<KeyValueDescibeData> parameters = getParameters(uuid); | |
311 Collection<KeyValueDescibeData> measurements = getMeasurements(uuid); | |
312 Collection<KeyValueDescibeData> dates = getDates(uuid); | |
313 Object[][] data = HistogramHelper.prepareHistogramData( | 351 Object[][] data = HistogramHelper.prepareHistogramData( |
314 results, parameters, measurements, dates); | 352 results, parameters, measurements, dates); |
315 | |
316 PreferredLocale[] locales = callMeta.getLanguages(); | |
317 Locale[] serverLocales = | |
318 RessourceFactory.getInstance().getLocales(); | |
319 Locale locale = | |
320 callMeta.getPreferredLocale(serverLocales); | |
321 requestParameter.put("locale", locale); | |
322 | 353 |
323 int size = data.length; | 354 int size = data.length; |
324 Chart[] histograms = new Chart[size]; | 355 Chart[] histograms = new Chart[size]; |
325 | 356 |
326 for (int i = 0; i < size; i++) { | 357 for (int i = 0; i < size; i++) { |
331 | 362 |
332 histograms[i] = new DefaultHistogram( | 363 histograms[i] = new DefaultHistogram( |
333 labels, data[i], theme, requestParameter); | 364 labels, data[i], theme, requestParameter); |
334 } | 365 } |
335 | 366 |
336 ChartExportHelper.exportHistograms( | 367 if (mode.equalsIgnoreCase("img")) { |
337 outputStream, | 368 ChartExportHelper.exportHistograms( |
338 histograms, | 369 outputStream, |
339 exportFormat, | 370 histograms, |
340 chartWidth, | 371 exportFormat, |
341 chartHeight | 372 chartWidth, |
342 ); | 373 chartHeight |
343 } | 374 ); |
344 else if (outputMode.equalsIgnoreCase("pdf")) { | 375 } |
345 log.debug("Output mode == pdf"); | 376 else if (mode.equalsIgnoreCase("pdf")) { |
346 | 377 log.info("not implemented yet."); |
347 Locale[] serverLocales = | 378 } |
348 RessourceFactory.getInstance().getLocales(); | 379 else if (mode.equalsIgnoreCase("svg")) { |
349 Locale locale = | 380 ChartExportHelper.exportHistogramsAsSVG( |
350 callMeta.getPreferredLocale(serverLocales); | 381 outputStream, |
351 | 382 histograms, |
352 log.debug( | 383 null, |
353 "Best locale - regarding intersection of server and " + | 384 chartWidth, |
354 "browser locales - is " + locale.toString() | 385 chartHeight |
355 ); | 386 ); |
356 | 387 } |
357 createPDF( | |
358 outputStream, | |
359 getParameters(uuid), | |
360 getMeasurements(uuid), | |
361 getDates(uuid), | |
362 createChartLabels(locale, uuid), | |
363 uuid, | |
364 "A4", | |
365 true, | |
366 lVisible, | |
367 sVisible, | |
368 locale, | |
369 callContext | |
370 ); | |
371 } | |
372 else if (outputMode.equalsIgnoreCase("svg")) { | |
373 log.debug("Output mode == svg"); | |
374 | |
375 Locale[] serverLocales = | |
376 RessourceFactory.getInstance().getLocales(); | |
377 Locale locale = | |
378 callMeta.getPreferredLocale(serverLocales); | |
379 | |
380 log.debug( | |
381 "Best locale - regarding intersection of server and " + | |
382 "browser locales - is " + locale.toString() | |
383 ); | |
384 | |
385 createSVG( | |
386 outputStream, | |
387 getParameters(uuid), | |
388 getMeasurements(uuid), | |
389 getDates(uuid), | |
390 createChartLabels(locale, uuid), | |
391 uuid, | |
392 locale, | |
393 chartWidth, | |
394 chartHeight, | |
395 lVisible, | |
396 sVisible, | |
397 callContext | |
398 ); | |
399 } | 388 } |
400 else if (outputMode.equalsIgnoreCase("csv")) { | 389 else if (outputMode.equalsIgnoreCase("csv")) { |
401 log.debug("CSV-File will be generated."); | 390 log.debug("CSV-File will be generated."); |
402 Object result = getChartResult(uuid, callContext); | 391 Object result = getChartResult(uuid, callContext); |
403 if (result instanceof Collection) { | 392 if (result instanceof Collection) { |
412 | 401 |
413 Statistics s = getStatisticsGenerator(); | 402 Statistics s = getStatisticsGenerator(); |
414 Object result = getChartResult(uuid, callContext); | 403 Object result = getChartResult(uuid, callContext); |
415 | 404 |
416 if (result != null && s != null) { | 405 if (result != null && s != null) { |
417 Collection<KeyValueDescibeData> parameters = | |
418 getParameters(uuid); | |
419 | |
420 Collection<KeyValueDescibeData> measurements = | |
421 getMeasurements(uuid); | |
422 | |
423 Collection<KeyValueDescibeData> dates = | |
424 getDates(uuid); | |
425 | |
426 statistics = s.calculateStatistics( | 406 statistics = s.calculateStatistics( |
427 result, | 407 result, |
428 parameters, | 408 parameters, |
429 measurements, | 409 measurements, |
430 dates); | 410 dates); |