Skip to main content

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
vertexVertex
Return value
Array<Group>

Descendants of a group​

getDescendants​

Gets a list of nodes/groups that are descendants of the given group.
Signature
getDescendants(vertex:Group)
Parameters
vertexGroup
Return value
Array<Node | Group>

Testing for ancestor​

isAncestor​

Returns whether or not possibleAncestor is in fact an ancestor of the given focus node/group
Signature
isAncestor(focus:Vertex, possibleAncestor:Group)
Parameters
focusVertexVertex to test
possibleAncestorGroupGroup which may be an ancestor of focus
Return value
boolean

Testing for descendant​

isDescendantGroup​

Determine whether possibleDescendant is in fact a descendant of the ancestor group
Signature
isDescendantGroup(possibleDescendant:Group, ancestor:Group)
Parameters
possibleDescendantGroupGroup to test
ancestorGroupAncestor group
Return value
boolean

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
selectDescendants(obj:string | Node | Group, includeFocus:boolean, includeEdges:boolean)
Parameters
objstring | Node | GroupNode/Group, or ID of Node/Group, to select
includeFocusbooleanWhether or not to include the focus node/group in the returned dataset. Defaults to false.
includeEdgesbooleanWhether or not to include edges in the returned dataset. Defaults to false.