SakshamSinghal20 opened a new pull request, #21503:
URL: https://github.com/apache/echarts/pull/21503
## Brief Information
This pull request is in the type of:
- [x] bug fixing
- [ ] new feature
- [ ] others
### What does this PR do?
Fixes label positioning bugs in heatmap series when using
`labelLayout.moveOverlap`, ensuring labels only shift when overlapping and stay
within coordinate system bounds.
### Fixed issues
- #21461: When using the moveOverLap attribute for label overlap, the
position should remain within the coordinate system, and in some cases, offsets
are applied unnecessarily
## Details
### Before: What was the problem?
When using `series.labelLayout: { moveOverlap: 'shiftX' | 'shiftY' }` on
Heatmap series with value or time axes, two issues occurred:
1. **Unnecessary shifts**: Labels were shifted even when they had no overlap
2. **Out-of-bounds positioning**: Labels moved outside the coordinate system
instead of staying within axis bounds
**Root causes:**
- `LabelManager.layout()` used canvas dimensions instead of coordinate
system bounds
- `shiftLayoutOnXY()` always eliminated gaps, shifting labels even without
overlaps
### After: How does it behave after the fixing?
**Fixed behavior:**
1. Labels only shift when they actually overlap
2. Labels stay within the coordinate system's plotting area
3. Non-overlapping labels remain in original positions
**Implementation:**
- Modified `LabelManager.ts` to detect Cartesian systems and use plotting
area bounds via `getArea()`
- Modified `labelLayoutHelper.ts` to add overlap detection; if no overlaps,
only clamp to bounds
- Falls back to canvas dimensions for non-Cartesian systems (backward
compatible)
**Changes:**
- `src/label/LabelManager.ts`: Added `getCoordSysBounds()` helper (28 lines)
- `src/label/labelLayoutHelper.ts`: Added overlap detection (35 lines)
- `test/heatmap-label-moveOverlap.html`: New test file
## Document Info
- [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 Checking
- [x] This PR uses security-sensitive Web APIs.
### ZRender Changes
- [ ] This PR depends on ZRender changes (ecomfe/zrender#xxx).
### Related test cases or examples to use the new APIs
- `test/heatmap-label-moveOverlap.html`
- `test/issue-21461-fix-demo.html`
### Merging options
- [x] Please squash the commits into a single one when merging.
### Other information
Fully backward compatible, minimal changes (63 lines), tested with
value/time/category axes.
--
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]