[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
    },
  },
})
相关推荐
灵感__idea2 小时前
Hello 算法:贪心的世界
前端·javascript·算法
GreenTea3 小时前
一文搞懂Harness Engineering与Meta-Harness
前端·人工智能·后端
killerbasd5 小时前
牧苏苏传 我不装了 4/7
前端·javascript·vue.js
吴声子夜歌5 小时前
ES6——二进制数组详解
前端·ecmascript·es6
码事漫谈6 小时前
手把手带你部署本地模型,让你Token自由(小白专属)
前端·后端
ZC跨境爬虫6 小时前
【爬虫实战对比】Requests vs Scrapy 笔趣阁小说爬虫,从单线程到高效并发的全方位升级
前端·爬虫·scrapy·html
爱上好庆祝6 小时前
svg图片
前端·css·学习·html·css3
王夏奇6 小时前
python中的__all__ 具体用法
java·前端·python
大家的林语冰7 小时前
《前端周刊》尤大开源 Vite+ 全家桶,前端工业革命启动;尤大爆料 Void 云服务新产品,Vite 进军全栈开发;ECMA 源码映射规范......
前端·javascript·vue.js
jiayong237 小时前
第 8 课:开始引入组合式函数
前端·javascript·学习