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.
X6 has built-in the following anchor point definitions.
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',},})
The center point of the element, supporting the following parameters:
Parameter Name | Parameter Type | Required | Default Value | Parameter Description |
---|---|---|---|---|
dx | number | string | No | 0 | X-axis offset, supporting absolute offset and percentage relative offset. |
dy | number | string | No | 0 | Y-axis offset, supporting absolute offset and percentage relative offset. |
rotate | boolean | No | false | Whether to use the element's bounding box rotated with the node, defaulting to not considering the rotation angle. |
The top center point of the element, supporting the following parameters:
Parameter Name | Parameter Type | Required | Default Value | Parameter Description |
---|---|---|---|---|
dx | number | string | No | 0 | X-axis offset, supporting absolute offset and percentage relative offset. |
dy | number | string | No | 0 | Y-axis offset, supporting absolute offset and percentage relative offset. |
rotate | boolean | No | false | Whether to use the element's bounding box rotated with the node, defaulting to not considering the rotation angle. |
The bottom center point of the element, supporting the following parameters:
Parameter Name | Parameter Type | Required | Default Value | Parameter Description |
---|---|---|---|---|
dx | number | string | No | 0 | X-axis offset, supporting absolute offset and percentage relative offset. |
dy | number | string | No | 0 | Y-axis offset, supporting absolute offset and percentage relative offset. |
rotate | boolean | No | false | Whether to use the element's bounding box rotated with the node, defaulting to not considering the rotation angle. |
The left center point of the element, supporting the following parameters:
Parameter Name | Parameter Type | Required | Default Value | Parameter Description |
---|---|---|---|---|
dx | number | string | No | 0 | X-axis offset, supporting absolute offset and percentage relative offset. |
dy | number | string | No | 0 | Y-axis offset, supporting absolute offset and percentage relative offset. |
rotate | boolean | No | false | Whether to use the element's bounding box rotated with the node, defaulting to not considering the rotation angle. |
The right center point of the element, supporting the following parameters:
Parameter Name | Parameter Type | Required | Default Value | Parameter Description |
---|---|---|---|---|
dx | number | string | No | 0 | X-axis offset, supporting absolute offset and percentage relative offset. |
dy | number | string | No | 0 | Y-axis offset, supporting absolute offset and percentage relative offset. |
rotate | boolean | No | false | Whether to use the element's bounding box rotated with the node, defaulting to not considering the rotation angle. |
The center point of the nearest side of the element, supporting the following parameters:
Parameter Name | Parameter Type | Required | Default Value | Parameter Description |
---|---|---|---|---|
padding | number | No | 0 | Offset the center point by padding pixels, supporting absolute offset and percentage relative offset. |
rotate | boolean | No | false | Whether 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. |
The top-left corner of the element, supporting the following parameters:
Parameter Name | Parameter Type | Required | Default Value | Parameter Description |
---|---|---|---|---|
dx | number | string | No | 0 | X-axis offset, supporting absolute offset and percentage relative offset. |
dy | number | string | No | 0 | Y-axis offset, supporting absolute offset and percentage relative offset. |
rotate | boolean | No | false | Whether to use the element's bounding box rotated with the node, defaulting to not considering the rotation angle. |
The top-right corner of the element, supporting the following parameters:
Parameter Name | Parameter Type | Required | Default Value | Parameter Description |
---|---|---|---|---|
dx | number | string | No | 0 | X-axis offset, supporting absolute offset and percentage relative offset. |
dy | number | string | No | 0 | Y-axis offset, supporting absolute offset and percentage relative offset. |
rotate | boolean | No | false | Whether to use the element's bounding box rotated with the node, defaulting to not considering the rotation angle. |
The bottom-left corner of the element, supporting the following parameters:
Parameter Name | Parameter Type | Required | Default Value | Parameter Description |
---|---|---|---|---|
dx | number | string | No | 0 | X-axis offset, supporting absolute offset and percentage relative offset. |
dy | number | string | No | 0 | Y-axis offset, supporting absolute offset and percentage relative offset. |
rotate | boolean | No | false | Whether to use the element's bounding box rotated with the node, defaulting to not considering the rotation angle. |
The bottom-right corner of the element, supporting the following parameters:
Parameter Name | Parameter Type | Required | Default Value | Parameter Description |
---|---|---|---|---|
dx | number | string | No | 0 | X-axis offset, supporting absolute offset and percentage relative offset. |
dy | number | string | No | 0 | Y-axis offset, supporting absolute offset and percentage relative offset. |
rotate | boolean | No | false | Whether to use the element's bounding box rotated with the node, defaulting to not considering the rotation angle. |
The orthogonal point, supporting the following parameters:
Parameter Name | Parameter Type | Required | Default Value | Parameter Description |
---|---|---|---|---|
padding | number | No | 0 | X-axis offset. |
The center point of the node, supporting the following parameters:
Parameter Name | Parameter Type | Required | Default Value | Parameter Description |
---|---|---|---|---|
dx | number | No | 0 | X-axis offset. |
dy | number | No | 0 | Y-axis offset. |
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 Name | Parameter Type | Parameter Description |
---|---|---|
this | EdgeView | The edge view. |
nodeView | NodeView | The node view. |
magnet | SVGElement | The magnet element. |
ref | Point.PointLike | SVGElement | The reference point/element. |
args | T | The arguments. |
type | Edge.TerminalType | The 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',},},})