通过将鼠标悬停在节点上突出显示 D3 中的边
Highlighting edges in D3 by hovering mouse over nodes
我是 D3 的新手,我通过将以下行添加到脚本来使用此模板 (http://bl.ocks.org/mbostock/1153292) to visualize my graph. I'd like to highlight the links that are connected to a node by hovering mouse over the node. I tried the technique used in (http://jsfiddle.net/2pdxz/2/)。
nodes.on('mouseover', function(d) {
link.style('stroke-width', function(l) {
if (d === l.source || d === l.target)
return 4;
else
return 2;
});
});
// Set the stroke width back to normal when mouse leaves the node.
nodes.on('mouseout', function() {
link.style('stroke-width', 2);
});
但它似乎对我不起作用,当我将鼠标移到节点上时没有任何反应。
如评论中所述,代码的基本原理是正确的,问题是 link
变量应该命名为 path
.
我是 D3 的新手,我通过将以下行添加到脚本来使用此模板 (http://bl.ocks.org/mbostock/1153292) to visualize my graph. I'd like to highlight the links that are connected to a node by hovering mouse over the node. I tried the technique used in (http://jsfiddle.net/2pdxz/2/)。
nodes.on('mouseover', function(d) {
link.style('stroke-width', function(l) {
if (d === l.source || d === l.target)
return 4;
else
return 2;
});
});
// Set the stroke width back to normal when mouse leaves the node.
nodes.on('mouseout', function() {
link.style('stroke-width', 2);
});
但它似乎对我不起作用,当我将鼠标移到节点上时没有任何反应。
如评论中所述,代码的基本原理是正确的,问题是 link
变量应该命名为 path
.