VivaGraphJS
VivaGraphJS copied to clipboard
Change constant layout to become circular layout
I'm trying to change the constant layout option to a circular layout which doesn't care about the number of crosses and just arranges the nodes in the form of a circle. The algo I'm using is:
var r = Math.min(this.width, this.height) / 2;
/* Where to start the circle. */ var dx = this.width / 2; var dy = this.height / 2;
/* Calculate the step so that the vertices are equally apart. _/ var step = 2_Math.PI / graph.vertexCount; var t = 0; // Start at "angle" 0.
for (var i = 0; i<graph.vertices.length; i++) { var v = graph.vertices[i]; v.x = Math.round(r_Math.cos(t) + dx); v.y = Math.round(r_Math.sin(t) + dy); t = t + step; }
I'm not able to figure out how to incorporate the algo into Viva so as to make it a circular layout. Any help is appreciated. :)