Panning
Previous
Background
Next
Mousewheel
Loading...
A regular canvas (without the Scroller plugin) can support panning by the panning option.
const graph = new Graph({panning: true, // If not provided, default is also true})// Equivalent toconst graph = new Graph({panning: {enabled: true,},})
The supported options are as follows:
interface Options {enabled?: booleanmodifiers?: ModifierKeyeventTypes?: ('leftMouseDown' | 'rightMouseDown' | 'mouseWheel' | 'mouseWheelDown')[]}
Whether to enable canvas panning interaction.
Dragging may conflict with other operations, so you can set the modifiers parameter to specify a modifier key that needs to be pressed along with the mouse click to trigger canvas panning.
The type definition of ModifierKey is as follows:
type ModifierKey = string | ('alt' | 'ctrl' | 'meta' | 'shift' | 'space')[] | null
It supports the following forms:
alt represents pressing the alt key.[alt, ctrl] represents pressing either the alt or ctrl key.alt|ctrl represents pressing either the alt or ctrl key.alt&ctrl represents pressing both the alt and ctrl keys simultaneously.alt|ctrl&shift represents pressing both the alt and shift keys simultaneously or pressing both the ctrl and shift keys simultaneously.The interaction types that trigger canvas panning. It supports four forms or their combinations:
leftMouseDown: Dragging by pressing the left mouse buttonrightMouseDown: Dragging by pressing the right mouse buttonmouseWheel: Dragging by scrolling the mouse wheelmouseWheelDown: Dragging by pressing the mouse wheelisPannable(): boolean
Returns whether canvas panning interaction is enabled.
enablePanning(): this
Enables canvas panning.
disablePanning(): this
Disables canvas panning.
togglePanning(enabled?: boolean): this
Toggles the enabled state of canvas panning. The parameter is as follows:
| Name | Type | Required | Default Value | Description |
|---|---|---|---|---|
| enabled | boolean | - | Whether to enable canvas panning, defaults to toggling the enabled state. |