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

d3.selection.sort() doesn't work in IE8 #1

Closed
shawnbot opened this issue Jun 8, 2012 · 6 comments
Closed

d3.selection.sort() doesn't work in IE8 #1

shawnbot opened this issue Jun 8, 2012 · 6 comments

Comments

@shawnbot
Copy link
Owner

shawnbot commented Jun 8, 2012

But Array.prototype.sort() does... Curious.

@gabrielmontagne
Copy link

This is doesn't seem to be an aight problem.

In IE8 D3 fails to override the native array's sort function so when you call d3.selection.sort() it just runs the stock array's sort function. That's why it doesn't crash but just silently fails to do anything useful.

This is because in IE sort, in particular, doesn't become enumerable even when you override it.

image

D3 builds a selection prototype array with all the extra and overridden methods and then loops through its enumerable keys and copies them to each particular selection. "sort" doesn't show up so it doesn't get copied.

@shawnbot
Copy link
Owner Author

Aha! Great catch, thank you. Should we force IE8 to make the shimmed Array.prototype methods enumerable then?

@gabrielmontagne
Copy link

I'm not sure what can be done from aight's side, to be honest. How could you force IE8 to show an overridden array's "sort" in an for...in loop?

@shawnbot
Copy link
Owner Author

Well, we could start monkey patching d3 in aight (probably in a d3-specific build), and just brute-force set d3.selection.prototype.sort.

@gabrielmontagne
Copy link

That's a nice angle to the problem. The function is hidden away in a closure, tho. If you want to take a look we added, to bypass the problem,

if ("sort" in prototype) array.sort = prototype.sort

... to a monkey-patched version of D3; right after this line https://github.com/mbostock/d3/blob/v2.10.3/d3.v2.js#L2588

shawnbot pushed a commit that referenced this issue Jul 31, 2013
Validate item() method of CSSStyleDeclaration
@shawnbot shawnbot mentioned this issue Sep 13, 2014
Merged
8 tasks
@shawnbot shawnbot added the d3 label Jan 28, 2015
@shawnbot
Copy link
Owner Author

I'm closing this because D3 v4 probably does things differently, and users have no doubt found their own workarounds.

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

No branches or pull requests

2 participants