changeset 2237:60615235e951

Added a ChartHelper class that currently contains a method to compute the xy ranges of an XYDataset. flys-artifacts/trunk@3884 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 02 Feb 2012 15:39:28 +0000
parents c2b15d9c0f43
children 23c7c51df772
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/exports/ChartHelper.java
diffstat 2 files changed, 61 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Thu Feb 02 14:00:40 2012 +0000
+++ b/flys-artifacts/ChangeLog	Thu Feb 02 15:39:28 2012 +0000
@@ -1,3 +1,8 @@
+2012-02-02  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/exports/ChartHelper.java: New helper
+	  class for working with charts.
+
 2012-02-02  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/exports/TimeseriesChartGenerator.java:
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/ChartHelper.java	Thu Feb 02 15:39:28 2012 +0000
@@ -0,0 +1,56 @@
+package de.intevation.flys.exports;
+
+import org.jfree.data.Range;
+import org.jfree.data.xy.XYDataset;
+
+
+/**
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+public class ChartHelper {
+
+    /**
+     * This method returns the ranges of the XYDataset <i>dataset</i> as array
+     * with [xrange, yrange].
+     *
+     * @param dataset The dataset which should be evaluated.
+     *
+     * @return an array with x and y ranges.
+     */
+    public static Range[] getRanges(XYDataset dataset) {
+        if (dataset == null) {
+            return null;
+        }
+
+        double minX = Double.MAX_VALUE;
+        double maxX = -Double.MAX_VALUE;
+        double minY = Double.MAX_VALUE;
+        double maxY = -Double.MAX_VALUE;
+
+        for (int i = 0, m = dataset.getSeriesCount(); i < m; i++) {
+            for (int j = 0, n = dataset.getItemCount(i); j < n; j++) {
+                double x = dataset.getXValue(i, j);
+                double y = dataset.getYValue(i, j);
+
+                if (x < minX) {
+                    minX = x;
+                }
+
+                if (x > maxX) {
+                    maxX = x;
+                }
+
+                if (y < minY) {
+                    minY = y;
+                }
+
+                if (y > maxY) {
+                    maxY = y;
+                }
+            }
+        }
+
+        return new Range[] { new Range(minX, maxX), new Range(minY, maxY) };
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org