changeset 4345:8eabbc5198e1

Added new Generator: ExtremeWQCurveGenerator (and its *Info*-counterpart).
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Thu, 01 Nov 2012 12:10:31 +0100 (2012-11-01)
parents c6db11e3b83a
children 603233b5a719
files flys-artifacts/src/main/java/de/intevation/flys/exports/extreme/ExtremeWQCurveGenerator.java flys-artifacts/src/main/java/de/intevation/flys/exports/extreme/ExtremeWQCurveInfoGenerator.java
diffstat 2 files changed, 221 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/extreme/ExtremeWQCurveGenerator.java	Thu Nov 01 12:10:31 2012 +0100
@@ -0,0 +1,206 @@
+package de.intevation.flys.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.w3c.dom.Document;
+
+import de.intevation.artifactdatabase.state.ArtifactAndFacet;
+import de.intevation.artifactdatabase.state.Facet;
+import de.intevation.flys.artifacts.access.FixAnalysisAccess;
+import de.intevation.flys.artifacts.model.DateRange;
+import de.intevation.flys.artifacts.model.FacetTypes;
+import de.intevation.flys.artifacts.model.extreme.Curve;
+import de.intevation.flys.artifacts.model.extreme.ExtremeCurveFacet;
+import de.intevation.flys.exports.fixings.FixWQCurveGenerator;
+import de.intevation.flys.artifacts.resources.Resources;
+import de.intevation.flys.exports.ChartGenerator;
+import de.intevation.flys.jfree.JFreeUtil;
+import de.intevation.flys.jfree.StyledXYSeries;
+
+/**
+ * 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 void doOut(ArtifactAndFacet aaf, Document doc, boolean visible) {
+        super.doOut(aaf, doc, visible);
+
+        String name = aaf.getFacetName();
+        logger.debug("doOut: " + name);
+
+        if (name.equals(EXTREME_WQ_CURVE)) {
+            doExtremeCurveOut(aaf, doc, visible);
+        }
+        else {
+            logger.warn("Unknown facet name " + name);
+            return;
+        }
+    }
+
+
+    /** Do Extreme Curve out */
+    protected void doExtremeCurveOut(ArtifactAndFacet aaf, Document doc, 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,
+                doc,
+                aaf.getFacetDescription(),
+                500,   // number of samples
+                0.0 ,  // start
+                maxQ); // end
+
+        // Add marker from where on its extrapolated.
+        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);
+        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));
+
+        StringBuilder buf = new StringBuilder();
+
+        // Add analysis periods as additional subtitle
+        FixAnalysisAccess access = new FixAnalysisAccess(artifact);
+        DateRange[] aperiods = access.getAnalysisPeriods();
+        buf.append(msg("fix.analysis.periods"));
+        buf.append(": ");
+        for(int n = 0; n < aperiods.length; n++) {
+            buf.append(
+                    Resources.format(
+                            context.getMeta(),
+                            I18N_CHART_SUBTITLE1,
+                            "",
+                            aperiods[n].getFrom(),
+                            aperiods[n].getTo()));
+            if(n + 1 < aperiods.length) {
+                buf.append("; ");
+            }
+        }
+
+        chart.addSubtitle(new TextTitle(buf.toString()));
+    }
+
+    @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);
+    }
+
+    @Override
+    protected ChartGenerator.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();
+            }
+        };
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/extreme/ExtremeWQCurveInfoGenerator.java	Thu Nov 01 12:10:31 2012 +0100
@@ -0,0 +1,15 @@
+package de.intevation.flys.exports.extreme;
+
+import de.intevation.flys.exports.ChartInfoGenerator;
+
+/**
+ * A ChartInfoGenerator that generates meta information for specific extreme
+ * analysis W/Q curves.
+ */
+public class ExtremeWQCurveInfoGenerator extends ChartInfoGenerator {
+
+    public ExtremeWQCurveInfoGenerator() {
+        super(new ExtremeWQCurveGenerator());
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org