Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/458.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript d3工具提示悬停问题_Javascript_Jquery_D3.js - Fatal编程技术网

Javascript d3工具提示悬停问题

Javascript d3工具提示悬停问题,javascript,jquery,d3.js,Javascript,Jquery,D3.js,我在悬停圆圈时显示和隐藏工具提示。我在工具提示中有一个数据,它可以有一个用户可能想要单击的链接。问题是,当我尝试单击工具提示链接工具提示获取隐藏时,我将悬停功能附加到节点。我试图在悬停元素的g中添加tooltip,但没有成功。有什么建议吗 尝试在mouseout事件中设置超时 尝试此操作,在特定时间隐藏工具提示 var json = { "name": "Base", "children": [ { "name": "Type A"

我在悬停
圆圈时显示和隐藏
工具提示
。我在
工具提示
中有一个数据,它可以有一个用户可能想要单击的链接。问题是,当我尝试单击
工具提示
链接
工具提示
获取隐藏时,我将
悬停
功能附加到节点。我试图在悬停元素的
g
中添加
tooltip
,但没有成功。有什么建议吗


尝试在mouseout事件中设置超时

尝试此操作,在特定时间隐藏工具提示

var json = 
{
    "name": "Base",
    "children": [
        {
            "name": "Type A"

        },
        {
            "name": "Type B"

        }
    ]
};

var setTime;
var delayTime = 1000;
var width = 700;
var height = 650;
var maxLabel = 150;
var duration = 500;
var radius = 5;

var i = 0;
var root;

var tree = d3.layout.tree()
    .size([height, width]);

var diagonal = d3.svg.diagonal()
    .projection(function(d) { return [d.x, d.y]; });

var svg = d3.select("#tree").append("svg")
    .attr("width", width)
    .attr("height", height)
        .append("g")
        .attr("transform", "translate(" + 0 + ",50)");

root = json;
root.x0 = height / 2;
root.y0 = 0;

root.children.forEach(collapse);
var div= d3.select('body').append('div').attr('class','tooltip').style('visibility','hidden').html('<div class="content"><a href="http:www.google.com">google</a></div>')


function update(source) 
{
    // Compute the new tree layout.
    var nodes = tree.nodes(root).reverse();
    var links = tree.links(nodes);

    // Normalize for fixed-depth.
    nodes.forEach(function(d) { d.y = d.depth * maxLabel; });

    // Update the nodes…
    var node = svg.selectAll("g.node")
        .data(nodes, function(d){ 
            return d.id || (d.id = ++i); 
        });

    // Enter any new nodes at the parent's previous position.
    var nodeEnter = node.enter()
        .append("g")
        .attr("class", "node")
        .attr("transform", function(d){ return "translate(" + source.y0 + "," + source.x0 + ")"; })
        .on("click", click);


     nodeEnter.append("circle")
        .attr("r", 10)
        .style("fill", function(d){ 
            return d._children ? "lightsteelblue" : "white"; 
        }).on('mouseover',function(){            
                div.style('left',d3.event.pageX+20+'px').style('top',d3.event.pageY+'px').style('visibility','visible')                     
        }).on('mouseout',function(){
        setTime = setTimeout(function() {
            div.style('visibility','hidden')
        }, delayTime);  
        })


    nodeEnter.append("text")
        .attr("x", function(d){ 
            var spacing = computeRadius(d) + 5;
            return d.children || d._children ? -spacing : spacing; 
        })
        .attr("dy", "3")
        .attr("text-anchor", function(d){ return d.children || d._children ? "end" : "start"; })
        .text(function(d){ return d.name; })
        .style("fill-opacity", 0);

    // Transition nodes to their new position.
    var nodeUpdate = node.transition()
        .duration(duration)
        .attr("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; });

    nodeUpdate.select("circle")
        .attr("r", 20)
        .style("fill", function(d) { return d._children ? "lightsteelblue" : "#fff"; });

    nodeUpdate.select("text").style("fill-opacity", 1);

    // Transition exiting nodes to the parent's new position.
    var nodeExit = node.exit().transition()
        .duration(duration)
        .attr("transform", function(d) { return "translate(" + source.y + "," + source.x + ")"; })
        .remove();

    nodeExit.select("circle").attr("r", 20);
    nodeExit.select("text").style("fill-opacity", 0);

    // Update the links…
    var link = svg.selectAll("path.link")
        .data(links, function(d){ return d.target.id; });

    // Enter any new links at the parent's previous position.
    link.enter().insert("path", "g")
        .attr("class", "link")
        .attr("d", function(d){
            var o = {x: source.x0, y: source.y0};
            return diagonal({source: o, target: o});
        });

    // Transition links to their new position.
    link.transition()
        .duration(duration)
        .attr("d", diagonal);

    // Transition exiting nodes to the parent's new position.
    link.exit().transition()
        .duration(duration)
        .attr("d", function(d){
            var o = {x: source.x, y: source.y};
            return diagonal({source: o, target: o});
        })
        .remove();

    // Stash the old positions for transition.
    nodes.forEach(function(d){
        d.x0 = d.x;
        d.y0 = d.y;
    });
}



function computeRadius(d)
{
    if(d.children || d._children) return radius + (radius * nbEndNodes(d) / 10);
    else return radius;
}

function nbEndNodes(n)
{
    nb = 0;    
    if(n.children){
        n.children.forEach(function(c){ 
            nb += nbEndNodes(c); 
        });
    }
    else if(n._children){
        n._children.forEach(function(c){ 
            nb += nbEndNodes(c); 
        });
    }
    else nb++;

    return nb;
}

function click(d)
{
    if (d.children){
        d._children = d.children;
        d.children = null;
    } 
    else{
        d.children = d._children;
        d._children = null;
    }
    update(d);
}

function collapse(d){
    if (d.children){
        d._children = d.children;
        d._children.forEach(collapse);
        d.children = null;
    }
}
function expand(d){   
    var children = (d.children)?d.children:d._children;
    if (d._children) {        
        d.children = d._children;
        d._children = null;       
    }
    if(children)
      children.forEach(expand);
}


 expand(root); 


update(root);
var json=
{
“名称”:“基础”,
“儿童”:[
{
“名称”:“类型A”
},
{
“名称”:“类型B”
}
]
};
var设定时间;
var延迟时间=1000;
var宽度=700;
var高度=650;
var maxLabel=150;
var持续时间=500;
var半径=5;
var i=0;
变种根;
var tree=d3.layout.tree()
.尺寸([高度、宽度]);
var diagonal=d3.svg.diagonal()
.投影(函数(d){返回[d.x,d.y];});
var svg=d3.选择(“树”).追加(“svg”)
.attr(“宽度”,宽度)
.attr(“高度”,高度)
.附加(“g”)
.attr(“转换”、“转换”(+0+),50)”;
root=json;
root.x0=高度/2;
root.y0=0;
根。子。forEach(塌陷);
var div=d3.select('body').append('div').attr('class','tooltip').style('visibility','hidden').html(“”)
函数更新(源)
{
//计算新的树布局。
var nodes=tree.nodes(root.reverse();
var links=tree.links(节点);
//为固定深度进行规格化。
forEach(函数(d){d.y=d.depth*maxLabel;});
//更新节点…
var node=svg.selectAll(“g.node”)
.数据(节点,函数(d){
返回d.id | |(d.id=++i);
});
//在父节点的上一个位置输入任何新节点。
var nodeEnter=node.enter()
.附加(“g”)
.attr(“类”、“节点”)
.attr(“transform”,函数(d){return“translate”(“+source.y0+”,“+source.x0+”));})
。开启(“点击”,点击);
nodeEnter.append(“圆”)
.attr(“r”,10)
.style(“填充”,函数(d){
返回d.(儿童?)浅蓝色“:“白色”;
}).on('mouseover',function(){
div.style('left',d3.event.pageX+20+'px')。style('top',d3.event.pageY+'px')。style('visibility','visible'))
}).on('mouseout',function(){
setTime=setTimeout(函数(){
div.style('可见性','隐藏')
},延迟时间);
})
nodeEnter.append(“文本”)
.attr(“x”,函数(d){
var间距=计算半径(d)+5;
返回d.children | | d.| children?-间距:间距;
})
.attr(“dy”,“3”)
.attr(“文本锚定”,函数(d){return d.children | | d.| u children?“end”:“start”})
.text(函数(d){返回d.name;})
.style(“填充不透明度”,0);
//将节点转换到其新位置。
var nodeUpdate=node.transition()
.持续时间(持续时间)
.attr(“transform”,函数(d){return“translate”(“+d.x+”,“+d.y+”)”);});
节点更新。选择(“圆圈”)
.attr(“r”,20)
.style(“fill”,函数(d){return d._children?“lightsteelblue”:“fff”});
nodeUpdate.select(“文本”).style(“填充不透明度”,1);
//将退出节点转换到父节点的新位置。
var nodeExit=node.exit().transition()
.持续时间(持续时间)
.attr(“transform”,函数(d){return“translate”(“+source.y+”,“+source.x+”)”);})
.remove();
nodeExit.select(“圆圈”).attr(“r”,20);
nodeExit.select(“文本”).style(“填充不透明度”,0);
//更新链接…
var link=svg.selectAll(“path.link”)
.data(链接,函数(d){返回d.target.id;});
//在父对象的上一个位置输入任何新链接。
link.enter()插入(“路径”,“g”)
.attr(“类”、“链接”)
.attr(“d”,函数(d){
var o={x:source.x0,y:source.y0};
返回对角线({source:o,target:o});
});
//过渡链接到他们的新位置。
link.transition()
.持续时间(持续时间)
.attr(“d”,对角线);
//将退出节点转换到父节点的新位置。
link.exit().transition()
.持续时间(持续时间)
.attr(“d”,函数(d){
var o={x:source.x,y:source.y};
返回对角线({source:o,target:o});
})
.remove();
//将旧位置隐藏起来,以便过渡。
nodes.forEach(函数(d){
d、 x0=d.x;
d、 y0=d.y;
});
}
功能计算机(d)
{
if(d.children | | d.| u children)返回半径+(半径*nbEndNodes(d)/10);
否则返回半径;
}
函数nbEndNodes(n)
{
nb=0;
如果(儿童){
n、 children.forEach(函数(c){
nb+=nbEndNodes(c);
});
}
else if(n._儿童){
n、 _children.forEach(函数(c){
nb+=nbEndNodes(c);
});
}
else-nb++;
返回nb;
}
功能点击(d)
{
如果(d.儿童){
d、 _children=d.children;
d、 children=null;
} 
否则{
d、 儿童=d.\U儿童;
d、 _children=null;
}
更新(d);
}
功能崩溃(d){
如果(d.儿童){
d、 _children=d.children;
d、 _儿童。forEach(崩溃);
d、 children=null;
}
}
函数展开(d){
变量children=(d.children)?d.children:d.\u children;
如果(d.)儿童{
d、 儿童=d.\U儿童;
d、 _children=null;
}
if(儿童)
儿童。forEach(扩展);
}
展开(根);
更新(根);

您可以在鼠标输出中设置超时吗?
on('mouseout',function(){
    setTimeout(function(){div.style('visibility','hidden');}, 2000)
})
var json = 
{
    "name": "Base",
    "children": [
        {
            "name": "Type A"

        },
        {
            "name": "Type B"

        }
    ]
};

var setTime;
var delayTime = 1000;
var width = 700;
var height = 650;
var maxLabel = 150;
var duration = 500;
var radius = 5;

var i = 0;
var root;

var tree = d3.layout.tree()
    .size([height, width]);

var diagonal = d3.svg.diagonal()
    .projection(function(d) { return [d.x, d.y]; });

var svg = d3.select("#tree").append("svg")
    .attr("width", width)
    .attr("height", height)
        .append("g")
        .attr("transform", "translate(" + 0 + ",50)");

root = json;
root.x0 = height / 2;
root.y0 = 0;

root.children.forEach(collapse);
var div= d3.select('body').append('div').attr('class','tooltip').style('visibility','hidden').html('<div class="content"><a href="http:www.google.com">google</a></div>')


function update(source) 
{
    // Compute the new tree layout.
    var nodes = tree.nodes(root).reverse();
    var links = tree.links(nodes);

    // Normalize for fixed-depth.
    nodes.forEach(function(d) { d.y = d.depth * maxLabel; });

    // Update the nodes…
    var node = svg.selectAll("g.node")
        .data(nodes, function(d){ 
            return d.id || (d.id = ++i); 
        });

    // Enter any new nodes at the parent's previous position.
    var nodeEnter = node.enter()
        .append("g")
        .attr("class", "node")
        .attr("transform", function(d){ return "translate(" + source.y0 + "," + source.x0 + ")"; })
        .on("click", click);


     nodeEnter.append("circle")
        .attr("r", 10)
        .style("fill", function(d){ 
            return d._children ? "lightsteelblue" : "white"; 
        }).on('mouseover',function(){            
                div.style('left',d3.event.pageX+20+'px').style('top',d3.event.pageY+'px').style('visibility','visible')                     
        }).on('mouseout',function(){
        setTime = setTimeout(function() {
            div.style('visibility','hidden')
        }, delayTime);  
        })


    nodeEnter.append("text")
        .attr("x", function(d){ 
            var spacing = computeRadius(d) + 5;
            return d.children || d._children ? -spacing : spacing; 
        })
        .attr("dy", "3")
        .attr("text-anchor", function(d){ return d.children || d._children ? "end" : "start"; })
        .text(function(d){ return d.name; })
        .style("fill-opacity", 0);

    // Transition nodes to their new position.
    var nodeUpdate = node.transition()
        .duration(duration)
        .attr("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; });

    nodeUpdate.select("circle")
        .attr("r", 20)
        .style("fill", function(d) { return d._children ? "lightsteelblue" : "#fff"; });

    nodeUpdate.select("text").style("fill-opacity", 1);

    // Transition exiting nodes to the parent's new position.
    var nodeExit = node.exit().transition()
        .duration(duration)
        .attr("transform", function(d) { return "translate(" + source.y + "," + source.x + ")"; })
        .remove();

    nodeExit.select("circle").attr("r", 20);
    nodeExit.select("text").style("fill-opacity", 0);

    // Update the links…
    var link = svg.selectAll("path.link")
        .data(links, function(d){ return d.target.id; });

    // Enter any new links at the parent's previous position.
    link.enter().insert("path", "g")
        .attr("class", "link")
        .attr("d", function(d){
            var o = {x: source.x0, y: source.y0};
            return diagonal({source: o, target: o});
        });

    // Transition links to their new position.
    link.transition()
        .duration(duration)
        .attr("d", diagonal);

    // Transition exiting nodes to the parent's new position.
    link.exit().transition()
        .duration(duration)
        .attr("d", function(d){
            var o = {x: source.x, y: source.y};
            return diagonal({source: o, target: o});
        })
        .remove();

    // Stash the old positions for transition.
    nodes.forEach(function(d){
        d.x0 = d.x;
        d.y0 = d.y;
    });
}



function computeRadius(d)
{
    if(d.children || d._children) return radius + (radius * nbEndNodes(d) / 10);
    else return radius;
}

function nbEndNodes(n)
{
    nb = 0;    
    if(n.children){
        n.children.forEach(function(c){ 
            nb += nbEndNodes(c); 
        });
    }
    else if(n._children){
        n._children.forEach(function(c){ 
            nb += nbEndNodes(c); 
        });
    }
    else nb++;

    return nb;
}

function click(d)
{
    if (d.children){
        d._children = d.children;
        d.children = null;
    } 
    else{
        d.children = d._children;
        d._children = null;
    }
    update(d);
}

function collapse(d){
    if (d.children){
        d._children = d.children;
        d._children.forEach(collapse);
        d.children = null;
    }
}
function expand(d){   
    var children = (d.children)?d.children:d._children;
    if (d._children) {        
        d.children = d._children;
        d._children = null;       
    }
    if(children)
      children.forEach(expand);
}


 expand(root); 


update(root);