PieRadarHighlighter.java
1.71 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
package com.github.mikephil.charting.highlight;
import com.github.mikephil.charting.charts.PieChart;
import com.github.mikephil.charting.charts.PieRadarChartBase;
import java.util.ArrayList;
import java.util.List;
/**
* Created by philipp on 12/06/16.
*/
public abstract class PieRadarHighlighter<T extends PieRadarChartBase> implements IHighlighter
{
protected T mChart;
/**
* buffer for storing previously highlighted values
*/
protected List<Highlight> mHighlightBuffer = new ArrayList<Highlight>();
public PieRadarHighlighter(T chart) {
this.mChart = chart;
}
@Override
public Highlight getHighlight(float x, float y) {
float touchDistanceToCenter = mChart.distanceToCenter(x, y);
// check if a slice was touched
if (touchDistanceToCenter > mChart.getRadius()) {
// if no slice was touched, highlight nothing
return null;
} else {
float angle = mChart.getAngleForPoint(x, y);
if (mChart instanceof PieChart) {
angle /= mChart.getAnimator().getPhaseY();
}
int index = mChart.getIndexForAngle(angle);
// check if the index could be found
if (index < 0 || index >= mChart.getData().getMaxEntryCountSet().getEntryCount()) {
return null;
} else {
return getClosestHighlight(index, x, y);
}
}
}
/**
* Returns the closest Highlight object of the given objects based on the touch position inside the chart.
*
* @param index
* @param x
* @param y
* @return
*/
protected abstract Highlight getClosestHighlight(int index, float x, float y);
}