d3.js鼠标悬停事件发生冲突

时间:2013-04-25 21:29:42

标签: javascript d3.js

我正在使用Christophe Viau的d3.js工具提示助手:

https://gist.github.com/milroc/2975255

但也希望在鼠标悬停时触发其他事件,而不仅仅是工具提示,特别是我想修改圆圈本身,所以我试过了:

var circle = svg.append("svg:g").selectAll("circle")
.data(force.nodes())
.enter().append("svg:circle")
.call(d3.helper.tooltip(function(d,i){return d.name;}))
.attr("r", 12)
 .call(force.drag)
 .on("mouseover", function(){d3.select(this).style("fill", "blue");});

要么一个人独立工作,而不是一起工作。我尝试编辑工具提示助手,但是我遇到了错误。我在工具提示助手上添加了这些变体:

var newvar = function(d,i) {d3.select(this).style("fill", "blue");}
var newvar = function(selection) {d3.select(this).style("fill", "blue");}

有谁知道说这个的正确方法是什么?

1 个答案:

答案 0 :(得分:4)

我更新了我10个月的代码;)http://bl.ocks.org/biovisualize/2973775

您需要的部分是event namespacing,因此您可以将多个事件应用于同一个元素而不会发生冲突:

.on('mousemove.tooltip', ...
相关问题