小编Jir*_*rka的帖子

如何从D3.js力图中的元素位置获取Web元素(id)

我正在使用D3.js力图,但无法从元素位置(我知道)中找出元素ID。

我正在使用Leap motion。我需要在没有鼠标的情况下模拟鼠标事件(单击,移动,拖动等)。而且,如果我是对的,为了能够做到这一点,我需要从坐标x和y(我从Leap运动指针知道的坐标)中找出元素id是什么。因此,从您上面的内容中,我需要找出('.node')。这是我已经尝试过的方法,但是没有用:

是否可以使用非鼠标,非触摸事件与D3.js图形进行交互?如果是这样,最有效的解决方法是什么?

因此,我使用了此功能(请参见下文),但是我需要知道元素ID才能使其正常工作:

//graph.simulate(document.getElementById("r_1"), 'dblclick', {pointerX: posX, pointerY: posY});
//here id r_1 is hardcoded, but I need to find out id from x and y coordinates.

this.simulate = function (element, eventName) {
    function extend(destination, source) {
        for (var property in source)
            destination[property] = source[property];
        return destination;
    }

    var eventMatchers = {
        'HTMLEvents': /^(?:load|unload|abort|error|select|change|submit|reset|focus|blur|resize|scroll)$/,
        'MouseEvents': /^(?:click|dblclick|mouse(?:down|up|over|move|out))$/
    };

    var defaultOptions = {
        pointerX: 0,
        pointerY: 0,
        button: 0,
        ctrlKey: false,
        altKey: false,
        shiftKey: false,
        metaKey: false,
        bubbles: true,
        cancelable: true …
Run Code Online (Sandbox Code Playgroud)

position element d3.js web

2
推荐指数
1
解决办法
7087
查看次数

标签 统计

d3.js ×1

element ×1

position ×1

web ×1