问题描述
我有一个(相当简单的)问题:如何在 D3.js 所做的选择上取消调用"force.drag?假设我创建了一组元素并在其上调用调用",为其提供强制导向布局的拖动回调.看起来像这样:
I have a (rather simple) question: How to "un-call" force.drag on a selection made by D3.js? Let's say I created a set of elements and called "call" on it, giving it the drag-callback of a force-directed layout. That looked like this:
d3.selectAll('rect').call(force.drag);
现在应该可以在以后从某些节点中删除该行为.我的方法包括使用
Now it shall be possible to remove that behavior from some of the nodes later on. My approaches included resetting various listeners, such as 'click', 'drag' etc. using
d3.select('rect#no-drag').on('click', null);
他们都没有工作.有人知道如何删除回调吗?
None of them worked. Does anybody know how to remove the callback?
推荐答案
你已经接近了.拖动事件由具有名为 drag
的命名空间的 mousedown
事件启动.请参阅:https://github.com/mbostock/d3/blob/master/src/behavior/drag.js#L5
You are close. The drag event is initiated by a mousedown
event with a namespace called drag
. See: https://github.com/mbostock/d3/blob/master/src/behavior/drag.js#L5
因此,要删除它,您可以这样做:
So, to remove this you could do:
d3.select('rect#no-drag').on('mousedown.drag', null);
这篇关于D3.js:从选择中删除 force.drag的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!