diff flys-artifacts/src/main/java/de/intevation/flys/exports/TimeseriesChartGenerator.java @ 3984:89d7e97e9c9a

Manual points working in fixing Delta W/t char (#462).
author Christian Lins <clins@intevation.de>
date Sat, 29 Sep 2012 20:09:27 +0200
parents 8490faba00e7
children 7cc05da7e35c
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/TimeseriesChartGenerator.java	Sat Sep 29 11:38:38 2012 +0200
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/TimeseriesChartGenerator.java	Sat Sep 29 20:09:27 2012 +0200
@@ -1,6 +1,7 @@
 package de.intevation.flys.exports;
 
 import de.intevation.artifactdatabase.state.ArtifactAndFacet;
+import de.intevation.flys.artifacts.resources.Resources;
 import de.intevation.flys.jfree.Bounds;
 import de.intevation.flys.jfree.CollisionFreeXYTextAnnotation;
 import de.intevation.flys.jfree.DoubleBounds;
@@ -10,6 +11,8 @@
 
 import java.awt.Color;
 import java.awt.Font;
+import java.text.DateFormat;
+import java.text.ParseException;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.HashMap;
@@ -656,6 +659,20 @@
     }
 
 
+    protected Date decodeXAxisValue(JSONArray array) throws JSONException, ParseException {
+        try {
+            double x = array.getDouble(0);
+            long l = (new Double(x)).longValue();
+            return new Date(l);
+        }
+        catch(JSONException ex) {
+            String str = array.getString(0);
+            DateFormat df = DateFormat.getDateInstance(
+                    DateFormat.MEDIUM, Resources.getLocale(context.getMeta()));
+            return df.parse(str);
+        }
+    }
+
     /**
      * Do Points out.
      */
@@ -677,22 +694,26 @@
             JSONArray points = new JSONArray((String) o);
             for (int i = 0, P = points.length(); i < P; i++) {
                 JSONArray array = points.getJSONArray(i);
-                double x    = array.getDouble(0);
+
                 double y    = array.getDouble(1);
                 String name = array.getString(2);
                 boolean act = array.getBoolean(3);
                 if (!act) {
                     continue;
                 }
-                long l = (new Double(x)).longValue();
-                Date date = new Date(l);
+
+                Date date = decodeXAxisValue(array);
+
                 Day day = new Day(date);
                 series.add(day, y, false);
                 names.put(day, name);
             }
         }
-        catch(JSONException e){
-            logger.error("Could not decode json.");
+        catch(JSONException ex) {
+            logger.error("Could not decode json");
+        }
+        catch(ParseException ex) {
+            logger.error("Could not parse date string");
         }
 
         TimeSeriesCollection tsc = new TimeSeriesCollection();
@@ -703,6 +724,7 @@
             double y = tsc.getYValue(0, i);
             xy.add(new CollisionFreeXYTextAnnotation(
                        names.get(series.getTimePeriod(i)), x, y));
+            logger.debug("doPoints(): x=" + x + " y=" + y);
         }
         FLYSAnnotation annotations =
             new FLYSAnnotation(null, null, null, theme);

http://dive4elements.wald.intevation.org