Appearance
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
- options(optional)
GridBackgroundOptionsOptional configuration; all fields have sensible defaults.
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
OgmaThe Ogma instance to attach to.
Returns
-
GridBackgroundthisfor method chaining.
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
-
ResolvedOptionsThe current options.
gridBackground.isEnabled()
Checks whether the grid is currently visible (enabled) or hidden.
Returns
-
booleantrueif the grid is visible,falseif hidden or not attached.
gridBackground.setEnabled(enabled)
Shows or hides the grid SVG layer without destroying it.
Arguments
- enabled
booleantrueto show,falseto hide.
Returns
-
GridBackgroundthisfor method chaining.
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
- options
GridBackgroundOptionsPartial options object with the keys to update.
Returns
-
GridBackgroundthisfor method chaining.