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 Edge Configurations

Previous
Edge Overview
Next
Cubic Bezier Curve

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 article introduces edge property configuration, with configuration locations as follows:

import { Graph } from '@antv/g6';
const graph = new Graph({
edge: {
type: 'line', // Edge type configuration
style: {}, // Edge style configuration
state: {}, // Edge state style
palette: {}, // Edge palette configuration
animation: {}, // Edge animation configuration
},
});

EdgeOptions

AttributeDescriptionTypeDefaultRequired
typeEdge type, name of built-in edge type or custom edgeTypeline
styleEdge style, including color, size, etc.Style-
stateDefine styles of edges in different statesState-
paletteDefine the palette of edges, used to map colors based on different dataPalette-
animationDefine the animation effects of edgesAnimation-

Type

Specify the edge type, name of built-in edge type or custom edge. The default is line (straight edge).

const graph = new Graph({
edge: {
type: 'polyline', // Edge type configuration
},
});

Optional values are:

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

Style

Define the style of the edge, including color, size, etc.

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

A complete edge consists of the following parts:

To understand the composition of edges, please read Element - Edge.

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

Main Graphic Style Key

AttributeDescriptionDefaultType
classEdge classNamestring-
cursorEdge mouse hover style, configuration itemstringdefault
fillEdge area fill colorstring-
fillRuleEdge internal fill rulenonzero | evenodd-
filterEdge shadow filter effectstring-
increasedLineWidthForHitTestingWhen the edge width is too small, it can be used to enlarge the interaction areastring | number-
isBillboardEffective in 3D scenes, always facing the screen, so the line width is not affected by perspective projectiontrueboolean
lineDashEdge dashed line style0number
lineDashOffsetEdge dashed line offsetnumber0
lineWidthEdge width1number
opacityOverall opacity of the edgenumber1
pointerEventsWhether the edge responds to pointer events, configuration itemstring-
shadowBlurEdge shadow blur effectnumber-
shadowColorEdge shadow colorstring-
shadowOffsetXEdge shadow X-axis offsetnumber-
shadowOffsetYEdge shadow Y-axis offsetnumber-
shadowTypeEdge shadow typeinner | outer | both-
sourcePortSource port of the edge connection-string
strokeEdge color#000string
strokeOpacityEdge color opacitynumber1
targetPortTarget port of the edge connection-string
transformThe transform attribute allows you to rotate, scale, skew, or translate the given edgestring-
transformOriginRotation and scaling center, also known as the transformation centerstring-
visibilityWhether the edge is visiblevisible | hiddenvisible
zIndexEdge rendering levelnumber1

PointerEvents

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

Cursor

Optional values are: 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({
edge: {
style: {
stroke: '#1783F', // Edge color
lineWidth: 2, // Edge width
},
},
});

The effect is as follows:

createGraph(
{
data: {
nodes: [
{ id: 'node1', style: { x: 60, y: 40 } },
{ id: 'node2', style: { x: 180, y: 40 } },
],
edges: [{ source: 'node1', target: 'node2' }],
},
node: {
style: { fill: '#1783FF' },
},
edge: {
style: {
stroke: '#FF0000', // Edge color
lineWidth: 2, // Edge width
},
},
},
{ width: 240, height: 100 },
);

Label Style

