我试图选择/取消选择单击的行(链接)。但我已经有鼠标悬停功能,它应该不同于鼠标悬停,当我选择一条线,该线的颜色需要改变,它需要绘制一个饼图,取消选择应该可用的点击。通过点击d3选择/取消选择
我有什么:
nodeenter.on("mouseover", function(d){
console.log(d);
d3.select(this).attr("fill", "yellow");
return tooltip.style("visibility", "visible").text("This node's id is: " + d.id + " and " + "Name: " + d.name);})
.on("mousemove", function(){
return tooltip.style("top",
(d3.event.pageY-10)+"px").style("left",(d3.event.pageX+10)+"px");})
.on("mouseout", function(d){
d3.select(this).attr("fill", "rgb(0, 0, " +(d*10) + ")");
return tooltip.style("visibility", "hidden");});
link.on("mouseover", function(d){
console.log(d)
d3.selectAll('.'+d.id).style('stroke','aqua');
return tooltip.style("visibility", "visible").text("This line's id is: " + d.id + " and " + "Name: " + d.name);})
.on("mousemove", function(){return tooltip.style("top",
(d3.event.pageY-10)+"px").style("left",(d3.event.pageX+10)+"px");})
.on("mouseout", function(d){
d3.selectAll('.'+d.id).style('stroke','black');
return tooltip.style("visibility", "hidden");});
//to select
link.on("click", function(d){
if (!d3.select(this).classed("selected")){
d3.select(this).classed("selected", true)
d3.select(this).style("stroke","red");
}else{
d3.select(this).classed("selected", false);
d3.select(this).style("stroke","black");
}
});
上传你的代码的一些平台像小提琴请。 –
当然!即将发布 –
@DavidGuan在js小提琴中可以看起来很荒谬。基本上我想要做的是通过单击它并以相同的方式取消选择它在两个节点之间选择一条线。你能帮我吗 ? –