如何使用 cy.load 设置 cytoscape.js 中节点的起始位置?

use*_*233 4 javascript cytoscape cytoscape-web cytoscape.js

我正在尝试手动设置节点的起始位置,但从 JSON 结构加载它们。如果我将位置放在“节点”结构中,它就可以工作,但是我试图添加一个名为“位置:”的单独结构,我认为它应该工作?请参阅下面的结构示例。

var graphdata = { nodes: [ { data: { id: 'j', name: 'Jerry', width: 20, height: 20 ,     shape: 'rectangle' }},
                       { data: { id: 't', name: 'Tom', width: 20 , height: 20, shape: 'circle' } },
                       { data: { id: 'm', name: 'Mary', width: 20 , height: 20, shape: 'circle' } } ,
                       { data: { id: 'b', name: 'Bob', width: 20 , height: 20, shape: 'circle' } } ],

              edges: [
                      { data: { source: 'j', target: 't', faveColor: '#6FB1FC', strength: 90 } },
                      { data: { source: 't', target: 'm', faveColor: '#6FB1FC', strength: 90 } },
                      { data: { source: 'm', target: 'b', faveColor: '#6FB1FC', strength: 90 } } ],

             positions: [ { j: { x:100,y:100 } }, 
                          { t: { x:100,y:200 } } ]
Run Code Online (Sandbox Code Playgroud)

后来我调用 cy.load(graphdata)。

节点和边缘显示良好,但位置似乎根本不受影响。

我还加载了预设布局。

谢谢。

max*_*anz 6

这是 Cytoscape Web 还是 Cytoscape.js?

在 Cytoscape.js 中,

  • 您必须指定每个元素中的位置或使用预设布局。 (2认同)