From 10e3287d82279b66182727603c2c2cfbbd7fa11f Mon Sep 17 00:00:00 2001 From: johan12345 Date: Fri, 14 Jul 2023 18:48:01 +0200 Subject: [PATCH] fix division by zero error --- app/src/main/java/net/vonforst/evmap/ui/BarGraphView.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/net/vonforst/evmap/ui/BarGraphView.kt b/app/src/main/java/net/vonforst/evmap/ui/BarGraphView.kt index baedb6b4b..f10dcb24b 100644 --- a/app/src/main/java/net/vonforst/evmap/ui/BarGraphView.kt +++ b/app/src/main/java/net/vonforst/evmap/ui/BarGraphView.kt @@ -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