Skip to content

Commit f43605c

Browse files
committed
Buffer size
1 parent e8781c0 commit f43605c

File tree

4 files changed

+8
-6
lines changed

4 files changed

+8
-6
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ package com.github.mikephil.charting.buffer
55
*
66
* @param <T> The data the buffer accepts to be fed with.
77
</T> */
8-
abstract class AbstractBuffer<T> {
8+
abstract class AbstractBuffer<T>(size: Int) {
99
/** index in the buffer */
1010
@JvmField
1111
protected var index: Int = 0
1212

1313
/** float-buffer that holds the data points to draw, order: x,y,x,y,... */
1414
@JvmField
15-
val buffer: MutableList<Float> = mutableListOf()
15+
var buffer: MutableList<Float> = mutableListOf()
1616

1717
/** animation phase x-axis */
1818
@JvmField
@@ -30,6 +30,7 @@ abstract class AbstractBuffer<T> {
3030

3131
init {
3232
index = 0
33+
buffer = FloatArray(size).toMutableList()
3334
}
3435

3536
/** limits the drawing on the x-axis */

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package com.github.mikephil.charting.buffer
33
import com.github.mikephil.charting.interfaces.datasets.IBarDataSet
44
import kotlin.math.abs
55

6-
open class BarBuffer(dataSetCount: Int, containsStacks: Boolean) : AbstractBuffer<IBarDataSet?>() {
6+
open class BarBuffer(size: Int, dataSetCount: Int, containsStacks: Boolean) : AbstractBuffer<IBarDataSet?>(size) {
77
protected var dataSetIndex: Int = 0
88
protected var dataSetCount: Int = 1
99

MPChartLib/src/main/java/com/github/mikephil/charting/buffer/HorizontalBarBuffer.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package com.github.mikephil.charting.buffer
33
import com.github.mikephil.charting.interfaces.datasets.IBarDataSet
44
import kotlin.math.abs
55

6-
class HorizontalBarBuffer(size: Int, dataSetCount: Int, containsStacks: Boolean) : BarBuffer(dataSetCount, containsStacks) {
6+
class HorizontalBarBuffer(size: Int, dataSetCount: Int, containsStacks: Boolean) : BarBuffer(size, dataSetCount, containsStacks) {
77
override fun feed(data: IBarDataSet?) {
88
val size = (data?.entryCount ?: 0) * phaseX
99
val barWidthHalf = barWidth / 2f

MPChartLib/src/main/java/com/github/mikephil/charting/renderer/BarChartRenderer.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,11 @@ open class BarChartRenderer(
5959
val barData = chart.barData
6060
barBuffers = mutableListOf()
6161

62-
barData.dataSets.forEach {
62+
barData.dataSets.forEach { iBarDataSet ->
6363
barBuffers.add(
6464
BarBuffer(
65-
barData.dataSetCount, it.isStacked
65+
iBarDataSet.entryCount * 4 * (if (iBarDataSet.isStacked) iBarDataSet.stackSize else 1),
66+
barData.dataSetCount, iBarDataSet.isStacked
6667
)
6768
)
6869
}

0 commit comments

Comments
 (0)