1
我使用VivaGraphJS來創建我的圖形,它是動態的,並且在數據進入時不斷更新。問題是VivaGraph默認情況下沒有我需要的圓形佈局。VivaGraphJS中的圓形佈局
我碰到circular layout在cytoscape.js,我想移植到VivaGraph。我無法完全理解要做出哪些更改,以便擁有VivaGraph的端口。如果你能幫助我並引導我完成,那將會非常感激。謝謝:)
此外,這是我需要的算法,因爲十字架的數量對我無關緊要。
function CircularLayout(width, height)
{
this.width = width;
this.height = height;
}
/**
* Spreads the vertices evenly in a circle. No cross reduction.
*
* @param graph A valid graph instance
*/
CircularLayout.prototype.layout = function(graph)
{
/* Radius. */
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;
}
}