Loading...
This document introduces the built-in edge common property configurations.
import { Graph } from '@antv/g6';const graph = new Graph({edge: {type: 'line', // Edge typestyle: {}, // Edge stylestate: {}, // State stylespalette: {}, // Palette configurationanimation: {}, // Animation configuration},});
Property | Description | Type | Default | Required |
---|---|---|---|---|
type | Edge type, built-in edge type name or custom edge name | Type | line | |
style | Edge style configuration, including color, thickness, etc. | Style | - | |
state | Style configuration for different states | State | - | |
palette | Define edge palette for mapping colors based on different data | Palette | - | |
animation | Define edge animation effects | Animation | - |
Specify the edge type, built-in edge type name or custom edge name. Default is line
(straight line edge). ⚠️ Note: This determines the shape of the main graphic.
const graph = new Graph({edge: {type: 'polyline',},});
⚠️ Dynamic Configuration Note: The type
property also supports dynamic configuration, allowing you to dynamically select edge types based on edge data:
const graph = new Graph({edge: {// Static configurationtype: 'line',// Dynamic configuration - arrow function formtype: (datum) => datum.data.edgeType || 'line',// Dynamic configuration - regular function form (can access graph instance)type: function (datum) {console.log(this); // graph instancereturn datum.data.importance > 5 ? 'polyline' : 'line';},},});
Available values:
line
: Straight line edgepolyline
: Polyline edgecubic
: Cubic Bezier curve edgecubic-horizontal
: Horizontal cubic Bezier curve edgecubic-vertical
: Vertical cubic Bezier curve edgequadratic
: Quadratic Bezier curve edgeDefine edge styles, including color, thickness, etc.
const graph = new Graph({edge: {style: {},},});
⚠️ Dynamic Configuration Note: All the following style properties support dynamic configuration, meaning you can pass functions to dynamically calculate property values based on edge data:
const graph = new Graph({edge: {style: {// Static configurationstroke: '#1783FF',// Dynamic configuration - arrow function formlineWidth: (datum) => (datum.data.isImportant ? 3 : 1),// Dynamic configuration - regular function form (can access graph instance)lineDash: function (datum) {console.log(this); // graph instancereturn datum.data.type === 'dashed' ? [5, 5] : [];},// Nested properties also support dynamic configurationlabelText: (datum) => `Edge: ${datum.id}`,endArrow: (datum) => datum.data.hasArrow,},},});
Where the datum
parameter is the edge data object (EdgeData
), containing all data information of the edge.
A complete edge consists of the following parts:
key
: The main graphic of the edge, representing the main path of the edge, such as straight lines, curves, etc.label
: Text label, usually used to display the name or description of the edgebadge
: Badge on the edgehalo
: The halo effect graphic displayed around the main graphicstartArrow
: Arrow at the starting end of the edgeendArrow
: Arrow at the ending end of the edgeThe following style configurations will be explained by atomic graphics in order:
The main graphic is the core part of the edge, defining the basic path and appearance of the edge. Here are common configuration scenarios:
Set the basic appearance of the edge:
import { Graph } from '@antv/g6';const graph = new Graph({container: 'container',width: 240,height: 100,autoFit: 'center',data: {nodes: [{ id: 'node1', style: { x: 60, y: 40 } },{ id: 'node2', style: { x: 180, y: 40 } },],edges: [{ source: 'node1', target: 'node2' }],},edge: {style: {stroke: '#5B8FF9', // Blue edgelineWidth: 2, // Edge width},},});graph.render();
Create edges with dashed line style:
import { Graph } from '@antv/g6';const graph = new Graph({container: 'container',width: 240,height: 100,autoFit: 'center',data: {nodes: [{ id: 'node1', style: { x: 60, y: 40 } },{ id: 'node2', style: { x: 180, y: 40 } },],edges: [{ source: 'node1', target: 'node2' }],},edge: {style: {stroke: '#F5222D',lineWidth: 2,lineDash: [6, 4], // Dashed line stylelineDashOffset: 0,},},});graph.render();
Add shadow effect to edges:
import { Graph } from '@antv/g6';const graph = new Graph({container: 'container',width: 240,height: 100,autoFit: 'center',data: {nodes: [{ id: 'node1', style: { x: 60, y: 40 } },{ id: 'node2', style: { x: 180, y: 40 } },],edges: [{ source: 'node1', target: 'node2' }],},edge: {style: {stroke: '#722ED1',lineWidth: 3,shadowColor: 'rgba(114, 46, 209, 0.3)',shadowBlur: 8,shadowOffsetX: 2,shadowOffsetY: 2,},},});graph.render();
The following is the complete main graphic style configuration:
Property | Description | Type | Default | Required |
---|---|---|---|---|
cursor | Mouse cursor style when hovering over edge, options | string | default | |
increasedLineWidthForHitTesting | When lineWidth is small, the interactive area also becomes small. We can increase this area to make "thin lines" easier to pick up | number | 0 | |
lineDash | Edge dash line style | number[] | - | |
lineDashOffset | Edge dash line offset | number | 0 | |
lineWidth | Edge width | number | 1 | |
opacity | Edge opacity | number | string | 1 | |
pointerEvents | How edge responds to pointer events, options | string | auto | |
shadowBlur | Edge shadow blur | number | - | |
shadowColor | Edge shadow color | string | - | |
shadowOffsetX | Edge shadow offset in x direction | number | string | - | |
shadowOffsetY | Edge shadow offset in y direction | number | string | - | |
shadowType | Edge shadow type | inner | outer | outer | |
sourcePort | Connection port at the source end of the edge | string | - | |
stroke | Edge color | string | #000 | |
strokeOpacity | Edge color opacity | number | string | 1 | |
targetPort | Connection port at the target end of the edge | string | - | |
transform | Transform property allows you to rotate, scale, skew, or translate the given edge | string | - | |
transformOrigin | The center of rotation and scaling, also known as the transform center | string | - | |
visibility | Whether the edge is visible | visible | hidden | visible | |
zIndex | Edge rendering layer | number | 1 |
The pointerEvents
property controls how graphics respond to interaction events. Refer to MDN documentation.
Available values: visible
| visiblepainted
| visiblestroke
| non-transparent-pixel
| visiblefill
| visible
| painted
| fill
| stroke
| all
| none
| auto
| inherit
| initial
| unset
In short, both stroke
and visibility
can independently or in combination affect hit testing behavior. Currently supports the following keywords:
auto
: Default value, equivalent to visiblepainted
none
: Never becomes a target for responding to eventsvisiblepainted
: Responds to events only when the following conditions are met:
visibility
is set to visible
, i.e., the graphic is visiblestroke
takes a non-none
valuevisiblestroke
: Responds to events only when the following conditions are met:
visibility
is set to visible
, i.e., the graphic is visiblestroke
valuevisible
: Responds to events only when the following conditions are met:
visibility
is set to visible
, i.e., the graphic is visiblestroke
valuepainted
: Responds to events only when the following conditions are met:
stroke
takes a non-none
valuevisibility
valuestroke
: Responds to events only when the following conditions are met:
stroke
valuevisibility
valueall
: Responds to events as long as entering the graphic stroke area, not affected by stroke
or visibility
valuesUsage Examples:
// Example 1: Only stroke area responds to eventsconst graph = new Graph({edge: {style: {stroke: '#000',lineWidth: 2,pointerEvents: 'stroke', // Only stroke responds to events},},});// Example 2: Completely non-responsive to eventsconst graph = new Graph({edge: {style: {pointerEvents: 'none', // Edge does not respond to any events},},});
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
Labels are used to display text information for edges, supporting various style configurations and layout options. Here are common usage scenarios:
The simplest text label configuration:
import { Graph } from '@antv/g6';const graph = new Graph({container: 'container',width: 240,height: 120,autoFit: 'center',data: {nodes: [{ id: 'node1', style: { x: 60, y: 60 } },{ id: 'node2', style: { x: 180, y: 60 } },],edges: [{ source: 'node1', target: 'node2' }],},edge: {style: {labelText: 'Edge Label',labelFill: '#262626',labelFontSize: 12,labelPlacement: 'center',},},});graph.render();
When text is long, you can set automatic line wrapping:
import { Graph } from '@antv/g6';const graph = new Graph({container: 'container',width: 240,height: 120,autoFit: 'center',data: {nodes: [{ id: 'node1', style: { x: 60, y: 60 } },{ id: 'node2', style: { x: 180, y: 60 } },],edges: [{ source: 'node1', target: 'node2' }],},edge: {style: {labelText: 'This is a very long edge label that needs line wrapping',labelWordWrap: true,labelMaxWidth: '200%',labelMaxLines: 2,labelTextOverflow: 'ellipsis',labelFill: '#434343',labelPlacement: 'center',labelTextAlign: 'center',},},});graph.render();
Add background to labels for better readability:
import { Graph } from '@antv/g6';const graph = new Graph({container: 'container',width: 240,height: 120,autoFit: 'center',data: {nodes: [{ id: 'node1', style: { x: 60, y: 60 } },{ id: 'node2', style: { x: 180, y: 60 } },],edges: [{ source: 'node1', target: 'node2' }],},edge: {style: {labelText: 'Important Connection',labelBackground: true,labelBackgroundFill: 'rgba(250, 140, 22, 0.1)',labelBackgroundRadius: 6,labelPadding: [4, 8],labelFill: '#D4380D',labelFontWeight: 'bold',labelPlacement: 'center',},},});graph.render();
Labels can automatically rotate to align with edge direction:
import { Graph } from '@antv/g6';const graph = new Graph({container: 'container',width: 240,height: 120,autoFit: 'center',data: {nodes: [{ id: 'node1', style: { x: 60, y: 30 } },{ id: 'node2', style: { x: 180, y: 90 } },],edges: [{ source: 'node1', target: 'node2' }],},edge: {style: {labelText: 'Auto Rotate',labelAutoRotate: true, // Auto rotatelabelFill: '#1890FF',labelFontWeight: 'bold',labelPlacement: 'center',},},});graph.render();
The following is the complete label style configuration:
Property | Description | Type | Default | Required |
---|---|---|---|---|
label | Whether to show edge label | boolean | true | |
labelAutoRotate | Whether edge label automatically rotates to align with edge direction | boolean | true | |
labelCursor | Mouse cursor style when hovering over edge label, options | string | default | |
labelFill | Edge label text color | string | - | |
labelFontFamily | Edge label font family | string | - | |
labelFontSize | Edge label font size | number | 12 | |
labelFontStyle | Edge label font style | normal | italic | oblique | - | |
labelFontVariant | Edge label font variant | normal | small-caps | string | - | |
labelFontWeight | Edge label font weight | normal | bold | bolder | lighter | number | - | |
labelLeading | Line spacing | number | 0 | |
labelLetterSpacing | Edge label letter spacing | number | string | - | |
labelLineHeight | Edge label line height | number | string | - | |
labelMaxLines | Edge label maximum lines | number | 1 | |
labelMaxWidth | Edge label maximum width, options | number | string | 200% | |
labelOffsetX | Edge label offset in x direction | number | 0 | |
labelOffsetY | Edge label offset in y direction | number | 0 | |
labelPadding | Edge label padding | number | number[] | 0 | |
labelPlacement | Edge label position relative to edge, options | string | number | center | |
labelText | Edge label text content | string | (datum) => string | - | |
labelTextAlign | Edge label text horizontal alignment | start | center | middle | end | left | right | left | |
labelTextBaseline | Edge label text baseline | top | hanging | middle | alphabetic | ideographic | bottom | - | |
labelTextDecorationColor | Edge label text decoration line color | string | - | |
labelTextDecorationLine | Edge label text decoration line | string | - | |
labelTextDecorationStyle | Edge label text decoration line style | solid | double | dotted | dashed | wavy | - | |
labelTextOverflow | Edge label text overflow handling | clip | ellipsis | string | - | |
labelTextPath | Edge label text path | Path | - | |
labelWordWrap | Whether to enable automatic line wrapping for edge labels. When enabled, text exceeding labelMaxWidth will wrap | boolean | false | |
labelZIndex | Edge label rendering layer | number | 0 |
Edge label position relative to the edge, can be set to:
start
: Label positioned at the starting point of the edgecenter
: Label positioned at the center of the edge (default)end
: Label positioned at the ending point of the edgenumber
: Value range 0-1, representing the specific position ratio of the label on the edge, 0 for start position, 1 for end positionAfter enabling automatic line wrapping labelWordWrap
, text exceeding this width will wrap:
50%
means the label width does not exceed half the edge lengthFor example, setting multi-line label text:
{"labelWordWrap": true,"labelMaxWidth": 200,"labelMaxLines": 3}
Label background is used to display the background of edge labels:
Property | Description | Type | Default |
---|---|---|---|
labelBackground | Whether to show edge label background | boolean | false |
labelBackgroundCursor | Edge label background mouse cursor style, options | string | default |
labelBackgroundFill | Edge label background fill color | string | - |
labelBackgroundFillOpacity | Edge label background opacity | number | 1 |
labelBackgroundHeight | Edge label background height | string | number | - |
labelBackgroundLineDash | Edge label background dash line configuration | number | string |(number | string )[] | - |
labelBackgroundLineDashOffset | Edge label background dash line offset | number | - |
labelBackgroundLineWidth | Edge label background stroke line width | number | - |
labelBackgroundRadius | Edge label background border radius - number: Uniform radius for all corners - number[]: Individual radius for each corner, auto-filled if insufficient | number | number[] | 0 |
labelBackgroundShadowBlur | Edge label background shadow blur | number | - |
labelBackgroundShadowColor | Edge label background shadow color | string | - |
labelBackgroundShadowOffsetX | Edge label background shadow X offset | number | - |
labelBackgroundShadowOffsetY | Edge label background shadow Y offset | number | - |
labelBackgroundStroke | Edge label background stroke color | string | - |
labelBackgroundStrokeOpacity | Edge label background stroke opacity | number | string | 1 |
labelBackgroundVisibility | Edge label background visibility | visible | hidden | - |
labelBackgroundZIndex | Edge label background rendering layer | number | 1 |
Halo is an effect displayed around the edge main graphic, usually used for highlighting or indicating special states of the edge.
Add basic halo effect to edges:
import { Graph } from '@antv/g6';const graph = new Graph({container: 'container',width: 240,height: 100,autoFit: 'center',data: {nodes: [{ id: 'node1', style: { x: 60, y: 50 } },{ id: 'node2', style: { x: 180, y: 50 } },],edges: [{ source: 'node1', target: 'node2' }],},edge: {style: {lineWidth: 2,halo: true,haloStroke: '#1890FF',haloLineWidth: 6,haloStrokeOpacity: 0.3,},},});graph.render();
The following is the complete halo style configuration:
Property | Description | Type | Default | Required |
---|---|---|---|---|
halo | Whether to show edge halo | boolean | false | |
haloCursor | Edge halo mouse cursor style, options | string | default | |
haloDraggable | Whether edge halo allows dragging | boolean | true | |
haloDroppable | Whether edge halo allows receiving dragged elements | boolean | true | |
haloFillRule | Edge halo fill rule | nonzero | evenodd | - | |
haloFilter | Edge halo filter | string | - | |
haloLineWidth | Edge halo stroke width | number | 3 | |
haloPointerEvents | Whether edge halo responds to pointer events, options | string | none | |
haloStroke | Edge halo stroke color, this property sets the color of the halo around the edge | string | Consistent with main graphic stroke color | |
haloStrokeOpacity | Edge halo stroke opacity | number | 0.25 | |
haloVisibility | Edge halo visibility | visible | hidden | visible | |
haloZIndex | Edge halo rendering layer | number | -1 |
Edges support adding arrows at the start and end points to indicate the directionality of the edge.
Add basic arrow to the end of the edge:
import { Graph } from '@antv/g6';const graph = new Graph({container: 'container',width: 240,height: 100,autoFit: 'center',data: {nodes: [{ id: 'node1', style: { x: 60, y: 50 } },{ id: 'node2', style: { x: 180, y: 50 } },],edges: [{ source: 'node1', target: 'node2' }],},edge: {style: {stroke: '#1890FF',lineWidth: 2,endArrow: true, // End arrowendArrowType: 'vee', // Arrow typeendArrowSize: 10, // Arrow size},},});graph.render();
Add arrows to both ends of the edge:
import { Graph } from '@antv/g6';const graph = new Graph({container: 'container',width: 240,height: 100,autoFit: 'center',data: {nodes: [{ id: 'node1', style: { x: 60, y: 50 } },{ id: 'node2', style: { x: 180, y: 50 } },],edges: [{ source: 'node1', target: 'node2' }],},edge: {style: {stroke: '#52C41A',lineWidth: 2,startArrow: true, // Start arrowstartArrowType: 'circle',startArrowSize: 8,endArrow: true, // End arrowendArrowType: 'triangle',endArrowSize: 10,},},});graph.render();
Customize arrow color and type:
import { Graph } from '@antv/g6';const graph = new Graph({container: 'container',width: 240,height: 100,autoFit: 'center',data: {nodes: [{ id: 'node1', style: { x: 60, y: 50 } },{ id: 'node2', style: { x: 180, y: 50 } },],edges: [{ source: 'node1', target: 'node2' }],},edge: {style: {stroke: '#722ED1',lineWidth: 3,endArrow: true,endArrowType: 'diamond', // Diamond arrowendArrowSize: 12,endArrowFill: '#FF4D4F', // Red arrow fillendArrowStroke: '#722ED1', // Arrow stroke colorendArrowStrokeOpacity: 0.8,},},});graph.render();
Property | Description | Type | Default | Required |
---|---|---|---|---|
startArrow | Whether to show edge start arrow | boolean | false | |
startArrowCursor | Edge start arrow mouse cursor style, options | string | default | |
startArrowFill | Edge start arrow fill color | string | Default consistent with edge color | |
startArrowFillOpacity | Edge start arrow fill opacity | number | 1 | |
startArrowOffset | Edge start arrow offset | number | 0 | |
startArrowSize | Edge start arrow size | number | [number, number] | 10 | |
startArrowStroke | Edge start arrow stroke color | string | Default consistent with edge color | |
startArrowStrokeOpacity | Edge start arrow stroke opacity | number | 1 | |
startArrowType | Edge start arrow type | triangle | circle | diamond | vee | rect | triangleRect | simple | vee |
Property | Description | Type | Default | Required |
---|---|---|---|---|
endArrow | Whether to show edge end arrow | boolean | false | |
endArrowCursor | Edge end arrow mouse cursor style, options | string | default | |
endArrowFill | Edge end arrow fill color | string | Default consistent with edge color | |
endArrowFillOpacity | Edge end arrow fill opacity | number | 1 | |
endArrowOffset | Edge end arrow offset | number | 0 | |
endArrowSize | Edge end arrow size | number | [number, number] | 10 | |
endArrowStroke | Edge end arrow stroke color | string | Default consistent with edge color | |
endArrowStrokeOpacity | Edge end arrow stroke opacity | number | 1 | |
endArrowType | Edge end arrow type | triangle | circle | diamond | vee | rect | triangleRect | simple | vee |
Loop edges are special edges where the start and end nodes are the same node.
Create a basic loop edge:
import { Graph } from '@antv/g6';const graph = new Graph({container: 'container',width: 200,height: 100,autoFit: 'center',data: {nodes: [{ id: 'node1', style: { x: 100, y: 50 } }],edges: [{ source: 'node1', target: 'node1' }],},edge: {style: {stroke: '#1890FF',lineWidth: 2,endArrow: true,loopPlacement: 'top', // Loop positionloopDist: 30, // Loop size},},});graph.render();
Create multiple loop edges at different positions for the same node:
import { Graph } from '@antv/g6';const graph = new Graph({container: 'container',width: 200,height: 120,autoFit: 'center',data: {nodes: [{ id: 'node1', style: { x: 100, y: 60 } }],edges: [{ id: 'edge1', source: 'node1', target: 'node1' },{ id: 'edge2', source: 'node1', target: 'node1' },{ id: 'edge3', source: 'node1', target: 'node1' },],},edge: {style: {lineWidth: 2,endArrow: true,loopPlacement: (datum) => {const placements = ['top', 'right', 'bottom'];return placements[parseInt(datum.id.slice(-1)) - 1];},loopDist: 25,stroke: (datum) => {const colors = ['#1890FF', '#52C41A', '#722ED1'];return colors[parseInt(datum.id.slice(-1)) - 1];},},},});graph.render();
The following is the complete loop edge style configuration:
Property | Description | Type | Default | Required |
---|---|---|---|---|
loop | Whether to enable loop edges | boolean | true | |
loopClockwise | Whether to draw the loop clockwise | boolean | true | |
loopDist | Distance from node edge to loop top, used to specify loop curvature | number | Default to max node size | |
loopPlacement | Loop edge position | left | right | top | bottom | left-top | left-bottom | right-top | right-bottom | top-left | top-right | bottom-left | bottom-right | top |
In some interactive behaviors, such as clicking to select an edge or hovering to activate an edge, it's simply marking certain states on that element. To reflect these states in the visual space seen by end users, we need to set different graphic element styles for different states to respond to changes in the state of that graphic element.
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 element's default styles.
The data structure is as follows:
type EdgeState = {[state: string]: EdgeStyle;};
For example, when an edge is in the focus
state, you can add a halo with a width of 6 and orange color.
const graph = new Graph({edge: {state: {focus: {halo: true,haloLineWidth: 6,haloStroke: 'orange',haloStrokeOpacity: 0.6,},},},});
The effect is shown in the following image:
import { Graph } from '@antv/g6';const graph = new Graph({container: 'container',width: 300,height: 100,autoFit: 'center',data: {nodes: [{ id: 'node1' }, { id: 'node2' }],edges: [{ source: 'node1', target: 'node2', states: ['focus'] }],},edge: {state: {focus: {halo: true,haloLineWidth: 6,haloStroke: 'orange',},},},layout: {type: 'grid',cols: 2,},});graph.render();
Define edge animation effects. Supports the following two configuration methods:
{"edge": {"animation": false}}
Stage animations refer to the animation effects when edges enter the canvas, update, or leave the canvas. Currently supported stages include:
enter
: Animation when edge enters the canvasupdate
: Animation when edge updatesexit
: Animation when edge leaves the canvasshow
: Animation when edge shows from hidden statehide
: Animation when edge hidescollapse
: Animation when edge collapsesexpand
: Animation when edge expandsYou can refer to Animation Paradigm to use animation syntax to configure edges, such as:
{"edge": {"animation": {"update": [{"fields": ["stroke"], // Only animate stroke property during update"duration": 1000, // Animation duration"easing": "linear" // Easing function}]}}}
You can also use built-in animation effects:
{"edge": {"animation": {"enter": "fade", // Use fade animation"update": "path-in", // Use path animation"exit": "fade" // Use fade animation}}}
You can pass false to disable specific stage animations:
{"edge": {"animation": {"enter": false // Disable edge entrance animation}}}
Define the edge palette, which is a predefined edge color pool that is allocated according to rules and maps colors to the stroke
property.
For palette definitions, please refer to Palette.
Property | Description | Type | Default |
---|---|---|---|
color | Palette colors. If the palette is registered, you can directly specify its registration name, or accept a color array | string | string[] | - |
field | Specify the grouping field in element data. If not specified, defaults to using id as grouping field | string | ((datum) => string) | id |
invert | Whether to invert the palette | boolean | false |
type | Specify current palette type. - group : Discrete palette - value : Continuous palette | group | value | group |
For example, to assign edge colors to a group of data by the direction
field, making edges of the same category have the same color:
{"edge": {"palette": {"type": "group","field": "direction","color": ["#F08F56", "#00C9C9", "#D580FF"]}}}
The effect is shown in the following image:
import { Graph } from '@antv/g6';const graph = new Graph({container: 'container',width: 600,height: 300,data: {nodes: new Array(6).fill(0).map((_, i) => ({ id: `node-${i + 1}` })),edges: [{ source: 'node-1', target: 'node-2', data: { direction: 'out' } },{ source: 'node-1', target: 'node-3', data: { direction: 'out' } },{ source: 'node-1', target: 'node-4', data: { direction: 'out' } },{ source: 'node-5', target: 'node-1', data: { direction: 'in' } },{ source: 'node-6', target: 'node-1', data: { direction: 'in' } },],},layout: {type: 'radial',unitRadius: 120,linkDistance: 120,},edge: {style: {endArrow: true,},palette: {type: 'group',field: 'direction',color: ['#F08F56', '#00C9C9'],},},});graph.render();
You can also use default configuration:
{"edge": {"palette": "tableau" // tableau is the palette name, colors assigned by ID by default}}
The effect is shown in the following image:
import { Graph } from '@antv/g6';const graph = new Graph({container: 'container',width: 600,height: 300,data: {nodes: new Array(6).fill(0).map((_, i) => ({ id: `node-${i + 1}` })),edges: [{ source: 'node-1', target: 'node-2', data: { direction: 'out' } },{ source: 'node-1', target: 'node-3', data: { direction: 'out' } },{ source: 'node-1', target: 'node-4', data: { direction: 'out' } },{ source: 'node-5', target: 'node-1', data: { direction: 'in' } },{ source: 'node-6', target: 'node-1', data: { direction: 'in' } },],},layout: {type: 'radial',unitRadius: 120,linkDistance: 120,},edge: {style: {endArrow: true,},palette: 'tableau',},});graph.render();