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

Common Node Configurations

Previous
Node Overview
Next
Diamond

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

This document introduces the common attribute configurations for built-in nodes.

NodeOptions

import { Graph } from '@antv/g6';
const graph = new Graph({
node: {
type: 'circle', // Node type
style: {}, // Node style
state: {}, // State style
palette: {}, // Palette configuration
animation: {}, // Animation configuration
},
});
AttributeDescriptionTypeDefaultRequired
typeNode type, name of built-in or custom nodeTypecircle
styleNode style configuration, including color, sizeStyle-
stateStyle configuration for different statesState-
paletteDefines the node's palette for color mappingPalette-
animationDefines the node's animation effectsAnimation-

Type

Specifies the node type, either a built-in node type name or a custom node name. The default is circle (circle). ⚠️ Note: This determines the shape of the main graphic.

const graph = new Graph({
node: {
type: 'circle',
},
});

Available values include:

  • circle: Circle Node
  • diamond: Diamond Node
  • donut: Donut Node
  • ellipse: Ellipse Node
  • hexagon: Hexagon Node
  • html: HTML Node
  • image: Image Node
  • rect: Rectangle Node
  • star: Star Node
  • triangle: Triangle Node

Style

Defines the node's style, including color, size, etc.

const graph = new Graph({
node: {
style: {},
},
});

A complete node consists of the following parts:

  • key: The main graphic of the node, representing the primary shape, such as a rectangle or circle;
  • label: Text label, usually used to display the node's name or description;
  • icon: Icon graphic, usually used to display the node's icon, which can be an image or text icon;
  • badge: A badge located at the top right corner of the node by default;
  • halo: A halo effect graphic displayed around the main graphic;
  • port: Connection points on the node for connecting edges.

The following style configurations will be explained in sequence by atomic graphics:

Main Graphic Style

The main graphic is the core part of the node, defining the basic shape and appearance of the node:

AttributeDescriptionTypeDefaultRequired
collapsedWhether the current node/group is collapsedbooleanfalse
cursorNode mouse hover style, configuration itemstringdefault
fillNode fill colorstring#1783FF
fillOpacityNode fill color opacitynumber | string1
increasedLineWidthForHitTestingWhen lineWidth is small, the interactive area also becomes smaller, sometimes we want to enlarge this area to make "thin lines" easier to pick upnumber0
lineCapNode stroke end styleround | square | buttbutt
lineDashNode stroke dash stylenumber[]-
lineDashOffsetNode stroke dash offsetnumber-
lineJoinNode stroke join styleround | bevel | mitermiter
lineWidthNode stroke widthnumber1
opacityNode opacitynumber | string1
shadowBlurNode shadow blurnumber-
shadowColorNode shadow colorstring-
shadowOffsetXNode shadow offset in the x-axis directionnumber | string-
shadowOffsetYNode shadow offset in the y-axis directionnumber | string-
shadowTypeNode shadow typeinner | outerouter
sizeNode size, quick setting of node width and height, configuration itemnumber | number[]32
strokeNode stroke colorstring#000
strokeOpacityNode stroke color opacitynumber | string1
transformThe transform attribute allows you to rotate, scale, skew, or translate the given nodestring-
transformOriginRotation and scaling center, also known as the transformation centerstring-
visibilityWhether the node is visiblevisible | hiddenvisible
xNode x coordinatenumber0
yNode y coordinatenumber0
zNode z coordinatenumber0
zIndexNode rendering levelnumber0

Size

Node size, quick setting of node width and height, supports three configuration methods:

  • number: Indicates that the node width and height are the same as the specified value
  • [number, number]: Indicates that the node width and height are represented by the array elements in order, representing the width and height of the node
  • [number, number, number]: Indicates that the node width and height are represented by the array elements in order, representing the width, height, and depth of the node

Cursor

Available values: 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

Example:

const graph = new Graph({
node: {
style: {
fill: '#1783FF', // Fill color
stroke: '#000', // Stroke color
lineWidth: 2, // Stroke width
},
},
});

The effect is as follows:

createGraph(
{
data: {
nodes: [{ id: 'node1', style: { x: 120, y: 40 } }],
},
node: {
style: { fill: '#1783FF', stroke: '#000', lineWidth: 2 },
},
},
{ width: 240, height: 100 },
);

Label Style

Labels are used to display the text information of the node:

AttributeDescriptionTypeDefaultRequired
labelWhether to display the node labelbooleantrue
labelCursorMouse hover style when hovering over the node label, configuration itemstringdefault
labelFillNode label text colorstring-
labelFontFamilyNode label font familystring-
labelFontSizeNode label font sizenumber12
labelFontStyleNode label font stylenormal | italic | oblique-
labelFontVariantNode label font variantnormal | small-caps | string-
labelFontWeightNode label font weightnormal | bold | bolder | lighter | number-
labelLeadingLine spacingnumber0
labelLetterSpacingNode label letter spacingnumber | string-
labelLineHeightNode label line heightnumber | string-
labelMaxLinesMaximum number of lines for the node labelnumber1
labelMaxWidthMaximum width of the node label, configuration itemnumber | string200%
labelOffsetXNode label offset in the x-axis directionnumber0
labelOffsetYNode label offset in the y-axis directionnumber0
labelPaddingNode label paddingnumber | number[]0
labelPlacementNode label position relative to the main graphic of the node, configuration itemstringbottom
labelTextNode label text contentstring-
labelTextAlignNode label text horizontal alignmentstart | center | middle | end | left | `right'left
labelTextBaselineNode label text baselinetop | hanging | middle | alphabetic | ideographic | bottom-
labelTextDecorationColorNode label text decoration line colorstring-
labelTextDecorationLineNode label text decoration linestring-
labelTextDecorationStyleNode label text decoration line stylesolid | double | dotted | dashed | wavy-
labelTextOverflowNode label text overflow handlingclip | ellipsis | string-
labelTextPathNode label text pathPath-
labelWordWrapWhether the node label automatically wraps. When labelWordWrap is enabled, the part exceeding labelMaxWidth automatically wrapsbooleanfalse
labelZIndexNode label rendering levelnumber0

LabelPlacement

Available values: left | right | top | bottom | left-top | left-bottom | right-top | right-bottom | top-left | top-right | bottom-left | bottom-right | center | bottom

LabelMaxWidth

When automatic wrapping labelWordWrap is enabled, it wraps when exceeding this width:

  • string: Defines the maximum width as a percentage of the node width. For example, 50% means the label width does not exceed half of the node width
  • number: Defines the maximum width in pixels. For example, 100 means the maximum width of the label is 100 pixels

For example, set multi-line label text:

{
"labelWordWrap": true,
"labelMaxWidth": 200,
"labelMaxLines": 3
}

Example:

const graph = new Graph({
node: {
style: {
label: true, // Whether to display the node label
labelText: 'Node Name', // Label text content
labelFill: '#000', // Label text color
labelFontSize: 12, // Label font size
labelFontWeight: 'normal', // Label font weight
labelPlacement: 'bottom', // Label position relative to the main graphic of the node
},
},
});

The effect is as follows:

createGraph(
{
data: {
nodes: [
{
id: 'node1',
style: {
x: 120,
y: 40,
label: true,
labelText: 'Node Name',
labelFill: '#000',
labelFontSize: 12,
labelFontWeight: 'normal',
labelPlacement: 'bottom',
},
},
],
},
},
{ width: 240, height: 100 },
);

Label Background Style

The label background is used to display the background of the node label:

AttributeDescriptionTypeDefault
labelBackgroundWhether the node label background is displayedbooleanfalse
labelBackgroundCursorNode label background mouse hover style, configuration itemstringdefault
labelBackgroundFillNode label background fill colorstring-
labelBackgroundFillOpacityNode label background opacitynumber1
labelBackgroundHeightNode label background heightstring | number-
labelBackgroundLineDashNode label background dash configurationnumber | string |(number | string )[]-
labelBackgroundLineDashOffsetNode label background dash offsetnumber-
labelBackgroundLineWidthNode label background stroke widthnumber-
labelBackgroundRadiusNode label background corner radius
- number: Uniformly set four corner radii
- number[]: Set four corner radii separately, automatically supplement if insufficient
number | number[]0
labelBackgroundShadowBlurNode label background shadow blurnumber-
labelBackgroundShadowColorNode label background shadow colorstring-
labelBackgroundShadowOffsetXNode label background shadow X direction offsetnumber-
labelBackgroundShadowOffsetYNode label background shadow Y direction offsetnumber-
labelBackgroundStrokeNode label background stroke colorstring-
labelBackgroundStrokeOpacityNode label background stroke opacitynumber | string1
labelBackgroundVisibilityWhether the node label background is visiblevisible | hidden-
labelBackgroundZIndexNode label background rendering levelnumber1

Example:

const graph = new Graph({
node: {
style: {
labelBackground: true, // Whether to display the node label background
labelBackgroundFill: '#000', // Label background fill
labelBackgroundRadius: 10, // Label background corner radius
labelBackgroundFillOpacity: 0.5, // Label background opacity
},
},
});

The effect is as follows:

createGraph(
{
data: {
nodes: [
{
id: 'node1',
style: {
x: 120,
y: 40,
label: true,
labelText: 'Node Name',
labelFill: '#000',
labelFontSize: 12,
labelFontWeight: 'normal',
labelPlacement: 'bottom',
labelBackground: true,
labelBackgroundFill: '#000',
labelBackgroundRadius: 10,
labelBackgroundFillOpacity: 0.5,
},
},
],
},
},
{ width: 240, height: 100 },
);

Halo Style

AttributeDescriptionTypeDefaultRequired
haloWhether the node halo is displayedbooleanfalse
haloCursorNode halo mouse hover style, configuration itemstrigdefault
haloDraggableWhether the node halo is draggablebooleantrue
haloDroppableWhether the node halo can receive dragged elementsbooleantrue
haloFillRuleNode halo fill rulenonzero | evenodd-
haloFilterNode halo filterstring-
haloLineWidthNode halo stroke widthnumber3
haloPointerEventsWhether the node halo effect responds to pointer events, configuration itemstringnone
haloStrokeNode halo stroke color, this attribute is used to set the color of the halo around the node, helping to highlight the nodestringSame as the main graphic's fill fill
haloStrokeOpacityNode halo stroke color opacitynumber0.25
haloVisibilityNode halo visibilityvisible | hiddenvisible
haloZIndexNode halo rendering levelnumber-1

PointerEvents

Available values: visible | visiblepainted | visiblestroke | non-transparent-pixel | visiblefill | visible | painted | fill | stroke | all | none | auto | inherit | initial | unset

Example:

const graph = new Graph({
node: {
style: {
halo: true, // Whether to display the node halo
haloStroke: '#FF0000', // Node halo stroke color
haloLineWidth: 10, // Node halo stroke width
},
},
});

The effect is as follows:

createGraph(
{
data: {
nodes: [
{
id: 'node1',
style: {
x: 120,
y: 40,
},
},
],
},
node: {
style: {
halo: true,
haloStroke: '#FF0000',
haloLineWidth: 10,
},
},
},
{ width: 240, height: 100 },
);

Icon Style

AttributeDescriptionTypeDefault
iconWhether to display the node iconbooleantrue
iconFillNode icon text colorstring-
iconFontFamilyNode icon font familystring-
iconFontSizeNode icon font sizenumber16
iconFontStyleNode icon font stylenormal | italic | obliquenormal
iconFontVariantNode icon font variantnormal | small-caps | stringnormal
iconFontWeightNode icon font weightnumber | stringnormal
iconHeightNode icon heightnumberHalf of the main graphic height
iconLetterSpacingNode icon text letter spacingnumber | string-
iconLineHeightNode icon text line heightnumber | string-
iconMaxLinesMaximum number of lines for the node icon textnumber1
iconRadiusNode icon corner radiusnumber0
iconSrcNode image source. It takes precedence over iconTextstring-
iconTextNode icon textstring-
iconTextAlignNode icon text horizontal alignmentstart | center | middle | end | left | rightleft
iconTextBaselineNode icon text baselinetop | hanging | middle | alphabetic | ideographic | bottomalphabetic
iconTextDecorationColorNode icon text decoration line colorstring-
iconTextDecorationLineNode icon text decoration linestring-
iconTextDecorationStyleNode icon text decoration line stylesolid | double | dotted | dashed | wavysolid
iconTextOverflowNode icon text overflow handlingclip | ellipsis | stringclip
iconWidthNode icon widthnumberHalf of the main graphic width
iconWordWrapWhether the node icon text automatically wrapsboolean-

Example:

const graph = new Graph({
node: {
style: {
iconText: 'Text', // Icon text
iconFill: '#FF0000', // Icon text color
iconFontSize: 14, // Icon text size
iconFontWeight: 'bold', // Icon text weight
iconFontStyle: 'italic', // Icon text style
},
},
});

The effect is as follows:

createGraph(
{
data: {
nodes: [
{
id: 'node1',
style: {
x: 120,
y: 40,
},
},
],
},
node: {
style: {
iconText: 'Text',
iconFill: '#FF0000',
iconFontSize: 14,
iconFontWeight: 'bold',
iconFontStyle: 'italic',
},
},
},
{ width: 240, height: 100 },
);

Badge Style

AttributeDescriptionTypeDefault
badgeWhether the node displays a badgebooleantrue
badgePaletteBackground color palette for the node badgestring[][#7E92B5, #F4664A, #FFBE3A]
badgesNode badge settingsBadgeStyleProps[]-

BadgeStyleProps

AttributeDescriptionTypeDefault
backgroundWhether the node badge displays a backgroundbooleantrue
backgroundCursorNode badge background mouse hover style, configuration itemstringdefault
backgroundFillNode badge background fill color. If not specified, the badgePalette is assigned in orderstring-
backgroundFillOpacityNode badge background fill opacitynumber1
backgroundFilterNode badge background filterstring-
backgroundHeightNode badge background heightnumber | string-
backgroundLineDashNode badge background dash configurationnumber | string |(number | string )[]-
backgroundLineDashOffsetNode badge background dash offsetnumber-
backgroundLineWidthNode badge background stroke widthnumber-
backgroundRadiusNode badge background corner radius
- number: Uniformly set four corner radii
- number[]: Set four corner radii separately, will supplement missing components
- string: Similar to the CSS padding attribute, using spaces to separate
number | number[] | string0
backgroundShadowBlurNode badge background shadow blurnumber-
backgroundShadowColorNode badge background shadow colorstring-
backgroundShadowOffsetXNode badge background shadow X direction offsetnumber-
backgroundShadowOffsetYNode badge background shadow Y direction offsetnumber-
backgroundStrokeNode badge background stroke colorstring-
backgroundStrokeOpacityNode badge background stroke opacitynumber | string1
backgroundVisibilityWhether the node badge background is visiblevisible | hidden-
backgroundZIndexNode badge background rendering levelnumber-
fillNode badge text colorstring-
fontFamilyNode badge font familystring-
fontSizeNode badge font sizenumber8
fontStyleNode badge font stylenormal | italic | obliquenormal
fontVariantNode badge font variantnormal | small-caps | stringnormal
fontWeightNode badge font weightnumber | stringnormal
lineHeightNode badge line heightstring | number-
lineWidthNode badge line widthstring | number-
maxLinesMaximum number of lines for the node badge textnumber1
offsetXNode badge offset in the x-axis directionnumber0
offsetYNode badge offset in the y-axis directionnumber0
paddingNode badge paddingnumber | number[]0
placementNode badge position relative to the main graphic of the node. If not specified, it defaults to clockwise from the top right cornerleft | right | top | bottom | left-top | left-bottom | right-top | right-bottom | top-left | top-right | bottom-left | bottom-right-
textNode badge text contentstring-
textAlignNode badge text horizontal alignmentstart | center | middle | end | left | rightleft
textBaselineNode badge text baselinetop | hanging | middle | alphabetic | ideographic | bottomalphabetic
textDecorationColorNode badge text decoration line colorstring-
textDecorationLineNode badge text decoration linestring-
textDecorationStyleNode badge text decoration line stylesolid | double | dotted | dashed | wavysolid
textOverflowNode badge text overflow handlingclip | ellipsis | stringclip
visibilityWhether the node badge is visiblevisible | hidden-
wordWrapWhether the node badge text automatically wrapsboolean-
zIndexNode badge rendering levelnumber3

For example, add three badges with different meanings to a node:

const graph = new Graph({
node: {
style: {
badge: true, // Whether to display the badge
badges: [
{ text: 'A', placement: 'right-top' },
{ text: 'Important', placement: 'right' },
{ text: 'Notice', placement: 'right-bottom' },
],
badgePalette: ['#7E92B5', '#F4664A', '#FFBE3A'], // Badge background color palette
badgeFontSize: 7, // Badge font size
},
},
});

The effect is as follows:

createGraph(
{
autoFit: 'center',
data: {
nodes: [{ id: 'node1', states: ['focus'] }],
},
node: {
style: {
badge: true,
badges: [
{ text: 'A', placement: 'right-top' },
{ text: 'Important', placement: 'right' },
{ text: 'Notice', placement: 'right-bottom' },
],
badgePalette: ['#7E92B5', '#F4664A', '#FFBE3A'],
badgeFontSize: 7,
},
},
},
{ width: 200, height: 100 },
);

Port Style

AttributeDescriptionTypeDefaultRequired
portWhether the node displays connection portsbooleantrue
portsNode connection port configuration items, supports multiple connection portsPortStyleProps[]

PortStyleProps

AttributeDescriptionTypeDefaultRequired
keyThe key value of the node connection port, default is the index of the node connection portstring-
placementNode connection port position relative to the main graphic of the nodeleft | right | top | bottom | center | left-top | left-bottom | right-top | right-bottom | top-left | top-right | bottom-left | bottom-right | [number, number]-✓
rNode connection port radius
- If set to undefined, the connection port is considered a point, not displayed on the canvas but exists, and the edge will preferentially connect to the nearest connection port
- If set to a number, the connection port is considered a circle, and the radius of the circle is specified here
number-
linkToCenterWhether the edge connects to the center of the node connection port
- If true, the edge connects to the center of the node connection port
- If false, the edge connects to the edge of the node connection port
booleanfalse
cursorNode connection port mouse hover style, configuration itemstringdefault
fillNode connection port fill colorstring-
fillOpacityNode connection port fill opacitynumber1
isBillboardWhether the node connection port is a Billboard effectboolean-
isSizeAttenuationWhether the node connection port enables size attenuationboolean-
lineDashNode connection port stroke dash configurationnumber | string |(number | string )[]-
lineDashOffsetNode connection port stroke dash offsetnumber-
lineWidthNode connection port stroke widthnumber-
shadowBlurNode connection port shadow blurnumber-
shadowColorNode connection port shadow colorstring-
shadowOffsetXNode connection port shadow X direction offsetnumber-
shadowOffsetYNode connection port shadow Y direction offsetnumber-
strokeNode connection port stroke colorstring-
strokeOpacityNode connection port stroke opacitynumber | string1
visibilityWhether the node connection port is visiblevisible | hiddenvisible
zIndexNode connection port rendering levelnumber2

For example, add four connection ports to a node:

const graph = new Graph({
node: {
style: {
port: true,
ports: [
{ key: 'top', placement: 'top', fill: '#7E92B5' },
{ key: 'right', placement: 'right', fill: '#F4664A' },
{ key: 'bottom', placement: 'bottom', fill: '#FFBE3A' },
{ key: 'left', placement: [0, 0.5], fill: '#D580FF' },
],
portR: 3,
portLineWidth: 1,
portStroke: '#fff',
},
},
});

The effect is as follows:

createGraph(
{
autoFit: 'center',
data: {
nodes: [{ id: 'node1', states: ['focus'] }],
},
node: {
style: {
port: true,
ports: [
{ key: 'top', placement: 'top', fill: '#7E92B5' },
{ key: 'right', placement: 'right', fill: '#F4664A' },
{ key: 'bottom', placement: 'bottom', fill: '#FFBE3A' },
{ key: 'left', placement: [0, 0.5], fill: '#D580FF' },
],
portR: 3,
portLineWidth: 1,
portStroke: '#fff',
},
},
},
{ width: 200, height: 100 },
);

State

In some interactive behaviors, such as clicking to select a node or hovering to activate an edge, it is merely marking certain states on the element. To reflect these states in the visual space seen by the end user, we need to set different graphic element styles for different states to respond to the changes in the element's state.

G6 provides several built-in states, including selected, highlight, active, inactive, and disabled. Additionally, it supports custom states to meet more specific needs. For each state, developers can define a set of style rules that will override the default styles of the element.

The data structure is as follows:

type NodeState = {
[state: string]: NodeStyle;
};

For example, when a node is in the focus state, you can add a stroke with a width of 3 and a color of orange.

const graph = new Graph({
node: {
state: {
focus: {
lineWidth: 3, // Stroke width
stroke: 'orange', // Stroke color
},
},
},
});

The effect is as follows:

createGraph(
{
autoFit: 'center',
data: {
nodes: [{ id: 'node1', states: ['focus'] }],
},
node: {
state: {
focus: {
lineWidth: 3,
stroke: 'orange',
},
},
},
},
{ width: 200, height: 100 },
);

Animation

Defines the node's animation effects, supporting the following two configuration methods:

  1. Turn off all node animations
{
"node": {
"animation": false
}
}
  1. Configure stage animations

Stage animations refer to the animation effects of nodes when entering the canvas, updating, and leaving the canvas. The currently supported stages include:

  • enter: Animation when the node enters the canvas
  • update: Animation when the node updates
  • exit: Animation when the node leaves the canvas
  • show: Animation when the node is displayed from a hidden state
  • hide: Animation when the node is hidden
  • collapse: Animation when the node is collapsed
  • expand: Animation when the node is expanded

You can refer to Animation Paradigm to use animation syntax to configure nodes, such as:

{
"node": {
"animation": {
"update": [
{
"fields": ["x", "y"], // Only animate the x and y attributes during updates
"duration": 1000, // Animation duration
"easing": "linear" // Easing function
}
]
}
}
}

You can also use built-in animation effects:

{
"node": {
"animation": {
"enter": "fade", // Use fade animation
"update": "translate", // Use translate animation
"exit": "fade" // Use fade animation
}
}
}

You can pass in false to turn off animations for specific stages:

{
"node": {
"animation": {
"enter": false // Turn off node entrance animation
}
}
}

Palette

Defines the node's palette, which is a predefined pool of node colors, and assigns colors to the fill attribute based on rules.

For the definition of palettes, please refer to Palette.

AttributeDescriptionTypeDefault
colorPalette color. If the palette is registered, you can directly specify its registered name, or accept a color arraystring | string[]-
fieldSpecifies the grouping field in the element data. If not specified, the default is to take the id as the grouping fieldstring | ((datum) => string)id
invertWhether to invert the palettebooleanfalse
typeSpecifies the current palette type.
- group: Discrete palette
- value: Continuous palette
group | valuegroup

For example, assign node colors based on the category field of a set of data, so that nodes of the same category have the same color:

{
"node": {
"palette": {
"type": "group",
"field": "category",
"color": ["#1783FF", "#F08F56", "#D580FF", "#00C9C9", "#7863FF"]
}
}
}

The effect is as follows:

createGraph(
{
data: {
nodes: new Array(10)
.fill(0)
.map((_, i) => ({ id: `node-${i}`, data: { category: ['A', 'B', 'C', 'D', 'E'][i % 5] } })),
},
layout: { type: 'grid', cols: 10 },
node: {
palette: {
type: 'group',
field: 'category',
color: ['#1783FF', '#F08F56', '#D580FF', '#00C9C9', '#7863FF'],
},
},
},
{ width: 600, height: 100 },
);

You can also use the default configuration:

{
"node": {
"palette": "tableau" // tableau is the palette name, default assigns colors based on ID
}
}

The effect is as follows:

createGraph(
{
data: {
nodes: new Array(10)
.fill(0)
.map((_, i) => ({ id: `node-${i}`, data: { category: ['A', 'B', 'C', 'D', 'E'][i % 5] } })),
},
layout: { type: 'grid', cols: 10 },
node: {
palette: 'tableau',
},
},
{ width: 600, height: 100 },
);