What you described can be achieved with a force simulation where nodes repel themselves. Here is an example in D3.
Creating a simulation encompasses an understanding of how it works, how to prepare data for it, and how to implement it; which are complex and broad topics that couldn't be fully explained in a single SO question. As a general direction, I recommend looking into the d3 documentation for force simulations. For searches, the keywords you might want to look for are "force simulation graph layout d3". There are several blog posts and examples that can help you implement with much more detail.
Diving a litte bit on your specific scenario, the main difference from your requirements from usual examples is the fixed node at the center. The force simulation works by assigning x
and y
properties to the nodes, but there are two properties fx
and fy
that you can manually set to fix the node's position.
When preparing the data for the simulation, find the node you want to be in the center and add the properties fx
and fy
to match the center of the screen. The force simulation will automatically position the other nodes around it, very similar to your second illustration.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…