Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/fsharp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 禁用在cytoscape.js中的区域外拖动节点_Javascript_Cytoscape.js - Fatal编程技术网

Javascript 禁用在cytoscape.js中的区域外拖动节点

Javascript 禁用在cytoscape.js中的区域外拖动节点,javascript,cytoscape.js,Javascript,Cytoscape.js,我正在使用cytoscape.js 我允许用户拖动节点,但现在也可以将节点拖动到“画布”之外 我查看了上的选项,但不知道如何确保节点不能离开可见区域。尝试自动移动扩展: 它允许您为节点位置设置规则,例如在当前视口或指定区域内进行约束。尝试自动移动扩展: 它允许您为节点位置设置规则,例如在当前视口或指定区域内进行约束。我知道这是很久以前的事了,但今天我遇到了同样的问题,这是我的解决方案,只需将节点移回 cy.on('mouseup', function (e) { let tg = e.t

我正在使用cytoscape.js

我允许用户拖动节点,但现在也可以将节点拖动到“画布”之外


我查看了上的选项,但不知道如何确保节点不能离开可见区域。

尝试自动移动扩展:


它允许您为节点位置设置规则,例如在当前视口或指定区域内进行约束。

尝试自动移动扩展:


它允许您为节点位置设置规则,例如在当前视口或指定区域内进行约束。

我知道这是很久以前的事了,但今天我遇到了同样的问题,这是我的解决方案,只需将节点移回

cy.on('mouseup', function (e) {
    let tg = e.target;
    if (tg.group != undefined && tg.group() == 'nodes') {
        let w = cy.width();
        let h = cy.height();
        if (tg.position().x > w) tg.position().x = w;
        if (tg.position().x < 0) tg.position().x = 0;
        if (tg.position().y > h) tg.position().y = h;
        if (tg.position().y < 0) tg.position().y = 0;
    }
})

我知道这是很久以前的事了,但今天我遇到了同样的问题,这是我的解决方案,只需将节点移回

cy.on('mouseup', function (e) {
    let tg = e.target;
    if (tg.group != undefined && tg.group() == 'nodes') {
        let w = cy.width();
        let h = cy.height();
        if (tg.position().x > w) tg.position().x = w;
        if (tg.position().x < 0) tg.position().x = 0;
        if (tg.position().y > h) tg.position().y = h;
        if (tg.position().y < 0) tg.position().y = 0;
    }
})

核心库中是否有任何东西可以避免拖到库外。核心库中是否有任何东西可以避免拖到库外。