Burak Cetin
Burak Cetin

Reputation: 53

vis.js fixed length edges

Is it possible to give an edge a fixed length? Even if I set the length of individual edges, physic engine changes it.

I am trying to visualize 3 clusters, each with couple hundred of nodes. There is an option to aggregate the cluster into couple of nodes. I want to connect these aggregated nodes with really short edges and give these nodes high mass so they will repulse other clusters like they were doing when they had hundreds of nodes.

Upvotes: 4

Views: 8280

Answers (2)

Harry Wood
Harry Wood

Reputation: 2351

It seems like the answer to this question these days is YES! The network/edges visjs.org docs describe a "length" option:

"The physics simulation gives edges a spring length. This value can override the length of the spring in rest."

So when you're setting up your edges you might do something like this to make an extra long edge:

myEdges.push({from:'nodeid1', to:'nodeid2', length:300});

The length by default is about 95 I think, so a length of 300 would be about three times the normal.

If you want to change the default edge length (not including any which you've set explicitly on edges) then this is the 'springLength' of the network, so pass an option while making the network:

var network = new vis.Network(container, data,
  {"physics": {"barnesHut": {"springLength":100, "springConstant": 0.04}}}
);

The physics engine might constrain things and sort of hide the changes you're trying to see, so you may also need to tweak things like 'springConstant'.

Upvotes: 6

Jos de Jong
Jos de Jong

Reputation: 6809

It's not possible to set a fixed length. You can play around though with the default springLength and springConstant though, checkout the docs on physics:

http://visjs.org/docs/network/physics.html

Upvotes: 0

Related Questions