chart = {
const root = d3.hierarchy(data);
const links = root.links();
const nodes = root.descendants();
const cArray=["#F55D3E", "#76BED0", "#F7CB15"]
const simulation = d3.forceSimulation(nodes)
.force('center', d3.forceCenter(-30,0))
.force("link", d3.forceLink(links).id(d => d.id).distance(d=> d.source.height*70).strength(0.6))
.force("charge", d3.forceManyBody().strength(d=> -400*(d.height+1)))
.force("x", d3.forceX())
.force("y", d3.forceY(200))
const svg = d3.create("svg")
.attr("viewBox", [-width / 2, -height / 2, width, height])
.style("font", "16px sans-serif")
.style("background-color", "#fff");
const link = svg.append("g")
.attr("stroke", "#878E88")
.attr("stroke-opacity", 0.6)
.selectAll("line")
.data(links)
.join("line")
.attr("stroke-width", d =>d.source.height*d.source.height);
const node = svg.append("g")
.attr("fill", "currentColor")
.attr("stroke-linecap", "round")
.attr("stroke-linejoin", "round")
.selectAll("g")
.data(nodes)
.join("g")
.call(drag(simulation));
node.append("circle")
.attr("fill", d => cArray[d.height])
.attr("r", d=> (d.height+1)*5)
.attr("stroke", "grey")
.attr("stroke-width", 1)
node.append("text")
.attr("text-align","center")
.attr("x", 15)
.attr("fill", d=>"#444")
.text(d => d.data.name)
.clone(true).lower()
.attr("fill", "none")
.attr("stroke", "white")
.attr("stroke-width", 3);
simulation.on("tick", () => {
nodes[0].vx= -(nodes[0].x+250);
nodes[0].vy = -(nodes[0].y);
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("transform", d => `translate(${d.x},${d.y})`)
.attr("cx", d => d.x)
.attr("cy", d => d.y);
});
invalidation.then(() => simulation.stop());
return svg.node();
}