uj5u.com熱心網友回復:
讓我們來解決這個問題,你需要首先知道你的內容的邊界框,然后調整svg的大小。要做到這一點,在這種特殊的情況下,你只需要看一下盒子或節點,而可以忽略鏈接。
考慮到這一點,你可以在你的renderRelationshipGraph函式中填充Nodes后進行以下操作,并回傳計算值:
。
function renderRelationshipGraph(data) {
/ ...
var bbox = Nodes.reduce(function (max, d)
{
var w = d.x boxWidth;
var h = d.y boxHeight;
if (w > max[0]) {max[0] = w}。
if (h > max[1]) {max[1] = h}。
return max
}, [0,0])
return bbox
}
然后在主代碼中修改,用它來更新svg的高度和寬度:
。svg = d3.select("#tree"/span>)。 append("svg")
.attr("width", width)
.attr("height", height)。
svg.append("g") 。
var bbox = renderRelationshipGraph(data)。
svg.attr("width", bbox[0] )
.attr("height", bbox[1] )。)
你可以添加一個過渡,并限制高度,但這能滿足你的要求,最終結果非常大。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/320649.html
標籤:
上一篇:在一個Markdown檔案中參考一個vscode擴展名
下一篇:d3散點圖示簽


