changeset 7047:b5e9b8b5c8d6

issue1493: Use other numberformat for csv data from diagram.
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Thu, 19 Sep 2013 09:16:52 +0200
parents 50b9959330de
children 3a55f49be155
files artifacts/src/main/java/org/dive4elements/river/exports/ChartExportHelper.java artifacts/src/main/java/org/dive4elements/river/utils/Formatter.java
diffstat 2 files changed, 25 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/exports/ChartExportHelper.java	Wed Sep 18 18:40:52 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/ChartExportHelper.java	Thu Sep 19 09:16:52 2013 +0200
@@ -305,6 +305,9 @@
             log.warn("Wrong encoding for CSV export.");
             return;
         }
+
+        NumberFormat format = Formatter.getCSVFormatter(context);
+
         XYPlot plot = chart.getXYPlot();
         int count = plot.getDatasetCount();
         for (int i = 0; i < count; i++) {
@@ -314,7 +317,7 @@
                 Comparable seriesKey = data.getSeriesKey(j);
                 log.debug("series key: " + seriesKey.toString());
                 writeCSVHeader(writer, seriesKey.toString());
-                writeCSVData(writer, data, context);
+                writeCSVData(writer, data, format);
             }
         }
         try {
@@ -334,19 +337,18 @@
     }
 
 
-    protected static void writeCSVData(CSVWriter writer, XYDataset data, CallContext context) {
+    /** Get x/y data from axis set and write it, on pair per line. */
+    protected static void writeCSVData(
+        CSVWriter writer, XYDataset data, NumberFormat format) {
         int series = data.getSeriesCount();
-        // TODO: Instantiate at other place, use
-        // better formatter.
-        NumberFormat numberFormat = Formatter.getWaterlevelW(context);
         for (int i = 0; i < series; i++) {
             int items = data.getItemCount(i);
             for (int j = 0; j < items; j++) {
                 log.debug("write data: " + data.getX(i, j) + ", " + data.getY(i, j));
                 try {
                     writer.writeNext(new String[] {
-                        numberFormat.format(data.getX(i, j)),
-                        numberFormat.format(data.getY(i, j))});
+                        format.format(data.getX(i, j)),
+                        format.format(data.getY(i, j))});
                 }
                 catch (NumberFormatException nfe) {
                     writer.writeNext(new String[] {
--- a/artifacts/src/main/java/org/dive4elements/river/utils/Formatter.java	Wed Sep 18 18:40:52 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/utils/Formatter.java	Thu Sep 19 09:16:52 2013 +0200
@@ -99,6 +99,10 @@
     public static final int SQ_RELATION_B_MAX_DIGITS  = 3;
     public static final int SQ_RELATION_B_MIN_DIGITS  = 3;
 
+    // OTHER
+    public static final int CSV_DIAGRAM_DATA_MAX_DIGITS  = 3;
+    public static final int CSV_DIAGRAM_DATA_MIN_DIGITS  = 3;
+
     /**
      * Creates a localized NumberFormatter with given range of decimal digits.
      * @param m CallMeta to find the locale.
@@ -191,6 +195,18 @@
                 WATERLEVEL_KM_MAX_DIGITS);
     }
 
+    /**
+     * Returns the number formatter for data exported from diagram (not from
+     * calculation.
+     *
+     * @return the number formatter for csv data from diagra.
+     */
+    public static NumberFormat getCSVFormatter(CallContext context) {
+        return getFormatter(
+                context,
+                CSV_DIAGRAM_DATA_MIN_DIGITS,
+                CSV_DIAGRAM_DATA_MAX_DIGITS);
+    }
 
     public static NumberFormat getWaterlevelW(CallMeta meta) {
         return getFormatter(

http://dive4elements.wald.intevation.org