简体   繁体   English

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

[英]How can i set default color on element after mouse out D3

I have a forced directed graph and I like to highlight its parents and make them a bit bigger than others I can make them new colour and make them bigger but I cannot return them to their default size and colour. 我有一个强制有向图,我喜欢突出它的父母,并使它们比其他人更大,我可以使它们成为新的颜色,并使它们更大,但我不能将它们恢复到默认的大小和颜色。 Whenever I move my mouse on the element it changes all of them green but when I move out my mouse only centre element changes colour but it does not return to its own colour it returns to colour that I put my mouse on. 每当我在元素上移动鼠标时,它都会将它们全部变为绿色,但是当我移出鼠标时,只有中心元素会改变颜色,但它不会返回到自己的颜色,而是返回到我将鼠标放在上面的颜色。

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));

            }
        }
    }
}

Could you use 'mouseout' event? 你能用'mouseout'活动吗?

For example: 例如:

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

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

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