chart = {
var svg = d3.create("svg").attr("width", width).attr("height", height);
var force = d3
.forceSimulation(dataset.nodes)
.force("charge", d3.forceManyBody().strength(-10))
.force("link", d3.forceLink(dataset.edges))
.force("center", d3.forceCenter(width / 2, height / 2))
.force("boundary", forceBoundary(3, 3, width, height));
var colors = d3.scaleOrdinal(d3.schemeCategory10);
var edges = svg
.selectAll("line")
.data(dataset.edges)
.join("line")
.style("stroke", "#ccc")
.style("stroke-width", 1);
const mouseover = function (event, d) {
tooltip.style("opacity", 1);
};
const mouseleave = function (event, d) {
tooltip.transition().duration(200).style("opacity", 0);
};
var nodes = svg
.selectAll("circle")
.data(dataset.nodes)
.join("circle")
.attr("r", (d) => d.value / 4)
.style("fill", "#333")
.on("mouseover", tooltip_in)
.on("mousemove", tooltip_in)
.on("mouseout", tooltip_out)
.call(drag(force));
force.on("tick", function () {
edges
.attr("x1", function (d) {
return d.source.x;
})
.attr("y1", function (d) {
return d.source.y;
})
.attr("x2", function (d) {
return d.target.x;
})
.attr("y2", function (d) {
return d.target.y;
});
nodes
.attr("cx", function (d) {
return d.x;
})
.attr("cy", function (d) {
return d.y;
});
});
invalidation.then(() => force.stop());
return svg.node();
}