view artifacts/src/main/java/org/dive4elements/river/exports/LongitudinalSectionGenerator2.java @ 8722:a83d519155ab

(issue1754) Do not base smoothing radius on calculation range Using the calculation parameters for startkm and endkm in the case that the domain axis had the default extend caused weird behavior when zooming and led to too large radius values for most data that only had valid values on a subset of the caluclation range.
author Andre Heinecke <andre.heinecke@intevation.de>
date Tue, 28 Apr 2015 14:22:47 +0200
parents cfb3a4d0c637
children 686d8876edf9
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.dive4elements.river.artifacts.D4EArtifact;
import org.dive4elements.artifactdatabase.state.ArtifactAndFacet;
import org.dive4elements.river.artifacts.access.RangeAccess;
import org.dive4elements.river.jfree.Bounds;
import org.dive4elements.river.jfree.DoubleBounds;
import org.dive4elements.river.themes.ThemeDocument;

public class LongitudinalSectionGenerator2 extends DiagramGenerator
{
    public static final String I18N_CHART_SHORT_SUBTITLE =
        "chart.longitudinal.section.shortsubtitle";

    public static final String I18N_CHART_LOCATION_SUBTITLE =
        "chart.longitudinal.section.locsubtitle";

    @Override
    public String getDefaultChartSubtitle() {
        double[] dist = getRange();
        String parts = "";
        if (subTitleParts != null && !subTitleParts.isEmpty()) {
             for (String p : subTitleParts) {
                 parts += ", " + p;
             }
        }
        if (dist == null || dist.length != 2 ||
                Double.isNaN(dist[0]) || Double.isNaN(dist[1])) {
            Object [] args = new Object[] {getRiverName()};
            return msg(I18N_CHART_SHORT_SUBTITLE, "", args) + parts;
        }

        if (Math.abs(dist[0] - dist[1]) < 1E-5) {
            Object [] args = new Object[] {getRiverName(), dist[1]};
            return msg(I18N_CHART_LOCATION_SUBTITLE, "", args) + parts;
        }

        return super.getDefaultChartSubtitle();
    }

    /* We override doOut here to save the startkm and endkm in the
     * context. Some facets will deliver different data because of
     * that setting. It is mainly used in MINFO where it causes
     * adaptive smoothing on the data if you are zoomed out do
     * reduce the static in the curve. */
    @Override
    public void doOut(
        ArtifactAndFacet bundle,
        ThemeDocument    theme,
        boolean          visible
    ) {
        /* Aheinecke (25.09.2013): I do not understand why this has to be
         * done so difficult and if it really must be done for every
         * facet. At least it has to be done _before_ the super class
         * actually does the output and accesses the facet data.
         */
        D4EArtifact artifact = (D4EArtifact)bundle.getArtifact();
        Object ctxV = context.getContextValue("bounds_defined");
        if (ctxV != null && (Boolean)ctxV) {
            super.doOut(bundle, theme, visible);
            return;
        }
        if (getXBounds(0) != null && getDomainAxisRange() != null) {
            Bounds bounds =
                calculateZoom(getXBounds(0), getDomainAxisRange());
            context.putContextValue("startkm", bounds.getLower());
            context.putContextValue("endkm", bounds.getUpper());
            context.putContextValue("bounds_defined", true);
        }
        else if (getXBounds(0) != null && getDomainAxisRange() == null) {
            context.putContextValue("startkm", getXBounds(0).getLower());
            context.putContextValue("endkm", getXBounds(0).getUpper());
            context.putContextValue("bounds_defined", true);
        }
        else if (getXBounds(0) == null && getDomainAxisRange() != null){
            RangeAccess access = new RangeAccess(artifact);
            if (access.hasFrom() && access.hasTo()) {
                Bounds b = new DoubleBounds(access.getFrom(), access.getTo());
                Bounds bounds =
                    calculateZoom(b, getDomainAxisRange());
                context.putContextValue("startkm", bounds.getLower());
                context.putContextValue("endkm", bounds.getUpper());
                context.putContextValue("bounds_defined", true);
            }
        }
        /*
        else if (getXBounds(0) == null && getDomainAxisRange() == null) {
            .. In this case the automatic zoom of the diagram will provide
            decent values for the zooom calculation.
        }
        */
        super.doOut(bundle, theme, visible);
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org