[antv x6] 限制节点/边是否可以移动,移动时返回父节点,限制节点的移动范围

interacting 限制节点和边的交互

nodeMovable 限制是否可以移动

官方文档-限制节点和边的交互

embedding 移动时,返回父节点

官方文档-移动时,返回父节点

javascript 复制代码
 new Graph({
  ......,
  embedding: {
    enabled: true,
    findParent({ node }) {
      const bbox = node.getBBox()
      return this.getNodes().filter((node) => {
        const data = node.getData<{ parent: boolean }>()
        if (data && data.parent) {
          const targetBBox = node.getBBox()
          return bbox.isIntersectWithRect(targetBBox)
        }
        return false
      })
    },
  },
})

限制子节点的移动范围

官方文档-示例-限制子节点的移动范围
官方文档-限制节点的移动范围

javascript 复制代码
new Graph({
  translating: {
    restrict: true, // 节点不能移动超出画布区域
  },
})
javascript 复制代码
// 指定一个节点的移动范围
const graph = new Graph({
  translating: {
    restrict: {
      x: 0,
      y: 0,
      width: 100,
      height: 100,
    },
  },
})
javascript 复制代码
// 不能超出父节点的范围
 new Graph({
  ......,
  translating: {
    restrict(view) {
      const cell = view.cell
      if (cell.isNode()) {
        const parent = cell.getParent()
        if (parent) {
          return parent.getBBox()
        }
      }
      return null
    },
  },
})
相关推荐
小村儿6 分钟前
连载10-Sub-agents 深度解析:从源码理解 Claude Code 的分身术
前端·后端·ai编程
IT_陈寒40 分钟前
Vite动态导入把我坑惨了,原来要这样用才对
前端·人工智能·后端
DFT计算杂谈43 分钟前
KPROJ编译教程
java·前端·python·算法·conda
觅_1 小时前
前端学习后端的时候 选择一个技术
前端·学习
独泪了无痕1 小时前
CryptoJS:数据安全的JavaScript加密利器
前端·vue.js·node.js
发现一只大呆瓜1 小时前
一文搞懂 Vite 处理CommonJS包、按需编译逻辑及 Rollup 插件兼容规则
前端
Edwardwu1 小时前
写了个y-mxgraph:给 draw.io 接上了 Yjs,顺便解决了部署在 iframe 里的一堆问题
前端·typescript
其实防守也摸鱼1 小时前
软件安全与漏洞--软件安全编码
java·前端·网络·安全·网络安全·web·工具
发现一只大呆瓜2 小时前
Vite 开发预构建机制详解,搞懂 esbuild 与 Rollup 分工差异
前端·面试·vite
九九落3 小时前
前端获取经纬度完全指南:从Geolocation API到地图集成
前端·获取经纬度