2016-08-20 52 views
1

我看着旭日图表 - 也就是从这个例子:D3炎爆 - 可以显示某些层

https://bl.ocks.org/kerryrodden/7090426

我想问的是有可能在D3 - 来控制的是响铃的次数所示。所以说我只想出现第二个戒指?

我注意到的代码

// For efficiency, filter nodes to keep only those large enough to see. 
var nodes = partition.nodes(json) 
     .filter(function(d) { 
      return (d.dx > 0.005); // 0.005 radians = 0.29 degrees 
}); 

我试图附加到这个东西沿着d.depth = 2行这部分但不工作:

// For efficiency, filter nodes to keep only those large enough to see. 
var nodes = partition.nodes(json) 
      .filter(function(d) { 
      if (d.depth = 2) { 
       return (d.dx > 0.005); // 0.005 radians = 0.29 degrees 
      } 
}); 

任何帮助将是赞赏。

谢谢。

回答

1

你很近,过滤器需要返回每个元素。尝试通过逻辑添加深度检查&&

// For efficiency, filter nodes to keep only those large enough to see. 
var nodes = partition.nodes(json) 
    .filter(function(d) { 
     return (d.dx > 0.005 && d.depth < 3); // 0.005 radians = 0.29 degrees 
}); 
+0

伟大的 - 那些作品 - 不知道为什么没有想到这一点。谢谢!! – userMod2

+0

如果我更新该变量来说'd.depth <5' - 我该如何刷新图表?有一个简单的方法吗? – userMod2