fix division by zero error

This commit is contained in:
johan12345
2023-07-14 18:48:01 +02:00
parent a0f7a389c8
commit 10e3287d82

View File

@@ -151,8 +151,9 @@ class BarGraphView(context: Context, attrs: AttributeSet) : View(context, attrs)
legendPaint.textAlign = Paint.Align.CENTER
data.entries.forEachIndexed { i, (t, v) ->
val divisor = maxValue.toFloat().takeIf { it > 0f } ?: 1f
val height =
zeroHeight + (graphBounds.height() - zeroHeight) * v.toFloat() / maxValue.toFloat()
zeroHeight + (graphBounds.height() - zeroHeight) * v.toFloat() / divisor
val left = graphBounds.left + (barWidth + barMargin) * i
if (left + barWidth > graphBounds.right) return@forEachIndexed