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

Polyline

Previous
Line
Next
Quadratic 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...

Overview

A polyline is an edge composed of multiple straight line segments, suitable for connecting nodes by bypassing obstacles in complex layouts.

Use cases:

  • Suitable for graphs with complex layouts, such as circuit diagrams and pipeline diagrams.

  • Use when you need to bypass other nodes or obstacles.

Online Experience

createGraph(
{
data: {
nodes: [
{
id: 'node1',
style: { x: 150, y: 150 },
},
{
id: 'node2',
style: {
x: 400,
y: 150,
labelText: 'Drag Me!',
labelPadding: [1, 5],
labelBackground: true,
labelBackgroundRadius: 10,
labelBackgroundFill: '#99add1',
},
},
],
edges: [
{
id: 'edge1',
source: 'node1',
target: 'node2',
text: 'polyline',
},
],
},
node: {
style: {
fill: '#f8f8f8',
stroke: '#8b9baf',
lineWidth: 1,
},
},
edge: {
type: 'polyline',
style: {
stroke: '#7e3feb',
lineWidth: 2,
labelText: (d) => d.text,
labelBackground: true,
labelBackgroundFill: '#f9f0ff',
labelBackgroundOpacity: 1,
labelBackgroundLineWidth: 2,
labelBackgroundStroke: '#7e3feb',
labelPadding: [1, 10],
labelBackgroundRadius: 4,
router: { type: 'orth' },
},
},
behaviors: ['drag-canvas', 'drag-element'],
plugins: [{ type: 'grid-line', size: 30 }],
},
{ width: 600, height: 300 },
(gui, graph) => {
gui.add({ type: 'polyline' }, 'type').disable();
let index = 3;
const options = {
radius: 0,
router: {
type: 'orth',
},
random: () => {
const x = Math.floor(Math.random() * 600);
const y = Math.floor(Math.random() * 300);
graph.addNodeData([
{
id: `node-${index}`,
style: {
size: 5,
fill: '#7e3feb',
x,
y,
},
},
]);
index++;
graph.updateEdgeData((prev) => {
const targetEdgeData = prev.find((edge) => edge.id === 'edge1');
const controlPoints = [...(targetEdgeData.style.controlPoints || [])];
controlPoints.push([x, y]);
return [{ ...targetEdgeData, style: { ...targetEdgeData.style, controlPoints } }];
});
graph.render();
},
};
const optionFolder = gui.addFolder('polyline.style');
optionFolder.add(options, 'radius', 0, 100, 1);
optionFolder.add(options, 'router');
optionFolder.add(options, 'random').name('Add random node as control points');
optionFolder.onChange(({ property, value }) => {
if (property === 'random') return;
graph.updateEdgeData([{ id: 'edge1', style: { [property]: value } }]);
graph.render();
});
},
);

设置 edge.type 为 polyline 以使用折线。

Style Configuration

If the element has specific attributes, we will list them below. For all general style attributes, see BaseEdge

AttributeDescriptionTypeDefaultRequired
controlPointsArray of control points used to define the turning points of the polyline.Point[][]
radiusCorner radius of the turning points.number0
routerWhether to enable routing.false | OrthRouter | ShortestPathRouterfalse

OrthRouter

AttributeDescriptionTypeDefault
typeOrthogonal routing, adding extra control points on the path to keep each segment horizontal or vertical.'orth'-
paddingMinimum distance between the node connection point and the corner.Padding0

ShortestPathRouter

AttributeDescriptionTypeDefault
typeShortest path routing, an intelligent version of orthogonal routing 'orth'. This routing consists of horizontal or vertical orthogonal segments. It uses the A* algorithm to calculate the shortest path and supports automatic avoidance of other nodes (obstacles) on the path.'shortest-path'-
offsetMinimum distance between the node anchor point and the corner.Padding0
gridSizeGrid cell size.number0
maxAllowedDirectionChangeMaximum allowed rotation angle (radians).number0
startDirectionsPossible starting directions of the node.Direction[]0
endDirectionsPossible ending directions of the node.Direction[]0
directionMapSpecifies the movable directions.{ [key in Direction]: { stepX: number; stepY: number } }0
penaltiesRepresents additional costs for certain paths during path searching. The key is the radian value, and the value is the cost.{ [key: string]: number }0
distFuncSpecifies the function to calculate the distance between two points.(p1: Point, p2: Point) => number0
maximumLoopsMaximum number of iterations.number0
enableObstacleAvoidanceWhether to enable obstacle avoidance.booleanfalse

Direction

type Direction = 'left' | 'right' | 'top' | 'bottom';

Point

type Point = [number, number] | [number, number, number] | Float32Array;

Padding

type Padding = number | [number, number] | [number, number, number, number];

Example

Built-in Polyline Edge Effect