diff artifacts/src/main/java/org/dive4elements/river/exports/extreme/ExtremeWQCurveGenerator.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/extreme/ExtremeWQCurveGenerator.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/extreme/ExtremeWQCurveGenerator.java	Thu Apr 25 15:23:37 2013 +0200
@@ -0,0 +1,194 @@
+package org.dive4elements.river.exports.extreme;
+
+import java.awt.Color;
+
+import org.apache.log4j.Logger;
+import org.jfree.chart.JFreeChart;
+import org.jfree.chart.plot.Marker;
+import org.jfree.chart.plot.ValueMarker;
+import org.jfree.chart.title.TextTitle;
+import org.jfree.data.xy.XYSeries;
+import org.w3c.dom.Document;
+
+import org.dive4elements.artifactdatabase.state.ArtifactAndFacet;
+import org.dive4elements.artifactdatabase.state.Facet;
+import org.dive4elements.river.artifacts.access.FixAnalysisAccess;
+import org.dive4elements.river.artifacts.model.DateRange;
+import org.dive4elements.river.artifacts.model.FacetTypes;
+import org.dive4elements.river.artifacts.model.extreme.Curve;
+import org.dive4elements.river.artifacts.model.extreme.ExtremeCurveFacet;
+import org.dive4elements.river.artifacts.resources.Resources;
+import org.dive4elements.river.exports.fixings.FixWQCurveGenerator;
+import org.dive4elements.river.exports.StyledSeriesBuilder;
+import org.dive4elements.river.jfree.JFreeUtil;
+import org.dive4elements.river.jfree.StyledXYSeries;
+
+import org.dive4elements.river.utils.ThemeUtil;
+
+
+/**
+ * Generator for WQ fixing charts.
+ * @author <a href="mailto:christian.lins@intevation.de">Christian Lins</a>
+ */
+public class ExtremeWQCurveGenerator
+extends      FixWQCurveGenerator
+implements   FacetTypes
+{
+    /** Private logger. */
+    private static Logger logger =
+            Logger.getLogger(ExtremeWQCurveGenerator.class);
+
+    public static final String I18N_CHART_TITLE =
+            "chart.extreme.wq.title";
+
+    public static final String I18N_CHART_SUBTITLE =
+            "chart.extreme.wq.subtitle";
+
+    public static final String I18N_CHART_SUBTITLE1 =
+            "chart.extreme.wq.subtitle1";
+
+    public static final String I18N_XAXIS_LABEL =
+            "chart.extreme.wq.xaxis.label";
+
+    public static final String I18N_YAXIS_LABEL =
+            "chart.extreme.wq.yaxis.label";
+
+    public static final String I18N_CHART_TITLE_DEFAULT  =
+            "Extremkurvenanalyse";
+
+    public static final String I18N_XAXIS_LABEL_DEFAULT  =
+            "Q [m\u00B3/s]";
+
+    public static final String I18N_YAXIS_LABEL_DEFAULT  =
+            "W [NN + m]";
+
+
+    @Override
+    public boolean prepareChartData(ArtifactAndFacet aaf, Document theme, boolean visible) {
+        if (!super.prepareChartData(aaf, theme, visible)) {
+            String name = aaf.getFacetName();
+            if (name.equals(EXTREME_WQ_CURVE)) {
+                doExtremeCurveOut(aaf, theme, visible);
+                return true;
+            }
+            else if (name.equals(EXTREME_WQ_CURVE_BASE)) {
+                doExtremeCurveBaseOut(aaf, theme, visible);
+                return true;
+            }
+            return false;
+        }
+        return true;
+    }
+
+    /** Do Extreme Curve nonextrapolated points out. */
+    protected void doExtremeCurveBaseOut(ArtifactAndFacet aaf, Document theme, boolean visible) {
+        logger.debug("doExtremeCurveBaseOut");
+        ExtremeCurveFacet facet = (ExtremeCurveFacet) aaf.getFacet();
+        Curve curve = (Curve) facet.getData(aaf.getArtifact(), context);
+        if (curve == null) {
+            logger.warn("doExtremeCurveBaseOut: Facet does not contain Curve");
+            return;
+        }
+
+        XYSeries qwseries = new StyledXYSeries(aaf.getFacetDescription(), theme);
+        StyledSeriesBuilder.addPointsQW(qwseries, curve.getQs(), curve.getWs());
+
+        addAxisSeries(qwseries, YAXIS.W.idx, visible);
+    }
+
+
+    /** Do Extreme Curve out */
+    protected void doExtremeCurveOut(ArtifactAndFacet aaf, Document theme, boolean visible) {
+        logger.debug("doExtremeCurveOut");
+        ExtremeCurveFacet facet = (ExtremeCurveFacet) aaf.getFacet();
+        Curve curve = (Curve) facet.getData(aaf.getArtifact(), context);
+        if (curve == null) {
+            logger.warn("doExtremeCurveOut: Facet does not contain Curve");
+            return;
+        }
+
+        double maxQ = curve.getSuggestedMaxQ();
+        if (maxQ == Double.MAX_VALUE) {
+            maxQ = 8000;
+        }
+
+        StyledXYSeries series = JFreeUtil.sampleFunction2D(
+                curve,
+                theme,
+                aaf.getFacetDescription(),
+                500,   // number of samples
+                0.0 ,  // start
+                maxQ); // end
+
+        // Add marker from where on its extrapolated.
+        if (ThemeUtil.parseShowExtraMark(theme)) {
+            double[] qs = curve.getQs();
+            double extrapolateFrom = qs[qs.length-1];
+
+            Marker m = new ValueMarker(extrapolateFrom);
+            m.setPaint(Color.black);
+            addDomainMarker(m);
+        }
+
+        addAxisSeries(series, 0, visible);
+    }
+
+
+    @Override
+    protected String getChartTitle() {
+        return Resources.format(
+                context.getMeta(),
+                I18N_CHART_TITLE,
+                I18N_CHART_TITLE_DEFAULT,
+                context.getContextValue(CURRENT_KM));
+    }
+
+
+    @Override
+    protected String getDefaultChartTitle() {
+        return msg(I18N_CHART_TITLE, I18N_CHART_TITLE_DEFAULT);
+    }
+
+    @Override
+    protected String getDefaultChartSubtitle() {
+        FixAnalysisAccess access = new FixAnalysisAccess(artifact, context);
+        DateRange dateRange = access.getDateRange();
+        DateRange refRange  = access.getReferencePeriod();
+
+        if (dateRange != null && refRange != null) {
+            return Resources.format(
+                    context.getMeta(),
+                    I18N_CHART_SUBTITLE,
+                    "",
+                    access.getRiver(),
+                    dateRange.getFrom(),
+                    dateRange.getTo(),
+                    refRange.getFrom(),
+                    refRange.getTo());
+        }
+
+        return null;
+    }
+
+    @Override
+    protected void addSubtitles(JFreeChart chart) {
+        String defaultSubtitle = getDefaultChartSubtitle();
+
+        if (defaultSubtitle == null || defaultSubtitle.length() == 0) {
+            return;
+        }
+
+        chart.addSubtitle(new TextTitle(defaultSubtitle));
+    }
+
+    @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);
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org