Skip to content

Commit 87b0618

Browse files
authored
Merge pull request #338 from AppDevNext/KotlinBuffer
Kotlin buffer
2 parents f5d5f6a + 0c04154 commit 87b0618

File tree

2 files changed

+91
-91
lines changed

2 files changed

+91
-91
lines changed

MPChartLib/src/main/java/com/github/mikephil/charting/buffer/AbstractBuffer.java

Lines changed: 0 additions & 91 deletions
This file was deleted.
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
package com.github.mikephil.charting.buffer
2+
3+
/**
4+
* Buffer class to boost performance while drawing. Concept: Replace instead of recreate.
5+
*
6+
* @param <T> The data the buffer accepts to be fed with.
7+
</T> */
8+
abstract class AbstractBuffer<T>(size: Int) {
9+
/** index in the buffer */
10+
@JvmField
11+
protected var index: Int = 0
12+
13+
/** float-buffer that holds the data points to draw, order: x,y,x,y,... */
14+
@JvmField
15+
val buffer: FloatArray
16+
17+
/** animation phase x-axis */
18+
@JvmField
19+
protected var phaseX: Float = 1f
20+
21+
/** animation phase y-axis */
22+
@JvmField
23+
protected var phaseY: Float = 1f
24+
25+
/** indicates from which x-index the visible data begins */
26+
protected var from: Int = 0
27+
28+
/** indicates to which x-index the visible data ranges */
29+
protected var to: Int = 0
30+
31+
/**
32+
* Initialization with buffer-size.
33+
*
34+
* @param size
35+
*/
36+
init {
37+
index = 0
38+
buffer = FloatArray(size)
39+
}
40+
41+
/** limits the drawing on the x-axis */
42+
fun limitFrom(fromGiven: Int) {
43+
from = if (fromGiven < 0)
44+
0
45+
else
46+
fromGiven
47+
}
48+
49+
/** limits the drawing on the x-axis */
50+
fun limitTo(toGiven: Int) {
51+
to = if (toGiven < 0)
52+
0
53+
else
54+
toGiven
55+
}
56+
57+
/**
58+
* Resets the buffer index to 0 and makes the buffer reusable.
59+
*/
60+
fun reset() {
61+
index = 0
62+
}
63+
64+
/**
65+
* Returns the size (length) of the buffer array.
66+
*
67+
* @return
68+
*/
69+
fun size(): Int {
70+
return buffer.size
71+
}
72+
73+
/**
74+
* Set the phases used for animations.
75+
*
76+
* @param phaseX
77+
* @param phaseY
78+
*/
79+
fun setPhases(phaseX: Float, phaseY: Float) {
80+
this.phaseX = phaseX
81+
this.phaseY = phaseY
82+
}
83+
84+
/**
85+
* Builds up the buffer with the provided data and resets the buffer-index
86+
* after feed-completion. This needs to run FAST.
87+
*
88+
* @param data
89+
*/
90+
abstract fun feed(data: T)
91+
}

0 commit comments

Comments
 (0)