Is there a way to calculate the maximum length of text elements in an SVG selection similar to using Array.map()
? Currently, I am retrieving the maximum length of a selection of SVG <text/>
elements by utilizing .selectAll(...)[0].map(...)
, but it feels like a workaround. Is there a more efficient approach?
var chi = svg.selectAll('.chi');
var xChi = d3.max(chi[0].map(function (itm) { return itm.getComputedTextLength(); }));
I am familiar with using selection.each()
to iterate a function over a selection, however, I am unsure how to incorporate d3.max()
into this process. My attempt at using
d3.max(chi.each(function (itm) { return itm.getComputedTextLength(); }))
was unsuccessful since d3.each()
does not generate an array of the returned values.