chart = {
const svg = d3
.create("svg")
.attr("width", width)
.attr("height", height)
.style("border", "1px solid lightgrey");
const links = svg
.append("g")
.attr("stroke", "lightgrey")
.attr("stroke-width", 1)
.selectAll("line")
.data(graph.links)
.join("line");
const nodes = svg
.append("g")
.attr("fill", "steelblue")
.selectAll("circle")
.data(graph.nodes)
.join("circle")
.attr("r", 5);
nodes.append("title").text((d) => d.id);
setupDrag(svg, nodes, simulation);
function update() {
nodes.attr("cx", (v) => v.x).attr("cy", (v) => v.y);
links
.attr("x1", (e) => e.source.x)
.attr("y1", (e) => e.source.y)
.attr("x2", (e) => e.target.x)
.attr("y2", (e) => e.target.y);
}
simulation.on("tick", update);
update();
return svg.node();
}