Skip to content

fix: compute axis drag zoom from local coordinates - #847

Open
NemeZZiZZ wants to merge 1 commit into
klinecharts:mainfrom
NemeZZiZZ:fix/axis-drag-zoom-local-coords
Open

fix: compute axis drag zoom from local coordinates#847
NemeZZiZZ wants to merge 1 commit into
klinecharts:mainfrom
NemeZZiZZ:fix/axis-drag-zoom-local-coords

Conversation

@NemeZZiZZ

Copy link
Copy Markdown
Contributor

Problem

Axis drag-zoom computes its scale from absolute page coordinates while every other gesture in Event.ts uses widget-local event.x/event.y:

this._xAxisStartScaleDistance = event.pageX          // :746
const scale = this._xAxisStartScaleDistance / event.pageX   // :755
...
this._yAxisStartScaleDistance = event.pageY          // :776
const scaleFactor = event.pageY / this._yAxisStartScaleDistance   // :788

Consequences:

  1. Sensitivity depends on where the chart sits on the page. A 50px drag starting at pageX=500 yields scale 500/550 ≈ 0.91; the same drag starting at pageX=50 yields 0.5 — ten times the zoom for the same physical movement.
  2. Page scroll mid-drag shifts pageX/pageY and the scale jumps.
  3. 0 doubles as the "not set" sentinel (!== 0), so a drag starting at page coordinate 0 — a full-width chart flush against the left/top edge of the page — silently disables axis zoom entirely.

Fix

  • Use widget-local event.x / event.y (already what _xAxisStartScaleCoordinate stores on the previous line).
  • Replace the 0 sentinel with null (Nullable<number>), matching _xAxisStartScaleCoordinate.
  • Guard the two newly reachable degenerate cases that page coordinates made practically impossible: a drag starting on the exact first pixel of the widget (start === 0, ratio meaningless) and the pointer reaching the widget's first pixel mid-drag (event.x/y === 0 → division by zero / zero scale factor). Both now skip that event instead of producing Infinity or collapsing the range to a point.

The hyperbolic response curve (start/current) is intentionally unchanged — this PR removes the external position/scroll dependency, it does not redesign the gesture feel.

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.

1 participant