我有一个优秀的强制定向布局(@eyaler http://bl.ocks.org/eyaler/1058611)和多个选项,我想隐藏一个特定的节点,使用jQuery或D3 + JavaScript,而不是直接从使用切换功能的d3代码。 (这是重要的,因为我在HTML代码的外部按钮)使用JavaScript或jQuery在D3.js中隐藏节点和子项
http://bl.ocks.org/carlos-andres/c3194c284763fde317b0
我试图命令等:
d3.selectAll("g#Avenger").attr("visibility", "hidden");
d3.select("g#Spathi").selectAll("*").attr("visibility", "hidden");
d3.select("g#Spathi").selectAll(this.children).attr("visibility", "hidden");
d3.select("g#Spathi + g").each(function(d){ console.log(d)});
它隐藏节点,但不是标签和路径。我也试过:
jQuery('g#Avenger').siblings().toggle();
它隐藏了所有其他节点。
UPDATE:我试着在这里使用解决方案:A d3.select... equivalent to jQuery.children()给@ @ Klaujesi它并不适用于我。我也查了另一篇文章,How to display and hide links and nodes when clicking on a node in D3 Javascript和我不能让这种做法很好的效果无论是。
检查图像;它隐藏节点G#Spathi但没有孩子和路径
你好@Klaujesi没关系,这工作得很好节点+文本,但儿童?我如何选择他们并隐藏?由于 –
要访问的孩子看看这个:http://stackoverflow.com/questions/19956602/a-d3-select-equivalent-to-jquery-children – Klaujesi
你好@Klaujesi I'm更新代码并运行你所建议的答案,不工作..谢谢 –