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.
aggregationPolicy 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
nodeTypePolicy: NodeTypePolicy.SEPARATE_AT_ROOT,
nodeTypes: (node: INode): any => node.tag,
// determine substructures according to the graph structure, not the geometry
aggregationPolicy: 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++
}See Also
Developer's Guide
Members
Constructors
Properties
Gets or sets the policy applied for determining the clusters.
Property Value
See Also
Developer's Guide
Gets or sets a mapping for specifying the directedness of edges.
- A directedness value of
1indicates that the edge is considered to be directed from source to target. - A directedness value of
-1indicates that the edge is considered to be directed from target to source. - A directedness value of
0indicates that the edge is considered to be undirected.
0.0.Gets or sets a mapping for specifying the (non-negative) weights of the edges.
10Property Value
Throws
- Exception ({ name: 'ArgumentError' })
- if a value
< 2is set.
See Also
Developer's Guide
5Property Value
Throws
- Exception ({ name: 'ArgumentError' })
- if a value
< 1is set.
See Also
Developer's Guide
Gets or sets whether nodes are only mapped to leaves of the directed rooted NodeAggregate tree that represents the hierarchical clustering structure.
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.
Property Value
true if nodes are only mapped to leaves, false otherwise.See Also
Developer's Guide
Gets or sets how node types are handled for aggregation.
Gets or sets a mapping which maps nodes to an object that specifies their type.
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 not contain nodes with different type.
Node types are ignored if nothing is set here. Also, if the nodeTypePolicy is set to IGNORE, the node types are not considered, either.
See Also
Developer's Guide
Gets or sets a mapping for specifying the (non-negative) weights of the nodes.
See Also
Developer's Guide
Gets or sets the duration that this algorithm should preferably run before stopping.
Property Value
Throws
Gets or sets the collection of edges which define a subset of the graph for the algorithms to work on.
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
// prepare the node aggregation algorithm
const algorithm = new NodeAggregation({
// Ignore edges without target arrow heads
subgraphEdges: {
excludes: (edge: IEdge): boolean =>
edge.style instanceof PolylineEdgeStyle &&
edge.style.targetArrow instanceof Arrow &&
edge.style.targetArrow.type === ArrowType.NONE,
},
})
// 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++
}Gets or sets the collection of nodes which define a subset of the graph for the algorithms to work on.
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
// prepare the node aggregation algorithm
const algorithm = new NodeAggregation({
subgraphNodes: {
// only consider elliptical nodes in the graph
includes: (node: INode): boolean =>
node.style instanceof ShapeNodeStyle &&
node.style.shape === ShapeNodeShape.ELLIPSE,
// but ignore the first node, regardless of its shape
excludes: graph.nodes.first()!,
},
})
// 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++
}algorithm.subgraphNodes = graphComponent.selection.nodesalgorithm.subgraphNodes.excludes = (n) => graph.isGroupNode(n)algorithm.subgraphNodes = graphComponent.selection.nodes
algorithm.subgraphNodes.excludes = (n) => graph.isGroupNode(n)Gets or sets the top-level nodes of the aggregation info.
See Also
Developer's Guide
Methods
Aggregates the nodes of the given graph and creates a hierarchical clustering structure.
graph and creates a hierarchical clustering structure.Parameters
- graph: IGraph
- The input graph to run the algorithm on.
Return Value
- 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
nodeTypePolicy: NodeTypePolicy.SEPARATE_AT_ROOT,
nodeTypes: (node: INode): any => node.tag,
// determine substructures according to the graph structure, not the geometry
aggregationPolicy: 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++
}