Skip to content

fix(dataZoom): allow wheel zoom-out to expand a collapsed inside dataZoom range#21641

Open
JamesGoslings wants to merge 1 commit into
apache:masterfrom
JamesGoslings:fix/21541-datazoom-wheel-zoom-out-category
Open

fix(dataZoom): allow wheel zoom-out to expand a collapsed inside dataZoom range#21641
JamesGoslings wants to merge 1 commit into
apache:masterfrom
JamesGoslings:fix/21541-datazoom-wheel-zoom-out-category

Conversation

@JamesGoslings
Copy link
Copy Markdown

Brief Information

This pull request is in the type of:

  • bug fixing
  • new feature
  • others

What does this PR do?

Make dataZoom inside wheel zoom-out work after the toolbox has collapsed the range to a single category, so users can zoom back out and see all categories again.

Fixed issues

Details

Before: What was the problem?

When the toolbox dataZoom feature brushes a single category on a category axis, it dispatches startValue === endValue and AxisProxy collapses the percent window to a zero-width range (for example [33.33, 33.33] for category index 1 of 4).

InsideZoomView.zoom expands the window multiplicatively around the wheel anchor:

range[i] = (range[i] - percentPoint) * scale + percentPoint

For a collapsed range every term is zero, so wheel-out leaves the range unchanged and the user is stuck looking at the single category they brushed. The bug was confirmed by @helgasoft and tracked in #20392.

Reproducer (from the issue):

  1. Toolbox dataZoom → brush exactly one category.
  2. Scroll the mouse wheel up to zoom out.
  3. The window stays collapsed; wheel does nothing.

After: How does it behave after the fixing?

Detect the collapsed-range case in the zoom handler. When the user is wheel-zooming out (scale > 1), seed the range with a small percent (currently 5%) centered on the wheel anchor before applying the multiplicative expansion:

const SEED_HALF_PERCENT = 2.5;
if (range[1] - range[0] < 1e-6 && scale > 1) {
    range[0] = percentPoint - SEED_HALF_PERCENT;
    range[1] = percentPoint + SEED_HALF_PERCENT;
}

range[0] = (range[0] - percentPoint) * scale + percentPoint;
range[1] = (range[1] - percentPoint) * scale + percentPoint;

After the seed, subsequent wheel ticks scale multiplicatively as before, so the user reaches the full range in roughly 30 ticks (default factor 1.1). The seed is anchored on the wheel position, then the existing sliderMove clamp ensures the range stays within [0, 100] even when the wheel anchor sits near the edge.

Wheel-in on a collapsed range is intentionally left as a no-op — it cannot collapse the range further, and the existing math already handles that correctly.

Tests

test/ut/spec/component/dataZoom/insideZoomViewWheel.test.ts adds four unit tests calling the exported getRangeHandlers.zoom directly with mocked context:

  • collapsed-range wheel-out → range expands and stays centered on the wheel anchor.
  • collapsed-range wheel-in → handler returns undefined (no change).
  • non-degenerate range wheel-out → existing multiplicative behavior preserved (≈1.1× factor).
  • collapsed range near 100% → seed gets clamped to [0, 100] without crashing.

test/dataZoom-wheel-zoom-out-collapsed.html is a visual reproducer matching the issue's steps so reviewers can brush a single category in the toolbox and verify the wheel now expands the window.

InsideZoomView.ts exports getRangeHandlers so the unit tests can drive the handler in isolation; the type alias DataZoomGetRangeHandlers was already exported, so this is purely a value export.

Full unit suite: 26 suites, 196 tests, all green.

Document Info

  • 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

  • test/ut/spec/component/dataZoom/insideZoomViewWheel.test.ts — unit tests
  • test/dataZoom-wheel-zoom-out-collapsed.html — visual reproducer

Merging options

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

Other information

The seed half-width (2.5% per side, 5% width on first tick) is empirical: small enough not to feel jumpy on the first tick, large enough that the user feels progress and reaches the full range in a reasonable number of ticks. Happy to tune this if reviewers prefer a different value.

…Zoom range. close apache#21541

When the toolbox dataZoom feature brushes a single category on a
category axis, it dispatches startValue === endValue and AxisProxy
collapses the percent window to a zero-width range (e.g. [33.33,
33.33] for category index 1 of 4).

InsideZoomView.zoom expands the window multiplicatively around the
wheel anchor:

    range[i] = (range[i] - percentPoint) * scale + percentPoint

For a collapsed range every term is zero, so wheel-out leaves the
range unchanged and the user is stuck looking at the single
category they brushed.

Detect the collapsed-range case in the zoom handler. When the user
is wheel-zooming out (scale > 1), seed the range with a small
percent (currently 5%) centered on the wheel anchor before applying
the multiplicative expansion. Wheel-in is intentionally left as a
no-op on a collapsed range — it cannot collapse the range further.

Adds unit coverage for the collapsed-range expand, the collapsed
no-op on wheel-in, the unchanged behavior on a non-degenerate
range, and the [0, 100] clamp at the edge. Adds a visual reproducer
matching the steps in the issue.
@echarts-bot
Copy link
Copy Markdown

echarts-bot Bot commented Jun 2, 2026

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.

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.

[Bug] Cannot zoom out to see all categories by scrolling mouse wheel in chart with category axis

1 participant