通过在d3中单击来选择/取消选择
selecting/deselecting by clicking in 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");
}
});
结果如下:https://jsfiddle.net/xcn35ycm/4/
我在链接上绑定了一个点击函数。
links.on("click", function(d){
if (!d3.select(this).classed("selected") ){
d3.select(this).classed("selected", true)
d3.select(this).transition().attr("stroke","red");
}else{
d3.select(this).classed("selected", false);
d3.select(this).transition().attr("stroke","black");
}
并更新鼠标输出功能
.on("mouseout", function(d){
if(!d3.select(this).classed("selected") ){
d3.selectAll('.'+d.id).style('stroke','black');
return tooltip.style("visibility", "hidden");
}
});
相关文章:
- 通过在d3中单击来选择/取消选择
- 复选框选择/取消选择触发器第一次工作,但在随后的尝试中失败
- 选择/取消选择复选框,该复选框未按预期使用.coneast('table').find('tbo
- 在angular.js中选择取消选择树结构
- Javascript函数用于选择/取消选中radgrid标头模板中的所有复选框
- 一个变量,多个复选框选择/取消选择 jQuery
- 基于下拉选择的单选选择/取消选择
- 选择/取消选择花式树插件上所有具有相同ID的节点
- 选择2 取消选择所有值
- 使用 JQuery 多次选择取消选中复选框
- jQuery:需要知道在变更事件中选择/取消选择了哪个选项
- 带有选择/取消选择和汇总选项的表格
- 在按钮上切换类(选择/取消选择)
- 关闭浏览器选项卡时,如何在确认框中默认选择“取消”
- jqxTreeGrid如果我单击一行中的特定单元格,则禁用对该行的选择/取消选择
- 如何使用 JavaScript/jQuery 选择/取消选中复选框
- 即使用户选择“取消”,我如何保留FileDialog输入值?(ASP.Net/Javascript)
- 使用JQuery取消选择/取消聚集输入字段
- 如何将JavaScript应用于引导程序btn组以选择/取消选择子按钮元素
- 如何选择/取消选择所有克隆节点