Specifies custom data for the SubgraphLayout.
Examples
The following example shows how to create a new instance of this class and use it in conjunction with a MultiStageLayout that has a SubgraphLayout already in its pipeline:
const hierarchicLayout = new HierarchicLayout({ subgraphLayoutEnabled: true })
const subgraphLayoutData = new SubgraphLayoutData()
//only nodes that have at least one adjacent edge are included and visible for the hierarchic layout
subgraphLayoutData.subgraphNodes = (node) => graph.degree(node) > 0
graphComponent.graph.applyLayout(hierarchicLayout, subgraphLayoutData)
The SubgraphLayout and its SubgraphLayoutData can be used as a stage with any other layout algorithm:
//create an edge routing algorithm wrapped by a subgraph layout stage
const layout = new SubgraphLayout(new EdgeRouter())
const layoutData = new SubgraphLayoutData()
//exclude edges that are a self-loop -> will not be visible for the core layout (EdgeRouter in this example)
layoutData.subgraphEdges.excludes = (edge) => edge.isSelfloop
graphComponent.graph.applyLayout(layout, layoutData)
Type Details
- yfiles module
- view-layout-bridge
- yfiles-umd modules
- view-layout-bridge
- Legacy UMD name
- yfiles.layout.SubgraphLayoutData
Constructors
Creates a new instance of SubgraphLayoutData which helps configuring SubgraphLayout.
Parameters
A map of options to pass to the method.
- subgraphNodes - DpKeyItemCollection<INode>
The collection of subgraph nodes that are included in the graph, thus, are visible for the core layout algorithm of the SubgraphLayout. This option sets the subgraphNodes property on the created object.
- subgraphEdges - DpKeyItemCollection<IEdge>
The collection of subgraph edges that are included in the graph, thus, are visible for the core layout algorithm of the SubgraphLayout. This option sets the subgraphEdges property on the created object.
Properties
Gets or sets the collection of subgraph edges that are included in the graph, thus, are visible for the core layout algorithm of the SubgraphLayout.
Remarks
If nothing is set, all edges of the graph will be included in the subgraph.
If only the excludes are set all edges in the graph except those provided in the excludes are part of the subgraph.
Note that edges which start or end at nodes which are not in the subgraphNodes are automatically excluded.
Examples
Defining the subgraph edges can be done in various ways, mostly depending on which option is more convenient for a particular use case. You can use the ItemCollection<TItem>'s source property to use any .NET collection or IEnumerable<T>:
layoutData.subgraphEdges = graphComponent.selection.selectedEdges
Alternatively, ItemCollection<TItem> also has an items property, which is a collection that already exists, in case the items may have to be added one by one. This can be more convenient than defining an own list and setting it to source:
layoutData.subgraphEdges.items.add(edge1)
layoutData.subgraphEdges.items.add(edge2)
A powerful option that doesn't use a collection is to use the delegate to set a custom delegate that returns for every edge whether it is contained in the subgraph or not:
// We assume here that all edges have a data instance as their tag,
// which then has a boolean property 'includeInSubgraph'.
layoutData.subgraphEdges = (edge) => edge.tag.includeInSubgraph
To only exclude specific edges, the excludes property can be used:
// In this example two specific edges are excluded
layoutData.subgraphEdges.excludes = (edge) =>
excludedEdge1 === edge || excludedEdge2 === edge
See Also
Gets or sets the collection of subgraph nodes that are included in the graph, thus, are visible for the core layout algorithm of the SubgraphLayout.
Remarks
If nothing is set, all nodes of the graph will be included in the subgraph.
If only the excludes are set all nodes in the graph except those provided in the excludes are part of the subgraph.
Examples
Defining the subgraph nodes can be done in various ways, mostly depending on which option is more convenient for a particular use case. You can use the ItemCollection<TItem>'s source property to use any .NET collection or IEnumerable<T>:
layoutData.subgraphNodes = graphComponent.selection.selectedNodes
Alternatively, ItemCollection<TItem> also has an items property, which is a collection that already exists, in case the items may have to be added one by one. This can be more convenient than defining an own list and setting it to source:
layoutData.subgraphNodes.items.add(node1)
layoutData.subgraphNodes.items.add(node2)
A powerful option that doesn't use a collection is to use the delegate to set a custom delegate that returns for every node whether it is contained in the subgraph or not:
// We assume here that all nodes have a data instance as their tag,
// which then has a boolean property 'includeInSubgraph'.
layoutData.subgraphNodes = (node) => node.tag.includeInSubgraph
To only exclude specific nodes, the excludes property can be used:
// In this example two specific nodes are excluded
layoutData.subgraphNodes.excludes = (node) =>
excludedNode1 === node || excludedNode2 === node
See Also
Methods
Combines this instance with the given layout data.
Remarks
Parameters
A map of options to pass to the method.
- data - LayoutData
- The LayoutData to combine this instance with.
Returns
- ↪LayoutData
- The combined layout data.