AttributeDescriptionTypeDefault
labelWhether the edge label is displayedbooleantrue
labelAutoRotateWhether the edge label auto-rotates to keep consistent with the edge directionbooleantrue
labelBackgroundWhether the edge label displays a backgroundbooleanfalse
labelBackgroundClassEdge label background classNamestring-
labelBackgroundCursorEdge label background mouse hover style, configuration itemstringdefault
labelBackgroundFillEdge label background fill colorstring-
labelBackgroundFillOpacityEdge label background opacitynumber1
labelBackgroundHeightEdge label background heightstring | number-
labelBackgroundLineDashEdge label background dashed line configurationnumber | string |(number | string )[]-
labelBackgroundLineDashOffsetEdge label background dashed line offsetnumber-
labelBackgroundLineWidthEdge label background stroke widthnumber-
labelBackgroundRadiusEdge label background corner radius
- number: Set four corner radii uniformly
- number[]: Set four corner radii separately, automatically supplementing missing parts
number | number[]0
labelBackgroundShadowBlurEdge label background shadow blur degreenumber-
labelBackgroundShadowColorEdge label background shadow colorstring-
labelBackgroundShadowOffsetXEdge label background shadow X direction offsetnumber-
labelBackgroundShadowOffsetYEdge label background shadow Y direction offsetnumber-
labelBackgroundStrokeEdge label background stroke colorstring-
labelBackgroundStrokeOpacityEdge label background stroke opacitynumber | string1
labelBackgroundVisibilityWhether the edge label background is visiblevisible | hidden-
labelBackgroundZIndexEdge label background rendering levelnumber-
labelClassEdge label classNamestring-
labelCursorEdge label mouse hover style, configuration itemstringdefault
labelFillEdge label text colorstring-
labelFillOpacityEdge label text color opacitystring1
labelFillRuleEdge label text fill rulenonzero | evenodd-
labelFilterEdge label text filterstring-
labelFontFamilyEdge label text font familysystem-ui, sans-serif-
labelFontSizeEdge label font sizenumber12
labelFontStyleEdge label text font stylenormal | italic | oblique-
labelFontVariantEdge label text font variantnormal | small-caps-
labelFontWeightEdge label font weightnumber | stringnormal
labelLeadingEdge label text line spacingnumber-
labelLetterSpacingEdge label text letter spacingnumber-
labelMaxLinesEdge label text maximum number of linesnumber1
labelMaxWidthEdge label maximum width. When auto-wrapping is enabled, it will wrap if it exceeds this width
- string: Define the maximum width as a percentage of the edge width. For example, 50% means the label width does not exceed half of the edge width
- number: Define the maximum width in pixels. For example, 100 means the maximum width of the label is 100 pixels
number | string80%
labelOffsetXLabel offset in the x-axis directionnumber4
labelOffsetYEdge label offset in the y-axis directionnumber0
labelOpacityOverall opacity of the edge labelnumber1
labelPaddingEdge label paddingnumber | number[]0
labelPlacementPosition of the edge label relative to the edge. The value range is start, center, end, or a specific ratio (number 0-1)start | center | end | numbercenter
labelTextEdge label text contentstring-
labelTextAlignEdge label text alignmentstart | center | middle | end | left | rightleft
labelTextBaseLineEdge label text baselinetop | hanging | middle | alphabetic | ideographicmiddle
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 handling methodclip | ellipsis | stringellipsis
labelVisibilityWhether the edge label is visiblevisible | hiddenvisible
labelWordWrapWhether the edge label enables auto-wrapping. When labelWordWrap is enabled, it will wrap if it exceeds labelMaxWidthbooleanfalse
labelZIndexEdge label rendering levelnumber-

Example:

const graph = new Graph({
edge: {
style: {
stroke: '#1783F', // Edge color
lineWidth: 2, // Edge width
label: true, // Enable edge label display
labelText: 'labelText', // Edge label text
labelPlacement: 'center', // Position of the edge label relative to the edge
labelFill: '#FF0000', // Edge label text color
labelOffsetY: 20, // Edge label offset in the y-axis direction
},
},
});

The effect is as follows:

createGraph(
{
data: {
nodes: [
{ id: 'node1', style: { x: 60, y: 40 } },
{ id: 'node2', style: { x: 180, y: 40 } },
],
edges: [{ source: 'node1', target: 'node2' }],
},
node: {
style: { fill: '#1783FF' },
},
edge: {
style: {
stroke: '#FF0000', // Edge color
lineWidth: 2, // Edge width
label: true, // Enable edge label display
labelText: 'labelText', // Edge label text
labelPlacement: 'center', // Position of the edge label relative to the edge
labelFill: '#FF0000', // Edge label text color
labelOffsetY: 20, // Edge label offset in the y-axis direction
},
},
},
{ width: 240, height: 100 },
);

Halo Style

