ingo@1040: package de.intevation.gnv.chart; ingo@1040: ingo@1040: import de.intevation.gnv.geobackend.base.Result; ingo@1040: import de.intevation.gnv.geobackend.base.ResultDescriptor; ingo@1040: ingo@1040: import java.util.Collection; ingo@1040: import java.util.Date; ingo@1040: import java.util.Iterator; ingo@1040: import java.util.Locale; ingo@1040: ingo@1040: import org.apache.log4j.Logger; ingo@1040: ingo@1040: import org.jfree.chart.ChartTheme; ingo@1040: import org.jfree.chart.plot.XYPlot; ingo@1040: ingo@1040: import org.jfree.data.time.Minute; ingo@1040: import org.jfree.data.time.TimeSeries; ingo@1040: import org.jfree.data.time.TimeSeriesCollection; ingo@1040: ingo@1040: ingo@1040: /** ingo@1040: * This class is used to create timeseries charts that contain components of a ingo@1040: * vector parameter. The domain axis contains multiple date/time objects. ingo@1040: * ingo@1040: * @author Ingo Weinzierl ingo@1040: */ ingo@1040: public class TimeSeriesVectorChart extends TimeSeriesChart { ingo@1040: ingo@1040: private static Logger logger =Logger.getLogger(TimeSeriesVectorChart.class); ingo@1040: ingo@1040: public TimeSeriesVectorChart( ingo@1040: ChartLabels labels, ingo@1040: ChartTheme theme, ingo@1040: Collection parameters, ingo@1040: Collection measurements, ingo@1040: Collection dates, ingo@1040: Collection result, ingo@1040: Collection timeGaps, ingo@1040: Locale locale, ingo@1040: boolean linesVisible, ingo@1040: boolean shapesVisible ingo@1040: ) { ingo@1040: super(labels, theme, parameters, measurements, dates, result, ingo@1040: timeGaps, locale, linesVisible, shapesVisible); ingo@1040: } ingo@1040: ingo@1040: ingo@1040: @Override ingo@1040: protected void initData() { ingo@1040: logger.debug("init data for timeseries vector chart"); ingo@1040: ingo@1040: Iterator iter = resultSet.iterator(); ingo@1040: Result row = null; ingo@1040: String seriesName = null; ingo@1040: TimeSeries series = null; ingo@1040: ingo@1040: int idx = 0; ingo@1040: int startPos = 0; ingo@1040: int endPos = 0; ingo@1040: Date startDate = null; ingo@1040: Date endDate = null; ingo@1040: ingo@1040: ResultDescriptor rd = null; ingo@1040: int idxSeries = -1; ingo@1040: int idxX = -1; ingo@1040: int idxY = -1; ingo@1040: ingo@1040: Result[] results = ingo@1040: (Result[]) resultSet.toArray(new Result[resultSet.size()]); ingo@1040: ingo@1040: while (iter.hasNext()) { ingo@1040: row = (Result) iter.next(); ingo@1040: ingo@1040: if (rd == null) { ingo@1040: rd = row.getResultDescriptor(); ingo@1040: idxSeries = rd.getColumnIndex("SERIES"); ingo@1040: idxX = rd.getColumnIndex("XORDINATE"); ingo@1040: idxY = rd.getColumnIndex("YORDINATE"); ingo@1040: } ingo@1040: ingo@1040: // add current data to plot and prepare for next one ingo@1040: if (!row.getString(idxSeries).equals(seriesName)) { ingo@1040: logger.debug("prepare data/plot for next dataset"); ingo@1040: ingo@1040: if(series != null) { ingo@1040: // add gaps before adding series to chart ingo@1040: startDate = results[startPos].getDate(idxX); ingo@1040: endDate = results[endPos-1].getDate(idxX); ingo@1040: addGaps(results,series,startDate,endDate,startPos,endPos); ingo@1040: addSeries(series, seriesName, idx); ingo@1040: ingo@1040: startPos = endPos + 1; ingo@1040: } ingo@1040: ingo@1040: // prepare variables for next plot ingo@1040: seriesName = row.getString(idxSeries); ingo@1040: ingo@1040: logger.debug("next dataset is '" + seriesName + "'"); ingo@1040: series = new TimeSeries(seriesName, Minute.class); ingo@1040: } ingo@1040: ingo@1040: addValue(row, series); ingo@1040: storeMaxRange(ranges, row.getDouble(idxY), seriesName); ingo@1040: endPos++; ingo@1040: } ingo@1040: ingo@1040: if (startPos < results.length && endPos-1 < results.length) { ingo@1040: // add the last dataset if existing to plot and prepare its axis ingo@1040: startDate = results[startPos].getDate(idxX); ingo@1040: endDate = results[endPos-1].getDate(idxX); ingo@1040: addGaps(results, series, startDate, endDate, startPos, endPos); ingo@1040: addSeries(series, seriesName, idx); ingo@1040: } ingo@1040: ingo@1040: addDatasets(); ingo@1040: } ingo@1040: ingo@1040: ingo@1040: @Override ingo@1040: protected void addDatasets() { ingo@1040: XYPlot plot = chart.getXYPlot(); ingo@1040: int idx = 0; ingo@1040: ingo@1040: TimeSeriesCollection tsc = null; ingo@1040: Iterator iter = datasets.keySet().iterator(); ingo@1040: ingo@1040: while (iter.hasNext()) { ingo@1040: String key = (String) iter.next(); ingo@1040: tsc = (TimeSeriesCollection)datasets.get(key); ingo@1040: plot.setDataset(idx, tsc ); ingo@1040: logger.debug("Added " + key + " parameter to plot."); ingo@1040: prepareAxis(key, idx); ingo@1040: adjustRenderer( ingo@1040: idx++, ingo@1040: tsc.getSeriesCount(), ingo@1040: linesVisible, ingo@1040: shapesVisible ingo@1040: ); ingo@1040: } ingo@1040: } ingo@1040: } ingo@1040: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :