D3可折叠树:树的可滚动容器

时间:2016-02-05 12:24:00

标签: javascript html css d3.js svg

我正在使用D3可折叠树。它的大小动态增加。我可以使用div标记及其class来使其可滚动吗?因此,当树的大小增加时,它可以滚动。

http://jsfiddle.net/bSQ8U/159/是问题的例子。这时我扩展了所有节点。我将无法看到完整的树。

1 个答案:

答案 0 :(得分:3)

您可以设置svg在扩展/折叠时的高度。

  window.setTimeout(function() {
    var max = d3.max(d3.selectAll(".node")[0], function(g) {
      return d3.transform(d3.select(g).attr("transform")).translate[1];
    });
    //set the max of the group
    d3.select("svg").attr("height", max + 100)
    console.log(max)
  }, 800)//execute after 800 milliseconds after the update.

工作代码here

希望这有帮助!