AttributeDescriptionTypeDefault
haloWhether the edge halo is displayedbooleanfalse
haloClassEdge halo classNamestring-
haloCursorEdge halo mouse hover style, configuration itemstrigdefault
haloDraggableWhether the edge halo is draggableboolean-
haloDroppableWhether the edge halo can receive dragged elementsbooleanfalse
haloFillRuleEdge halo fill rulenonzero | evenodd-
haloFilterEdge halo filterstring-
haloLineDashEdge halo stroke dashed line stylenumber | string | (number | string)[]0
haloLineWidthEdge halo stroke widthnumber3
haloPointerEventsWhether the edge halo effect responds to pointer events, configuration itemstringnone
haloStrokeEdge halo stroke colorstringConsistent with the fill color of the main graphic
haloStrokeOpacityEdge halo stroke color opacitynumber0.25
haloVisibilityEdge halo visibilityvisible | hiddenvisible
haloZIndexEdge halo rendering levelnumber-1

Example:

const graph = new Graph({
edge: {
style: {
stroke: '#1783F', // Edge color
lineWidth: 2, // Edge width
label: true, // Enable edge label display
labelText: 'labelText', // Edge label text
labelPlacement: 'center', // Position of the edge label relative to the edge
labelFill: '#FF0000', // Edge label text color
labelOffsetY: 20, // Edge label offset in the y-axis direction
halo: true, // Enable edge halo
haloStroke: '#000', // Edge halo color
haloStrokeOpacity: 0.2, // Edge halo opacity
},
},
});

The effect is as follows:

createGraph(
{
data: {
nodes: [
{ id: 'node1', style: { x: 60, y: 40 } },
{ id: 'node2', style: { x: 180, y: 40 } },
],
edges: [{ source: 'node1', target: 'node2' }],
},
node: {
style: { fill: '#1783FF' },
},
edge: {
style: {
stroke: '#FF0000', // Edge color
lineWidth: 2, // Edge width
label: true, // Enable edge label display
labelText: 'labelText', // Edge label text
labelPlacement: 'center', // Position of the edge label relative to the edge
labelFill: '#FF0000', // Edge label text color
labelOffsetY: 20, // Edge label offset in the y-axis direction
halo: true, // Enable edge halo
haloStroke: '#000', // Edge halo color
haloStrokeOpacity: 0.2, // Edge halo opacity
},
},
},
{ width: 240, height: 100 },
);

Badge Style

