view flys-artifacts/src/main/java/de/intevation/flys/exports/DischargeCurveGenerator.java @ 1812:dd084cf3f284

Refactored to allow mainvalues in discharge curve diagrams, too. flys-artifacts/trunk@3141 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Wed, 02 Nov 2011 12:12:48 +0000
parents 41ba2276d785
children 3918bd7eb4e1
line wrap: on
line source
package de.intevation.flys.exports;

import org.apache.log4j.Logger;

import org.w3c.dom.Document;

import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.plot.XYPlot;
import org.jfree.data.Range;
import org.jfree.data.xy.XYSeries;

import de.intevation.artifacts.Artifact;

import de.intevation.artifactdatabase.state.Facet;

import de.intevation.flys.artifacts.model.FacetTypes;
import de.intevation.flys.model.Gauge;
import de.intevation.flys.model.River;

import de.intevation.flys.artifacts.FLYSArtifact;
import de.intevation.flys.artifacts.WINFOArtifact;

import de.intevation.flys.artifacts.model.WQKms;

import de.intevation.flys.utils.FLYSUtils;
import de.intevation.flys.jfree.FLYSAnnotation;

/**
 * An OutGenerator that generates discharge curves.
 *
 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
 */
public class DischargeCurveGenerator
extends      XYChartGenerator
implements   FacetTypes {

    /** The logger used in this generator. */
    private static Logger logger =
        Logger.getLogger(DischargeCurveGenerator.class);

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

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

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

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

    public static final String I18N_CHART_TITLE_DEFAULT  = "Abflusskurven";
    public static final String I18N_XAXIS_LABEL_DEFAULT  = "Q [m\u00b3/s]";
    public static final String I18N_YAXIS_LABEL_DEFAULT  = "W [cm]";



    public DischargeCurveGenerator() {
        super();
    }


    protected String getChartTitle() {
        return msg(I18N_CHART_TITLE, I18N_CHART_TITLE_DEFAULT);
    }


    /**
     * Empty (suppress subtitle).
     */
    @Override
    protected void addSubtitles(JFreeChart chart) {
        ;
    }


    protected String getXAxisLabel() {
        return msg(I18N_XAXIS_LABEL, I18N_XAXIS_LABEL_DEFAULT);
    }


    protected String getYAxisLabel() {
        return msg(I18N_YAXIS_LABEL, I18N_YAXIS_LABEL_DEFAULT);
    }


    @Override
    protected boolean zoomX(XYPlot plot, ValueAxis axis, Range range, Range x) {
        boolean zoomin = super.zoom(plot, axis, range, x);

        if (!zoomin) {
            axis.setLowerBound(0d);
        }

        return zoomin;
    }


    public void doOut(
        Artifact artifact,
        Facet    facet,
        Document theme,
        boolean  visible
    ) {
        logger.debug("DischargeCurveGenerator.doOut: " + facet.getName());

        String name = facet.getName();

        FLYSArtifact flysArtifact = (FLYSArtifact) artifact;

        Facet nativeFacet = flysArtifact.getNativeFacet(facet);

        if (nativeFacet == null) {
            logger.debug("no facet found");
            return;
        }

        if (name.equals(DISCHARGE_CURVE)) {
            doDischargeOut(
                (WINFOArtifact) flysArtifact,
                nativeFacet.getData(flysArtifact, context),
                nativeFacet.getDescription(),
                theme,
                visible);
        }
        else if (name.equals(COMPUTED_DISCHARGE_MAINVALUES_Q)
                || name.equals(MAINVALUES_Q))
        {
            doMainValueQAnnotations(
                nativeFacet.getData(artifact, context), facet, theme, visible);
        }
        else if (name.equals(COMPUTED_DISCHARGE_MAINVALUES_W)
                || name.equals(MAINVALUES_W))
        {
            doMainValueWAnnotations(
                nativeFacet.getData(artifact, context), facet, theme, visible);
        }
        else {
           logger.warn("DischargeCurveGenerator.doOut: Unknown facet name: " + name);
           return;
        }
    }


    /**
     * Add series with discharge curve to diagram.
     */
    protected void doDischargeOut(
        WINFOArtifact artifact,
        Object o,
        String description,
        Document theme,
        boolean visible)
    {
        WQKms wqkms = (WQKms) o;

        String gaugeName = wqkms.getName();

        River river = FLYSUtils.getRiver(artifact);

        if (river == null) {
            logger.debug("no river found");
            return;
        }

        Gauge gauge = river.determineGaugeByName(gaugeName);

        if (gauge == null) {
            logger.debug("no gauge found");
            return;
        }

        XYSeries series = new StyledXYSeries(description, theme);

        StyledSeriesBuilder.addPointsQW(series, wqkms);

        addFirstAxisSeries(series, visible);
    }

            

    /**
     * Store W MainValues as annotations for later plotting.
     */
    protected void doMainValueWAnnotations(
        Object   o,
        Facet    facet,
        Document theme,
        boolean  visible
    ) {
        logger.debug("ComputedDischargeCurveGenerator set W MainValues.");

        FLYSAnnotation fa = (FLYSAnnotation) o;
        fa.setTheme(theme);
        fa.setLabel(facet.getDescription());
        addAnnotations(fa, visible);
    }


    /**
     * Store Q MainValues as annotations for later plotting.
     */
    protected void doMainValueQAnnotations(
        Object   o,
        Facet    facet,
        Document theme,
        boolean  visible
    ) {
        logger.debug("ComputedDischargeCurveGenerator set Q MainValues.");

        FLYSAnnotation fa = (FLYSAnnotation) o;
        fa.setTheme(theme);
        fa.setLabel(facet.getDescription());
        addAnnotations(fa, visible);
    }



}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org