Undocumented third argument to event listener callbacks in v3?

19 views
Skip to first unread message

Anna Whitney

unread,
Oct 13, 2016, 2:16:56 PM10/13/16
to d3-js
I am in the process of updating some code from D3 v3 to v4, and the original v3 code does something like this:

selection.on('mouseenter', function(datum, unused, sIndex) {
   // more code that uses datum and sIndex
})

I can't figure out how to replicate the usage of the mysterious "sIndex" in D3 v4, since the v3 docs say event listener callbacks receive two arguments: the datum and the element index. What is this number being passed as the third argument, and how do I get at it in v4?

Anna Whitney

unread,
Oct 13, 2016, 2:31:10 PM10/13/16
to d3-js
In case anyone else is wondering, this is the group index (http://stackoverflow.com/questions/32507388/d3-on-sends-3-arguments-to-a-callback-function).

Mike Tahani

unread,
Oct 14, 2016, 2:12:21 PM10/14/16
to d3...@googlegroups.com
The group index is no longer exposed in v4 (the third argument is the group itself). Instead, you can "push that parent data down into the child data, replicating it for each child. Or you can use selection.each and create a closure that exposes parent and child data simultaneously" (source).

Bostock includes an example in the above Github issue that illustrates that concept.

MT

--
You received this message because you are subscribed to the Google Groups "d3-js" group.
To unsubscribe from this group and stop receiving emails from it, send an email to d3-js+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages