chart = {
const root = d3.hierarchy(data);
const links = root.links();
const nodes = root.descendants();
const simulation = d3.forceSimulation(nodes)
.force("link", d3.forceLink(links).id(d => d.id).distance(0).strength(1))
.force("charge", d3.forceManyBody().strength(-80))
.force("x", d3.forceX())
.force("y", d3.forceY());
const svg = d3.create("svg")
.attr("viewBox", [-width / 2, -height / 2, width, height]);
const bg = svg.append("rect")
.attr("x", "-477")
.attr("y", "-400")
.attr("width", "100%")
.attr("height", "100%")
.attr("fill", "#1B2633");
const link = svg.append("g")
.attr("stroke", "#8954FF")
.attr("stroke-opacity", 1)
.selectAll("line")
.data(links)
.join("line");
const node = svg.append("g")
.attr("fill", "red")
.attr("stroke", "#fff")
.attr("stroke-width", 1)
.selectAll("circle")
.data(nodes)
.join("rect")
.attr("fill", "#1B2633")
.attr("stroke", "#596E87")
.attr("width", 8)
.attr("height", 13)
.attr("rx", 2)
.call(drag(simulation));
node.append("title")
.text(d => d.data.name);
simulation.on("tick", () => {
link
.attr("x1", d => d.source.x)
.attr("y1", d => d.source.y)
.attr("x2", d => d.target.x)
.attr("y2", d => d.target.y);
node
.attr("x", d => d.x-4)
.attr("y", d => d.y-7);
});
invalidation.then(() => simulation.stop());
return svg.node();
}