C

SequenceConstraintData<TNode, TEdge, TItem>

Specifies sequence constraints for TNode and TEdge for a HierarchicalLayout.
Inheritance Hierarchy

Remarks

Sequence constraints affect the sequence of nodes within a layer.

If itemComparables are specified, they are used to sort all nodes and edges accordingly and create placeNodeBeforeNode, placeNodeBeforeEdge, placeEdgeBeforeNode and placeEdgeBeforeEdge constraints that are handles just like manually added constraints.

Type Parameters

TNode

TEdge

TItem

Examples

One way to set sequence constraints is by mapping nodes or edges to an IComparable (e.g. a number) which define the order in which those nodes are placed within the same layer. This can be done with the itemComparables property. One way to map each item to such an IComparable is to use the mapperFunction:

Using a delegate to map items to objects that can be ordered to define relative placements within a layer
// Map each item to an IComparable, in this case taken from a custom object stored in the tag
layoutData.sequenceConstraints.itemComparables = (item) => {
  const data = item.tag
  if (data !== null) {
    return data.sequenceOrder
  }
  // Don't constrain sequencing if the tag doesn't contain our custom object.
  return null
}

If only some nodes should be constrained, the mapper can be used instead:

Using a mapper to map certain items to objects that can be ordered to define relative placements within a layer
// Define sequence constraints for a few nodes via a mapper. Nodes that are not
// explicitly mapped don't have constraints on their placement within the layer.
const mapper = layoutData.sequenceConstraints.itemComparables
  .mapper as IMapper<INode, any>
// Place node1 before node2
mapper.set(node1, 1)
mapper.set(node2, 3)
// Place node3 between both of them
mapper.set(node3, 2)
// Place node4 after the others by assigning a larger value
mapper.set(node4, 8)
// The exact values don't matter much they just define an ordering. However, all
// values must have the same type you cannot mix int and string or double, for example.

If those mappings have been prepared beforehand, e.g. in a HashMap<TKey, TValue> or IMapper<K, V>, that property on the ItemMapping<TItem, TValue> can also be set:

Setting a prepared mapper or Map for relative placement within a layer
layoutData.sequenceConstraints.itemComparables = sequenceMapper
// Or create the mapping from a Map, instead:
layoutData.sequenceConstraints.itemComparables = sequenceMap

IComparable is only the most natural option if such an object can be readily produced from a node, or there already exists such a mapping from nodes to something that can be compared. In many cases it can be easier to construct constraints manually with the respective methods on SequenceConstraintData<TNode, TEdge, TItem>:

Defining custom sequence constraints
// Ensure that node1 is placed before node2
layoutData.sequenceConstraints.placeNodeBeforeNode(node1, node2)
// Also place another node at the very start
layoutData.sequenceConstraints.placeNodeAtHead(firstNodeInLayer)

See Also

Developer's Guide

Members

No filters for this type

Constructors

Properties

Gets or sets the mapping from nodes or edges to an IComparable (for example a number or string) defining their sequence sort order.
Items with a lower sort order are constrained to be placed before items with a higher sort order. For items mapped to null, no constraints are added.
conversionfinal

Examples

Using the node's labels to indicate their order
layoutData.layerConstraints.nodeComparables = (node: INode): any =>
  node.labels.size > 0 ? node.labels.get(0).text : null

Sample Graphs

ShownSetting: Base graph laid out with default settings. Labels indicate the desired relative node order within the middle layer.

Methods

Clears all previously defined constraints.

All constraints that were previously defined via the various methods to place nodes and edges before or after other nodes and edges or to place nodes and edges either at the start or at the end of a sequence were cleared so that new constraints can be declared.

This doesn't affect indirect constraints specified by the itemComparables.

final

Examples

Clearing all previously set sequence constraints
layoutData.sequenceConstraints.clearConstraints()
Adds a constraint that places a TEdge at the start of the sequence.
For edges, this constraint applies to each layer that the edge spans including the edge's source and target. Edges with recursiveEdgePolicy are ignored.
If there are groups or swimlanes, there are implicit constraints on the edges, e.g., the edge path never leaves the bounds of the group that is the common ancestor of the edge's endpoints. Furthermore, if both endpoints of an edge are associated with the same swimlane, the route does never leave this lane. Such constraints cannot be affected by sequence constraints.
final

Parameters

edge: TEdge
the edge that should be placed at the start

Examples

Placing a node at the start of the layer
layoutData.sequenceConstraints.placeEdgeAtHead(edge)

Sample Graphs

ShownSetting: A graph laid out with HierarchicalLayout with default settings. The labeled node should be placed at the start of the layer.
Adds a constraint that places a TEdge at the end of the sequence.
For edges, this constraint applies to each layer that the edge spans including the edge's source and target. Edges with recursiveEdgePolicy are ignored.
If there are groups or swimlanes, there are implicit constraints on the edges, e.g., the edge path never leaves the bounds of the group that is the common ancestor of the edge's endpoints. Furthermore, if both endpoints of an edge are associated with the same swimlane, the route does never leave this lane. Such constraints cannot be affected by sequence constraints.
final

Parameters

edge: TEdge
the edge that should be placed at the end

Examples

Placing a node at the end of a layer
layoutData.sequenceConstraints.placeEdgeAtTail(edge)

Sample Graphs

