changeset 6467:0f997d6397c6

FixWQCurveGenerator: Introduce second (cm) axis.
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Thu, 27 Jun 2013 10:44:31 +0200
parents cf514239d290
children 5de3388c5978
files artifacts/src/main/java/org/dive4elements/river/exports/fixings/FixWQCurveGenerator.java
diffstat 1 files changed, 65 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/exports/fixings/FixWQCurveGenerator.java	Thu Jun 27 10:42:57 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/fixings/FixWQCurveGenerator.java	Thu Jun 27 10:44:31 2013 +0200
@@ -10,6 +10,7 @@
 
 import java.awt.BasicStroke;
 import java.awt.Color;
+import java.awt.Font;
 import java.text.DateFormat;
 import java.util.ArrayList;
 import java.util.List;
@@ -17,6 +18,7 @@
 import org.apache.log4j.Logger;
 import org.jfree.chart.JFreeChart;
 import org.jfree.chart.annotations.XYTextAnnotation;
+import org.jfree.chart.axis.NumberAxis;
 import org.jfree.chart.plot.Marker;
 import org.jfree.chart.plot.ValueMarker;
 import org.jfree.chart.title.TextTitle;
@@ -44,6 +46,8 @@
 import org.dive4elements.river.artifacts.model.fixings.QWI;
 import org.dive4elements.river.artifacts.resources.Resources;
 import org.dive4elements.river.exports.ChartGenerator;
+import org.dive4elements.river.exports.DischargeCurveGenerator;
+import org.dive4elements.river.exports.SyncNumberAxis;
 import org.dive4elements.river.exports.StyledSeriesBuilder;
 import org.dive4elements.river.jfree.CollisionFreeXYTextAnnotation;
 import org.dive4elements.river.jfree.RiverAnnotation;
@@ -94,7 +98,8 @@
     public static final double EPSILON = 0.001d;
 
     public static enum YAXIS {
-        W(0);
+        WCm(0),
+        W(1);
         public int idx;
         private YAXIS(int c) {
             idx = c;
@@ -105,6 +110,58 @@
     /** Needed to access data to create subtitle. */
     protected D4EArtifact artifact;
 
+    // TODO dupe of ComputedDischargeCurveGenerator
+    protected SyncNumberAxis secondYAxis;
+    // TODO dupe of ComputedDischargeCurveGenerator
+    protected NumberAxis firstYAxis;
+
+
+    /**
+     * Create Y (range) axis for given index, here with a special axis
+     * that depends on other axis (does translation and scaling for
+     * special case at gauge in cm).
+     */
+    // TODO dupe of ComputedDischargeCurveGenerator
+    @Override
+    protected NumberAxis createYAxis(int index) {
+        logger.debug("createYAxis: " + index);
+        if (index == 1) {
+            firstYAxis = super.createYAxis(1);
+            if (secondYAxis != null) {
+                secondYAxis.setProxyAxis(firstYAxis);
+            }
+            return firstYAxis;
+        }
+        YAxisWalker walker = getYAxisWalker();
+
+        Font labelFont = new Font(
+            DEFAULT_FONT_NAME,
+            Font.BOLD,
+            getYAxisFontSize(index));
+
+        SyncNumberAxis axis = new SyncNumberAxis(
+            walker.getId(index),
+            getYAxisLabel(index),
+            firstYAxis);
+
+        axis.setAutoRangeIncludesZero(false);
+        axis.setLabelFont(labelFont);
+        axis.setTickLabelFont(labelFont);
+        axis.setShift((double)-getCurrentGaugeDatum());
+
+        secondYAxis = axis;
+        return axis;
+    }
+
+    public double getCurrentGaugeDatum() {
+        if (context.getContextValue(CURRENT_KM) != null) {
+            return DischargeCurveGenerator.getCurrentGaugeDatum(
+                (Double) context.getContextValue(CURRENT_KM),
+                (D4EArtifact) getMaster(), 0.1d);
+        }
+        else return 0d;
+    }
+
 
     @Override
     public void doOut(ArtifactAndFacet aaf, Document doc, boolean visible) {
@@ -612,7 +669,13 @@
 
     @Override
     protected String getDefaultYAxisLabel(int pos) {
-        return msg(I18N_YAXIS_LABEL, I18N_YAXIS_LABEL_DEFAULT);
+        D4EArtifact flys = (D4EArtifact) master;
+
+        String unit = RiverUtils.getRiver(flys).getWstUnit().getName();
+        if (pos == 0 && getCurrentGaugeDatum() != 0)
+            unit = "cm";
+
+        return msg(I18N_YAXIS_LABEL, I18N_YAXIS_LABEL_DEFAULT, new Object[] { unit });
     }
 
     @Override

http://dive4elements.wald.intevation.org