Skip to content

Fix: scale tooltip coordinates during sync between different size charts#6387

Merged
ckifer merged 6 commits intorecharts:mainfrom
vmizg:fix/scale-tooltip-coordinates-during-sync
Oct 3, 2025
Merged

Fix: scale tooltip coordinates during sync between different size charts#6387
ckifer merged 6 commits intorecharts:mainfrom
vmizg:fix/scale-tooltip-coordinates-during-sync

Conversation

@vmizg
Copy link
Contributor

@vmizg vmizg commented Sep 26, 2025

Description

Sync event needed information about the viewbox of the source chart to be able to correctly sync tooltip position when the chart sizes differ.

There is a side effect from including the sourceViewBox that I noticed in unit tests and that's additional sync events being dispatched. Not sure if it's important, so please comment if there is an alternative approach you can think of.

Related Issue

Hopefully finally fixes: #6253

Motivation and Context

See linked issue.

How Has This Been Tested?

Tested by adding unit tests for testing tooltip position ratio, updated Storybook example and doing manual checks.

Screenshots (if appropriate):

image

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • I have added a storybook story or VR test, or extended an existing story or VR test to show my changes

@ckifer ckifer requested a review from PavelVanecek September 26, 2025 15:22
@ckifer
Copy link
Member

ckifer commented Sep 28, 2025

looks like this is failing typecheck

Copy link
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

This PR fixes tooltip coordinate synchronization between charts of different sizes by including the source chart's viewBox in sync events and scaling coordinates proportionally.

  • Adds sourceViewBox property to sync events to enable coordinate scaling between different-sized charts
  • Updates coordinate calculation logic to scale based on source and target viewBox dimensions instead of just bounding
  • Adds comprehensive test coverage for coordinate ratio validation across different chart types

Reviewed Changes

Copilot reviewed 9 out of 10 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/synchronisation/useChartSynchronisation.tsx Implements coordinate scaling logic and includes sourceViewBox in sync events
src/state/tooltipSlice.ts Adds sourceViewBox field to TooltipSyncState type and initial state
test/synchronisation/useChartSynchronisation.spec.tsx Updates test expectations to include sourceViewBox in sync events
test/synchronisation/eventCenter.spec.ts Updates test expectations to include sourceViewBox parameter
test/component/Tooltip/Tooltip.sync.spec.tsx Adds coordinate ratio testing and updates expected call counts
test/component/Tooltip/Tooltip.visibility.spec.tsx Updates test expectations for sourceViewBox field
test/chart/ScatterChart.spec.tsx Updates test expectations for sourceViewBox field
test/cartesian/Bar.spec.tsx Updates test expectations for sourceViewBox field
storybook/stories/Examples/AreaChart.stories.tsx Updates story to demonstrate synchronization with different chart sizes

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@codecov
Copy link

codecov bot commented Sep 29, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.43%. Comparing base (6531dcd) to head (44d895e).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6387   +/-   ##
=======================================
  Coverage   93.43%   93.43%           
=======================================
  Files         412      412           
  Lines       37876    37878    +2     
  Branches     4424     4426    +2     
=======================================
+ Hits        35391    35393    +2     
  Misses       2458     2458           
  Partials       27       27           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@vmizg vmizg force-pushed the fix/scale-tooltip-coordinates-during-sync branch from 013e902 to 8b54d78 Compare September 29, 2025 08:44
@vmizg
Copy link
Contributor Author

vmizg commented Oct 1, 2025

Checks should be passing now

@vmizg
Copy link
Contributor Author

vmizg commented Oct 2, 2025

Merged with main to resolve a conflict. Ready again 😄

@codecov
Copy link

codecov bot commented Oct 2, 2025

Bundle Report

Changes will decrease total bundle size by 480 bytes (-0.02%) ⬇️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
recharts/bundle-cjs 1.06MB 328 bytes (0.03%) ⬆️
recharts/bundle-es6* 916.37kB -619 bytes (-0.07%) ⬇️
recharts/bundle-umd* 489.8kB -189 bytes (-0.04%) ⬇️

ℹ️ *Bundle size includes cached data from a previous commit

Affected Assets, Files, and Routes:

view changes for bundle: recharts/bundle-umd

Assets Changed:

Asset Name Size Change Total Size Change (%)
Recharts.js -189 bytes 489.8kB -0.04%
view changes for bundle: recharts/bundle-cjs

Assets Changed:

Asset Name Size Change Total Size Change (%)
synchronisation/useChartSynchronisation.js 298 bytes 12.71kB 2.4%
state/tooltipSlice.js 30 bytes 7.85kB 0.38%
view changes for bundle: recharts/bundle-es6

Assets Changed:

Asset Name Size Change Total Size Change (%)
chart/Treemap.js -619 bytes 25.98kB -2.33%

@ckifer ckifer merged commit ff51cd8 into recharts:main Oct 3, 2025
22 checks passed
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.

Regression: tooltip position synced incorrectly for varying width charts

3 participants