-
Notifications
You must be signed in to change notification settings - Fork 19.8k
fix(grid): respect axisLabel.width when containLabel is true #21392
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(grid): respect axisLabel.width when containLabel is true #21392
Conversation
Previously, when grid.containLabel was set to true, the grid layout calculation used the actual text width instead of the configured axisLabel.width, causing incorrect layout when overflow was set to 'truncate'. This fix checks if axisLabel.width is configured and uses that value for grid layout calculation, ensuring consistent behavior. Fixes apache#16111
|
Thanks for your contribution! Please DO NOT commit the files in dist, i18n, and ssr/client/dist folders in a non-release pull request. These folders are for release use only. |
|
i tried to reproduce
When grid.containLabel was set to true and yAxis.axisLabel.width was configured with overflow: 'truncate', the grid layout calculation incorrectly used the actual text width instead of the configured width value. This caused the grid to reserve too much space for axis labels, resulting in incorrect chart layout. before the fix |
This caused the grid to reserve too much space for axis labels, resulting in incorrect chart layout. |
you need to change the width to 300px or more to see the extra blank space to reproduce just open the demo and copy paste the code option = { }, |
It still looks fine on my side. demo |
i seen the demo on my end there is still issue on my end. i don't know the reason why it different on your end. could you please go through the Pr changes. there you will understand the main logical issue in calculating the y-axis lable width. the logic is simple get the configured lable width and if it is available use it. go through this video on my end Uploading Recording 2025-12-15 094929.mp4… |
|
This issue can only be reproduced on Windows. |
thanks for the information. i tried it on windows earlier and this Pr will successfully fix this issue for any type of device and browser |
|
containLabel is deprecated since 6.0 |
thanks for clarification as the package is deprecated. I am closing this PR. |









Previously, when grid.containLabel was set to true, the grid layout calculation used the actual text width instead of the configured axisLabel.width, causing incorrect layout when overflow was set to 'truncate'.
This fix checks if axisLabel.width is configured and uses that value for grid layout calculation, ensuring consistent behavior.
Fixes #16111
Brief Information
This pull request is in the type of:
What does this PR do?
Fix grid layout calculation to respect
axisLabel.widthconfiguration whengrid.containLabelis enabled andoverflowis set to'truncate'.Fixed issues
Details
Before: What was the problem?
When
grid.containLabelwas set totrueandyAxis.axisLabel.widthwas configured withoverflow: 'truncate', the grid layout calculation incorrectly used the actual text width instead of the configured width value. This caused the grid to reserve too much space for axis labels, resulting in incorrect chart layout.Example of the bug:
In this case, the grid would reserve space based on the full text width (e.g., 500px) instead of the configured 300px, causing layout issues.
After: How does it behave after the fixing?
The grid layout calculation now correctly:
axisLabel.widthis configuredstringandnumbertypes for the width valueAfter the fix:
Implementation:
Modified the
fillLabelNameOverflowOnOneDimensionfunction insrc/coord/cartesian/Grid.tsto retrieve the configuredaxisLabel.widthand apply it to the label rect before margin calculation.Document Info
One of the following should be checked.
Misc
Security Checking
ZRender Changes
Related test cases or examples to use the new APIs
Manual test case added:
test/bug-16111.htmlThis test demonstrates the fix by showing a chart with:
grid.containLabel: trueyAxis.axisLabel.width: 300yAxis.axisLabel.overflow: 'truncate'Before the fix, the grid would overflow. After the fix, it correctly respects the 300px width.
Merging options
Other information
This is my first contribution to Apache ECharts. The fix is minimal and focused on the specific issue - it only affects grid layout calculation when both
containLabel: trueandaxisLabel.widthare configured together.The fix properly handles type conversion from
string | numbertonumberand only applies to y-axis labels (where width is the relevant dimension for horizontal layout).