Loading...
Hold down the
Commandkey and use the mouse wheel to zoom in/out of the canvas.
You can use the mousewheel configuration to zoom in/out of the canvas, often used in combination with modifier keys. The usage is as follows:
const graph = new Graph({mousewheel: {enabled: true,modifiers: ['ctrl', 'meta'],},})
Supported options are as follows:
interface MouseWheelOptions {enabled?: booleanglobal?: booleanfactor?: numberzoomAtMousePosition?: booleanmodifiers?: string | ('alt' | 'ctrl' | 'meta' | 'shift')[] | nullguard?: (this: Graph, e: WheelEvent) => boolean}
Whether to enable mouse wheel zooming interaction.
The zoom factor. Defaults to 1.2.
Whether to zoom in/out at the mouse position. Defaults to true.
Whether to bind the wheel event globally. If set to true, the wheel event is bound to the Document, otherwise it is bound to the canvas container. Defaults to false.
Modifier keys (alt, ctrl, meta, shift), which can be set to resolve conflicts between default wheel behavior and canvas zooming. Modifier keys support the following formats:
alt represents pressing the alt key.[alt, ctrl] represents pressing either alt or ctrl.alt|ctrl represents pressing either alt or ctrl.alt&ctrl represents pressing both alt and ctrl simultaneously.alt|ctrl&shift represents pressing both alt and shift simultaneously or both ctrl and shift simultaneously.Determines whether a wheel event should be handled, returning false to ignore the event.
new Graph({mousewheel: {enabled: true,guard(e: WheelEvent) {if (e.altKey) {// Ignore all wheel events when the alt key is pressedreturn false}return true},},})
isMouseWheelEnabled(): boolean
Returns whether mouse wheel zooming is enabled.
enableMouseWheel(): this
Enables mouse wheel zooming.
disableMouseWheel(): this
Disables mouse wheel zooming.
toggleMouseWheel(enabled?: boolean): this
Toggles the enabled state of mouse wheel zooming.
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| enabled | boolean | - | Whether to enable mouse wheel zooming, toggles the state if not provided. |