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

Options

Previous
Graph
Next
extension

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...

autoFit

{ type: 'view'; options?: FitViewOptions; animation?: ViewportAnimationEffectTiming; } | { type: 'center'; animation?: ViewportAnimationEffectTiming; } | 'view' | 'center'

Whether to automatically fit the canvas. ⚠️ Note: Each time render is executed, it will adapt according to autoFit.

Two basic adaptation modes:

  • 'view' - Automatically scale to ensure all content is visible within the view
  • 'center' - Center the content without changing the zoom level

More precise adaptation control can be achieved through object form:

const graph = new Graph({
autoFit: {
type: 'view', // Adaptation type: 'view' or 'center'
options: {
// Only applicable to 'view' type
when: 'overflow', // When to adapt: 'overflow' (only when content overflows) or 'always' (always adapt)
direction: 'x', // Adaptation direction: 'x', 'y', or 'both'
},
animation: {
// Adaptation animation effect
duration: 1000, // Animation duration (milliseconds)
easing: 'ease-in-out', // Animation easing function
},
},
});

FitViewOptions

PropertyDescriptionTypeDefaultRequired
whenAdaptation occurs under the following conditions
- 'overflow' adapt only when content overflows
- 'always' always adapt
'overflow' | 'always''always'
directionAdapt only in the specified direction
- 'x' adapt only in x direction
- 'y' adapt only in y direction
- 'both' adapt in both x and y directions
'x' | 'y' | 'both''both'

ViewportAnimationEffectTiming

type ViewportAnimationEffectTiming =
| boolean // true to enable default animation, false to disable animation
| {
easing?: string; // Animation easing function: 'ease-in-out', 'ease-in', 'ease-out', 'linear'
duration?: number; // Animation duration (milliseconds)
};

autoResize

boolean Default: false

Whether to automatically resize the canvas.

Implemented based on the window.onresize event. When the browser window size changes, the canvas will automatically resize to fit the container.

background

string

Canvas background color.

This color is used as the background color when exporting images. Any valid CSS color value can be used, such as hexadecimal, RGB, RGBA, etc.

canvas

CanvasConfig

Canvas configuration. Related configuration items under GraphOptions (such as container, width, height, devicePixelRatio, background, cursor) are shortcut configuration items and will be converted to canvas configuration items.

CanvasConfig

PropertyDescriptionTypeDefaultRequired
containerCanvas containerstring | HTMLElement-
devicePixelRatioDevice pixel rationumber-
widthCanvas widthnumber-
heightCanvas heightnumber-
cursorCursor style, same as GraphOptions.cursorstring-
backgroundCanvas background colorstring-
rendererRenderer, same as GraphOptions.renderer(layer: 'background' | 'main' | 'label' | 'transient') => IRenderer-
enableMultiLayerWhether to enable multi-layer. Non-dynamic parameter, effective only during initializationboolean-

container

string | HTMLElement | Canvas

Canvas container, can be one of the following three assignments:

  • ID string of the DOM element, such as 'container'
  • HTML element object, such as document.getElementById('container')
  • Canvas instance, such as new Canvas(options), where options is of type CanvasConfig.

cursor

string

Cursor style, controls the cursor shape when hovering over the canvas. Any valid CSS cursor value can be used.

