C

LayoutStageStack

Manages a collection of layout stages that can be executed in a stack-wise manner.
Inheritance Hierarchy

Remarks

The LayoutStageStack class manages a list of layout stages, enabling the composition of complex layout processes by stacking multiple stages together. The stages are executed in the order they are stacked. Each stage can do work before applying its core and after applying it, i.e., the invocation of coreLayout. Thus, the stack forms a complex nesting of stages into each other, so that a stage becomes the core of the previous stage and so on.

It provides various methods to add, remove, and retrieve stages, such as append and prepend, which add stages to the end or beginning of the stack, respectively. The stack can be directly accessed via the stack property for more advanced manipulations, like reordering or clearing all stages.

Additionally, you can add preprocessing and post-processing steps to the stack using addPreprocessor and addPostprocessor, allowing you to inject custom logic before or after all other stages are applied.

See Also

Developer's Guide

API

linkCoreLayouts

Members

Show:

Constructors

Properties

All properties are filtered. Go to Filters.

Methods

Adds a layout algorithm as a post-processing stage to the stack.
Wraps the specified algorithm in a layout stage and adds it to the stack. The algorithm is executed after any other stages in the stack.
final

Parameters

algorithm: ILayoutAlgorithm
The ILayoutAlgorithm to be used as the post-processing stage.

Return Value

ILayoutStage
The ILayoutStage that was created and added.

Examples

The following example shows the effect of adding a stage this way. Note that the custom layout can be an ILayoutAlgorithm or an ILayoutStage.
Adding a stage as postprocessor
  // Assume the following existing stack with three stages (they all are doing stuff before and after invoking their core)
  const stages = new LayoutStageStack()
  stages.append(new SubgraphLayoutStage({ enabled: true }))
  stages.append(new ComponentLayout({ enabled: true }))
  stages.append(new OrientationStage({ enabled: true }))

  stages.addPostprocessor(new MyStage())

  /*
 Resulting order: added MyStage will run after everything else
 - SubgraphLayoutStage [before core]
 - ComponentLayout [before core]
 - OrientationStage [before core]
 - Core of Main Algorithm
 - OrientationStage [after core]
 - ComponentLayout [after core]
 - SubgraphLayoutStage [after core]
 - MyStage
*/

See Also

Developer's Guide
Adds a layout algorithm as a pre-processing stage to the stack.
Wraps the specified algorithm in a layout stage and adds it to the stack. The algorithm is executed before any other stages in the stack.
final

Parameters

algorithm: ILayoutAlgorithm
The ILayoutAlgorithm to be used as the pre-processing stage.

Return Value

ILayoutStage
The ILayoutStage that was created and added.

Examples

The following example shows the effect of adding a stage this way. Note that the custom layout can be an ILayoutAlgorithm or an ILayoutStage.
Adding a stage as preprocessor
  // Assume the following existing stack with three stages (they all are doing stuff before and after invoking their core)
  const stages = new LayoutStageStack()
  stages.append(new SubgraphLayoutStage({ enabled: true }))
  stages.append(new ComponentLayout({ enabled: true }))
  stages.append(new OrientationStage({ enabled: true }))

  stages.addPreprocessor(new MyStage())

  /*
 Resulting order: added MyStage will run before everything else
 - MyStage
 - SubgraphLayoutStage [before core]
 - ComponentLayout [before core]
 - OrientationStage [before core]
 - Core of Main Algorithm
 - OrientationStage [after core]
 - ComponentLayout [after core]
 - SubgraphLayoutStage [after core]
*/

See Also

Developer's Guide
Appends a new stage to the end of the stack.
final

Parameters

stage: ILayoutStage
The layout stage to append to the stack.

Return Value

ILayoutStage
The appended ILayoutStage instance.

Throws

Exception ({ name: 'ArgumentError' })
Thrown if the stage instance is already present in the stack.

Examples

The following example shows the effect of appending a stage.
Appending a stage.
 // Assume the following existing stack with three stages (they all are doing stuff before and after invoking their core)
 const stages = new LayoutStageStack()
 stages.append(new SubgraphLayoutStage({ enabled: true }))
 stages.append(new ComponentLayout({ enabled: true }))
 stages.append(new OrientationStage({ enabled: true }))

 stages.append(new MyStage())

 /*
 Resulting order: appended MyStage, it is doing stuff directly before and after the main core
 - SubgraphLayoutStage [before core]
 - ComponentLayout [before core]
 - OrientationStage [before core]
 - MyStage [before core]
 - Core of Main Algorithm
 - MyStage [after core]
 - OrientationStage [after core]
 - ComponentLayout [after core]
 - SubgraphLayoutStage [after core]
*/

See Also

Developer's Guide
Appends a core layout algorithm to the stack.
final

Parameters

algorithm: ILayoutAlgorithm
The core layout algorithm to append.

Return Value

ILayoutStage
The created ILayoutStage instance wrapping the core layout.
Disables all stages in the stack by setting their enabled property to false.
final
Retrieves the first instance of a layout stage of the specified type from the stack.
final

Parameters

stageType: Constructor<T>
The type of the layout stage to retrieve.

Return Value

T
The first matching stage of the specified type, or null if none is found.

See Also

Developer's Guide
Prepends a new stage to the beginning of the stack.
final

Parameters

stage: ILayoutStage
The layout stage to prepend to the stack.

Return Value

ILayoutStage
The prepended ILayoutStage instance.

Throws

Exception ({ name: 'ArgumentError' })
Thrown if the stage instance is already present in the stack.

Examples

The following example shows the effect of prepending a stage.
Prepending a stage.
  // Assume the following existing stack with three stages (they all are doing stuff before and after invoking their core)
  const stages = new LayoutStageStack()
  stages.append(new SubgraphLayoutStage({ enabled: true }))
  stages.append(new ComponentLayout({ enabled: true }))
  stages.append(new OrientationStage({ enabled: true }))

  stages.prepend(new MyStage())

  /*
 Resulting order: prepended MyStage, it is the first and last to do stuff
 - MyStage [before core]
 - SubgraphLayoutStage [before core]
 - ComponentLayout [before core]
 - OrientationStage [before core]
 - Core of Main Algorithm
 - OrientationStage [after core]
 - ComponentLayout [after core]
 - SubgraphLayoutStage [after core]
 - MyStage [after core]
*/

See Also

Developer's Guide
Removes a specific stage from the stack.
final

Parameters

stage: ILayoutStage
The layout stage to remove.
Replaces an existing layout stage of a specified type on the stack with a new stage.
final

Parameters

stageType: Constructor<T>
The type of the layout stage to replace.
stage: T
The layout stage that should replace the current stage on the stack

Return Value

ILayoutStage
The added layout stage instance.

Throws

Exception ({ name: 'ArgumentError' })
Thrown if no stage of the specified type is on the stack or if the given instance is already on the stack.

Static Methods

Chains a collection of ILayoutStage instances together and configures them into a stack.
Only enabled stages are included in the chain. The coreLayout is added as the final element in the stack. The method returns the top-most stage, which represents the entry point for the applyLayout call.
static

Parameters

stages: IEnumerable<ILayoutStage>
The collection of stages to chain together.
coreLayout?: function(LayoutGraph): void
An optional callback to be used as the final core layout stage in the stack.

Return Value

ILayoutAlgorithm
A layout algorithm to apply the entire stack.