Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/jfree/AxisDataset.java @ 9496:d8e753d0fdb9
stripedArea introduced for Assessment Scheme/Bewertungsschema
author | gernotbelger |
---|---|
date | Wed, 26 Sep 2018 15:48:05 +0200 |
parents | e5f688820951 |
children | ef5754ba5573 |
comparison
equal
deleted
inserted
replaced
9495:bb278c927b66 | 9496:d8e753d0fdb9 |
---|---|
6 * documentation coming with Dive4Elements River for details. | 6 * documentation coming with Dive4Elements River for details. |
7 */ | 7 */ |
8 | 8 |
9 package org.dive4elements.river.jfree; | 9 package org.dive4elements.river.jfree; |
10 | 10 |
11 import java.util.ArrayList; | |
11 import java.util.List; | 12 import java.util.List; |
12 import java.util.ArrayList; | |
13 | 13 |
14 import org.jfree.data.Range; | 14 import org.jfree.data.Range; |
15 import org.jfree.data.RangeInfo; | 15 import org.jfree.data.RangeInfo; |
16 import org.jfree.data.time.TimeSeriesCollection; | |
16 import org.jfree.data.xy.XYDataset; | 17 import org.jfree.data.xy.XYDataset; |
17 import org.jfree.data.xy.XYSeries; | |
18 import org.jfree.data.xy.XYSeriesCollection; | |
19 import org.jfree.data.time.TimeSeriesCollection; | |
20 | |
21 import org.apache.log4j.Logger; | |
22 | 18 |
23 /** | 19 /** |
24 * Axis datasets. | 20 * Axis datasets. |
25 */ | 21 */ |
26 public class AxisDataset | 22 public class AxisDataset { |
27 { | |
28 private static Logger log = Logger.getLogger(AxisDataset.class); | |
29 | 23 |
30 /** Symbolic integer, but also coding the priority (0 goes first). */ | 24 /** Symbolic integer, but also coding the priority (0 goes first). */ |
31 protected int axisSymbol; | 25 protected int axisSymbol; |
32 | 26 |
33 /** List of assigned datasets (in order). */ | 27 /** List of assigned datasets (in order). */ |
40 protected int plotAxisIndex; | 34 protected int plotAxisIndex; |
41 | 35 |
42 protected boolean rangeDirty; | 36 protected boolean rangeDirty; |
43 | 37 |
44 /** Create AxisDataset. */ | 38 /** Create AxisDataset. */ |
45 public AxisDataset(int symb) { | 39 public AxisDataset(final int symb) { |
46 axisSymbol = symb; | 40 this.axisSymbol = symb; |
47 datasets = new ArrayList<XYDataset>(); | 41 this.datasets = new ArrayList<>(); |
48 } | 42 } |
49 | 43 |
50 /** Add a dataset to internal list for this axis. */ | 44 /** Add a dataset to internal list for this axis. */ |
51 public void addDataset(XYDataset dataset) { | 45 public void addDataset(final XYDataset dataset) { |
52 datasets.add(dataset); | 46 this.datasets.add(dataset); |
53 rangeDirty = true; | 47 this.rangeDirty = true; |
54 } | 48 } |
55 | 49 |
56 /** Add a dataset. */ | 50 public void setRange(final Range val) { |
57 public void addDataset(XYSeries series) { | 51 this.range = val; |
58 addDataset(new XYSeriesCollection(series)); | |
59 } | |
60 | |
61 public void setRange(Range val) { | |
62 range = val; | |
63 } | 52 } |
64 | 53 |
65 /** Get Range for the range axis of this dataset. */ | 54 /** Get Range for the range axis of this dataset. */ |
66 public Range getRange() { | 55 public Range getRange() { |
67 if (range != null && !rangeDirty) { | 56 if (this.range != null && !this.rangeDirty) { |
68 return range; | 57 return this.range; |
69 } | 58 } |
70 /* Calculate the min / max of all series */ | 59 /* Calculate the min / max of all series */ |
71 for (XYDataset dataset: datasets) { | 60 for (final XYDataset dataset : this.datasets) { |
72 Range newRange = null; | 61 Range newRange = null; |
73 if (dataset instanceof StyledAreaSeriesCollection) { | 62 if (dataset instanceof StyledAreaSeriesCollection) { |
74 final StyledAreaSeriesCollection areaSeries = (StyledAreaSeriesCollection) dataset; | 63 final StyledAreaSeriesCollection areaSeries = (StyledAreaSeriesCollection) dataset; |
75 if( areaSeries.shouldCalculateRange() ) | 64 if (areaSeries.shouldCalculateRange()) |
76 newRange = areaSeries.getRangeBounds(false); | 65 newRange = areaSeries.getRangeBounds(false); |
77 else { | 66 else { |
78 /* For most area themes, we do not include areas in the range calculation because | 67 /* |
68 * For most area themes, we do not include areas in the range calculation because | |
79 * they are used with very large / small values to draw areas | 69 * they are used with very large / small values to draw areas |
80 * with axis boundaries */ | 70 * with axis boundaries |
71 */ | |
81 continue; | 72 continue; |
82 } | 73 } |
83 } else if (dataset instanceof RangeInfo) { | 74 } else if (dataset instanceof RangeInfo) { |
84 /* The usual case for most series */ | 75 /* The usual case for most series */ |
85 newRange = ((RangeInfo) dataset).getRangeBounds(false); | 76 newRange = ((RangeInfo) dataset).getRangeBounds(false); |
86 } else if (dataset instanceof TimeSeriesCollection) { | 77 } else if (dataset instanceof TimeSeriesCollection) { |
87 /* Lalala <3 Jfreechart's class hirarchy */ | 78 /* Lalala <3 Jfreechart's class hirarchy */ |
88 newRange = ((TimeSeriesCollection)dataset) | 79 newRange = ((TimeSeriesCollection) dataset).getRangeBounds(false); |
89 .getRangeBounds(false); | |
90 } | 80 } |
91 | 81 |
92 /* Now we only expand as we also only add new data */ | 82 /* Now we only expand as we also only add new data */ |
93 if (range == null) { | 83 if (this.range == null) { |
94 range = newRange; | 84 this.range = newRange; |
95 } else { | 85 } else { |
96 range = Range.combine(range, newRange); | 86 this.range = Range.combine(this.range, newRange); |
97 } | 87 } |
98 } | 88 } |
99 rangeDirty = false; | 89 this.rangeDirty = false; |
100 return range; | 90 return this.range; |
101 } | 91 } |
102 | 92 |
103 /** Get Array of Datasets. */ | 93 /** Get Array of Datasets. */ |
104 public XYDataset[] getDatasets() { | 94 public XYDataset[] getDatasets() { |
105 return datasets.toArray(new XYDataset[datasets.size()]); | 95 return this.datasets.toArray(new XYDataset[this.datasets.size()]); |
106 } | |
107 | |
108 /** True if to be rendered as area. */ | |
109 public boolean isArea(XYDataset series) { | |
110 return (series instanceof StyledAreaSeriesCollection); | |
111 } | 96 } |
112 | 97 |
113 /** True if no datasets given. */ | 98 /** True if no datasets given. */ |
114 public boolean isEmpty() { | 99 public boolean isEmpty() { |
115 return datasets.isEmpty(); | 100 return this.datasets.isEmpty(); |
116 } | 101 } |
117 | 102 |
118 /** Set the 'real' axis index that this axis is mapped to. */ | 103 /** Set the 'real' axis index that this axis is mapped to. */ |
119 public void setPlotAxisIndex(int axisIndex) { | 104 public void setPlotAxisIndex(final int axisIndex) { |
120 plotAxisIndex = axisIndex; | 105 this.plotAxisIndex = axisIndex; |
121 } | 106 } |
122 | 107 |
123 /** Get the 'real' axis index that this axis is mapped to. */ | 108 /** Get the 'real' axis index that this axis is mapped to. */ |
124 public int getPlotAxisIndex() { | 109 public int getPlotAxisIndex() { |
125 return plotAxisIndex; | 110 return this.plotAxisIndex; |
126 } | 111 } |
127 | |
128 /** Add a Dataset that describes an area. */ | |
129 public void addArea(StyledAreaSeriesCollection series) { | |
130 addDataset(series); | |
131 } | |
132 | |
133 } | 112 } |