2016-02-05 81 views
1

我正在使用D3可摺疊樹。它的大小會動態增加。我可以使用div標籤及其class使其可滾動嗎?所以當樹的大小增加時它可以滾動。D3可摺疊樹:樹的可滾動容器

http://jsfiddle.net/bSQ8U/159/是問題的例子。在這裏,當我展開所有節點。我將無法看到完整的樹。

+0

可能是此鏈接很有用。 http://bl.ocks.org/CrandellWS/ca7e6626c9e6b1413963 – Gilsha

+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

希望這有助於!

+0

G8 Cyril非常感謝你......我一直在尋找它...... –