C

PlaceNodesAtBarycenterStageData<TNode, TEdge, TNodeLabel, TEdgeLabel>

Specifies custom data for the PlaceNodesAtBarycenterStage.
Inheritance Hierarchy

Remarks

Type Parameters

TNode

TEdge

TNodeLabel

TEdgeLabel

Examples

The following example shows how to create a new instance of PlaceNodesAtBarycenterStageData<TNode, TEdge, TNodeLabel, TEdgeLabel> and use it with a PlaceNodesAtBarycenterStage:

Creating an instance of PlaceNodesAtBarycenterStageData
const layoutData = new PlaceNodesAtBarycenterStageData({
  affectedNodes: graphComponent.selection.nodes,
})

// Combine the layout data of the stage and the core layout
const compositeLayoutData = coreLayoutData.combineWith(layoutData)

graphComponent.graph.applyLayout(
  new PlaceNodesAtBarycenterStage(coreLayout),
  compositeLayoutData,
)

In many cases the complete initialization of PlaceNodesAtBarycenterStageData<TNode, TEdge, TNodeLabel, TEdgeLabel> can also be done in a single object initializer:

Using an object initializer for easy creation of PlaceNodesAtBarycenterStageData
const layoutData = new PlaceNodesAtBarycenterStageData({
  affectedNodes: graphComponent.selection.nodes,
})

graphComponent.graph.applyLayout(
  new PlaceNodesAtBarycenterStage(coreLayout),
  coreLayoutData.combineWith(layoutData),
)

Members

Show:

Constructors

Parameters

Properties

Gets or sets the collection of nodes that should be affected by the PlaceNodesAtBarycenterStage.
These nodes are temporarily hidden, then the core layout algorithm (if any) is applied to the resulting graph, and, finally, the affected nodes are reinserted by placing them on the barycenter of their neighbors.
conversionfinal

Examples

Defining the subset of nodes that should be temporarily hidden 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>:

Setting a collection of affected nodes
layoutData.affectedNodes = graphComponent.selection.nodes

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:

Adding individual nodes as affected nodes
for (const edge of graphComponent.selection.edges) {
  layoutData.affectedNodes.items.add(edge.sourceNode)
  layoutData.affectedNodes.items.add(edge.targetNode)
}

A powerful option that doesn't use a collection is to use the predicate to set a custom delegate that returns for every node whether it is contained in the set or not:

Using a delegate to determine whether a node is affected or not
// Temporarily hide nodes with labels
layoutData.affectedNodes = (node) => node.labels.size > 0

See Also

API
AFFECTED_NODES_DATA_KEY
Gets or sets the mapping from the affected nodes to their sizes.
The dimension of the affected nodes will be changed to the specified sizes after applying the core layout algorithm.
conversionfinal

See Also

API
AFFECTED_NODES_SIZE_DATA_KEY

Methods

Combines this instance with the given layout data.
This keeps the current instance unmodified and instead returns a new instance that dynamically combines the contents of all involved instances.
final

Parameters

data: LayoutData<TNode, TEdge, TNodeLabel, TEdgeLabel>
The LayoutData<TNode, TEdge, TNodeLabel, TEdgeLabel> to combine this instance with.

Return Value

LayoutData<TNode, TEdge, TNodeLabel, TEdgeLabel>
The combined layout data.

See Also

Developer's Guide
API
CompositeLayoutData, GenericLayoutData