Home > @jsplumbtoolkit/core > Magnetizer
Magnetizer class
Offers a means to apply 'magnetization' to some list of elements, pushing them apart so that they do not overlap. For a given run of the magnetizer there is the concept of a "focus" rectangle. The center of this rectangle is the point from which magnetization occurs, with elements being pushed out radially from this point. There are a few different scenarios:
- execute magnetizer with a given origin, and affect all elements - execute magnetizer on all elements, having first computed the center of them - execute magnetizer using a specific element as the focus
Signature:
export declare class Magnetizer<T>
Constructors
| Constructor | Modifiers | Description |
|---|---|---|
| (constructor)(params) | Constructs a new instance of the Magnetizer class |
Properties
| Property | Modifiers | Type | Description |
|---|---|---|---|
| constrain | MagnetizerConstrainFunction | ||
| container | any | ||
| currentFocus | string | ||
| debug | boolean | ||
| elements | Array<T> | ||
| exclude | FilterFunction<T> | ||
| filter | FilterFunction<T> | ||
| focusElement | { id: string; bounds: RectangleXY; } | ||
| getContainerPosition | (c: any) => PointXY | ||
| getId | (el: T) => string | ||
| getPosition | (el: T) => PointXY | ||
| getSize | (el: T) => Size | ||
| origin | PointXY | ||
| originalPositions | Map<string, RectangleXY> | ||
| originDebugMarker | any | ||
| padding | PointXY | ||
| positionArray | Array<ElementPosition<T>> | ||
| positions | Map<string, RectangleXY> | ||
| setPosition | (el: T, p: PointXY) => T | ||
| sizes | Map<string, Size> |
Methods
| Method | Modifiers | Description |
|---|---|---|
| addElement(el, doNotTestForDuplicates) | ||
| addElements(els, doNotTestForDuplicates) | ||
| executeAtCenter(options) | Run the magnetizer using an origin computed to be the center of all elements. | |
| executeAtPoint(origin, options) | Run the magnetizer using the specified origin. | |
| executeWithFocus(focus, options) | Run the magnetizer with the given element as its focus - the focus element will not be shifted. | |
| removeElement(el) | ||
| reset() | ||
| setElements(_els) | ||
| snapToGrid(grid) | Snaps all elements to a grid. Returns a map of element IDs, representing all the elements that were moved. |