我有更新我的力量向圖,這是我每一次我從respectives陣列刪除節點和鏈路將調用此代碼:刪/改標籤
function update_graph() {
link_update = svg.selectAll(".link").data(
force.links(),
function (d) {
return d.source.id + "-" + d.target.id;
}
);
link_update.enter()
.insert("line", ".node")
.attr("class", "link");
link_update.exit()
.remove();
node_update = svg.selectAll(".node").data(
force.nodes(),
function (d) {
return d.id;
}
);
node_update.enter()
.append("circle")
.attr("class", function (d) {
return "node " + d.id;
})
.attr("r", function (d) {
return radio/d.group;
})
.call(force.drag)
.on('dblclick', connectedNodes);
//labels
node_update.enter().append("text")
.attr("dx", function (d) {
return (radio-7)/d.group;
})
.attr("dy", function (d) {
return (radio-7)/d.group;
})
.text(function (d) {
return d.id;
})
.style("stroke", "black");
// Remove the SVG circle whenever a node vanishes from the node list.
node_update.exit()
.remove();
// Start calling the tick() method repeatedly to lay out the graph.
force.start();
}
節點和鏈接從圖中正確刪除,但標籤保留在那裏,我如何讓標籤與節點同步並只顯示圖上當前的內容?
小提琴複製問題:提前
https://jsfiddle.net/vzes4h8y/感謝
你可以放在一起工作小提琴 – thatOneGuy
下面是一個小提琴複製問題,請單擊「添加節點」,然後在「重置圖形」 HTTPS幾次://的jsfiddle .net/vzes4h8y/ – RCRH89