BarLineScatterCandleBubbleRenderer.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
94
95
96
package com.github.mikephil.charting.renderer;
import com.github.mikephil.charting.animation.ChartAnimator;
import com.github.mikephil.charting.data.DataSet;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.interfaces.dataprovider.BarLineScatterCandleBubbleDataProvider;
import com.github.mikephil.charting.interfaces.datasets.IBarLineScatterCandleBubbleDataSet;
import com.github.mikephil.charting.interfaces.datasets.IDataSet;
import com.github.mikephil.charting.utils.ViewPortHandler;
/**
* Created by Philipp Jahoda on 09/06/16.
*/
public abstract class BarLineScatterCandleBubbleRenderer extends DataRenderer {
/**
* buffer for storing the current minimum and maximum visible x
*/
protected XBounds mXBounds = new XBounds();
public BarLineScatterCandleBubbleRenderer(ChartAnimator animator, ViewPortHandler viewPortHandler) {
super(animator, viewPortHandler);
}
/**
* Returns true if the DataSet values should be drawn, false if not.
*
* @param set
* @return
*/
protected boolean shouldDrawValues(IDataSet set) {
return set.isVisible() && (set.isDrawValuesEnabled() || set.isDrawIconsEnabled());
}
/**
* Checks if the provided entry object is in bounds for drawing considering the current animation phase.
*
* @param e
* @param set
* @return
*/
protected boolean isInBoundsX(Entry e, IBarLineScatterCandleBubbleDataSet set) {
if (e == null)
return false;
float entryIndex = set.getEntryIndex(e);
if (e == null || entryIndex >= set.getEntryCount() * mAnimator.getPhaseX()) {
return false;
} else {
return true;
}
}
/**
* Class representing the bounds of the current viewport in terms of indices in the values array of a DataSet.
*/
protected class XBounds {
/**
* minimum visible entry index
*/
public int min;
/**
* maximum visible entry index
*/
public int max;
/**
* range of visible entry indices
*/
public int range;
/**
* Calculates the minimum and maximum x values as well as the range between them.
*
* @param chart
* @param dataSet
*/
public void set(BarLineScatterCandleBubbleDataProvider chart, IBarLineScatterCandleBubbleDataSet dataSet) {
float phaseX = Math.max(0.f, Math.min(1.f, mAnimator.getPhaseX()));
float low = chart.getLowestVisibleX();
float high = chart.getHighestVisibleX();
Entry entryFrom = dataSet.getEntryForXValue(low, Float.NaN, DataSet.Rounding.DOWN);
Entry entryTo = dataSet.getEntryForXValue(high, Float.NaN, DataSet.Rounding.UP);
min = entryFrom == null ? 0 : dataSet.getEntryIndex(entryFrom);
max = entryTo == null ? 0 : dataSet.getEntryIndex(entryTo);
range = (int) ((max - min) * phaseX);
}
}
}