diff artifacts/src/main/java/org/dive4elements/river/exports/sq/SQRelationGenerator.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/sq/SQRelationGenerator.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/sq/SQRelationGenerator.java	Thu Apr 25 15:23:37 2013 +0200
@@ -0,0 +1,209 @@
+package org.dive4elements.river.exports.sq;
+
+import org.dive4elements.artifactdatabase.state.ArtifactAndFacet;
+import org.dive4elements.artifactdatabase.state.Facet;
+
+import org.dive4elements.river.artifacts.model.FacetTypes;
+
+import org.dive4elements.river.artifacts.model.sq.SQ;
+import org.dive4elements.river.artifacts.model.sq.SQFunction;
+
+import org.dive4elements.river.exports.XYChartGenerator;
+
+import org.dive4elements.river.jfree.JFreeUtil;
+import org.dive4elements.river.jfree.StyledXYSeries;
+
+import org.apache.log4j.Logger;
+
+import org.jfree.chart.axis.LogarithmicAxis;
+import org.jfree.chart.axis.NumberAxis;
+
+import org.jfree.data.xy.XYSeries;
+
+import org.w3c.dom.Document;
+
+/**
+ * An OutGenerator that generates charts for MINFO sq relation.
+ *
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+public class SQRelationGenerator
+extends      XYChartGenerator
+implements   FacetTypes
+{
+    public enum YAXIS {
+        S(0);
+        protected int idx;
+        private YAXIS(int c) {
+           idx = c;
+        }
+    }
+
+
+    public static final String I18N_XAXIS_LABEL =
+        "chart.sq_relation.xaxis.label";
+
+    public static final String I18N_YAXIS_LABEL =
+        "chart.sq_relation.yaxis.label";
+
+
+    /** The logger that is used in this generator. */
+    private static Logger logger = Logger.getLogger(SQRelationGenerator.class);
+
+
+    @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();
+            }
+        };
+    }
+
+
+    @Override
+    public String getDefaultChartTitle() {
+        return "TODO: CHART TITLE";
+    }
+
+
+    @Override
+    protected String getDefaultXAxisLabel() {
+        return msg(I18N_XAXIS_LABEL, I18N_XAXIS_LABEL);
+    }
+
+
+    @Override
+    protected String getDefaultYAxisLabel(int index) {
+        return msg(I18N_YAXIS_LABEL, I18N_YAXIS_LABEL);
+    }
+
+
+    @Override
+    protected NumberAxis createXAxis(String label) {
+        return new LogarithmicAxis(label);
+    }
+
+
+    @Override
+    protected NumberAxis createYAxis(int index) {
+        return new LogarithmicAxis(getDefaultYAxisLabel(index));
+    }
+
+
+    @Override
+    public void doOut(
+        ArtifactAndFacet artifactAndFacet,
+        Document         attr,
+        boolean          visible
+    ) {
+        logger.debug("doOut");
+
+        Facet  facet = artifactAndFacet.getFacet();
+        String name  = facet != null ? facet.getName() : null;
+
+        if (name == null || name.length() == 0) {
+            logger.warn("Invalid facet with no name given!");
+            return;
+        }
+
+        if (IS.SQ_CURVE(name)) {
+            doSQCurveOut(artifactAndFacet, attr, visible);
+        }
+        else if (IS.SQ_MEASUREMENT(name)) {
+            doSQOut(artifactAndFacet, attr, visible);
+        }
+        else if (IS.SQ_OUTLIER(name)) {
+            doSQOut(artifactAndFacet, attr, visible);
+        }
+        else if (IS.MANUALPOINTS(name)) {
+            doPoints(
+                artifactAndFacet.getData(context),
+                artifactAndFacet,
+                attr,
+                visible,
+                YAXIS.S.idx);
+        }
+    }
+
+
+    protected void doSQCurveOut(
+        ArtifactAndFacet artifactAndFacet,
+        Document         attr,
+        boolean          visible
+    ) {
+        String desc = artifactAndFacet.getFacetDescription();
+        logger.debug("doSQCurveOut: " + desc);
+
+        SQFunction func = (SQFunction) artifactAndFacet.getData(context);
+
+        if (func == null) {
+            return;
+        }
+
+        XYSeries series = JFreeUtil.sampleFunction2DPositive(
+            func.getFunction(),
+            attr,
+            desc,
+            500,
+            Math.max(func.getMinQ(), 0.01),
+            Math.max(func.getMaxQ(), 0.02));
+
+        if (logger.isDebugEnabled()) {
+            logger.debug("Series '" + desc + "' has "
+                + series.getItemCount() + " items.");
+
+            logger.debug("   -> min x = " + series.getMinX());
+            logger.debug("   -> max x = " + series.getMaxX());
+            logger.debug("   -> min y = " + series.getMinY());
+            logger.debug("   -> max y = " + series.getMaxY());
+        }
+
+        addAxisSeries(series, YAXIS.S.idx, visible);
+    }
+
+
+    protected void doSQOut(
+        ArtifactAndFacet artifactAndFacet,
+        Document         attr,
+        boolean          visible
+    ) {
+        String desc = artifactAndFacet.getFacetDescription();
+        logger.debug("doSQOut: " + desc);
+
+        SQ[]     sqs    = (SQ[]) artifactAndFacet.getData(context);
+        if (sqs == null) {
+            logger.debug("No SQs found for facet");
+            return;
+        }
+        XYSeries series = new StyledXYSeries(desc, attr);
+
+        for (SQ sq: sqs) {
+            double q = sq.getQ();
+            double s = sq.getS();
+            if (s > 0d && q > 0d) {
+                series.add(q, s, false);
+            }
+        }
+
+        if (logger.isDebugEnabled()) {
+            logger.debug("Series '" + desc + "' has "
+                + series.getItemCount() + " items.");
+
+            logger.debug("   -> min x = " + series.getMinX());
+            logger.debug("   -> max x = " + series.getMaxX());
+            logger.debug("   -> min y = " + series.getMinY());
+            logger.debug("   -> max y = " + series.getMaxY());
+        }
+
+        addAxisSeries(series, YAXIS.S.idx, visible);
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org