Skip to content

Commit

Permalink
fix division by zero error
Browse files Browse the repository at this point in the history
  • Loading branch information
johan12345 committed Jul 14, 2023
1 parent a0f7a38 commit 10e3287
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/src/main/java/net/vonforst/evmap/ui/BarGraphView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 10e3287

Please sign in to comment.