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

Fix tooltip positioning when charts are rendered inside an scaled div #2034

Merged
merged 2 commits into from
Jun 17, 2022

Conversation

andresgutgon
Copy link
Contributor

What?

In a normal situation mouse enter / mouse leave events capture the position ok. But when the chart is inside a scaled
element with a CSS transform like: transform: scale(2); tooltip are not positioned ok. Comparing original width box.width agains scaled width give us the scaling factor to calculate ok mouse position.

The issue

This PR fix this issue

The problem

The problem as explained in the issue that when the charts are inside an scaled div like this:

<div style={{ transform: 'scale(2)' }}>
  <MyFancyNivoChart />
</div>

The tooltip will be misplaced as you can see in the video in the issue I linked

The solution

I found the solution here

In a normal situation mouse enter / mouse leave events
capture the position ok. But when the chart is inside a scaled
element with a CSS transform like: `transform: scale(2);`
tooltip are not positioned ok.
Comparing original width `box.width` agains scaled width give us the
scaling factor to calculate ok mouse position.
@codesandbox-ci
Copy link

codesandbox-ci bot commented Jun 7, 2022

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit c6cbb09:

Sandbox Source
nivo Configuration

When a Nivo chart is inside an scaled div with something like
`transform: scale(2)` for example tooltips inside slides are not
positoned correctly. Taking into accoun `offsetWidth` fix the issue
@geclos
Copy link

geclos commented Jun 14, 2022

Having the same issue, could we move this forward?

Copy link
Owner

@plouc plouc left a comment

Choose a reason for hiding this comment

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

LGTM

@plouc plouc merged commit a1a529c into plouc:master Jun 17, 2022
@andresgutgon andresgutgon deleted the feature/zoom-level branch June 18, 2022 08:59
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.

3 participants