D3.js adjust rect to text size: getBBox()?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm creating a force directed graph using D3.js, see JSFiddle: http://jsfiddle.net/pwxecn8q/ . The text and rect are placed in the same group. When appending the rect s I want to select the text element for the same group. Call getBBox() on it and use those values to resize the rect to fit the text "in" it. However, I'm unsure how to select the text element from the same group when appending the rect s... Any suggestion on how to go about this? The relevant code: var color = d3.scale.category20(); var svg = d3.select("body").append("svg")