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

Node Overview

Previous
Element State
Next
Common Node Configurations

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

What is a Node

A node is one of the basic elements in a graph, representing an entity or an abstract concept, such as a person, a place, an organization, etc. Nodes can contain attributes like ID, name, type, etc. In G6, nodes can have various shapes and styles, and support rich interactions and customization.

You can create any number of nodes in a graph and connect them with edges to represent relationships.

Node System

The G6 node system includes three main categories: built-in nodes, extended nodes, and custom nodes. In most cases, built-in nodes are sufficient.

Built-in Nodes

G6 provides a variety of built-in node types, which can be used directly without registration:

Node TypeRegistration NameDescription
Circle NodecircleCommonly used for entities
Rectangle NoderectSuitable for more text and details
Ellipse NodeellipseA variant of the circle
Diamond NodediamondOften used for decision points or special nodes
Triangle NodetriangleCan indicate direction or special marks
Hexagon NodehexagonSuitable for grid layouts and honeycomb charts
Star NodestarHighlights important nodes
Donut NodedonutCan display proportions or progress
Image NodeimageUses an image as the node body
HTML NodehtmlSupports custom HTML content

3D Nodes

@antv/g6-extension-3d provides 3D nodes:

  • Capsule - Capsule-shaped node
  • Cone - Cone-shaped node
  • Cube - Cube-shaped node
  • Cylinder - Cylinder-shaped node
  • Plane - Plane node
  • Sphere - Sphere node
  • Torus - Torus node

React Nodes

@antv/g6-extension-react provides React nodes, supporting the use of React components as the node body. For detailed tutorials, please refer to the Using React to Define Nodes document.

Custom Nodes

When built-in and extended nodes cannot meet the requirements, G6 offers powerful customization capabilities:

  • Extend built-in nodes
  • Create entirely new node types

Unlike built-in nodes, custom nodes need to be registered before use. For detailed tutorials, please refer to the Custom Nodes document.

Data Structure

When defining nodes, you need to add a nodes field to the graph's data object. Each node is an object with the following structure:

PropertyDescriptionTypeDefaultRequired
idUnique identifier for the node, used to distinguish different nodesstring-✓
typeNode type, either a built-in node type name or a custom node namestring-
dataNode data, used to store custom data such as the node's name, description, etc. Can be accessed via callback functions in style mappingobject-
styleNode style, including visual attributes like position, size, color, etc.object-
statesInitial states of the node, such as selected, active, hover, etc.string[]-
comboThe ID of the combo to which the node belongs, used to organize hierarchical relationships. If none, it is nullstring | null-
childrenCollection of child node IDs, used only in tree graph scenariosstring[]-

An example of a data item in the nodes array:

{
"id": "node-1",
"type": "circle",
"data": { "name": "alice", "role": "Admin" },
"style": { "x": 100, "y": 200, "size": 32, "fill": "violet" },
"states": ["selected"],
"combo": null
}

Configuration Methods

There are three ways to configure nodes, listed in order of priority from high to low:

  • Use graph.setNode() for dynamic configuration
  • Global configuration during graph instantiation
  • Dynamic properties in data

These configuration methods can be used simultaneously. When there are identical configuration items, the method with higher priority will override the one with lower priority.

Using graph.setNode()

After creating the graph instance, you can use graph.setNode() to dynamically set the node's style mapping logic.

This method must be called before graph.render() to take effect and has the highest priority.

graph.setNode({
style: {
type: 'circle',
style: { size: 60, fill: '#7FFFD4', stroke: '#5CACEE', lineWidth: 2 },
},
});
graph.render();

Global Configuration During Graph Instantiation

When instantiating the graph, you can configure node style mapping through node, which is a global configuration and will apply to all nodes.

import { Graph } from '@antv/g6';
const graph = new Graph({
node: {
type: 'circle',
style: { size: 60, fill: '#7FFFD4', stroke: '#5CACEE', lineWidth: 2 },
},
});

Dynamic Configuration in Data

If you need different configurations for different nodes, you can write the configuration into the node data. This configuration method can be directly written into the data in the following form:

const data = {
nodes: [
{
id: 'node-1',
type: 'circle',
style: { size: 60, fill: '#7FFFD4', stroke: '#5CACEE', lineWidth: 2 },
},
],
};

Adjusting Priority

If you want the configuration in the data to have a higher priority than the global configuration, you can do so as follows:

const data = {
nodes: [
{
id: 'node-1',
type: 'circle',
style: { size: 60, fill: '#7FFFD4', stroke: '#5CACEE', lineWidth: 2 },
},
],
};
const graph = new Graph({
node: {
type: 'circle',
style: {
stroke: (d) => d.style.stroke || '#5CACEE',
lineWidth: 2,
},
},
});

Dynamically Updating Nodes

G6 supports dynamically updating the style and state of nodes at runtime:

// Update the style of a single node
graph.updateNodeData([
{
id: 'node-1',
style: {
fill: 'red',
size: 80,
},
},
]);
graph.draw();
// Set node state
graph.setElementState('node-1', ['selected']);

Note

When updating nodes, only the specified attributes will be updated, and unspecified attributes will remain unchanged.

For more node-related APIs, please refer to API - Element Operations.

Node States

Nodes can have different states, such as selected, highlighted, disabled, etc. You can define the display effect of nodes in different states by configuring state styles:

const graph = new Graph({
node: {
style: {
// Default style
fill: '#C6E5FF',
},
// State styles
state: {
selected: {
fill: '#ffa940',
stroke: '#ff7a00',
haloStroke: '#ff7a00',
},
highlight: {
stroke: '#1890ff',
lineWidth: 3,
},
},
},
});

The state system is the foundation for implementing node interaction effects. For more information on states, please refer to Element States.