Skip to content

Commit b1f8c73

Browse files
committed
barBuffers as MuteableList
1 parent ac2c242 commit b1f8c73

File tree

3 files changed

+19
-18
lines changed

3 files changed

+19
-18
lines changed

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

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ open class BarChartRenderer(
2828
protected var barRect: RectF = RectF()
2929

3030
@JvmField
31-
protected var barBuffers: Array<BarBuffer?>? = null
31+
protected var barBuffers: MutableList<BarBuffer?> = mutableListOf()
3232

3333
@JvmField
3434
protected var shadowPaint: Paint
@@ -56,19 +56,20 @@ open class BarChartRenderer(
5656

5757
override fun initBuffers() {
5858
val barData = chart.barData
59-
barBuffers = arrayOfNulls(barData.dataSetCount)
60-
61-
for (i in barBuffers!!.indices) {
62-
val set = barData.getDataSetByIndex(i)
63-
barBuffers!![i] = BarBuffer(
64-
set.entryCount * 4 * (if (set.isStacked) set.stackSize else 1),
65-
barData.dataSetCount, set.isStacked
59+
barBuffers = mutableListOf()
60+
61+
barData.dataSets.forEach {
62+
barBuffers.add(
63+
BarBuffer(
64+
it.entryCount * 4 * (if (it.isStacked) it.stackSize else 1),
65+
barData.dataSetCount, it.isStacked
66+
)
6667
)
6768
}
6869
}
6970

7071
override fun drawData(c: Canvas) {
71-
if (barBuffers == null) {
72+
if (barBuffers.size == 0) {
7273
initBuffers()
7374
}
7475

@@ -154,7 +155,7 @@ open class BarChartRenderer(
154155
}
155156

156157
// initialize the buffer
157-
val buffer = barBuffers!![index]!!.apply {
158+
val buffer = barBuffers[index]!!.apply {
158159
setPhases(phaseX, phaseY)
159160
setDataSet(index)
160161
setInverted(chart.isInverted(dataSet.axisDependency))
@@ -285,7 +286,7 @@ open class BarChartRenderer(
285286
}
286287

287288
// get the buffer
288-
val buffer = barBuffers!![i]
289+
val buffer = barBuffers[i]
289290

290291
val phaseY = animator.phaseY
291292

MPChartLib/src/main/java/com/github/mikephil/charting/renderer/HorizontalBarChartRenderer.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ public HorizontalBarChartRenderer(BarDataProvider chart, ChartAnimator animator,
4444
public void initBuffers() {
4545

4646
BarData barData = chart.getBarData();
47-
barBuffers = new HorizontalBarBuffer[barData.getDataSetCount()];
47+
// barBuffers = new HorizontalBarBuffer[barData.getDataSetCount()];
4848

49-
for (int i = 0; i < barBuffers.length; i++) {
49+
for (int i = 0; i < barData.getDataSetCount(); i++) {
5050
IBarDataSet set = barData.getDataSetByIndex(i);
51-
barBuffers[i] = new HorizontalBarBuffer(set.getEntryCount() * 4 * (set.isStacked() ? set.getStackSize() : 1),
52-
barData.getDataSetCount(), set.isStacked());
51+
barBuffers.add(new HorizontalBarBuffer(set.getEntryCount() * 4 * (set.isStacked() ? set.getStackSize() : 1),
52+
barData.getDataSetCount(), set.isStacked()));
5353
}
5454
}
5555

@@ -107,7 +107,7 @@ protected void drawDataSet(@NonNull Canvas c, IBarDataSet dataSet, int index) {
107107
}
108108

109109
// initialize the buffer
110-
BarBuffer buffer = barBuffers[index];
110+
BarBuffer buffer = barBuffers.get(index);
111111
buffer.setPhases(phaseX, phaseY);
112112
buffer.setDataSet(index);
113113
buffer.setInverted(chart.isInverted(dataSet.getAxisDependency()));
@@ -194,7 +194,7 @@ public void drawValues(@NonNull Canvas c) {
194194
IValueFormatter formatter = dataSet.getValueFormatter();
195195

196196
// get the buffer
197-
BarBuffer buffer = barBuffers[i];
197+
BarBuffer buffer = barBuffers.get(i);
198198

199199
final float phaseY = animator.getPhaseY();
200200

MPChartLib/src/main/java/com/github/mikephil/charting/renderer/RoundedHorizontalBarChartRenderer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ protected void drawDataSet(Canvas c, IBarDataSet dataSet, int index) {
8787
}
8888
}
8989

90-
BarBuffer buffer = barBuffers[index];
90+
BarBuffer buffer = barBuffers.get(index);
9191
buffer.setPhases(phaseX, phaseY);
9292
buffer.setDataSet(index);
9393
buffer.setInverted(chart.isInverted(dataSet.getAxisDependency()));

0 commit comments

Comments
 (0)