AttributeDescriptionTypeDefault
badgeWhether the edge badge is displayedbooleantrue
badgeBackgroundWhether the edge badge displays a backgroundbooleantrue
badgeBackgroundClassEdge badge background classNamestring-
badgeBackgroundCursorEdge badge background mouse hover style, configuration itemstringdefault
badgeBackgroundFillEdge badge background fill color. If not specified, badgePalette is preferred to be assigned in orderstring-
badgeBackgroundFillOpacityEdge badge background fill opacitynumber1
badgeBackgroundFilterEdge badge background filterstring-
badgeBackgroundHeightEdge badge background heightnumber | string-
badgeBackgroundLineDashEdge badge background dashed line configurationnumber | string |(number | string )[]-
badgeBackgroundLineDashOffsetEdge badge background dashed line offsetnumber-
badgeBackgroundLineWidthEdge badge background stroke widthnumber-
badgeBackgroundOpacityEdge badge background opacitynumber1
badgeBackgroundRadiusEdge badge background corner radius
- number: Set four corner radii uniformly
- number[]: Set four corner radii separately, supplementing missing parts
- string: Similar to the CSS padding property, using spaces to separate
number | number[] | string50%
badgeBackgroundShadowBlurEdge badge background shadow blur degreenumber-
badgeBackgroundShadowColorEdge badge background shadow colorstring-
badgeBackgroundShadowOffsetXEdge badge background shadow X direction offsetnumber-
badgeBackgroundShadowOffsetYEdge badge background shadow Y direction offsetnumber-
badgeBackgroundStrokeEdge badge background stroke colorstring-
badgeBackgroundStrokeOpacityEdge badge background stroke opacitynumber | string1
badgeBackgroundVisibilityWhether the edge badge background is visiblevisible | hiddenvisible
badgeBackgroundZIndexEdge badge background rendering levelnumber-
badgeFillEdge badge text colorstring-
badgeFontSizeEdge badge font sizenumber10
badgeFontVariantEdge badge font variantnormal | small-caps | stringnormal
badgeFontWeightEdge badge font weightnumber | stringnormal
badgeLineHeightEdge badge line heightstring | number-
badgeLineWidthEdge badge line widthstring | number-
badgeMaxLinesEdge badge text maximum number of linesnumber1
badgeOffsetXEdge badge offset in the x-axis directionnumber0
badgeOffsetYEdge badge offset in the y-axis directionnumber0
badgePaddingEdge badge paddingnumber | number[][2, 4, 2, 4]
badgePlacementPosition of the edge badge relative to the main graphic of the edgeprefix | suffixsuffix
badgeTextEdge badge text contentstring-
badgeTextAlignEdge badge text horizontal alignmentstart | center | middle | end | left | rightleft
badgeTextBaselineEdge badge text baselinetop | hanging | middle | alphabetic | ideographic | bottomalphabetic
badgeTextDecorationColorEdge badge text decoration line colorstring-
badgeTextDecorationLineEdge badge text decoration linestring-
badgeTextDecorationStyleEdge badge text decoration line stylesolid | double | dotted | dashed | wavysolid
badgeTextOverflowEdge badge text overflow handling methodclip | ellipsis | stringclip
badgeVisibilityWhether the edge badge is visiblevisible | hidden-
badgeWordWrapWhether the edge badge text automatically wraps, it will wrap if it exceeds badgeWordWrapWidthboolean-
badgeWordWrapWidthEdge badge text wrap widthnumber-
badgeZIndexEdge badge rendering levelnumber1

Example:

const graph = new Graph({
edge: {
style: {
stroke: '#1783F', // Edge color
lineWidth: 2, // Edge width
label: true, // Enable edge label display
labelText: 'labelText', // Edge label text
labelPlacement: 'center', // Position of the edge label relative to the edge
labelFill: '#FF0000', // Edge label text color
labelOffsetY: 20, // Edge label offset in the y-axis direction
halo: true, // Enable edge halo
haloStroke: '#000', // Edge halo color
haloStrokeOpacity: 0.2, // Edge halo opacity
badgeText: 'badge', // Edge badge text
badgeFill: 'green', // Edge badge text color
badgeOffsetX: -20, // Edge badge offset in the x-axis direction
badgeBackground: true, // Enable edge badge background
},
},
});

The effect is as follows:

createGraph(
{
data: {
nodes: [
{ id: 'node1', style: { x: 60, y: 40 } },
{ id: 'node2', style: { x: 180, y: 40 } },
],
edges: [{ source: 'node1', target: 'node2' }],
},
node: {
style: { fill: '#1783FF' },
},
edge: {
style: {
stroke: '#FF0000', // Edge color
lineWidth: 2, // Edge width
label: true, // Enable edge label display
labelText: 'labelText', // Edge label text
labelPlacement: 'center', // Position of the edge label relative to the edge
labelFill: '#FF0000', // Edge label text color
labelOffsetY: 20, // Edge label offset in the y-axis direction
halo: true, // Enable edge halo
haloStroke: '#000', // Edge halo color
haloStrokeOpacity: 0.2, // Edge halo opacity
badgeText: 'badge', // Edge badge text
badgeFill: 'green', // Edge badge text color
badgeOffsetX: -20, // Edge badge offset in the x-axis direction
badgeBackground: true, // Enable edge badge background
},
},
},
{ width: 240, height: 100 },
);

Start Arrow Style

