网格、环形与层级布局

用 Grid、Circular 和 Dagre 排列节点

选择布局

类型描述配置示例
grid将节点排成两行三列。{ type: 'grid', rows: 2, cols: 3 }
circular沿半径为 100 的圆周排列。{ type: 'circular', radius: 100 }
dagre按依赖关系从左到右分层。{ type: 'dagre', rankdir: 'LR' }

布局对比

在 Layout 中切换 grid、circular 和 dagre,观察同一组节点的排布。关键代码列出了三种布局的完整参数。

正在加载示例…
切换 Layout,对比同一张图的网格、环形和层级布局。
const layouts: Record<string, LayoutConfig> = {
  grid: { type: 'grid', rows: 2, cols: 3, width: 360, height: 160 },
  circular: { type: 'circular', radius: 100 },
  dagre: { type: 'dagre', rankdir: 'LR', nodesep: 64, ranksep: 96, nodeSize: 28 },
};

调整层级间距

Dagre 中,同一层的节点间距用 nodesep 设置,层与层之间的间距用 ranksep 设置。方向通过 rankdir 配置,LR 从左到右,TB 从上到下。

更多参数见布局配置参考。完整的业务示例见流程图。