鼠标退出 D3 后如何在元素上设置默认颜色



我有一个强制有向图,我喜欢突出显示它的父级并使它们比其他项大一点,我可以使它们成为新颜色并使它们更大,但我无法将它们恢复为默认大小和颜色。每当我将鼠标移到元素上时,它都会变成绿色,但是当我移出鼠标时,只有中心元素会改变颜色,但它不会恢复到自己的颜色,它会恢复到我放置鼠标的颜色。

function highlightParents(d) {
    var colour = d3.event.type === 'mouseover' ? 'green' : color(d.group);
    d3.select('#id-' + parseInt(d.id)).style('fill', colour);
    var bid = "";
    for (var i = 0; i < link._groups[0].length; i++) {
        if (link._groups[0][i].attributes[0].value.replace("t-", "") == d.id) //target
        {
            bid += link._groups[0][i].attributes[1].value.replace("s-", ""); //source
            d.id = link._groups[0][i].attributes[1].value.replace("s-", "");  //source

            var colour = d3.event.type === 'mouseover' ? 'green' : color(d.group);
            d3.select('#id-' + parseInt(d.id)).style('fill', colour);
            var setr = d3.event.type === 'mouseover' ? '7' : 5;
            d3.select('#id-' + parseInt(d.id)).style('r', setr);                         
            i = 0;
            if (link._groups[0][i].attributes[1].value == "304410") {
                break;
                d3.selectAll('#id-' + parseInt(d.id)).style('fill', (d.group));
            }
        }
    }
}

你能使用"mouseout"事件吗?

例如:

function highlightParents(d) {
  var colour = color(d.group);
  if (d3.event.type === 'mouseover') colour = 'green';
  if (d3.event.type === 'mouseout') colour = 'red';
  ...

最新更新