[Dive4elements-commits] [PATCH 08 of 13] FixWQCurveGenerator: Introduce second (cm) axis

Wald Commits scm-commit at wald.intevation.org
Thu Jun 27 10:40:17 CEST 2013


# HG changeset patch
# User Felix Wolfsteller <felix.wolfsteller at intevation.de>
# Date 1372322671 -7200
# Node ID 0f997d6397c63c565bb0328fdc4d21a240229e66
# Parent  cf514239d290bab60bac1155e9b35d617ef41728
FixWQCurveGenerator: Introduce second (cm) axis.

diff -r cf514239d290 -r 0f997d6397c6 artifacts/src/main/java/org/dive4elements/river/exports/fixings/FixWQCurveGenerator.java
--- 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


More information about the Dive4elements-commits mailing list