Skip to content

barBuffers as MuteableList #339

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions MPChartLib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ dependencies {
implementation 'androidx.annotation:annotation:1.9.1'
implementation 'androidx.core:core:1.16.0'
implementation "androidx.activity:activity-ktx:1.10.1"
api "com.github.AppDevNext.Logcat:LogcatCoreLib:3.3.1"
testImplementation 'junit:junit:4.13.2'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ package com.github.mikephil.charting.buffer
*
* @param <T> The data the buffer accepts to be fed with.
</T> */
abstract class AbstractBuffer<T>(size: Int) {
abstract class AbstractBuffer<T> {
/** index in the buffer */
@JvmField
protected var index: Int = 0

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

/** animation phase x-axis */
@JvmField
Expand All @@ -30,7 +30,6 @@ abstract class AbstractBuffer<T>(size: Int) {

init {
index = 0
buffer = FloatArray(size)
}

/** limits the drawing on the x-axis */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.github.mikephil.charting.buffer
import com.github.mikephil.charting.interfaces.datasets.IBarDataSet
import kotlin.math.abs

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

Expand Down Expand Up @@ -48,7 +48,7 @@ open class BarBuffer(size: Int, dataSetCount: Int, containsStacks: Boolean) : Ab
", containsStacks=" + containsStacks +
", inverted=" + inverted +
", barWidth=" + barWidth +
", buffer=" + buffer.contentToString() +
", buffer=" + buffer +
", index=" + index +
'}'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.github.mikephil.charting.buffer
import com.github.mikephil.charting.interfaces.datasets.IBarDataSet
import kotlin.math.abs

class HorizontalBarBuffer(size: Int, dataSetCount: Int, containsStacks: Boolean) : BarBuffer(size, dataSetCount, containsStacks) {
class HorizontalBarBuffer(size: Int, dataSetCount: Int, containsStacks: Boolean) : BarBuffer(dataSetCount, containsStacks) {
override fun feed(data: IBarDataSet?) {
val size = (data?.entryCount ?: 0) * phaseX
val barWidthHalf = barWidth / 2f
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import com.github.mikephil.charting.utils.MPPointF
import com.github.mikephil.charting.utils.Transformer
import com.github.mikephil.charting.utils.Utils
import com.github.mikephil.charting.utils.ViewPortHandler
import timber.log.Timber
import kotlin.math.ceil
import kotlin.math.min

Expand Down Expand Up @@ -59,11 +60,11 @@ open class BarChartRenderer(
val barData = chart.barData
barBuffers = mutableListOf()

barData.dataSets.forEach {
barData.dataSets.forEachIndexed { index, iBarDataSet ->
Timber.d("$index ${barBuffers.size}")
barBuffers.add(
BarBuffer(
it.entryCount * 4 * (if (it.isStacked) it.stackSize else 1),
barData.dataSetCount, it.isStacked
barData.dataSetCount, iBarDataSet.isStacked
)
)
}
Expand All @@ -78,7 +79,6 @@ open class BarChartRenderer(

for (i in 0..<barData.dataSetCount) {
val set = barData.getDataSetByIndex(i)

if (set.isVisible) {
drawDataSet(c, set, i)
}
Expand Down Expand Up @@ -112,6 +112,7 @@ open class BarChartRenderer(
val phaseX = animator.phaseX
val phaseY = animator.phaseY

Timber.d("shadow=${chart.isDrawBarShadowEnabled}")
// draw the bar shadow before the values
if (chart.isDrawBarShadowEnabled) {
shadowPaint.color = dataSet.barShadowColor
Expand All @@ -125,6 +126,7 @@ open class BarChartRenderer(
var i = 0
val count = min((ceil(((dataSet.entryCount).toFloat() * phaseX).toDouble())).toInt().toDouble(), dataSet.entryCount.toDouble()).toInt()
while (i < count) {
Timber.d("$i")
val e = dataSet.getEntryForIndex(i)

x = e.x
Expand Down Expand Up @@ -156,14 +158,15 @@ open class BarChartRenderer(
}

// initialize the buffer
Timber.d("Init buffer index=$index size=${barBuffers!!.size} ${barBuffers!![index]}")
val buffer = barBuffers[index]!!.apply {
setPhases(phaseX, phaseY)
setDataSet(index)
setInverted(chart.isInverted(dataSet.axisDependency))
setBarWidth(chart.barData.barWidth)
feed(dataSet)
}
trans!!.pointValuesToPixel(buffer.buffer)
trans!!.pointValuesToPixel(buffer.buffer.toFloatArray())

val isCustomFill = dataSet.fills != null && dataSet.fills.isNotEmpty()
val isSingleColor = dataSet.colors.size == 1
Expand All @@ -175,14 +178,19 @@ open class BarChartRenderer(

var j = 0
var pos = 0
var cnt = -1
while (j < buffer.size()) {
cnt++
Timber.d("buffer #${j} $cnt buf=${buffer.buffer[j + 2]} ${viewPortHandler.contentRect}")
if (!viewPortHandler.isInBoundsLeft(buffer.buffer[j + 2])) {
j += 4
pos++
Timber.d("continue 1")
continue
}

if (!viewPortHandler.isInBoundsRight(buffer.buffer[j])) {
Timber.d("break")
break
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ open class HorizontalBarChartRenderer(

buffer.feed(dataSet)

trans!!.pointValuesToPixel(buffer.buffer)
trans!!.pointValuesToPixel(buffer.buffer.toFloatArray())

val isCustomFill = dataSet.fills != null && dataSet.fills.isNotEmpty()
val isCustomFill = dataSet.fills != null && !dataSet.fills.isEmpty()
val isSingleColor = dataSet.colors.size == 1
val isInverted = chart.isInverted(dataSet.axisDependency)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ class RoundedBarChartRenderer(chart: BarDataProvider, animator: ChartAnimator?,
}
}

val buffer = barBuffers!![index]!!
val buffer = barBuffers[index]!!
buffer.setPhases(phaseX, phaseY)
buffer.setDataSet(index)
buffer.setInverted(chart.isInverted(dataSet.axisDependency))
buffer.setBarWidth(chart.barData.barWidth)
buffer.feed(dataSet)
trans!!.pointValuesToPixel(buffer.buffer)
trans!!.pointValuesToPixel(buffer.buffer.toFloatArray())

// if multiple colors has been assigned to Bar Chart
if (dataSet.colors.size > 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class RoundedHorizontalBarChartRenderer(chart: BarDataProvider, animator: ChartA
buffer.setInverted(chart.isInverted(dataSet.axisDependency))
buffer.setBarWidth(chart.barData.barWidth)
buffer.feed(dataSet)
trans!!.pointValuesToPixel(buffer.buffer)
trans!!.pointValuesToPixel(buffer.buffer.toFloatArray())

// if multiple colors has been assigned to Bar Chart
if (dataSet.colors.size > 1) {
Expand Down
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<application
android:allowBackup="true"
android:hardwareAccelerated="true"
android:name="info.hannes.logcat.LoggingApplication"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
Expand Down
Loading