Skip to content

Commit df70d4c

Browse files
committed
Buffer in Kotlin
1 parent bf4e08f commit df70d4c

File tree

6 files changed

+242
-240
lines changed

6 files changed

+242
-240
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: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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+
init {
32+
index = 0
33+
buffer = FloatArray(size)
34+
}
35+
36+
/** limits the drawing on the x-axis */
37+
fun limitFrom(fromGiven: Int) {
38+
var fromLocal = fromGiven
39+
if (fromLocal < 0)
40+
fromLocal = 0
41+
from = fromLocal
42+
}
43+
44+
/** limits the drawing on the x-axis */
45+
fun limitTo(toGiven: Int) {
46+
var toLocal = toGiven
47+
if (toLocal < 0)
48+
toLocal = 0
49+
to = toLocal
50+
}
51+
52+
/**
53+
* Resets the buffer index to 0 and makes the buffer reusable.
54+
*/
55+
fun reset() {
56+
index = 0
57+
}
58+
59+
/**
60+
* Returns the size (length) of the buffer array.
61+
*
62+
* @return
63+
*/
64+
fun size(): Int {
65+
return buffer.size
66+
}
67+
68+
/**
69+
* Set the phases used for animations.
70+
*
71+
* @param phaseX
72+
* @param phaseY
73+
*/
74+
fun setPhases(phaseX: Float, phaseY: Float) {
75+
this.phaseX = phaseX
76+
this.phaseY = phaseY
77+
}
78+
79+
/**
80+
* Builds up the buffer with the provided data and resets the buffer-index
81+
* after feed-completion. This needs to run FAST.
82+
*
83+
* @param data
84+
*/
85+
abstract fun feed(data: T)
86+
}

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

Lines changed: 0 additions & 130 deletions
This file was deleted.

0 commit comments

Comments
 (0)