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

AntvDagre Layout

Previous
3D Force-Directed Layout
Next
Circular 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

AntvDagre builds upon the original dagre layout and adds more useful options, such as nodeOrder, edgeLabelSpace, and more. The dagre layout itself is a hierarchical layout suitable for directed acyclic graphs (DAGs), which can automatically handle node direction and spacing, and supports both horizontal and vertical layouts. See more Dagre layout examples, source code, and official documentation.

Dagre Layout

Configuration

const graph = new Graph({
layout: {
type: 'antv-dagre',
rankdir: 'TB',
align: 'UL',
nodesep: 50,
ranksep: 50,
controlPoints: false,
},
});

Options

For more native dagre options, refer to the official documentation. Here, only some core and new options are listed.

Dagre Layout Options Diagram
PropertyDescriptionTypeDefaultRequired
typeLayout typeantv-dagre-✓
rankdirLayout direction, optionsTB | BT | LR | RLTB
alignNode alignment, optionsUL | UR | DL | DRUL
nodesepNode spacing (px). For TB or BT, it's horizontal spacing; for LR or RL, it's vertical spacing.number50
nodesepFuncCallback for node spacing (px), allows different spacing for different nodes. For TB or BT, it's horizontal spacing; for LR or RL, it's vertical spacing. Takes precedence over nodesep.(d?: Node) => number
ranksepRank spacing (px). For TB or BT, it's vertical spacing between ranks; for LR or RL, it's horizontal spacing.number100
ranksepFuncCallback for rank spacing (px), allows different spacing for different ranks. For TB or BT, it's vertical spacing; for LR or RL, it's horizontal spacing. Takes precedence over ranksep.(d?: Node) => number
rankerAlgorithm for assigning ranks to nodes: longest-path, tight-tree, or network-simplexnetwork-simplex | tight-tree | longest-pathnetwork-simplex
nodeSizeSpecify node size for all or each node, used for collision detection. If a single number is returned, width and height are the same; if an array, e.g. [width, height].Size((nodeData: Node) => Size)
controlPointsWhether to keep edge control points. Only effective when using built-in polyline edges (type: 'polyline-edge') or any edge that uses style.controlPoints as control points. Adds style.controlPoints to edge data.booleanfalse
beginTop-left alignment position of the layout[number, number] | [number, number, number]
sortByComboWhether to sort nodes in the same rank by their parentId to prevent Combo overlapbooleanfalse
edgeLabelSpaceWhether to reserve space for edge labelsbooleantrue
nodeOrderReference array for node order in the same rank, stores node ids. If not specified, dagre's default order is used.string[]
radialWhether to use radial layout based on dagrebooleanfalse
focusNodeFocus node, only effective when radial is trueID | Node | null
presetReference node positions for layout calculation, usually for smooth transitions when switching data. In G6, if updating data, the existing layout result is used as input.OutNode[]

align

DagreAlign Default: UL

Node alignment: U = upper, D = down, L = left, R = right

  • UL: align to upper left
  • UR: align to upper right
  • DL: align to lower left
  • DR: align to lower right

rankdir

DagreRankdir Default: TB

Layout direction. T = top, B = bottom, L = left, R = right

  • TB: top to bottom
  • BT: bottom to top
  • LR: left to right
  • RL: right to left

ranker

network-simplex | tight-tree | longest-path

Layout mode

ranksep

number Default: 50

Rank spacing (px)

For 'TB' or 'BT', it's vertical spacing; for 'LR' or 'RL', it's horizontal spacing. ranksepFunc has higher priority.

ranksepFunc

(d?: Node) => number

Callback for rank spacing (px)

For 'TB' or 'BT', it's vertical spacing; for 'LR' or 'RL', it's horizontal spacing. Takes precedence over nodesep if set.

nodesep

number Default: 50

Node spacing (px)

For 'TB' or 'BT', it's horizontal spacing; for 'LR' or 'RL', it's vertical spacing. nodesepFunc has higher priority.

nodesepFunc

(d?: Node) => number

Callback for node spacing (px), allows different spacing for different nodes

For 'TB' or 'BT', it's horizontal spacing; for 'LR' or 'RL', it's vertical spacing. Takes precedence over nodesep if set.

begin

[number, number] | [number, number, number] Default: undefined

Top-left alignment position of the layout

controlPoints

boolean Default: false

Whether to keep edge control points. Only effective when using built-in polyline edges (type: 'polyline-edge') or any edge that uses style.controlPoints as control points. Adds style.controlPoints to edge data.

edgeLabelSpace

boolean Default: true

Whether to reserve space for edge labels

This affects whether a dummy node is added in the middle of the edge.

focusNode

ID | Node | null

Focus node, only effective when radial is true

  • ID: node id
  • Node: node instance
  • null: cancel focus

nodeOrder

string[] Default: undefined

Reference array for node order in the same rank, stores node ids

If not specified, dagre's default order is used.

nodeSize

Size | ((nodeData: Node) => Size) Default: undefined

Specify node size for all or each node.

Used for collision detection to prevent node overlap

preset

OutNode[] Default: undefined

Reference node positions for layout calculation

Usually for smooth transitions when switching data. In G6, if updating data, the existing layout result is used as input.

radial

boolean

Whether to use radial layout based on dagre

sortByCombo

boolean Default: false

Whether to sort nodes in the same rank by their parentId to prevent Combo overlap

Recommended to enable when using Combo

Suitable Scenarios

  • Flowcharts: Suitable for displaying flowcharts, node direction and spacing are automatically handled
  • Dependency Graphs: Display dependencies between packages or modules
  • Task Scheduling Graphs: Show dependencies and execution order between tasks

Related Documentation

The following documents can help you better understand the Dagre layout

  • Graph Layout Algorithms: In-depth Dagre Layout
  • In-depth Dagre Layout Algorithm