AttributeDescriptionTypeDefault
startArrowWhether the edge start arrow is displayedbooleanfalse
startArrowClassEdge start arrow classNamestring-
startArrowCursorEdge start arrow mouse hover style, configuration itemstringdefault
startArrowFillEdge start arrow fill colorstringConsistent with the edge color by default
startArrowFillOpacityOverall opacity of the edge start arrownumber1
startArrowFillRuleEdge start arrow fill rulenonzero | evenodd-
startArrowFilterEdge start arrow filterstring-
startArrowIncreasedLineWidthForHitTestingWhen the edge start arrow size is small, the interaction area also becomes smaller, we can enlarge this area to make the arrow easier to pick upnumber0
startArrowLineDashEdge start arrow stroke dashed line configurationnumber0
startArrowLineDashOffsetEdge start arrow stroke dashed line offsetnumber0
startArrowLineJoinEdge start arrow stroke join styleround | bevel | miterround
startArrowOffsetEdge start arrow offsetnumber |0 |
startArrowOpacityEdge start arrow opacitynumber1
startArrowShadowBlurEdge start arrow shadow blur degreenumber-
startArrowShadowColorEdge start arrow shadow colorstring-
startArrowShadowOffsetXEdge start arrow shadow X-axis offsetnumber0
startArrowShadowOffsetYEdge start arrow shadow Y-axis offsetnumber0
startArrowSizeEdge start arrow sizenumber | [number, number]-
startArrowSrcEdge start arrow image address (passing in the image address can replace the arrow with an image)string-
startArrowStrokeEdge start arrow stroke colorstringConsistent with the edge color by default
startArrowStrokeOpacityEdge start arrow stroke opacitynumber1
startArrowTransformEdge start arrow rotation, scaling, skewing, or translation configurationstring-
startArrowTransformOriginEdge start arrow rotation and scaling center, also known as the transformation centerstringcenter
startArrowTypeEdge start arrow typetriangle | circle | diamond | vee | rect | triangleRect | simple | ((width: number, height: number) => PathArray)vee
startArrowZIndexEdge start arrow rendering levelnumber-

Example:

const graph = new Graph({
edge: {
style: {
stroke: '#1783F', // Edge color
lineWidth: 2, // Edge width
label: true, // Enable edge label display
labelText: 'labelText', // Edge label text
labelPlacement: 'center', // Position of the edge label relative to the edge
labelFill: '#FF0000', // Edge label text color
labelOffsetY: 20, // Edge label offset in the y-axis direction
halo: true, // Enable edge halo
haloStroke: '#000', // Edge halo color
haloStrokeOpacity: 0.2, // Edge halo opacity
badgeText: 'badge', // Edge badge text
badgeFill: 'green', // Edge badge text color
badgeOffsetX: -20, // Edge badge offset in the x-axis direction
badgeBackground: true, // Enable edge badge background
startArrow: true, // Enable edge start arrow
startArrowFill: 'yellow', // Edge start arrow fill color
},
},
});

The effect is as follows:

createGraph(
{
data: {
nodes: [
{ id: 'node1', style: { x: 60, y: 40 } },
{ id: 'node2', style: { x: 180, y: 40 } },
],
edges: [{ source: 'node1', target: 'node2' }],
},
node: {
style: { fill: '#1783FF' },
},
edge: {
style: {
stroke: '#FF0000', // Edge color
lineWidth: 2, // Edge width
label: true, // Enable edge label display
labelText: 'labelText', // Edge label text
labelPlacement: 'center', // Position of the edge label relative to the edge
labelFill: '#FF0000', // Edge label text color
labelOffsetY: 20, // Edge label offset in the y-axis direction
halo: true, // Enable edge halo
haloStroke: '#000', // Edge halo color
haloStrokeOpacity: 0.2, // Edge halo opacity
badgeText: 'badge', // Edge badge text
badgeFill: 'green', // Edge badge text color
badgeOffsetX: -20, // Edge badge offset in the x-axis direction
badgeBackground: true, // Enable edge badge background
startArrow: true, // Enable edge start arrow
startArrowFill: 'yellow', // Edge start arrow fill color
},
},
},
{ width: 240, height: 100 },
);

End Arrow Style

