HorizontalAxis: No way to display labels at first and last x-values with edge-aligned text #1475
Closed
Replies: 2 comments
-
|
@Gowsky I've raised the PR that implements this feature. Could you check please? |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
Thanks for the detailed write-up! Closing this as a duplicate, as the underlying needs are already tracked across a few existing ideas:
Together these cover both halves of what you describe (label placement at the extremes and avoiding plot-area shrinkage). Please follow / upvote those so interest stays consolidated. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Moved from #1472 (opened by @dmitry-stakhov).
Problem
There is currently no way to display x-axis labels at the first and last data points with proper edge alignment (left-aligned at start, right-aligned at end).
Two separate limitations combine to make this impossible:
1. First and last x-values are excluded from label positions
In
HorizontalAxisItemPlacers.kt, the privategetLabelValueshelper explicitly skips the range boundaries:Both
ItemPlacer.aligned()andItemPlacer.segmented()use this helper, so neither built-in placer can produce labels at the first or last x-value.A custom
ItemPlacerimplementation can return these values fromgetLabelValues(), but then hits the second issue:2. All labels are center-aligned on their x-position
In
HorizontalAxis.drawUnderLayers(), labels are always drawn centered oncanvasX:label?.draw( context = this, text = ..., x = canvasX, y = textY, verticalPosition = position.textVerticalPosition, maxWidth = maxWidth, ... )For labels at the plot boundaries, center-alignment causes half of the label to extend outside the plot area and get clipped. The
addExtremeLabelPaddingflag onItemPlacer.aligned()addresses this by addingunscalableStartPadding/unscalableEndPadding, but this shrinks the plot area rather than adjusting label alignment.Expected behavior
It should be possible to configure the horizontal axis to:
Use case
This is a common pattern in financial/asset charts where the x-axis shows a date range and only the start and end dates should be labeled, flush with the plot edges.
Workaround
We currently disable the bottom axis labels entirely (
label = null) and place ComposeTextcomponents manually below the chart, measuring the y-axis label width to align them with the plot area.Version
Vico 3.1.0 (Compose Multiplatform)
Beta Was this translation helpful? Give feedback.
All reactions