[PATCH 7 of 8] Add new option to diagram axes "logarithmic" that can be set to an evaluator

Wald Commits scm-commit at wald.intevation.org
Fri Oct 4 17:56:41 CEST 2013


# HG changeset patch
# User Andre Heinecke <aheinecke at intevation.de>
# Date 1380898921 -7200
# Node ID 32db4f89b65fac671f3ad3dafaffa2f3782b3e2f
# Parent  bb4a6b0077cf7bb67f2a43e43261a2e5fb428d70
Add new option to diagram axes "logarithmic" that can be set to an evaluator

diff -r bb4a6b0077cf -r 32db4f89b65f artifacts/src/main/java/org/dive4elements/river/exports/DiagramAttributes.java
--- a/artifacts/src/main/java/org/dive4elements/river/exports/DiagramAttributes.java	Fri Oct 04 17:00:05 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/DiagramAttributes.java	Fri Oct 04 17:02:01 2013 +0200
@@ -115,6 +115,7 @@
         private boolean includeZero; // TODO: Use Evaluator
 
         private Evaluator isInverted;
+        private Evaluator isLog;
 
         public AxisAttributes() {
         }
@@ -124,13 +125,15 @@
             boolean   isLeftAlign,
             boolean   forceAlign,
             boolean   includeZero,
-            Evaluator isInverted
+            Evaluator isInverted,
+            Evaluator isLog
         ) {
             this.name        = name;
             this.isLeftAlign = isLeftAlign;
             this.forceAlign  = forceAlign;
             this.includeZero = includeZero;
             this.isInverted  = isInverted;
+            this.isLog       = isLog;
         }
 
         public String getName() {
@@ -152,6 +155,10 @@
         public Evaluator isInverted() {
             return isInverted;
         }
+
+        public Evaluator isLog() {
+            return isLog;
+        }
     } // class AxisAttributes
 
     public class DomainAxisAttributes extends AxisAttributes {
@@ -167,9 +174,11 @@
             boolean   forceAlign,
             boolean   includeZero,
             Evaluator isInverted,
+            Evaluator isLog,
             Title     title
         ) {
-            super(name, isLeftAlign, forceAlign, includeZero, isInverted);
+            super(name, isLeftAlign, forceAlign, includeZero, isInverted,
+                    isLog);
             this.title = title;
         }
 
@@ -364,6 +373,7 @@
                 axisElement.getAttribute("include-zero").trim();
 
             String isInverted = axisElement.getAttribute("inverted");
+            String isLog = axisElement.getAttribute("logarithmic");
 
             if (name.isEmpty()) {
                 continue;
@@ -379,10 +389,12 @@
 
             Evaluator isInvertedE = parseEvaluator(isInverted, FALSE);
 
+            Evaluator isLogE = parseEvaluator(isLog, FALSE);
+
             axesAttrs.add(new AxisAttributes(
                 name, isleftAlign, forceAlign,
                 includeZero.equals("true"),
-                isInvertedE));
+                isInvertedE, isLogE));
         }
     }
 
@@ -466,8 +478,18 @@
 
     private void parseDomainAxis(Element config) {
         Title title = extractTitle(config, "domain-axis");
-        String includeZero = config.getAttribute("include-zero");
-        String isInverted = config.getAttribute("inverted");
+        String includeZero = "";
+        String isInverted = "";
+        String isLog = "";
+
+        NodeList dAlist = config.getElementsByTagName("domain-axis");
+        if (dAlist.getLength() > 0) {
+            Element dAelement = (Element)dAlist.item(0);
+
+            includeZero = dAelement.getAttribute("include-zero");
+            isInverted = dAelement.getAttribute("inverted");
+            isLog = dAelement.getAttribute("logarithmic");
+        }
 
         domainAxis = new DomainAxisAttributes(
             "X",
@@ -475,6 +497,7 @@
             false,
             includeZero.equals("true"),
             parseEvaluator(isInverted, FALSE),
+            parseEvaluator(isLog, FALSE),
             title);
     }
 
diff -r bb4a6b0077cf -r 32db4f89b65f artifacts/src/main/java/org/dive4elements/river/exports/DiagramGenerator.java
--- a/artifacts/src/main/java/org/dive4elements/river/exports/DiagramGenerator.java	Fri Oct 04 17:00:05 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/DiagramGenerator.java	Fri Oct 04 17:02:01 2013 +0200
@@ -356,7 +356,14 @@
 
 
     protected NumberAxis createXAxis(String label) {
-        return new NumberAxis(label);
+        boolean logarithmic = (Boolean)diagramAttributes.getDomainAxis().
+            isLog().evaluate((D4EArtifact)getMaster(), context);
+
+        if (logarithmic) {
+            return new LogarithmicAxis(label);
+        } else {
+            return new NumberAxis(label);
+        }
     }
 
 
@@ -1090,6 +1097,10 @@
         return axisSections;
     }
 
+    protected String getYAxisLabel(int index) {
+        return getYAxisLabel(diagramAttributes.getAxisName(index));
+    }
+
     /**
      * Returns the Y-Axis label of a chart at position <i>pos</i>.
      *
@@ -1157,7 +1168,15 @@
 
     @Override
     protected NumberAxis createYAxis(int index) {
-        NumberAxis axis = super.createYAxis(index);
+        NumberAxis axis;
+        boolean logarithmic = (Boolean)diagramAttributes.getAxesAttributes().
+            get(index).isLog().evaluate((D4EArtifact)getMaster(), context);
+
+        if (logarithmic) {
+            axis = new LogarithmicAxis(getYAxisLabel(index));
+        } else {
+            axis = super.createYAxis(index);
+        }
 
         if (diagramAttributes.getAxesAttributes().get(index).includeZero()) {
             axis.setAutoRangeIncludesZero(true);


More information about the Dive4elements-commits mailing list