簡單地刪除節點應該足以使力重新排列並重新組合節點。但是,您需要保存節點以將其恢復(可能使用臨時數組)。
但是,如果你想要的節點飛出屏幕(回),那麼我會做(使用V4)是移動節點到一個新的forcePoint這道關屏:
legend.append("rect")
.attr("x", width - 18)
.attr("width", 18)
.attr("height", 18)
.style("fill", color)
.on("click", function (d) {
node.filter(function() {
return this.dataset.bank === d;
})
position
.force('x', d3.forceX(width/2).strength(20))
.force('y', d3.forceY(height*2).strength(20));//should be twice the height of the svg, so way off the y axis. Or whichever direction you choose.
});
嗨馬塞洛,非常感謝你,正是我需要的!現在有一件事與動畫:當點擊「交換x軸變量」按鈕幾次,動畫凍結,只有在點擊一個圖例鍵後重新開始。有任何想法嗎? – WoltjerD
@WoltjerD:'d3.force'是在DrawNode函數中定義的。交換軸的函數調用'force.resume',但'force'在'DrawNode'之外是不確定的。我更新了塊,在它調用'force.resume'的任何地方調用'DrawNode'。 – Marcelo