chart = {
const width = 800;
const height = 800;
const radius = 5
const links = structuredClone(plotData.links);
const nodes = structuredClone(plotData.nodes);
const simulation = d3.forceSimulation(nodes).alphaDecay(0.0001)
.force('boxing', boxingForce)
.force("link", d3.forceLink(links).id(d => d.id).strength(1.5))
.force("charge", d3.forceManyBody().strength(()=>-15).distanceMax(75))
.force("center", d3.forceCenter(width / 2, height / 2))
.force('collision',d3.forceCollide().radius((d) => radius))
.on("tick", ticked);
function blockNodeCoordinates(
radius,
node,
svgSize
) {
return node;
}
function boxingForce() {
nodes.forEach((node) => {
node = blockNodeCoordinates(2*radius, node, {width: width, height: height});
});
}
const svg = d3.create("svg")
.attr("width", width)
.attr("height", height)
.attr("viewBox", [0, 0, width, height])
.attr("style", "width:auto; max-width:100%; background-color: #f0f0f0");
const node = svg.append("g")
.attr("stroke", "#000")
.attr("stroke-width", 1)
.selectAll()
.data(nodes)
.join("circle")
.attr("r", radius)
.attr("fill", d => 'black')
function ticked() {
node
.attr("cx", d => d.x)
.attr("cy", d => d.y);
}
node.call(d3.drag()
.on("start", dragstarted)
.on("drag", dragged)
.on("end", dragended));
function dragstarted(event) {
if (!event.active) simulation.alphaTarget(0.3).restart();
event.subject.fx = event.subject.x;
event.subject.fy = event.subject.y;
}
function dragged(event) {
event.subject.fx = event.x;
event.subject.fy = event.y;
}
function dragended(event) {
if (!event.active) simulation.alphaTarget(0);
event.subject.fx = null;
event.subject.fy = null;
}
invalidation.then(() => simulation.stop());
return svg.node();
}