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
| Field | Type | Description |
|---|---|---|
container | string | HTMLElement | Canvas container. A string is looked up as an element id |
data | GraphData | Nodes, edges, and optional combos |
node | NodeConfig | Node shape, style, and state styles |
edge | EdgeConfig | Edge shape, style, arrows, and state styles |
combo | ComboConfig | Combo appearance. Collapse and nesting are still experimental |
label | LabelOptions | Zoom and collision policy shared by node and edge labels |
layout | LayoutConfig | Layout type and algorithm parameters |
behaviors | BehaviorOption[] | Interaction list. Omitted means wheel zoom and drag pan |
transforms | TransformOption[] | Data transforms before drawing, such as parallel edges |
plugins | PluginOption[] | Registered plugins |
theme | ThemeOption | 'light', 'dark', or a preset plus token overrides |
autoFitOnResize | boolean | number | FitViewOptions | Whether 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
| Field | Required | Description |
|---|---|---|
id | Yes | Unique in the graph |
name | No | Node name |
data | No | Business fields. Style functions and tooltips read them here |
x / y | No | Existing coordinates, used when there is no layout or as the layout's initial position |
fx / fy | No | Coordinates fixed during layout |
states | No | Initial states, such as ['selected'] |
comboId | No | Id of the owning combo |
Edge GraphEdge
| Field | Required | Description |
|---|---|---|
source | Yes | Source node id |
target | Yes | Target node id |
id | No | Generated by the engine when omitted |
data | No | Business fields |
states | No | Initial states |
Combo ComboData
| Field | Description |
|---|---|
id | Required and unique |
parentId | Parent combo, used for nesting |
collapsed | Whether it starts collapsed |
style | Style overrides on top of combo.style |
data | Business fields |
states | Initial 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 field | Description |
|---|---|
fill / stroke / strokeWidth / opacity | Fill, stroke, and opacity |
size | Circle diameter, or the size used when width and height are not set separately |
width / height / borderRadius | Rectangle size and corner radius |
label | Text, or a function that returns text. Omitted means no node label; false explicitly hides it |
labelFontSize / labelFontFamily / labelFontWeight / labelColor | Text appearance |
labelPlacement | 'center' | 'top' | 'bottom' | 'left' | 'right', default 'bottom' |
labelOffsetX / labelOffsetY | Offset from the placement point |
labelBackground / labelBackgroundPadding / labelMaxWidth | Text background, padding, and maximum width |
icon / iconType | Icon content. iconType is 'image' or 'text' |
iconWidth / iconHeight / iconFontFamily / iconFontSize / iconColor | Icon size and text-icon style |
iconOffsetX / iconOffsetY | Icon 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 field | Description |
|---|---|
stroke / lineWidth / opacity / lineDash | Color, width, opacity, and dash pattern |
hitAreaWidth | Pickable width in screen pixels. Defaults to the final line width |
curvature / curveOffset | Bend of arcs and curves |
endArrow / startArrow / arrowSize | End arrow, start arrow, and size |
radius | Polyline corner radius |
router | Polyline routing: 'orth' | 'tree' | 'indented' | 'fishbone' |
label, plus labelFontSize, labelFontFamily, labelColor | Edge label content. Omitted label draws nothing; the default font size is 10 |
labelPlacement | 'start' | 'center' | 'end' |
labelBackground / labelBackgroundPadding / labelAutoRotate | Background, 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:
| Field | Default | Description |
|---|---|---|
enabled | on | Whether separation runs |
offset | 20 | Graph-space distance between adjacent edges |
mergeBy | source/target | Grouping currently supports the two endpoints |
includeReverse | true | A→B and B→A belong to one group |
minOffset | 0 | Minimum absolute offset for non-center edges |
maxOffset | 80 | Maximum 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.
| Field | Default | Description |
|---|---|---|
scaleWithZoom | true | Whether node-label size follows camera zoom. Edge labels stay in screen space |
hideOnLowZoom | true | Hide labels below their zoom threshold |
hideOnCollision | true | Hide a label that overlaps an earlier one |
nodeMinZoom | 0.3 | Minimum zoom for node labels |
edgeMinZoom | 0.5 | Minimum 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.
type | Effect | Options |
|---|---|---|
zoom-canvas | Wheel zoom | sensitivity default 1, minZoom default 0.1, maxZoom default 20 |
drag-canvas | Drag to pan | ignoreModifierKeys default true, so a modifier key stays available for brush select |
drag-node | Drag a node | No extra options |
drag-edge | Drag an edge endpoint to reconnect it | No extra options |
click-select | Click to select a node or edge | multiple default false; trigger default 'shift', also 'ctrl' or 'meta' |
hover-highlight | Highlight a neighborhood on hover | degree default 1; optional inactiveState |
highlight-node | Hovering a node highlights it, its one-hop neighbors, and the connecting edges | No extra options |
highlight-edge | Hovering an edge highlights it and its endpoints | No extra options |
brush-select | Rectangular selection | key is 'shift', 'ctrl', or null; throttleMs default 100 |
lasso-select | Freeform selection | Same options as brush-select |
tooltip | Overlay | See the table below |
tooltip options:
| Field | Default | Description |
|---|---|---|
trigger | 'hover' | 'hover' or 'click' |
getContent | Node id, or the edge endpoints | Returns a string or HTMLElement. A custom string is written as HTML, so untrusted content must be escaped by the caller |
enable | Always shown | Return false to skip that element |
offset | [10, 10] | Pixel offset from the pointer |
delay | 80 | Milliseconds to wait before a hover tooltip appears |
className | 'g6lite-tooltip' | Overlay class name |
container | document.body | DOM 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'.