logo

G6

  • Docs
  • API
  • Playground
  • Community
  • Productsantv logo arrow
  • 5.0.47
  • Introduction
  • Data
  • Getting Started
    • Quick Start
    • Installation
    • Integration
      • react
      • vue
      • angular
    • Step-by-step guide
  • Graph
    • Extensions En
    • Graph
    • Options
    • extension
  • Element
    • Element Overview
    • Element State
    • Node
      • Node Overview
      • Build-in Node
        • Common Node Configurations
        • Diamond
        • Donut
        • Ellipse
        • Hexagon
        • Html
        • Image
        • Rect
        • Star
        • Triangle
        • Circle
      • Custom Node
      • Define Nodes with React
    • Edge
      • Edge Overview
      • Build-in Edge
        • Common Edge Configurations
        • Cubic Bezier Curve
        • CubicHorizontal Bezier Curve
        • CubicVertical Bezier Curve
        • Line
        • Polyline
        • Quadratic Bezier Curve
      • Custom Edge
    • Combo
      • Combo Overview
      • Build-in Combo
        • Circle
        • Combo Configuration Options
        • Rect
      • Custom Combo
    • Shape
      • Shape and KeyShape
      • Atomic Shapes and Their Properties
      • Design and Implementation of Composite Shape
  • Layout
    • Layout Overview
    • Build-in Layout
      • 3D Force-Directed Layout
      • AntvDagre Layout
      • Circular Layout
      • ComboCombined Layout
      • Common Layout Configuration Options
      • CompactBox
      • Concentric Layout
      • D3 Force-Directed Layout
      • Dagre Layout
      • Dendrogram Layout
      • Fishbone Layout
      • Force Force-directed Layout
      • ForceAtlas2 Force-directed Layout
      • Fruchterman Force-directed Layout
      • Grid Layout
      • Indented Tree
      • MDS High-dimensional Data Dimensionality Reduction Layout
      • Mindmap Tree
      • Radial Layout
      • Random Layout
      • Snake Layout
    • Custom Layout
  • Behavior
    • Behavior Overview
    • Build-in Behavior
      • AutoAdaptLabel
      • BrushSelect
      • ClickSelect
      • CollapseExpand
      • CreateEdge
      • DragCanvas
      • DragElement
      • DragElementForce
      • FixElementSize
      • FocusElement
      • HoverActivate
      • LassoSelect
      • OptimizeViewportTransform
      • ScrollCanvas
      • ZoomCanvas
    • Custom Behavior
  • Plugin
    • Plugin Overview
    • Build-in Plugin
      • Background
      • BubbleSets
      • Contextmenu
      • EdgeBundling
      • EdgeFilterLens
      • Fisheye
      • Fullscreen
      • GridLine
      • History
      • Hull
      • Legend
      • Minimap
      • Snapline
      • Timebar
      • Toolbar
      • Tooltip
      • Watermark
    • Custom Plugin
  • Transform
    • Data Transformation Overview
    • Build-in Transform
      • MapNodeSize
      • PlaceRadialLabels
      • ProcessParallelEdges
    • Custom Transform
  • Theme
    • Theme Overview
    • Custom Theme
    • Palette
    • Custom Palette
  • Animation
    • Animation Overview
    • Custom Animation
  • Further Reading
    • Event
    • renderer
    • coordinate
    • download-image
    • Using Iconfont
    • Use 3D
    • Bundle Project
  • What's new
    • Feature
    • Upgrade To 5.0
  • FAQ
  • contribute

Layout Overview

Previous
Design and Implementation of Composite Shape
Next
3D Force-Directed Layout

Resources

Ant Design
Galacea Effects
Umi-React Application Framework
Dumi-Component doc generator
ahooks-React Hooks Library

Community

Ant Financial Experience Tech
seeconfSEE Conf-Experience Tech Conference

Help

GitHub
StackOverflow

more productsMore Productions

Ant DesignAnt Design-Enterprise UI design language
yuqueYuque-Knowledge creation and Sharing tool
EggEgg-Enterprise-class Node development framework
kitchenKitchen-Sketch Tool set
GalaceanGalacean-互动图形解决方案
xtechLiven Experience technology
© Copyright 2025 Ant Group Co., Ltd..备案号:京ICP备15032932号-38

Loading...

Overview

