Aggregates the nodes of a given graph and creates a hierarchical clustering structure subject to user-specified constraints.
Remarks
The result is subject to user-specified constraints like the type of nodes as well as the preferred minimum and maximum size of a cluster. The result of the aggregation can be used to (interactively) visualize parts of large graphs.
Note that the resulting clustering structure corresponds to a directed rooted tree which is encoded by means of a set of NodeAggregate instances. More precisely, each node of the original graph is mapped to a unique NodeAggregate instance. Each NodeAggregate has a reference to its parent which induces a directed tree structure.There is always exactly one NodeAggregate without a parent that represents the root of the tree.
aggregation specifies whether the algorithm should consider structural properties (i.e., considering the connectivity) for the aggregation or geometric properties (i.e., the distance between nodes).
Examples
// prepare the node aggregation algorithm
const algorithm = new NodeAggregation({
// group according to the node types which are specified in the node's tag
nodeTypeHandling:
NodeAggregationNodeTypeHandlingPolicy.SEPARATE_AT_ROOT,
nodeTypes: (node) => node.tag,
// determine substructures according to the graph structure, not the geometry
aggregation: NodeAggregationPolicy.STRUCTURAL
})
// run the algorithm
const result = algorithm.run(graph)
// highlight the nodes of the aggregates with different styles
// group by the top level aggregates
let index = 0
for (const aggregate of result.root.children) {
for (const node of aggregate.nodes) {
graph.setStyle(node, clusterStyles.get(index))
}
index++
}
// prepare the node aggregation algorithm
const algorithm = new NodeAggregation({
// group according to the node types which are specified in the node's tag
nodeTypeHandling:
NodeAggregationNodeTypeHandlingPolicy.SEPARATE_AT_ROOT,
nodeTypes: (node: INode): any => node.tag,
// determine substructures according to the graph structure, not the geometry
aggregation: NodeAggregationPolicy.STRUCTURAL
})
// run the algorithm
const result = algorithm.run(graph)
// highlight the nodes of the aggregates with different styles
// group by the top level aggregates
let index = 0
for (const aggregate of result.root.children) {
for (const node of aggregate.nodes) {
graph.setStyle(node, clusterStyles.get(index)!)
}
index++
}
Type Details
- yfiles module
- view-layout-bridge
- yfiles-umd modules
- view-layout-bridge
- Legacy UMD name
- yfiles.analysis.NodeAggregation
See Also
Constructors
Creates a new instance with default settings.
Parameters
A map of options to pass to the method.
- subgraphNodes - ItemCollection<INode>
The collection of nodes which define a subset of the graph for the algorithms to work on. This option sets the subgraphNodes property on the created object.
- subgraphEdges - ItemCollection<IEdge>
The collection of edges which define a subset of the graph for the algorithms to work on. This option sets the subgraphEdges property on the created object.
- topLevelNodes - ItemCollection<INode>
The top-level nodes of the aggregation info. This option sets the topLevelNodes property on the created object.
- nodeTypes - ItemMapping<INode,Object>
A mapping which maps nodes to an object which specifies their type. This option sets the nodeTypes property on the created object.
- nodeWeights - ItemMapping<INode,number>
A mapping for specifying the (non-negative) weights of the nodes. This option sets the nodeWeights property on the created object.
- edgeWeights - ItemMapping<IEdge,number>
A mapping for specifying the (non-negative) weights of the edges. This option sets the edgeWeights property on the created object.
- edgeDirectedness - ItemMapping<IEdge,number>
A mapping for specifying the directedness of edges. This option sets the edgeDirectedness property on the created object.
- aggregation - NodeAggregationPolicy
The policy applied for determining the clusters. This option sets the aggregation property on the created object.
- nodeTypeHandling - NodeAggregationNodeTypeHandlingPolicy
How node types are handled for aggregation. This option sets the nodeTypeHandling property on the created object.
- minimumClusterSize - number
The preferred minimum number of elements contained in a cluster. This option sets the minimumClusterSize property on the created object.
- maximumClusterSize - number
The preferred maximum number of elements contained in a cluster. This option sets the maximumClusterSize property on the created object.
- maximumDuration - TimeSpan
The maximum duration that this algorithm is allowed to run. This option sets the maximumDuration property on the created object.
- nodesOnlyOnLeaves - boolean
Whether or not nodes are only mapped to leaves of the directed rooted aggregation tree that represents the hierarchical clustering structure. This option sets the nodesOnlyOnLeaves property on the created object.
Properties
Gets or sets the policy applied for determining the clusters.
Gets or sets a mapping for specifying the directedness of edges.
Remarks
- A directedness value of
1
indicates that the edge is considered to be directed from source to target. - A directedness value of
-1
indicates that the edge is considered to be directed from target to source. - A directedness value of
0
indicates that the edge is considered to be undirected.
0.0
.Gets or sets a mapping for specifying the (non-negative) weights of the edges.
Remarks
Gets or sets the preferred maximum number of elements contained in a cluster.
Remarks
10
Throws
- Exception({ name: 'ArgumentError' })
- if a value
< 2
is set.
See Also
Gets or sets the maximum duration that this algorithm is allowed to run.
Remarks
Throws
- Exception({ name: 'ArgumentError' })
- if the specified duration is less than
.
Gets or sets the preferred minimum number of elements contained in a cluster.
Remarks
5
Throws
- Exception({ name: 'ArgumentError' })
- if a value
< 1
is set.
See Also
Gets or sets whether or not nodes are only mapped to leaves of the directed rooted aggregation tree that represents the hierarchical clustering structure.
Remarks
If set to false
, nodes can also represent inner nodes and, thus, the associated NodeAggregate can contain other node elements. This may allow a more efficient representation of the resulting tree structure. For example, for a star-like structure in the input graph, the root of the star can directly represent the parent aggregate of the star. Otherwise, an additional virtual tree node is inserted.
Default is true
.
See Also
Gets or sets a mapping which maps nodes to an object which specifies their type.
Remarks
The type objects can be arbitrary objects. Nodes mapped to equal objects are considered to be of the same type. After aggregating, the resulting clusters do never contain nodes with different type.
Node types are ignored if nothing is set here. Also, if the nodeTypeHandling is set to IGNORE, the node types are not considered, either.
See Also
Gets or sets a mapping for specifying the (non-negative) weights of the nodes.
Remarks
See Also
Gets or sets the collection of edges which define a subset of the graph for the algorithms to work on.
Remarks
If nothing is set, all edges of the graph will be processed.
If only the excludes are set all edges in the graph except those provided in the excludes are processed.
Note that edges which start or end at nodes which are not in the subgraphNodes are automatically not considered by the algorithm.
ItemCollection<T> instances may be shared among algorithm instances and will be (re-)evaluated upon (re-)execution of the algorithm.
Examples
Gets or sets the collection of nodes which define a subset of the graph for the algorithms to work on.
Remarks
If nothing is set, all nodes of the graph will be processed.
If only the excludes are set all nodes in the graph except those provided in the excludes are processed.
ItemCollection<T> instances may be shared among algorithm instances and will be (re-)evaluated upon (re-)execution of the algorithm.
Examples
Gets or sets the top-level nodes of the aggregation info.
Remarks
See Also
Methods
Aggregates the nodes of the given graph
and creates a hierarchical clustering structure.
Remarks
Parameters
A map of options to pass to the method.
- graph - IGraph
- The input graph to run the algorithm on.
Returns
- ↪NodeAggregationResult
- The hierarchical clustering of the
graph
.
Throws
- Exception({ name: 'InvalidOperationError' })
- If the algorithm can't create a valid result due to an invalid graph structure or wrongly configured properties.
Examples
// prepare the node aggregation algorithm
const algorithm = new NodeAggregation({
// group according to the node types which are specified in the node's tag
nodeTypeHandling:
NodeAggregationNodeTypeHandlingPolicy.SEPARATE_AT_ROOT,
nodeTypes: (node) => node.tag,
// determine substructures according to the graph structure, not the geometry
aggregation: NodeAggregationPolicy.STRUCTURAL
})
// run the algorithm
const result = algorithm.run(graph)
// highlight the nodes of the aggregates with different styles
// group by the top level aggregates
let index = 0
for (const aggregate of result.root.children) {
for (const node of aggregate.nodes) {
graph.setStyle(node, clusterStyles.get(index))
}
index++
}
// prepare the node aggregation algorithm
const algorithm = new NodeAggregation({
// group according to the node types which are specified in the node's tag
nodeTypeHandling:
NodeAggregationNodeTypeHandlingPolicy.SEPARATE_AT_ROOT,
nodeTypes: (node: INode): any => node.tag,
// determine substructures according to the graph structure, not the geometry
aggregation: NodeAggregationPolicy.STRUCTURAL
})
// run the algorithm
const result = algorithm.run(graph)
// highlight the nodes of the aggregates with different styles
// group by the top level aggregates
let index = 0
for (const aggregate of result.root.children) {
for (const node of aggregate.nodes) {
graph.setStyle(node, clusterStyles.get(index)!)
}
index++
}