view artifacts/src/main/java/org/dive4elements/river/exports/LongitudinalSectionGenerator2.java @ 7691:fa4fbd66e752

(issue1579) Fix axes syncronisation at Gauges The SyncNumberAxis was completely broken. It only synced in one direction and even that did not work correctly when data was added to the axis (and the syncAxis rescaled but forgot the old axis) then there were lots of ways to bypass that scaling. And i also think the trans calculation was wrong. It has been replaced by a "mostly" simple method to just keep the W in M and W in CM+Datum axes in sync. I say "Mostly" because it had to deal with the Bounds interface.
author Andre Heinecke <aheinecke@intevation.de>
date Fri, 13 Dec 2013 19:03:00 +0100
parents 81416a62fa57
children ad4a3980092f
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();

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

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

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

        if (getXBounds(0) != null && getDomainAxisRange() != null) {
            Bounds bounds =
                calculateZoom(getXBounds(0), getDomainAxisRange());
            context.putContextValue("startkm", bounds.getLower());
            context.putContextValue("endkm", bounds.getUpper());
        }
        else if (getXBounds(0) != null && getDomainAxisRange() == null) {
            context.putContextValue("startkm", getXBounds(0).getLower());
            context.putContextValue("endkm", getXBounds(0).getUpper());
        }
        else if (getXBounds(0) == null && getDomainAxisRange() == null) {
            RangeAccess access = new RangeAccess(artifact);
            if (access.hasFrom() && access.hasTo()) {
                context.putContextValue("startkm", access.getFrom());
                context.putContextValue("endkm", access.getTo());
            }
        }
        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());
            }
        }
        super.doOut(bundle, theme, visible);
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org