comparison flys-artifacts/src/main/java/de/intevation/flys/exports/ChartHelper.java @ 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
children 2b232871ba28
comparison
equal deleted inserted replaced
2236:c2b15d9c0f43 2237:60615235e951
1 package de.intevation.flys.exports;
2
3 import org.jfree.data.Range;
4 import org.jfree.data.xy.XYDataset;
5
6
7 /**
8 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
9 */
10 public class ChartHelper {
11
12 /**
13 * This method returns the ranges of the XYDataset <i>dataset</i> as array
14 * with [xrange, yrange].
15 *
16 * @param dataset The dataset which should be evaluated.
17 *
18 * @return an array with x and y ranges.
19 */
20 public static Range[] getRanges(XYDataset dataset) {
21 if (dataset == null) {
22 return null;
23 }
24
25 double minX = Double.MAX_VALUE;
26 double maxX = -Double.MAX_VALUE;
27 double minY = Double.MAX_VALUE;
28 double maxY = -Double.MAX_VALUE;
29
30 for (int i = 0, m = dataset.getSeriesCount(); i < m; i++) {
31 for (int j = 0, n = dataset.getItemCount(i); j < n; j++) {
32 double x = dataset.getXValue(i, j);
33 double y = dataset.getYValue(i, j);
34
35 if (x < minX) {
36 minX = x;
37 }
38
39 if (x > maxX) {
40 maxX = x;
41 }
42
43 if (y < minY) {
44 minY = y;
45 }
46
47 if (y > maxY) {
48 maxY = y;
49 }
50 }
51 }
52
53 return new Range[] { new Range(minX, maxX), new Range(minY, maxY) };
54 }
55 }
56 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org