I'm currently delving into this code to grasp the inner workings of d3-force.
As I examine the variable nodes
, I am intrigued by how positions are assigned to them.
// Replace the input nodes and links with mutable objects for the simulation.
console.log(nodes); // Added by me
nodes = d3.map(nodes, (_, i) => ({id: N[i]}));
console.log(nodes); // Added by me
links = d3.map(links, (_, i) => ({source: LS[i], target: LT[i]}));
It's fascinating to see that after the d3.map
operation, the variable nodes
contains all the necessary parameters for forceSimulation, such as index
, x
, y
, vx
, vy
.
I suspect that the behavior is more related to how JavaScript executes the functions below it rather than d3 itself, but I haven't quite pinpointed how.
I also checked the output of N
, but it seems to only contain the expected id
values without any surprises.