shawnbot / aight

JavaScript shims and shams for making IE8-9 behave reasonably
Other
756 stars 98 forks source link

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

Closed shawnbot closed 7 years ago

shawnbot commented 12 years ago

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

gabrielmontagne commented 11 years ago

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 commented 11 years ago

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

gabrielmontagne commented 11 years ago

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 commented 11 years ago

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 commented 11 years ago

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 commented 7 years ago

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