我正在尝试使用带有画布的d3-drag:
select(canvas)
.call(
drag()
.container(canvas)
.subject(partial(getNodeAtMouse, simulation, canvas))
.on('start', someFunction))
Run Code Online (Sandbox Code Playgroud)
但是,当我实际尝试拖动时,我收到以下错误:
Cannot read property 'button' of null
Run Code Online (Sandbox Code Playgroud)
从d3-drag中的以下行开始(d3原始源代码)
function defaultFilter() {
return !d3Selection.event.button;
}
Run Code Online (Sandbox Code Playgroud)
如果我删除该功能(通过指定我自己的过滤器),我收到以下错误:
Cannot read property 'sourceEvent' of null
Run Code Online (Sandbox Code Playgroud)
在d3选择中(d3原始源代码)
function sourceEvent() {
var current = exports.event, source;
while (source = current.sourceEvent) current = source;
return current;
}
Run Code Online (Sandbox Code Playgroud)
这让我觉得d3-drag和d3-selection的期望之间存在一些错误.有任何想法吗?
小智 0
我不知道这是否适合你,但对我来说,问题是因为我没有导入整个 d3 包,我猜这使得“事件”未定义。
所以代替这个:
import {drag} from 'd3';
现在我正在使用:
import * as d3 from 'd3';