changeset 4447:a5993b69439b

Add processor to be able to generate curves for WKms values
author Björn Ricks <bjoern.ricks@intevation.de>
date Wed, 07 Nov 2012 15:52:25 +0100
parents 05a54b4d579d
children 9425b7c51b73
files flys-artifacts/src/main/java/de/intevation/flys/exports/process/WOutProcessor.java
diffstat 1 files changed, 113 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/process/WOutProcessor.java	Wed Nov 07 15:52:25 2012 +0100
@@ -0,0 +1,113 @@
+package de.intevation.flys.exports.process;
+
+import org.apache.log4j.Logger;
+import org.jfree.data.xy.XYSeries;
+import org.w3c.dom.Document;
+
+import de.intevation.artifactdatabase.state.ArtifactAndFacet;
+import de.intevation.artifacts.CallContext;
+import de.intevation.flys.artifacts.model.FacetTypes;
+import de.intevation.flys.artifacts.model.WKms;
+import de.intevation.flys.exports.StyledSeriesBuilder;
+import de.intevation.flys.exports.XYChartGenerator;
+import de.intevation.flys.jfree.StyledAreaSeriesCollection;
+import de.intevation.flys.jfree.StyledXYSeries;
+import de.intevation.flys.utils.DataUtil;
+import de.intevation.flys.utils.ThemeUtil;
+
+/**
+ * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a>
+ */
+public class WOutProcessor implements Processor {
+
+    private static final Logger logger =
+            Logger.getLogger(WOutProcessor.class);
+
+    @Override
+    public void doOut(
+            XYChartGenerator generator,
+            ArtifactAndFacet    aaf,
+            Document             theme,
+            boolean               visible,
+            int                         index)
+    {
+        CallContext context = generator.getCallContext();
+        WKms wkms = (WKms) aaf.getData(context);
+
+        logger.debug("doOut");
+
+        XYSeries series = new StyledXYSeries(aaf.getFacetDescription(), theme);
+
+        StyledSeriesBuilder.addPoints(series, wkms);
+        generator.addAxisSeries(series, index, visible);
+
+        // If a "band around the curve shall be drawn, add according area.
+        double bandWidth = ThemeUtil.parseBandWidth(theme);
+        if (bandWidth > 0 ) {
+            XYSeries seriesDown = new StyledXYSeries(
+                "band " + aaf.getFacetDescription(), false, theme);
+            XYSeries seriesUp = new StyledXYSeries(
+                aaf.getFacetDescription()+"+/-"+bandWidth, false, theme);
+            StyledSeriesBuilder.addUpperBand(seriesUp, wkms, bandWidth);
+            StyledSeriesBuilder.addLowerBand(seriesDown, wkms, bandWidth);
+
+            StyledAreaSeriesCollection area = new StyledAreaSeriesCollection(theme);
+            area.addSeries(seriesUp);
+            area.addSeries(seriesDown);
+            area.setMode(StyledAreaSeriesCollection.FILL_MODE.BETWEEN);
+            generator.addAreaSeries(area, index, visible);
+        }
+
+        invertAxis(generator, wkms);
+    }
+
+    /**
+     * Returns true if facettype is longitutinal_section.w
+     */
+    @Override
+    public boolean canHandle(String facettype) {
+        if (facettype == null) {
+            return false;
+        }
+
+        if (facettype.equals(FacetTypes.LONGITUDINAL_W)
+                || facettype.equals(FacetTypes.STATIC_WKMS)
+                || facettype.equals(FacetTypes.HEIGHTMARKS_POINTS)
+                || facettype.equals(FacetTypes.STATIC_WQKMS)
+                || facettype.equals(FacetTypes.STATIC_WQKMS_W)
+                || facettype.equals(FacetTypes.DISCHARGE_LONGITUDINAL_W))
+        {
+            return true;
+        }
+        return false;
+    }
+
+    /**
+     * This method determines - taking JFreeCharts auto x value ordering into
+     * account - if the x axis need to be inverted. Waterlines in these charts
+     * should decrease.
+     *
+     * @param wkms The data object that stores the x and y values used for this
+     * chart.
+     */
+    public void invertAxis(XYChartGenerator generator, WKms wkms) {
+        boolean wsUp = wkms.guessWaterIncreasing();
+        boolean kmUp = DataUtil.guessWaterIncreasing(wkms.allKms());
+        boolean inv = (wsUp && kmUp) || (!wsUp && !kmUp);
+
+        int size = wkms.size();
+
+        if (logger.isDebugEnabled()) {
+            logger.debug("(Wkms)Values  : " + size);
+            if (size > 0) {
+                logger.debug("Start km: " + wkms.getKm(0));
+                logger.debug("End   km: " + wkms.getKm(size-1));
+            }
+            logger.debug("wsUp: " + wsUp);
+            logger.debug("kmUp: " + kmUp);
+            logger.debug("inv:  " + inv);
+        }
+        generator.setInverted(inv);
+    }
+
+}

http://dive4elements.wald.intevation.org