0
私は端末でnodejsを使ってcytoscapejsを使って簡単なjavascriptを書いています。私の目的は、ノードとエッジリストとレイアウトが与えられたすべてのノードの位置を取得することです。私はコードの下に実行します。私は位置の結果を見るとCytoscapejs layputはすべてのノードに0を与えます
var cytoscape = require('cytoscape');
var cy = cytoscape({
elements: [ // list of graph elements to start with
{ // node a
data: { id: 'a' }
},
{ // node b
data: { id: 'b' }
},
{ // node b
data: { id: 'c' }
},
{ // node b
data: { id: 'd' }
},
{ // node b
data: { id: 'e' }
},
{ // node b
data: { id: 'f' }
},
{ // node b
data: { id: 'g' }
},
{ // node b
data: { id: 'h' }
},
{ // edge ab
data: { id: 'ab', source: 'a', target: 'b' }
},
{ // edge ab
data: { id: 'bc', source: 'b', target: 'c' }
},
{ // edge ab
data: { id: 'cd', source: 'c', target: 'd' }
},
{ // edge ab
data: { id: 'de', source: 'd', target: 'e' }
},
{ // edge ab
data: { id: 'ef', source: 'e', target: 'f' }
},
{ // edge ab
data: { id: 'fg', source: 'f', target: 'g' }
},
{ // edge ab
data: { id: 'gh', source: 'g', target: 'h' }
}
],
style: [ // the stylesheet for the graph
{
selector: 'node',
style: {
'background-color': '#666',
'label': 'data(id)'
}
},
{
selector: 'edge',
style: {
'width': 3,
'line-color': '#ccc',
'target-arrow-color': '#ccc',
'target-arrow-shape': 'triangle'
}
}
],
layout: {name: "cose",randomize: true}
});
cy.nodes().forEach(function(s){
console.log(s.position().x)
console.log(s.position().y)
});
、それはすべてのノードに0を与えます。他のタイプのレイアウトを使用すると、0以外の結果が得られます。レイアウトにcoseを正しく使用する方法は?ありがとうございました。
Cytoscapeが以前に非同期を実行していることがわかりませんでした。今私はそれを解決しました。 – Bharata