Mercurial > dive4elements > river
changeset 8455:6dfc3a1fc70d
(issue1764) Set upper-time and lower-time for time series axes
This introduces new optional chart settings. Upper-time and
lower-time. If they are present the client can show a date selection
and they can be used for the domain axis in timeseries diagrams.
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Wed, 29 Oct 2014 19:51:39 +0100 |
parents | 7003cf5c19ed |
children | 572c102b1819 |
files | artifacts/src/main/java/org/dive4elements/river/exports/AxisSection.java artifacts/src/main/java/org/dive4elements/river/exports/ChartGenerator.java artifacts/src/main/java/org/dive4elements/river/exports/ChartSettings.java artifacts/src/main/java/org/dive4elements/river/exports/TimeseriesChartGenerator.java |
diffstat | 4 files changed, 79 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/exports/AxisSection.java Wed Oct 29 19:49:18 2014 +0100 +++ b/artifacts/src/main/java/org/dive4elements/river/exports/AxisSection.java Wed Oct 29 19:51:39 2014 +0100 @@ -28,6 +28,8 @@ public static final String FIXATION_ATTR = "fixation"; public static final String UPPERRANGE_ATTR = "upper"; public static final String LOWERRANGE_ATTR = "lower"; + public static final String UPPERRANGE_TIME_ATTR = "upper-time"; + public static final String LOWERRANGE_TIME_ATTR = "lower-time"; public AxisSection() { @@ -107,6 +109,34 @@ return getDoubleValue(LOWERRANGE_ATTR); } + public void setUpperTimeRange(long upperRange) { + setStringValue(UPPERRANGE_TIME_ATTR, Long.toString(upperRange)); + } + + /* return the upper time rang limit as a long value that can be converted + * to a date. If none is set null is returned. */ + public Long getUpperTimeRange() { + try { + return Long.valueOf(getStringValue(UPPERRANGE_TIME_ATTR)); + } catch (NumberFormatException e) { + return null; + } + } + + public void setLowerTimeRange(long lowerRange) { + setStringValue(LOWERRANGE_TIME_ATTR, Long.toString(lowerRange)); + } + + /* See getUpperTimeRange */ + public Long getLowerTimeRange() { + try { + return Long.valueOf(getStringValue(LOWERRANGE_TIME_ATTR)); + } catch (NumberFormatException e) { + return null; + } + } + + @Override public void toXML(Node parent) {
--- a/artifacts/src/main/java/org/dive4elements/river/exports/ChartGenerator.java Wed Oct 29 19:49:18 2014 +0100 +++ b/artifacts/src/main/java/org/dive4elements/river/exports/ChartGenerator.java Wed Oct 29 19:51:39 2014 +0100 @@ -952,8 +952,20 @@ Boolean fixed = as.isFixed(); + if (fixed != null && fixed) { - if (fixed != null && fixed) { + /* Only time series charts have time ranges so prefer those. */ + if (axisId.equals("X")) { + Long lowerTime = as.getLowerTimeRange(); + Long upperTime = as.getUpperTimeRange(); + if ( lowerTime != null && upperTime != null ) { + log.debug("Using time range: " + lowerTime + " - " + upperTime); + return lowerTime < upperTime + ? new Range(lowerTime, upperTime) + : new Range(upperTime, lowerTime); + } + } + Double upper = as.getUpperRange(); Double lower = as.getLowerRange();
--- a/artifacts/src/main/java/org/dive4elements/river/exports/ChartSettings.java Wed Oct 29 19:49:18 2014 +0100 +++ b/artifacts/src/main/java/org/dive4elements/river/exports/ChartSettings.java Wed Oct 29 19:51:39 2014 +0100 @@ -212,6 +212,8 @@ String low = XMLUtils.xpathString(axis, "lower", null); String up = XMLUtils.xpathString(axis, "upper", null); String sugLabel = XMLUtils.xpathString(axis, "suggested-label", null); + String lowTime = XMLUtils.xpathString(axis, "lower-time", null); + String upTime = XMLUtils.xpathString(axis, "upper-time", null); if (log.isDebugEnabled()) { log.debug("Found axis id: '" + id + "'"); @@ -220,6 +222,8 @@ log.debug("Found axis fixation: '" + fixation + "'"); log.debug("Found axis lower: '" + low + "'"); log.debug("Found axis upper: '" + up + "'"); + log.debug("Found axis lower-time:'" + lowTime + "'"); + log.debug("Found axis upper-time:'" + upTime + "'"); log.debug("Found axis sug. label:'" + sugLabel + "'"); } @@ -227,8 +231,13 @@ section.setLabel(label); section.setFontSize(Integer.parseInt(fSize.length() > 0 ? fSize : "-1")); section.setFixed(Boolean.valueOf(fixation)); - section.setLowerRange(Double.parseDouble(low.length() > 0 ? low : "0")); - section.setUpperRange(Double.parseDouble(up.length() > 0 ? up : "0")); + if (upTime != null && !upTime.isEmpty() && lowTime != null && !lowTime.isEmpty()) { + section.setLowerTimeRange(Long.parseLong(lowTime)); + section.setUpperTimeRange(Long.parseLong(upTime)); + } else { + section.setLowerRange(Double.parseDouble(low.length() > 0 ? low : "0")); + section.setUpperRange(Double.parseDouble(up.length() > 0 ? up : "0")); + } section.setSuggestedLabel(sugLabel); target.addAxisSection(section);
--- a/artifacts/src/main/java/org/dive4elements/river/exports/TimeseriesChartGenerator.java Wed Oct 29 19:49:18 2014 +0100 +++ b/artifacts/src/main/java/org/dive4elements/river/exports/TimeseriesChartGenerator.java Wed Oct 29 19:51:39 2014 +0100 @@ -141,7 +141,7 @@ * Shortcut, especially to be overridden in (LS) charts where * axis could be inverted. */ - protected double getLeftX() { + protected long getLeftX() { return (Long)getXBounds(0).getLower(); } @@ -151,7 +151,7 @@ * Shortcut, especially to be overridden in (LS) charts where * axis could be inverted. */ - protected double getRightX() { + protected long getRightX() { return (Long)getXBounds(0).getUpper(); } @@ -839,5 +839,28 @@ } } + /* Create an axis section with setUpperTimeRange and + * setLowerTimeRange */ + @Override + protected List<AxisSection> buildXAxisSections() { + List<AxisSection> axisSections = new ArrayList<AxisSection>(); + + String identifier = "X"; + + AxisSection axisSection = new AxisSection(); + axisSection.setIdentifier(identifier); + axisSection.setLabel(getXAxisLabel()); + axisSection.setFontSize(14); + axisSection.setFixed(false); + + axisSection.setUpperTimeRange(getRightX()); + axisSection.setLowerTimeRange(getLeftX()); + + axisSections.add(axisSection); + + return axisSections; + } + + } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :