Skip to content
  1. API
  2. GridBackground

GridBackground

SVG-based grid background layer for Ogma. Renders an adaptive multi-level grid that reacts to zoom changes, automatically switching between finer and coarser cell sizes to maintain a readable density on screen. Optionally snaps dragged nodes to the nearest grid line or intersection. Can be passed directly to the background option of the Ogma constructor for tree-shakable usage.

gridBackground.constructor([options])

Creates a new GridBackground. Pass it as the background option to new Ogma({ background: … }) for automatic attachment, or call {@link GridBackground.attach} manually after construction.

Arguments

gridBackground.attach(ogma)

Attaches this grid background to an Ogma instance. Called automatically when the instance is passed as the background option to the Ogma constructor.

Arguments

  • ogma Ogma The Ogma instance to attach to.

Returns

gridBackground.destroy()

Removes the grid SVG layer from Ogma and unbinds all event listeners. The instance should not be used after this call.

gridBackground.getOptions()

Returns the current effective options of the grid background.

Returns

  • ResolvedOptions The current options.

gridBackground.isEnabled()

Checks whether the grid is currently visible (enabled) or hidden.

Returns

  • boolean true if the grid is visible, false if hidden or not attached.

gridBackground.setEnabled(enabled)

Shows or hides the grid SVG layer without destroying it.

Arguments

  • enabled boolean true to show, false to hide.

Returns

gridBackground.setOptions(options)

Updates one or more options and redraws the grid immediately. Nested objects (snap) are merged with the current values — only pass the keys you want to change.

Arguments

Returns