changeset 640:e5f1e868ee3e

Implementedr histogram pdf export. gnv-artifacts/trunk@726 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 03 Mar 2010 13:44:15 +0000
parents a94ed2755480
children 8d2bd52f05e3
files gnv-artifacts/ChangeLog gnv-artifacts/doc/conf/products/horizontalprofile/conf_instantaneouspoint.xml gnv-artifacts/doc/conf/products/horizontalprofile/conf_mesh.xml gnv-artifacts/doc/conf/products/horizontalprofile/conf_mesh_cross.xml gnv-artifacts/doc/conf/products/timeseries/conf_mesh.xml gnv-artifacts/doc/conf/products/timeseries/conf_timeseriespoint.xml gnv-artifacts/doc/conf/products/verticalprofile/conf_instantaneouspoint.xml gnv-artifacts/doc/conf/products/verticalprofile/conf_mesh.xml gnv-artifacts/doc/conf/products/verticalprofile/conf_timeseriespoint.xml gnv-artifacts/src/main/java/de/intevation/gnv/exports/ChartExportHelper.java gnv-artifacts/src/main/java/de/intevation/gnv/state/timeseries/TimeSeriesOutputState.java
diffstat 11 files changed, 99 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/gnv-artifacts/ChangeLog	Tue Mar 02 14:48:32 2010 +0000
+++ b/gnv-artifacts/ChangeLog	Wed Mar 03 13:44:15 2010 +0000
@@ -1,3 +1,21 @@
+2010-03-03  Ingo Weinzierl <ingo.weinzierl@intevation.de>
+
+	* src/main/java/de/intevation/gnv/state/timeseries/TimeSeriesOutputState.java:
+	  Trigger pdf creation for histograms when an 'out' call arrives with output
+	  mode 'histogram' and export mode 'pdf'.
+
+	* src/main/java/de/intevation/gnv/exports/ChartExportHelper.java:
+	  Implemented a method to export histograms as multipage pdf file.
+
+	* doc/conf/products/timeseries/conf_mesh.xml,
+	  doc/conf/products/horizontalprofile/conf_mesh.xml,
+	  doc/conf/products/horizontalprofile/conf_instantaneouspoint.xml,
+	  doc/conf/products/horizontalprofile/conf_mesh_cross.xml,
+	  doc/conf/products/verticalprofile/conf_mesh.xml,
+	  doc/conf/products/verticalprofile/conf_timeseriespoint.xml,
+	  doc/conf/products/verticalprofile/conf_instantaneouspoint.xml: Added pdf
+	  support for histogram charts.
+
 2010-03-02  Ingo Weinzierl <ingo.weinzierl@intevation.de>
 
 	* src/main/java/de/intevation/gnv/state/OutputStateBase.java: Added an xpath
--- a/gnv-artifacts/doc/conf/products/horizontalprofile/conf_instantaneouspoint.xml	Tue Mar 02 14:48:32 2010 +0000
+++ b/gnv-artifacts/doc/conf/products/horizontalprofile/conf_instantaneouspoint.xml	Wed Mar 03 13:44:15 2010 +0000
@@ -240,9 +240,7 @@
                     </parameters>
                     <exportModes>
                         <export name="img" description="IMG-Export der Daten" mime-type="image/png" />
-                        <!-- not implemented yet
                         <export name="pdf" description="PDF-Export der Daten" mime-type="application/pdf" />
-                        -->
                         <export name="svg" description="SVG-Export der Daten" mime-type="image/svg+xml" />
                     </exportModes>
                 </outputsMode>
--- a/gnv-artifacts/doc/conf/products/horizontalprofile/conf_mesh.xml	Tue Mar 02 14:48:32 2010 +0000
+++ b/gnv-artifacts/doc/conf/products/horizontalprofile/conf_mesh.xml	Wed Mar 03 13:44:15 2010 +0000
@@ -241,9 +241,7 @@
                     </parameters>
                     <exportModes>
                         <export name="img" description="IMG-Export der Daten" mime-type="image/png" />
