-
Notifications
You must be signed in to change notification settings - Fork 19.8k
Avoid axisLabel and axisName overflowing the viewport by default. And fix the "contain axis name" breaking. #21059
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
Conversation
… deprecated `grid.containLabel`. Support `grid.layoutContain.axisName` and `grid.layoutContain.axisLabel`.
…. (2) Fix label related TS type.
…upport some complex input to build complex test cases. (3) Enhance mktest.
…in axisName (3) refactor: use the same logic to measure axisLabel/axisName contain and view build. (3) support auto avoid axisLabel and axisName overflow even containLabel is not specified, while also considered axis line alignment between different grids. Introduce `grid.outerBounds` and `grid.outerBoundsContain`.
… pure object. (2) fix name overlap cache bug. (3) make outerBounds merge as box layout merge.
# Conflicts: # src/component/axis/CartesianAxisView.ts # src/component/axis/axisBreakHelper.ts # src/coord/cartesian/Grid.ts # src/coord/cartesian/GridModel.ts # src/echarts.all.ts # src/export/features.ts # src/label/labelStyle.ts # src/util/graphic.ts # src/util/types.ts # test/build/mktest-tpl.html # test/lib/testHelper.js # test/tmp-base.html
….getBoundingRect wrongly include (0, 0, 0, 0) issue.
Thanks for your contribution! The pull request is marked to be |
Document changes are required in this PR. Please also make a PR to apache/echarts-doc for document changes and update the issue id in the PR description. When the doc PR is merged, the maintainers will remove the |
The changes brought by this PR can be previewed at: https://echarts.apache.org/examples/editor?version=PR-21059@21d51a5 |
Congratulations! Your PR has been merged. Thanks for your contribution! 👍 |
To reviewers: If this PR is going to be described in the changelog in the future release, please make sure this PR has one of the following labels: This message is shown because the PR description doesn't contain the document related template. |
Brief Information
This pull request is in the type of:
Big thanks to @robin-gerling and @konrad-amtenbrink for their excellent work in #19534 and #16825!
This PR is a follow-up of them. Considering some backward compatibility, universally adoption and code maintainability, this PR make some changes in echarts option and implementation.
Brief:
grid
component).grid
component).Some related issues: #15654 #9265 #9286 #14996 #15562
Document and Usage
(The full document will be published on echarts website when v6.0.0 is released.)
Basic Usage
In most cases users do not need to set specific option, since this feature have been make as the default. But detailed tuning is require, check the new introduced options in:
The overflow control: grid.outerBounds, grid.outerBoundsMode, grid.outerBoundsClampWidth, grid.outerBoundsClampHeight.
The overlap between axis names and axis labels: xAxis.nameMoveOverlap, yAxis.nameMoveOverlap
Regarding the existing option grid.containLabel:
grid.containLabel:true
is not necessary any more.grid.containLabel:true
is deprecated but still supported, and the behavior is the same as the new introduced optiongrid.outBoundsMode: 'same'
.grid.containLabel:true
is not precise enough, as mentioned in containLabel not working as expected #15562. The new implementation (grid.outBoundsMode: 'same'
) is more precise to avoid some edge labels partially overflowing the viewport.grid.containLabel:true
, see "Breaking Change and Restore".Breaking Change and Restore
This feature introduces a breaking change against the previous echarts (v5.6.0-).
The position of Cartesian axes might shift slightly if the axis names or labels previously overflowed the canvas or overlapped, as anti-overflow and anti-axisLabel-axisName-overlap mechanism are enabled by default. In most cases that changes will be indiscernible to the naked eye. But if any unreasonable change occurs, you can use option
grid.outerBoundsMode: 'none'
to disable the anti-overflow mechanism, and/or use optionxAxis/yAxis.axisLabel.nameMoveOverlap: false
to disable the anti-axisLabel-axisName-overlap mechanism.The old implementation of
grid.containLabel:true
has been moved to featureLegacyGridContainLabel
.LegacyGridContainLabel
is imported byecharts/dist/echarts.all.js
, but not imported byecharts/dist/echarts.common.js
andecharts/dist/echarts.simple.js
.If no
LegacyGridContainLabel
imported,grid.containLabel:true
still works and uses the new implementation, which is more precise than the old one and is recommended.Details
Before: What was the problem?
Axis labels and axis names may overflow the viewport:
grid.left/right/top/bottom/width/height
determines a rect for cartesians (say,cartesianRect
),grid.containLabel: false
(default)xAxis
/yAxis
line is placed on the edges ofcartesianRect
, the long axis labels and axis name may overflow the canvas (viewport), since the variation inseres.data
makes it difficult for users to allocate proper spacing between axis line and viewport edges.grid.containLabel: true
can mitigate this issue.grid.containLabel: true
,cartesianRect
while touching the edges.grid.containLabel: true
the default - doing so would introduce a significant breaking change, since many users have configured layout params based ongrid.containLabel: false
.Axis name overlaps with axis labels
Especially when
xAxis/yAxis.nameLocation: 'center'
. This issues are not addressed previously, and the variation in axis label length (due to the variation inseries.data
) makes it difficult for users to allocate proper space between the axis name and axis line (byxAxis/yAxis.nameGap
).#19534 have made great implementation that makes
containLabel
also consider axisName. However, that would introduce significant breaking change, and it also introduced another way to compute the layout of axis names and axis labels. Having two mechanisms coexist could reduce the maintainability of the codebase. This is what this PR needed to resolve. Moreover, this PR aims to resolves all of the issues mentioned above, and makes overflow/overlap feature the default without bringing big breaking. And more edge cases are covered in this PR.After: How does it behave after the fixing?
Avoid axis names overlapping with axis labels in Cartesian (

grid
component)Before (if
grid.containLabel: false
):Before (if

grid.containLabel: true
):After:

Avoid axis labels and axis names overflowing the canvas (viewport) in Cartesian (

grid
component)Before:
After:

The mechanism behind this:
grid.left/right/top/bottom/width/height
determines a rect for cartesians (say,cartesianRect
), andxAxis
/yAxis
line is firstly placed on the edges ofcartesianRect
.grid.outerBounds.left/right/top/bottom/width/height
determines a rect for the outermost bounds (say,outerBoundsRect
). If axis labels or names overflow the bounds, shrink the Cartesian to avoid overflowing.outerBoundsRect
is the canvas (viewport) by default, and no need to be modified in most cases.The example below uses colored indicator rectangles to visualize the

cartesianRect
andouterBoundsRect
.The effect of modifying

grid.left/right/top/bottom/width/height
:The effect of modifying

grid.outerBounds.left/right/top/bottom/width/height
:Test
test/axis-layout-0.html