{
const nodes= network.nodes.map( d=> ({...d})),
links= network.links.map( s=> ({
source: s.source.id,
target: s.target.id,
value: s.value
}));
const svg= d3.create("svg").attr("viewBox", [0 , 0 , width, height]);
const lines= svg
.selectAll("line")
.data(links)
.join("line")
.style("stroke", "#ccc")
.style("stroke-opacity", l => {
console.log(l, opacity(l.value));
return opacity(l.value);
});
const text= svg.selectAll("text")
.data(nodes)
.join("text")
.attr("fill", "#333")
.style("font-size", d => size( d.value) + "pt")
.style("fill", d => color(d.cluster))
.text( d => d.id);
const ticked= () =>{
lines
.attr("x1", d => d.source.x)
.attr("y1", d=> d.source.y)
.attr("x2", d=> d.target.x)
.attr("y2", d=> d.target.y);
text.attr("x", d => d.x)
.attr("y", d => d.y);
}
const simulation= d3.forceSimulation(nodes)
.force("charge", d3.forceManyBody().strength(-20))
.force("link", d3.forceLink(links).id( d => d.id))
.force("center", d3.forceCenter( width/ 2, height/ 2) )
.force("boundary", forceBoundary(3, 3 , width, height))
.on("tick", ticked);
text.call(drag(simulation));
return svg.node();
invalidation.then(() => simulation.stop());
}