From a2d7be6b57f5023393f0aa2d9a45c36f154a9594 Mon Sep 17 00:00:00 2001 From: Patrick Michalik <120058021+patrickmichalik@users.noreply.github.com> Date: Tue, 5 Mar 2024 18:12:14 +0100 Subject: [PATCH] Fix `Zoom.Content` misbehaving when `HorizontalDimensions#getScalableContentWidth` returns zero --- .../main/java/com/patrykandpatrick/vico/core/zoom/Zoom.kt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/vico/core/src/main/java/com/patrykandpatrick/vico/core/zoom/Zoom.kt b/vico/core/src/main/java/com/patrykandpatrick/vico/core/zoom/Zoom.kt index e10ba6aca..1efeee592 100644 --- a/vico/core/src/main/java/com/patrykandpatrick/vico/core/zoom/Zoom.kt +++ b/vico/core/src/main/java/com/patrykandpatrick/vico/core/zoom/Zoom.kt @@ -38,8 +38,11 @@ public fun interface Zoom { public val Content: Zoom = Zoom { context, horizontalDimensions, bounds -> val scalableContentWidth = horizontalDimensions.getScalableContentWidth(context) - val reducedChartWidth = bounds.width() - horizontalDimensions.unscalablePadding - reducedChartWidth / scalableContentWidth + if (scalableContentWidth == 0f) { + 1f + } else { + (bounds.width() - horizontalDimensions.unscalablePadding) / scalableContentWidth + } } /** Uses a zoom factor of [value]. */