# HG changeset patch # User Ingo Weinzierl # Date 1324984784 0 # Node ID 49b7c2b1a6a7bb3b34b627cebbac0dab8e03f928 # Parent 76eeb3b4358ebf5e2690f975c23601051d1f7a77 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 diff -r 76eeb3b4358e -r 49b7c2b1a6a7 flys-artifacts/ChangeLog --- a/flys-artifacts/ChangeLog Tue Dec 27 10:12:14 2011 +0000 +++ b/flys-artifacts/ChangeLog Tue Dec 27 11:19:44 2011 +0000 @@ -1,3 +1,19 @@ +2011-12-27 Ingo Weinzierl + + * src/main/java/de/intevation/flys/exports/ChartGenerator.java: The + getSize() method now returns null if no width and height is specified in + the request document or if width/height <= 0. It no longer returns the + result of getDefaultSize(). + + * src/main/java/de/intevation/flys/exports/XYChartGenerator.java: Set the + size of a chart export to the size specified in the ChartSettings if + there are no valid values in the request document. + + * src/main/java/de/intevation/flys/exports/ChartInfoGenerator.java: Set the + chart size to ChartGenerator.getDefaultSize() if no valid values are + returned by ChartGenerator.getSize(). This has been done autoamtically + before. + 2011-12-27 Ingo Weinzierl * src/main/java/de/intevation/flys/exports/TypeSection.java: New. This diff -r 76eeb3b4358e -r 49b7c2b1a6a7 flys-artifacts/src/main/java/de/intevation/flys/exports/ChartGenerator.java --- a/flys-artifacts/src/main/java/de/intevation/flys/exports/ChartGenerator.java Tue Dec 27 10:12:14 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/ChartGenerator.java Tue Dec 27 11:19:44 2011 +0000 @@ -233,8 +233,8 @@ * Returns the size of a chart export as array which has been specified by * the incoming request document. * - * @return the size of a chart as [width, height] or the result of - * getDefaultSize() if no width or height are given in the request document. + * @return the size of a chart as [width, height] or null if no width or + * height are given in the request document. */ protected int[] getSize() { int[] size = new int[2]; @@ -262,7 +262,7 @@ } } - return size[0] > 0 && size[1] > 0 ? size : getDefaultSize(); + return size[0] > 0 && size[1] > 0 ? size : null; } diff -r 76eeb3b4358e -r 49b7c2b1a6a7 flys-artifacts/src/main/java/de/intevation/flys/exports/ChartInfoGenerator.java --- a/flys-artifacts/src/main/java/de/intevation/flys/exports/ChartInfoGenerator.java Tue Dec 27 10:12:14 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/ChartInfoGenerator.java Tue Dec 27 11:19:44 2011 +0000 @@ -110,6 +110,9 @@ JFreeChart chart = generator.generateChart(); int[] size = generator.getSize(); + if (size == null) { + size = generator.getDefaultSize(); + } ChartRenderingInfo info = new ChartRenderingInfo(); diff -r 76eeb3b4358e -r 49b7c2b1a6a7 flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java --- 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. */