annotate flys-artifacts/src/main/java/de/intevation/flys/exports/ChartHelper.java @ 2394:02ac373b6d69

Added chart helper function to determine the min and max bounds (x and y) for TimeSeriesCollections. flys-artifacts/trunk@4016 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Fri, 10 Feb 2012 08:43:06 +0000
parents 2b232871ba28
children bece6f604899
rev   line source
2237
60615235e951 Added a ChartHelper class that currently contains a method to compute the xy ranges of an XYDataset.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
1 package de.intevation.flys.exports;
60615235e951 Added a ChartHelper class that currently contains a method to compute the xy ranges of an XYDataset.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
2
60615235e951 Added a ChartHelper class that currently contains a method to compute the xy ranges of an XYDataset.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
3 import org.jfree.data.Range;
60615235e951 Added a ChartHelper class that currently contains a method to compute the xy ranges of an XYDataset.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
4 import org.jfree.data.xy.XYDataset;
2394
02ac373b6d69 Added chart helper function to determine the min and max bounds (x and y) for TimeSeriesCollections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2241
diff changeset
5 import org.jfree.data.time.RegularTimePeriod;
02ac373b6d69 Added chart helper function to determine the min and max bounds (x and y) for TimeSeriesCollections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2241
diff changeset
6 import org.jfree.data.time.TimeSeriesCollection;
02ac373b6d69 Added chart helper function to determine the min and max bounds (x and y) for TimeSeriesCollections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2241
diff changeset
7 import org.jfree.data.time.TimeSeries;
2237
60615235e951 Added a ChartHelper class that currently contains a method to compute the xy ranges of an XYDataset.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
8
2241
2b232871ba28 New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2237
diff changeset
9 import org.apache.log4j.Logger;
2b232871ba28 New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2237
diff changeset
10
2394
02ac373b6d69 Added chart helper function to determine the min and max bounds (x and y) for TimeSeriesCollections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2241
diff changeset
11 import de.intevation.flys.jfree.Bounds;
02ac373b6d69 Added chart helper function to determine the min and max bounds (x and y) for TimeSeriesCollections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2241
diff changeset
12 import de.intevation.flys.jfree.DoubleBounds;
02ac373b6d69 Added chart helper function to determine the min and max bounds (x and y) for TimeSeriesCollections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2241
diff changeset
13 import de.intevation.flys.jfree.TimeBounds;
02ac373b6d69 Added chart helper function to determine the min and max bounds (x and y) for TimeSeriesCollections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2241
diff changeset
14
2237
60615235e951 Added a ChartHelper class that currently contains a method to compute the xy ranges of an XYDataset.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
15
60615235e951 Added a ChartHelper class that currently contains a method to compute the xy ranges of an XYDataset.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
16 /**
60615235e951 Added a ChartHelper class that currently contains a method to compute the xy ranges of an XYDataset.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
17 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
60615235e951 Added a ChartHelper class that currently contains a method to compute the xy ranges of an XYDataset.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
18 */
60615235e951 Added a ChartHelper class that currently contains a method to compute the xy ranges of an XYDataset.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
19 public class ChartHelper {
60615235e951 Added a ChartHelper class that currently contains a method to compute the xy ranges of an XYDataset.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
20
2241
2b232871ba28 New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2237
diff changeset
21 private static final Logger logger = Logger.getLogger(ChartHelper.class);
2b232871ba28 New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2237
diff changeset
22
2b232871ba28 New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2237
diff changeset
23
2237
60615235e951 Added a ChartHelper class that currently contains a method to compute the xy ranges of an XYDataset.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
24 /**
60615235e951 Added a ChartHelper class that currently contains a method to compute the xy ranges of an XYDataset.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
25 * This method returns the ranges of the XYDataset <i>dataset</i> as array
60615235e951 Added a ChartHelper class that currently contains a method to compute the xy ranges of an XYDataset.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
26 * with [xrange, yrange].
60615235e951 Added a ChartHelper class that currently contains a method to compute the xy ranges of an XYDataset.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
27 *
60615235e951 Added a ChartHelper class that currently contains a method to compute the xy ranges of an XYDataset.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
28 * @param dataset The dataset which should be evaluated.
60615235e951 Added a ChartHelper class that currently contains a method to compute the xy ranges of an XYDataset.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
29 *
60615235e951 Added a ChartHelper class that currently contains a method to compute the xy ranges of an XYDataset.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
30 * @return an array with x and y ranges.
60615235e951 Added a ChartHelper class that currently contains a method to compute the xy ranges of an XYDataset.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
31 */
60615235e951 Added a ChartHelper class that currently contains a method to compute the xy ranges of an XYDataset.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
32 public static Range[] getRanges(XYDataset dataset) {
2241
2b232871ba28 New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2237
diff changeset
33 int seriesCount = dataset != null ? dataset.getSeriesCount() : 0;
2b232871ba28 New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2237
diff changeset
34
2b232871ba28 New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2237
diff changeset
35 if (seriesCount == 0) {
2b232871ba28 New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2237
diff changeset
36 logger.warn("Dataset is empty or has no Series set.");
2237
60615235e951 Added a ChartHelper class that currently contains a method to compute the xy ranges of an XYDataset.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
37 return null;
60615235e951 Added a ChartHelper class that currently contains a method to compute the xy ranges of an XYDataset.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
38 }
60615235e951 Added a ChartHelper class that currently contains a method to compute the xy ranges of an XYDataset.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
39
2241
2b232871ba28 New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2237
diff changeset
40 boolean foundValue = false;
2b232871ba28 New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2237
diff changeset
41
2237
60615235e951 Added a ChartHelper class that currently contains a method to compute the xy ranges of an XYDataset.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
42 double minX = Double.MAX_VALUE;
60615235e951 Added a ChartHelper class that currently contains a method to compute the xy ranges of an XYDataset.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
43 double maxX = -Double.MAX_VALUE;
60615235e951 Added a ChartHelper class that currently contains a method to compute the xy ranges of an XYDataset.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
44 double minY = Double.MAX_VALUE;
60615235e951 Added a ChartHelper class that currently contains a method to compute the xy ranges of an XYDataset.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
45 double maxY = -Double.MAX_VALUE;
60615235e951 Added a ChartHelper class that currently contains a method to compute the xy ranges of an XYDataset.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
46
2241
2b232871ba28 New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2237
diff changeset
47 for (int i = 0, m = seriesCount; i < m; i++) {
2237
60615235e951 Added a ChartHelper class that currently contains a method to compute the xy ranges of an XYDataset.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
48 for (int j = 0, n = dataset.getItemCount(i); j < n; j++) {
60615235e951 Added a ChartHelper class that currently contains a method to compute the xy ranges of an XYDataset.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
49 double x = dataset.getXValue(i, j);
60615235e951 Added a ChartHelper class that currently contains a method to compute the xy ranges of an XYDataset.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
50 double y = dataset.getYValue(i, j);
60615235e951 Added a ChartHelper class that currently contains a method to compute the xy ranges of an XYDataset.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
51
2241
2b232871ba28 New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2237
diff changeset
52 if (Double.isNaN(x) || Double.isNaN(y)) {
2b232871ba28 New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2237
diff changeset
53 logger.warn("Item " + j + " in Series " + i + " is broken");
2b232871ba28 New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2237
diff changeset
54 continue;
2b232871ba28 New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2237
diff changeset
55 }
2b232871ba28 New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2237
diff changeset
56
2b232871ba28 New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2237
diff changeset
57 foundValue = true;
2b232871ba28 New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2237
diff changeset
58
2237
60615235e951 Added a ChartHelper class that currently contains a method to compute the xy ranges of an XYDataset.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
59 if (x < minX) {
60615235e951 Added a ChartHelper class that currently contains a method to compute the xy ranges of an XYDataset.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
60 minX = x;
60615235e951 Added a ChartHelper class that currently contains a method to compute the xy ranges of an XYDataset.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
61 }
60615235e951 Added a ChartHelper class that currently contains a method to compute the xy ranges of an XYDataset.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
62
60615235e951 Added a ChartHelper class that currently contains a method to compute the xy ranges of an XYDataset.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
63 if (x > maxX) {
60615235e951 Added a ChartHelper class that currently contains a method to compute the xy ranges of an XYDataset.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
64 maxX = x;
60615235e951 Added a ChartHelper class that currently contains a method to compute the xy ranges of an XYDataset.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
65 }
60615235e951 Added a ChartHelper class that currently contains a method to compute the xy ranges of an XYDataset.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
66
60615235e951 Added a ChartHelper class that currently contains a method to compute the xy ranges of an XYDataset.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
67 if (y < minY) {
60615235e951 Added a ChartHelper class that currently contains a method to compute the xy ranges of an XYDataset.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
68 minY = y;
60615235e951 Added a ChartHelper class that currently contains a method to compute the xy ranges of an XYDataset.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
69 }
60615235e951 Added a ChartHelper class that currently contains a method to compute the xy ranges of an XYDataset.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
70
60615235e951 Added a ChartHelper class that currently contains a method to compute the xy ranges of an XYDataset.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
71 if (y > maxY) {
60615235e951 Added a ChartHelper class that currently contains a method to compute the xy ranges of an XYDataset.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
72 maxY = y;
60615235e951 Added a ChartHelper class that currently contains a method to compute the xy ranges of an XYDataset.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
73 }
60615235e951 Added a ChartHelper class that currently contains a method to compute the xy ranges of an XYDataset.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
74 }
60615235e951 Added a ChartHelper class that currently contains a method to compute the xy ranges of an XYDataset.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
75 }
60615235e951 Added a ChartHelper class that currently contains a method to compute the xy ranges of an XYDataset.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
76
2241
2b232871ba28 New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2237
diff changeset
77 return foundValue
2b232871ba28 New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2237
diff changeset
78 ? new Range[] { new Range(minX, maxX), new Range(minY, maxY) }
2b232871ba28 New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2237
diff changeset
79 : null;
2b232871ba28 New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2237
diff changeset
80 }
2b232871ba28 New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2237
diff changeset
81
2b232871ba28 New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2237
diff changeset
82
2394
02ac373b6d69 Added chart helper function to determine the min and max bounds (x and y) for TimeSeriesCollections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2241
diff changeset
83 public static Bounds[] getBounds(TimeSeriesCollection collection) {
02ac373b6d69 Added chart helper function to determine the min and max bounds (x and y) for TimeSeriesCollections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2241
diff changeset
84 int seriesCount = collection != null ? collection.getSeriesCount() : 0;
02ac373b6d69 Added chart helper function to determine the min and max bounds (x and y) for TimeSeriesCollections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2241
diff changeset
85
02ac373b6d69 Added chart helper function to determine the min and max bounds (x and y) for TimeSeriesCollections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2241
diff changeset
86 if (seriesCount == 0) {
02ac373b6d69 Added chart helper function to determine the min and max bounds (x and y) for TimeSeriesCollections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2241
diff changeset
87 logger.warn("TimeSeriesCollection is empty or has no Series set.");
02ac373b6d69 Added chart helper function to determine the min and max bounds (x and y) for TimeSeriesCollections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2241
diff changeset
88 return null;
02ac373b6d69 Added chart helper function to determine the min and max bounds (x and y) for TimeSeriesCollections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2241
diff changeset
89 }
02ac373b6d69 Added chart helper function to determine the min and max bounds (x and y) for TimeSeriesCollections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2241
diff changeset
90
02ac373b6d69 Added chart helper function to determine the min and max bounds (x and y) for TimeSeriesCollections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2241
diff changeset
91 boolean foundValue = false;
02ac373b6d69 Added chart helper function to determine the min and max bounds (x and y) for TimeSeriesCollections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2241
diff changeset
92
02ac373b6d69 Added chart helper function to determine the min and max bounds (x and y) for TimeSeriesCollections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2241
diff changeset
93 long lowerX = Long.MAX_VALUE;
02ac373b6d69 Added chart helper function to determine the min and max bounds (x and y) for TimeSeriesCollections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2241
diff changeset
94 long upperX = -Long.MAX_VALUE;
02ac373b6d69 Added chart helper function to determine the min and max bounds (x and y) for TimeSeriesCollections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2241
diff changeset
95
02ac373b6d69 Added chart helper function to determine the min and max bounds (x and y) for TimeSeriesCollections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2241
diff changeset
96 double lowerY = Double.MAX_VALUE;
02ac373b6d69 Added chart helper function to determine the min and max bounds (x and y) for TimeSeriesCollections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2241
diff changeset
97 double upperY = -Double.MAX_VALUE;
02ac373b6d69 Added chart helper function to determine the min and max bounds (x and y) for TimeSeriesCollections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2241
diff changeset
98
02ac373b6d69 Added chart helper function to determine the min and max bounds (x and y) for TimeSeriesCollections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2241
diff changeset
99 for (int i = 0, m = seriesCount; i < m; i++) {
02ac373b6d69 Added chart helper function to determine the min and max bounds (x and y) for TimeSeriesCollections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2241
diff changeset
100 TimeSeries series = collection.getSeries(i);
02ac373b6d69 Added chart helper function to determine the min and max bounds (x and y) for TimeSeriesCollections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2241
diff changeset
101
02ac373b6d69 Added chart helper function to determine the min and max bounds (x and y) for TimeSeriesCollections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2241
diff changeset
102 for (int j = 0, n = collection.getItemCount(i); j < n; j++) {
02ac373b6d69 Added chart helper function to determine the min and max bounds (x and y) for TimeSeriesCollections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2241
diff changeset
103 RegularTimePeriod rtp = series.getTimePeriod(j);
02ac373b6d69 Added chart helper function to determine the min and max bounds (x and y) for TimeSeriesCollections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2241
diff changeset
104
02ac373b6d69 Added chart helper function to determine the min and max bounds (x and y) for TimeSeriesCollections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2241
diff changeset
105 if (rtp == null) {
02ac373b6d69 Added chart helper function to determine the min and max bounds (x and y) for TimeSeriesCollections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2241
diff changeset
106 continue;
02ac373b6d69 Added chart helper function to determine the min and max bounds (x and y) for TimeSeriesCollections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2241
diff changeset
107 }
02ac373b6d69 Added chart helper function to determine the min and max bounds (x and y) for TimeSeriesCollections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2241
diff changeset
108
02ac373b6d69 Added chart helper function to determine the min and max bounds (x and y) for TimeSeriesCollections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2241
diff changeset
109 foundValue = true;
02ac373b6d69 Added chart helper function to determine the min and max bounds (x and y) for TimeSeriesCollections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2241
diff changeset
110
02ac373b6d69 Added chart helper function to determine the min and max bounds (x and y) for TimeSeriesCollections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2241
diff changeset
111 long start = rtp.getFirstMillisecond();
02ac373b6d69 Added chart helper function to determine the min and max bounds (x and y) for TimeSeriesCollections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2241
diff changeset
112 long end = rtp.getLastMillisecond();
02ac373b6d69 Added chart helper function to determine the min and max bounds (x and y) for TimeSeriesCollections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2241
diff changeset
113
02ac373b6d69 Added chart helper function to determine the min and max bounds (x and y) for TimeSeriesCollections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2241
diff changeset
114 if (start < lowerX) {
02ac373b6d69 Added chart helper function to determine the min and max bounds (x and y) for TimeSeriesCollections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2241
diff changeset
115 lowerX = start;
02ac373b6d69 Added chart helper function to determine the min and max bounds (x and y) for TimeSeriesCollections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2241
diff changeset
116 }
02ac373b6d69 Added chart helper function to determine the min and max bounds (x and y) for TimeSeriesCollections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2241
diff changeset
117
02ac373b6d69 Added chart helper function to determine the min and max bounds (x and y) for TimeSeriesCollections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2241
diff changeset
118 if (end > upperX) {
02ac373b6d69 Added chart helper function to determine the min and max bounds (x and y) for TimeSeriesCollections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2241
diff changeset
119 upperX = end;
02ac373b6d69 Added chart helper function to determine the min and max bounds (x and y) for TimeSeriesCollections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2241
diff changeset
120 }
02ac373b6d69 Added chart helper function to determine the min and max bounds (x and y) for TimeSeriesCollections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2241
diff changeset
121
02ac373b6d69 Added chart helper function to determine the min and max bounds (x and y) for TimeSeriesCollections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2241
diff changeset
122 double y = series.getValue(j).doubleValue();
02ac373b6d69 Added chart helper function to determine the min and max bounds (x and y) for TimeSeriesCollections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2241
diff changeset
123
02ac373b6d69 Added chart helper function to determine the min and max bounds (x and y) for TimeSeriesCollections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2241
diff changeset
124 lowerY = Math.min(lowerY, y);
02ac373b6d69 Added chart helper function to determine the min and max bounds (x and y) for TimeSeriesCollections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2241
diff changeset
125 upperY = Math.max(upperY, y);
02ac373b6d69 Added chart helper function to determine the min and max bounds (x and y) for TimeSeriesCollections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2241
diff changeset
126 }
02ac373b6d69 Added chart helper function to determine the min and max bounds (x and y) for TimeSeriesCollections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2241
diff changeset
127 }
02ac373b6d69 Added chart helper function to determine the min and max bounds (x and y) for TimeSeriesCollections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2241
diff changeset
128
02ac373b6d69 Added chart helper function to determine the min and max bounds (x and y) for TimeSeriesCollections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2241
diff changeset
129 if (foundValue) {
02ac373b6d69 Added chart helper function to determine the min and max bounds (x and y) for TimeSeriesCollections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2241
diff changeset
130 return new Bounds[] {
02ac373b6d69 Added chart helper function to determine the min and max bounds (x and y) for TimeSeriesCollections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2241
diff changeset
131 new TimeBounds(lowerX, upperX),
02ac373b6d69 Added chart helper function to determine the min and max bounds (x and y) for TimeSeriesCollections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2241
diff changeset
132 new DoubleBounds(lowerY, upperY)
02ac373b6d69 Added chart helper function to determine the min and max bounds (x and y) for TimeSeriesCollections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2241
diff changeset
133 };
02ac373b6d69 Added chart helper function to determine the min and max bounds (x and y) for TimeSeriesCollections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2241
diff changeset
134 }
02ac373b6d69 Added chart helper function to determine the min and max bounds (x and y) for TimeSeriesCollections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2241
diff changeset
135
02ac373b6d69 Added chart helper function to determine the min and max bounds (x and y) for TimeSeriesCollections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2241
diff changeset
136 return null;
02ac373b6d69 Added chart helper function to determine the min and max bounds (x and y) for TimeSeriesCollections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2241
diff changeset
137 }
02ac373b6d69 Added chart helper function to determine the min and max bounds (x and y) for TimeSeriesCollections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2241
diff changeset
138
02ac373b6d69 Added chart helper function to determine the min and max bounds (x and y) for TimeSeriesCollections.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2241
diff changeset
139
2241
2b232871ba28 New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2237
diff changeset
140 /**
2b232871ba28 New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2237
diff changeset
141 * Expand range by percent.
2b232871ba28 New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2237
diff changeset
142 *
2b232871ba28 New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2237
diff changeset
143 * @param range The range to expand.
2b232871ba28 New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2237
diff changeset
144 * @param percent The percentage to expand.
2b232871ba28 New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2237
diff changeset
145 *
2b232871ba28 New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2237
diff changeset
146 * @param an expanded range.
2b232871ba28 New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2237
diff changeset
147 */
2b232871ba28 New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2237
diff changeset
148 public static Range expandRange(Range range, double percent) {
2b232871ba28 New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2237
diff changeset
149 if (range == null) {
2b232871ba28 New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2237
diff changeset
150 return null;
2b232871ba28 New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2237
diff changeset
151 }
2b232871ba28 New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2237
diff changeset
152
2b232871ba28 New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2237
diff changeset
153 double value = range.getLowerBound();
2b232871ba28 New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2237
diff changeset
154 double expand = Math.abs(value / 100 * percent);
2b232871ba28 New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2237
diff changeset
155
2b232871ba28 New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2237
diff changeset
156 return expand != 0
2b232871ba28 New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2237
diff changeset
157 ? new Range(value-expand, value+expand)
2b232871ba28 New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2237
diff changeset
158 : new Range(-0.01 * percent, 0.01 * percent);
2237
60615235e951 Added a ChartHelper class that currently contains a method to compute the xy ranges of an XYDataset.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
159 }
60615235e951 Added a ChartHelper class that currently contains a method to compute the xy ranges of an XYDataset.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
160 }
60615235e951 Added a ChartHelper class that currently contains a method to compute the xy ranges of an XYDataset.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
161 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org