Raman-Katiyar opened a new pull request, #21822:
URL: https://github.com/apache/echarts/pull/21822
## Brief Information
This pull request is in the type of:
- [x] bug fixing
- [ ] new feature
- [ ] others
### What does this PR do?
Fixes `grid.containLabel` reserving the full axis label width/height even
when `axisLabel.align` / `axisLabel.verticalAlign` makes the labels extend
inwards from their anchor point, which left unwanted dead space next to the
axis.
### Fixed issues
- #21140: [Bug] Y-axis labels are aligned to the left and coincide with
columns. They need to be moved out by margin, but the reserved position of the
label is still reserved on the left side (I don't need this reserved position)
## Details
### Before
The legacy containLabel layout (`legacyLayOutGridByContained` in
`src/coord/cartesian/legacyContainLabel.ts`) always reserves the full label
size plus margin, regardless of label alignment. With `yAxis.axisLabel: {align:
'left', margin: 100}` and `grid.containLabel: true`, the grid starts 120.16px
from the chart edge instead of 100px — 20.16px of dead space, exactly the
widest label's width (for `align: 'center'` the dead space is half the label
width).
### After
The reserved size now accounts for alignment via a new
`estimateOuterLabelSize` helper: only the part of the label that extends
outwards from its anchor point is reserved (full size for the default/outward
alignment, half for center/middle, zero for inward alignment). With the fix,
the grid starts exactly at 100px in the issue's configuration and the labels
begin at the chart edge. Nothing changes for the default/outward alignment, and
the full size is still reserved when `axisLabel.rotate` is set. The newer
outer-bounds layout path already accounts for real label geometry and is
unaffected.
Validation results:
- New 11-case regression test in
`test/ut/spec/component/axis/containLabel.test.ts`: 5 cases fail without the
fix, all 11 pass with it.
- Surrounding suites (component/coord/api): 10 suites / 51 tests pass.
- Full unit suite: 27 suites / 205 tests pass.
- `npm run checktype`, ESLint on the changed files, and `npm run build` all
pass. Regenerated `dist/` output is not included in this PR.
## Document Info
One of the following should be checked.
- [x] This PR doesn't relate to document changes
- [ ] The document should be updated later
- [ ] The document changes have been made in apache/echarts-doc#xxx
## Misc
### Security
- [ ] This PR ensures the security (I have read the security policy)
### ZRender Changes
- [ ] This PR depends on ZRender changes (ecomfe/zrender#xxx).
### Related test cases or examples to use the new APIs
New regression test: `test/ut/spec/component/axis/containLabel.test.ts`,
covering the #21140 reproduction plus guard cases for the default, center, and
inward alignments.
### Others
- [x] Please squash the commits into one when merging
This PR is a single commit.
Could a maintainer please approve the CI workflow run for this PR? Thank you!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]