teichmann@5863: /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde teichmann@5863: * Software engineering by Intevation GmbH teichmann@5863: * teichmann@5994: * This file is Free Software under the GNU AGPL (>=v3) teichmann@5863: * and comes with ABSOLUTELY NO WARRANTY! Check out the teichmann@5994: * documentation coming with Dive4Elements River for details. teichmann@5863: */ teichmann@5863: teichmann@5831: package org.dive4elements.river.exports; christian@3242: christian@3242: import org.jfree.chart.axis.ValueAxis; tom@8316: import org.jfree.chart.axis.LogarithmicAxis; christian@3242: sascha@3257: /** Two Ranges that span a rectangular area. */ sascha@3257: public class ChartArea { tom@8316: protected double xLower; tom@8316: protected double xUpper; tom@8316: protected double xLength; tom@8316: protected double yLower; tom@8316: protected double yUpper; tom@8316: protected double yLength; tom@8316: protected boolean xIsLog; tom@8316: protected boolean yIsLog; christian@3242: sascha@3257: public ChartArea(ValueAxis axisX, ValueAxis axisY) { tom@8316: this.xLower = axisX.getRange().getLowerBound(); tom@8316: this.xUpper = axisX.getRange().getUpperBound(); tom@8316: this.xLength= axisX.getRange().getLength(); tom@8316: this.yLower = axisY.getRange().getLowerBound(); tom@8316: this.yUpper = axisY.getRange().getUpperBound(); tom@8316: this.yLength= axisY.getRange().getLength(); tom@8316: this.xIsLog = axisX instanceof LogarithmicAxis; tom@8316: this.yIsLog = axisY instanceof LogarithmicAxis; sascha@3257: } christian@3242: sascha@3257: public double ofLeft(double percent) { tom@8316: if (xIsLog) { tom@8316: return Math.pow(10, tom@8316: Math.log10(xLower) tom@8316: + Math.log10(xUpper / xLower) * percent tom@8316: ); tom@8316: } tom@8316: return xLower + xLength * percent; christian@3242: } sascha@3257: sascha@3257: public double ofRight(double percent) { tom@8316: if (xIsLog) { tom@8316: return Math.pow(10, tom@8316: Math.log10(xUpper) tom@8316: - Math.log10(xUpper / xLower) * percent tom@8316: ); tom@8316: } tom@8316: return xUpper - xLength * percent; sascha@3257: } sascha@3257: sascha@3257: public double ofGround(double percent) { tom@8316: if (yIsLog) { tom@8316: return Math.pow(10, tom@8316: Math.log10(yLower) tom@8316: + Math.log10(yUpper / yLower) * percent tom@8316: ); tom@8316: } tom@8316: return yLower + yLength * percent; sascha@3257: } sascha@3257: sascha@3257: public double atTop() { tom@8316: return yUpper; sascha@3257: } sascha@3257: sascha@3257: public double atGround() { tom@8316: return yLower; sascha@3257: } sascha@3257: sascha@3257: public double atRight() { tom@8316: return xUpper; sascha@3257: } sascha@3257: sascha@3257: public double atLeft() { tom@8316: return xLower; sascha@3257: } sascha@3257: sascha@3257: public double above(double percent, double base) { tom@8316: if (yIsLog) { tom@8316: return Math.pow(10, tom@8316: Math.log10(base) tom@8316: + Math.log10(yUpper / yLower) * percent tom@8316: ); tom@8316: } tom@8316: return base + yLength * percent; sascha@3257: } sascha@3257: } sascha@3259: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :