Usage guidesLayoutRecommended optional layouts

Indented tree layout

List nodes in traversal order and indent them by depth.

Overview

List nodes in traversal order and indent them by depth.

When to use it

Use it for file directories, navigation menus, and taxonomies.

Basic usage

This layout is optional. Import and register it before setting layout.type. For CDN usage, see Optional layouts.

import { Graph, register } from '@antv/g6-lite';
import indented from '@antv/g6-lite/layouts/indented';

register('layout', 'indented', indented);

const graph = new Graph({
  container,
  data,
  layout: { type: 'indented' },
});

Options

OptionDescriptionTypeDefault
indentHorizontal indent per level.number80
rowHeightVertical distance between adjacent rows.number40
direction'LR' indents right and 'RL' indents left.'LR' | 'RL''LR'
rootIdRoot node ID.stringFirst node without a parent

Common layout options · Layout reference

Code example

Define parent-child relationships as edges. Use the parent ID as source and the child ID as target.

Each level indents by 72. The indented router draws the directory-style connectors.

Loading example…
Drag to pan or scroll to zoom.
import { register } from '@antv/g6-lite';

import indented from '@antv/g6-lite/layouts/indented';

register('layout', 'indented', indented);

const layout = { type: 'indented', direction: 'LR', indent: 72, rowHeight: 30 };

Compare tree layouts