ingo@1115: /* ingo@1115: * Copyright (c) 2010 by Intevation GmbH ingo@1115: * ingo@1115: * This program is free software under the LGPL (>=v2.1) ingo@1115: * Read the file LGPL.txt coming with the software for details ingo@1115: * or visit http://www.gnu.org/licenses/ if it does not exist. ingo@1115: */ ingo@1115: ingo@1071: package de.intevation.gnv.chart; ingo@1071: ingo@1071: import de.intevation.gnv.geobackend.base.Result; ingo@1071: import de.intevation.gnv.geobackend.base.ResultDescriptor; ingo@1071: ingo@1071: import java.util.Collection; ingo@1071: import java.util.Iterator; ingo@1071: import java.util.Locale; ingo@1071: ingo@1071: import org.apache.log4j.Logger; ingo@1071: ingo@1071: import org.jfree.chart.ChartTheme; ingo@1071: ingo@1071: import org.jfree.chart.plot.XYPlot; ingo@1071: ingo@1071: import org.jfree.data.xy.XYSeries; ingo@1071: import org.jfree.data.xy.XYSeriesCollection; ingo@1071: ingo@1071: /** ingo@1071: * This class is used to create xy charts of vertical profiles. ingo@1071: * ingo@1071: * @author Ingo Weinzierl ingo@1071: */ ingo@1071: public class VerticalProfileVectorChart ingo@1071: extends VerticalProfileChart ingo@1071: { ingo@1071: private static Logger logger = ingo@1071: Logger.getLogger(VerticalProfileVectorChart.class); ingo@1071: ingo@1071: public VerticalProfileVectorChart( ingo@1071: ChartLabels labels, ingo@1071: ChartTheme theme, ingo@1071: Collection parameters, ingo@1071: Collection measurements, ingo@1071: Collection dates, ingo@1071: Collection result, ingo@1071: Collection timeGaps, ingo@1071: Locale locale, ingo@1071: boolean linesVisible, ingo@1071: boolean shapesVisible ingo@1071: ) { ingo@1071: super(labels, theme, parameters, measurements, dates, result, ingo@1071: timeGaps, locale, linesVisible, shapesVisible); ingo@1071: } ingo@1071: ingo@1071: ingo@1071: @Override ingo@1071: protected void initData() { ingo@1071: logger.debug("init data for verticalprofile chart with vector data."); ingo@1071: ingo@1085: int items = resultSet.size(); ingo@1085: logger.debug("Found " + items + " items for this chart."); ingo@1085: ingo@1071: Iterator iter = resultSet.iterator(); ingo@1071: Result row = null; ingo@1071: String seriesName = null; ingo@1071: XYSeries series = null; ingo@1071: ingo@1071: int idx = 0; ingo@1071: int startPos = 0; ingo@1071: int endPos = 0; ingo@1071: ingo@1071: double startValue = 0; ingo@1071: double endValue = 0; ingo@1071: ingo@1071: ResultDescriptor rd = null; ingo@1071: int idxSeries = -1; ingo@1071: int idxX = -1; ingo@1071: int idxY = -1; ingo@1071: ingo@1071: Result[] results = ingo@1071: (Result[]) resultSet.toArray(new Result[resultSet.size()]); ingo@1071: ingo@1071: while (iter.hasNext()) { ingo@1071: row = (Result) iter.next(); ingo@1071: ingo@1071: if (rd == null) { ingo@1071: rd = row.getResultDescriptor(); ingo@1071: idxSeries = rd.getColumnIndex("SERIES"); ingo@1071: idxX = rd.getColumnIndex("XORDINATE"); ingo@1071: idxY = rd.getColumnIndex("YORDINATE"); ingo@1071: } ingo@1071: ingo@1071: if (!row.getString(idxSeries).equals(seriesName)) { ingo@1071: logger.debug("prepare data/plot for next dataset."); ingo@1071: ingo@1071: if (series != null) { ingo@1085: if (startPos >= 0 && endPos < items) { ingo@1085: gapDetection(results, series, startPos, endPos); ingo@1085: } ingo@1085: ingo@1071: addSeries(series, seriesName, idx); ingo@1071: ingo@1071: startPos = endPos + 1; ingo@1071: } ingo@1071: ingo@1071: seriesName = row.getString(idxSeries); ingo@1071: ingo@1071: logger.debug("next data is '" + seriesName + "'"); ingo@1071: series = new XYSeries(seriesName); ingo@1071: } ingo@1071: ingo@1071: addValue(row, series); ingo@1071: Object x = getValue(row); ingo@1071: Double y = row.getDouble(idxY); ingo@1071: if (x != null && y != null) { ingo@1071: storeMaxRange(ranges, y, seriesName); ingo@1071: storeMaxValue(values, x, seriesName); ingo@1071: } ingo@1071: ingo@1071: endPos++; ingo@1071: } ingo@1071: ingo@1071: if (results.length == 0) ingo@1071: return; ingo@1071: ingo@1085: if (startPos >= 0 && endPos < items) { ingo@1085: gapDetection(results, series, startPos, endPos); ingo@1085: } ingo@1071: addSeries(series, seriesName, idx); ingo@1071: ingo@1071: addDatasets(); ingo@1071: } ingo@1071: ingo@1071: ingo@1071: @Override ingo@1071: protected void addDatasets() { ingo@1071: XYPlot plot = chart.getXYPlot(); ingo@1071: int idx = 0; ingo@1071: ingo@1071: XYSeriesCollection sc = null; ingo@1071: Iterator iter = datasets.keySet().iterator(); ingo@1071: ingo@1071: while (iter.hasNext()) { ingo@1071: String key = (String) iter.next(); ingo@1071: sc = (XYSeriesCollection)datasets.get(key); ingo@1071: plot.setDataset(idx, sc ); ingo@1071: logger.debug("Added " + key + " parameter to plot."); ingo@1071: prepareAxis(key, idx); ingo@1071: adjustRenderer( ingo@1071: idx++, ingo@1071: sc.getSeriesCount(), ingo@1071: linesVisible, ingo@1071: shapesVisible ingo@1071: ); ingo@1071: } ingo@1085: ingo@1085: prepareRangeAxis(null, -1); ingo@1071: } ingo@1071: } ingo@1071: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :