view artifacts/src/main/java/org/dive4elements/river/exports/WDifferencesCurveGenerator.java @ 6611:dfdeed3e997e

Shorten and correct waterlevel not in gauge string
author Andre Heinecke <aheinecke@intevation.de>
date Thu, 18 Jul 2013 17:54:44 +0200
parents 27f5182996ea
children aee8cb5c801a
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.dive4elements.artifactdatabase.state.ArtifactAndFacet;
import org.dive4elements.artifactdatabase.state.Facet;

import org.dive4elements.river.artifacts.model.FacetTypes;
import org.dive4elements.river.artifacts.model.WKms;

import org.dive4elements.river.exports.StyledSeriesBuilder;
import org.dive4elements.river.jfree.StyledXYSeries;
import org.dive4elements.river.artifacts.model.minfo.MorphologicWidth;


import org.dive4elements.river.exports.process.BedDiffYearProcessor;
import org.dive4elements.river.exports.process.BedDiffHeightYearProcessor;
import org.dive4elements.river.exports.process.BedheightProcessor;
import org.dive4elements.river.exports.process.Processor;

import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.XYPlot;
import org.jfree.data.xy.XYSeries;
import org.w3c.dom.Document;


/**
 * An OutGenerator that generates w differences curves.
 */
public class WDifferencesCurveGenerator
extends      LongitudinalSectionGenerator
implements   FacetTypes
{
    /** The logger that is used in this generator. */
    private static Logger logger = Logger.getLogger(WDifferencesCurveGenerator.class);

    public enum YAXIS {
        W(0),
        D(1),
        Q(2);
        protected int idx;
        private YAXIS(int c) {
           idx = c;
        }
    }

    /** Key for internationalized title of WDiff charts. */
    public final static String I18N_WDIFF_TITLE = "chart.w_differences.title";

    /** Default for internationalized title (when no translation found). */
    public final static String I18N_WDIFF_TITLE_DEFAULT = "Differences";

    public final static String I18N_WDIFF_SUBTITLE =
        "chart.w_differences.subtitle";


    @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();
            }
        };
    }


    /**
     * Get internationalized title for chart.
     * @return internationalized Chart title.
     */
    @Override
    public String getDefaultChartTitle() {
        return msg(I18N_WDIFF_TITLE, I18N_WDIFF_TITLE_DEFAULT);
    }


    @Override
    protected String getDefaultChartSubtitle() {
        return getRiverName();
    }


    /**
     * Gets key to look up internationalized String for the charts subtitle.
     * @return key to look up translated subtitle.
     */
    @Override
    protected String getChartSubtitleKey() {
        return I18N_WDIFF_SUBTITLE;
    }


    /** Handle additional facets (beddifferences). */
    @Override
    public void doOut(ArtifactAndFacet bundle, Document attr, boolean visible) {
        super.doOut(bundle, attr, visible);

        String name = bundle.getFacetName();
        logger.debug("doOut: " + name);

        if (name == null) {
            logger.error("No facet name for doOut(). No output generated!");
            return;
        }

        Facet facet = bundle.getFacet();

        if (facet == null) {
            return;
        }

        Processor bedp = new BedheightProcessor();
        Processor bdyProcessor = new BedDiffYearProcessor();
        Processor bdhyProcessor = new BedDiffHeightYearProcessor();

        if (bedp.canHandle(name)) {
           bedp.doOut(this, bundle, attr, visible, YAXIS.W.idx);
        }
        else if (bdyProcessor.canHandle(name)) {
           bdyProcessor.doOut(this, bundle, attr, visible, YAXIS.W.idx);
        }
        else if (bdhyProcessor.canHandle(name)) {
           bdhyProcessor.doOut(this, bundle, attr, visible, YAXIS.W.idx);
        }
        else {
            logger.warn("WDifferencesCurveGenerator.doOut: unknown facet type " + name);
        }
    }


    /**
     * Sets the zero base line visible.
     */
    @Override
    public JFreeChart generateChart() {
        JFreeChart chart = super.generateChart();
        if (chart != null && chart.getPlot() != null) {
            XYPlot plot = (XYPlot) chart.getPlot();
            plot.setRangeZeroBaselineVisible(true);
        }
        return chart;
    }


    /**
     * Get name of series (displayed in legend).
     * @return name of the series.
     */
    protected String getSeriesName(WKms wqkms, String mode) {
        String name   = wqkms.getName();
        String prefix = (name != null && 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