在D3中单击鼠标即可显示/隐藏元素

用户名

我试图使该框在您单击节点时出现,然后在您单击该节点时消失。现在,它从一开始就显示出来,当您单击时它不会消失。这是JSFiddle

我试图以为编辑在这里某处进行,但我一生都无法弄清楚。我也检查了其他相关问题,但是它们有不同的特定问题。

 var node = svg.selectAll(".node")
  .data(data.nodes)
.enter().append("g")
  .attr("class", "node")
  .on("mouseover", mouseover)
.on("mouseout", mouseout)
 .on("click", function(d) {
  text = "Generic Text Here: " + d.name;
      d3.selectAll(".infobox")  
    //.append("rect")
    //.attr("x", 70)
    //.attr("y", 5)
    //.attr("height", 100)
    //.attr("width", 200) 
    //.select("text")
    .select("a")
    .attr("xlink:href", text) 
    .selectAll("text").text(text)})  
  .call(force.drag);

谢谢谢谢

维诺德·路易(Vinod Louis)

除了隐藏/显示之外,我想您还需要处理以下情况:单击一个节点,然后单击显示的框,然后单击另一个节点,则该框应与该节点数据一起可见

  if(this.getAttribute("ind") == prev && document.getElementById("plot").style.display == 'block'){
        document.getElementById("plot").style.display = 'none';
    }else{
    document.getElementById("plot").style.display = 'block';}
    prev = i;

看到这个小提琴http://jsfiddle.net/nw7g157c/9/

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章