diff flys-artifacts/src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java @ 1931:7c52e9cb2a72

Allow more than two datasets and more flexibility with axes in plots. Based on patch by S. Teichmann. flys-artifacts/trunk@3312 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Thu, 24 Nov 2011 07:20:46 +0000
parents 11c4b1429117
children 0ad05cb691fc
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java	Wed Nov 23 14:09:29 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java	Thu Nov 24 07:20:46 2011 +0000
@@ -39,6 +39,16 @@
 extends      XYChartGenerator
 implements   FacetTypes
 {
+    public static enum YAXIS {
+        W(0),
+        Q(1),
+        D(2);
+        protected int idx;
+        private YAXIS(int c) {
+           idx = c;
+        }
+    }
+
     /** The logger that is used in this generator. */
     private static Logger logger =
         Logger.getLogger(LongitudinalSectionGenerator.class);
@@ -161,6 +171,29 @@
 
 
     /**
+     * Create Axis for given index.
+     * @return axis with according internationalized label.
+     */
+    @Override
+    protected NumberAxis createYAxis(int index) {
+        Font labelFont = new Font("Tahoma", Font.BOLD, 14);
+        String label = "default";
+        if (index == YAXIS.W.idx) {
+            label = getYAxisLabel();
+        }
+        else if (index == YAXIS.Q.idx) {
+            label = msg(get2YAxisLabelKey(), get2YAxisDefaultLabel());
+        }
+        else if (index == YAXIS.D.idx) {
+            // TODO: diff label
+            label = "TODO: diff";
+        }
+        NumberAxis axis = new NumberAxis(label);
+        axis.setLabelFont(labelFont);
+        return axis;
+    }
+
+    /**
      * Get default value for the second Y-Axis' label (if no translation was
      * found).
      */
@@ -178,23 +211,11 @@
 
 
     /**
-     * Adjust the axis to meet LongitudinalSection diagram demands.
-     * (e.g. add second Y-axis with internationalized label, trigger
-     * inversion).
-     * @param see get2YAxisLabelKey, get2YAxisDefaultLabel
+     * Trigger inversion.
      */
     @Override
     protected void adjustAxes(XYPlot plot) {
         super.adjustAxes(plot);
-
-        NumberAxis qAxis = new NumberAxis(
-            msg(get2YAxisLabelKey(), get2YAxisDefaultLabel()));
-
-        plot.setRangeAxis(1, qAxis);
-
-        Font font = plot.getRangeAxis(0).getLabelFont();
-        qAxis.setLabelFont(font);
-
         invertXAxis(plot.getDomainAxis());
     }
 
@@ -321,7 +342,7 @@
 
         StyledSeriesBuilder.addPoints(series, wkms);
 
-        addFirstAxisSeries(series, visible);
+        addAxisSeries(series, YAXIS.W.idx, visible);
 
         if (wkms instanceof WQKms) {
             if (needInvertAxis((WQKms) wkms)) {
@@ -359,7 +380,7 @@
 
         StyledSeriesBuilder.addPoints(series, wkms);
 
-        addSecondAxisSeries(series, visible);
+        addAxisSeries(series, YAXIS.D.idx, visible);
         if (DataUtil.guessWaterIncreasing(wkms.allWs())) {
             setInverted(true);
         }
@@ -389,7 +410,7 @@
 
         StyledSeriesBuilder.addPoints(series, wqkms);
 
-        addSecondAxisSeries(series, visible);
+        addAxisSeries(series, YAXIS.Q.idx, visible);
 
         if (needInvertAxis(wqkms)) {
             setInverted(true);

http://dive4elements.wald.intevation.org