Provides methods for querying and analyzing directed trees.
Inheritance Hierarchy
TreeAnalyzer
Type Details
- yfiles module
- view-layout-bridge
- yfiles-umd modules
- view-layout-bridge
- Legacy UMD name
- yfiles.analysis.TreeAnalyzer
Class TreeAnalysis offers a larger feature set for analyzing tree graphs. Notably, it allows to analyze only a subset of nodes/edges (see subgraphNodes and subgraphEdges) and it supports the analysis of undirected trees.
Deprecation warning
It is recommended to use the TreeAnalysis class which offers more features instead.Constructors
Initializes a new instance of the TreeAnalyzer class with the given graph.
Parameters
options - Object
A map of options to pass to the method.
A map of options to pass to the method.
- graph - IGraph
- The graph to use for subsequent queries.
Methods
Gets the child nodes of the given node in the tree.
Complexity
O(|V|)
Parameters
options - Object
A map of options to pass to the method.
A map of options to pass to the method.
- node - INode
- The parent node to get children from.
Returns
- ↪IListEnumerable<INode>
- An IEnumerable<T> of
node
's children.
Gets the depth of the node, that is, the length of the path between the root and node
.
Remarks
Nodes with the same depth are commonly drawn in layers in typical tree visualizations.
Complexity
O(|V|)
Parameters
options - Object
A map of options to pass to the method.
A map of options to pass to the method.
- node - INode
- The node to determine the depth for.
Returns
- ↪number
- The distance between the root node and
node
.
Throws
- Exception({ name: 'InvalidOperationError' })
- If the graph is not a tree.
Gets all leaf nodes of the tree.
Remarks
Leaf nodes are nodes without outgoing edges.
Complexity
O(|V|)
Returns
- ↪IListEnumerable<INode>
- An IEnumerable<T> of leaf nodes in the tree.
Throws
- Exception({ name: 'InvalidOperationError' })
- If the graph is not a tree.
Determines the nearest common ancestor for the given nodes.
Remarks
Note that each node is considered to be its own ancestor so the returned node may be one of
nodes
. Another way to look at this is to picture the result to be the root of the smallest sub-tree that contains all nodes
.Complexity
O(|V|)
Parameters
options - Object
A map of options to pass to the method.
A map of options to pass to the method.
- nodes - INode
- The nodes for which to find the nearest common ancestor.
Returns
- ↪INode
- The nearest ancestor of all given nodes or
null
ifnodes
is empty.
Throws
Determines the nearest common ancestor for the given nodes.
Remarks
Note that each node is considered to be its own ancestor so the returned node may be one of
nodes
. Another way to look at this is to picture the result to be the root of the smallest sub-tree that contains all nodes
.Complexity
O(|V|)
Parameters
options - Object
A map of options to pass to the method.
A map of options to pass to the method.
- nodes - IEnumerable<INode>
- The nodes for which to find the nearest common ancestor.
Returns
- ↪INode
- The nearest ancestor of all given nodes or
null
ifnodes
is empty.
Throws
Gets the parent of the given node in the tree.
Gets all nodes of the sub-tree that has subtreeRoot
as root.
Complexity
O(|V|)
Parameters
options - Object
A map of options to pass to the method.
A map of options to pass to the method.
- subtreeRoot - INode
- The sub-tree root node.
Returns
- ↪IListEnumerable<INode>
- An IEnumerable<T> of nodes in the sub-tree of
subtreeRoot
.
Throws
- Exception({ name: 'InvalidOperationError' })
- If the algorithm can't create a valid result due to an invalid graph structure.