Graph
Data representing a (potentially directed) graph.
A graph is guaranteed to have several invariants enforced:
- In undirected graphs, for each edge (i, j), there is the edge (j, i) in the graph.
- Each node has a fixed number of features (see GraphNode.features).
- Each edge has a fixed number of features (see GraphEdge.features). These invariants ensure that:
- Deleting a node is O(log(N)) (assuming some fixed number of edges per node).
- Features can be accessed by index, and are guaranteed to exist. Self-loops are allowed.
Extends
Properties
| Property | Type | Description |
|---|---|---|
matrixToWorld | mat4 | The matrix of this Graph mapping to world coordinates. |
matrixFromWorld | mat4 | The matrix of this Graph mapping from world coordinates. |
Accessors
Inherited from Data
| Accessor | Description |
|---|---|
| name | The name of the dataset |
Methods
| Method | Description |
|---|---|
| numNodes() | |
| numEdges() | |
| dimension() | |
| type() | |
| nodeFeatureNames() | |
| edgeFeatureNames() | |
| getNodeFeature() | Returns the node feature index, or undefined if the name is not present. |
| addNodeFeature() | Adds a node feature with the given name. |
| getEdgeFeature() | Returns the edge feature index, or undefined if the name is not present. |
| addEdgeFeature() | Adds an edge feature with the given name. |
| addNode() | Adds a node and assigns it an index. |
| nodes() | Returns All nodes, ordered by node index. |
| editNode() | Edits a node. |
| removeNode() | Removes a node and its incident edges. |
| addEdge() | Adds an edge between two existing nodes. |
| edges() | Returns all edges. |
| editEdge() | Edits an edge. |
| removeEdge() | Removes an edge. |
| displayOptions() | |
| edge() | Returns an edge, or undefined if the directed edge does not exist. |
| node() | Returns a node, or undefined if the index does not exist. |
Inherited from Data
| Method | Description |
|---|---|
| kind() | Returns the kind of this data. |
| modality() | Returns the modality of this data. |
| bounds() | Returns the axis-aligned bounding box of this data in world space. |
Inherited from ClassHandle
| Method | Description |
|---|---|
| isAliasOf() | Returns true if this handle and other alias the same underlying C++ object. |
| delete() | Releases this JavaScript handle. |
| deleteLater() | Schedules this handle for deferred deletion and returns this handle. |
| isDeleted() | Returns true if this handle has already been deleted. |
| [dispose]() | Releases this handle when the enclosing scope exits, so a handle can be declared with using instead of calling delete() later manually. |
| clone() | Returns a new JavaScript handle aliasing the same underlying C++ object. |
numNodes()
Returns
number
The number of nodes of this graph.
numEdges()
Returns
number
The number of edges of this graph.
dimension()
Returns
Whether this graph is planar or three-dimensional.
type()
Returns
Whether the edges of this graph are directed.
nodeFeatureNames()
Returns
The names of the features attached to every node, in feature order.
edgeFeatureNames()
Returns
The names of the features attached to every edge, in feature order.
getNodeFeature()
Returns the node feature index, or undefined if the name is not present.
Parameters
| Parameter | Type |
|---|---|
name | EmbindString |
Returns
number | undefined
addNodeFeature()
Adds a node feature with the given name. All existing and subsequently added nodes are assigned defaultValue if no explicit value is provided in the respective addNode function.
Parameters
| Parameter | Type | Description |
|---|---|---|
name | EmbindString | - |
defaultValue? | number | Defaults to 0. |
Returns
number | undefined
The feature index in GraphNode.features, or undefined if the name already exists.
getEdgeFeature()
Returns the edge feature index, or undefined if the name is not present.
Parameters
| Parameter | Type |
|---|---|
name | EmbindString |
Returns
number | undefined
addEdgeFeature()
Adds an edge feature with the given name. All existing and subsequently added edges are assigned defaultValue if no explicit value is provided in the respective addEdge function.
Parameters
| Parameter | Type | Description |
|---|---|---|
name | EmbindString | - |
defaultValue? | number | Defaults to 0. |
Returns
number | undefined
The feature index in GraphEdge.features, or undefined if the name already exists.
addNode()
Adds a node and assigns it an index. Omitted feature values are populated from the node feature defaults.
Parameters
Returns
number
The new node index.
nodes()
Returns All nodes, ordered by node index.
Returns
editNode()
Edits a node.
Parameters
| Parameter | Type | Description |
|---|---|---|
index | number | - |
options | { position?: vec3; features?: number[]; } | Position and/or complete feature array to replace. Omitted properties remain unchanged. |
options.position? | vec3 | - |
options.features? | number[] | - |
Returns
boolean
Whether the node existed and was edited.
removeNode()
Removes a node and its incident edges.
Parameters
| Parameter | Type |
|---|---|
index | number |
Returns
boolean
Whether the node existed and was removed.
addEdge()
Adds an edge between two existing nodes.
Parameters
| Parameter | Type |
|---|---|
edge | { from: number; to: number; features?: number[]; } |
edge.from | number |
edge.to | number |
edge.features? | number[] |
Returns
boolean
false if either node does not exist or the edge already exists.
edges()
Returns all edges. Undirected edges are returned once.
Returns
editEdge()
Edits an edge.
Parameters
| Parameter | Type | Description |
|---|---|---|
from | number | - |
to | number | - |
options | { features: number[]; } | Complete feature array to replace. |
options.features | number[] | - |
Returns
boolean
Whether the edge existed and was edited.
removeEdge()
Removes an edge.
Parameters
| Parameter | Type |
|---|---|
from | number |
to | number |
Returns
boolean
false if the directed edge does not exist.
displayOptions()
Returns
GraphDisplayOptions for configuring Graph rendering.
edge()
Returns an edge, or undefined if the directed edge does not exist.
For undirected graphs, either node order addresses the same edge.
Parameters
| Parameter | Type |
|---|---|
from | number |
to | number |
Returns
GraphEdge | undefined
node()
Returns a node, or undefined if the index does not exist.
Parameters
| Parameter | Type |
|---|---|
index | number |
Returns
GraphNode | undefined