logo

X6

  • Tutorials
  • API
  • Examples
  • Q&A
  • Change Log
  • XFlow
  • Productsantv logo arrow
  • 2.x
  • Graph
    • Graph
    • Grid
    • Background
    • Panning
    • Mousewheel
    • Viewport Transformation
    • Coordinate Systems
  • Element
    • Cell
    • Node
    • Edge
    • Labels
    • Arrow
    • Element Attributes
    • Interaction
  • MVC
    • Model
    • View
  • Extension
    • Node Tools
    • Edge Tools
    • Routing
    • Connector
    • Node Anchor
    • Edge Anchor
    • Connection Point
    • Port Layout Algorithm
    • Port Label Layout
    • Attributes
    • Highlighter
    • Filter

Node Anchor

Previous
Connector
Next
Edge Anchor

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...

When connecting to a node, you can specify the anchor point of the connected node using NodeAnchor, which, together with the connection point ConnectionPoint, determines the starting and ending points of the edge.

  • Starting point: Draw a reference line from the first path point or the center of the target node (when there is no path point) to the anchor point of the source node, and then calculate the intersection point of the reference line and the graph according to the intersection calculation method specified by connectionPoint, which is the starting point of the edge.
  • Ending point: Draw a reference line from the last path point or the center of the source node (when there is no path point) to the anchor point of the target node, and then calculate the intersection point of the reference line and the graph according to the intersection calculation method specified by connectionPoint, which is the ending point of the edge.

X6 has built-in the following anchor point definitions.

  • center The center point of the element connected to the edge (default value).
  • top The top center point of the element connected to the edge.
  • bottom The bottom center point of the element connected to the edge.
  • left The left center point of the element connected to the edge.
  • right The right center point of the element connected to the edge.
  • midSide The center point of the nearest side of the element connected to the edge.
  • topLeft The top-left corner of the element connected to the edge.
  • topRight The top-right corner of the element connected to the edge.
  • bottomLeft The bottom-left corner of the element connected to the edge.
  • bottomRight The bottom-right corner of the element connected to the edge.
  • orth The orthogonal point.
  • nodeCenter The center point of the node.

You can specify the anchor point when creating an edge:

const edge = graph.addEdge({
source: {
cell: 'source-id',
anchor: {
name: 'midSide',
args: {
dx: 10,
},
},
},
target: {
cell: 'target-id',
anchor: 'orth', // Simplified writing when there are no parameters
},
})

After creation, you can modify the anchor point by calling the edge.setSource and edge.setTarget methods:

edge.setSource({
cell: 'source-id',
anchor: {
name: 'midSide',
args: {
dx: 10,
},
},
})

When creating a canvas, you can set the global default anchor point through the connecting option:

new Graph({
connecting: {
anchor: {
name: 'midSide',
args: {
dx: 10,
},
},
},
})

Simplified writing when there are no parameters:

new Graph({
connecting: {
anchor: 'midSide',
},
})

Built-in Anchors

center

The center point of the element, supporting the following parameters:

Parameter NameParameter TypeRequiredDefault ValueParameter Description
dxnumber | stringNo0X-axis offset, supporting absolute offset and percentage relative offset.
dynumber | stringNo0Y-axis offset, supporting absolute offset and percentage relative offset.
rotatebooleanNofalseWhether to use the element's bounding box rotated with the node, defaulting to not considering the rotation angle.

top

The top center point of the element, supporting the following parameters:

Parameter NameParameter TypeRequiredDefault ValueParameter Description
dxnumber | stringNo0X-axis offset, supporting absolute offset and percentage relative offset.
dynumber | stringNo0Y-axis offset, supporting absolute offset and percentage relative offset.
rotatebooleanNofalseWhether to use the element's bounding box rotated with the node, defaulting to not considering the rotation angle.

bottom

The bottom center point of the element, supporting the following parameters:

Parameter NameParameter TypeRequiredDefault ValueParameter Description
dxnumber | stringNo0X-axis offset, supporting absolute offset and percentage relative offset.
dynumber | stringNo0Y-axis offset, supporting absolute offset and percentage relative offset.
rotatebooleanNofalseWhether to use the element's bounding box rotated with the node, defaulting to not considering the rotation angle.

left

The left center point of the element, supporting the following parameters:

