2015-09-01 33 views
3

我有一个优秀的强制定向布局(@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但没有孩子和路径

enter image description here

回答

2

您有<tex><g>元素:

<g id="Drone" class="node" ... 
    <path d="M-8.378872.....city: 1;"></path> 
</g> 
<text dy=".35em" dx="9.45 .... city: 1;">&ensp;Drone</text> 

必须是:

<g id="Drone" class="node" ... 
    <path d="M-8.378872.....city: 1;"></path> 
    <text dy=".35em" dx="9.45 .... city: 1;">&ensp;Drone</text> 
</g> 

使<text><g>依赖

+0

你好@Klaujesi没关系,这工作得很好节点+文本,但儿童?我如何选择他们并隐藏?由于 –

+0

要访问的孩子看看这个:http://stackoverflow.com/questions/19956602/a-d3-select-equivalent-to-jquery-children – Klaujesi

+0

你好@Klaujesi I'm更新代码并运行你所建议的答案,不工作..谢谢 –