Deno
Deno

Reputation: 137

Always display network nodes in a ring in Vis.js

I tried reading the documentation but couldn't find what I was looking for. This is what I want, how can I do it? Thank you.

enter image description here

Upvotes: 1

Views: 1010

Answers (1)

stdob--
stdob--

Reputation: 29172

You can use the initRedraw event to calculate and to set the node coordinates for a circular layout:

var radius = 150
network.on('initRedraw', function () {
  var ids = data.nodes.getIds()
  var d = 2 * Math.PI / ids.length // Angular pitch
  ids.forEach(function(id, i) {
    var x = radius * Math.cos(d * i)
    var y = radius * Math.sin(d * i)
    network.moveNode(id, x, y)
  })
})

https://jsfiddle.net/L6s6hjwz/

Upvotes: 1

Related Questions