检测删除/移动时的节点是否与另一个节点相交 - mxgraph

发布于 2025-01-17 09:55:22 字数 537 浏览 5 评论 0原文

当您移动一个细胞时,我正在尝试检测细胞节点的任何部分是否与另一个单元格相交,并且其某些身体与另一个节点相交。我尝试编写自己的自定义mouseup函数,以便如果有一些交叉点,我会显示一个错误,说允许它。以下是我编写的代码。它不能完美地工作。有一次它运行良好的是,如果我在另一个节点上放置一个节点,而有时我将一个节点放在另一个节点的远处时,则无法正常工作。

const mouseUp = graph.graphHandler.mouseUp;
graph.graphHandler.mouseUp = function(...args) {
      const target = graph.getCellAt(args[1].graphX, args[1].graphY);
      if (target) {
        alert('not allowed');
        graph.graphHandler.reset();
      } else {
        mouseUp.apply(this, args);
      }
    };

I am trying to detect if any part of cell node intersects with another cell when u move a cell and some of its body intersects with another node. I tried to write my own custom mouseUp function such that if the there's some intersection, I'll display an error saying that its allowed. Below is the code i wrote. It doesn't work perfectly. one time when it works well is if I put a node on the center on another node but other times when I put a node on the far edge of another node it doesn't work.

const mouseUp = graph.graphHandler.mouseUp;
graph.graphHandler.mouseUp = function(...args) {
      const target = graph.getCellAt(args[1].graphX, args[1].graphY);
      if (target) {
        alert('not allowed');
        graph.graphHandler.reset();
      } else {
        mouseUp.apply(this, args);
      }
    };

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文