use*_*968 5 javascript svg selector d3.js
是否有类似Array.map()D3选择的东西?为了找到所选SVG <text/>元素的最大长度,我目前正在执行以下操作.然而,.selectAll(...)[0].map(...)对我来说似乎是一个黑客.有没有更好的办法?
var chi = svg.selectAll('.chi');
var xChi = d3.max(chi[0].map(function (itm) { return itm.getComputedTextLength(); }));
Run Code Online (Sandbox Code Playgroud)
我可以用来selection.each()在选择上迭代一个函数,但我不知道如何将它与它结合起来d3.max().我试过了d3.max(chi.each(function (itm) { return itm.getComputedTextLength(); })),但d3.each()没有返回返回值的数组
var allLength
d3.selectAll(".element")
.each(function(d, i) {allLength[i]=d3.select(this).node().getComputedTextLength() })
var maxLength = d3.max(a)
Run Code Online (Sandbox Code Playgroud)