annotate flys-artifacts/src/main/java/de/intevation/flys/exports/ChartHelper.java @ 2270:e92545d2069e

Win fight against svn, added further i18n and slightly more data in reference-curve/csv export. flys-artifacts/trunk@3927 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Mon, 06 Feb 2012 14:02:04 +0000
parents 2b232871ba28
children 594885703687
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;
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
5
2241
2b232871ba28 New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2237
diff changeset
6 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
7
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
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 /**
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
10 * @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
11 */
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
12 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
13
2241
2b232871ba28 New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2237
diff changeset
14 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
15
2b232871ba28 New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2237
diff changeset
16
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
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 * 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
19 * 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
20 *
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 * @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
22 *
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
23 * @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
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 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
26 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
27
2b232871ba28 New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2237
diff changeset
28 if (seriesCount == 0) {
2b232871ba28 New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2237
diff changeset
29 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
30 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
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
2241
2b232871ba28 New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2237
diff changeset
33 boolean foundValue = false;
2b232871ba28 New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2237
diff changeset
34
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
35 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
36 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
37 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
38 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
39
2241
2b232871ba28 New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2237
diff changeset
40 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
41 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
42 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
43 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
44
2241
2b232871ba28 New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2237
diff changeset
45 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
46 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
47 continue;
2b232871ba28 New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2237
diff changeset
48 }
2b232871ba28 New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2237
diff changeset
49
2b232871ba28 New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2237
diff changeset
50 foundValue = true;
2b232871ba28 New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2237
diff changeset
51
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
52 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
53 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
54 }
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
55
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
56 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
57 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
58 }
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
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 (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
61 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
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 (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
65 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
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 }
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
2241
2b232871ba28 New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2237
diff changeset
70 return foundValue
2b232871ba28 New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2237
diff changeset
71 ? 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
72 : null;
2b232871ba28 New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2237
diff changeset
73 }
2b232871ba28 New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2237
diff changeset
74
2b232871ba28 New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2237
diff changeset
75
2b232871ba28 New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2237
diff changeset
76 /**
2b232871ba28 New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2237
diff changeset
77 * Expand range by percent.
2b232871ba28 New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2237
diff changeset
78 *
2b232871ba28 New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2237
diff changeset
79 * @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
80 * @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
81 *
2b232871ba28 New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2237
diff changeset
82 * @param an expanded range.
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 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
85 if (range == null) {
2b232871ba28 New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2237
diff changeset
86 return null;
2b232871ba28 New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2237
diff changeset
87 }
2b232871ba28 New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2237
diff changeset
88
2b232871ba28 New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2237
diff changeset
89 double value = range.getLowerBound();
2b232871ba28 New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2237
diff changeset
90 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
91
2b232871ba28 New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2237
diff changeset
92 return expand != 0
2b232871ba28 New helper functions in ChartHelper and improvements in EnhancedLineAndShapeRenderer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2237
diff changeset
93 ? 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
94 : 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
95 }
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
96 }
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
97 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org