AttributeDescriptionTypeDefault
endArrowWhether the edge end arrow is displayedbooleanfalse
endArrowClassEdge end arrow classNamestring-
endArrowCursorEdge end arrow mouse hover style, configuration itemstringdefault
endArrowFillEdge end arrow fill colorstringConsistent with the edge color by default
endArrowFillOpacityOverall opacity of the edge end arrownumber1
endArrowFillRuleEdge end arrow fill rulenonzero | evenodd-
endArrowFilterEdge end arrow filterstring-
endArrowIncreasedLineWidthForHitTestingWhen the edge end arrow size is small, the interaction area also becomes smaller, we can enlarge this area to make the arrow easier to pick upnumber0
endArrowLineDashEdge end arrow stroke dashed line configurationnumber0
endArrowLineDashOffsetEdge end arrow stroke dashed line offsetnumber0
endArrowLineJoinEdge end arrow stroke join styleround | bevel | miterround
endArrowOffsetEdge end arrow offsetnumber0
endArrowOpacityEdge end arrow opacitynumber1
endArrowShadowBlurEdge end arrow shadow blur degreenumber-
endArrowShadowColorEdge end arrow shadow colorstring-
endArrowShadowOffsetXEdge end arrow shadow X-axis offsetnumber0
endArrowShadowOffsetYEdge end arrow shadow Y-axis offsetnumber0
endArrowSizeEdge end arrow sizenumber | [number, number]-
endArrowSrcEdge end arrow image address (passing in the image address can replace the arrow with an image)string-
endArrowStrokeEdge end arrow stroke colorstringConsistent with the edge color by default
endArrowStrokeOpacityEdge end arrow stroke opacitynumber1
endArrowTransformEdge end arrow rotation, scaling, skewing, or translation configurationstring-
endArrowTransformOriginEdge end arrow rotation and scaling center, also known as the transformation centerstringcenter
endArrowTypeEdge end arrow typetriangle | circle | diamond | vee | rect | triangleRect | simple | ((width: number, height: number) => PathArray)vee
endArrowZIndexEdge end arrow rendering levelnumber-

Example:

const graph = new Graph({
edge: {
style: {
stroke: '#1783F', // Edge color
lineWidth: 2, // Edge width
label: true, // Enable edge label display
labelText: 'labelText', // Edge label text
labelPlacement: 'center', // Position of the edge label relative to the edge
labelFill: '#FF0000', // Edge label text color
labelOffsetY: 20, // Edge label offset in the y-axis direction
halo: true, // Enable edge halo
haloStroke: '#000', // Edge halo color
haloStrokeOpacity: 0.2, // Edge halo opacity
badgeText: 'badge', // Edge badge text
badgeFill: 'green', // Edge badge text color
badgeOffsetX: 20, // Edge badge offset in the x-axis direction
badgePlacement: 'prefix', // Position of the edge badge relative to the edge
badgeBackground: true, // Enable edge badge background
endArrow: true, // Enable edge end arrow
endArrowFill: 'yellow', // Edge end arrow fill color
},
},
});

The effect is as follows:

createGraph(
{
data: {
nodes: [
{ id: 'node1', style: { x: 60, y: 40 } },
{ id: 'node2', style: { x: 180, y: 40 } },
],
edges: [{ source: 'node1', target: 'node2' }],
},
node: {
style: { fill: '#1783FF' },
},
edge: {
style: {
stroke: '#FF0000', // Edge color
lineWidth: 2, // Edge width
label: true, // Enable edge label display
labelText: 'labelText', // Edge label text
labelPlacement: 'center', // Position of the edge label relative to the edge
labelFill: '#FF0000', // Edge label text color
labelOffsetY: 20, // Edge label offset in the y-axis direction
halo: true, // Enable edge halo
haloStroke: '#000', // Edge halo color
haloStrokeOpacity: 0.2, // Edge halo opacity
badgeText: 'badge', // Edge badge text
badgeFill: 'green', // Edge badge text color
badgeOffsetX: 20, // Edge badge offset in the x-axis direction
badgePlacement: 'prefix', // Position of the edge badge relative to the edge
badgeBackground: true, // Enable edge badge background
endArrow: true, // Enable edge end arrow
endArrowFill: 'yellow', // Edge end arrow fill color
},
},
},
{ width: 240, height: 100 },
);