-                        <!-- not implemented yet
                         <export name="pdf" description="PDF-Export der Daten" mime-type="application/pdf" />
-                        -->
                         <export name="svg" description="SVG-Export der Daten" mime-type="image/svg+xml" />
                     </exportModes>
                 </outputsMode>
--- a/gnv-artifacts/doc/conf/products/horizontalprofile/conf_mesh_cross.xml	Tue Mar 02 14:48:32 2010 +0000
+++ b/gnv-artifacts/doc/conf/products/horizontalprofile/conf_mesh_cross.xml	Wed Mar 03 13:44:15 2010 +0000
@@ -207,9 +207,7 @@
                     </parameters>
                     <exportModes>
                         <export name="img" description="IMG-Export der Daten" mime-type="image/png" />
-                        <!-- not implemented yet
                         <export name="pdf" description="PDF-Export der Daten" mime-type="application/pdf" />
-                        -->
                         <export name="svg" description="SVG-Export der Daten" mime-type="image/svg+xml" />
                     </exportModes>
                 </outputsMode>
--- a/gnv-artifacts/doc/conf/products/timeseries/conf_mesh.xml	Tue Mar 02 14:48:32 2010 +0000
+++ b/gnv-artifacts/doc/conf/products/timeseries/conf_mesh.xml	Wed Mar 03 13:44:15 2010 +0000
@@ -229,9 +229,7 @@
                     </parameters>
                     <exportModes>
                         <export name="img" description="IMG-Export der Daten" mime-type="image/png" />
-                        <!-- not yet implemented
                         <export name="pdf" description="PDF-Export der Daten" mime-type="application/pdf" />
-                        -->
                         <export name="svg" description="SVG-Export der Daten" mime-type="image/svg+xml" />
                     </exportModes>
                 </outputsMode>
--- a/gnv-artifacts/doc/conf/products/timeseries/conf_timeseriespoint.xml	Tue Mar 02 14:48:32 2010 +0000
+++ b/gnv-artifacts/doc/conf/products/timeseries/conf_timeseriespoint.xml	Wed Mar 03 13:44:15 2010 +0000
@@ -212,9 +212,7 @@
                     </parameters>
                     <exportModes>
                         <export name="img" description="IMG-Export der Daten" mime-type="image/png" />
-                        <!-- not yet implemented
                         <export name="pdf" description="PDF-Export der Daten" mime-type="application/pdf" />
-                        -->
                         <export name="svg" description="SVG-Export der Daten" mime-type="image/svg+xml" />
                     </exportModes>
                 </outputsMode>
--- a/gnv-artifacts/doc/conf/products/verticalprofile/conf_instantaneouspoint.xml	Tue Mar 02 14:48:32 2010 +0000
+++ b/gnv-artifacts/doc/conf/products/verticalprofile/conf_instantaneouspoint.xml	Wed Mar 03 13:44:15 2010 +0000
@@ -110,9 +110,7 @@
                 </outputsMode>
                 <exportModes>
                         <export name="img" description="IMG-Export der Daten" mime-type="image/png" />
-                        <!-- not implemented yet
                         <export name="pdf" description="PDF-Export der Daten" mime-type="application/pdf" />
-                        -->
                         <export name="svg" description="SVG-Export der Daten" mime-type="image/svg+xml" />
                     </exportModes>
              <outputsMode name="csv" description="CSV-Export der Daten" mime-type="text/plain"/>
--- a/gnv-artifacts/doc/conf/products/verticalprofile/conf_mesh.xml	Tue Mar 02 14:48:32 2010 +0000
+++ b/gnv-artifacts/doc/conf/products/verticalprofile/conf_mesh.xml	Wed Mar 03 13:44:15 2010 +0000
@@ -245,9 +245,7 @@
                     </parameters>
                     <exportModes>
                         <export name="img" description="IMG-Export der Daten" mime-type="image/png" />
-                        <!-- not implemented yet
                         <export name="pdf" description="PDF-Export der Daten" mime-type="application/pdf" />
