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: /**
sascha@780: * @author Ingo Weinzierl
sascha@422: */
sascha@422: public class PolygonDataset
sascha@422: extends AbstractSeriesDataset
sascha@422: {
sascha@422: /** PolygonSeries included in this Dataset */
sascha@422: private List data;
sascha@422:
sascha@422:
sascha@422: public PolygonDataset() {
sascha@436: data = new ArrayList();
sascha@422: }
sascha@422:
sascha@436: public PolygonDataset(Collection series) {
sascha@436: data = new ArrayList(series);
sascha@436: }
sascha@422:
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:
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:
sascha@447: public void addAllSeries(Collection series) {
sascha@447: data.addAll(series);
sascha@447: }
sascha@422:
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:
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:
sascha@422: public int getSeriesCount() {
sascha@422: return data.size();
sascha@422: }
sascha@422:
sascha@422:
sascha@422: public Comparable getSeriesKey(int series) {
sascha@422: return ((PolygonSeries)data.get(series)).getKey();
sascha@422: }
sascha@422:
sascha@422:
sascha@422: public PolygonSeries getSeries(int idx) {
sascha@422: return (PolygonSeries)data.get(idx);
sascha@422: }
sascha@422: }
sascha@422: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :