CombinedData.java
6.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
package com.github.mikephil.charting.data;
import android.util.Log;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.interfaces.datasets.IBarLineScatterCandleBubbleDataSet;
import java.util.ArrayList;
import java.util.List;
/**
* Data object that allows the combination of Line-, Bar-, Scatter-, Bubble- and
* CandleData. Used in the CombinedChart class.
*
* @author Philipp Jahoda
*/
public class CombinedData extends BarLineScatterCandleBubbleData<IBarLineScatterCandleBubbleDataSet<? extends Entry>> {
private LineData mLineData;
private BarData mBarData;
private ScatterData mScatterData;
private CandleData mCandleData;
private BubbleData mBubbleData;
public CombinedData() {
super();
}
public void setData(LineData data) {
mLineData = data;
notifyDataChanged();
}
public void setData(BarData data) {
mBarData = data;
notifyDataChanged();
}
public void setData(ScatterData data) {
mScatterData = data;
notifyDataChanged();
}
public void setData(CandleData data) {
mCandleData = data;
notifyDataChanged();
}
public void setData(BubbleData data) {
mBubbleData = data;
notifyDataChanged();
}
@Override
public void calcMinMax() {
if(mDataSets == null){
mDataSets = new ArrayList<>();
}
mDataSets.clear();
mYMax = -Float.MAX_VALUE;
mYMin = Float.MAX_VALUE;
mXMax = -Float.MAX_VALUE;
mXMin = Float.MAX_VALUE;
mLeftAxisMax = -Float.MAX_VALUE;
mLeftAxisMin = Float.MAX_VALUE;
mRightAxisMax = -Float.MAX_VALUE;
mRightAxisMin = Float.MAX_VALUE;
List<BarLineScatterCandleBubbleData> allData = getAllData();
for (ChartData data : allData) {
data.calcMinMax();
List<IBarLineScatterCandleBubbleDataSet<? extends Entry>> sets = data.getDataSets();
mDataSets.addAll(sets);
if (data.getYMax() > mYMax)
mYMax = data.getYMax();
if (data.getYMin() < mYMin)
mYMin = data.getYMin();
if (data.getXMax() > mXMax)
mXMax = data.getXMax();
if (data.getXMin() < mXMin)
mXMin = data.getXMin();
if (data.mLeftAxisMax > mLeftAxisMax)
mLeftAxisMax = data.mLeftAxisMax;
if (data.mLeftAxisMin < mLeftAxisMin)
mLeftAxisMin = data.mLeftAxisMin;
if (data.mRightAxisMax > mRightAxisMax)
mRightAxisMax = data.mRightAxisMax;
if (data.mRightAxisMin < mRightAxisMin)
mRightAxisMin = data.mRightAxisMin;
}
}
public BubbleData getBubbleData() {
return mBubbleData;
}
public LineData getLineData() {
return mLineData;
}
public BarData getBarData() {
return mBarData;
}
public ScatterData getScatterData() {
return mScatterData;
}
public CandleData getCandleData() {
return mCandleData;
}
/**
* Returns all data objects in row: line-bar-scatter-candle-bubble if not null.
*
* @return
*/
public List<BarLineScatterCandleBubbleData> getAllData() {
List<BarLineScatterCandleBubbleData> data = new ArrayList<BarLineScatterCandleBubbleData>();
if (mLineData != null)
data.add(mLineData);
if (mBarData != null)
data.add(mBarData);
if (mScatterData != null)
data.add(mScatterData);
if (mCandleData != null)
data.add(mCandleData);
if (mBubbleData != null)
data.add(mBubbleData);
return data;
}
public BarLineScatterCandleBubbleData getDataByIndex(int index) {
return getAllData().get(index);
}
@Override
public void notifyDataChanged() {
if (mLineData != null)
mLineData.notifyDataChanged();
if (mBarData != null)
mBarData.notifyDataChanged();
if (mCandleData != null)
mCandleData.notifyDataChanged();
if (mScatterData != null)
mScatterData.notifyDataChanged();
if (mBubbleData != null)
mBubbleData.notifyDataChanged();
calcMinMax(); // recalculate everything
}
/**
* Get the Entry for a corresponding highlight object
*
* @param highlight
* @return the entry that is highlighted
*/
@Override
public Entry getEntryForHighlight(Highlight highlight) {
if (highlight.getDataIndex() >= getAllData().size())
return null;
ChartData data = getDataByIndex(highlight.getDataIndex());
if (highlight.getDataSetIndex() >= data.getDataSetCount())
return null;
// The value of the highlighted entry could be NaN -
// if we are not interested in highlighting a specific value.
List<Entry> entries = data.getDataSetByIndex(highlight.getDataSetIndex())
.getEntriesForXValue(highlight.getX());
for (Entry entry : entries)
if (entry.getY() == highlight.getY() ||
Float.isNaN(highlight.getY()))
return entry;
return null;
}
/**
* Get dataset for highlight
*
* @param highlight current highlight
* @return dataset related to highlight
*/
public IBarLineScatterCandleBubbleDataSet<? extends Entry> getDataSetByHighlight(Highlight highlight) {
if (highlight.getDataIndex() >= getAllData().size())
return null;
BarLineScatterCandleBubbleData data = getDataByIndex(highlight.getDataIndex());
if (highlight.getDataSetIndex() >= data.getDataSetCount())
return null;
return (IBarLineScatterCandleBubbleDataSet<? extends Entry>)
data.getDataSets().get(highlight.getDataSetIndex());
}
public int getDataIndex(ChartData data) {
return getAllData().indexOf(data);
}
@Override
public boolean removeDataSet(IBarLineScatterCandleBubbleDataSet<? extends Entry> d) {
List<BarLineScatterCandleBubbleData> datas = getAllData();
boolean success = false;
for (ChartData data : datas) {
success = data.removeDataSet(d);
if (success) {
break;
}
}
return success;
}
@Deprecated
@Override
public boolean removeDataSet(int index) {
Log.e("MPAndroidChart", "removeDataSet(int index) not supported for CombinedData");
return false;
}
@Deprecated
@Override
public boolean removeEntry(Entry e, int dataSetIndex) {
Log.e("MPAndroidChart", "removeEntry(...) not supported for CombinedData");
return false;
}
@Deprecated
@Override
public boolean removeEntry(float xValue, int dataSetIndex) {
Log.e("MPAndroidChart", "removeEntry(...) not supported for CombinedData");
return false;
}
}