logo

G6

  • Docs
  • API
  • Playground
  • Community
  • Productsantv logo arrow
  • 5.0.49
  • 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
      • Common Node Configuration
      • Circle Node
      • Diamond Node
      • Donut Node
      • Ellipse Node
      • Hexagon Node
      • HTML Node
      • Image Node
      • Rect Node
      • Star Node
      • Triangle Node
      • Custom Node
      • Define Nodes with React
    • Edge
      • Edge Overview
      • Edge Common Configuration
      • Cubic Bezier Curve Edge
      • CubicHorizontal Bezier Curve Edge
      • CubicVertical Bezier Curve Edge
      • Line Edge
      • Polyline Edge
      • Quadratic Bezier Curve Edge
      • Custom Edge
    • Combo
      • Combo Overview
      • Combo Common Options
      • Circle Combo
      • Rect Combo
      • Custom Combo
    • Shape
      • Shape and KeyShape
      • Atomic Shapes and Their Properties
      • Design and Implementation of Composite Shape
  • Layout
    • Layout Overview
    • Common Layout Configuration Options
    • AntvDagre Layout
    • Circular Layout
    • ComboCombined Layout
    • CompactBox Layout
    • Concentric Layout
    • 3D Force-Directed Layout
    • D3 Force-Directed Layout
    • Dagre Layout
    • Dendrogram Layout
    • Fishbone Layout
    • ForceAtlas2 Force-directed Layout
    • 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
    • ZoomCanvas
    • AutoAdaptLabel
    • BrushSelect
    • ClickSelect
    • CollapseExpand
    • CreateEdge
    • DragCanvas
    • DragElement
    • DragElementForce
    • FixElementSize
    • FocusElement
    • HoverActivate
    • LassoSelect
    • OptimizeViewportTransform
    • ScrollCanvas
    • Custom Behavior
  • Plugin
    • Plugin Overview
    • Background
    • BubbleSets
    • Contextmenu
    • EdgeBundling
    • EdgeFilterLens
    • Fisheye
    • Fullscreen
    • GridLine
    • History
    • Hull
    • Legend
    • Minimap
    • Snapline
    • Timebar
    • Toolbar
    • Tooltip
    • Watermark
    • Custom Plugin
  • Transform
    • Data Transformation Overview
    • 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

Edge Common Configuration

Previous
Edge Overview
Next
Cubic Bezier Curve Edge

Resource

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-Interactive solution
xtechLiven Experience technology
© Copyright 2025 Ant Group Co., Ltd..备案号:京ICP备15032932号-38

Loading...

This document introduces the built-in edge common property configurations.

EdgeOptions

import { Graph } from '@antv/g6';
const graph = new Graph({
edge: {
type: 'line', // Edge type
style: {}, // Edge style
state: {}, // State styles
palette: {}, // Palette configuration
animation: {}, // Animation configuration
},
});
PropertyDescriptionTypeDefaultRequired
typeEdge type, built-in edge type name or custom edge nameTypeline
styleEdge style configuration, including color, thickness, etc.Style-
stateStyle configuration for different statesState-
paletteDefine edge palette for mapping colors based on different dataPalette-
animationDefine edge animation effectsAnimation-

Type

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 configuration
type: 'line',
// Dynamic configuration - arrow function form
type: (datum) => datum.data.edgeType || 'line',
// Dynamic configuration - regular function form (can access graph instance)
type: function (datum) {
console.log(this); // graph instance
return datum.data.importance > 5 ? 'polyline' : 'line';
},
},
});

Available values:

  • line: Straight line edge
  • polyline: Polyline edge
  • cubic: Cubic Bezier curve edge
  • cubic-horizontal: Horizontal cubic Bezier curve edge
  • cubic-vertical: Vertical cubic Bezier curve edge
  • quadratic: Quadratic Bezier curve edge

Style

