Node
绘制它们的位置很重要(应该显示在顶部的那些需要最后绘制)。
这些节点的位置和z轴可能会发生变化,这就是为什么我尝试使用
钥匙
指数
case class Node(id: Int)
def addNodesToSVG = {
val sortedData: List[Node] = ???
val nodesSelection = d3.select("#nodes").selectAll(".node")
.data(sortedData.toJSArray, (n: Node) => {
n.id.toString +
// the position of those nodes may change over time
// that's why we need to include the position in the identifier
sortedData.indexOf(n)
}
nodesSelection.enter().append("g").attr("class", "node") // ...
nodesSelection
.attr("transform", transform) // ...
nodesSelection.exit().remove()
}
理论上,如果我只有两个节点的话,这就是我认为它会起作用的方式(
n1
n2
),它们保存在
List(n1, n2)
node key
----- ---
n1 10 // node 1 at position 0
n2 21 // node 2 at position 1
现在如果我将列表更改为
List(n2, n1)
打电话
addNodesToSVG
这也是我认为会发生的事情:
node key
----- ---
n2 20 // node 1 at position 0
n1 12 // node 2 at position 1
nodesSelection.exit().remove()
编辑
经过进一步的调试,我发现我的
exit
所选内容的大小始终为0。