Skip to main content

Snaplines

Snaplines provide visual cues to allow your users to fine-tune their layouts.

Snaplines - jsPlumb Toolkit, flowcharts, chatbots, bar charts, decision trees, mindmaps, org charts and more

Setup

Vanilla JS
React
Angular
Vue
Svelte
import { newInstance,
SnaplinesPlugin } from "@jsplumbtoolkit/browser-ui"

const toolkit = newInstance()

const surface = toolkit.render(someElement, {
"plugins": [
SnaplinesPlugin.type
]
});

This will add the snaplines plugin with its default settings.

Configuration

Snaplines offers a few basic customization options:

Vanilla JS
React
Angular
Vue
Svelte
import { newInstance,
SnaplinesPlugin } from "@jsplumbtoolkit/browser-ui"

const toolkit = newInstance()

const surface = toolkit.render(someElement, {
"plugins": [
{
"type": SnaplinesPlugin.type,
"options": {
"showEdges": true,
"showCenters": true,
"tolerance": 15
}
}
]
});

Enable/disable

You can switch the snaplines plugin on and off via its setEnabled(..) method. To do this, you need to get a reference to the plugin and then call the method:

const snaplinesPlugin = surface.getPlugin(SnaplinesPlugin.type)
snaplinesPlugin.setEnabled(false)

CSS

Classes used by the Snaplines plugin.

Default values specified in the jsplumbtoolkit.css stylesheet

ClassDescription
jtk-snaplineAssigned to both horizontal and vertical snaplines when active
jtk-snapline-horizontalAssigned to horizontal snaplines when active
jtk-snapline-verticalAssigned to vertical snaplines when active
jtk-snapline-exactAssigned to both horizontal and vertical snaplines when the elements are exactly aligned
jtk-snapline-activeAssigned to an element attached to an active snapline
jtk-snapline-active-exactAssigned to an element attached to an active snapline and the elements on the snapline are exactly aligned

Options

Interface SnaplinesPluginOptions

NameTypeDescription
enabled?booleanDefaults to true. If false, you can start the plugin in disabled mode.
showCenters?booleanWhether or not to show center snaplines. Defaults to true.
showEdges?booleanWhether or not to show edge snaplines. Defaults to true.
tolerance?numberThe tolerance either side of a snapline inside which an element must be before the snapline is activated. Defaults to 10 pixels (either side of the line).