javascript - D3 v4 - Accessing selection array and find corresponding element -


i'm trying constraint relaxing work piechart. based on example https://jsfiddle.net/thudfactor/hdwth/ relaxing method used seems not work v4 more.
concrete problem how access selection group array directly:

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 changed d3 v4.x how access selections group array?
how go now?

in d3 4.0, selections not arrays anymore. according api:

selections no longer subclass array using prototype chain injection; plain objects, improving performance.

so, if console.log(textlabels), you're gonna see this:

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

depending on selecting. there, can access array using textlabels._groups, instance.

for having array, have use selection.nodes(), which, according api:

returns array of (non-null) elements in selection.


Comments