logo

X6

  • Tutorials
  • API
  • Examples
  • Q&A
  • Change Log
  • Productsantv logo arrow
  • 3.x
  • Introduction
  • Quickstart
  • Basic
    • Graph
    • Nodes
    • Edges
    • Ports
    • Interaction
    • Events
    • Data Serialization
    • Animation
  • Intermediate
    • Connection Points
    • Tools
    • Group
    • React Nodes
    • Vue Nodes
    • Angular Nodes
    • HTML Nodes
  • Plugin
    • Graphic Transformations
    • Snapline
    • Clipboard
    • Keyboard
    • History
    • Selection Box
    • Scroller
    • Dnd
    • Mini Map
    • Stencil
    • Export
  • Upgrade to 3.x
  • Developer Tools

Snapline

Previous
Graphic Transformations
Next
Clipboard

Resource

Ant Design
Galacea Effects
Umi-React Application Framework
Dumi-Component doc generator
ahooks-React Hooks Library
WeaveFox-AI Coding Assistant

Community

Ant Financial Experience Tech
seeconfSEE Conf-Experience Tech Conference
weavefoxWeaveFox-AI Developer Community

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
weavefoxWeaveFox-AI Coding Assistant
© Copyright 2025 Ant Group Co., Ltd..备案号:京ICP备15032932号-38

Loading...

This section mainly introduces the Snapline plugin. By reading, you will learn:

  • How to use snaplines on the canvas

Usage

Snaplines help align moving nodes. Enable the feature via the Snapline plugin:

import { Graph, Snapline } from '@antv/x6'
const graph = new Graph({
background: {
color: '#F2F7FA',
},
})
graph.use(
new Snapline({
enabled: true,
}),
)

Demo

Configuration

Property NameTypeDefault ValueRequiredDescription
classNamestring-Additional class name to customize snapline styles
tolerancenumber10Snapline precision; a snapline is shown when the distance to the target position is less than tolerance
sharpbooleanfalseWhether to use short snaplines (truncated)
resizingbooleanfalseWhether to trigger snaplines when resizing nodes
cleanbooleantrueIf true, snaplines are cleared after 3 seconds; if false, they are not cleared; if a number (ms), they are cleared after the specified duration
filterFilter-Node filter

The above Filter type is relatively flexible and supports the following forms:

  • string[]: An array of node shapes; only nodes with those shapes participate in snapline calculations
  • ({ id: string })[]: An array of node IDs; only the specified nodes participate in snapline calculations
  • (this: Graph, node: Node) => boolean: Only nodes for which the function returns true participate in snapline calculations

API

graph.isSnaplineEnabled()

isSnaplineEnabled(): boolean

Returns whether snaplines are enabled.

graph.enableSnapline()

enableSnapline(): this

Enables snaplines.

graph.disableSnapline()

disableSnapline(): this

Disables snaplines.

graph.toggleSnapline(...)

toggleSnapline(enabled?: boolean): this

Toggles whether snaplines are enabled. Parameters are as follows:

NameTypeRequiredDefault ValueDescription
enabledboolean-Whether to enable snaplines; if omitted, toggles the current enabled state.

graph.hideSnapline()

hideSnapline(): this

Hides snaplines.

graph.isSnaplineOnResizingEnabled()

isSnaplineOnResizingEnabled(): boolean

Whether to trigger snaplines when resizing nodes.

graph.enableSnaplineOnResizing()

enableSnaplineOnResizing(): this

Enables triggering snaplines during node resizing.

graph.disableSnaplineOnResizing()

disableSnaplineOnResizing(): this

Disables triggering snaplines during node resizing.

graph.toggleSnaplineOnResizing(...)

toggleSnaplineOnResizing(enabled?: boolean): this

Toggles whether to trigger snaplines during node resizing. Parameters are as follows:

NameTypeRequiredDefault ValueDescription
enabledboolean-Whether to enable snaplines; if omitted, toggles the current enabled state.

graph.isSharpSnapline()

isSharpSnapline(): boolean

Whether to use short snaplines.

graph.enableSharpSnapline()

enableSharpSnapline(): this

Enables short snaplines; when enabled, snaplines are truncated at relevant node positions; otherwise they span across the canvas.

graph.disableSharpSnapline()

disableSharpSnapline(): this

Disables short snaplines; snaplines span the entire canvas.

graph.toggleSharpSnapline()

toggleSharpSnapline(enabled?: boolean): this

Toggles whether short snaplines are enabled. Parameters are as follows:

NameTypeRequiredDefault ValueDescription
enabledboolean-Whether to enable short snaplines; if omitted, toggles the current enabled state.

graph.getSnaplineTolerance()

getSnaplineTolerance(): number

Gets snapline precision.

graph.setSnaplineTolerance(...)

setSnaplineTolerance(tolerance: number): this

Sets snapline precision.

graph.setSnaplineFilter(...)

setSnaplineFilter(
filter?:
| null
| (string | { id: string })[]
| ((this: Graph, node: Node) => boolean)
): this

Sets the filter; only nodes that meet the condition participate in snapline calculations.

Snapline Settings
Tolerance
10