Usage guidesLayoutRecommended optional layouts

Mind map layout

Expand branches to one or both sides of a central topic.

Overview

Expand branches to one or both sides of a central topic.

When to use it

Use it to organize ideas, knowledge, and categories.

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 mindmap from '@antv/g6-lite/layouts/mindmap';

register('layout', 'mindmap', mindmap);

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

Options

OptionDescriptionTypeDefault
direction'LR' goes right, 'RL' goes left, and 'H' uses getSide.'H' | 'LR' | 'RL''H'
getSideSelect a side using the node, its branch index, and its parent’s side.Function returning 'left' or 'right'Returns 'right'
levelGapHorizontal gap between a parent and its child.number120
nodeGapVertical gap between siblings on the same side.number30

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.

getSide places branches A and C on the left and B and D on the right.

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

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

register('layout', 'mindmap', mindmap);

const layout = {
  type: 'mindmap',
  direction: 'H',
  levelGap: 100,
  nodeGap: 24,
  getWidth: () => 16,
  getHeight: (node: GraphNode) => node.id.length === 1 ? 64 : 16,
  getSide: (node: GraphNode) => /^[AC]/.test(node.id) ? 'left' : 'right',
};

Compare tree layouts