如何锁定cytoscape.js节点在其父节点内的位置 [英] How to lock the position of a cytoscape.js node within its parent node

查看:360
本文介绍了如何锁定cytoscape.js节点在其父节点内的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想锁定一个节点相对于其父复合节点的位置,这样,如果我抓住并拖动父节点,子节点将随之移动,但子节点无法单独抓取。如果我将孩子设置为无法抓握和/或锁定,则它不会与父对象一起移动,但是如果我不这样做,则可以单独拖动它,这是我不希望的。可以做到这一点吗?

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?

推荐答案

带有孩子的复合抓取/锁定逻辑可能总体上需要改进,但是您应该能够实现使用当前版本,今天要获得的效果:

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.

改进参考: https://github.com。 com / cytoscape / cytoscape.js / issues / 1074

这篇关于如何锁定cytoscape.js节点在其父节点内的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