3

我正在使用 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");}

有谁知道正确的表达方式是什么?

4

1 回答 1

4

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

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

.on('mousemove.tooltip', ...
于 2013-04-25T23:29:24.213 回答