changeset 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 f97cf2e350c9
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/exports/ChartGenerator.java flys-artifacts/src/main/java/de/intevation/flys/exports/ChartInfoGenerator.java flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java
diffstat 4 files changed, 81 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- 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 <ingo@intevation.de>
+
+	* 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 <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/exports/TypeSection.java: New. This
--- 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;
     }
 
 
--- 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();
 
--- 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.
      */

http://dive4elements.wald.intevation.org