简体   繁体   English

在鼠标悬停时显示连接的节点会显示交叉的链接

[英]Showing connected nodes on mouseover shows crossed links

I have a force-directed graph where on node mouseover the elements which are not connected to the current node are faded out, based on the following example . 我有一个力导向图,根据以下示例 ,在该图上,鼠标悬停在节点上时,未连接到当前节点的元素将淡出。 The problem is that if the cursor is moved fast and it crosses a link which is not part of the target node's connections, it is still shown in full opacity since the crossed link mouseover is triggered on the way, but apparently does not have time to complete its mouseout function. 问题是,如果光标快速移动并且穿过了不属于目标节点连接的一部分的链接,由于交叉链接鼠标悬停在途中被触发,但它仍显示为完全不透明,但是显然没有时间完成其mouseout功能。 For instance you can see this: 例如,您可以看到以下内容: 褪色问题

In the picture the mouse is moved fast from top to bottom and the cursor is stopped at the HSA-MIR-424. 在图片中,鼠标从上到下快速移动,光标停在HSA-MIR-424上。 The connections to the target node are shown correctly but also three extra links are visible since their mouseover is triggered when the cursor crosses them. 正确显示了到目标节点的连接,但是还显示了三个额外的链接,因为当光标越过它们时,就会触发它们的鼠标悬停。 If I repeat the top-to-bottom motion slowly to the same node or move bottom-to-top to the node such problem is not seen (since there are no links to be crossed in that direction, in the picture). 如果我缓慢地对同一节点重复从上到下的运动,或从下到上移动到该节点,则不会出现此问题(因为图中没有链接可沿该方向交叉)。

How can this problem be avoided? 如何避免这个问题?

Relevant parts of the code, link mouseover/mouseout: 代码的相关部分,链接鼠标悬停/鼠标悬停:

    .on("mouseover", function(d) {
      var selection = d3.select(this);
      var initialWidth = Number( selection.style("stroke-width") );
      selection.transition().style("stroke-width", initialWidth + Number(4) )
      .style("stroke-opacity", 1.0);
      //.style("stroke", linkOverColor);
    } )
    .on("mouseout", function(d) {
      var selection = d3.select(this);
      selection.transition().style("stroke-width", getLinkStroke( selection.data()[0] ) )
      .style("stroke-opacity", conf.link_def_opacity);
    })

Node mouseover/mouseout: 节点鼠标悬停/鼠标移出:

    // display closest neighbors and fade others out
    .on("mouseover", fade(0.10) )
    // return to default view
    .on("mouseout", fade(conf.node_def_opacity) );

The fading function: 衰落功能:

    function fade(opacity) {
      return function(d) {

        d3.event.stopPropagation();

        var thisOpacity;

        // return to default view
        if( opacity === conf.node_def_opacity )
        {
          d3.selectAll('marker > path').transition().style("opacity", 1);
          nodeGroup.transition().style("opacity", conf.node_def_opacity);
          link.style("stroke-opacity", conf.link_def_opacity);
        }
        else // fade not-neighborhood away
        {
          d3.selectAll('marker > path').transition().style("opacity", 0);
          // d3.selectAll('marker > path').transition().style('display', 'none');
          nodeGroup.transition().style("opacity", function(o)
          {
            thisOpacity = isConnected(d, o) ? conf.node_def_opacity : opacity;
            return thisOpacity; 
          });

          link.style("stroke-opacity", function(o) {
            return o.source === d || o.target === d ? conf.link_def_opacity : opacity;
          });              
        }
      }
    }   

This problem was solved by introducing a timer for the node and link mouseover actions. 通过为节点和链接鼠标悬停操作引入计时器来解决此问题。 The code is listed in this answer . 该代码在此答案中列出。

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

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