apply method
Applies the force to the simulation.
Implementation
@override
void apply(ForceSimulation simulation) {
final nodes = simulation.nodes;
final n = nodes.length;
if (n == 0) return;
// Calculate center of mass
double sx = 0, sy = 0;
for (final node in nodes) {
sx += node.x;
sy += node.y;
}
sx = (sx / n - x) * strength;
sy = (sy / n - y) * strength;
// Move nodes toward center
for (final node in nodes) {
node.x -= sx;
node.y -= sy;
}
}