view artifacts/src/main/java/org/dive4elements/river/exports/ChartArea.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 c086b06b81e5
children ff0e5386de70
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.jfree.chart.axis.ValueAxis;
import org.jfree.chart.axis.LogarithmicAxis;

/** Two Ranges that span a rectangular area. */
public class ChartArea {
    protected double xLower;
    protected double xUpper;
    protected double xLength;
    protected double yLower;
    protected double yUpper;
    protected double yLength;
    protected boolean xIsLog;
    protected boolean yIsLog;

    public ChartArea(ValueAxis axisX, ValueAxis axisY) {
        this.xLower = axisX.getRange().getLowerBound();
        this.xUpper = axisX.getRange().getUpperBound();
        this.xLength= axisX.getRange().getLength();
        this.yLower = axisY.getRange().getLowerBound();
        this.yUpper = axisY.getRange().getUpperBound();
        this.yLength= axisY.getRange().getLength();
        this.xIsLog = axisX instanceof LogarithmicAxis;
        this.yIsLog = axisY instanceof LogarithmicAxis;
    }

    public double ofLeft(double percent) {
        if (xIsLog) {
            return Math.pow(10,
                Math.log10(xLower)
                + Math.log10(xUpper / xLower) * percent
            );
        }
        return xLower + xLength * percent;
    }

    public double ofRight(double percent) {
        if (xIsLog) {
            return Math.pow(10,
                Math.log10(xUpper)
                - Math.log10(xUpper / xLower) * percent
            );
        }
        return xUpper - xLength * percent;
    }

    public double ofGround(double percent) {
        if (yIsLog) {
            return Math.pow(10,
                Math.log10(yLower)
                + Math.log10(yUpper / yLower) * percent
            );
        }
        return yLower + yLength * percent;
    }

    public double atTop() {
        return yUpper;
    }

    public double atGround() {
        return yLower;
    }

    public double atRight() {
        return xUpper;
    }

    public double atLeft() {
        return xLower;
    }

    public double above(double percent, double base) {
        if (yIsLog) {
            return Math.pow(10,
                Math.log10(base)
                + Math.log10(yUpper / yLower) * percent
            );
        }
        return base + yLength * percent;
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org