Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new(tooltip, xychart): force update TooltipInPortal bounds #1045

Merged
merged 3 commits into from
Feb 4, 2021

Conversation

williaster
Copy link
Collaborator

🚀 Enhancements

This PR fixes an issue with XYChart's Tooltip described in #983, where Tooltip position does not correctly update when the chart container changes position due to limitations with react-use-measure (note that position does update upon page scroll or container resize). It's not obvious how to fix this with IntersectionObserver, etc. so I used a relatively simple approach:

  • expose react-use-measure's forceRefreshBounds function in the @visx/tooltip useTooltipInPortal hook, which will force update the Tooltip container bounds
  • invoke ^forceRefreshBounds whenever @visx/xychart's Tooltip goes from the unopen => open state

Closes #983.

Before
In this case, the chart animates in from the left so the Portal thinks its bounds are way left/off screen until I scroll, at which point react-use-measure updates the position and the tooltip is correctly positioned; see #983 for a different example with drag & drop

After
Tooltip has correct position from the outset

@kristw @hshoff
cc @valtism

@coveralls
Copy link

Pull Request Test Coverage Report for Build 535116481

  • 6 of 7 (85.71%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.08%) to 61.824%

Changes Missing Coverage Covered Lines Changed/Added Lines %
packages/visx-tooltip/src/hooks/useTooltipInPortal.tsx 0 1 0.0%
Totals Coverage Status
Change from base Build 516508911: 0.08%
Covered Lines: 1791
Relevant Lines: 2758

💛 - Coveralls

@valtism
Copy link
Contributor

valtism commented Feb 4, 2021

Amazing! Thank you

@williaster williaster merged commit 078ca18 into master Feb 4, 2021
@williaster williaster deleted the chris--force-update-tooltip-in-portal branch February 4, 2021 19:27
@VigneshTrantor
Copy link

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[xychart] Tooltip does not update when chart position changes
5 participants