d3-drag 0.3.0 - “无法读取属性”按钮'为null' [英] d3-drag 0.3.0 - "Cannot read property 'button' of null"
问题描述
我正在尝试使用带有画布的d3-drag:
I'm trying to use d3-drag with a canvas a such:
select(canvas)
.call(
drag()
.container(canvas)
.subject(partial(getNodeAtMouse, simulation, canvas))
.on('start', someFunction))
然而,当我实际尝试拖动时出现以下错误:
However, I get the following error when I actually attempt to drag:
Cannot read property 'button' of null
来自d3-drag中的以下行(d3原始源代码)
from the following line in d3-drag (d3 original source code)
function defaultFilter() {
return !d3Selection.event.button;
}
如果我删除该功能(通过指定我自己的过滤器),我得到了以下错误:
If I remove that function (by specifying my own filter), I get the following error:
Cannot read property 'sourceEvent' of null
在d3选择中(d3原始源代码)
In d3-selection (d3 original source code)
function sourceEvent() {
var current = exports.event, source;
while (source = current.sourceEvent) current = source;
return current;
}
这让我觉得d3-drag的期望值之间存在一些误差和d3选择。有什么想法吗?
This makes me think that there is some bug between the expectations of d3-drag and d3-selection. Any ideas?
推荐答案
当我只导入 d3-zoom时,我也遇到了这个错误
。通过导入 d3-zoom
和 d3-selection
解决了这个问题:
I was also getting this error when I was importing only d3-zoom
. Solved it by importing both d3-zoom
and d3-selection
:
import {zoom} from 'd3-zoom';
import {select} from 'd3-selection';
参考: https://github.com/d3/d3-zoom/issues/27
这篇关于d3-drag 0.3.0 - “无法读取属性”按钮'为null'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!