Supported values include: 'auto', 'default', 'none', 'context-menu', 'help', 'pointer', 'progress', 'wait', 'cell', 'crosshair', 'text', 'vertical-text', 'alias', 'copy', 'move', 'no-drop', 'not-allowed', 'grab', 'grabbing', 'all-scroll', 'col-resize', 'row-resize', 'n-resize', 'e-resize', 's-resize', 'w-resize', 'ne-resize', 'nw-resize', 'se-resize', 'sw-resize', 'ew-resize', 'ns-resize', 'nesw-resize', 'nwse-resize', 'zoom-in', `'zoom-out'.

Cursor values are referenced from MDN - cursor.

devicePixelRatio

number

Device pixel ratio.

Used for high-definition screens, the default is window.devicePixelRatio.

width

number

Canvas width. If not set, the container width will be automatically obtained.

height

number

Canvas height. If not set, the container height will be automatically obtained.

renderer

(layer: 'background' | 'main' | 'label' | 'transient') => IRenderer

Manually specify the renderer

G6 uses a layered rendering approach, divided into four layers: background, main, label, transient. Users can set the renderer for each layer of the canvas through this configuration item.

Example: Use SVG renderer for rendering

import { Renderer as SVGRenderer } from '@antv/g-svg';
import { Graph } from '@antv/g6';
const graph = new Graph({
renderer: () => new SVGRenderer(),
});

padding

number | number[]

Canvas padding

Usually, during adaptation, it will be adapted according to the padding. It can be a single value (same padding on all sides) or an array form (specify the padding for top, right, bottom, left in order).

Example:

// Single value
const graph1 = new Graph({
padding: 20, // 20 pixels of padding on all sides
});
// Array form
const graph2 = new Graph({
padding: [20, 40, 20, 40], // Padding for top, right, bottom, left
});

rotation

number Default: 0

Rotation angle (in radians)

x

number

Viewport x coordinate, sets the initial horizontal position of the viewport.

y

number

Viewport y coordinate, sets the initial vertical position of the viewport.

zoom

number Default: 1

Sets the initial zoom level of the viewport, 1 means 100% (original size).

zoomRange

[number, number] Default: [0.01, 10]

Zoom range, limits the minimum and maximum scale that users can zoom.

animation

boolean | AnimationEffectTiming

Enable or disable global animation

When configured as an animation option, animation will be enabled, and this animation configuration will be used as the base configuration for global animation.

AnimationEffectTiming

PropertyDescriptionTypeDefaultRequired
delayAnimation delay timenumber-
directionAnimation direction'alternate' | 'alternate-reverse' | 'normal' | 'reverse''forward'
durationAnimation durationnumber-
easingAnimation easing functionstring-
fillFill mode after animation ends'auto' | 'backwards' | 'both' | 'forwards' | 'none''none'
iterationsAnimation iteration countnumber-

Example:

// Simple enable
const graph1 = new Graph({
animation: true,
});
// Detailed configuration
const graph2 = new Graph({
animation: {
duration: 500, // Animation duration (milliseconds)
easing: 'ease-in-out', // Easing function
},
});

data

GraphData

Data.

GraphData

PropertyDescriptionTypeDefaultRequired
nodesNode dataNodeData[]-✓
edgesEdge dataEdgeData[]-✓
combosCombo dataComboData[]-✓

NodeData

PropertyDescriptionTypeDefaultRequired
idUnique identifier for the node, used to distinguish different nodesstring-✓
typeNode type, built-in node type name or custom node namestring-
dataNode data, used to store custom data for the node, such as node name, description, etc. Can be accessed in style mapping through callback functionsobject-
styleNode style, including visual attributes such as position, size, color, etc.object-
statesInitial state of the node, such as selected, activated, hovered, etc.string[]-
comboID of the combo to which it belongs, used to organize the hierarchical relationship of nodes, if none, it is nullstring | null-
childrenCollection of child node IDs, used only in tree graph scenariosstring[]-

EdgeData

PropertyDescriptionTypeDefaultRequired
sourceStarting node ID of the edgestring-✓
targetTarget node ID of the edgestring-✓
idUnique identifier for the edgestring-
typeEdge type, built-in edge type name or custom edge namestring-
dataEdge data, used to store custom data for the edge, can be accessed in style mapping through callback functionsobject-
styleEdge style, including visual attributes such as line color, width, arrow, etc.object-
statesInitial state of the edgestring[]-

ComboData

PropertyDescriptionTypeDefaultRequired
idUnique identifier for the combostring-✓
typeCombo type, built-in combo type name or custom combo namestring-
dataCombo data, used to store custom data for the combo, can be accessed in style mapping through callback functionsobject-
styleCombo styleobject-
statesInitial state of the combostring[]-
comboParent combo ID. If there is no parent combo, it is nullstring | null-

Example:

const graph = new Graph({
data: {
nodes: [
{ id: 'node1', style: { x: 100, y: 100 } },
{ id: 'node2', style: { x: 200, y: 200 } },
],
edges: [{ id: 'edge1', source: 'node1', target: 'node2' }],
combos: [{ id: 'combo1', style: { x: 150, y: 150 } }],
},
});
  • Read Data to learn more about graph data, including but not limited to data formats, how to manipulate data, etc.

node

NodeOptions

Node configuration options.

NodeOptions

PropertyDescriptionTypeDefaultRequired
typeNode type, built-in node type name or custom node nameTypecircle
styleNode style, including color, size, etc.Style-
stateDefine the style of the node in different statesState-
paletteDefine the color palette of the node, used to map colors based on different dataPalette-
animationDefine the animation effect of the nodeAnimation-

See Node for details

Example:

const graph = new Graph({
node: {
type: 'circle', // Node type
style: {
fill: '#e6f7ff', // Fill color
stroke: '#91d5ff', // Border color
lineWidth: 1, // Border width
r: 20, // Radius
labelText: (d) => d.id, // Label text
},
// Node state style
state: {
hover: {
lineWidth: 2,
stroke: '#69c0ff',
},
selected: {
fill: '#bae7ff',
stroke: '#1890ff',
lineWidth: 2,
},
},
},
});

edge

EdgeOptions

Edge configuration options

EdgeOptions

PropertyDescriptionTypeDefaultRequired
typeEdge type, built-in edge type name or custom edge nameTypeline
styleEdge style, including color, size, etc.Style-
stateDefine the style of the edge in different statesState-
paletteDefine the color palette of the edge, used to map colors based on different dataPalette-
animationDefine the animation effect of the edgeAnimation-

See Edge for details

Example:

const graph = new Graph({
edge: {
type: 'polyline', // Edge type
style: {
stroke: '#91d5ff', // Edge color
lineWidth: 2, // Edge width
endArrow: true, // Whether there is an arrow
},
// Edge state style
state: {
selected: {
stroke: '#1890ff',
lineWidth: 3,
},
},
},
});

combo

ComboOptions

Combo configuration options

PropertyDescriptionTypeDefaultRequired
typeCombo type, built-in combo type name or custom combo nameTypecircle
styleCombo style, including color, size, etc.Style-
stateDefine the style of the combo in different statesState-
paletteDefine the color palette of the combo, used to map colors based on different dataPalette-
animationDefine the animation effect of the comboAnimation-

See Combo for details

Example:

const graph = new Graph({
combo: {
type: 'circle', // Combo type
style: {
fill: '#f0f0f0', // Background color
stroke: '#d9d9d9', // Border color
lineWidth: 1, // Border width
},
// Combo state style
state: {
selected: {
stroke: '#1890ff',
lineWidth: 2,
},
},
},
});

layout

CustomLayoutOptions | CustomLayoutOptions[]

Layout configuration options, can be an object (normal layout) or an array (pipeline layout).

Example:

const graph = new Graph({
container: 'container',
layout: {
type: 'force', // Force-directed layout
preventOverlap: true, // Prevent node overlap
nodeStrength: -50, // Repulsion between nodes
edgeStrength: 0.5, // Elastic coefficient of edges
iterations: 200, // Number of iterations
animation: true, // Enable layout animation
},
});

theme

false | 'light' | 'dark' | string

Set the theme of the chart, can be the built-in 'light', 'dark' theme, or the name of a custom theme. Set to false to use no theme.

behaviors

(string | CustomExtensionOptions | ((this:Graph) =>CustomExtensionOptions))[]

Configure the interaction behaviors of the chart, can be a string (using default configuration), an object (custom configuration), or a function (dynamic configuration, the graph instance can be accessed within the function).

Example:

const graph = new Graph({
behaviors: [
'drag-canvas', // Enable canvas dragging with default configuration
'zoom-canvas', // Enable canvas zooming with default configuration
{
type: 'drag-element', // Custom configuration for dragging elements
key: 'drag-node-only',
enable: (event) => event.targetType === 'node', // Only allow dragging nodes
},
function () {
console.log(this); // Output graph instance
return {
type: 'hover-activate',
};
},
],
});
  • View Interaction Overview to learn more about interaction principles
  • Browse Built-in Interactions to get a list of all built-in interactions and their configuration options

plugins

(string | CustomExtensionOptions | ((this:Graph) =>CustomExtensionOptions))[]

Set the plugins of the chart, can be a string (using default configuration), an object (custom configuration), or a function (dynamic configuration, the graph instance can be accessed within the function).

Example:

const graph = new Graph({
container: 'container',
plugins: [
'minimap', // Enable minimap with default configuration
{
type: 'grid', // Enable grid background
key: 'grid-plugin',
line: {
stroke: '#d9d9d9',
lineWidth: 1,
},
},
{
type: 'toolbar', // Enable toolbar
key: 'graph-toolbar',
position: 'top-right', // Position
},
],
});
  • View Plugin Overview to learn more about plugin principles
  • Browse Built-in Plugins to get a list of all built-in plugins and their configuration options

transforms

(string | CustomExtensionOptions | ((this:Graph) =>CustomExtensionOptions))[]

Configure data processing, used to process data before rendering, does not affect the original data. Can be a string (using default configuration), an object (custom configuration), or a function (dynamic configuration, the graph instance can be accessed within the function).

Example:

const graph = new Graph({
transforms: [
'process-parallel-edges', // Process parallel edges with default configuration
{
type: 'map-node-size', // Map node size based on node data
field: 'value', // Use the value of the field
max: 50, // Maximum radius
min: 20, // Minimum radius
},
],
});
  • View Data Processing Overview to learn more about data processing principles
  • Browse Built-in Data Processing to get a list of all built-in data processing and their configuration options

CustomExtensionOptions

interface CustomExtensionOption extends Record<string, any> {
/** Extension type */
type: string;
/** Extension key, i.e., unique identifier */
key?: string;
}