Reputation: 37
I have created a network diagram using python, networkx and pyvis. By default, the diagram changed visually each time I open / refresh it. So to stop that, I have added the following code
# Compute static positions for nodes
positions = nx.spring_layout(G, seed=42) # `seed` ensures reproducibility
# Add nodes to the PyVis network with fixed positions
for node, pos in positions.items():
x, y = pos[0] * 200, pos[1] * 200 # Scale positions to better fit the PyVis canvas
net.add_node(str(node), x=x, y=y, color="lightblue", size=10)
Also, I have below physics options because if I turn off physics it clutters and overlap the diagram and doesn't look good visually.
net.set_options("""
var options = {
"configure": {
"enabled": true,
"filter": ["physics"]
},
"physics": {
"enabled": true,
"solver": "barnesHut",
"barnesHut": {
"theta": 0.5,
"gravitationalConstant": -11500,
"centralGravity": 0,
"springLength": 300,
"springConstant": 0.04,
"damping": 0.1,
"avoidOverlap": 0
},
"stabilization": {
"enabled": true,
"iterations": 1000,
"fit": true
},
"minVelocity": 0.75,
"timestep": 1
}
}
""")
Now, the diagram remains the same visually no mater how many times I refresh or open it.
But, now the problem is whenever I select a node on the diagram it always quickly shrinks and expands just like something is dropped into the water. When it settles it is slightly changed (nodes and edges remain the same but appearance is little bit changed).
Has someone experienced a same situation I kindly seek a way to stop this effect.
Thank you!
Upvotes: 0
Views: 54