comparison flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java @ 2057:49b7c2b1a6a7

Make use of the export size for charts specified in ChartSettings if a chart export is requested. flys-artifacts/trunk@3549 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 27 Dec 2011 11:19:44 +0000
parents 76eeb3b4358e
children 4cdd9c4896f6
comparison
equal deleted inserted replaced
2056:76eeb3b4358e 2057:49b7c2b1a6a7
42 import org.jfree.data.xy.XYSeriesCollection; 42 import org.jfree.data.xy.XYSeriesCollection;
43 import org.jfree.data.xy.XYDataset; 43 import org.jfree.data.xy.XYDataset;
44 44
45 import org.jfree.ui.RectangleInsets; 45 import org.jfree.ui.RectangleInsets;
46 46
47 import de.intevation.artifacts.CallContext;
48
47 import de.intevation.artifactdatabase.state.Facet; 49 import de.intevation.artifactdatabase.state.Facet;
48 import de.intevation.flys.jfree.StableXYDifferenceRenderer;
49 import de.intevation.artifactdatabase.state.Section; 50 import de.intevation.artifactdatabase.state.Section;
50 import de.intevation.artifactdatabase.state.Settings; 51 import de.intevation.artifactdatabase.state.Settings;
51 52
52 53
53 import de.intevation.flys.exports.ChartExportHelper; 54 import de.intevation.flys.exports.ChartExportHelper;
54 import de.intevation.flys.jfree.FLYSAnnotation; 55 import de.intevation.flys.jfree.FLYSAnnotation;
56 import de.intevation.flys.jfree.StableXYDifferenceRenderer;
55 import de.intevation.flys.jfree.StickyAxisAnnotation; 57 import de.intevation.flys.jfree.StickyAxisAnnotation;
56 58
57 import de.intevation.flys.utils.ThemeAccess; 59 import de.intevation.flys.utils.ThemeAccess;
58 60
59 /** 61 /**
397 return fontSize != null ? fontSize : DEFAULT_FONT_SIZE; 399 return fontSize != null ? fontSize : DEFAULT_FONT_SIZE;
398 } 400 }
399 401
400 402
401 /** 403 /**
404 * This method returns the export dimension specified in ChartSettings as
405 * int array [width,height].
406 *
407 * @return an int array with [width,height].
408 */
409 protected int[] getExportDimension() {
410 ChartSettings chartSettings = getChartSettings();
411 if (chartSettings == null) {
412 return new int[] { 600, 400 };
413 }
414
415 ExportSection export = chartSettings.getExportSection();
416 Integer width = export.getWidth();
417 Integer height = export.getHeight();
418
419 if (width != null && height != null) {
420 return new int[] { width, height };
421 }
422
423 return new int[] { 600, 400 };
424 }
425
426
427 /**
402 * Generate chart. 428 * Generate chart.
403 */ 429 */
404 public void generate() 430 public void generate()
405 throws IOException 431 throws IOException
406 { 432 {
409 JFreeChart chart = generateChart(); 435 JFreeChart chart = generateChart();
410 436
411 String format = getFormat(); 437 String format = getFormat();
412 int[] size = getSize(); 438 int[] size = getSize();
413 439
440 if (size == null) {
441 size = getExportDimension();
442 }
443
414 context.putContextValue("chart.width", size[0]); 444 context.putContextValue("chart.width", size[0]);
415 context.putContextValue("chart.height", size[1]); 445 context.putContextValue("chart.height", size[1]);
416 446
417 if (format.equals(ChartExportHelper.FORMAT_PNG)) { 447 if (format.equals(ChartExportHelper.FORMAT_PNG)) {
418 context.putContextValue("chart.image.format", "png"); 448 context.putContextValue("chart.image.format", "png");
421 out, 451 out,
422 chart, 452 chart,
423 context); 453 context);
424 } 454 }
425 else if (format.equals(ChartExportHelper.FORMAT_PDF)) { 455 else if (format.equals(ChartExportHelper.FORMAT_PDF)) {
426 context.putContextValue("chart.marginLeft", 5f); 456 preparePDFContext(context);
427 context.putContextValue("chart.marginRight", 5f);
428 context.putContextValue("chart.marginTop", 5f);
429 context.putContextValue("chart.marginBottom", 5f);
430 context.putContextValue(
431 "chart.page.format",
432 ChartExportHelper.DEFAULT_PAGE_SIZE);
433 457
434 ChartExportHelper.exportPDF( 458 ChartExportHelper.exportPDF(
435 out, 459 out,
436 chart, 460 chart,
437 context); 461 context);
438 } 462 }
439 else if (format.equals(ChartExportHelper.FORMAT_SVG)) { 463 else if (format.equals(ChartExportHelper.FORMAT_SVG)) {
440 context.putContextValue( 464 prepareSVGContext(context);
441 "chart.encoding",
442 ChartExportHelper.DEFAULT_ENCODING);
443 465
444 ChartExportHelper.exportSVG( 466 ChartExportHelper.exportSVG(
445 out, 467 out,
446 chart, 468 chart,
447 context); 469 context);
487 localizeAxes(plot); 509 localizeAxes(plot);
488 adjustAxes(plot); 510 adjustAxes(plot);
489 autoZoom(plot); 511 autoZoom(plot);
490 512
491 return chart; 513 return chart;
514 }
515
516
517 protected void preparePDFContext(CallContext context) {
518 int[] dimension = getExportDimension();
519
520 context.putContextValue("chart.width", dimension[0]);
521 context.putContextValue("chart.height", dimension[1]);
522 context.putContextValue("chart.marginLeft", 5f);
523 context.putContextValue("chart.marginRight", 5f);
524 context.putContextValue("chart.marginTop", 5f);
525 context.putContextValue("chart.marginBottom", 5f);
526 context.putContextValue(
527 "chart.page.format",
528 ChartExportHelper.DEFAULT_PAGE_SIZE);
529 }
530
531
532 protected void prepareSVGContext(CallContext context) {
533 int[] dimension = getExportDimension();
534
535 context.putContextValue("chart.width", dimension[0]);
536 context.putContextValue("chart.height", dimension[1]);
537 context.putContextValue(
538 "chart.encoding",
539 ChartExportHelper.DEFAULT_ENCODING);
492 } 540 }
493 541
494 542
495 /** 543 /**
496 * Put debug output about datasets. 544 * Put debug output about datasets.

http://dive4elements.wald.intevation.org