Skip to content

Commit 4d3919c

Browse files
committed
barBuffers as MutaableList
1 parent 87b0618 commit 4d3919c

File tree

4 files changed

+21
-19
lines changed

4 files changed

+21
-19
lines changed

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

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@ 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
35+
3536
@JvmField
3637
protected var barBorderPaint: Paint
3738

@@ -55,19 +56,20 @@ open class BarChartRenderer(
5556

5657
override fun initBuffers() {
5758
val barData = chart.barData
58-
barBuffers = arrayOfNulls(barData.dataSetCount)
59-
60-
for (i in barBuffers!!.indices) {
61-
val set = barData.getDataSetByIndex(i)
62-
barBuffers!![i] = BarBuffer(
63-
set.entryCount * 4 * (if (set.isStacked) set.stackSize else 1),
64-
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+
)
6567
)
6668
}
6769
}
6870

6971
override fun drawData(c: Canvas) {
70-
if (barBuffers == null) {
72+
if (barBuffers.size == 0) {
7173
initBuffers()
7274
}
7375

@@ -154,7 +156,7 @@ open class BarChartRenderer(
154156
}
155157

156158
// initialize the buffer
157-
val buffer = barBuffers!![index]
159+
val buffer = barBuffers[index]
158160
buffer!!.setPhases(phaseX, phaseY)
159161
buffer.setDataSet(index)
160162
buffer.setInverted(chart.isInverted(dataSet.axisDependency))
@@ -286,7 +288,7 @@ open class BarChartRenderer(
286288
}
287289

288290
// get the buffer
289-
val buffer = barBuffers!![i]
291+
val buffer = barBuffers[i]
290292

291293
val phaseY = mAnimator.phaseY
292294

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
@@ -42,12 +42,12 @@ public HorizontalBarChartRenderer(BarDataProvider chart, ChartAnimator animator,
4242
public void initBuffers() {
4343

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

47-
for (int i = 0; i < barBuffers.length; i++) {
47+
for (int i = 0; i < barData.getDataSetCount(); i++) {
4848
IBarDataSet set = barData.getDataSetByIndex(i);
49-
barBuffers[i] = new HorizontalBarBuffer(set.getEntryCount() * 4 * (set.isStacked() ? set.getStackSize() : 1),
50-
barData.getDataSetCount(), set.isStacked());
49+
barBuffers.add(new HorizontalBarBuffer(set.getEntryCount() * 4 * (set.isStacked() ? set.getStackSize() : 1),
50+
barData.getDataSetCount(), set.isStacked()));
5151
}
5252
}
5353

@@ -105,7 +105,7 @@ protected void drawDataSet(Canvas c, IBarDataSet dataSet, int index) {
105105
}
106106

107107
// initialize the buffer
108-
BarBuffer buffer = barBuffers[index];
108+
BarBuffer buffer = barBuffers.get(index);
109109
buffer.setPhases(phaseX, phaseY);
110110
buffer.setDataSet(index);
111111
buffer.setInverted(chart.isInverted(dataSet.getAxisDependency()));
@@ -192,7 +192,7 @@ public void drawValues(Canvas c) {
192192
IValueFormatter formatter = dataSet.getValueFormatter();
193193

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

197197
final float phaseY = mAnimator.getPhaseY();
198198

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

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

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

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)