Define 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 configuration
stroke: '#1783FF',
// Dynamic configuration - arrow function form
lineWidth: (datum) => (datum.data.isImportant ? 3 : 1),
// Dynamic configuration - regular function form (can access graph instance)
lineDash: function (datum) {
console.log(this); // graph instance
return datum.data.type === 'dashed' ? [5, 5] : [];
},
// Nested properties also support dynamic configuration
labelText: (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 edge
  • badge: Badge on the edge
  • halo: The halo effect graphic displayed around the main graphic
  • startArrow: Arrow at the starting end of the edge
  • endArrow: Arrow at the ending end of the edge

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

Main Graphic Styles

The main graphic is the core part of the edge, defining the basic path and appearance of the edge. Here are common configuration scenarios:

Basic Style Configuration

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 edge
lineWidth: 2, // Edge width
},
},
});
graph.render();

Dashed Line Style

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 style
lineDashOffset: 0,
},
},
});
graph.render();

Shadow Effect

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:

PropertyDescriptionTypeDefaultRequired
cursorMouse cursor style when hovering over edge, optionsstringdefault
increasedLineWidthForHitTestingWhen lineWidth is small, the interactive area also becomes small. We can increase this area to make "thin lines" easier to pick upnumber0
lineDashEdge dash line stylenumber[]-
lineDashOffsetEdge dash line offsetnumber0
lineWidthEdge widthnumber1
opacityEdge opacitynumber | string1
pointerEventsHow edge responds to pointer events, optionsstringauto
shadowBlurEdge shadow blurnumber-
shadowColorEdge shadow colorstring-
shadowOffsetXEdge shadow offset in x directionnumber | string-
shadowOffsetYEdge shadow offset in y directionnumber | string-
shadowTypeEdge shadow typeinner | outerouter
sourcePortConnection port at the source end of the edgestring-
strokeEdge colorstring#000
strokeOpacityEdge color opacitynumber | string1
targetPortConnection port at the target end of the edgestring-
transformTransform property allows you to rotate, scale, skew, or translate the given edgestring-
transformOriginThe center of rotation and scaling, also known as the transform centerstring-
visibilityWhether the edge is visiblevisible | hiddenvisible
zIndexEdge rendering layernumber1

PointerEvents

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 events
  • visiblepainted: Responds to events only when the following conditions are met:
    • visibility is set to visible, i.e., the graphic is visible
    • Triggered in the graphic stroke area while stroke takes a non-none value
  • visiblestroke: Responds to events only when the following conditions are met:
    • visibility is set to visible, i.e., the graphic is visible
    • Triggered in the graphic stroke area, not affected by stroke value
  • visible: Responds to events only when the following conditions are met:
    • visibility is set to visible, i.e., the graphic is visible
    • Triggered in the graphic stroke area, not affected by stroke value
  • painted: Responds to events only when the following conditions are met:
    • Triggered in the graphic stroke area while stroke takes a non-none value
    • Not affected by visibility value
  • stroke: Responds to events only when the following conditions are met:
    • Triggered in the graphic stroke area, not affected by stroke value
    • Not affected by visibility value
  • all: Responds to events as long as entering the graphic stroke area, not affected by stroke or visibility values

Usage Examples:

// Example 1: Only stroke area responds to events
const graph = new Graph({
edge: {
style: {
stroke: '#000',
lineWidth: 2,
pointerEvents: 'stroke', // Only stroke responds to events
},
},
});
// Example 2: Completely non-responsive to events
const graph = new Graph({
edge: {
style: {
pointerEvents: 'none', // Edge does not respond to any events
},
},
});

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

Label Styles

Labels are used to display text information for edges, supporting various style configurations and layout options. Here are common usage scenarios:

Basic Text Label

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();

Multi-line Text Label

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();

Label with Background

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();

Auto-rotating Label

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 rotate
labelFill: '#1890FF',
labelFontWeight: 'bold',
labelPlacement: 'center',
},
},
});
graph.render();

The following is the complete label style configuration:

