Cytoscape layouts - Handle locked nodes

女生的网名这么多〃 提交于 2019-12-11 14:57:36

问题


I am using vue-cytoscape to render a graph and navigate through a tree-like data structure.

My goal is to expand parent nodes and keep their position in the graph. I would like to simply add the new children nodes.

My approach is to lock current nodes, add the children and unlock the nodes.

this.cy.nodes().lock()
for(let d of data){
  this.cy.add(d)
}
this.cy.elements().layout(this.config.layout).run()
setTimeout(() => {this.cy.nodes().unlock()}, 2000) // Give some time for the layout to render before unlocking nodes.

The problem is that the layouts do not consider the locked state of the nodes. Only the new nodes are moved around, which is fine. But the layout is not respected. I am under the impression that the layout calculates a new position for all nodes, but then moves only nodes that are unlocked.

According to this GitHub issue, some layout algorithm should handle locked nodes. I am using the following layouts and none seem to consider locked nodes.

  • Cola
  • Fcose
  • Dagre
  • avsdf
  • grid
  • concentric

回答1:


Please try calling the layout function only on the added nodes:

var eles = cy.add(data);   // refer to http://js.cytoscape.org/#cy.add for adding nodes
eles.layout(this.config.layout).run();

If you don't want nodes to move when calling the layout function, you can exclude them from the rendering. While calling cy.add(), the function returns an object with every added element inside (see var eles = ... in the code).



来源:https://stackoverflow.com/questions/56926576/cytoscape-layouts-handle-locked-nodes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!