comparison artifacts/src/main/java/org/dive4elements/river/jfree/AxisDataset.java @ 7034:557cb3a3d772 generator-refactoring

Combine AxisDataset implementations and remove / simplify handling code. Tested with longitudinal section and hist. discharges should be ok.
author Andre Heinecke <aheinecke@intevation.de>
date Wed, 18 Sep 2013 10:12:47 +0200
parents
children 59e477500a50
comparison
equal deleted inserted replaced
7033:0d91a6598a89 7034:557cb3a3d772
1 /* Copyright (C) 2013 by Bundesanstalt für Gewässerkunde
2 * Software engineering by Intevation GmbH
3 *
4 * XYDatasethis file is Free Software under the GNU AGPL (>=v3)
5 * and comes with ABSOLUXYDatasetELY NO WARRANTY! Check out the
6 * documentation coming with Dive4Elements River for details.
7 */
8
9 package org.dive4elements.river.jfree;
10
11 import java.util.List;
12 import java.util.ArrayList;
13 import java.lang.Math;
14
15 import org.jfree.data.Range;
16 import org.jfree.data.RangeInfo;
17 import org.jfree.data.xy.XYDataset;
18 import org.jfree.data.xy.XYSeries;
19 import org.jfree.data.xy.XYSeriesCollection;
20 import org.jfree.data.time.TimeSeriesCollection;
21
22 import org.apache.log4j.Logger;
23
24 /**
25 * Axis datasets.
26 */
27 public class AxisDataset
28 {
29 private static Logger logger = Logger.getLogger(AxisDataset.class);
30
31 /** Symbolic integer, but also coding the priority (0 goes first). */
32 protected int axisSymbol;
33
34 /** List of assigned datasets (in order). */
35 protected List<XYDataset> datasets;
36
37 /** Range to use to include all given datasets. */
38 protected Range range;
39
40 /** Index of axis in plot. */
41 protected int plotAxisIndex;
42
43 protected boolean rangeDirty;
44
45 /** Create AxisDataset. */
46 public AxisDataset(int symb) {
47 axisSymbol = symb;
48 datasets = new ArrayList<XYDataset>();
49 }
50
51 /** Add a dataset to internal list for this axis. */
52 public void addDataset(XYDataset dataset) {
53 datasets.add(dataset);
54 rangeDirty = true;
55 }
56
57 /** Add a dataset. */
58 public void addDataset(XYSeries series) {
59 addDataset(new XYSeriesCollection(series));
60 }
61
62 public void setRange(Range val) {
63 range = val;
64 }
65
66 /** Get Range for the range axis of this dataset. */
67 public Range getRange() {
68 if (range != null && !rangeDirty) {
69 return range;
70 }
71 /* Calculate the min / max of all series */
72 for (XYDataset dataset: datasets) {
73 Range newRange = null;
74 if (dataset instanceof StyledAreaSeriesCollection) {
75 /* We do not include areas in the range calculation because
76 * they are used with very large / small values to draw areas
77 * with axis boundaries */
78 continue;
79 } else if (dataset instanceof RangeInfo) {
80 /* The usual case for most series */
81 newRange = ((RangeInfo) dataset).getRangeBounds(false);
82 } else if (dataset instanceof TimeSeriesCollection) {
83 /* Lalala <3 Jfreechart's class hirarchy */
84 newRange = ((TimeSeriesCollection) dataset).getRangeBounds(false);
85 }
86
87 /* Now we only expand as we also only add new data */
88 if (range == null) {
89 range = newRange;
90 } else {
91 range = Range.combineIgnoringNaN(range, newRange);
92 }
93 }
94 rangeDirty = false;
95 return range;
96 }
97
98 /** Get Array of Datasets. */
99 public XYDataset[] getDatasets() {
100 return datasets.toArray(new XYDataset[datasets.size()]);
101 }
102
103 /** True if to be rendered as area. */
104 public boolean isArea(XYDataset series) {
105 return (series instanceof StyledAreaSeriesCollection);
106 }
107
108 /** True if no datasets given. */
109 public boolean isEmpty() {
110 return datasets.isEmpty();
111 }
112
113 /** Set the 'real' axis index that this axis is mapped to. */
114 public void setPlotAxisIndex(int axisIndex) {
115 plotAxisIndex = axisIndex;
116 }
117
118 /** Get the 'real' axis index that this axis is mapped to. */
119 public int getPlotAxisIndex() {
120 return plotAxisIndex;
121 }
122
123 /** Add a Dataset that describes an area. */
124 public void addArea(StyledAreaSeriesCollection series) {
125 addDataset(series);
126 }
127
128 }

http://dive4elements.wald.intevation.org