API reference

Options

Data, node, edge, layout, interaction, label, and theme fields accepted by new Graph()

The argument of new Graph(options) is GraphOptions. Only container and data are required. Node appearance, edge appearance, layout, interaction, and theme all have defaults and can be overridden where the graph needs to differ.

const graph = new Graph({
  container: 'container',
  data: {
    nodes: [{ id: 'a' }, { id: 'b' }],
    edges: [{ id: 'a-b', source: 'a', target: 'b' }],
  },
  node: { style: { size: 28, fill: '#5366ad' } },
  edge: { style: { endArrow: true } },
  layout: { type: 'dagre', rankdir: 'TB' },
  behaviors: ['zoom-canvas', 'drag-canvas', 'click-select'],
  theme: 'light',
});

Visual recipes live in the guides: Data, Node, Edge, Label, Layout, Interactions, and Theme.

GraphOptions

FieldTypeDescription
containerstring | HTMLElementCanvas container. A string is looked up as an element id
dataGraphDataNodes, edges, and optional combos
nodeNodeConfigNode shape, style, and state styles
edgeEdgeConfigEdge shape, style, arrows, and state styles
comboComboConfigCombo appearance. Collapse and nesting are still experimental
labelLabelOptionsZoom and collision policy shared by node and edge labels
layoutLayoutConfigLayout type and algorithm parameters
behaviorsBehaviorOption[]Interaction list. Omitted means wheel zoom and drag pan
transformsTransformOption[]Data transforms before drawing, such as parallel edges
pluginsPluginOption[]Registered plugins
themeThemeOption'light', 'dark', or a preset plus token overrides
autoFitOnResizeboolean | number | FitViewOptionsWhether a container resize calls fitView() again. Default false, which keeps the current camera

At runtime, node, edge, label, and theme can be updated with graph.updateOptions().

Graph data

const data: GraphData = {
  nodes: [{ id: 'a', data: { cluster: 'svc' } }],
  edges: [{ source: 'a', target: 'b', data: { weight: 1 } }],
  combos: [{ id: 'group', collapsed: false }],
};

Node GraphNode

FieldRequiredDescription
idYesUnique in the graph
nameNoNode name
dataNoBusiness fields. Style functions and tooltips read them here
x / yNoExisting coordinates, used when there is no layout or as the layout's initial position
fx / fyNoCoordinates fixed during layout
statesNoInitial states, such as ['selected']
comboIdNoId of the owning combo

Edge GraphEdge

FieldRequiredDescription
sourceYesSource node id
targetYesTarget node id
idNoGenerated by the engine when omitted
dataNoBusiness fields
statesNoInitial states

Combo ComboData

FieldDescription
idRequired and unique
parentIdParent combo, used for nesting
collapsedWhether it starts collapsed
styleStyle overrides on top of combo.style
dataBusiness fields
statesInitial states

Node

node?: {
  type?: 'circle' | 'rect' | string;
  labelRenderer?: string;
  decorations?: NodeDecorationConfig[];
  autoExternalLabelPlacement?: boolean;
  style?: NodeStyleConfig | ((node: GraphNode) => Partial<NodeStyleConfig>);
  stateStyles?: Partial<Record<ElementState, NodeStateStyleOverride>>;
}

An omitted type, or 'circle', draws a circle. 'rect' draws a rounded rectangle. Any other string must already be registered with register('node', ...).

Each visual field in style can be a constant or (node: GraphNode) => value. label: false and icon: false skip that layer.

Style fieldDescription
fill / stroke / strokeWidth / opacityFill, stroke, and opacity
sizeCircle diameter, or the size used when width and height are not set separately
width / height / borderRadiusRectangle size and corner radius
labelText, or a function that returns text. Omitted means no node label; false explicitly hides it
labelFontSize / labelFontFamily / labelFontWeight / labelColorText appearance
labelPlacement'center' | 'top' | 'bottom' | 'left' | 'right', default 'bottom'
labelOffsetX / labelOffsetYOffset from the placement point
labelBackground / labelBackgroundPadding / labelMaxWidthText background, padding, and maximum width
icon / iconTypeIcon content. iconType is 'image' or 'text'
iconWidth / iconHeight / iconFontFamily / iconFontSize / iconColorIcon size and text-icon style
iconOffsetX / iconOffsetYIcon offset

stateStyles overrides fill, stroke, strokeWidth, opacity, and haloWidth while that state is active. Turn states on and off with the Graph state methods.

labelRenderer is the name of a registered custom label renderer. decorations attaches badges and other node decorations; register the renderer with register('decoration', ...). Fields and collision rules are in Label and Custom node.

Edge

edge?: {
  type?: 'line' | 'arc' | 'polyline' | 'cubic' | string;
  labelRenderer?: string;
  parallelEdges?: boolean | ParallelEdgesConfig;
  style?: { /* fields below; values may be functions */ };
  stateStyles?: Partial<Record<ElementState, EdgeStateStyleOverride>>;
}

