DEMOS
DOCS
FEATURES
DOWNLOAD
PURCHASE
CONTACT
BLOG
Show:

Selection Class

Constructor

Selection

(
  • params
)

Parameters:

  • params Object

    Constructor params

    • toolkit JsPlumbToolkitInstance

      jsPlumb Toolkit instance to which this Selection belongs.

    • [generator] Function optional

      Optional function that can be called to fill the selection. You'd use this when you are rendering individual selections and you need to be able to refresh the whole view based on some change in the data model.

    • [onClear] Function optional

      Optional function to call when the selection is cleared.

Methods

append

(
  • obj
)

Appends the given object to the selection.

Parameters:

  • obj Node | Edge | Node[] | Edge[] | Path

    Object(s) to add. May take many forms - a Node, Node Id, or Edge, or a list of these, or a Path.

clear

()

Clears this selection.

each

(
  • fn
  • [type="Node"]
)

Iterates the objects of the given type in the selection, calling the supplied callback for each item. The callback's signature should be function(index, item). If you don't supply type, the default of "Node" will be used.

Parameters:

  • fn Function

    Function to call with each item.

  • [type="Node"] String optional

eachEdge

(
  • fn
)

Iterates the Edges in the selection, calling the supplied callback for each item. The callback's signature should be function(index, item).

Parameters:

  • fn Function

    Function to call with each item.

eachGroup

(
  • fn
)

Iterates the Groups in the selection, calling the supplied callback for each item. The callback's signature should be function(index, item).

Parameters:

  • fn Function

    Function to call with each item.

eachNode

(
  • fn
)

Iterates the Nodes in the selection, calling the supplied callback for each item. The callback's signature should be function(index, item).

Parameters:

  • fn Function

    Function to call with each item.

eachNodeOrGroup

(
  • fn
)

Iterates the Nodes and the Groups in the selection, calling the supplied callback for each item. The callback's signature should be function(index, item).

Parameters:

  • fn Function

    Function to call with each item.

get

(
  • idx
)
Object

Gets the Node/Port at the given index.

Parameters:

  • idx Integer

    Index of the Node/Port to retrieve.

Returns:

Object:

Node/Port at the given index, null if nothing found at that index.

getAllEdgesFor

(
  • node
  • [filter]
)
Edge[]

Gets all Edges for the given Node or Group.

Parameters:

  • node Node

    The Node to get Edges for.

  • [filter] Function optional

    Optional filter for edges.

Returns:

getEdge

(
  • idx
)
Object

Gets the Edge at the given index.

Parameters:

  • idx Integer

    Index of the Edge to retrieve.

Returns:

Object:

Edge at the given index, null if nothing found at that index.

getEdgeCount

() Number

Get the current number of Edges in the selection.

Returns:

Number:

getEdges

() Array

Gets all the edges in the selection

Returns:

Array:

All the edges in the selection, perhaps an empty list. Never null.

getGroup

(
  • id
)

Gets the Group with the given ID

Parameters:

  • id String

    ID of the Group to retrieve

getGroupAt

(
  • idx
)
Group

Gets the Group at the given index.

Parameters:

  • idx Object

    Index of the Gorup to retrieve. Will return null if index out of range.

Returns:

Group:

A Group, or null.

getGroupCount

() Number

Get the current number of Groups in the selection.

Returns:

Number:

getGroups

() Group[]

Gets all the Groups in the Selection.

Returns:

getNode

(
  • id
)

Gets the Node with the given ID

Parameters:

  • id String

    ID of the Node to retrieve

getNodeAt

(
  • idx
)
Node

Gets the node at the given index.

Parameters:

  • idx Object

    Index of the Node to retrieve. Will return null if index out of range.

Returns:

Node:

A Node, or null.

getNodeCount

() Number

Get the current number of Nodes in the selection.

Returns:

Number:

getNodes

() Node[]

Gets all the Nodes in the Selection.

Returns:

getSourceEdgesFor

(
  • node
)
Edge[]

Gets all source Edges for the given Node or Group.

Parameters:

  • node Node | Group

    The Node to get source Edges for.

Returns:

reload

()

Reloads the content of this Selection, if a generator was supplied to the constructor. Otherwise does nothing. A data load start event is fired first, followed by a call to the generator to repopulate, and then a data load end event is fired. So calling this method on a Selection that you are rendering to a Surface will cause the Surface to repaint itself.

remove

(
  • obj
)

Removes the given object from the selection.

Parameters:

  • obj Node | Edge | Node[] | Edge[] | Path

    Object(s) to remove. May take many forms - a Node, Node Id, or Edge, or a list of these, or a Path.

setCapacityPolicy

(
  • policy
)

Sets the action taken when appending an edge or node that would take the selection above its limit for that given type. Depends on the current capacityPolicy, which can be either jsPlumbUtil.Selection.DISCARD_EXISTING (the default) or jsPlumbUtil.Selection.DISCARD_NEW.

Parameters:

  • policy String

    One of jsPlumbUtil.Selection.DISCARD_EXISTING (which removes the 0th entry from the list before insertion of the new value) or jsPlumbUtil.Selection.DISCARD_NEW.

setMaxEdges

(
  • _maxEdges
)

Sets the maximum number of edges the selection can hold. The action taken when appending an edge that would take the selection above its limit depends on the current capacityPolicy, which can be either Selection.DISCARD_EXISTING (the default) or Selection.DISCARD_NEW.

Parameters:

  • _maxEdges Integer

setMaxNodes

(
  • _maxNodes
)

Sets the maximum number of nodes the selection can hold. The action taken when appending a node that would take the selection above its limit depends on the current capacityPolicy, which can be either Selection.DISCARD_EXISTING (the default) or Selection.DISCARD_NEW.

Parameters:

  • _maxNodes Integer

toggle

(
  • obj
)

Toggles the given object's membership in the current selection. If obj is a Path, then the individual members of the Path are toggled independently.

Parameters:

  • obj Node | Edge | Node[] | Edge[] | Path

    Object(s) to add. May take many forms - a Node, Node Id, or Edge, or a list of these, or a Path.