Querying the model
The VisuallyJs model offers several methods to query the hierarchy of nodes and groups.
Groups
When you have a hierarchical model where nodes or groups can be nested within other groups, you can use these methods to navigate the hierarchy.
Ancestor groups
getAncestors
Gets a list of groups that are ancestors of the given node/group (or port, for which we first resolve the node/group it resides on). The list of ancestors is ordered in terms of their proximity to the focus, ie. the first entry is the focus vertex's immediate parent.
Signature
getAncestors(vertex:Vertex)
Parameters
| vertex | Vertex |
Return value
Array<Group>Descendants of a group
Testing for ancestor
Testing for descendant
Selecting descendants
While the methods above return arrays of objects, you may sometimes want to perform selection-based operations on a hierarchy.
selectDescendants
Selects all descendants of some Node or Group, and, optionally, the Node/Group itself.
Signature
Parameters
| obj | string | Node | Group | Node/Group, or ID of Node/Group, to select |
| includeFocus | boolean | Whether or not to include the focus node/group in the returned dataset. Defaults to false. |
| includeEdges | boolean | Whether or not to include edges in the returned dataset. Defaults to false. |
Return value
VisuallyJsSelection