-                        -->
                         <export name="svg" description="SVG-Export der Daten" mime-type="image/svg+xml" />
                     </exportModes>
                 </outputsMode>
--- a/gnv-artifacts/doc/conf/products/verticalprofile/conf_timeseriespoint.xml	Tue Mar 02 14:48:32 2010 +0000
+++ b/gnv-artifacts/doc/conf/products/verticalprofile/conf_timeseriespoint.xml	Wed Mar 03 13:44:15 2010 +0000
@@ -183,9 +183,7 @@
                     </parameters>
                     <exportModes>
                        <export name="img" description="IMG-Export der Daten" mime-type="image/png" />
-                       <!-- not implemented yet
                        <export name="pdf" description="PDF-Export der Daten" mime-type="application/pdf" />
-                       -->
                        <export name="svg" description="SVG-Export der Daten" mime-type="image/svg+xml" />
                     </exportModes>
                 </outputsMode>
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/exports/ChartExportHelper.java	Tue Mar 02 14:48:32 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/exports/ChartExportHelper.java	Wed Mar 03 13:44:15 2010 +0000
@@ -218,5 +218,79 @@
             document.close();
         }
     }
+
+
+    public static void exportHistogramsAsPDF(
+        OutputStream out,
+        Chart[]      histograms,
+        String       pageFormat,
+        boolean      landscape,
+        float        marginLeft,
+        float        marginRight,
+        float        marginTop,
+        float        marginBottom
+    ) {
+        log.info("export histogram as pdf.");
+
+        if (pageFormat == null)
+            pageFormat = DEFAULT_PAGE_SIZE;
+
+        Rectangle page = PageSize.getRectangle(pageFormat);
+        int pageWidth  =
+            (int) (page.getRight(marginRight) - page.getLeft(marginLeft));
+        int pageHeight =
+            (int) (page.getTop(marginTop) - page.getBottom(marginBottom));
+
+        Document document = null;
+        if (landscape) {
+            document = new Document(page.rotate());
+            log.debug("Create landscape pdf.");
+        }
+        else
+            document = new Document(page);
+
+        try {
+            PdfWriter writer = PdfWriter.getInstance(document, out);
+
+            document.addCreationDate();
+            document.open();
+
+            PdfContentByte content  = writer.getDirectContent();
+
+            int width  = 0;
+            int height = 0;
+            if (landscape) {
+                width  = pageHeight;
+                height = pageWidth;
+            }
+            else {
+                width  = pageWidth;
+                height = pageHeight;
+            }
+
+            int size = histograms.length;
+            for (int i = 0; i < size; i++) {
+                if (i > 0) {
+                    document.newPage();
+                }
+
+                JFreeChart chart     = histograms[i].generateChart();
+                PdfTemplate template = content.createTemplate(width, height);
+                Graphics2D  graphics = template.createGraphics(width, height);
+                Rectangle2D area     = new Rectangle2D.Double(
+                    0.0D, 0.0D,width,height);
+
+                chart.draw(graphics, area);
+                graphics.dispose();
+                content.addTemplate(template, marginLeft, marginBottom);
+            }
+        }
+        catch (DocumentException de) {
+            log.error("Error while exporting chart to pdf.", de);
+        }
+        finally {
+            document.close();
+        }
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/timeseries/TimeSeriesOutputState.java	Tue Mar 02 14:48:32 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/timeseries/TimeSeriesOutputState.java	Wed Mar 03 13:44:15 2010 +0000
@@ -374,7 +374,13 @@
                     );
                 }
                 else if (mode.equalsIgnoreCase("pdf")) {
-                    log.info("not implemented yet.");
+                    ChartExportHelper.exportHistogramsAsPDF(
+                        outputStream,
+                        histograms,
+                        "A4",
+                        PDF_FORMAT_LANDSCAPE,
+                        50F, 50F, 50F, 50F
+                    );
                 }
                 else if (mode.equalsIgnoreCase("svg")) {
                     ChartExportHelper.exportHistogramsAsSVG(

http://dive4elements.wald.intevation.org