# HG changeset patch # User Ingo Weinzierl # Date 1276076277 0 # Node ID 01e26528bb39b8fbf399aa83c916003816131580 # Parent 1657ee3ac0544e9df32c915f9822d47fa4603480 Some code refactoring for the implementation of histograms using vectorial parameters. gnv-artifacts/trunk@1182 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 1657ee3ac054 -r 01e26528bb39 gnv-artifacts/ChangeLog --- 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 + + * 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 * src/main/java/de/intevation/gnv/statistics/VerticalProfileVectorStatistics.java: diff -r 1657ee3ac054 -r 01e26528bb39 gnv-artifacts/src/main/java/de/intevation/gnv/histogram/HistogramHelper.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 data 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 : diff -r 1657ee3ac054 -r 01e26528bb39 gnv-artifacts/src/main/java/de/intevation/gnv/state/timeseries/TimeSeriesOutputState.java --- 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 parameters, + Collection measurements, + Collection 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 data 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.