PropertyDescriptionTypeDefaultRequired
labelWhether to show edge labelbooleantrue
labelAutoRotateWhether edge label automatically rotates to align with edge directionbooleantrue
labelCursorMouse cursor style when hovering over edge label, optionsstringdefault
labelFillEdge label text colorstring-
labelFontFamilyEdge label font familystring-
labelFontSizeEdge label font sizenumber12
labelFontStyleEdge label font stylenormal | italic | oblique-
labelFontVariantEdge label font variantnormal | small-caps | string-
labelFontWeightEdge label font weightnormal | bold | bolder | lighter | number-
labelLeadingLine spacingnumber0
labelLetterSpacingEdge label letter spacingnumber | string-
labelLineHeightEdge label line heightnumber | string-
labelMaxLinesEdge label maximum linesnumber1
labelMaxWidthEdge label maximum width, optionsnumber | string200%
labelOffsetXEdge label offset in x directionnumber0
labelOffsetYEdge label offset in y directionnumber0
labelPaddingEdge label paddingnumber | number[]0
labelPlacementEdge label position relative to edge, optionsstring | numbercenter
labelTextEdge label text contentstring | (datum) => string-
labelTextAlignEdge label text horizontal alignmentstart | center | middle | end | left | rightleft
labelTextBaselineEdge label text baselinetop | hanging | middle | alphabetic | ideographic | bottom-
labelTextDecorationColorEdge label text decoration line colorstring-
labelTextDecorationLineEdge label text decoration linestring-
labelTextDecorationStyleEdge label text decoration line stylesolid | double | dotted | dashed | wavy-
labelTextOverflowEdge label text overflow handlingclip | ellipsis | string-
labelTextPathEdge label text pathPath-
labelWordWrapWhether to enable automatic line wrapping for edge labels. When enabled, text exceeding labelMaxWidth will wrapbooleanfalse
labelZIndexEdge label rendering layernumber0

LabelPlacement

Edge label position relative to the edge, can be set to:

  • start: Label positioned at the starting point of the edge
  • center: Label positioned at the center of the edge (default)
  • end: Label positioned at the ending point of the edge
  • number: Value range 0-1, representing the specific position ratio of the label on the edge, 0 for start position, 1 for end position

LabelMaxWidth

After enabling automatic line wrapping labelWordWrap, text exceeding this width will wrap:

  • string: Represents the maximum width defined as a percentage relative to the edge length. For example, 50% means the label width does not exceed half the edge length
  • number: Represents the maximum width defined in pixels. For example, 100 means the label's maximum width is 100 pixels

For example, setting multi-line label text:

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

Label Background Styles

Label background is used to display the background of edge labels:

PropertyDescriptionTypeDefault
labelBackgroundWhether to show edge label backgroundbooleanfalse
labelBackgroundCursorEdge label background mouse cursor style, optionsstringdefault
labelBackgroundFillEdge label background fill colorstring-
labelBackgroundFillOpacityEdge label background opacitynumber1
labelBackgroundHeightEdge label background heightstring | number-
labelBackgroundLineDashEdge label background dash line configurationnumber | string |(number | string )[]-
labelBackgroundLineDashOffsetEdge label background dash line offsetnumber-
labelBackgroundLineWidthEdge label background stroke line widthnumber-
labelBackgroundRadiusEdge label background border radius
- number: Uniform radius for all corners
- number[]: Individual radius for each corner, auto-filled if insufficient
number | number[]0
labelBackgroundShadowBlurEdge label background shadow blurnumber-
labelBackgroundShadowColorEdge label background shadow colorstring-
labelBackgroundShadowOffsetXEdge label background shadow X offsetnumber-
labelBackgroundShadowOffsetYEdge label background shadow Y offsetnumber-
labelBackgroundStrokeEdge label background stroke colorstring-
labelBackgroundStrokeOpacityEdge label background stroke opacitynumber | string1
labelBackgroundVisibilityEdge label background visibilityvisible | hidden-
labelBackgroundZIndexEdge label background rendering layernumber1

Halo Styles

Halo is an effect displayed around the edge main graphic, usually used for highlighting or indicating special states of the edge.

Basic Halo Effect

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:

