almende / vis

⚠️ This project is not maintained anymore! Please go to https://github.com/visjs
7.85k stars 1.48k forks source link

Prevent nodes from moving on Dataset.update #4206

Closed cmflynn closed 5 years ago

cmflynn commented 5 years ago

I have a network graph which is in a hierachical layout with physics: true to initially space the nodes. After its been drawn, i disable physics via the "stabilizationIterationsDone" event. At this point it looks like this: image

Next, I run a function in the background which builds a new Dataset of nodes(this is only to add an extra string to the label), and then i update via Dataset.update(). Now it looks like this: image

This squashes all the nodes together which can only be fixed by either calling network.stabilize() or by leaving physics: true, so it will re stabilize automatically.

My question is, is this expected behavior? I really want the layout to remain the same after I update the labels of these nodes to the user doesn't see the entire network redraw.

I'm using Chrome Version 70.0.3538.110 (Official Build) (64-bit).

xeembio commented 5 years ago

Having the same issue, I just updated the Dataset of VIS NETWORK using

network.setData({nodes:nodes, edges:edges});

and everything is redrawn again. This should not happen. VisJS is very easy and good but this feature is a must.

mojoaxel commented 5 years ago

Is there any activity in visjs to add this kind of feature?

Yes. If physics is disabled the layout doesn't get recalculated automatically. The best way is just to call network.stabilize().

I really want the layout to remain the same after I update the labels of these nodes to the user doesn't see the entire network redraw.

You could go through all your nodes and save the x,y position of each node and than reset the positions the physics-engine calculated after changing node. As I see it the network can not know what you changes so it needs to be stabilized again.