我正在尝试手动设置节点的起始位置,但从 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 } } ]
稍后我打电话 cy.load(图形数据)。
节点和边显示正常,但位置似乎完全没有受到影响。
我还加载了预设布局。
谢谢。
最佳答案
这是 Cytoscape Web 还是 Cytoscape.js?
在 Cytoscape.js 中,
- 只需在每个元素中指定 init 的位置 (http://cytoscape.github.io/cytoscape.js/#core/initialisation),或者
- 在预设布局选项中指定位置并在初始化时使用该布局 (http://cytoscape.github.io/cytoscape.js/#core/initialisation)。
关于javascript - 如何使用 cy.load 设置 cytoscape.js 中节点的起始位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19344355/