Remarks
The hierarchy is represented as a tree where group nodes are the parents of the nodes they contain. Group nodes can contain both normal nodes and other group nodes, and all top-level nodes are children of a virtual root node.
This class caches the hierarchical structure of the graph when instantiated. Therefore, subsequent modifications to the graph may not be reflected in the current instance.
When group nodes are copied or replaced, the original hierarchy should be restored by calling the restore method to avoid inconsistencies.
The following example shows a hierarchical graph containing group nodes, illustrating how nodes are nested inside group nodes:
The figure below shows the tree representing the hierarchical structure of the grouped graph. The labels in the hierarchy tree correspond to nodes from the grouped graph, and group nodes are treated as the parents of their contents.
This class cannot be instantiated
See Also
Developer's Guide
Members
Properties
Gets the virtual root of the hierarchy tree, which is null.
null.Property Value
null.See Also
API
- getChildren
Methods
Clears all grouping information from the current LayoutGraphGrouping.
Return Value
- boolean
trueif clearing was successful, otherwisefalse.
Throws
- Exception ({ name: 'InvalidOperationError' })
- Thrown if the current grouping hierarchy is a read-only view.
Returns the direct children of the specified group node.
Parameters
- parent: LayoutNode
- The group node whose children are to be retrieved.
Return Value
- ILinkedItemEnumerable<LayoutNode>
- The child nodes of the specified parent.
Sample Graphs
5 (grouped graph)See Also
API
- root, getParent, getDescendants
Returns all descendants of the given group node.
Parameters
- parent: LayoutNode
- The group node for which to retrieve descendants. Passing the virtual root node will return all nodes in the graph.
Return Value
- ILinkedItemEnumerable<LayoutNode>
- A collection of nodes that belong to the subtree of the hierarchy tree rooted at the given parent.
Sample Graphs
5 in the grouped graph.See Also
API
- getParent, getChildren
Returns the nearest common ancestor of the given nodes in the hierarchy.
node1 == node2: Returns the parent ofnode1/node2.node1 is an ancestor of node2: Returns the parent ofnode1.node2 is an ancestor of node1: Returns the parent ofnode2.
Parameters
- node1: LayoutNode
- One of the nodes to find the common ancestor for.
- node2: LayoutNode
- The other node to find the common ancestor for.
Return Value
- LayoutNode
- The nearest common ancestor node, or the virtual root if no common ancestor exists.
Sample Graphs
1 and 2 is group node 5 (grouped graph).Returns the parent of the specified node.
Parameters
- node: LayoutNode
- The node for which the parent is determined.
Return Value
- LayoutNode
- The parent of the given node, or
nullif the node is top-level.
Throws
- Exception ({ name: 'ArgumentError' })
- Thrown if the given node is
null.
See Also
Returns the immediate child of a group node that represents the given node.
Parameters
- node: LayoutNode
- The node for which to search for a representative.
- group: LayoutNode
- The group node to which the representative should belong.
Return Value
- LayoutNode
- The representative node or
nullif no representative exists.
Throws
- Exception ({ name: 'ArgumentError' })
- Thrown if the provided
nodeisnull.
Sample Graphs
4 is the representative for node 2 in group node 5 (grouped graph)Determines whether the specified group node has children as per the initial layout grouping.
While normal nodes never have children, group nodes may contain one or more child nodes.
This method checks for children that were part of the group node when the LayoutGraphGrouping was initially created. Note that the current structure of the graph may have changed, so this method reflects only the original layout grouping and not any modifications made afterward.
Parameters
- node: LayoutNode
- The node to check if it has children.
Return Value
- boolean
trueif the node has children; otherwise,false.
See Also
Determines whether the specified node has a parent.
true if the node is contained within a group node, otherwise false.Parameters
- node: LayoutNode
- The node to check.
Return Value
- boolean
trueif the node has a parent; otherwise,false.
Determines whether the specified node is a group node.
Parameters
- node: LayoutNode
- The node to check if it is a group node.
Return Value
- boolean
trueif the node is a group node ornull; otherwise,false.
See Also
API
- hasChildren
Determines whether the given edge is a normal edge, as opposed to an edge that crosses any group node boundaries.
Parameters
- edge: LayoutEdge
- The edge to check.
Return Value
- boolean
trueif the given edge is normal; otherwise,false.
Disposes of all internal data structures held by this LayoutGraphGrouping instance and restores the original grouping structure.
Sets the group node state of the specified node.
Parameters
- node: LayoutNode
- The node whose group node state will be set.
- isGroup: boolean
- A boolean indicating whether the node should be a group node (
true) or a normal node (false).
Throws
Sets the parent for the specified node.
parent is null, the node becomes a top-level node.Parameters
- node: LayoutNode
- The node for which the parent will be set.
- parent: LayoutNode
- The group node to set as the parent of the node, or
nullto make the node a top-level node.
Throws
Static Methods
The old grouping hierarchy should be restored by calling the restore method on the returned LayoutGraphGrouping instance when the copy is no longer needed.
This method can be useful for ensuring that grouping information can be modified or reset to its original state, allowing for easy disposal of intermediate changes to the hierarchy.
The original (replaced) grouping hierarchy does not recognize changes made by the newly created instance, whereas the created instance is aware of changes made directly to the original grouping.
Parameters
- graph: LayoutGraph
- The graph for which the hierarchy is copied.
Return Value
- LayoutGraphGrouping
- A new instance of LayoutGraphGrouping that represents the copied grouping hierarchy, and allows the restoration of the previous hierarchy.
Creates a read-only view of the current grouping hierarchy of the graph.
graph.Parameters
- graph: LayoutGraph
- The LayoutGraph to create a read-only view for.
Return Value
- LayoutGraphGrouping
- A new read-only LayoutGraphGrouping instance.
Temporarily hides the current grouping hierarchy of the graph.
graph.After calling this method, isGrouped will return false.
The hidden hierarchy can be restored by using the returned RestoreToken.
Parameters
- graph: LayoutGraph
- The LayoutGraph whose grouping hierarchy will be hidden.
Return Value
- RestoreToken
- A RestoreToken that can be used to restore the original hierarchy.
Determines whether the given graph is flat.
Parameters
- graph: LayoutGraph
- The graph to check.
Return Value
- boolean
trueif the graph is flat; otherwise,false.
See Also
API
- isGrouped
Determines whether the given graph is grouped.
Parameters
- graph: LayoutGraph
- The graph to check.
Return Value
- boolean
trueif the graph contains hierarchical information, otherwisefalse.
See Also
API
- isFlat
Replaces the existing grouping hierarchy of the graph with a new hierarchy, optionally using the provided isGroupNode and getParent callbacks to define the new hierarchy.
graph with a new hierarchy, optionally using the provided isGroupNode and getParent callbacks to define the new hierarchy.The old grouping hierarchy can be restored by calling the restore method on the returned LayoutGraphGrouping instance.
If both isGroupNode and getParent are null, the new grouping hierarchy will be empty and all nodes are top-level.
The original (replaced) grouping hierarchy does not recognize changes made by the newly created instance, whereas the created instance is aware of changes made directly to the original grouping.
Parameters
- graph: LayoutGraph
- The LayoutGraph whose grouping hierarchy will be replaced.
- isGroupNode?: function(LayoutNode): boolean
- An optional callback to determine if a node should be treated as a group node.
- getParent?: function(LayoutNode): LayoutNode
- An optional callback that returns the parent node for a given node or
nullif the node is top-level.
Return Value
- LayoutGraphGrouping
- A new LayoutGraphGrouping instance that can restore the original hierarchy.