Skip to content

fix(grid): account for inverse axes when laying out the grid by outer bounds. close #21839 - #21842

Open
xh123637 wants to merge 1 commit into
apache:masterfrom
xh123637:fix/21839-inverse-outer-bounds
Open

xh123637 wants to merge 1 commit into
apache:masterfrom
xh123637:fix/21839-inverse-outer-bounds

Conversation

@xh123637

Copy link
Copy Markdown

Brief Information

This pull request is in the type of:

  • bug fixing
  • new feature
  • others

What does this PR do?

Flip the label proportion for inverse axes in layOutGridByOuterBounds, so the grid is no longer collapsed when an inverse axis has a tick near the axis edge.

Fixed issues

Details

Before: What was the problem?

layOutGridByOuterBounds in src/coord/cartesian/Grid.ts computed each label's proportion with axis.scale.normalize(...), which is a data-space proportion that ignores axis.inverse, while the proportion is used in pixel space measured from the min edge of the grid. On an inverted axis, a tick sitting ~0.1% from one edge was treated as ~0.1% from the other edge, so applyProportion divided a few px of overhang by ~0.001 and the grid shrank to its minimum (64px tall in a 600x400 container in the issue's reproduction, versus 229px without inverse).

After: How does it behave after the fixing?

The proportion is flipped (1 - proportion) when axis.inverse is set, before the existing y-axis flip, so the proportion matches the label's pixel position on both inverse x and inverse y axes. The grid now lays out (nearly) the same height with and without inverse.

A new unit test test/ut/spec/component/grid.test.ts reproduces the issue's option: before the fix the inverse grid height was 63.75px versus 245.5px without inverse; after the fix the test passes. test/ut/spec/api/converter.test.ts and test/ut/spec/api/containPixel.test.ts also pass (9 tests total across the three files). ESLint is clean on both changed files.

Document Info

One of the following should be checked.

  • 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

  • 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

New unit test: test/ut/spec/component/grid.test.ts (outerBoundsContain should not collapse the grid on an inverse axis).

Merging options

  • Please squash the commits into a single one when merging.

Other information

… bounds. close apache#21839

The label proportion in layOutGridByOuterBounds is measured in pixel space from the min edge of the grid, but scale.normalize returns a data-space proportion that ignores inverse. Flip the proportion for inverse axes so a tick near one edge is not treated as near the other edge, which divided a small overhang by a near-zero proportion and collapsed the grid.

Signed-off-by: xh123637 <3324733895@qq.com>
@echarts-bot

echarts-bot Bot commented Nov 14, 2026

Copy link
Copy Markdown

Thanks for your contribution!
The community will review it ASAP. In the meanwhile, please checkout the coding standard and Wiki about How to make a pull request.

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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant