2015-02-07 384 views
4

我想在指定位置添加節點。我開始試圖在同一位置(x = 0,Y = 0),像這樣添加兩個節點:如何在Cytoscape.js的指定位置添加節點?

$(document).ready(function() { 

var cy = cytoscape({ 
    container: document.getElementById('cy'), 
}); 

cy.add([ 
    { group: "nodes", data: { id: "n0" }, position: { x: 0, y: 0 } }, 
    { group: "nodes", data: { id: "n1" }, position: { x: 0, y: 0 } }, 
]); 

}); 

,我估計它給我看兩個節點在同一位置,一個比其他。但結果非常出乎意料。以下是我的了:

enter image description here

事實上,節點的位置是一樣的,不管我指定哪些x和y的值。我也試過renderedPosition而不是position,但無濟於事。

我正在尋找Cytoscape文檔以瞭解如何實現我想要的功能,但我還沒有能夠提出解決方案。

回答

7

明白了。我忘了指定必須使用預設佈局。添加以下內容:

layout: { 
    name: 'preset' 
}, 

到cy對象,它的工作原理。

+0

變種CY = Cytoscape的({ \t \t \t \t容器:的document.getElementById( 'CY'), \t \t \t \t準備就緒:函數(){的console.log( '準備就緒');}, \t \t \t \t佈局:{ \t \t \t \t \t名: '預置' \t \t \t \t} \t \t \t}); – jonprasetyo 2015-06-16 07:31:44

+0

@AkshayDamle:在任何其他人都能找到答案之前+1。 :) – 2015-12-29 00:19:16

相關問題