diff artifacts/src/main/java/org/dive4elements/river/exports/DischargeCurveGenerator.java @ 5838:5aa05a7a34b7

Rename modules to more fitting names.
author Sascha L. Teichmann <teichmann@intevation.de>
date Thu, 25 Apr 2013 15:23:37 +0200
parents flys-artifacts/src/main/java/org/dive4elements/river/exports/DischargeCurveGenerator.java@bd047b71ab37
children 4897a58c8746
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/DischargeCurveGenerator.java	Thu Apr 25 15:23:37 2013 +0200
@@ -0,0 +1,188 @@
+package org.dive4elements.river.exports;
+
+import org.dive4elements.artifactdatabase.state.ArtifactAndFacet;
+import org.dive4elements.river.artifacts.FLYSArtifact;
+import org.dive4elements.river.artifacts.model.FacetTypes;
+import org.dive4elements.river.artifacts.model.WQKms;
+import org.dive4elements.river.jfree.Bounds;
+import org.dive4elements.river.jfree.FLYSAnnotation;
+import org.dive4elements.river.jfree.StyledXYSeries;
+import org.dive4elements.river.model.Gauge;
+import org.dive4elements.river.model.River;
+import org.dive4elements.river.utils.FLYSUtils;
+
+import org.apache.log4j.Logger;
+import org.jfree.chart.axis.ValueAxis;
+import org.jfree.chart.plot.XYPlot;
+import org.jfree.data.Range;
+import org.jfree.data.xy.XYSeries;
+import org.w3c.dom.Document;
+
+
+/**
+ * An OutGenerator that generates discharge curves.
+ *
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+public class DischargeCurveGenerator
+extends      XYChartGenerator
+implements   FacetTypes {
+
+    public static enum YAXIS {
+        W(0);
+        protected int idx;
+        private YAXIS(int c) {
+            idx = c;
+        }
+    }
+
+    /** The logger used in this generator. */
+    private static Logger logger =
+        Logger.getLogger(DischargeCurveGenerator.class);
+
+    public static final String I18N_CHART_TITLE =
+        "chart.discharge.curve.title";
+
+    public static final String I18N_CHART_SUBTITLE =
+        "chart.discharge.curve.subtitle";
+
+    public static final String I18N_XAXIS_LABEL =
+        "chart.discharge.curve.xaxis.label";
+
+    public static final String I18N_YAXIS_LABEL =
+        "chart.discharge.curve.yaxis.label";
+
+    public static final String I18N_CHART_TITLE_DEFAULT  = "Abflusskurven";
+    public static final String I18N_XAXIS_LABEL_DEFAULT  = "Q [m\u00b3/s]";
+    public static final String I18N_YAXIS_LABEL_DEFAULT  = "W [cm]";
+
+
+    public DischargeCurveGenerator() {
+        super();
+    }
+
+
+    @Override
+    protected YAxisWalker getYAxisWalker() {
+        return new YAxisWalker() {
+            @Override
+            public int length() {
+                return YAXIS.values().length;
+            }
+
+            @Override
+            public String getId(int idx) {
+                YAXIS[] yaxes = YAXIS.values();
+                return yaxes[idx].toString();
+            }
+        };
+    }
+
+
+    /**
+     * Returns always null to suppress subtitles.
+     */
+    @Override
+    protected String getDefaultChartTitle() {
+        return null;
+    }
+
+
+    @Override
+    protected String getDefaultXAxisLabel() {
+        return msg(I18N_XAXIS_LABEL, I18N_XAXIS_LABEL_DEFAULT);
+    }
+
+    @Override
+    protected String getDefaultYAxisLabel(int pos) {
+        return msg(I18N_YAXIS_LABEL, I18N_YAXIS_LABEL_DEFAULT);
+    }
+
+
+    /* TODO is this one really needed? */
+    @Override
+    protected boolean zoomX(XYPlot plot, ValueAxis axis, Bounds bounds, Range x) {
+        boolean zoomin = super.zoom(plot, axis, bounds, x);
+
+        if (!zoomin) {
+            axis.setLowerBound(0d);
+        }
+
+        return zoomin;
+    }
+
+
+    @Override
+    public void doOut(
+        ArtifactAndFacet artifactFacet,
+        Document         theme,
+        boolean          visible
+    ) {
+        String name = artifactFacet.getFacetName();
+        logger.debug("DischargeCurveGenerator.doOut: " + name);
+
+        if (name.equals(DISCHARGE_CURVE)
+                || name.equals(GAUGE_DISCHARGE_CURVE)) {
+            doDischargeOut(
+                (FLYSArtifact)artifactFacet.getArtifact(),
+                artifactFacet.getData(context),
+                artifactFacet.getFacetDescription(),
+                theme,
+                visible);
+        }
+        else if (name.equals(COMPUTED_DISCHARGE_MAINVALUES_Q)
+                || name.equals(MAINVALUES_Q)
+                || name.equals(COMPUTED_DISCHARGE_MAINVALUES_W)
+                || name.equals(MAINVALUES_W))
+        {
+            doAnnotations((FLYSAnnotation) artifactFacet.getData(context),
+                artifactFacet, theme, visible);
+        }
+        else if (FacetTypes.IS.MANUALPOINTS(name)) {
+            doPoints(artifactFacet.getData(context),
+                artifactFacet,
+                theme, visible, YAXIS.W.idx);
+        }
+        else {
+           logger.warn("DischargeCurveGenerator.doOut: Unknown facet name: " + name);
+           return;
+        }
+    }
+
+
+    /**
+     * Add series with discharge curve to diagram.
+     */
+    protected void doDischargeOut(
+        FLYSArtifact artifact,
+        Object        o,
+        String        description,
+        Document      theme,
+        boolean       visible)
+    {
+        WQKms wqkms = (WQKms) o;
+
+        String gaugeName = wqkms.getName();
+
+        River river = FLYSUtils.getRiver(artifact);
+
+        if (river == null) {
+            logger.debug("no river found");
+            return;
+        }
+
+        Gauge gauge = river.determineGaugeByName(gaugeName);
+
+        if (gauge == null) {
+            logger.debug("no gauge found");
+            return;
+        }
+
+        XYSeries series = new StyledXYSeries(description, theme);
+
+        StyledSeriesBuilder.addPointsQW(series, wqkms);
+
+        addAxisSeries(series, YAXIS.W.idx, visible);
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org