Mercurial > dive4elements > river
changeset 2240:e9173de1026c
The HistoricalDischargeCurveGenerator now creates new AxisDataset objects and new TimeSeriesCollections for each Facet.
flys-artifacts/trunk@3887 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Thu, 02 Feb 2012 16:39:50 +0000 |
parents | e7843533f086 |
children | 2b232871ba28 |
files | flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/exports/HistoricalDischargeCurveGenerator.java |
diffstat | 2 files changed, 77 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Thu Feb 02 16:38:12 2012 +0000 +++ b/flys-artifacts/ChangeLog Thu Feb 02 16:39:50 2012 +0000 @@ -1,3 +1,8 @@ +2012-02-02 Ingo Weinzierl <ingo@intevation.de> + + * src/main/java/de/intevation/flys/exports/HistoricalDischargeCurveGenerator.java: + Create new AxisDatasets and new TimeSeriesCollections for each Facet. + 2012-02-02 Ingo Weinzierl <ingo@intevation.de> * src/main/java/de/intevation/flys/artifacts/model/WQTimerange.java: Added a
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/HistoricalDischargeCurveGenerator.java Thu Feb 02 16:38:12 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/HistoricalDischargeCurveGenerator.java Thu Feb 02 16:39:50 2012 +0000 @@ -1,6 +1,7 @@ package de.intevation.flys.exports; import java.awt.Font; +import java.util.Date; import org.w3c.dom.Document; @@ -9,10 +10,18 @@ import org.jfree.chart.JFreeChart; import org.jfree.chart.axis.NumberAxis; +import org.jfree.data.general.SeriesException; +import org.jfree.data.time.Minute; +import org.jfree.data.time.RegularTimePeriod; +import org.jfree.data.time.TimeSeries; +import org.jfree.data.time.TimeSeriesCollection; + import de.intevation.artifactdatabase.state.ArtifactAndFacet; import de.intevation.flys.artifacts.FLYSArtifact; import de.intevation.flys.artifacts.model.FacetTypes; +import de.intevation.flys.artifacts.model.Timerange; +import de.intevation.flys.artifacts.model.WQTimerange; /** @@ -135,6 +144,69 @@ { logger.debug("doHistoricalDischargeOut(): description = " + desc); logger.warn("TODO IMPLEMENT ME"); + + WQTimerange wqt = (WQTimerange) data; + + TimeSeriesCollection tsc = newTimeSeriesCollection(wqt, desc); + + addAxisDataset(tsc, 0, visible); + } + + + /** + * Creates a new TimeSeriesCollection with a single TimeSeries. The + * TimeSeries will consist of two RegularTimePeriods for each W/Q value + * provided by <i>wqt</i>. This has the effect, that the line in the chart + * looks like a "step chart". + */ + protected TimeSeriesCollection newTimeSeriesCollection( + WQTimerange wqt, + String desc + ) { + logger.debug("Create new TimeSeriesCollection for: " + desc); + + TimeSeriesCollection tsc = new TimeSeriesCollection(); + TimeSeries series = new TimeSeries(desc); + + Timerange tr = null; + double[] res = new double[2]; + + for (int i = 0, n = wqt.size(); i < n; i++) { + res = wqt.get(i, res); + + RegularTimePeriod[] rtp = newRegularTimePeriod(wqt.getTimerange(i)); + + try { + // TODO WHICH (W/Q) IS REQUIRED? + series.add(rtp[0], res[1]); + series.add(rtp[1], res[1]); + } + catch (SeriesException se) { + logger.warn("Error while adding TimePeriod: " + se); + } + } + + tsc.addSeries(series); + + return tsc; + } + + + /** + * Creates an array that consists of two <i>Minute</i> periods [start, end]. + * + * @param timerange Supports start and end time. + * + * @return an array with two <i>Minute</i> periods [start, end]. + */ + protected RegularTimePeriod[] newRegularTimePeriod(Timerange timerange) { + Date start = new Date(timerange.getStart()); + Date end = new Date(timerange.getEnd() - 1000 * 60); + + return new RegularTimePeriod[] { + new Minute(start), + new Minute(end) + }; } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :