Skip to content

@graphty/graphty-element / session / SelectionApi

Interface: SelectionApi ​

Defined in: graphty-element/src/session/selection/SelectionApi.ts:177

The one selection a session holds.

A consumer that only needs to know whether an element is selected calls SelectionApi.has and touches no array at all; SelectionApi.nodes and SelectionApi.edges exist for a consumer that wants to iterate, and are not the boundary type, because a list of every selected id is unbounded in a way the masks are not.

Properties ​

cap ​

readonly cap: number

Defined in: graphty-element/src/session/selection/SelectionApi.ts:191

The most elements this selection will hold.


edges ​

readonly edges: readonly string[]

Defined in: graphty-element/src/session/selection/SelectionApi.ts:187

The selected edge ids, frozen and identity-stable in the same way.


nodes ​

readonly nodes: readonly NodeId[]

Defined in: graphty-element/src/session/selection/SelectionApi.ts:185

The selected node ids, in ascending index order.

Frozen and IDENTITY-STABLE: the same array object comes back until the contents change, so previous === next is a valid staleness test and a read of an unchanged selection costs nothing.


origin ​

readonly origin: SelectionTarget | null

Defined in: graphty-element/src/session/selection/SelectionApi.ts:212

The target the selection was made from, as it was passed to apply, while the selection is still exactly that target: { neighborsOf: ["Javert"] } after a neighborhood was selected, so a panel that did not make the call can tell a neighborhood from any other set of nodes. A frozen copy: changing the object you passed does not change it.

Null before anything was selected, after an apply that adds to, removes from, toggles or intersects the selection, after a replace the cap cut short, and once anything else changes the selection or the graph -- a click, an undo or redo, clear(), or any edit to the graph's nodes, edges or data (the target might name something different now).

ts
const origin = session.selection.origin;
if (origin !== null && "neighborsOf" in origin && origin.neighborsOf?.length === 1) {
    showNeighbors(origin.neighborsOf[0]);
}

size ​

readonly size: number

Defined in: graphty-element/src/session/selection/SelectionApi.ts:189

How many elements are selected, counting nodes and edges together.


truncated ​

readonly truncated: boolean

Defined in: graphty-element/src/session/selection/SelectionApi.ts:193

Whether the last mutation dropped elements to stay within the cap.

Methods ​

apply() ​

apply(target, op?): Promise<SelectionDelta>

Defined in: graphty-element/src/session/selection/SelectionApi.ts:240

Change the selection.

Parameters ​

target ​

SelectionTarget

What to select.

op? ​

SelectionOp

What to do with it. Replaces the selection when absent, which is what a click does.

Returns ​

Promise<SelectionDelta>

What changed.


clear() ​

clear(): SelectionDelta

Defined in: graphty-element/src/session/selection/SelectionApi.ts:245

Empty the selection.

Returns ​

SelectionDelta

What changed.


edgeMask() ​

edgeMask(): Uint8Array

Defined in: graphty-element/src/session/selection/SelectionApi.ts:232

The selected edges as one byte per edge, for a worker.

Returns ​

Uint8Array

A detached copy, one byte per edge of the current graph.


has() ​

has(id): boolean

Defined in: graphty-element/src/session/selection/SelectionApi.ts:222

Whether one element is selected.

One array read, and no allocation at all, so a render loop can ask once per element per frame. It reads the masks as they stand and never walks or rebuilds anything, which is why it is the only member that does not first reconcile with the current graph.

Parameters ​

id ​

NodeId

The node or edge id.

Returns ​

boolean

True when the element is selected.


nodeMask() ​

nodeMask(): Uint8Array

Defined in: graphty-element/src/session/selection/SelectionApi.ts:227

The selected nodes as one byte per node, for a worker.

Returns ​

Uint8Array

A detached copy, one byte per node of the current graph.


promote() ​

promote(name): string

Defined in: graphty-element/src/session/selection/SelectionApi.ts:258

Keep this selection under a name, as a kept set created from the selection, so it can be named as { set: id } later.

The kept set holds the selected nodes and the selected edges. With nodes selected it reads induced: every edge between its nodes comes with it, and the selected edges are kept beside them. With edges alone it reads listed: those edges and their endpoints.

Parameters ​

name ​

string

The name to save it under.

Returns ​

string

The minted set id.

Deprecated ​

Use session.sets.createFrom("selection"), which keeps the same members and also takes a reading; this verb keeps working.


statistics() ​

statistics(): Promise<SelectionStatistics>

Defined in: graphty-element/src/session/selection/SelectionApi.ts:263

What the current selection adds up to.

Returns ​

Promise<SelectionStatistics>

The statistics.