Skip to content

Commit f5a5284

Browse files
committed
barBuffers as MuteableList
1 parent b6e15b5 commit f5a5284

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
@@ -29,7 +29,7 @@ open class BarChartRenderer(
2929
protected var barRect: RectF = RectF()
3030

3131
@JvmField
32-
protected var barBuffers: Array<BarBuffer?>? = null
32+
protected var barBuffers: MutableList<BarBuffer?> = mutableListOf()
3333

3434
@JvmField
3535
protected var shadowPaint: Paint
@@ -57,19 +57,20 @@ open class BarChartRenderer(
5757

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

7172
override fun drawData(c: Canvas) {
72-
if (barBuffers == null) {
73+
if (barBuffers.size == 0) {
7374
initBuffers()
7475
}
7576

@@ -155,7 +156,7 @@ open class BarChartRenderer(
155156
}
156157

157158
// initialize the buffer
158-
val buffer = barBuffers!![index]!!.apply {
159+
val buffer = barBuffers[index]!!.apply {
159160
setPhases(phaseX, phaseY)
160161
setDataSet(index)
161162
setInverted(chart.isInverted(dataSet.axisDependency))
@@ -286,7 +287,7 @@ open class BarChartRenderer(
286287
}
287288

288289
// get the buffer
289-
val buffer = barBuffers!![i]
290+
val buffer = barBuffers[i]
290291

291292
val phaseY = animator.phaseY
292293

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)