{
const simulation = d3.forceSimulation(acini)
.force("charge", d3.forceManyBody().strength( grosso? -200: -690))
.force("link", d3.forceLink(viticci).distance( grosso? 20: 100))
.force("x", d3.forceX())
.force("y", d3.forceY());
const groups = ["viticci","acini","punte"]
const g = d3.select(essevvuggi)
.attr("width", width)
.attr("height", height)
.attr("viewBox", [-width / 2, -height / 2, width, height])
.selectAll("g")
.data(groups, d => d)
.join("g")
const links = g.filter( d => d == "viticci")
.attr("class","viticcio")
.selectAll("path")
.data(viticci)
.join("path")
.attr("id",function(d){return"("+d.source.id+","+d.target.id+")"})
.attr("marker-end","url(#punta)")
.attr("marker-start",function(d){return "url('#w("+d.source.id+","+d.target.id+")')";});
const nodes = g.filter( d => d == "acini" )
.attr("class","uva_acerba")
.selectAll("circle")
.data(acini)
.join("circle")
.attr("r", grosso? 35: 15)
.attr("id",function(d){return d.id;})
.call(drag(simulation));
g.filter( d => d == "punte" ).selectAll("defs").data([1]).join("defs")
.selectAll("marker")
.data(["punta","punta_B","punta_T","punta_to","punta_F","punta_C"])
.enter().append("marker")
.attr("id", function(d) { return d; })
.attr("viewBox", "0 -5 10 10")
.attr("refX", 15)
.attr("refY", -1.5)
.attr("markerWidth", 5)
.attr("markerHeight", 5)
.attr("orient", "auto")
.append("path")
.attr("d", "M0,-5L10,0L0,5")
simulation.on("tick", () => {
links.attr("d", d => {
const dx = d.target.x - d.source.x,
dy = d.target.y - d.source.y,
dr = Math.sqrt(dx * dx + dy * dy);
return "M" + d.source.x + "," + d.source.y + "A" + dr + "," +
dr + " 0 0,1 " + d.target.x + "," + d.target.y;
});
nodes.attr("transform", d => "translate(" + d.x + "," + d.y + ")");
});
invalidation.then(() => simulation.stop());
}