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

Scale gives different results in the v5.8 #161

Closed
Atralbus opened this issue Jan 31, 2019 · 2 comments
Closed

Scale gives different results in the v5.8 #161

Atralbus opened this issue Jan 31, 2019 · 2 comments

Comments

@Atralbus
Copy link

The code below is giving 2014 0 as an output in the v5.5.

const scale = d3.scaleLog().clamp(true)
 .rangeRound([150, 0])
 .domain([2009, 2014])
console.log(scale.invert(0), scale(2014))

But after switching to the v5.8, I realized that now it's giving 2013.999999999999 0. Is there a way to fix it without explicitly rounding the numbers?

@mbostock
Copy link
Member

Due to floating point precision, we don’t guarantee that scale or scale.invert return exact values in the range or domain, respectively. The implementation changed in 5.8 to allow for generic transformations on continuous scales.

Why do you require exact values in your application? What I’d recommend depends on what you are trying to do.

@Atralbus
Copy link
Author

Atralbus commented Jan 31, 2019

@mbostock Thanks for the clarification. I have a logarithmic line chart where I'm selecting a range on the y axis with a brush. Inside the end event of brush, scale.invert returns 2013.999999999999 and prevents me to select the value 2014 at the top. And I don't want to round numbers coming from scale.invert in there because I also want to be able select continuous values.

Shouldn't we be able to directly get the values given in the domain? I understand that it might need to support continuous scales, but why prevent getting 2014 at all?

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

No branches or pull requests

2 participants