Repository navigation
fix(axis): respect axisLabel.width in auto interval calculation. close #21194 - #21819
Open
Raman-Katiyar wants to merge 1 commit into
Open
Raman-Katiyar wants to merge 1 commit into
Raman-Katiyar wants to merge 1 commit into
Conversation
|
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. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Brief Information
This pull request is in the type of:
What does this PR do?
Fixes category axis labels being dropped by the auto interval calculation even when they are wrapped or truncated into a fixed
axisLabel.width(withoverflow: 'break'or'truncate'), so they would not overlap.Fixed issues
Details
Before: What was the problem?
With the option from #21194 (bar chart,
grid.width: 300withcontainLabel, andxAxis.axisLabel: {width: 50, overflow: 'break', hideOverlap: false}), only two of the three category labels are displayed: the middle label ("YY当日发电量") is missing, although every label is wrapped into the configured 50px width and the wrapped labels do not overlap (see the screenshot in #21194). The labels only all appear whenaxisLabel.interval: 0is set explicitly.The auto category interval in
calculateCategoryInterval(src/coord/axisTickLabelBuilder.ts) measures the unwrapped content bounding rect of each label and derives the interval from that width. It never takesaxisLabel.widthinto account, so for a label that is wrapped or truncated into a fixed width it overestimates the space the label occupies along the axis (here about 100px estimated vs. an about 86px category band), computes interval1, and drops every second label even though the rendered labels would fit.After: How does it behave after the fixing?
All three labels from #21194 are displayed, wrapped into the configured width, and the behaviour matches what
axisLabel.interval: 0already produced for this case.The interval calculation now respects the effective label width:
fetchAutoCategoryIntervalCalculationParamsexposes the numericaxisLabel.widthwhenoverflowis'break'or'truncate'(exactly the cases in which the width is applied to the label layout increateTextStyle), andcalculateCategoryIntervalcaps the per-label width estimate at that width. The cap is skipped for (nearly) vertical label rotation, where the occupied width is governed by the content height instead. Nothing changes when no effective width is set: labels that genuinely overlap at their natural width are still thinned out by the auto interval as before.Validation performed locally:
test/ut/spec/component/axis/axisLabel.test.ts(4 cases). Note: the Jest environment measures text with jest-canvas-mock at 1px per character, which cannot reproduce this layout bug, so the test installs a deterministic, browser-likemeasureTextthrough zrender'ssetPlatformAPIbefore creating the charts.["XX当日发电量", "ZZ当日发电量"]— the middle label is dropped.overflow: 'break'andoverflow: 'truncate'withwidth: 50show all labels, whilewidthwithout an effectiveoverflow— and no width at all — still thin out the overlapping labels via the auto interval.npx jest --config test/ut/jest.config.cjs): 27 suites, 198 tests, all pass.npm run checktype: pass.npm run build: pass (the regenerateddist/output was reverted and is not part of this PR).Document Info
One of the following should be checked.
Misc
Security Checking
ZRender Changes
Related test cases or examples to use the new APIs
New unit test file
test/ut/spec/component/axis/axisLabel.test.ts; the minimal reproduction option in #21194 can also be used to verify manually (all three category labels are shown, wrapped into two lines each).Merging options
Other information
This is a single commit on a fresh branch from
master, touching onlysrc/coord/axisTickLabelBuilder.tsand the new unit test file.Could a maintainer please approve the CI workflow run for this PR? Thank you!