PropertyDescriptionTypeDefaultRequired
haloWhether to show edge halobooleanfalse
haloCursorEdge halo mouse cursor style, optionsstringdefault
haloDraggableWhether edge halo allows draggingbooleantrue
haloDroppableWhether edge halo allows receiving dragged elementsbooleantrue
haloFillRuleEdge halo fill rulenonzero | evenodd-
haloFilterEdge halo filterstring-
haloLineWidthEdge halo stroke widthnumber3
haloPointerEventsWhether edge halo responds to pointer events, optionsstringnone
haloStrokeEdge halo stroke color, this property sets the color of the halo around the edgestringConsistent with main graphic stroke color
haloStrokeOpacityEdge halo stroke opacitynumber0.25
haloVisibilityEdge halo visibilityvisible | hiddenvisible
haloZIndexEdge halo rendering layernumber-1

Arrow Styles

Edges support adding arrows at the start and end points to indicate the directionality of the edge.

Basic Arrow

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 arrow
endArrowType: 'vee', // Arrow type
endArrowSize: 10, // Arrow size
},
},
});
graph.render();

Bidirectional Arrows

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 arrow
startArrowType: 'circle',
startArrowSize: 8,
endArrow: true, // End arrow
endArrowType: 'triangle',
endArrowSize: 10,
},
},
});
graph.render();

Custom Arrow Style

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 arrow
endArrowSize: 12,
endArrowFill: '#FF4D4F', // Red arrow fill
endArrowStroke: '#722ED1', // Arrow stroke color
endArrowStrokeOpacity: 0.8,
},
},
});
graph.render();

Start Arrow Style Configuration

PropertyDescriptionTypeDefaultRequired
startArrowWhether to show edge start arrowbooleanfalse
startArrowCursorEdge start arrow mouse cursor style, optionsstringdefault
startArrowFillEdge start arrow fill colorstringDefault consistent with edge color
startArrowFillOpacityEdge start arrow fill opacitynumber1
startArrowOffsetEdge start arrow offsetnumber0
startArrowSizeEdge start arrow sizenumber | [number, number]10
startArrowStrokeEdge start arrow stroke colorstringDefault consistent with edge color
startArrowStrokeOpacityEdge start arrow stroke opacitynumber1
startArrowTypeEdge start arrow typetriangle | circle | diamond | vee | rect | triangleRect | simplevee

End Arrow Style Configuration

PropertyDescriptionTypeDefaultRequired
endArrowWhether to show edge end arrowbooleanfalse
endArrowCursorEdge end arrow mouse cursor style, optionsstringdefault
endArrowFillEdge end arrow fill colorstringDefault consistent with edge color
endArrowFillOpacityEdge end arrow fill opacitynumber1
endArrowOffsetEdge end arrow offsetnumber0
endArrowSizeEdge end arrow sizenumber | [number, number]10
endArrowStrokeEdge end arrow stroke colorstringDefault consistent with edge color
endArrowStrokeOpacityEdge end arrow stroke opacitynumber1
endArrowTypeEdge end arrow typetriangle | circle | diamond | vee | rect | triangleRect | simplevee

Loop Edge Styles

Loop edges are special edges where the start and end nodes are the same node.

Basic Loop Edge

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 position
loopDist: 30, // Loop size
},
},
});
graph.render();

Multiple Loop Edges

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:

PropertyDescriptionTypeDefaultRequired
loopWhether to enable loop edgesbooleantrue
loopClockwiseWhether to draw the loop clockwisebooleantrue
loopDistDistance from node edge to loop top, used to specify loop curvaturenumberDefault to max node size
loopPlacementLoop edge positionleft | right | top | bottom | left-top | left-bottom | right-top | right-bottom | top-left | top-right | bottom-left | bottom-righttop

State

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();

Animation

Define edge animation effects. Supports the following two configuration methods:

  1. Disable all edge animations
{
"edge": {
"animation": false
}
}
  1. Configure stage animations

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 canvas
  • update: Animation when edge updates
  • exit: Animation when edge leaves the canvas
  • show: Animation when edge shows from hidden state
  • hide: Animation when edge hides
  • collapse: Animation when edge collapses
  • expand: Animation when edge expands

You 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
}
}
}

Palette

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.

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

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();