changeset 492:79e80c289018

Added labels and titles to 'Profilschnitt' charts. gnv-artifacts/trunk@569 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 19 Jan 2010 10:06:03 +0000
parents cbb6b592bc6f
children cef17cc90fd0
files gnv-artifacts/ChangeLog gnv-artifacts/src/main/java/de/intevation/gnv/chart/ChartLabels.java gnv-artifacts/src/main/java/de/intevation/gnv/chart/VerticalCrossSectionChart.java gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/verticalcrosssection/VerticalCrossSectionOutputState.java gnv-artifacts/src/main/java/de/intevation/gnv/state/timeseries/TimeSeriesOutputState.java gnv-artifacts/src/main/resources/lang/artifactMessages.properties gnv-artifacts/src/main/resources/lang/artifactMessages_de.properties gnv-artifacts/src/main/resources/lang/artifactMessages_de_DE.properties gnv-artifacts/src/main/resources/lang/artifactMessages_en.properties
diffstat 9 files changed, 179 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/gnv-artifacts/ChangeLog	Mon Jan 18 15:49:12 2010 +0000
+++ b/gnv-artifacts/ChangeLog	Tue Jan 19 10:06:03 2010 +0000
@@ -1,3 +1,23 @@
+2010-01-19  Ingo Weinzierl <ingo.weinzierl@intevation.de>
+
+	* src/main/java/de/intevation/gnv/state/profile/verticalcrosssection/VerticalCrossSectionOutputState.java,
+	  src/main/java/de/intevation/gnv/state/timeseries/TimeSeriesOutputState.java:
+	  Sourced creation of a ChartLabel object out to an own method which can be
+	  overwritten in subclasses to adjust the labels in each chart type.
+	
+	* src/main/java/de/intevation/gnv/chart/ChartLabels.java: Added string for
+	  labeling y axis and a parameter used in 'Profilschnitten'.
+
+	* src/main/java/de/intevation/gnv/chart/VerticalCrossSectionChart.java: Read
+	  labels from ChartLabel object and set chart and axes titles according to
+	  these labels.
+	
+	* src/main/resources/lang/artifactMessages.properties,
+	  src/main/resources/lang/artifactMessages_de_DE.properties,
+	  src/main/resources/lang/artifactMessages_en.properties,
+	  src/main/resources/lang/artifactMessages_de.properties: Added labels for
+	  x and y axes of 'Profilschnitt' charts.
+
 2010-01-18  Ingo Weinzierl <ingo.weinzierl@intevation.de>
 
 	* src/main/java/de/intevation/gnv/artifacts/GNVDefaultArtifact.java: Add an
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/chart/ChartLabels.java	Mon Jan 18 15:49:12 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/chart/ChartLabels.java	Tue Jan 19 10:06:03 2010 +0000
@@ -15,6 +15,7 @@
 /**
  * @author drewnak
  * @author Tim Englich <tim.englich@intevation.de> Changes and codecleanup
+ * @author Ingo Weinzierl <ingo.weinzierl@intevation.de>
  */
 public class ChartLabels {
     /**
@@ -33,15 +34,48 @@
     private String domainAxisLabel;
 
     /**
+     *
+     */
+    private String rangeAxisLabel;
+
+    /**
+     *
+     */
+    private String parameterName;
+
+
+    /**
      * Constructor
      * 
      * @param title
      * @param domainAxisLabel
      */
     public ChartLabels(String title, String subtitle, String domainAxisLabel) {
+        this(title, subtitle, domainAxisLabel, null);
+    }
+
+    public ChartLabels(
+        String title,
+        String subtitle,
+        String domainAxisLabel,
+        String rangeAxisLabel
+    ) {
+        this(title, subtitle, domainAxisLabel, rangeAxisLabel, null);
+    }
+
+
+    public ChartLabels(
+        String title,
+        String subtitle,
+        String domainAxisLabel,
+        String rangeAxisLabel,
+        String parameterName
+    ) {
         this.title           = title;
         this.subtitle        = subtitle;
         this.domainAxisLabel = domainAxisLabel;
+        this.rangeAxisLabel  = rangeAxisLabel;
+        this.parameterName   = parameterName;
     }
 
     /**
@@ -65,4 +99,15 @@
     public String getDomainAxisLabel() {
         return this.domainAxisLabel;
     }
+
+
+    public String getRangeAxisLabel() {
+        return this.rangeAxisLabel;
+    }
+
+
+    public String getParameterName() {
+        return this.parameterName;
+    }
 }
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/chart/VerticalCrossSectionChart.java	Mon Jan 18 15:49:12 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/chart/VerticalCrossSectionChart.java	Tue Jan 19 10:06:03 2010 +0000
@@ -27,6 +27,7 @@
 import org.jfree.chart.axis.SymbolAxis;
 
 import org.jfree.chart.title.PaintScaleLegend;
+import org.jfree.chart.title.TextTitle;
 
 import org.jfree.chart.renderer.LookupPaintScale;
 
@@ -80,6 +81,7 @@
     protected AttributedXYColumns columns;
     protected Palette             palette;
     protected Locale              locale;
+    protected ChartLabels         labels;
 
     public VerticalCrossSectionChart() {
     }
@@ -87,21 +89,20 @@
     public VerticalCrossSectionChart(
         AttributedXYColumns columns,
         Palette             palette,
-        Locale              locale
+        Locale              locale,
+        ChartLabels         labels
     ) {
         this.columns = columns;
         this.palette = palette;
         this.locale  = locale;
+        this.labels  = labels;
     }
 
     protected JFreeChart createChart() {
 
-        String title        = "Neues 2D-Diagramm";
-        String xAxis        = "x-Achse des Diagramms";
-        String yAxis        = "y-Achse des Diagramms";
-        boolean legendB     = false;
-        boolean tooltips    = false;
-        boolean urls        = false;
+        boolean legendB  = false;
+        boolean tooltips = false;
+        boolean urls     = false;
 
         PlotOrientation po  = PlotOrientation.HORIZONTAL;
         PolygonDataset data = columns.getPolygonDataset();
@@ -124,8 +125,8 @@
             new PalettePaintLookup(palette),
             new LocalizedLabelGenerator(format));
 
-        ValueAxis domainAxis = new NumberAxis(xAxis);
-        ValueAxis rangeAxis  = new NumberAxis(yAxis);
+        ValueAxis domainAxis = new NumberAxis(this.labels.getDomainAxisLabel());
+        ValueAxis rangeAxis  = new NumberAxis(this.labels.getRangeAxisLabel());
 
         PolygonPlot plot = new PolygonPlot(
             data,
@@ -153,14 +154,15 @@
         }
 
         JFreeChart chart = new JFreeChart(
-            title,
+            this.labels.getTitle(),
             JFreeChart.DEFAULT_TITLE_FONT,
             plot,
             legendB);
 
         chart.removeLegend();
+        chart.addSubtitle(new TextTitle(this.labels.getSubtitle()));
 
-        SymbolAxis scale = new SymbolAxis("Temperatur", labels);
+        SymbolAxis scale = new SymbolAxis(this.labels.getParameterName(), labels);
         scale.setRange(-1.5d, labels.length+0.5d);
         scale.setGridBandsVisible(false);
         scale.setPlot(plot);
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/verticalcrosssection/VerticalCrossSectionOutputState.java	Mon Jan 18 15:49:12 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/verticalcrosssection/VerticalCrossSectionOutputState.java	Tue Jan 19 10:06:03 2010 +0000
@@ -35,6 +35,7 @@
 import de.intevation.gnv.artifacts.context.GNVArtifactContext;
 
 import de.intevation.gnv.artifacts.cache.CacheFactory;
+import de.intevation.gnv.artifacts.ressource.RessourceFactory;
 
 import de.intevation.gnv.chart.Chart;
 import de.intevation.gnv.chart.ChartLabels;
@@ -87,11 +88,13 @@
 
 /**
  * @author Tim Englich         (tim.englich@intevation.de)
- * @author Ingo Weinzierl      (iweinzierl@intevation.de)
+ * @author Ingo Weinzierl      (ingo.weinzierl@intevation.de)
  * @author Sascha L. Teichmann (sascha.teichmann@intevation.de)
  */
 public class VerticalCrossSectionOutputState extends TimeSeriesOutputState {
 
+    public static final String CHART_TYPE = "verticalcrosssection";
+
     public static final String[] ATTRIBUTE_LIST = {
         "SHAPE",
         "Z",
@@ -106,6 +109,8 @@
 
     private String ijkQueryID = "horizontalprofile_meshpoint_cross_ij";
 
+    private String rangeLabel;
+
     /**
      * The UID of this Class
      */
@@ -117,6 +122,41 @@
     public VerticalCrossSectionOutputState() {
         super();
         super.domainLable = "chart.verticalcrosssection.title.xaxis";
+        this.rangeLabel   = "chart.verticalcrosssection.title.yaxis";
+    }
+
+
+    @Override
+    protected ChartLabels createChartLabels(Locale locale, String uuid) {
+        RessourceFactory factory = RessourceFactory.getInstance();
+        String parameterName     = getSelectedInputDataName(
+            uuid, parameterValuesName);
+
+        if (parameterName == null)
+            parameterName = "parameterid";
+
+        return new ChartLabels(
+            createChartTitle(locale, uuid),
+            createChartSubtitle(locale, uuid),
+            factory.getRessource(locale, domainLable, domainLable),
+            factory.getRessource(locale, rangeLabel, rangeLabel),
+            parameterName
+        );
+    }
+
+
+    @Override
+    protected String createChartSubtitle(Locale locale, String uuid) {
+        String date = getSelectedInputDataName(uuid, dateValueName);
+
+        if (date == null)
+            date = "dateid";
+
+        RessourceFactory factory = RessourceFactory.getInstance();
+        String chartType         = factory.getRessource(
+            locale, CHART_TYPE, CHART_TYPE);
+
+        return chartType + ": " + date;
     }
 
 
@@ -183,6 +223,24 @@
         return obj;
     }
 
+
+    protected String getSelectedInputDataName(String uuid, String id) {
+        Collection values = getCollection(id, uuid);
+
+        if (values != null) {
+            Iterator it = values.iterator();
+
+            while (it.hasNext()) {
+                KeyValueDescibeData data = (KeyValueDescibeData) it.next();
+
+                if (data.isSelected()) {
+                    return data.getValue();
+                }
+            }
+        }
+        return null;
+    }
+
     private static int getGroundInterpolation(CallContext callContext) {
         GNVArtifactContext context = 
             (GNVArtifactContext)callContext.globalContext();
@@ -490,7 +548,8 @@
         chart = new VerticalCrossSectionChart(
             columns,
             paletteManager.getBase(),
-            locale);
+            locale,
+            chartLables);
 
         chart.generateChart();
 
@@ -502,6 +561,7 @@
         return chart;
     }
 
+
     /**
      * @see de.intevation.gnv.state.timeseries.TimeSeriesOutputState#createChart(java.io.OutputStream,
      *      java.util.Collection, java.util.Collection, java.lang.String,
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/timeseries/TimeSeriesOutputState.java	Mon Jan 18 15:49:12 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/timeseries/TimeSeriesOutputState.java	Tue Jan 19 10:06:03 2010 +0000
@@ -245,15 +245,7 @@
                 Collection measurements = this.getMeasurements(uuid);
                 Collection dates        = this.getDates(uuid);
 
-                ChartLabels chartLables = new ChartLabels(
-                    createChartTitle(locale, uuid),
-                    createChartSubtitle(locale, uuid),
-                    RessourceFactory.getInstance().getRessource(
-                        locale,
-                        domainLable,
-                        domainLable
-                    )
-                );
+                ChartLabels chartLables = createChartLabels(locale, uuid);
 
                 String exportFormat = getExportFormat(mimeType);
 
@@ -766,6 +758,18 @@
         return theme;
     }
 
+    protected ChartLabels createChartLabels(Locale locale, String uuid) {
+        return new ChartLabels(
+            createChartTitle(locale, uuid),
+            createChartSubtitle(locale, uuid),
+            RessourceFactory.getInstance().getRessource(
+                locale,
+                domainLable,
+                domainLable
+            )
+        );
+    }
+
 
     protected String createChartTitle(Locale locale, String uuid) {
         return getFisName(locale);
@@ -795,6 +799,24 @@
     }
 
 
+    protected String getSelectedInputDataName(String uuid, String key) {
+        Collection values = getCollection(key, uuid);
+
+        if (values != null) {
+            Iterator it = values.iterator();
+
+            while (it.hasNext()) {
+                KeyValueDescibeData data = (KeyValueDescibeData) it.next();
+
+                if (data.isSelected()) {
+                    return data.getValue();
+                }
+            }
+        }
+        return null;
+    }
+
+
     protected Collection<KeyValueDescibeData> getParameters(String uuid) {
         return this.getCollection(parameterValuesName, uuid);
     }
--- a/gnv-artifacts/src/main/resources/lang/artifactMessages.properties	Mon Jan 18 15:49:12 2010 +0000
+++ b/gnv-artifacts/src/main/resources/lang/artifactMessages.properties	Tue Jan 19 10:06:03 2010 +0000
@@ -57,6 +57,7 @@
 chart.timeseries.date.format=yyyy-MMM-dd
 chart.timeseries.title.xaxis=Time [UTC]
 chart.verticalprofile.title.xaxis=Depth [m]
-chart.verticalcrosssection.title.xaxis=Depth [m]
+chart.verticalcrosssection.title.xaxis=Distance [km]
+chart.verticalcrosssection.title.yaxis=Depth [m]
 chart.horizontalprofile.title.xaxis=Distance [km]
 chart.horizontalcrosssection.title.xaxis=Latitude [m]
--- a/gnv-artifacts/src/main/resources/lang/artifactMessages_de.properties	Mon Jan 18 15:49:12 2010 +0000
+++ b/gnv-artifacts/src/main/resources/lang/artifactMessages_de.properties	Tue Jan 19 10:06:03 2010 +0000
@@ -57,6 +57,7 @@
 chart.timeseries.date.format=dd-MMM-yyyy
 chart.timeseries.title.xaxis=Zeit [UTC]
 chart.verticalprofile.title.xaxis=Tiefe [m]
-chart.verticalcrosssection.title.xaxis=Tiefe [m]
+chart.verticalcrosssection.title.xaxis=Distanz [km]
+chart.verticalcrosssection.title.yaxis=Tiefe [m]
 chart.horizontalprofile.title.xaxis=Distanz [km]
 chart.horizontalcrosssection.title.xaxis=Ausdehnung [m]
--- a/gnv-artifacts/src/main/resources/lang/artifactMessages_de_DE.properties	Mon Jan 18 15:49:12 2010 +0000
+++ b/gnv-artifacts/src/main/resources/lang/artifactMessages_de_DE.properties	Tue Jan 19 10:06:03 2010 +0000
@@ -57,6 +57,7 @@
 chart.timeseries.date.format=dd-MMM-yyyy
 chart.timeseries.title.xaxis=Zeit [UTC]
 chart.verticalprofile.title.xaxis=Tiefe [m]
-chart.verticalcrosssection.title.xaxis=Tiefe [m]
+chart.verticalcrosssection.title.xaxis=Distanz [km]
+chart.verticalcrosssection.title.yaxis=Tiefe [m]
 chart.horizontalprofile.title.xaxis=Distanz [km]
 chart.horizontalcrosssection.title.xaxis=Ausdehnung [m]
--- a/gnv-artifacts/src/main/resources/lang/artifactMessages_en.properties	Mon Jan 18 15:49:12 2010 +0000
+++ b/gnv-artifacts/src/main/resources/lang/artifactMessages_en.properties	Tue Jan 19 10:06:03 2010 +0000
@@ -58,6 +58,7 @@
 chart.timeseries.date.format=yyyy-MMM-dd
 chart.timeseries.title.xaxis=Time [UTC]
 chart.verticalprofile.title.xaxis=Depth [m]
-chart.verticalcrosssection.title.xaxis=Depth [m]
+chart.verticalcrosssection.title.xaxis=Distance [km]
+chart.verticalcrosssection.title.yaxis=Depth [m]
 chart.horizontalprofile.title.xaxis=Distance [km]
 chart.horizontalcrosssection.title.xaxis=Latitude [m]

http://dive4elements.wald.intevation.org