view flys-artifacts/src/main/java/de/intevation/flys/exports/DischargeLongitudinalSectionGenerator.java @ 1684:bdb05dc9b763

Bugfix: #353 Enabled chart's to be drawn with proper axes set even if no data is contained. flys-artifacts/trunk@2902 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Fri, 07 Oct 2011 10:51:09 +0000
parents 0cb1a70b8b92
children 7e19449d7826
line wrap: on
line source
package de.intevation.flys.exports;

import org.apache.log4j.Logger;

import org.jfree.data.xy.XYSeries;

import org.w3c.dom.Document;

import de.intevation.artifacts.Artifact;

import de.intevation.artifactdatabase.state.Facet;

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


/**
 * An OutGenerator that generates discharge longitudinal section curves.
 *
 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
 */
public class DischargeLongitudinalSectionGenerator
extends      LongitudinalSectionGenerator
{
    private static Logger logger =
        Logger.getLogger(DischargeLongitudinalSectionGenerator.class);



    public DischargeLongitudinalSectionGenerator() {
        super();
    }


    @Override
    public void doOut(
        Artifact artifact,
        Facet    facet,
        Document attr,
        boolean  visible
    ) {
        logger.debug("DischargeLongitudinalSectionGenerator.doOut");

        if (facet == null) {
            return;
        }

        String name = facet.getName();

        if (name == null) {
            return;
        }

        FLYSArtifact flys = (FLYSArtifact) artifact;
        Facet        f    = flys.getNativeFacet(facet);

        if (name.equals(DISCHARGE_LONGITUDINAL_W)) {
            doWOut((WQKms) f.getData(artifact, context), attr, visible);
        }
        else if (name.equals(DISCHARGE_LONGITUDINAL_Q)) {
            doQOut((WQKms) f.getData(artifact, context), attr, visible);
        }
        else if (name.equals(DISCHARGE_LONGITUDINAL_C)) {
            doCorrectedWOut(
                (WQCKms) f.getData(artifact, context),
                attr,
                visible);
        }
        else {
            logger.warn("Unknown facet name: " + name);
        }
    }


    /**
     * Adds a new series for the corrected W curve.
     *
     * @param wqckms The object that contains the corrected W values.
     * @param theme The theme that contains styling information.
     */
    protected void doCorrectedWOut(
        WQCKms   wqckms,
        Document theme,
        boolean  visible
    ) {
        logger.debug("DischargeLongitudinalSectionGenerator.doCorrectedWOut");

        int size = wqckms.size();

        if (size > 0) {
            XYSeries series = new StyledXYSeries(
                getSeriesNameForCorrected(wqckms, "W"),
                theme);

            for (int i = 0; i < size; i++) {
                series.add(wqckms.getKm(i), wqckms.getC(i));
            }

            addFirstAxisSeries(series, visible);
        }

        if (wqckms.guessWaterIncreasing()) {
            setInverted(true);
        }
    }


    protected String getSeriesNameForCorrected(WQKms wqkms, String mode) {
        String name = wqkms.getName();

        name = name.replace(
            "benutzerdefiniert",
            "benutzerdefiniert [korrigiert]");

        String prefix = name.indexOf(mode) >= 0 ? null : mode;

        return prefix != null && prefix.length() > 0
            ? prefix + "(" + name + ")"
            : name;
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org