Mercurial > dive4elements > river
diff 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 |
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java Tue Dec 27 10:12:14 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java Tue Dec 27 11:19:44 2011 +0000 @@ -44,14 +44,16 @@ import org.jfree.ui.RectangleInsets; +import de.intevation.artifacts.CallContext; + import de.intevation.artifactdatabase.state.Facet; -import de.intevation.flys.jfree.StableXYDifferenceRenderer; import de.intevation.artifactdatabase.state.Section; import de.intevation.artifactdatabase.state.Settings; import de.intevation.flys.exports.ChartExportHelper; import de.intevation.flys.jfree.FLYSAnnotation; +import de.intevation.flys.jfree.StableXYDifferenceRenderer; import de.intevation.flys.jfree.StickyAxisAnnotation; import de.intevation.flys.utils.ThemeAccess; @@ -399,6 +401,30 @@ /** + * This method returns the export dimension specified in ChartSettings as + * int array [width,height]. + * + * @return an int array with [width,height]. + */ + protected int[] getExportDimension() { + ChartSettings chartSettings = getChartSettings(); + if (chartSettings == null) { + return new int[] { 600, 400 }; + } + + ExportSection export = chartSettings.getExportSection(); + Integer width = export.getWidth(); + Integer height = export.getHeight(); + + if (width != null && height != null) { + return new int[] { width, height }; + } + + return new int[] { 600, 400 }; + } + + + /** * Generate chart. */ public void generate() @@ -411,6 +437,10 @@ String format = getFormat(); int[] size = getSize(); + if (size == null) { + size = getExportDimension(); + } + context.putContextValue("chart.width", size[0]); context.putContextValue("chart.height", size[1]); @@ -423,13 +453,7 @@ context); } else if (format.equals(ChartExportHelper.FORMAT_PDF)) { - context.putContextValue("chart.marginLeft", 5f); - context.putContextValue("chart.marginRight", 5f); - context.putContextValue("chart.marginTop", 5f); - context.putContextValue("chart.marginBottom", 5f); - context.putContextValue( - "chart.page.format", - ChartExportHelper.DEFAULT_PAGE_SIZE); + preparePDFContext(context); ChartExportHelper.exportPDF( out, @@ -437,9 +461,7 @@ context); } else if (format.equals(ChartExportHelper.FORMAT_SVG)) { - context.putContextValue( - "chart.encoding", - ChartExportHelper.DEFAULT_ENCODING); + prepareSVGContext(context); ChartExportHelper.exportSVG( out, @@ -492,6 +514,32 @@ } + protected void preparePDFContext(CallContext context) { + int[] dimension = getExportDimension(); + + context.putContextValue("chart.width", dimension[0]); + context.putContextValue("chart.height", dimension[1]); + context.putContextValue("chart.marginLeft", 5f); + context.putContextValue("chart.marginRight", 5f); + context.putContextValue("chart.marginTop", 5f); + context.putContextValue("chart.marginBottom", 5f); + context.putContextValue( + "chart.page.format", + ChartExportHelper.DEFAULT_PAGE_SIZE); + } + + + protected void prepareSVGContext(CallContext context) { + int[] dimension = getExportDimension(); + + context.putContextValue("chart.width", dimension[0]); + context.putContextValue("chart.height", dimension[1]); + context.putContextValue( + "chart.encoding", + ChartExportHelper.DEFAULT_ENCODING); + } + + /** * Put debug output about datasets. */