Skip to main content

Home > @jsplumb/core > Viewport

Viewport class#

Models the positions of the elements a given jsPlumb instance is tracking. Users of the API should not need to interact directly with a Viewport.

Signature:

export declare class Viewport<T extends {    E: unknown;}> extends EventGenerator 

Extends: EventGenerator

Constructors#

ConstructorModifiersDescription
(constructor)(instance)Constructs a new instance of the Viewport class

Properties#

PropertyModifiersTypeDescription
_boundsRecord<string, number>
_elementMapMap<string, ViewportElement<T["E"]>>
_sortedElementsRecord<string, Array<[string, number]>>
_transformedElementMapMap<string, TranslatedViewportElement<T["E"]>>
instanceJsPlumbInstance<T>

Methods#

MethodModifiersDescription
addElement(id, x, y, width, height, rotation)Adds the element with the given id, with the given values for x, y, width, height and rotation. Any of these may be null.
endTransaction()
getBoundsHeight()Gets the height of the content managed by the viewport, taking any rotated elements into account.
getBoundsWidth()Gets the width of the content managed by the viewport, taking any rotated elements into account.
getElements()Get all elements managed by the Viewport.
getOffset(el)
getPosition(id)Gets the position of the element. This returns both the original position, and also the translated position of the element. Certain internal methods, such as the anchor calculation code, use the unrotated position and then subsequently apply the element's rotation to any calculated positions. Other parts of the codebase - the Toolkit's magnetizer or pan/zoom widget, for instance - are interested in the rotated position.
getSize(el)
getX()Gets the leftmost point of the content managed by the viewport, taking any rotated elements into account.
getY()Gets the topmost of the content managed by the viewport, taking any rotated elements into account.
isEmpty()Returns whether or not the viewport is empty.
recomputeBounds()
refreshElement(elId, doNotRecalculateBounds)Update the size/offset of the element with the given id, and adjust viewport bounds.
registerElement(id, doNotRecalculateBounds)Creates an empty entry for an element with the given ID.
remove(id)Remove the element with the given ID from the viewport.
reset()Clears the internal state of the viewport, removing all elements.
rotateElement(id, rotation)Rotates the element with the given id, recalculating bounds afterwards.
setPosition(id, x, y)Sets the [x,y] position of the element with the given ID, recalculating bounds.
setSize(id, w, h)Sets the size of the element with the given ID, recalculating bounds.
shouldFireEvent(event, value, originalEvent)
startTransaction()
updateElement(id, x, y, width, height, rotation, doNotRecalculateBounds)Updates the element with the given id. Any of the provided values may be null, in which case they are ignored (we never overwrite an existing value with null).
updateElements(entries)