[英]d3.js v4 move viewport to specific node
I use d3.js v4 to build force-directed graph just like in the basic example. 就像在基本示例中一样,我使用d3.js v4来构建力导向图。 I've also created input field, where user can type the node name.
我还创建了输入字段,用户可以在其中输入节点名称。 Then I search the matching
circle
element like so: 然后我搜索匹配的
circle
元素,如下所示:
findNode(name) {
let theNode = this.d3Svg.selectAll('circle').filter(function(d) {
return d.name == name;
});
}
After that I want to move viewport to the foundNode
. 之后,我想将视口移至
foundNode
。 How can I do that? 我怎样才能做到这一点?
Tried this: this.d3.zoom().translateTo(theNode, theNode.x, theNode.y);
尝试过这个:
this.d3.zoom().translateTo(theNode, theNode.x, theNode.y);
but nothing happens. 但什么也没发生。 Here is what
console.log('theNode: ',theNode)
says: 这是
console.log('theNode: ',theNode)
所说的:
I've also found similar question , but some older version of d3 is used there. 我也找到了类似的问题 ,但是在那里使用了较旧版本的d3。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.