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.

Type Parameters

  • T extends {
        E: unknown;
    }

Hierarchy (view full)

Methods

  • Adds the element with the given id, with the given values for x, y, width, height and rotation. Any of these may be null.

    Parameters

    • id: string
    • x: number
    • y: number
    • width: number
    • height: number
    • rotation: number

    Returns ViewportElement<T["E"]>

  • Bind an event listener. This method can be used with a type parameter by call sites; although it's not necessary it can be helpful to use this to ensure you've thought about what the payload to your event handler is going to be.

    Type Parameters

    • T = any

    Parameters

    • event: string

      Name of the event(s) to bind to.

    • listener: ((a, e?) => any)

      Function to bind to the given event(s)

        • (a, e?): any
        • Parameters

          • a: T
          • Optional e: any

          Returns any

    • Optional insertAtStart: boolean

      Whether or not to insert this listener at the head of the listener queue. Defaults to false.

    Returns EventGenerator

  • Fire the named event.

    Type Parameters

    • T

    Parameters

    • event: string

      Event to fire

    • Optional value: T

      Value to pass to event handlers

    • Optional originalEvent: Event

      Optional original event that caused this event to be fired.

    Returns any

  • Gets the height of the content managed by the viewport, taking any rotated elements into account.

    Returns number

  • Gets the width of the content managed by the viewport, taking any rotated elements into account.

    Returns number

  • Get all elements managed by the Viewport.

    Returns Map<string, ViewportElement<T["E"]>>

  • Gets all listeners for the given named event.

    Parameters

    • forEvent: string

    Returns any[]

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

    Parameters

    • id: string

    Returns ViewportElement<T["E"]>

  • Gets the leftmost point of the content managed by the viewport, taking any rotated elements into account.

    Returns number

  • Gets the topmost of the content managed by the viewport, taking any rotated elements into account.

    Returns number

  • Returns whether or not the viewport is empty.

    Returns boolean

  • Update the size/offset of the element with the given id, and adjust viewport bounds.

    Parameters

    • elId: string
    • Optional doNotRecalculateBounds: boolean

      If true, the viewport's bounds won't be recalculated after the element's size and position has been refreshed.

    Returns ViewportElement<T["E"]>

  • Creates an empty entry for an element with the given ID.

    Parameters

    • id: string
    • Optional doNotRecalculateBounds: boolean

      If true, the viewport's bounds won't be recalculated after the element has been registered.

    Returns ViewportElement<T["E"]>

  • Remove the element with the given ID from the viewport.

    Parameters

    • id: string

    Returns void

  • Clears the internal state of the viewport, removing all elements.

    Returns void

  • Rotates the element with the given id, recalculating bounds afterwards.

    Parameters

    • id: string
    • rotation: number

    Returns ViewportElement<T["E"]>

  • Sets the [x,y] position of the element with the given ID, recalculating bounds.

    Parameters

    • id: string
    • x: number
    • y: number

    Returns ViewportElement<T["E"]>

  • Sets the size of the element with the given ID, recalculating bounds.

    Parameters

    • id: string
    • w: number
    • h: number

    Returns ViewportElement<T["E"]>

  • Sets whether not event firing is currently suspended

    Parameters

    • val: boolean

    Returns void

  • Run the given function without firing any events.

    Parameters

    • fn: Function

    Returns void

  • Unbind the given event listener, or all listeners. If you call this method with no arguments then all event listeners are unbound.

    Parameters

    • Optional eventOrListener: string | Function

      Either an event name, or an event handler function

    • Optional listener: Function

      If eventOrListener is defined, this is the event handler to unbind.

    Returns EventGenerator

  • 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).

    Parameters

    • id: string
    • x: number
    • y: number
    • width: number
    • height: number
    • rotation: number
    • Optional doNotRecalculateBounds: boolean

      Defaults to false. For internal use. If true, does not update viewport bounds after updating the element.

    Returns ViewportElement<T["E"]>

Version :