Mercurial > dive4elements > river
diff artifacts/src/main/java/org/dive4elements/river/exports/DiagramAttributes.java @ 8889:f87f435df856
Allow to configure lower and upper margin of a chart axis
author | gernotbelger |
---|---|
date | Wed, 14 Feb 2018 18:45:01 +0100 |
parents | 32db4f89b65f |
children | 87a242425467 |
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/exports/DiagramAttributes.java Wed Feb 14 18:16:03 2018 +0100 +++ b/artifacts/src/main/java/org/dive4elements/river/exports/DiagramAttributes.java Wed Feb 14 18:45:01 2018 +0100 @@ -109,16 +109,15 @@ } // class Instance public static class AxisAttributes { - private String name; - private boolean isLeftAlign; // TODO: Remove! - private boolean forceAlign; // TODO: Remove! - private boolean includeZero; // TODO: Use Evaluator + private final String name; + private final boolean isLeftAlign; // TODO: Remove! + private final boolean forceAlign; // TODO: Remove! + private final boolean includeZero; // TODO: Use Evaluator - private Evaluator isInverted; - private Evaluator isLog; - - public AxisAttributes() { - } + private final Evaluator isInverted; + private final Evaluator isLog; + private final double lowerMargin; + private final double upperMargin; public AxisAttributes( String name, @@ -126,7 +125,9 @@ boolean forceAlign, boolean includeZero, Evaluator isInverted, - Evaluator isLog + Evaluator isLog, + double lowerMargin, + double upperMargin ) { this.name = name; this.isLeftAlign = isLeftAlign; @@ -134,6 +135,8 @@ this.includeZero = includeZero; this.isInverted = isInverted; this.isLog = isLog; + this.lowerMargin = lowerMargin; + this.upperMargin = upperMargin; } public String getName() { @@ -159,15 +162,20 @@ public Evaluator isLog() { return isLog; } + + public double getLowerMargin() { + return this.lowerMargin; + } + + public double getUpperMargin() { + return this.upperMargin; + } } // class AxisAttributes public class DomainAxisAttributes extends AxisAttributes { private Title title; - public DomainAxisAttributes() { - } - public DomainAxisAttributes( String name, boolean isLeftAlign, @@ -178,7 +186,7 @@ Title title ) { super(name, isLeftAlign, forceAlign, includeZero, isInverted, - isLog); + isLog, 0.0, 0.0); this.title = title; } @@ -375,6 +383,9 @@ String isInverted = axisElement.getAttribute("inverted"); String isLog = axisElement.getAttribute("logarithmic"); + final double lowerMargin = parseDouble( axisElement.getAttribute("lowerMargin"), 0.0 ); + final double upperMargin = parseDouble( axisElement.getAttribute("upperMargin"), 0.0 ); + if (name.isEmpty()) { continue; } @@ -394,7 +405,22 @@ axesAttrs.add(new AxisAttributes( name, isleftAlign, forceAlign, includeZero.equals("true"), - isInvertedE, isLogE)); + isInvertedE, isLogE, + lowerMargin,upperMargin)); + } + } + + private static double parseDouble( final String text, final double defaultValue ) { + if( text == null || text.isEmpty() ) + return defaultValue; + + try { + return Double.parseDouble(text); + } + catch (final NumberFormatException e) { + e.printStackTrace(); + log.error(String.format("Invalid double attribute: ", text), e); + return defaultValue; } }