An edge style function is (source, target, edge) => value.

Style fieldDescription
stroke / lineWidth / opacity / lineDashColor, width, opacity, and dash pattern
hitAreaWidthPickable width in screen pixels. Defaults to the final line width
curvature / curveOffsetBend of arcs and curves
endArrow / startArrow / arrowSizeEnd arrow, start arrow, and size
radiusPolyline corner radius
routerPolyline routing: 'orth' | 'tree' | 'indented' | 'fishbone'
label, plus labelFontSize, labelFontFamily, labelColorEdge label content. Omitted label draws nothing; the default font size is 10
labelPlacement'start' | 'center' | 'end'
labelBackground / labelBackgroundPadding / labelAutoRotateBackground, padding, and whether the text follows the edge

stateStyles can override stroke, lineWidth, hitAreaWidth, opacity, and lineDash.

parallelEdges: true separates edges that share endpoints with the default spacing. The object form is:

FieldDefaultDescription
enabledonWhether separation runs
offset20Graph-space distance between adjacent edges
mergeBysource/targetGrouping currently supports the two endpoints
includeReversetrueA→B and B→A belong to one group
minOffset0Minimum absolute offset for non-center edges
maxOffset80Maximum absolute offset

'process-parallel-edges' in transforms has the same effect. See Parallel edges.

Label policy

label controls how the engine shows node and edge labels that already have text. It does not choose the text.

FieldDefaultDescription
scaleWithZoomtrueWhether node-label size follows camera zoom. Edge labels stay in screen space
hideOnLowZoomtrueHide labels below their zoom threshold
hideOnCollisiontrueHide a label that overlaps an earlier one
nodeMinZoom0.3Minimum zoom for node labels
edgeMinZoom0.5Minimum zoom for edge labels

Layout

layout?: {
  type: string;
  worker?: boolean;
  width?: number;
  height?: number;
  center?: [number, number];
  [algorithmOption: string]: unknown;
}

type is a built-in name or a registered layout name, such as 'force', 'dagre', or 'mindmap'. The remaining fields are passed to that algorithm. worker: true runs supported algorithms in a Web Worker. Omitted width, height, and center are derived from the canvas.

Available types, parameters, and rerunning layout are in Layout.

Interactions

Each behaviors item is a behavior name or { type, ...options }.

Omitting the field is equivalent to ['zoom-canvas', 'drag-canvas']. Once an array is passed, that array is the complete list. [] turns off the default zoom and pan.

typeEffectOptions
zoom-canvasWheel zoomsensitivity default 1, minZoom default 0.1, maxZoom default 20
drag-canvasDrag to panignoreModifierKeys default true, so a modifier key stays available for brush select
drag-nodeDrag a nodeNo extra options
drag-edgeDrag an edge endpoint to reconnect itNo extra options
click-selectClick to select a node or edgemultiple default false; trigger default 'shift', also 'ctrl' or 'meta'
hover-highlightHighlight a neighborhood on hoverdegree default 1; optional inactiveState
highlight-nodeHovering a node highlights it, its one-hop neighbors, and the connecting edgesNo extra options
highlight-edgeHovering an edge highlights it and its endpointsNo extra options
brush-selectRectangular selectionkey is 'shift', 'ctrl', or null; throttleMs default 100
lasso-selectFreeform selectionSame options as brush-select
tooltipOverlaySee the table below

tooltip options:

FieldDefaultDescription
trigger'hover''hover' or 'click'
getContentNode id, or the edge endpointsReturns a string or HTMLElement. A custom string is written as HTML, so untrusted content must be escaped by the caller
enableAlways shownReturn false to skip that element
offset[10, 10]Pixel offset from the pointer
delay80Milliseconds to wait before a hover tooltip appears
className'g6lite-tooltip'Overlay class name
containerdocument.bodyDOM node that hosts the overlay

getContent receives a TooltipContext with itemType, nodeId or the edge's edgeId / source / target, data, and the original event.

Behavior combinations and events are in Interactions. A custom behavior uses register('behavior', ...).

Theme

theme?: 'light' | 'dark' | ({ type: 'light' | 'dark' } & Partial<ThemeTokens>)

An object starts from the preset named by type, then overrides tokens on that object. Overridable tokens are nodeFill, nodeSize, nodeStroke, nodeStrokeWidth, edgeStroke, edgeLineWidth, edgeArrow, canvasBackground, edgeDefaultColor, edgeCategoryPalette, nodeStateStyles, and edgeStateStyles.

import { resolveTheme } from '@antv/g6-lite';

const tokens = resolveTheme({ type: 'light', nodeFill: '#1677ff' });

resolveTheme() returns a new complete ThemeTokens and does not mutate the preset.

Plugins and transforms

plugins?: Array<{ type: string; [option: string]: unknown }>
transforms?: Array<'process-parallel-edges' | string | { type: string; options?: object }>

A custom plugins or transforms type must be registered with register() first. The built-in transform name is 'process-parallel-edges'.