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

会有一股神秘感。 提交于 2019-12-04 12:36:33

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

For posterity, the code that will do this in cytoscape-automove

let nodeList = cy.nodes().nonorphans();
for (let i=0; i < nodeList.length; i++) {
        let n = nodeList[i];
        let parent = n.parent()[0];
        let family = parent.children();
        family.add(parent);

        this.cy.automove({
            nodesMatching: family,
            reposition: 'drag',
            dragWith: n
        });
    }
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!