Skip to content

Commit

Permalink
Change the constant MAX_LABEL_WIDTH_KEY in VerticalAxis to an ins…
Browse files Browse the repository at this point in the history
…tance-dependent key

Co-authored-by: Patrick Michalik <[email protected]>
  • Loading branch information
Gowsky and patrickmichalik committed Jun 19, 2024
1 parent 2321b71 commit b9addce
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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].
Expand All @@ -64,6 +63,8 @@ public class VerticalAxis<Position : AxisPosition.Vertical>(
private val textHorizontalPosition: HorizontalPosition
get() = if (areLabelsOutsideAtStartOrInsideAtEnd) HorizontalPosition.Start else HorizontalPosition.End

private val maxLabelWidthKey = System.identityHashCode(this)

/**
* The maximum label count.
*/
Expand Down Expand Up @@ -221,7 +222,7 @@ public class VerticalAxis<Position : AxisPosition.Vertical>(
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(),
)
}
}
Expand Down Expand Up @@ -280,7 +281,7 @@ public class VerticalAxis<Position : AxisPosition.Vertical>(
val labelSpace = when (horizontalLabelPosition) {
Outside -> {
val maxLabelWidth = getMaxLabelWidth(height).ceil
putExtra(MAX_LABEL_WIDTH_KEY, maxLabelWidth)
putExtra(maxLabelWidthKey, maxLabelWidth)
maxLabelWidth + tickLength
}

Expand Down

0 comments on commit b9addce

Please sign in to comment.