changeset 1080:01e26528bb39

Some code refactoring for the implementation of histograms using vectorial parameters. gnv-artifacts/trunk@1182 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 09 Jun 2010 09:37:57 +0000
parents 1657ee3ac054
children 846b2b70b2e0
files gnv-artifacts/ChangeLog gnv-artifacts/src/main/java/de/intevation/gnv/histogram/HistogramHelper.java gnv-artifacts/src/main/java/de/intevation/gnv/state/timeseries/TimeSeriesOutputState.java
diffstat 3 files changed, 68 insertions(+), 37 deletions(-) [+]
line wrap: on
line diff
--- a/gnv-artifacts/ChangeLog	Wed Jun 09 07:38:40 2010 +0000
+++ b/gnv-artifacts/ChangeLog	Wed Jun 09 09:37:57 2010 +0000
@@ -1,3 +1,13 @@
+2010-06-09  Ingo Weinzierl <ingo.weinzierl@intevation.de>
+
+	* src/main/java/de/intevation/gnv/state/timeseries/TimeSeriesOutputState.java:
+	  Seperated the histogram creation into an own method. This enables
+	  subclasses to override the histogram creation. Moved the method
+	  createHistogramLabels(.) to HistogramHelper.
+
+	* src/main/java/de/intevation/gnv/histogram/HistogramHelper.java:
+	  New method to create histogram labels (moved from TimeSeriesOutputState).
+
 2010-06-09  Ingo Weinzierl <ingo.weinzierl@intevation.de>
 
 	* src/main/java/de/intevation/gnv/statistics/VerticalProfileVectorStatistics.java:
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/histogram/HistogramHelper.java	Wed Jun 09 07:38:40 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/histogram/HistogramHelper.java	Wed Jun 09 09:37:57 2010 +0000
@@ -215,5 +215,26 @@
         }
         return "";
     }
+
+
+    /**
+     * Creates and returns labels to decorate histograms.
+     *
+     * @param uuid The UUID of the current artifact.
+     * @param context The CallContext object.
+     * @param data An array storing strings.
+     * @return A ChartLabels object with the 1st string in <i>data</i> as title.
+     */
+    public static ChartLabels createHistogramLabels(
+        String uuid, CallContext context, Locale locale, Object[] data)
+    {
+        RessourceFactory fac = RessourceFactory.getInstance();
+
+        return new ChartLabels(
+            (String) data[0],
+            "",
+            "",
+            fac.getRessource(locale, "histogram.axis.range.title", ""));
+    }
 }
 // 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	Wed Jun 09 07:38:40 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/timeseries/TimeSeriesOutputState.java	Wed Jun 09 09:37:57 2010 +0000
@@ -402,24 +402,15 @@
             }
             // HISTOGRAM
             else if (outputMode.equalsIgnoreCase("histogram")) {
-                Collection results = (Collection) getChartResult(uuid, callContext);
                 requestParameter.put("locale", locale);
 
-                Object[][] data = HistogramHelper.prepareHistogramData(
-                    results, parameters, measurements, dates);
-
-                int size           = data.length;
-                Chart[] histograms = new Chart[size];
-
-                for (int i = 0; i < size; i++) {
-                    ChartLabels labels = createHistogramLabels(
-                        uuid, callContext, locale, data[i]);
-
-                    ChartTheme theme   = createStyle(callContext);
-
-                    histograms[i] = new DefaultHistogram(
-                        labels, data[i], theme, requestParameter);
-                }
+                Chart[] histograms = getHistograms(
+                    uuid,
+                    callContext,
+                    parameters,
+                    measurements,
+                    dates,
+                    requestParameter);
 
                 if (mode.equalsIgnoreCase("img")) {
                     ChartExportHelper.exportHistograms(
@@ -500,6 +491,36 @@
     }
 
 
+    protected Chart[] getHistograms(
+        String      uuid,
+        CallContext callContext,
+        Collection<KeyValueDescibeData>  parameters,
+        Collection<KeyValueDescibeData>  measurements,
+        Collection<KeyValueDescibeData>  dates,
+        Map         requestParameter
+    ) {
+        Locale locale = (Locale) requestParameter.get("locale");
+
+        Collection results = (Collection) getChartResult(uuid, callContext);
+        ChartTheme theme   = createStyle(callContext);
+
+        Object[][] data = HistogramHelper.prepareHistogramData(
+            results, parameters, measurements, dates);
+
+        int size           = data.length;
+        Chart[] histograms = new Chart[size];
+
+        for (int i = 0; i < size; i++) {
+            ChartLabels labels = HistogramHelper.createHistogramLabels(
+                uuid, callContext, locale, data[i]);
+
+            histograms[i] = new DefaultHistogram(
+                labels, data[i], theme, requestParameter);
+        }
+
+        return histograms;
+    }
+
     /**
      * @param outputStream
      * @param uuid
@@ -1101,27 +1122,6 @@
 
 
     /**
-     * Creates and returns labels to decorate histograms.
-     *
-     * @param uuid The UUID of the current artifact.
-     * @param context The CallContext object.
-     * @param data An array storing strings.
-     * @return A ChartLabels object with the 1st string in <i>data</i> as title.
-     */
-    protected ChartLabels createHistogramLabels(
-        String uuid, CallContext context, Locale locale, Object[] data)
-    {
-        RessourceFactory fac = RessourceFactory.getInstance();
-
-        return new ChartLabels(
-            (String) data[0],
-            "",
-            "",
-            fac.getRessource(locale, "histogram.axis.range.title", ""));
-    }
-
-
-    /**
      * Returns the selected fis name.
      *
      * @param locale The Locale object used to adjust the language.

http://dive4elements.wald.intevation.org