Loop Edge Style

AttributeDescriptionTypeDefault
loopWhether to enable loop edgesbooleantrue
loopClockwiseSpecify whether to draw the loop clockwisebooleantrue
loopDistDistance from the node keyShape edge to the top of the loop, used to specify the curvature of the loopnumberThe maximum value of width or height by default
loopPlacementPosition of the edge'left' | 'right' | 'top' | 'bottom' | 'left-top' | 'left-bottom' | 'right-top' | 'right-bottom' | 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right''top'

Example:

const graph = new Graph({
data: {
nodes: [
{ id: 'node1', style: { x: 60, y: 40 } },
{ id: 'node2', style: { x: 180, y: 40 } },
],
edges: [
{ source: 'node1', target: 'node1', id: 'left' },
{ source: 'node2', target: 'node2', id: 'right' },
],
},
node: {
style: { fill: '#1783FF' },
},
edge: {
style: {
loopPlacement: (d) => d.id, // Set the position of the loop based on the edge configuration
endArrow: true, // Enable edge end arrow
},
},
});

The effect is as follows:

createGraph(
{
data: {
nodes: [
{ id: 'node1', style: { x: 60, y: 40 } },
{ id: 'node2', style: { x: 180, y: 40 } },
],
edges: [
{ source: 'node1', target: 'node1', id: 'left' },
{ source: 'node2', target: 'node2', id: 'right' },
],
},
node: {
style: { fill: '#1783FF' },
},
edge: {
style: {
loopPlacement: (d) => d.id, // Set the position of the loop based on the edge configuration
endArrow: true, // Enable edge end arrow
},
},
},
{ width: 240, height: 100 },
);

State

In some interactive behaviors, such as clicking to select an edge 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 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 a color of yellow.

const graph = new Graph({
data: {
nodes: [{ id: 'node1' }, { id: 'node2' }],
edges: [{ source: 'node1', target: 'node2', states: ['focus'] }],
},
edge: {
state: {
focus: {
halo: true,
haloLineWidth: 6,
haloStroke: 'yellow',
},
},
},
layout: {
type: 'grid',
cols: 2,
},
});

The effect is as shown below:

createGraph(
{
data: {
nodes: [{ id: 'node1' }, { id: 'node2' }],
edges: [{ source: 'node1', target: 'node2', states: ['focus'] }],
},
edge: {
state: {
focus: {
halo: true,
haloLineWidth: 6,
haloStroke: 'yellow',
},
},
},
layout: {
type: 'grid',
cols: 2,
},
},
{ width: 300, height: 100 },
);

Animation

Define the animation effects of edges, supporting the following two configuration methods:

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

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

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

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

{
"node": {
"animation": {
"update": [
{
"fields": ["stroke"], // Only animate the stroke attribute during update
"duration": 1000, // Animation duration
"easing": "linear" // Easing function
}
],
}
}

You can also use built-in animation effects:

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

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

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

Palette

Define the palette of edges, which is a predefined color pool, and assign colors to the stroke attribute according to rules.

For the definition of palettes, please refer to Palette.

AttributeDescriptionTypeDefault
typeSpecify the current palette type.
- group: Discrete palette
- value: Continuous palette
group | valuegroup
fieldSpecify the grouping field in the element data. If not specified, the id is used as the grouping field by defaultstring | ((datum) => string)id
colorPalette color. If the palette is registered, you can directly specify its registration name, and it also accepts a color arraystring | string[]-
invertWhether to invert the palettebooleanfalse

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

const graph = new Graph({
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'],
},
},
});

The effect is as shown below:

createGraph(
{
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'],
},
},
},
{ width: 600, height: 300 },
);

You can also use the default configuration:

{
"edge": {
"palette": "tableau" // tableau is the palette name, colors are assigned based on ID by default
}
}

The effect is as shown below:

createGraph(
{
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',
},
},
{ width: 600, height: 300 },
);