Skip to content

fix: correct tooltip coordinate mapping when chart is zoomed + fix pa…#649

Open
wvanooijen92 wants to merge 2 commits intoFormidableLabs:mainfrom
VanOoijenIT:fix/gesture-dead-zones-and-zoom-tooltip-coords
Open

fix: correct tooltip coordinate mapping when chart is zoomed + fix pa…#649
wvanooijen92 wants to merge 2 commits intoFormidableLabs:mainfrom
VanOoijenIT:fix/gesture-dead-zones-and-zoom-tooltip-coords

Conversation

@wvanooijen92
Copy link
Copy Markdown

Fix: gesture dead zones + wrong tooltip position when chart is zoomed

Fixes #515 (partially) and a related coordinate mapping bug.


Description

This PR fixes two separate but connected bugs that both surface when transformState (pan/zoom) is active alongside chartPressState.

Bug 1; Dead zones after panning or zooming

GestureHandler was applying the chart's transform matrix to its own React Native view style, so the gesture hit area physically moved along with the chart content. After panning far enough, the hit area drifted off-screen or into a region the user couldn't reach, making pan/zoom gestures silently fail. The fix is straightforward: the handler fills its entire parent container instead of following the transform. CartesianChart's handleTouch already reads the current pan offset out of the matrix and compensates, so tooltip accuracy is not affected by this change.

Bug 2; Tooltip snaps to the wrong data point when zoomed

handleTouch was computing the canvas-space touch position as:

touch.absoluteX - translateX

Subtracting the translate cancels the pan, but zoom scale is never factored out. At scaleX = 2, a finger in the centre of the screen produces a value roughly twice the correct canvas coordinate, which consistently maps to a data point near the far end of the range; the chart appears to "jump to max X" every time you lift and re-place your finger.

The fix uses view-relative touch.x / touch.y (which already accounts for where the container sits on screen) and divides by the current scale:

(touch.x - translateX) / scaleX

This works for all combinations of pan and zoom. When no transform is applied (scaleX = 1, translateX = 0) the formula reduces to touch.x, which is equivalent to the old behaviour.

The two fixes are coupled: switching to touch.x is only correct once GestureHandler is stationary (Bug 1 fix), because touch.x is relative to the handler view itself.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

Tested manually on android with a CartesianChart using chartPressState and transformState together:

  • Pan the chart ~50% to the right, then drag a single finger across it -> the tooltip now follows the finger the full width of the canvas with no dead zones.
  • Pinch to zoom 2× in, then tap/drag to show the tooltip -> it tracks the correct data point instead of jumping to the end of the series.
  • With no transform applied (default state) the tooltip behaviour is unchanged.

Checklist

  • I have included a changeset
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have run yarn run check:code and all checks pass
  • My changes generate no new warnings

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 19, 2026

🦋 Changeset detected

Latest commit: 8e5bf11

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
victory-native Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 19, 2026

@wvanooijen92 is attempting to deploy a commit to the formidable-labs Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes gesture “dead zones” after pan/zoom and corrects tooltip coordinate-to-data mapping when the chart is zoomed, by decoupling the gesture hit-area from the chart transform and properly inverting pan/zoom when converting touch coordinates.

Changes:

  • Make GestureHandler fill its parent container instead of following the chart’s transform matrix.
  • Fix CartesianChart touch-to-canvas mapping under zoom by using touch.x/touch.y and dividing by the current scale.
  • Update the pie/donut example to demonstrate PolarChart pan/zoom + add a patch changeset.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
lib/src/shared/GestureHandler.tsx Removes transform-following layout; pins gesture hit area to parent bounds.
lib/src/polar/PolarChart.tsx Updates GestureHandler usage to match the new API (no dimensions).
lib/src/cartesian/CartesianChart.tsx Adjusts touch coordinate mapping to account for zoom scale and view-relative coordinates.
example/app/pie-and-donut-charts.tsx Adds an example donut chart demonstrating pan/zoom with a reset button.
.changeset/fix-gesture-dead-zones-zoom-tooltip.md Adds a patch changeset describing the fixes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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.

Chart gestures break when xaxis contains datapoint outside the viewport

2 participants