ShownSetting: A graph laid out with HierarchicalLayout with default settings. The labeled node should be placed at the end of the layer.
Adds a constraint that forces the afterEdge of type TEdge to lie after the beforeEdge of type TEdge.
A constraint is only considered if both elements share at least one layer. An edge is associated with each layer that it spans, i.e., each layer between its source and target (excluding the source and target layer).
An edge constraint is associated with each layer that the edge spans including the edge's source and target (e.g., an after constraint between two edges also implies that the source/target of the after edge should be placed after that of the before edge, if possible). Constraints of edges with recursiveEdgePolicy are ignored.
If there are groups or swimlanes, there are implicit constraints on the edges, e.g., the edge path never leaves the bounds of the group that is the common ancestor of the edge's endpoints. Furthermore, if both endpoints of an edge are associated with the same swimlane, the route does never leave this lane. Such constraints cannot be affected by sequence constraints.
final

Parameters

beforeEdge: TEdge
the first edge
afterEdge: TEdge
the edge that should be placed after the first edge

Examples

Placing an edge after another edge
layoutData.sequenceConstraints.placeEdgeBeforeEdge(
  beforeEdge,
  afterEdge,
)

Sample Graphs

ShownSetting: A graph laid out with HierarchicalLayout with default settings. The node labeled "After" should be placed after the node labeled "Before".
Adds a constraint that forces the afterNode of type TNode to lie after the beforeEdge of type TEdge.
A constraint is only considered if both elements share at least one layer. An edge is associated with each layer that it spans, i.e., each layer between its source and target (excluding the source and target layer).
An edge constraint is associated with each layer that the edge spans including the edge's source and target (e.g., an after constraint between two edges also implies that the source/target of the after edge should be placed after that of the before edge, if possible). Constraints of edges with recursiveEdgePolicy are ignored.
If there are groups or swimlanes, there are implicit constraints on the edges, e.g., the edge path never leaves the bounds of the group that is the common ancestor of the edge's endpoints. Furthermore, if both endpoints of an edge are associated with the same swimlane, the route does never leave this lane. Such constraints cannot be affected by sequence constraints.
final

Parameters

beforeEdge: TEdge
the edge
afterNode: TNode
the node that should be placed after the edge

Examples

Placing a node after an edge
layoutData.sequenceConstraints.placeEdgeBeforeNode(
  beforeEdge,
  afterNode,
)

Sample Graphs

ShownSetting: A graph laid out with HierarchicalLayout with default settings. The node labeled "After" should be placed after the node labeled "Before".
Adds a constraint that places a TNode at the start of the sequence.
If there are groups or swimlanes, there are implicit constraints on the nodes, e.g., a node in the last swimlane/column cannot be at the head (if there are multiple swimlanes/columns). Such constraints cannot be affected by sequence constraints.
final

Parameters

node: TNode
the node that should be placed at the start

Examples

Placing a node at the start of the layer
layoutData.sequenceConstraints.placeNodeAtHead(node)

Sample Graphs

ShownSetting: A graph laid out with HierarchicalLayout with default settings. The labeled node should be placed at the start of the layer.

See Also

Developer's Guide
Adds a constraint that places a TNode at the end of the sequence.
If there are groups or swimlanes, there are implicit constraints on the nodes, e.g., a node in the first swimlane/column cannot be at the tail (if there are multiple swimlanes/columns). Such constraints cannot be affected by sequence constraints.
final

Parameters

node: TNode
the node that should be placed at the end

Examples

Placing a node at the end of a layer
layoutData.sequenceConstraints.placeNodeAtTail(node)

Sample Graphs

ShownSetting: A graph laid out with HierarchicalLayout with default settings. The labeled node should be placed at the end of the layer.

See Also

Developer's Guide
Adds a constraint that forces the afterEdge of type TEdge to lie after the beforeNode of type TNode.
A constraint is only considered if both elements share at least one layer. An edge is associated with each layer that it spans, i.e., each layer between its source and target (excluding the source and target layer).
An edge constraint is associated with each layer that the edge spans including the edge's source and target (e.g., an after constraint between two edges also implies that the source/target of the after edge should be placed after that of the before edge, if possible). Constraints of edges with recursiveEdgePolicy are ignored.
If there are groups or swimlanes, there are implicit constraints on the edges, e.g., the edge path never leaves the bounds of the group that is the common ancestor of the edge's endpoints. Furthermore, if both endpoints of an edge are associated with the same swimlane, the route does never leave this lane. Such constraints cannot be affected by sequence constraints.
final

Parameters

beforeNode: TNode
the node
afterEdge: TEdge
the edge that should be placed after the node

Examples

Placing an edge after a node
layoutData.sequenceConstraints.placeNodeBeforeEdge(
  beforeNode,
  afterEdge,
)

Sample Graphs

ShownSetting: A graph laid out with HierarchicalLayout with default settings. The node labeled "After" should be placed after the node labeled "Before".
Adds a constraint that forces the afterNode of type TNode to lie after the beforeNode of type TNode.
A constraint is only considered if both elements share at least one layer.
If there are groups or swimlanes, there are implicit constraints on the nodes. Such constraints cannot be affected by sequence constraints.
final

Parameters

beforeNode: TNode
the first node
afterNode: TNode
the node that should be placed after the first node

Examples

Placing a node after another node
layoutData.sequenceConstraints.placeNodeBeforeNode(
  beforeNode,
  afterNode,
)

Sample Graphs

ShownSetting: A graph laid out with HierarchicalLayout with default settings. The node labeled "After" should be placed after the node labeled "Before".

See Also

Developer's Guide