forked from PhilJay/MPAndroidChart
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLineBuffer.java
More file actions
58 lines (41 loc) · 1.33 KB
/
LineBuffer.java
File metadata and controls
58 lines (41 loc) · 1.33 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
package com.github.mikephil.charting.buffer;
import com.github.mikephil.charting.data.Entry;
import java.util.List;
public class LineBuffer extends AbstractBuffer<Entry> {
public LineBuffer(int size) {
super((size < 4) ? 4 : size);
}
public void moveTo(float x, float y) {
if (index != 0)
return;
buffer[index++] = x;
buffer[index++] = y;
// in case just one entry, this is overwritten when lineTo is called
buffer[index] = x;
buffer[index + 1] = y;
}
public void lineTo(float x, float y) {
if (index == 2) {
buffer[index++] = x;
buffer[index++] = y;
} else {
float prevX = buffer[index - 2];
float prevY = buffer[index - 1];
buffer[index++] = prevX;
buffer[index++] = prevY;
buffer[index++] = x;
buffer[index++] = y;
}
}
@Override
public void feed(List<Entry> entries) {
moveTo(entries.get(mFrom).getXIndex(), entries.get(mFrom).getVal() * phaseY);
int size = (int) Math.ceil((mTo - mFrom) * phaseX + mFrom);
int from = mFrom + 1;
for (int i = from; i < size; i++) {
Entry e = entries.get(i);
lineTo(e.getXIndex(), e.getVal() * phaseY);
}
reset();
}
}