view artifacts/src/main/java/org/dive4elements/river/exports/HistoricalDischargeWQCurveGenerator.java @ 6140:60b94dec104b

Add handling of bound artifacts. When an artifact is bound to an out its facets will only be shown in that Out. They will be removed in the blackboard pass and marked as incompatible by the AttributeWriter
author Andre Heinecke <aheinecke@intevation.de>
date Fri, 31 May 2013 15:29:30 +0200
parents af13ceeba52a
children b494a9cf25e5
line wrap: on
line source
/* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
 * Software engineering by Intevation GmbH
 *
 * This file is Free Software under the GNU AGPL (>=v3)
 * and comes with ABSOLUTELY NO WARRANTY! Check out the
 * documentation coming with Dive4Elements River for details.
 */

package org.dive4elements.river.exports;

import org.apache.log4j.Logger;
import org.jfree.data.xy.XYSeries;
import org.w3c.dom.Document;

import org.dive4elements.artifactdatabase.state.ArtifactAndFacet;
import org.dive4elements.river.artifacts.D4EArtifact;
import org.dive4elements.river.artifacts.access.HistoricalDischargeAccess;
import org.dive4elements.river.artifacts.model.FacetTypes;
import org.dive4elements.river.artifacts.model.Timerange;
import org.dive4elements.river.artifacts.model.WQKms;

import org.dive4elements.river.jfree.RiverAnnotation;
import org.dive4elements.river.jfree.StyledValueMarker;
import org.dive4elements.river.jfree.StyledXYSeries;
import org.dive4elements.river.utils.RiverUtils;


/**
 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
 */
public class HistoricalDischargeWQCurveGenerator
extends      XYChartGenerator
implements   FacetTypes {

    /** Private logger. */
    private static Logger logger = Logger
        .getLogger(HistoricalDischargeWQCurveGenerator.class);

    public static final String I18N_CHART_TITLE = "chart.historical.discharge.wq.title";

    public static final String I18N_CHART_SUBTITLE = "chart.historical.discharge.wq.subtitle";

    public static final String I18N_XAXIS_LABEL = "chart.historical.discharge.wq.xaxis.label";

    public static final String I18N_YAXIS_LABEL = "chart.historical.discharge.wq.yaxis.label";

    /** One Y-Axis only, in this chart. */
    public static enum YAXIS {
        W(0);

        protected int idx;

        private YAXIS(int c) {
            idx = c;
        }
    }

    @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
    protected String getDefaultChartTitle() {
        return msg(I18N_CHART_TITLE, I18N_CHART_TITLE);
    }

    @Override
    protected String getDefaultChartSubtitle() {
        D4EArtifact flys = (D4EArtifact) master;
        Timerange evalTime = new HistoricalDischargeAccess(flys)
            .getEvaluationTimerange();

        Object[] args = new Object[] { RiverUtils.getReferenceGaugeName(flys),
            evalTime.getStart(), evalTime.getEnd() };

        return msg(I18N_CHART_SUBTITLE, "", args);
    }

    @Override
    protected String getDefaultXAxisLabel() {
        return msg(I18N_XAXIS_LABEL, I18N_XAXIS_LABEL);
    }

    @Override
    protected String getDefaultYAxisLabel(int pos) {
        if (pos == 0) {
            return msg(I18N_YAXIS_LABEL, I18N_YAXIS_LABEL);
        }
        else {
            return "NO TITLE FOR Y AXIS: " + pos;
        }
    }

    @Override
    public void doOut(ArtifactAndFacet artifactFacet, Document theme,
        boolean visible) {
        String name = artifactFacet.getFacetName();
        logger.debug("HistoricalDischargeWQCurveGenerator.doOut: " + name);
        logger.debug("Theme description is: "
            + artifactFacet.getFacetDescription());

        if (name.equals(HISTORICAL_DISCHARGE_WQ_Q)) {
            doHistoricalDischargeOutQ(
                (D4EArtifact) artifactFacet.getArtifact(),
                artifactFacet.getData(context),
                artifactFacet.getFacetDescription(), theme, visible);
        }
        else if (name.equals(HISTORICAL_DISCHARGE_WQ_W)) {
            doHistoricalDischargeOutW(
                (D4EArtifact) artifactFacet.getArtifact(),
                artifactFacet.getData(context),
                artifactFacet.getFacetDescription(), theme, visible);
        }
        else if (name.equals(HISTORICAL_DISCHARGE_WQ_CURVE)) {
            doHistoricalDischargeCurveOut(
                (D4EArtifact) artifactFacet.getArtifact(),
                artifactFacet.getData(context),
                artifactFacet.getFacetDescription(), theme, visible);
        }
        else if (FacetTypes.IS.MANUALPOINTS(name)) {
            doPoints(artifactFacet.getData(context), artifactFacet, theme,
                visible, YAXIS.W.idx);
        }
        else if (HISTORICAL_DISCHARGE_MAINVALUES_Q.equals(name)) {
            doAnnotations((RiverAnnotation)
                artifactFacet.getData(context), artifactFacet, theme, visible);
        }
        else if (HISTORICAL_DISCHARGE_MAINVALUES_W.equals(name)) {
            doAnnotations((RiverAnnotation)
                artifactFacet.getData(context), artifactFacet, theme, visible);
        }
        else {
            logger.warn("doOut(): unknown facet name: " + name);
            return;
        }
    }

    protected void doHistoricalDischargeOutQ(D4EArtifact artifact,
        Object data, String desc, Document theme, boolean visible) {
        double value = Double.valueOf(data.toString());
        addDomainMarker(new StyledValueMarker(value, theme), visible);
    }

    protected void doHistoricalDischargeOutW(D4EArtifact artifact,
        Object data, String desc, Document theme, boolean visible) {
        double value = Double.valueOf(data.toString());
        addValueMarker(new StyledValueMarker(value, theme), visible);
    }

    protected void doHistoricalDischargeCurveOut(D4EArtifact artifact,
        Object data, String desc, Document theme, boolean visible) {
        XYSeries series = new StyledXYSeries(desc, theme);
        StyledSeriesBuilder.addPointsQW(series, (WQKms) data);

        addAxisSeries(series, YAXIS.W.idx, visible);
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org