Parameter NameParameter TypeRequiredDefault ValueParameter Description
dxnumber | stringNo0X-axis offset, supporting absolute offset and percentage relative offset.
dynumber | stringNo0Y-axis offset, supporting absolute offset and percentage relative offset.
rotatebooleanNofalseWhether to use the element's bounding box rotated with the node, defaulting to not considering the rotation angle.

right

The right center point of the element, supporting the following parameters:

Parameter NameParameter TypeRequiredDefault ValueParameter Description
dxnumber | stringNo0X-axis offset, supporting absolute offset and percentage relative offset.
dynumber | stringNo0Y-axis offset, supporting absolute offset and percentage relative offset.
rotatebooleanNofalseWhether to use the element's bounding box rotated with the node, defaulting to not considering the rotation angle.

midSide

The center point of the nearest side of the element, supporting the following parameters:

Parameter NameParameter TypeRequiredDefault ValueParameter Description
paddingnumberNo0Offset the center point by padding pixels, supporting absolute offset and percentage relative offset.
rotatebooleanNofalseWhether to use the element's bounding box rotated with the node, defaulting to not considering the rotation angle.
direction'H' | 'V'No-The direction of the connection point, such as setting to H to only connect to the left or right center point of the node, automatically judging based on the position.

topLeft

The top-left corner of the element, supporting the following parameters:

Parameter NameParameter TypeRequiredDefault ValueParameter Description
dxnumber | stringNo0X-axis offset, supporting absolute offset and percentage relative offset.
dynumber | stringNo0Y-axis offset, supporting absolute offset and percentage relative offset.
rotatebooleanNofalseWhether to use the element's bounding box rotated with the node, defaulting to not considering the rotation angle.

topRight

The top-right corner of the element, supporting the following parameters:

Parameter NameParameter TypeRequiredDefault ValueParameter Description
dxnumber | stringNo0X-axis offset, supporting absolute offset and percentage relative offset.
dynumber | stringNo0Y-axis offset, supporting absolute offset and percentage relative offset.
rotatebooleanNofalseWhether to use the element's bounding box rotated with the node, defaulting to not considering the rotation angle.

bottomLeft

The bottom-left corner of the element, supporting the following parameters:

Parameter NameParameter TypeRequiredDefault ValueParameter Description
dxnumber | stringNo0X-axis offset, supporting absolute offset and percentage relative offset.
dynumber | stringNo0Y-axis offset, supporting absolute offset and percentage relative offset.
rotatebooleanNofalseWhether to use the element's bounding box rotated with the node, defaulting to not considering the rotation angle.

bottomRight

The bottom-right corner of the element, supporting the following parameters:

Parameter NameParameter TypeRequiredDefault ValueParameter Description
dxnumber | stringNo0X-axis offset, supporting absolute offset and percentage relative offset.
dynumber | stringNo0Y-axis offset, supporting absolute offset and percentage relative offset.
rotatebooleanNofalseWhether to use the element's bounding box rotated with the node, defaulting to not considering the rotation angle.

orth

The orthogonal point, supporting the following parameters:

Parameter NameParameter TypeRequiredDefault ValueParameter Description
paddingnumberNo0X-axis offset.

nodeCenter

The center point of the node, supporting the following parameters:

Parameter NameParameter TypeRequiredDefault ValueParameter Description
dxnumberNo0X-axis offset.
dynumberNo0Y-axis offset.

Custom Anchors

An anchor point definition is a function with the following signature, returning an anchor point.

export type Definition<T> = (
this: EdgeView,
nodeView: NodeView,
magnet: SVGElement,
ref: Point.PointLike | SVGElement,
args: T,
type: Edge.TerminalType,
) => Point
Parameter NameParameter TypeParameter Description
thisEdgeViewThe edge view.
nodeViewNodeViewThe node view.
magnetSVGElementThe magnet element.
refPoint.PointLike | SVGElementThe reference point/element.
argsTThe arguments.
typeEdge.TerminalTypeThe edge terminal type.

After completing the anchor point definition, we register the anchor point:

Graph.registerAnchor('custom-anchor', ...)

After registration, we can use the anchor point by name:

new Graph({
connecting: {
anchor: {
name: 'custom-anchor',
},
},
})
Anchor