documentationfor yFiles for HTML 3.0.0.3

IGraphSelection

Manages the selection state of items in an IGraph instance.

Inheritance Hierarchy
IGraphSelection
Implemented Interfaces

Remarks

An implementation of this interface is typically obtained from selection.

This interface provides access to the IObservableCollection<T> instances that manage the set of selected nodes, edges, labels, ports, and bends. The methods on the instance that use IModelItem parameters delegate to the corresponding domain-specific selection models.

Typically, only items that are in the current graph may be selected and the selection will automatically be adjusted when elements get removed from the graph.

Examples

In order to work with the selection of a graph, obtain the selection from the GraphComponent:
Working with the graph selection.
// Determine whether an item is selected
let selected = graphComponent.selection.includes(node)
// alternatively, if you know the type:
selected = graphComponent.selection.nodes.includes(node)

// Deselect an edge
graphComponent.selection.remove(edge)

// check whether the selection is empty
const isEmpty = graphComponent.selection.size === 0

// Iterate over selected nodes
for (const n of graphComponent.selection.nodes) {
  // ...
}

// Iterate all selected items
graphComponent.selection.forEach((selection) => {
  // ...
})

// Unselect all edges
graphComponent.selection.edges.clear()

// clear the whole selection
graphComponent.selection.clear()

// select all nodes
graphComponent.graph.nodes.forEach((n) => {
  graphComponent.selection.nodes.add(n)
})

// listen to low-level changes in the selection
graphComponent.selection.addEventListener('item-added', (args) => {
  console.log(`Selected ${args.item}`)
})
graphComponent.selection.addEventListener('item-removed', (args) => {
  console.log(`Deselected ${args.item}`)
})

Type Details

yFiles module
view

See Also

Properties

Methods

Events