Mercurial > dive4elements > river
changeset 8316:c086b06b81e5
Make ChartArea and thus annotations sensible for logarithmic axes (plus some minor cleanup).
author | "Tom Gottfried <tom@intevation.de>" |
---|---|
date | Wed, 24 Sep 2014 13:29:34 +0200 |
parents | d4c501d2c098 |
children | c04c66839288 |
files | artifacts/src/main/java/org/dive4elements/river/artifacts/MainValuesArtifact.java artifacts/src/main/java/org/dive4elements/river/exports/ChartArea.java artifacts/src/main/java/org/dive4elements/river/exports/ChartGenerator.java artifacts/src/main/java/org/dive4elements/river/exports/CrossSectionGenerator.java artifacts/src/main/java/org/dive4elements/river/exports/process/MiscDischargeProcessor.java artifacts/src/main/java/org/dive4elements/river/jfree/AnnotationHelper.java |
diffstat | 6 files changed, 56 insertions(+), 36 deletions(-) [+] |
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/MainValuesArtifact.java Wed Sep 24 12:16:53 2014 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/MainValuesArtifact.java Wed Sep 24 13:29:34 2014 +0200 @@ -127,28 +127,24 @@ DURATION_MAINVALUES_Q, Resources.getMsg( callMeta, - "facet.discharge_curves.mainvalues.q", "facet.discharge_curves.mainvalues.q"), false); Facet qfacet1 = new MainValuesQFacet( COMPUTED_DISCHARGE_MAINVALUES_Q, Resources.getMsg( callMeta, - "facet.discharge_curves.mainvalues.q", "facet.discharge_curves.mainvalues.q"), false); Facet qfacet2 = new MainValuesQFacet( MAINVALUES_Q, Resources.getMsg( callMeta, - "facet.discharge_curves.mainvalues.q", "facet.discharge_curves.mainvalues.q"), true); Facet qfacet3 = new MainValuesQFacet( HISTORICAL_DISCHARGE_MAINVALUES_Q, Resources.getMsg( callMeta, - "historical_discharge.mainvalues.q", "historical_discharge.mainvalues.q"), false); @@ -162,21 +158,18 @@ COMPUTED_DISCHARGE_MAINVALUES_W, Resources.getMsg( callMeta, - "facet.discharge_curves.mainvalues.w", "facet.discharge_curves.mainvalues.w"), false); Facet wfacet2 = new MainValuesWFacet( MAINVALUES_W, Resources.getMsg( callMeta, - "facet.discharge_curves.mainvalues.w", "facet.discharge_curves.mainvalues.w"), true); Facet wfacet3 = new MainValuesWFacet( HISTORICAL_DISCHARGE_MAINVALUES_W, Resources.getMsg( callMeta, - "historical_discharge.mainvalues.w", "historical_discharge.mainvalues.w"), true); fs.add(wfacet1);
--- a/artifacts/src/main/java/org/dive4elements/river/exports/ChartArea.java Wed Sep 24 12:16:53 2014 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/exports/ChartArea.java Wed Sep 24 13:29:34 2014 +0200 @@ -9,57 +9,84 @@ package org.dive4elements.river.exports; import org.jfree.chart.axis.ValueAxis; - -import org.jfree.data.Range; +import org.jfree.chart.axis.LogarithmicAxis; /** Two Ranges that span a rectangular area. */ public class ChartArea { - protected Range xRange; - protected Range yRange; - - public ChartArea(Range rangeX, Range rangeY) { - this.xRange = rangeX; - this.yRange = rangeY; - } + 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.xRange = axisX.getRange(); - this.yRange = axisY.getRange(); + 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) { - return xRange.getLowerBound() - + xRange.getLength() * percent; + if (xIsLog) { + return Math.pow(10, + Math.log10(xLower) + + Math.log10(xUpper / xLower) * percent + ); + } + return xLower + xLength * percent; } public double ofRight(double percent) { - return xRange.getUpperBound() - - xRange.getLength() * percent; + if (xIsLog) { + return Math.pow(10, + Math.log10(xUpper) + - Math.log10(xUpper / xLower) * percent + ); + } + return xUpper - xLength * percent; } public double ofGround(double percent) { - return yRange.getLowerBound() - + yRange.getLength() * percent; + if (yIsLog) { + return Math.pow(10, + Math.log10(yLower) + + Math.log10(yUpper / yLower) * percent + ); + } + return yLower + yLength * percent; } public double atTop() { - return yRange.getUpperBound(); + return yUpper; } public double atGround() { - return yRange.getLowerBound(); + return yLower; } public double atRight() { - return xRange.getUpperBound(); + return xUpper; } public double atLeft() { - return xRange.getLowerBound(); + return xLower; } public double above(double percent, double base) { - return base + yRange.getLength() * percent; + 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 :
--- a/artifacts/src/main/java/org/dive4elements/river/exports/ChartGenerator.java Wed Sep 24 12:16:53 2014 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/exports/ChartGenerator.java Wed Sep 24 13:29:34 2014 +0200 @@ -431,8 +431,8 @@ // OPTMIMIZE: Pre-calculate positions ChartArea area = new ChartArea( - plot.getDomainAxis(0).getRange(), - plot.getRangeAxis().getRange()); + plot.getDomainAxis(0), + plot.getRangeAxis()); // Walk over all Annotation sets. for (RiverAnnotation fa: annotations) {
--- a/artifacts/src/main/java/org/dive4elements/river/exports/CrossSectionGenerator.java Wed Sep 24 12:16:53 2014 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/exports/CrossSectionGenerator.java Wed Sep 24 13:29:34 2014 +0200 @@ -176,8 +176,8 @@ // OPTMIMIZE: Pre-calculate positions ChartArea area = new ChartArea( - plot.getDomainAxis(0).getRange(), - plot.getRangeAxis().getRange()); + plot.getDomainAxis(0), + plot.getRangeAxis()); for(RiverAnnotation fa : this.annotations) {
--- a/artifacts/src/main/java/org/dive4elements/river/exports/process/MiscDischargeProcessor.java Wed Sep 24 12:16:53 2014 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/exports/process/MiscDischargeProcessor.java Wed Sep 24 13:29:34 2014 +0200 @@ -193,7 +193,7 @@ ) { if (!(generator instanceof DischargeCurveGenerator)) { log.error("DischargeProcessor can only be used in " + - " in DischargeCurveGenerator-classes."); + "DischargeCurveGenerator-classes."); return; } log.debug("doRiverAnnotationOut");
--- a/artifacts/src/main/java/org/dive4elements/river/jfree/AnnotationHelper.java Wed Sep 24 12:16:53 2014 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/jfree/AnnotationHelper.java Wed Sep 24 13:29:34 2014 +0200 @@ -58,8 +58,8 @@ // OPTMIMIZE: Pre-calculate positions ChartArea area = new ChartArea( - plot.getDomainAxis(0).getRange(), - plot.getRangeAxis().getRange()); + plot.getDomainAxis(0), + plot.getRangeAxis()); // Walk over all Annotation sets. for (RiverAnnotation fa: annotations) {