[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
    },
  },
})
相关推荐
步步为营DotNet1 小时前
深入理解ASP.NET Core Middleware:构建高效Web应用的管道基石
前端·后端·asp.net
|晴 天|1 小时前
微前端架构入门:从概念到落地实践
前端·架构
悟能不能悟1 小时前
vue项目,url访问不了,用route-link跳过去就可以访问,为什么
前端·javascript·vue.js
程序媛_MISS_zhang_01101 小时前
APP中列表到详情,详情返回列表时候,返回定位到之前查看详情那条数据
前端·javascript·vue.js
还有多远.1 小时前
前端部署后自动检测更新
前端·javascript·vue.js
拾忆,想起1 小时前
Dubbo本地存根与本地伪装实战指南:提升微服务容错能力的利器
前端·微服务·云原生·架构·dubbo·safari
wuli_滔滔1 小时前
DevUI弹窗体系重构:微前端场景下的模态管理策略
前端·重构·架构
fruge1 小时前
Angular 17 新特性深度解析:独立组件 + 信号系统实战
前端·javascript·vue.js