[PATCH] Make ChartArea and thus annotations sensible for logarithmic axes (plus some minor cleanup)

Wald Commits scm-commit at wald.intevation.org
Wed Sep 24 13:29:38 CEST 2014


# HG changeset patch
# User "Tom Gottfried <tom at intevation.de>"
# Date 1411558174 -7200
# Node ID c086b06b81e57ba4108d373f597e94a485463578
# Parent  d4c501d2c09880ac9c5bed66ad710572adab531b
Make ChartArea and thus annotations sensible for logarithmic axes (plus some minor cleanup).

diff -r d4c501d2c098 -r c086b06b81e5 artifacts/src/main/java/org/dive4elements/river/artifacts/MainValuesArtifact.java
--- 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);
diff -r d4c501d2c098 -r c086b06b81e5 artifacts/src/main/java/org/dive4elements/river/exports/ChartArea.java
--- 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 :
diff -r d4c501d2c098 -r c086b06b81e5 artifacts/src/main/java/org/dive4elements/river/exports/ChartGenerator.java
--- 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) {
diff -r d4c501d2c098 -r c086b06b81e5 artifacts/src/main/java/org/dive4elements/river/exports/CrossSectionGenerator.java
--- 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) {
 
diff -r d4c501d2c098 -r c086b06b81e5 artifacts/src/main/java/org/dive4elements/river/exports/process/MiscDischargeProcessor.java
--- 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");
diff -r d4c501d2c098 -r c086b06b81e5 artifacts/src/main/java/org/dive4elements/river/jfree/AnnotationHelper.java
--- 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) {


More information about the Dive4Elements-commits mailing list