fix: enable tooltip synchronization for PieChart#6989
fix: enable tooltip synchronization for PieChart#6989PavelVanecek merged 1 commit intorecharts:mainfrom
Conversation
WalkthroughAdds support for synchronized tooltips for pie charts by including the active graphical item id in tooltip sync events and adjusting payload combining to return all tooltip items when synchronization is active without a graphicalItemId filter. Changes
Sequence Diagram(s)sequenceDiagram
participant User as User (hover)
participant Source as SourceChart
participant Sync as SyncService
participant Target as TargetChart
User->>Source: hover sector
Source->>Source: determine activeGraphicalItemId
Source->>Sync: emit TOOLTIP_SYNC_EVENT { index, activeGraphicalItemId, syncInteraction.active }
Sync->>Target: forward sync event
Target->>Target: combineTooltipPayloadConfigurations(syncActive=true, filterByGraphicalItemId=null)
Target-->>Target: return all tooltipItemPayloads for synced index
Target->>User: display synced tooltip
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
No actionable comments were generated in the recent review. 🎉 Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@src/state/selectors/combiners/combineTooltipPayloadConfigurations.ts`:
- Around line 42-50: The current ordering in combineTooltipPayloadConfigurations
causes the defaultIndex branch (when defaultIndex is set and
filterByGraphicalItemId is null) to short-circuit before syncInteraction logic,
so a synced tooltip is ignored when a defaultIndex exists; either move the
syncInteraction check (tooltipState.syncInteraction.active) to run before the
defaultIndex check so synced events take precedence over defaultIndex, or if the
current ordering is intentional add a clarifying comment above the defaultIndex
branch mentioning why defaultIndex must override syncInteraction; update
references in the function to tooltipState, filterByGraphicalItemId,
defaultIndex and syncInteraction accordingly.
src/state/selectors/combiners/combineTooltipPayloadConfigurations.ts
Outdated
Show resolved
Hide resolved
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6989 +/- ##
=======================================
Coverage 90.10% 90.10%
=======================================
Files 522 522
Lines 38844 38853 +9
Branches 5347 5349 +2
=======================================
+ Hits 35000 35009 +9
Misses 3835 3835
Partials 9 9 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
- Add sync-aware fallback in combineTooltipPayloadConfigurations so receiving charts show tooltip items when syncInteraction is active - Pass activeGraphicalItemId through sync events instead of undefined - Uncomment and enable PieChart sync test case
3f78c9d to
cae6ac7
Compare
PavelVanecek
left a comment
There was a problem hiding this comment.
Looks easier than I thought it would be. Thanks!
Description
Fix tooltip synchronization for PieChart (and other
item-type charts like ScatterChart/FunnelChart).When two PieCharts share a
syncId, hovering on the first chart should display a tooltip on the second — but currently no tooltip appears on the receiving chart. This was a known issue explicitly marked asTODOin the test suite.Root Cause
Two bugs in the tooltip sync pipeline:
combineTooltipPayloadConfigurations filters payloads by
graphicalItemIdfromitemInteraction.hover, but on the receiving chart the interaction arrives viasyncInteraction— sofilterByGraphicalItemIdisundefinedand the filter returns an empty array → no tooltip.useTooltipChartSynchronisation always sets
graphicalItemId: undefinedin sync events, never forwarding the source chart's active item ID.Changes
syncInteractionis activeactiveGraphicalItemIdthrough sync events instead ofundefinedRelated Issue
Tooltip synchronization for Pie, Scatter, and Funnel charts was marked as a
TODOin Tooltip.sync.spec.tsx.Fixes #6863
Motivation and Context
PieChart tooltip sync was broken in Recharts v3. Users with synced PieCharts saw no tooltip on the receiving chart when hovering the first.
How Has This Been Tested?
PieChartTestCasein Tooltip.sync.spec.tsxTypes of changes
Checklist:
Summary by CodeRabbit
Bug Fixes
New Features