I am a little bit lost in the way to initialize a graph layout.
I have forked the Sticky Force Layout / D3 | Observable
and computed my own version.
The problem is that the behaviour is not the same at the initialization and when I rerun the cell where the graph layout is produced.
The visibility of labels of the connected nodes are not set properly when a click event is used on a node. And the coAuthors variable is empty.
Once rerun the cell with the svg.nodes(), the behaviour is correct (labels of connected nodes are visible), the coAuthors array set correctly.
I must also admit that the yield svg.nodes();is not clear.
Another point when you load the notebook for the first time is that the variable coAuthors is an empy array whereas it should set properly.
That what is heppening when I run the cell.
I have captured what is shown when I first load the notebook, then what happens when I run the cell that defines the variable coAuthors.
Once run, the array is no more empty (what I expect). Why it is empty when I load the notebook the first time ?
This is what I do not understand.
I don’t quite understand the first issue you are facing.
But after playing with your notebook a bit, the second issue where you don’t see new coAuthors until rerunning cell manually, is because the cell depends on json.links, which doesn’t get updated – the objects inside the array does, but not the array itself.
Without diving deeper, I think you potentially can fix this by:
at where you update objects in json.links, return a new array for json.links, instead of mutating/pushing/poping objects from the array itself. Like instead of json.links.push(<new obj>), do json.links = [...json.links, <new obj>]
at a variable that mutates with your change to objects in json.links, and then include that variable in the coAuthors cell, too, such that the object change triggers the coAuthors cell change, too.