view artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowDepthChartExtender.java @ 8948:a4f1ac81f26d

Work on SINFO-FlowDepthMinMax. Also rework of result row stuff, in order to reduce abstraction, using result type concept
author gernotbelger
date Wed, 14 Mar 2018 14:10:32 +0100
parents 8596f95673b1
children 6b2496d71936
line wrap: on
line source
/** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde
 * Software engineering by
 *  Björnsen Beratende Ingenieure GmbH
 *  Dr. Schumacher Ingenieurbüro für Wasser und Umwelt
 *
 * 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.artifacts.sinfo.flowdepth;

import java.awt.BasicStroke;
import java.awt.Stroke;

import org.dive4elements.river.exports.ChartExtender;
import org.dive4elements.river.exports.DiagramGenerator;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.plot.XYPlot;

/**
 * @author Gernot Belger
 */
public class FlowDepthChartExtender implements ChartExtender {

    private static final String TKH_AXIS = "tkhAxis";

    private static final String FLOWDEPTH_AXIS = "flowdepthAxis";

    @Override
    public void beforeAutoZoom(final DiagramGenerator generator) {
        final ValueAxis tkhAxis = generator.getAxis(TKH_AXIS);
        if (tkhAxis != null) {
            /* If tkh is not the only dataset, we push it to the bottom */
            final int numYAxes = generator.getNumYAxes();
            if (numYAxes > 1)
                tkhAxis.setUpperMargin(4.0);
        }
    }

    /**
     * Synchronizes the location of '0' on the flow-depth-axis with the tkh-axis, by extending the lower bound of the
     * flow-depth-axis.
     */
    @Override
    public void afterAutoZoom(final DiagramGenerator generator) {
        final ValueAxis axis1 = generator.getAxis(FLOWDEPTH_AXIS);
        final ValueAxis axis2 = generator.getAxis(TKH_AXIS);
        if (axis1 == null || axis2 == null)
            return;

        final double axis2lb = axis2.getLowerBound();
        final double axis1ub = axis1.getUpperBound();
        final double axis2ub = axis2.getUpperBound();

        final double ratio = axis2lb / (axis2ub - axis2lb);
        final double axis1lbNew = axis1ub / (1 / ratio + 1);

        axis1.setLowerBound(axis1lbNew);
    }

    @Override
    public void afterGenerateChart(final DiagramGenerator generator, final XYPlot plot) {
        final ValueAxis tkhAxis = generator.getAxis(TKH_AXIS);
        if (tkhAxis != null) {
            /* show baseline if tkhAxis is present */

            // TODO: it would probably better to configure this via the ChartSettings, but currently no chart settings are loaded,
            // so it is unclear if that feature still works.
            final Stroke baselineStroke = new BasicStroke(2, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER);
            plot.setRangeZeroBaselineStroke(baselineStroke);
            plot.setRangeZeroBaselineVisible(true);
        }
    }
}

http://dive4elements.wald.intevation.org