This document introduces node properties.
Property | Description | Type | Default Value |
---|---|---|---|
type | Node type, either a built-in node type name or a custom node name | string | circle |
style | Node style, including color, size, etc. | Style | - |
state | Defines styles for nodes in different states | Record<string, Style> | - |
palette | Defines the color palette for nodes, used to map colors to different data | Palette | - |
animation | Defines animation effects for nodes | Animation | - |
type
Specifies the node type, either a built-in node type name or a custom node name. Defaults to circle
. For more built-in supported node types, refer to the Node Registry.
style
Defines the node's style, including color, size, etc.
For an in-depth understanding of node composition, read Core Concepts - Element - Node.
The following style will be explained sequentially based on atomic shapes:
key
Property | Description | Type | Default Value |
---|---|---|---|
x | x-coordinate | number | 0 |
y | y-coordinate | number | 0 |
z | z-coordinate | number | 0 |
size | Node size, a shortcut to set the width, height, and depth of the node - If the value is a number, it sets the same width, height, and depth for the node - If the value is an array, it specifies width, height, and depth sequentially | number | [number, number] | Float32Array | [number, number, number] | 32 |
fill | Fill color | string | #1783FF |
stroke | Stroke color | string | #000 |
lineWidth | Stroke width | number | string | 1 |
collapsed | Whether the current node/group is expanded | boolean | false |
{StyleProps} | Additional shape options, refer to DisplayObject options. For instance, fillOpacity indicates the transparency of the main shape's fill color | DisplayObject | - |
label
Property | Description | Type | Default Value |
---|---|---|---|
label | Whether to display the node label | boolean | true |
labelText | Label text content | string | - |
labelFill | Label text color | string | - |
labelFontSize | Label font size | number | 12 |
labelFontWeight | Label font weight | number | string | normal |
labelPlacement | Label position relative to the main shape of the node | left | right | top | bottom | left-top | left-bottom | right-top | right-bottom | top-left | top-right | bottom-left | bottom-right | center | bottom |
labelOffsetX | Label offset in the x-axis direction | number | 0 |
labelOffsetY | Label offset in the y-axis direction | number | 0 |
labelWordWrap | Whether to enable word wrapping. When labelWordWrap is enabled, content exceeding labelMaxWidth automatically wraps | boolean | false |
labelMaxWidth | Maximum label width. When word wrapping is enabled, the label wraps at this width - string : Defines the maximum width as a percentage of the node width, e.g., 50% means the label width does not exceed half of the node width - number : Defines the maximum width in pixels, e.g., 100 means the maximum label width is 100 pixels | number | string | 200% |
labelMaxLines | Maximum number of lines | number | 1 |
labelPadding | Padding inside the label | number | number[] | 0 |
label{StyleProps} | Additional label style options, refer to TextStyleProps. For instance, labelFontSize specifies the label font size | TextStyleProps | - |
labelBackground | Whether to display a background | boolean | false |
labelBackgroundFill | Label background fill color | string | - |
labelBackgroundRadius | Label background corner radius - number : Sets the same radius for all four corners - number[] : Sets the radius for each corner | number | number[] | 0 |
labelBackground{StyleProps} | Additional label background style options, refer to RectStyleProps. For instance, labelBackgroundFillOpacity specifies the transparency of the label background | RectStyleProps | - |
halo
Property | Description | Type | Default Value |
---|---|---|---|
halo | Whether to display a halo effect around the node | boolean | false |
haloFill | Halo fill color | string | Same as the fill color of the main shape |
haloStroke | Halo stroke color | string | Same as the stroke color of the main shape |
haloLineWidth | Halo stroke width | number | 3 |
halo{StyleProps} | Additional halo style options, refer to DisplayObject. For instance, haloFillOpacity specifies the transparency of the halo's fill color | DisplayObject | - |
icon
Property | Description | Type | Default Value |
---|---|---|---|
icon | Whether to display an icon on the node | boolean | true |
iconSrc | Image source. Overrides iconText | string | - |
iconWidth | Image width | number | Half of the main shape's width |
iconHeight | Icon height | number | Half of the main shape's height |
iconRadius | Icon corner radius | number | 0 |
iconText | Icon text | string | - |
iconFill | Icon text color | string | - |
iconFontSize | Icon font size | number | 16 |
iconFontWeight | Icon font weight | number | string | normal |
icon{StyleProps} | Additional icon style options, refer to TextStyleProps and ImageStyleProps. For instance, iconFontSize specifies the font size for icon text | TextStyleProps | ImageStyleProps | - |
badges
Property | Description | Type | Default Value |
---|---|---|---|
badge | Whether to display node badges | boolean | true |
badges | Sets the badges | BadgeStyleProps[] | - |
badgePalette | Background color palette for badges | string[] | [#7E92B5 , #F4664A , #FFBE3A ] |
badge{StyleProps} | General badge style options applied to each badge individually. Badge-specific styles in badges take precedence over this setting | BadgeStyleProps | - |
Property | Description | Type | Default Value |
---|---|---|---|
placement | Badge position relative to the main shape of the node. If unspecified, badges are placed clockwise starting from the top-right corner by default | left | right | top | bottom | left-top | left-bottom | right-top | right-bottom | top-left | top-right | bottom-left | bottom-right | - |
offsetX | Horizontal offset for the badge | number | 0 |
offsetY | Vertical offset for the badge | number | 0 |
text | Text content for the badge | string | - |
fill | Text color | string | - |
fontSize | Font size | number | 8 |
fontWeight | Font weight | number | string | normal |
padding | Padding inside the badge | number | number[] | 0 |
{StyleProps} | Additional text style options. Refer to TextStyleProps | TextStyleProps | - |
background | Whether to display a background | boolean | true |
backgroundFill | Background fill color. If unspecified, the colors are assigned sequentially from badgePalette | string | - |
backgroundRadius | Background corner radius - number : Sets the same radius for all four corners - number[] : Sets individual corner radii, completing any missing values - string : Similar to the CSS padding property with space-separated values | number | number[] | string | 0 |
background{StyleProps} | Additional background style options. Refer to RectStyleProps. For instance, backgroundFillOpacity adjusts the transparency of the background color | RectStyleProps | - |
Example: Adding three badges with different meanings to a node:
{"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}}}
The resulting 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 },);
ports
Property | Description | Type | Default Value |
---|---|---|---|
port | Whether to display connection ports | boolean | true |
ports | Connection port options, supporting multiple ports | PortStyleProps[] | - |
port{StyleProps} | Additional connection port styles. Refer to PortStyleProps. For example, portR specifies the radius of circular ports | PortStyleProps | - |
Property | Description | Type | Default Value |
---|---|---|---|
r | Port radius - If undefined, the port is treated as a point, not visible on the canvas, but edges will connect to the nearest port - If a number, the port is treated as a circle with the specified radius | number | - |
linkToCenter | Whether edges connect to the center of the port. - If true , edges connect to the center - If false , edges connect to the port's boundary | boolean | false |
{StyleProps} | Additional port styles. Refer to CircleStyleProps | CircleStyleProps | - |
Example: Adding four connection ports to a node:
{"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 resulting 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 certain interactive behaviors, such as selecting a node by clicking or activating an edge by hovering, the element merely undergoes a state change to indicate its status. To visually reflect these state changes for end users, different graphical styles must be defined for each state, which respond to state transitions of the element.
G6 provides several built-in states, including selected, highlight, active, inactive, and disabled. Additionally, it supports custom states to meet specific needs. Developers can define a set of style rules for each state, which override the default styles of the element.
For example, when a node is in the focus
state, a stroke with a width of 3 and the color orange can be added.
{"node": {"state": {"focus": {"lineWidth": 3,"stroke": "orange"}}}}
The resulting 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 animation effect of the node, and supports the following two configuration methods:
{"node": {"animation": false}}
Stage animation is the animation effect of a node when it enters the graph, updates, and leaves the graph. Currently supported stages include:
enter
: animation when a node enters the graphupdate
: animation when the node is updated.exit
: animation when the node leaves the graphshow
: animation when the node is shown from hidden statehide
: 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 configure the node using the animation syntax, e.g.:
{"node": {"animation": {"update": [{"fields": ["x", "y"], // update animates only the x and y attributes"duration": 1000, // duration of the animation"easing": "linear" // the easing function}]}}}
Built-in animation effects can also be used:
{"node": {"animation": {"enter": "fade", // use a fade animation"update": "translate", // Use a panning animation."exit": "fade" // Use the fade animation.}}}
You can pass in false to turn off animation for a particular stage:
{"node": {"animation": {"enter": false // Turn off the node entry animation.}}}
palette
This defines the node's palette, a predefined set of node colors that are allocated according to specific rules, with the colors mapped to the fill
property.
For the definition of a palette, please refer to Core Concepts - Palette.
Property | Description | Type | Default Value |
---|---|---|---|
type | Specifies the type of the current palette. - group : Discrete palette - value : Continuous palette | group | value | group |
field | Specifies the grouping attribute in the node's data. If not specified, the default grouping attribute is id . | string | ((datum) => string) | id |
color | The palette colors. If the palette has been previously registered, its name can be specified directly, or an array of color values can be provided. | string | string[] | - |
invert | Whether to invert the color palette. | boolean | false |
For example, when assigning node colors based on the category
attribute, ensuring nodes in the same category share the same color:
{"node": {"palette": {"type": "group","field": "category","color": ["#1783FF", "#F08F56", "#D580FF", "#00C9C9", "#7863FF"]}}}
The result is displayed in the following figure:
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 },);
Alternatively, the default configuration can also be used:
{"node": {"palette": "tableau" // 'tableau' is the name of the palette, and colors are allocated based on the ID by default.}}
The result is displayed in the following figure:
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 },);