2016-06-17 37 views
9

我試圖使用D3拖動用帆布這樣一個:D3拖動0.3.0 - 「無法讀取空的屬性‘按鈕’」

select(canvas) 
.call(
    drag() 
    .container(canvas) 
    .subject(partial(getNodeAtMouse, simulation, canvas)) 
    .on('start', someFunction)) 

不過,我得到以下錯誤,當其實,我試圖拖動:

Cannot read property 'button' of null 

從下面的行D3拖動(D3原始源代碼)

function defaultFilter() { 
    return !d3Selection.event.button; 
    } 

如果我刪除功能(通過指定我自己過濾器),我收到以下錯誤:

Cannot read property 'sourceEvent' of null 

在D3中選擇(D3原始源代碼)

function sourceEvent() { 
    var current = exports.event, source; 
    while (source = current.sourceEvent) current = source; 
    return current; 
    } 

這讓我覺得有D3拖動的期望之間有一些錯誤D3選擇。有任何想法嗎?

回答

0

我不知道這是否適合你,但對我來說,問題是因爲我沒有導入整個d3軟件包,我猜測這會讓「事件」未定義。

因此,不是這樣的: import {drag} from 'd3';

現在我使用的是: import * as d3 from 'd3';

1

我也收到這個錯誤,我只是d3-zoom導入時。

import {zoom} from 'd3-zoom'; 
import {select} from 'd3-selection'; 

參考:https://github.com/d3/d3-zoom/issues/27

通過導入這兩種 d3-zoomd3-selection解決它
相關問題