Skip to content

fix(charts): scrolling over a chart scrolls the page - #568

Merged
samcm merged 1 commit into
masterfrom
fix/chart-wheel-scroll
Nov 11, 2026
Merged

samcm merged 1 commit into
masterfrom
fix/chart-wheel-scroll

Conversation

@samcm

@samcm samcm commented Nov 11, 2026

Copy link
Copy Markdown
Member

Scrolling the mouse wheel or trackpad over a chart used to zoom it and stop the page from scrolling. Now the page scrolls.

  • Desktop: plain wheel over any chart scrolls the page. Ctrl+wheel (which trackpad pinch sends) still zooms, and the zoom slider and mouse drag-pan are unchanged. ECharts swallows the wheel over inside dataZoom, geo roam and echarts-gl views whatever their options say (zoomOnMouseWheel: false still calls preventDefault), so echarts-theme.ts, which every chart imports, stops plain wheel events before they reach any chart instance.
  • Touch: inside dataZoom no longer swallows one-finger swipes (theme preventDefaultMouseMove: false on devices without hover), and Map2D pinch-zooms only, so a swipe over the world map scrolls the page instead of dragging the map. Pinch zoom still works on both.

Checked on the dev server against the production backend with Playwright, on desktop at 1440px and on mobile emulation at 390px:

before (prod) after
wheel over consensus chart page 0px, zoom 0–100 → 12–87 page scrolls, zoom unchanged
wheel over /xatu/nodes map page 0px, zoom 1.2 → 1.6 page scrolls, zoom unchanged
ctrl+wheel zooms zooms
mobile swipe on chart 0px on 1 of 3 runs scrolls 4/4
mobile swipe on map 0px, map dragged scrolls, map still
mobile pinch chart 0–100 → 27–65, map 1.2 → 2.8

Plain mouse-wheel and trackpad scrolling over any chart no longer zooms it; the
page scrolls instead. Ctrl+wheel (and trackpad pinch) still zooms, as do the
zoom slider and touch pinch.

- echarts-theme: stop plain wheel events before they reach any ECharts instance.
  ECharts swallows the wheel over inside dataZoom, geo roam and echarts-gl views
  whatever their options say, so this is the only place that covers every chart.
- echarts-theme: on touch screens, inside dataZoom no longer swallows one-finger
  swipes, which intermittently blocked page scrolling on mobile.
- Map2D: touch screens pinch-zoom only; one-finger drag scrolls the page instead
  of panning the map. Mouse drag still pans.
- MultiLine: drop its explicit zoomOnMouseWheel override.

Amp-Thread-ID: https://ampcode.com/threads/T-01a1c9ca-25ef-77a1-95a5-61b71ea16537
Co-authored-by: Sam Calder-Mason <samcaldermason@gmail.com>
@samcm
samcm requested a review from Savid as a code owner November 11, 2026 09:22
@samcm
samcm merged commit 3b3a1f1 into master Nov 11, 2026
5 checks passed
@samcm
samcm deleted the fix/chart-wheel-scroll branch November 11, 2026 09:24

@redpandabot redpandabot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

Replaces wheel-to-zoom with page scrolling by stopping plain wheel events at a capture-phase window listener in echarts-theme.ts, and makes touch roaming less grabby (preventDefaultMouseMove: false on hover-less devices, Map2D roam: 'scale'). The desktop wheel path checks out against the ECharts 6 sources; the touch path looks only half-fixed, since disabling preventDefaultMouseMove stops the preventDefault but not the dataZoom panning.

Issues

  • 🟡 src/utils/echarts-theme.ts:11 — mobile swipe still pans the dataZoom window while the page scrolls — see the thread on that line

Reviewed @ 5f249c25
A red panda's tail is nearly as long as its body — balance bar by day, blanket by night.

registerTheme(ECHARTS_THEME, {
textStyle: { fontFamily: CHART_FONT_FAMILY },
// On touch screens a one-finger swipe over a zoomable chart must scroll the page, not get swallowed
dataZoom: { preventDefaultMouseMove: globalThis.matchMedia?.('(hover: hover)').matches ?? true },

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 mobile swipe still pans the dataZoom window while the page scrolls

In ECharts' RoamController _mousemoveHandler (echarts 6.0.0 dist echarts.js ~49230) preventDefaultMouseMove only guards stop(e.event); the pan trigger runs regardless, and touch is routed through the same mousedown/mousemove handlers with moveOnMouseMove: true. So on hover-less devices a one-finger swipe over a MultiLine chart (enableDataZoom) now scrolls the page and shifts the dataZoom range for as many touchmove events as the browser delivers, which the PR's mobile row (only 0px/scrolls measured) doesn't cover. I did not run a browser to see how much drift survives once the scroll gesture cancels the pointer stream.

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.

2 participants