【问题标题】:D3 Collapsible tree: Scrollable container for treeD3 可折叠树:树的可滚动容器
【发布时间】:2016-02-05 12:24:00
【问题描述】:

我正在使用 D3 可折叠树。并且它的大小动态增加。我可以使用div 标签及其class 使其可滚动吗?这样当树的大小增加时,它就可以滚动了。

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

【问题讨论】:

  • 这个链接可能有用。 bl.ocks.org/CrandellWS/ca7e6626c9e6b1413963
  • 不,画布的大小在这里是固定的。当我们展开所有节点时,它会合并。如果树的大小增加,我想通过滚动查看完整的树。

标签: javascript html css d3.js svg


【解决方案1】:

您可以在 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

希望这会有所帮助!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-03-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多