chart = {
const root = tree(data);
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height ]);
const g = svg.append("g")
.attr("font-family", "sans-serif")
.attr("font-size", 10)
.attr("transform", `translate(${width/2},${0.1*height})`);
const link = g.append("g")
.attr("fill", "none")
.attr("stroke", "#555")
.attr("stroke-opacity", 0.4)
.attr("stroke-width", 1.5)
.selectAll("path")
.data(root.links())
.join("path")
.attr("d", d3.linkVertical()
.x(d => d.x)
.y(d => d.y));
const node = g.append("g")
.attr("stroke-linejoin", "round")
.attr("stroke-width", 3)
.selectAll("g")
.data(root.descendants())
.join("g")
.attr("transform", d => `translate(${d.x},${d.y})`);
node.append("rect")
.attr("fill", d => d.children ? "#555" : "#999")
.attr("width", root.dx * 0.9)
.attr("height", root.dx* 0.6)
.attr("transform", d => `translate(${-root.dx*0.45},${-root.dy*0.3})`);
return svg.node();
}