D3 v4 - Access to the selection array and search for the corresponding item

I try to force myself to relax to work on my cake. It is based on this example https://jsfiddle.net/thudfactor/HdwTH/ , but the relaxation method used seems to no longer work with v4.
The specific problem is how they directly access the array of select groups:

textLabels = labelGroups.append("text").attr( ... ); if(again) { labelElements = textLabels[0]; <------------- here textLines.attr("y2",function(d,i) { labelForLine = d3.select(labelElements[i]); return labelForLine.attr("y"); }); setTimeout(relax,20) } 

Has this changed with D3 v4.x how do you access an array of pick groups?
How would you do it now?

+3
javascript d3v4
source share
1 answer

In D3 4.0, selection is no longer an array. According to the API:

Choosing to no longer subclass Array using prototype chain injection; they are now simple objects that improve performance.

So, if you are console.log(textLabels) , you will see something like this:

 {_groups: Array[1], _parents: Array[1]} 

Depending on what you choose. From there, you can access your array using textLabels._groups , for example.

To have an array, you should use selection.nodes() , which, according to the API:

Returns an array of all (non-null) elements in this selection.

+8
source share

All Articles