chart = {
const width = 200;
const height = 140;
const svg = d3.select(DOM.svg(width, height))
.style("width", "100%")
.style("height", "auto");
const marker = svg.append('defs')
.append("marker")
.attr("id", "arrowhead")
.attr("markerWidth", 8)
.attr("markerHeight", 8)
.attr("refX", 6)
.attr("refY", 3)
.attr("orient", "auto")
.append('path')
.attr("d", "M 0 0 L 6 3 L 0 6")
.attr("fill", "none")
.attr("stroke", "grey")
.attr("stroke-linejoin", "miter-clip");
const dr = rayon / 2;
const decalage = rayon + 4;
const formes = svg.append("svg:g")
.attr("id", "forme");
formes
.append("rect")
.attr("x", 0)
.attr("y", 0)
.attr("width", width)
.attr("height", height)
.attr("fill", "none")
.attr("stroke", "black")
.attr("stroke-width", 1);
// Points attirés
const pt = formes.selectAll("circle").data(pos).enter()
.append("circle")
.attr("cx", function(d) {return d.x;})
.attr("cy", function(d) {return d.y;})
.attr("r", rayon)
.attr("fill", "black")
.attr("stroke-width", 1)
.attr("stroke", "black")
.transition()
.on("start", function repeat() {
d3.active(this)
.transition().duration(vitesse)
.attr("fill", "white")
.attr("stroke", "grey")
.transition().duration(0)
.attr("fill", "black")
.attr("stroke", "black")
.on("end", repeat);
});
// Pôle attractif
const ptpole = formes
.append("circle")
.attr("cx", pole.x)
.attr("cy", pole.y)
.attr("r", rayon)
.attr("fill", "white")
.attr("stroke-width", 1)
.attr("stroke", "black")
.transition()
.on("start", function repeat() {
d3.active(this)
.transition().duration(vitesse)
.attr("fill", "black")
.attr("stroke", "black")
.transition().duration(0)
.attr("fill", "white")
.attr("stroke", "grey")
.on("end", repeat);
});
// Flèches en tiretés avec pointe
const LFleche = [];
for (const dest in pos) {
LFleche.push(offset(pos[dest], pole, decalage));
}
const fleche = formes.selectAll("line").data(pos).enter()
.append("line")
.attr("x1", function(d,i) {return LFleche[i][0].x;})
.attr("y1", function(d,i) {return LFleche[i][0].y;})
.attr("x2", function(d,i) {return LFleche[i][1].x;})
.attr("y2", function(d,i) {return LFleche[i][1].y;})
.attr("stroke-width", 1)
.attr("stroke", "grey")
.attr("stroke-dasharray", "4, 2")
.attr("marker-end", "url(#arrowhead)");
// Points qui se déplacent
const pm = formes.selectAll("div").data(pos).enter()
.append("circle")
.attr("cx", function(d) {return d.x;})
.attr("cy", function(d) {return d.y;})
.attr("r", rayon)
.attr("fill", "black")
.transition()
.on("start", function repeat() {
d3.active(this)
.transition().duration(vitesse)
.attr("cx", pole.x)
.attr("cy", pole.y)
.transition().duration(0)
.attr("cx", function(d) {return d.x;})
.attr("cy", function(d) {return d.y;})
.on("end", repeat);
});
//Dessin par rendu
return svg.node();
}