我使用d3进行强制布局中的节点和边。现在我想刷一些节点,并将类“选定”添加到刷过的节点上。它在画笔过程中工作得很好,但是一旦画笔结束,“选定”的类就消失了,我不知道为什么。下面是我的代码:
function brushstarted () {
console.log('brush start')
nodegroup.each(function (d) {
d.selected = false
d.previouslySelected = false
})
}
function brushed () {
let selection = d3.event.selection
nodegroup.classed('selected', function (d) {
d.selected = d.previouslySelected ^ (selection != null && selection[0][0] <= d.x && d.x < selection[1][0] && selection[0][1] <= d.y && d.y < selection[1][1])
return d.selected
})
}
function brushended () {
console.log('brush end')
if (d3.event.selection !== null) {
d3.select(this).call(d3.event.target.move, null)
}
}下面是处于“已刷”状态和“已刷”状态的节点,如您所见,在“已刷”状态下,节点应该与“已刷”相同,但事实并非如此,这就是我的问题,我该如何解决它? nodes in "brushed" state nodes in "brushend" state
发布于 2018-06-05 21:35:46
我想通了。只需在刷新函数中添加一行代码
if (d3.event.sourceEvent.type !== 'end') {
// previous code move into here
}https://stackoverflow.com/questions/50695073
复制相似问题