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

Tooltip value display incorrent #6926

Open
hatienloi opened this issue Mar 15, 2024 · 7 comments
Open

Tooltip value display incorrent #6926

hatienloi opened this issue Mar 15, 2024 · 7 comments

Comments

@hatienloi
Copy link

hatienloi commented Mar 15, 2024

Step

  • Add new chart with x: [1,2,3,4,5], y: [2.02825,1.63728,171.96,4.8485,4.73463],and hovertemplate: '<i>Price</i>: $%{y:.1f}',
  • Check display when hover to point.

Codesandbox
https://codesandbox.io/p/sandbox/plotlyjs-issue-9zd9rk?file=%2Findex.html

Screenshots

  • With 171..95 => Incorrect
    image

  • With 171.96 => Correct
    image

@alexcjohnson
Copy link
Collaborator

Interesting, thanks @hatienloi!

I suspect this is due to the fact that with JS floating point, 171.95 actually IS closer to 171.9 than to 172.0:

> 171.95-171
0.9499999999999886

And if so it's going to be tough to fix without breaking numbers that are just a little bit lower, like 171.949999, so really SHOULD round down.

If anyone is interested in taking a crack at this, it will be crucial to add good unit tests

@hatienloi
Copy link
Author

hatienloi commented Mar 19, 2024

Interesting, thanks @hatienloi!

I suspect this is due to the fact that with JS floating point, 171.95 actually IS closer to 171.9 than to 172.0:

> 171.95-171
0.9499999999999886

And if so it's going to be tough to fix without breaking numbers that are just a little bit lower, like 171.949999, so really SHOULD round down.

If anyone is interested in taking a crack at this, it will be crucial to add good unit tests

@alexcjohnson Yes, so weird. Could we have a fix for it

@archmoj
Copy link
Contributor

archmoj commented Mar 19, 2024

Thanks for the report.
Please provide a link to your codepen in the issue description.

@hatienloi
Copy link
Author

@archmoj Updated the description with codesandbox link. Thanks!

@archmoj
Copy link
Contributor

archmoj commented Mar 19, 2024

@archmoj Updated the description with codesandbox link. Thanks!

Please note the "latest" bundle you are using is last v1.
In this codepen I use latest v2 plotly.js and I get 172.0 in the hover. Do you get the same number?

@hatienloi
Copy link
Author

@archmoj Updated the description with codesandbox link. Thanks!

Please note the "latest" bundle you are using is last v1. In this codepen I use latest v2 plotly.js and I get 172.0 in the hover. Do you get the same number?

@archmoj With 171.9599999 i got the same number like you. But with 171.95 it stills 171.9

@hatienloi
Copy link
Author

Hi @archmoj Any update for it? Do we have a patch fix for it?

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

No branches or pull requests

3 participants