Skip to content

fix: update the chart once per frame for a stream of wheel events - #1011

Open
kurkle wants to merge 2 commits into
chartjs:masterfrom
kurkle:fix/coalesce-wheel-events
Open

kurkle wants to merge 2 commits into
chartjs:masterfrom
kurkle:fix/coalesce-wheel-events

Conversation

@kurkle

@kurkle kurkle commented Nov 21, 2026

Copy link
Copy Markdown
Member

A touchpad sends wheel events faster than a large chart can update. Every event updated the chart synchronously, so the events queued up behind the updates and the chart fell further and further behind the gesture.

What changes

  • The first wheel event zooms right away, as before.
  • The events that follow before the next animation frame are added up and applied together in that frame. While events keep coming, each frame applies what arrived since the one before, so a steady stream gives one chart update per frame.
  • Zoom amounts are combined the way zooms in a row combine (a zoom by a leaves 2 - a of the range), so the chart ends up where zooming for each event would have taken it. The focal point is that of the latest event.
  • What is waiting is dropped when the wheel is disabled or the chart is destroyed.

onZoomStart and onZoomRejected are still called for every event, and onZoomComplete is debounced as before. onZoom is called once per zoom, so at most once per frame after the first event.

Visible to tests

Code that dispatches several wheel events in a row and expects each to have zoomed by the next line now sees only the first until a frame has passed. One spec and two image fixtures here did that; they give each event its own frame, and the reference images are unchanged.

On a category scale every zoom moves at least one category, so several small events in one frame now move one category where they used to move one each.

Fixes #1006

A touchpad sends wheel events faster than a large chart can update.
Every event updated the chart synchronously, so the events queued up
behind the updates and the chart fell further behind the gesture.

The first event still zooms right away. The events that follow before
the next animation frame are added up and applied together in that
frame, and the same goes for each frame after it while events keep
coming. The result is where zooming for each event would have ended.

Specs and image fixtures that look at the chart after each of several
wheel events now give each event its own frame.
Without a global requestAnimationFrame, as in a DOM emulation that does
not pretend to be visual, the first wheel event threw after zooming.
Each event now zooms at once there, as it did before events were
applied per frame.

The specs also cover turning the wheel off while events are waiting,
and the documentation says which position a combined zoom uses.
@kurkle
kurkle marked this pull request as ready for review November 21, 2026 20:42
@kurkle
kurkle requested a review from etimberg November 21, 2026 21:26

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Coalesce wheel events into one chart update per animation frame

2 participants