Graph layout refers to the process of arranging elements in a graph according to certain rules, such as force-directed layout based on charge elasticity models, grid layout with sequential arrangement, and tree layout based on hierarchical structures.

Layout Types

G6 provides a variety of layout algorithms, allowing users to choose the appropriate one based on their needs:

  • AntVDagreLayout: Custom layout based on dagre
  • CircularLayout: Circular layout
  • ComboCombinedLayout: Layout suitable for combinations
  • ConcentricLayout: Concentric layout
  • D3Force3DLayout: 3D Force-directed layout
  • D3ForceLayout: Force-directed layout based on D3
  • DagreLayout: dagre layout
  • FishboneLayout: Fishbone layout
  • ForceAtlas2Layout: ForceAtlas2 layout
  • ForceLayout: Force-directed layout
  • FruchtermanLayout: Fruchterman layout
  • GridLayout: Grid layout
  • MDSLayout: High-dimensional data dimensionality reduction layout
  • RadialLayout: Radial layout
  • RandomLayout: Random layout
  • SnakeLayout: Snake layout
  • CompactBoxLayout: Compact tree layout
  • DendrogramLayout: Dendrogram layout
  • MindmapLayout: Mindmap layout
  • IndentedLayout: Indented tree layout

Among them, CompactBox Layout, Dendrogram Layout, Mindmap Layout, and Indented Layout are types of tree layouts suitable for tree-structured graphs.

Register Layout

You can directly use built-in layouts, but if you want to use other layouts, you need to register them first:

import { register, ExtensionCategory } from '@antv/g6';
import { CustomLayout } from 'package-name/or/path-to-your-custom-layout';
register(ExtensionCategory.LAYOUT, 'custom-layout', CustomLayout);

Configure Layout

The layout configuration item can specify the graph's layout algorithm, for example:

{
layout: {
// Specify the layout algorithm to use
type: 'force',
// Configuration items for the layout algorithm
gravity: 10
// ...
}
}

You can also use graph.setLayout to update the layout configuration after the graph is instantiated.

Layout Acceleration

G6 provides accelerated versions for some layout algorithms, including executing layout algorithms in Web Workers, providing WASM versions of layout algorithms, and GPU-accelerated layout algorithms. They can be used as follows:

Execute Layout Algorithms in Web Workers

Except for tree layouts, all built-in layout algorithms in G6 support execution in Web Workers. Simply set enableWorker to true:

{
layout: {
type: 'force',
enableWorker: true,
// ...
}
}

Use WASM Version Layout Algorithms

Currently supported WASM version layout algorithms include: Fruchterman Layout, ForceAtlas Layout, Force Layout, Dagre Layout.

First, install @antv/layout-wasm:

npm install @antv/layout-wasm --save

Import and register the layout algorithm:

import { register, Graph, ExtensionCategory } from '@antv/g6';
import { FruchtermanLayout, initThreads, supportsThreads } from '@antv/layout-wasm';
register(ExtensionCategory.LAYOUT, 'fruchterman-wasm', FruchtermanLayout);

Initialize threads:

const supported = await supportsThreads();
const threads = await initThreads(supported);

Initialize the graph and pass in the layout configuration:

const graph = new Graph({
// ... other configurations
layout: {
type: 'fruchterman-wasm',
threads,
// ... other configurations
},
});

Use GPU-Accelerated Layout

Currently supported GPU-accelerated layout algorithms include: Fruchterman Layout, GForce Layout.

First, install @antv/layout-gpu:

npm install @antv/layout-gpu --save

Import and register the layout algorithm:

import { register, Graph, ExtensionCategory } from '@antv/g6';
import { FruchtermanLayout } from '@antv/layout-gpu';
register(ExtensionCategory.LAYOUT, 'fruchterman-gpu', FruchtermanLayout);

Initialize the graph and pass in the layout configuration:

const graph = new Graph({
// ... other configurations
layout: {
type: 'fruchterman-gpu',
// ... other configurations
},
});

Execute Layout

Usually, after calling graph.render(), G6 will automatically execute the layout algorithm.

If you need to manually execute the layout algorithm, G6 provides the following APIs:

  • layout: Execute layout algorithm
  • setLayout: Set layout algorithm
  • stopLayout: Stop layout algorithm

Custom Layout

If the built-in layout algorithms cannot meet your needs, you can customize layout algorithms. For details, please refer to Custom Layout.