Skip to main content

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#

ConstructorModifiersDescription
(constructor)(params)Constructs a new instance of the Magnetizer class

Properties#

PropertyModifiersTypeDescription
constrainMagnetizerConstrainFunction
containerany
currentFocusstring
debugboolean
elementsArray<T>
excludeFilterFunction<T>
filterFilterFunction<T>
focusElement{ id: string; bounds: RectangleXY; }
getContainerPosition(c: any) => PointXY
getId(el: T) => string
getPosition(el: T) => PointXY
getSize(el: T) => Size
originPointXY
originalPositionsMap<string, RectangleXY>
originDebugMarkerany
paddingPointXY
positionArrayArray<ElementPosition<T>>
positionsMap<string, RectangleXY>
setPosition(el: T, p: PointXY) => T
sizesMap<string, Size>

Methods#

MethodModifiersDescription
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.