You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by "Justin-ZS (via GitHub)" <gi...@apache.org> on 2025/08/22 06:32:30 UTC
[PR] fix(bar): wrong data label position when bar width/height is 0 [echarts]
Justin-ZS opened a new pull request, #21218:
URL: https://github.com/apache/echarts/pull/21218
<!-- Please fill in the following information to help us review your PR more efficiently. -->
## Brief Information
This pull request is in the type of:
- [x] bug fixing
- [ ] new feature
- [ ] others
### What does this PR do?
<!-- USE ONE SENTENCE TO DESCRIBE WHAT THIS PR DOES. -->
Fix incorrect data label position when bar width/height is 0.
<img width="1325" height="572" alt="截屏2025-08-22 14 15 30" src="https://github.com/user-attachments/assets/336d0a37-c0b4-4572-85d6-d9ee75a37b9d" />
### Fixed issues
<!--
- #xxxx: ...
-->
- #21144
## Details
### Before: What was the problem?
<!-- DESCRIBE THE BUG OR REQUIREMENT HERE. -->
When a bar has zero width or height (data value is 0), the label position calculation for `label.position: 'outside'` was incorrect, especially when the axis is inverted.
The original logic only checked `layout.height >= 0` or `layout.width >= 0` without considering axis inversion, causing labels to appear in wrong positions.
<!-- ADD SCREENSHOT HERE IF APPLICABLE. -->
### After: How does it behave after the fixing?
<!-- THE RESULT AFTER FIXING AND A SIMPLE EXPLANATION ABOUT HOW IT IS FIXED. -->
Added two helper functions `getLabelPositionForHorizontal` and `getLabelPositionForVertical` to properly handle label positioning when bar dimensions are zero.
The functions check the value axis's `inverse` property to determine the correct label position, ensuring labels appear correctly regardless of axis configuration.
<!-- ADD SCREENSHOT HERE IF APPLICABLE. -->
## 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
### ZRender Changes
- [ ] This PR depends on ZRender changes (ecomfe/zrender#xxx).
### Related test cases or examples to use the new APIs
N.A.
## Others
### Merging options
- [ ] Please squash the commits into a single one when merging.
### Other information
Modified `src/chart/bar/BarView.ts` to replace simple ternary operators with smarter function calls that consider axis inversion when determining label positions for zero-dimension bars.
--
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: commits-unsubscribe@echarts.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org
Re: [PR] fix(bar): wrong data label position when bar width/height is 0 [echarts]
Posted by "Justin-ZS (via GitHub)" <gi...@apache.org>.
Justin-ZS commented on PR #21218:
URL: https://github.com/apache/echarts/pull/21218#issuecomment-3213377781
> Does this also depends on `label.position`?
Yes. the value is assigned to `labelPositionOutside` and is only used for `position: 'outside'`
--
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: commits-unsubscribe@echarts.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org
Re: [PR] fix(bar): wrong data label position when bar width/height is 0 [echarts]
Posted by "Ovilia (via GitHub)" <gi...@apache.org>.
Ovilia merged PR #21218:
URL: https://github.com/apache/echarts/pull/21218
--
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: commits-unsubscribe@echarts.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org
Re: [PR] fix(bar): wrong data label position when bar width/height is 0 [echarts]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #21218:
URL: https://github.com/apache/echarts/pull/21218#issuecomment-3213409890
The changes brought by this PR can be previewed at: https://echarts.apache.org/examples/editor?version=PR-21218@cbf5c62
<!-- ECHARTS_PR_PREVIEW -->
--
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: commits-unsubscribe@echarts.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org
Re: [PR] fix(bar): wrong data label position when bar width/height is 0 [echarts]
Posted by "Ovilia (via GitHub)" <gi...@apache.org>.
Ovilia commented on PR #21218:
URL: https://github.com/apache/echarts/pull/21218#issuecomment-3218603625
Thanks for your contribution!
--
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: commits-unsubscribe@echarts.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org
Re: [PR] fix(bar): wrong data label position when bar width/height is 0 [echarts]
Posted by "echarts-bot[bot] (via GitHub)" <gi...@apache.org>.
echarts-bot[bot] commented on PR #21218:
URL: https://github.com/apache/echarts/pull/21218#issuecomment-3218603515
Congratulations! Your PR has been merged. Thanks for your contribution! 👍
--
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: commits-unsubscribe@echarts.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org
Re: [PR] fix(bar): wrong data label position when bar width/height is 0 [echarts]
Posted by "echarts-bot[bot] (via GitHub)" <gi...@apache.org>.
echarts-bot[bot] commented on PR #21218:
URL: https://github.com/apache/echarts/pull/21218#issuecomment-3213209241
Thanks for your contribution!
The community will review it ASAP. In the meanwhile, please checkout [the coding standard](https://echarts.apache.org/en/coding-standard.html) and Wiki about [How to make a pull request](https://github.com/apache/echarts/wiki/How-to-make-a-pull-request).
--
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: commits-unsubscribe@echarts.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org