简体   繁体   English

Javascript InfoVis Toolkit:事件在随后的函数中返回错误的节点

[英]Javascript InfoVis Toolkit: Event returns wrong node in function that ensues

I stumbled upon the following problem with the Javascript InfoVis Toolkit's Spacetree visualization: When I click a node with the right mouse button, the action which ensues operates on a different node in the same subtree than the one which actually has been clicked.我在 Javascript InfoVis Toolkit 的 Spacetree 可视化中偶然发现了以下问题:当我用鼠标右键单击一个节点时,随之而来的操作在同一子树中的不同节点上运行,而不是实际单击的节点。

Here is the relevant portion of code:这是代码的相关部分:

st = new $jit.ST({

    Events: {  
        enable: true,
        onRightClick: function(node, eventInfo, e) {
            console.log(eventInfo); // line 87
            console.log(e); // line 88
            if (node != undefined) {
                console.log(node.id); // line 90
                if (removedNodes.indexOf(node.data.uniqueId)>-1) {
                    console.log(node.id, " has been restored");
                    removedNodes.splice(removedNodes.indexOf(node.data.uniqueId),1);
                } else {
                    console.log(node.id, " has been deleted"); // line 95
                    removedNodes.push(node.data.uniqueId);
                }
                localStorage.setItem("removedNodes", JSON.stringify(removedNodes));
                loadNewTree(currentTreeId, true, 0)
            }
        },
    },
    /* further code */
}

As you can see, I put the event info and node ID of the target node to console output (the relevant line numbers marked in the code snippet above).如您所见,我将目标节点的事件信息和节点 ID 放入控制台输出(上面代码片段中标记的相关行号)。 Here is the console output for a case where the wrong node is targeted:以下是针对错误节点的情况的控制台输出:

上面代码的控制台输出

I'm stuck on this problem and don't see what could have gone wrong.我被这个问题困住了,看不出哪里出了问题。 The problem occurs approximately once in ten clicks, if clicking nodes from the same subtree, frequently (but not always!) the targeted node is the one which has been clicked one click earlier.如果单击同一子树中的节点,则该问题大约每十次单击就会发生一次,并且经常(但并非总是!)目标节点是之前单击过一次的节点。

Thanks for any input!感谢您提供任何意见!

Found a hack to work around the problem: Take the node ID directly from the event:找到了解决该问题的 hack:直接从事件中获取节点 ID:

let Node = st.graph.getNode(e.target.attributes.id.nodeValue);

and then use the newly defined Node rather than the misbehaving node.然后使用新定义的节点而不是行为不端的节点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM