Mercurial > dive4elements > river
annotate flys-artifacts/src/main/java/de/intevation/flys/exports/ChartHelper.java @ 4654:861c47e0a8a0
Refactor Mapserver mapfile generation.
Prepares the existing mapfile generation code for
a river axis mapfile generator.
Removes unused asynchronous mapfile generation to
reduce complexity.
author | Christian Lins <christian.lins@intevation.de> |
---|---|
date | Sat, 08 Dec 2012 00:19:29 +0100 |
parents | b2ea89a665bc |
children |
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; |
2587
bece6f604899
Removed references to Range and replaced those with references to Bounds in ChartGenerators.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2394
diff
changeset
|
5 import org.jfree.data.xy.XYSeriesCollection; |
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
|
6 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
|
7 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
|
8 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
|
9 |
2241
2b232871ba28
New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2237
diff
changeset
|
10 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
|
11 |
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
|
12 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
|
13 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
|
14 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
|
15 |
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
|
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 /** |
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 * @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
|
19 */ |
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 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
|
21 |
2241
2b232871ba28
New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2237
diff
changeset
|
22 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
|
23 |
2b232871ba28
New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2237
diff
changeset
|
24 |
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
|
25 /** |
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 * 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
|
27 * 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
|
28 * |
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 * @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
|
30 * |
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 * @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
|
32 */ |
2587
bece6f604899
Removed references to Range and replaced those with references to Bounds in ChartGenerators.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2394
diff
changeset
|
33 public static Bounds[] getBounds(XYSeriesCollection dataset) { |
2241
2b232871ba28
New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2237
diff
changeset
|
34 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
|
35 |
2b232871ba28
New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2237
diff
changeset
|
36 if (seriesCount == 0) { |
2b232871ba28
New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2237
diff
changeset
|
37 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
|
38 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
|
39 } |
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
|
40 |
2241
2b232871ba28
New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2237
diff
changeset
|
41 boolean foundValue = false; |
2b232871ba28
New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2237
diff
changeset
|
42 |
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
|
43 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
|
44 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
|
45 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
|
46 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
|
47 |
2241
2b232871ba28
New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2237
diff
changeset
|
48 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
|
49 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
|
50 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
|
51 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
|
52 |
2241
2b232871ba28
New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2237
diff
changeset
|
53 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
|
54 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
|
55 continue; |
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 |
2b232871ba28
New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2237
diff
changeset
|
58 foundValue = true; |
2b232871ba28
New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2237
diff
changeset
|
59 |
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
|
60 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
|
61 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
|
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 |
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 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
|
65 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
|
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 |
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 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
|
69 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
|
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 |
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 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
|
73 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
|
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 } |
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
|
77 |
2241
2b232871ba28
New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2237
diff
changeset
|
78 return foundValue |
2587
bece6f604899
Removed references to Range and replaced those with references to Bounds in ChartGenerators.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2394
diff
changeset
|
79 ? new Bounds[] { |
bece6f604899
Removed references to Range and replaced those with references to Bounds in ChartGenerators.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2394
diff
changeset
|
80 new DoubleBounds(minX, maxX), |
bece6f604899
Removed references to Range and replaced those with references to Bounds in ChartGenerators.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2394
diff
changeset
|
81 new DoubleBounds(minY, maxY) } |
2241
2b232871ba28
New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2237
diff
changeset
|
82 : null; |
2b232871ba28
New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2237
diff
changeset
|
83 } |
2b232871ba28
New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2237
diff
changeset
|
84 |
2b232871ba28
New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2237
diff
changeset
|
85 |
2587
bece6f604899
Removed references to Range and replaced those with references to Bounds in ChartGenerators.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2394
diff
changeset
|
86 public static Bounds[] getBounds(XYDataset dataset) { |
bece6f604899
Removed references to Range and replaced those with references to Bounds in ChartGenerators.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2394
diff
changeset
|
87 if (dataset instanceof XYSeriesCollection) { |
bece6f604899
Removed references to Range and replaced those with references to Bounds in ChartGenerators.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2394
diff
changeset
|
88 return getBounds((XYSeriesCollection) dataset); |
bece6f604899
Removed references to Range and replaced those with references to Bounds in ChartGenerators.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2394
diff
changeset
|
89 } |
bece6f604899
Removed references to Range and replaced those with references to Bounds in ChartGenerators.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2394
diff
changeset
|
90 else if(dataset instanceof TimeSeriesCollection) { |
bece6f604899
Removed references to Range and replaced those with references to Bounds in ChartGenerators.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2394
diff
changeset
|
91 return getBounds((TimeSeriesCollection) dataset); |
bece6f604899
Removed references to Range and replaced those with references to Bounds in ChartGenerators.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2394
diff
changeset
|
92 } |
bece6f604899
Removed references to Range and replaced those with references to Bounds in ChartGenerators.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2394
diff
changeset
|
93 else { |
bece6f604899
Removed references to Range and replaced those with references to Bounds in ChartGenerators.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2394
diff
changeset
|
94 logger.warn("Unknown XYDataset instance: " + dataset.getClass()); |
bece6f604899
Removed references to Range and replaced those with references to Bounds in ChartGenerators.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2394
diff
changeset
|
95 return null; |
bece6f604899
Removed references to Range and replaced those with references to Bounds in ChartGenerators.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2394
diff
changeset
|
96 } |
bece6f604899
Removed references to Range and replaced those with references to Bounds in ChartGenerators.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2394
diff
changeset
|
97 } |
bece6f604899
Removed references to Range and replaced those with references to Bounds in ChartGenerators.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2394
diff
changeset
|
98 |
bece6f604899
Removed references to Range and replaced those with references to Bounds in ChartGenerators.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2394
diff
changeset
|
99 |
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
|
100 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
|
101 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
|
102 |
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 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
|
104 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
|
105 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
|
106 } |
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 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
|
109 |
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 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
|
111 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
|
112 |
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 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
|
114 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
|
115 |
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 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
|
117 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
|
118 |
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 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
|
120 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
|
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 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
|
123 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
|
124 } |
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 |
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 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
|
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 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
|
129 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
|
130 |
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 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
|
132 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
|
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 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
|
136 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
|
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 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
|
140 |
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
|
141 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
|
142 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
|
143 } |
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
|
144 } |
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
|
145 |
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
|
146 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
|
147 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
|
148 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
|
149 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
|
150 }; |
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
|
151 } |
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
|
152 |
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
|
153 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
|
154 } |
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
|
155 |
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
|
156 |
2241
2b232871ba28
New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2237
diff
changeset
|
157 /** |
3247
638b1da85450
New ChartHelper method to expand bounds added.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
2587
diff
changeset
|
158 * Expand bounds by percent. |
638b1da85450
New ChartHelper method to expand bounds added.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
2587
diff
changeset
|
159 * |
638b1da85450
New ChartHelper method to expand bounds added.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
2587
diff
changeset
|
160 * @param bounds The bounds to expand. |
638b1da85450
New ChartHelper method to expand bounds added.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
2587
diff
changeset
|
161 * @param percent The percentage to expand. |
638b1da85450
New ChartHelper method to expand bounds added.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
2587
diff
changeset
|
162 * |
3269
b2ea89a665bc
Fix issues in 'documentation'.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3247
diff
changeset
|
163 * @return a new, expanded bounds. |
3247
638b1da85450
New ChartHelper method to expand bounds added.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
2587
diff
changeset
|
164 */ |
638b1da85450
New ChartHelper method to expand bounds added.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
2587
diff
changeset
|
165 public static Bounds expandBounds(Bounds bounds, double percent) { |
638b1da85450
New ChartHelper method to expand bounds added.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
2587
diff
changeset
|
166 if (bounds == null) { |
638b1da85450
New ChartHelper method to expand bounds added.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
2587
diff
changeset
|
167 return null; |
638b1da85450
New ChartHelper method to expand bounds added.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
2587
diff
changeset
|
168 } |
638b1da85450
New ChartHelper method to expand bounds added.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
2587
diff
changeset
|
169 |
638b1da85450
New ChartHelper method to expand bounds added.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
2587
diff
changeset
|
170 double value = (Double) bounds.getLower(); |
638b1da85450
New ChartHelper method to expand bounds added.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
2587
diff
changeset
|
171 double expand = Math.abs(value / 100 * percent); |
638b1da85450
New ChartHelper method to expand bounds added.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
2587
diff
changeset
|
172 |
638b1da85450
New ChartHelper method to expand bounds added.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
2587
diff
changeset
|
173 return expand != 0 |
638b1da85450
New ChartHelper method to expand bounds added.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
2587
diff
changeset
|
174 ? new DoubleBounds(value-expand, value+expand) |
638b1da85450
New ChartHelper method to expand bounds added.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
2587
diff
changeset
|
175 : new DoubleBounds(-0.01 * percent, 0.01 * percent); |
638b1da85450
New ChartHelper method to expand bounds added.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
2587
diff
changeset
|
176 } |
638b1da85450
New ChartHelper method to expand bounds added.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
2587
diff
changeset
|
177 |
638b1da85450
New ChartHelper method to expand bounds added.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
2587
diff
changeset
|
178 |
638b1da85450
New ChartHelper method to expand bounds added.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
2587
diff
changeset
|
179 /** |
2241
2b232871ba28
New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2237
diff
changeset
|
180 * Expand range by percent. |
2b232871ba28
New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2237
diff
changeset
|
181 * |
2b232871ba28
New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2237
diff
changeset
|
182 * @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
|
183 * @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
|
184 * |
3269
b2ea89a665bc
Fix issues in 'documentation'.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3247
diff
changeset
|
185 * @return a new, expanded range. |
2241
2b232871ba28
New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2237
diff
changeset
|
186 */ |
2b232871ba28
New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2237
diff
changeset
|
187 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
|
188 if (range == null) { |
2b232871ba28
New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2237
diff
changeset
|
189 return null; |
2b232871ba28
New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2237
diff
changeset
|
190 } |
2b232871ba28
New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2237
diff
changeset
|
191 |
2b232871ba28
New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2237
diff
changeset
|
192 double value = range.getLowerBound(); |
2b232871ba28
New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2237
diff
changeset
|
193 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
|
194 |
2b232871ba28
New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2237
diff
changeset
|
195 return expand != 0 |
2b232871ba28
New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2237
diff
changeset
|
196 ? 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
|
197 : 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
|
198 } |
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
|
199 } |
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
|
200 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |