sascha@422: package de.intevation.gnv.jfreechart; sascha@422: sascha@779: import java.util.ArrayList; sascha@779: import java.util.Collection; sascha@422: import java.util.List; sascha@422: sascha@422: import org.jfree.data.Range; sascha@779: sascha@422: import org.jfree.data.general.AbstractSeriesDataset; sascha@422: sascha@422: /** ingo@795: * An implementation of {@link org.jfree.data.xy.XYDataset} to create 2D charts. ingo@795: * This dataset contains several PolygonSeries and is used by ingo@795: * PolygonRenderer to draw its items into a 2D chart. sascha@803: * sascha@780: * @author Ingo Weinzierl sascha@422: */ sascha@422: public class PolygonDataset sascha@422: extends AbstractSeriesDataset sascha@422: { ingo@795: /** ingo@795: * PolygonSeries included in this Dataset ingo@795: */ sascha@422: private List data; sascha@422: sascha@422: ingo@795: /** ingo@795: * Constructor. ingo@795: */ sascha@422: public PolygonDataset() { sascha@436: data = new ArrayList(); sascha@422: } sascha@422: ingo@795: /** ingo@795: * Constructs a new PolygonDataset containing multiple PolygonSeries. ingo@795: * ingo@795: * @param series A collection containing some PolygonSeries. ingo@795: */ sascha@436: public PolygonDataset(Collection series) { sascha@436: data = new ArrayList(series); sascha@436: } sascha@422: ingo@795: /** ingo@795: * Constructs a PolygonDataset with a single PolygonSeries. sascha@803: * ingo@795: * @param series A PolygonSeries. ingo@795: */ sascha@422: public PolygonDataset(PolygonSeries series) { sascha@436: this(); sascha@422: sascha@422: if (series != null) { sascha@422: data.add(series); sascha@422: } sascha@422: } sascha@422: sascha@422: ingo@795: /** ingo@795: * ingo@795: * @param series ingo@795: */ sascha@422: public void addSeries(PolygonSeries series) { sascha@422: if (series == null) sascha@422: throw new IllegalArgumentException("Null 'series' argument."); sascha@422: sascha@422: data.add(series); sascha@422: } sascha@422: ingo@795: /** ingo@795: * ingo@795: * @param series ingo@795: */ sascha@447: public void addAllSeries(Collection series) { sascha@447: data.addAll(series); sascha@447: } sascha@422: ingo@795: /** ingo@795: * Retrieves the x-axis range of all PolygonSeries in this dataset. ingo@795: * ingo@795: * @return range of the x-axis. ingo@795: */ sascha@422: public Range getDomainBounds() { sascha@422: double lower = Double.POSITIVE_INFINITY; sascha@422: double upper = Double.NEGATIVE_INFINITY; sascha@422: int seriesCount = getSeriesCount(); sascha@422: sascha@422: for (int s = 0; s < seriesCount; s++) { sascha@422: PolygonSeries series = getSeries(s); sascha@422: sascha@422: Range domainRange = series.getDomainBounds(); sascha@422: double minX = domainRange.getLowerBound(); sascha@422: if (!Double.isNaN(minX)) { sascha@422: lower = Math.min(lower, minX); sascha@422: } sascha@422: sascha@422: double maxX = domainRange.getUpperBound(); sascha@422: if (!Double.isNaN(maxX)) { sascha@422: upper = Math.max(upper, maxX); sascha@422: } sascha@422: } sascha@422: sascha@422: return new Range(lower, upper); sascha@422: } sascha@422: sascha@422: ingo@795: /** ingo@795: * Retrieves the y-axis range of all PolygonSeries in this dataset. ingo@795: * ingo@795: * @return the y-axis range. ingo@795: */ sascha@422: public Range getRangeBounds() { sascha@422: double lower = Double.POSITIVE_INFINITY; sascha@422: double upper = Double.NEGATIVE_INFINITY; sascha@422: int seriesCount = getSeriesCount(); sascha@422: sascha@422: for (int i = 0; i < seriesCount; i++) { sascha@422: PolygonSeries series = getSeries(i); sascha@422: sascha@422: Range range = series.getRangeBounds(); sascha@422: double minX = range.getLowerBound(); sascha@422: if (!Double.isNaN(minX)) { sascha@422: lower = Math.min(lower, minX); sascha@422: } sascha@422: sascha@422: double maxX = range.getUpperBound(); sascha@422: if (!Double.isNaN(maxX)) { sascha@422: upper = Math.max(upper, maxX); sascha@422: } sascha@422: } sascha@422: sascha@422: return new Range(lower, upper); sascha@422: } sascha@422: sascha@422: ingo@795: /** ingo@795: * Returns the number of series in this dataset. ingo@795: * ingo@795: * @return the number of series in this dataset. ingo@795: */ sascha@422: public int getSeriesCount() { sascha@422: return data.size(); sascha@422: } sascha@422: sascha@422: ingo@795: /** ingo@795: * Returns the key for a series. ingo@795: * ingo@795: * @param index Index of a specific series. ingo@795: * @return the series key of the series with the given index. ingo@795: */ ingo@795: public Comparable getSeriesKey(int index) { ingo@795: return ((PolygonSeries)data.get(index)).getKey(); sascha@422: } sascha@422: sascha@422: ingo@795: /** ingo@795: * ingo@795: * @param idx Index. ingo@795: * @return the series with the given index. ingo@795: */ sascha@422: public PolygonSeries getSeries(int idx) { sascha@422: return (PolygonSeries)data.get(idx); sascha@422: } sascha@422: } ingo@795: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :