Mercurial > dive4elements > gnv-client
diff gnv-artifacts/src/main/java/de/intevation/gnv/jfreechart/PolygonDataset.java @ 540:80630520e25a
merged gnv-artifacts/0.4
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:13:49 +0200 |
parents | 92b7ccbf6163 |
children | b1f5f2a8840f |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/jfreechart/PolygonDataset.java Fri Sep 28 12:13:49 2012 +0200 @@ -0,0 +1,110 @@ +package de.intevation.gnv.jfreechart; + +import java.util.List; +import java.util.Collection; +import java.util.ArrayList; + +import org.jfree.data.Range; +import org.jfree.data.general.AbstractSeriesDataset; + +/** + * @author Ingo Weinzierl <ingo.weinzierl@intevation.de> + */ +public class PolygonDataset +extends AbstractSeriesDataset +{ + /** PolygonSeries included in this Dataset */ + private List data; + + + public PolygonDataset() { + data = new ArrayList(); + } + + public PolygonDataset(Collection series) { + data = new ArrayList(series); + } + + public PolygonDataset(PolygonSeries series) { + this(); + + if (series != null) { + data.add(series); + } + } + + + public void addSeries(PolygonSeries series) { + if (series == null) + throw new IllegalArgumentException("Null 'series' argument."); + + data.add(series); + } + + public void addAllSeries(Collection<PolygonSeries> series) { + data.addAll(series); + } + + public Range getDomainBounds() { + double lower = Double.POSITIVE_INFINITY; + double upper = Double.NEGATIVE_INFINITY; + int seriesCount = getSeriesCount(); + + for (int s = 0; s < seriesCount; s++) { + PolygonSeries series = getSeries(s); + + Range domainRange = series.getDomainBounds(); + double minX = domainRange.getLowerBound(); + if (!Double.isNaN(minX)) { + lower = Math.min(lower, minX); + } + + double maxX = domainRange.getUpperBound(); + if (!Double.isNaN(maxX)) { + upper = Math.max(upper, maxX); + } + } + + return new Range(lower, upper); + } + + + public Range getRangeBounds() { + double lower = Double.POSITIVE_INFINITY; + double upper = Double.NEGATIVE_INFINITY; + int seriesCount = getSeriesCount(); + + for (int i = 0; i < seriesCount; i++) { + PolygonSeries series = getSeries(i); + + Range range = series.getRangeBounds(); + double minX = range.getLowerBound(); + if (!Double.isNaN(minX)) { + lower = Math.min(lower, minX); + } + + double maxX = range.getUpperBound(); + if (!Double.isNaN(maxX)) { + upper = Math.max(upper, maxX); + } + } + + return new Range(lower, upper); + } + + + public int getSeriesCount() { + return data.size(); + } + + + public Comparable getSeriesKey(int series) { + return ((PolygonSeries)data.get(series)).getKey(); + } + + + public PolygonSeries getSeries(int idx) { + return (PolygonSeries)data.get(idx); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :