From b9addcecb368740706a5f9106747b133d47ef6e1 Mon Sep 17 00:00:00 2001 From: Patryk Goworowski Date: Wed, 19 Jun 2024 19:12:52 +0200 Subject: [PATCH] Change the constant `MAX_LABEL_WIDTH_KEY` in `VerticalAxis` to an instance-dependent key Co-authored-by: Patrick Michalik <120058021+patrickmichalik@users.noreply.github.com> --- .../vico/core/axis/vertical/VerticalAxis.kt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/vico/core/src/main/java/com/patrykandpatrick/vico/core/axis/vertical/VerticalAxis.kt b/vico/core/src/main/java/com/patrykandpatrick/vico/core/axis/vertical/VerticalAxis.kt index 2d51d9cf4..29813d026 100644 --- a/vico/core/src/main/java/com/patrykandpatrick/vico/core/axis/vertical/VerticalAxis.kt +++ b/vico/core/src/main/java/com/patrykandpatrick/vico/core/axis/vertical/VerticalAxis.kt @@ -45,7 +45,6 @@ import com.patrykandpatrick.vico.core.extension.translate import com.patrykandpatrick.vico.core.throwable.UnknownAxisPositionException private const val TITLE_ABS_ROTATION_DEGREES = 90f -private const val MAX_LABEL_WIDTH_KEY = "maxLabelWidthKey" /** * An implementation of [AxisRenderer] used for vertical axes. This class extends [Axis]. @@ -64,6 +63,8 @@ public class VerticalAxis( private val textHorizontalPosition: HorizontalPosition get() = if (areLabelsOutsideAtStartOrInsideAtEnd) HorizontalPosition.Start else HorizontalPosition.End + private val maxLabelWidthKey = System.identityHashCode(this) + /** * The maximum label count. */ @@ -221,7 +222,7 @@ public class VerticalAxis( horizontalPosition = textHorizontalPosition, verticalPosition = verticalLabelPosition.textPosition, rotationDegrees = labelRotationDegrees, - maxTextWidth = getExtraOr(MAX_LABEL_WIDTH_KEY) { chartBounds.width().half - tickLength }.toInt(), + maxTextWidth = getExtraOr(maxLabelWidthKey) { chartBounds.width().half - tickLength }.toInt(), ) } } @@ -280,7 +281,7 @@ public class VerticalAxis( val labelSpace = when (horizontalLabelPosition) { Outside -> { val maxLabelWidth = getMaxLabelWidth(height).ceil - putExtra(MAX_LABEL_WIDTH_KEY, maxLabelWidth) + putExtra(maxLabelWidthKey, maxLabelWidth) maxLabelWidth + tickLength }