How to lock the position of a cytoscape.js node within its parent node

匿名 (未验证) 提交于 2019-12-03 10:24:21

问题:

I want to lock the position of a node relative to its parent compound node, such that if I grab and drag the parent node, the child node moves with it, but the child is not individually grabbable. If I set the child to be ungrabbable and/or locked, then it doesn't move with its parent, but if I don't, it can be individually dragged, which I don't want. Can this be done?

Failing that, is there a way to programmatically grab/ungrab a node so that I can listen for a grab event and then grab the parent instead/as well?

回答1:

Compound grabbing/locking logic with children probably needs to be improved in general, but you should be able to achieve the effect you want today with the current version:

cy.nodes().nonorphans()   .on('grab', function(){ this.ungrabify(); })   .on('free', function(){ this.grabify(); }) ; 

This makes all nonorphan/child nodes not directly grabbable but still moveable with their parents.

Ref for improvements : https://github.com/cytoscape/cytoscape.js/issues/1074



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