[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
    },
  },
})
相关推荐
Setsuna_F_Seiei6 小时前
前端转型 Agent 开发 06 之 Agent Memory 记忆系统(让 Agent 更智能,更懂你)
前端·agent·ai编程
zhangzeyuaaa7 小时前
Ruby 多线程、GVL(GIL)与 Mutex 完全指南
开发语言·前端·ruby
默_笙7 小时前
🌊 向量库和 ES 都查不出"关系",我只好给奶茶建了一张人脉网
前端·javascript
优选资讯7 小时前
标签打印软件怎么对接 Excel 数据
前端·excel
一个风轻云淡8 小时前
GCC 和 GDB命令简单解读
java·linux·前端
u0111026759 小时前
图片处理接口如何统一错误信息 前端提示与后端错误码设计
前端·状态模式
福兮说10 小时前
浏览器里把 iPhone 的 HEIC 转成 JPG:Chrome 解不开、转完大了七成、拍摄时间全丢,六个坑实测
前端·javascript·图像处理·chrome·ios·iphone·heic
libokaifa10 小时前
把语音模型塞进手机:sherpa-onnx 在 Android 上的 ASR / TTS
前端
deli00710 小时前
DLA 枝晶生长实测:5000 个粒子集体停摆之后,分形维数收敛到 1.70
前端
IT_陈寒10 小时前
Redis卡顿的锅,这次真不是大key的错
前端·人工智能·后端