|
13 | 13 | */ |
14 | 14 | public class RadarHighlighter extends PieRadarHighlighter<RadarChart> { |
15 | 15 |
|
16 | | - public RadarHighlighter(RadarChart chart) { |
17 | | - super(chart); |
18 | | - } |
| 16 | + public RadarHighlighter(RadarChart chart) { |
| 17 | + super(chart); |
| 18 | + } |
19 | 19 |
|
20 | | - @Override |
21 | | - protected Highlight getClosestHighlight(int index, float x, float y) { |
| 20 | + @Override |
| 21 | + protected Highlight getClosestHighlight(int index, float x, float y) { |
22 | 22 |
|
23 | | - List<Highlight> highlights = getHighlightsAtIndex(index); |
| 23 | + List<Highlight> highlights = getHighlightsAtIndex(index); |
24 | 24 |
|
25 | | - float distanceToCenter = mChart.distanceToCenter(x, y) / mChart.getFactor(); |
| 25 | + float distanceToCenter = mChart.distanceToCenter(x, y) / mChart.getFactor(); |
26 | 26 |
|
27 | | - Highlight closest = null; |
28 | | - float distance = Float.MAX_VALUE; |
| 27 | + Highlight closest = null; |
| 28 | + float distance = Float.MAX_VALUE; |
29 | 29 |
|
30 | | - for (int i = 0; i < highlights.size(); i++) { |
| 30 | + for (int i = 0; i < highlights.size(); i++) { |
31 | 31 |
|
32 | | - Highlight high = highlights.get(i); |
| 32 | + Highlight high = highlights.get(i); |
33 | 33 |
|
34 | | - float cdistance = Math.abs(high.getY() - distanceToCenter); |
35 | | - if (cdistance < distance) { |
36 | | - closest = high; |
37 | | - distance = cdistance; |
38 | | - } |
39 | | - } |
| 34 | + float cdistance = Math.abs(high.getY() - distanceToCenter); |
| 35 | + if (cdistance < distance) { |
| 36 | + closest = high; |
| 37 | + distance = cdistance; |
| 38 | + } |
| 39 | + } |
40 | 40 |
|
41 | | - return closest; |
42 | | - } |
43 | | - /** |
44 | | - * Returns an array of Highlight objects for the given index. The Highlight |
45 | | - * objects give information about the value at the selected index and the |
46 | | - * DataSet it belongs to. INFORMATION: This method does calculations at |
47 | | - * runtime. Do not over-use in performance critical situations. |
48 | | - */ |
49 | | - protected List<Highlight> getHighlightsAtIndex(int index) { |
| 41 | + return closest; |
| 42 | + } |
50 | 43 |
|
51 | | - mHighlightBuffer.clear(); |
| 44 | + /** |
| 45 | + * Returns an array of Highlight objects for the given index. The Highlight |
| 46 | + * objects give information about the value at the selected index and the |
| 47 | + * DataSet it belongs to. INFORMATION: This method does calculations at |
| 48 | + * runtime. Do not over-use in performance critical situations. |
| 49 | + */ |
| 50 | + protected List<Highlight> getHighlightsAtIndex(int index) { |
52 | 51 |
|
53 | | - float phaseX = mChart.getAnimator().getPhaseX(); |
54 | | - float phaseY = mChart.getAnimator().getPhaseY(); |
55 | | - float sliceangle = mChart.getSliceAngle(); |
56 | | - float factor = mChart.getFactor(); |
| 52 | + mHighlightBuffer.clear(); |
57 | 53 |
|
58 | | - MPPointF pOut = MPPointF.getInstance(0,0); |
59 | | - for (int i = 0; i < mChart.getData().getDataSetCount(); i++) { |
| 54 | + float phaseX = mChart.getAnimator().getPhaseX(); |
| 55 | + float phaseY = mChart.getAnimator().getPhaseY(); |
| 56 | + float sliceangle = mChart.getSliceAngle(); |
| 57 | + float factor = mChart.getFactor(); |
60 | 58 |
|
61 | | - IDataSet<?> dataSet = mChart.getData().getDataSetByIndex(i); |
| 59 | + MPPointF pOut = MPPointF.getInstance(0, 0); |
| 60 | + for (int i = 0; i < mChart.getData().getDataSetCount(); i++) { |
62 | 61 |
|
63 | | - final Entry entry = dataSet.getEntryForIndex(index); |
| 62 | + IDataSet<?> dataSet = mChart.getData().getDataSetByIndex(i); |
64 | 63 |
|
65 | | - float y = (entry.getY() - mChart.getYChartMin()); |
| 64 | + final Entry entry = dataSet.getEntryForIndex(index); |
66 | 65 |
|
67 | | - Utils.getPosition( |
68 | | - mChart.getCenterOffsets(), y * factor * phaseY, |
69 | | - sliceangle * index * phaseX + mChart.getRotationAngle(), pOut); |
| 66 | + float y = (entry.getY() - mChart.getYChartMin()); |
70 | 67 |
|
71 | | - mHighlightBuffer.add(new Highlight(index, entry.getY(), pOut.x, pOut.y, i, dataSet.getAxisDependency())); |
72 | | - } |
| 68 | + Utils.getPosition( |
| 69 | + mChart.getCenterOffsets(), y * factor * phaseY, |
| 70 | + sliceangle * index * phaseX + mChart.getRotationAngle(), pOut |
| 71 | + ); |
73 | 72 |
|
74 | | - return mHighlightBuffer; |
75 | | - } |
| 73 | + mHighlightBuffer.add(new Highlight(index, entry.getY(), pOut.x, pOut.y, i, dataSet.getAxisDependency())); |
| 74 | + } |
| 75 | + |
| 76 | + return mHighlightBuffer; |
| 77 | + } |
76 | 78 | } |
0 commit comments