CombinedHighlighter.java
3 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
package com.github.mikephil.charting.highlight;
import com.github.mikephil.charting.data.BarData;
import com.github.mikephil.charting.data.BarLineScatterCandleBubbleData;
import com.github.mikephil.charting.data.ChartData;
import com.github.mikephil.charting.data.DataSet;
import com.github.mikephil.charting.interfaces.dataprovider.BarDataProvider;
import com.github.mikephil.charting.interfaces.dataprovider.CombinedDataProvider;
import com.github.mikephil.charting.interfaces.datasets.IDataSet;
import java.util.List;
/**
* Created by Philipp Jahoda on 12/09/15.
*/
public class CombinedHighlighter extends ChartHighlighter<CombinedDataProvider> implements IHighlighter
{
/**
* bar highlighter for supporting stacked highlighting
*/
protected BarHighlighter barHighlighter;
public CombinedHighlighter(CombinedDataProvider chart, BarDataProvider barChart) {
super(chart);
// if there is BarData, create a BarHighlighter
barHighlighter = barChart.getBarData() == null ? null : new BarHighlighter(barChart);
}
@Override
protected List<Highlight> getHighlightsAtXValue(float xVal, float x, float y) {
mHighlightBuffer.clear();
List<BarLineScatterCandleBubbleData> dataObjects = mChart.getCombinedData().getAllData();
for (int i = 0; i < dataObjects.size(); i++) {
ChartData dataObject = dataObjects.get(i);
// in case of BarData, let the BarHighlighter take over
if (barHighlighter != null && dataObject instanceof BarData) {
Highlight high = barHighlighter.getHighlight(x, y);
if (high != null) {
high.setDataIndex(i);
mHighlightBuffer.add(high);
}
} else {
for (int j = 0, dataSetCount = dataObject.getDataSetCount(); j < dataSetCount; j++) {
IDataSet dataSet = dataObjects.get(i).getDataSetByIndex(j);
// don't include datasets that cannot be highlighted
if (!dataSet.isHighlightEnabled())
continue;
List<Highlight> highs = buildHighlights(dataSet, j, xVal, DataSet.Rounding.CLOSEST);
for (Highlight high : highs)
{
high.setDataIndex(i);
mHighlightBuffer.add(high);
}
}
}
}
return mHighlightBuffer;
}
// protected Highlight getClosest(float x, float y, Highlight... highs) {
//
// Highlight closest = null;
// float minDistance = Float.MAX_VALUE;
//
// for (Highlight high : highs) {
//
// if (high == null)
// continue;
//
// float tempDistance = getDistance(x, y, high.getXPx(), high.getYPx());
//
// if (tempDistance < minDistance) {
// minDistance = tempDistance;
// closest = high;
// }
// }
//
// return closest;
// }
}