[英]How do I move all selected nodes at once ? D3/JS
我在D3中制作了一個力向圖。
我可以在節點上拖動一個框並將其屬性更改為“選定”。
我現在要做的是一次移動所有這些選定的節點。 這是我的拖動功能
function dragstart(d, i)
{
force.stop(); //-stop the force layout as soon as you move nodes
}
function dragmove(d, i) //-change coordinates of nodes and lines ???
{
d.px += d3.event.dx;
d.py += d3.event.dy;
d.x += d3.event.dx;
d.y += d3.event.dy;
tick();
}
function dragend(d, i) //-when you stop dragging the node
{
d.fixed = true; //-D3 giving the node a fixed attribute
d3.select(this).classed("fixed", true); //-changing nodes CSS class
tick(); //-update positions
}
如何應用此功能,以便一次移動所有選定的節點?
我假設您的意思是將節點的類更改為“選定”,而不是其屬性。 我是D3js的初學者,但是我認為這應該發生:
d3.behaviour.drag()
.on("dragstart", function() {
d3.selectAll('.selected').each(dragstart(d,i))
})
.on("drag", function() {
d3.selectAll('.selected').each(dragmove(d,i))
})
.on("dragend", function() {
d3.selectAll('.selected').each(dragend(d,i))
})
根據您的函數tick()
作用,這可能適合您。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.