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

numberDisplay tweening breaks on divide-by-zero #1176

Closed
XaserAcheron opened this issue Jul 6, 2016 · 3 comments
Closed

numberDisplay tweening breaks on divide-by-zero #1176

XaserAcheron opened this issue Jul 6, 2016 · 3 comments
Labels
Milestone

Comments

@XaserAcheron
Copy link
Contributor

Welp! Another bug of sorts -- currently seeing this on beta-31.

The gist is that setting the valueAccessor of a numberDisplay to a function that can divide by zero will cause tweening to malfunction when filtering away from Infinity -- the display gets stuck at NaN until the numberDisplay is redrawn once more.

Good ol' JSFiddle time:
https://jsfiddle.net/fzkjch04/1/

To reproduce, select and deselect the "Not Rush" slice -- you'll notice the numberDisplay labeled "borks" will, true to its name, get stuck at NaN on the way out. Just calling dc.redrawAll (i.e. clicking the "Redraw Charts" button) is enough to get it un-stuck.

The second number display (labeled "works") has its valueAccessor modified to explicitly return NaN when the divisor is zero -- this makes it work just fine for whatever reason.

[aside: Although I technically may be able to work around this in my own app, I've gotten into the habit of converting NaNs to positive or negative Infinity for table sorting purposes, meaning there are cases where a value of Infinity makes sense in context. I don't want to lose that.]

@gordonwoodhull
Copy link
Contributor

Thanks @XaserAcheron!

Tweening infinity, eh? Isn't that impossible?

Hmm, numerically speaking, I'd expect d3.interpolateNumber to get stuck on infinity rather than going to NaN. But either way we'll probably have to special-case it!

It's a very simple component, if you want to take a look...

@gordonwoodhull gordonwoodhull added this to the v2.0 milestone Jul 6, 2016
@XaserAcheron
Copy link
Contributor Author

Taking a quick look, It indeed ought to be a simple one-liner if we're allowed to alias Infinity as 0 for the first parameter of the d3.interpolateNumber call. That's how it treats NaNs currently, so it's in "should work" territory.

I'll make a fix attempt here in a bit.

@gordonwoodhull
Copy link
Contributor

Thanks @XaserAcheron! Fixed in 2.0 beta 32.

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

No branches or pull requests

2 participants