Specifies custom data for the RecursiveGroupLayout.
Examples
The following example shows how to create a new instance of RecursiveGroupLayoutData<TNode,TEdge,TNodeLabel,TEdgeLabel> and use it with an RecursiveGroupLayout:
// Create layout data for both the RecursiveGroupLayout and the layout that's being run
const recursiveGroupLayoutData = new RecursiveGroupLayoutData()
// Use Orthogonal layout for group node contents
recursiveGroupLayoutData.groupNodeLayouts = new OrthogonalLayout()
const organicLayoutData = new OrganicLayoutData()
const orthogonalLayoutData = new OrthogonalLayoutData()
// Configure the other layout data objects ...
// Wrap both into a CompositeLayoutData
const layoutData = new CompositeLayoutData(
recursiveGroupLayoutData,
organicLayoutData,
organicLayoutData,
)
// Run the layout - The top-level layout will be done by an OrganicLayout
graphComponent.graph.applyLayout(
new RecursiveGroupLayout(new OrganicLayout()),
layoutData,
)
In many cases the complete initialization of RecursiveGroupLayoutData<TNode,TEdge,TNodeLabel,TEdgeLabel> can also be done in a single object initializer:
// Create layout data for both the RecursiveGroupLayout and the layout that's being run
const recursiveGroupLayoutData = new RecursiveGroupLayoutData({
// Use Orthogonal layout for group node contents
groupNodeLayouts: new OrthogonalLayout(),
})
const organicLayoutData = new OrganicLayoutData()
// Configure the organic layout data ...
const orthogonalLayoutData = new OrthogonalLayoutData()
// Configure the orthogonal layout data ...
// Wrap all three into a CompositeLayoutData
const layoutData = new CompositeLayoutData(
recursiveGroupLayoutData,
organicLayoutData,
orthogonalLayoutData,
)
// Run the layout - The top-level layout will be done by an OrganicLayout
graphComponent.graph.applyLayout(
new RecursiveGroupLayout(new OrganicLayout()),
layoutData,
)
Another fairly useful way of using RecursiveGroupLayout is to just do a top-level layout and leave the contents of the group nodes alone. This can be done by using FIX_CONTENT_LAYOUT as the layout algorithm for group nodes:
const layoutData = new RecursiveGroupLayoutData()
layoutData.groupNodeLayouts = RecursiveGroupLayout.FIX_CONTENT_LAYOUT
graphComponent.graph.applyLayout(
new RecursiveGroupLayout(new OrthogonalLayout()),
layoutData,
)
Type Parameters
- TNode
- TEdge
- TNodeLabel
- TEdgeLabel
Type Details
- yFiles module
- algorithms
Constructors
Parameters
A map of options to pass to the method.
- groupNodeLayouts - ItemMapping<TNode,ILayoutAlgorithm>
- The mapping from group nodes to the ILayoutAlgorithm used for their child nodes. This option either sets the value directly or recursively sets properties to the instance of the groupNodeLayouts property on the created object.
- nodeMargins - ItemMapping<TNode,Insets>
- The mapping from nodes to their margins. This option either sets the value directly or recursively sets properties to the instance of the nodeMargins property on the created object.
- sourceSplitIds - ItemMapping<TEdge,any>
- A mapping from edges connecting to group nodes to source split IDs. This option either sets the value directly or recursively sets properties to the instance of the sourceSplitIds property on the created object.
- targetSplitIds - ItemMapping<TEdge,any>
- A mapping from edges connecting to group nodes to target split IDs. This option either sets the value directly or recursively sets properties to the instance of the targetSplitIds property on the created object.
- ports - BasicPortData<TNode,TEdge,TNodeLabel,TEdgeLabel>
- The sub-data that provides a way of influencing the placement of the ports. This option either sets the value directly or recursively sets properties to the instance of the ports property on the created object.
- layoutGridData - LayoutGridData<TNode,TEdge,TNodeLabel,TEdgeLabel>
- The layout grid layout data. This option either sets the value directly or recursively sets properties to the instance of the layoutGridData property on the created object.
Properties
Gets or sets the mapping from group nodes to the ILayoutAlgorithm used for their child nodes.
Remarks
The specified layout is applied to the content of the group node. To arrange the top level elements the coreLayout is used.
The core layout is also applied to group nodes if there are no groupNodeLayouts defined at all. Importantly, this must be distinguished from the case that the mapping is defined but null
is mapped with a group. Then, RecursiveGroupLayout handles this group node non-recursively. The group node and its content is arranged using the ILayoutAlgorithm instance specified for the nearest ancestor of the group node which is associated with an ILayoutAlgorithm.
Examples
The layout algorithms for individual group nodes can be specified in various ways, depending on which option is the most convenient. The easiest way would be to set the same layout algorithm for all group nodes:
layoutData.groupNodeLayouts = new OrthogonalLayout()
For scenarios where only some group nodes should have a specific layout algorithm the mapper is usually the best option. However, due to RecursiveGroupLayout's handling of individual group node layouts as described above, this can be a bit complicated to specify since the IMapper<K,V> by default returns null
.
So when only the mapped group nodes should have a layout algorithm applied to their contents a new Mapper<K,V> would have to be created:
const mapper = new Mapper<INode, ILayoutAlgorithm>()
mapper.defaultValue = RecursiveGroupLayout.FIX_CONTENT_LAYOUT
mapper.set(groupNode1, new OrthogonalLayout())
mapper.set(groupNode2, new HierarchicalLayout())
layoutData.groupNodeLayouts = mapper
In cases where all group node's contents should be laid out, most of them with the coreLayout and only some customized, the predefined IMapper<K,V> can be used as is:
layoutData.groupNodeLayouts.mapper.set(groupNode1, new OrthogonalLayout())
layoutData.groupNodeLayouts.mapper.set(
groupNode2,
new HierarchicalLayout(),
)
If the desired layout algorithm for a group node can be readily inferred from the node itself, the mapperFunction is usually the easiest to use:
// Determine the layout for the group node from a property in the tag object
layoutData.groupNodeLayouts = (groupNode: INode): ILayoutAlgorithm => {
switch ((groupNode.tag as CustomData).layoutStyle) {
case 'hierarchic':
return new HierarchicalLayout()
case 'organic':
return new OrganicLayout()
case 'orthogonal':
return new OrthogonalLayout()
case 'none':
default:
return RecursiveGroupLayout.FIX_CONTENT_LAYOUT
}
}
See Also
Gets or sets the layout grid layout data.
Remarks
Gets or sets the mapping from nodes to their margins.
Remarks
Examples
The easiest option is to reserve the same space around all nodes, by setting a constant value:
layoutData.nodeMargins = new Insets(20)
Handling only certain nodes differently can be done easily by using the mapper property:
// node1 only reserves space above and below
layoutData.nodeMargins.mapper.set(node1, new Insets(20, 10, 0, 0))
// node2 has space all around
layoutData.nodeMargins.mapper.set(node2, new Insets(25))
// all other nodes don't get extra space
In cases where the nodeMargins for each node can be determined by looking at the node itself it's often easier to just set a mapperFunction instead of preparing a mapper:
// Retrieve the space around the node from its tag property
layoutData.nodeMargins = (node: INode): Insets =>
new Insets(parseFloat(node.tag))
See Also
Gets or sets the sub-data that provides a way of influencing the placement of the ports.
Remarks
The port placement can be influenced by specifying EdgePortCandidates for the source and target of an edge, as well as by specifying NodePortCandidates at the nodes.
In addition, it is possible to specify that ports should be grouped at the source or target.
If and how the layout algorithm supports these port placement constraints depends on the specified coreLayout, the layout algorithms specified by groupNodeLayouts, and the router for the inter-edges.
Gets or sets a mapping from edges connecting to group nodes to source split IDs.
Remarks
See Also
Gets or sets a mapping from edges connecting to group nodes to target split IDs.
Remarks
See Also
Methods
combineWith
(data: LayoutData<TNode,TEdge,TNodeLabel,TEdgeLabel>…) : LayoutData<TNode,TEdge,TNodeLabel,TEdgeLabel>Combines this instance with the given layout data.
Remarks
Parameters
A map of options to pass to the method.
- data - LayoutData<TNode,TEdge,TNodeLabel,TEdgeLabel>
- The LayoutData<TNode,TEdge,TNodeLabel,TEdgeLabel> to combine this instance with.
Returns
- ↪LayoutData<TNode,TEdge,TNodeLabel,TEdgeLabel>
- The combined layout data.