Mercurial > dive4elements > river
changeset 7241:32db4f89b65f
Add new option to diagram axes "logarithmic" that can be set to an evaluator
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Fri, 04 Oct 2013 17:02:01 +0200 |
parents | bb4a6b0077cf |
children | 69709f490d92 |
files | artifacts/src/main/java/org/dive4elements/river/exports/DiagramAttributes.java artifacts/src/main/java/org/dive4elements/river/exports/DiagramGenerator.java |
diffstat | 2 files changed, 49 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- 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); }
--- 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);