[英]d3.js force-collapsible with labels
Actually I've integrated collapsible feature inside bounded force directed graph. 实际上,我已经在有向力有向图中集成了可折叠功能。 But when I tried to put a label on each node, I got unexpected output. 但是,当我尝试在每个节点上放置标签时,得到了意外的输出。
I used bellow code to append labels on node: 我使用下面的代码在节点上附加标签:
node.enter().append("text")
.attr("class","node")
.attr("cx", function(d) { return d.x; })
.attr("cy", function(d) { return d.y; })
.on("click",click)
.text(function(d){return d.name})
.call(force.drag);
And below code I've written inside a tick function: 在下面的代码中,我编写了一个tick函数:
node.attr("transform", function(d) {
return "translate(" + d.x + "," + d.y + ")";
});
What I might be doing wrong? 我可能做错了什么?
I need to append the g tag and then circle and text: 我需要附加g标记,然后圈出和文字:
var nodeEnter = node.enter().append("g")
.attr("class", "node")
.on("click", click)
.call(force.drag);
nodeEnter.append("circle")
.attr("r", function(d) { return Math.sqrt(d.size) / 10 || 8.5; });
nodeEnter.append("text")
.attr("dy", ".35em")
.text(function(d) { return d.name; });
node.select("circle")
.style("fill", color);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.