C

LayoutAbortController

Controls the early termination of graph algorithms.
Inheritance Hierarchy

Remarks

The LayoutAbortController class allows graph algorithms to be interrupted or terminated before they complete. It supports both graceful terminations (via the stop method) and immediate cancellations (via the cancel method).

This class is particularly useful when algorithms are long-running and need to be interrupted due to time constraints or user interactions. It can be used in both multithreaded and single-threaded scenarios.

Usage in Client Code

When working with IGraph and related APIs, the LayoutAbortController of the LayoutExecutor provides an instance of this class that can be configured and monitored by layout algorithms.

If working directly with the LayoutGraph API, an instance of this class should be attached via the layoutAbortController property. This ensures that layout algorithms executed on the graph will respect stop or cancel requests.

  • stop – Schedules a request for graceful termination. This allows the algorithm to finish its current step and leave the graph in a consistent state.
  • cancel – Requests an immediate termination, discarding any partial results. There is no guarantee that the graph or the layout algorithm will be left in a consistent state, and any in-progress work will be discarded.

In scenarios where an algorithm runs multiple times on the same graph or where different algorithms are applied sequentially, the controller must be reset using the reset method before each execution. Failure to reset the controller can result in unintended early terminations due to lingering stop or cancel requests.

stop and cancel are designed for multithreaded scenarios where the algorithm runs in a background thread while the stop or cancel requests are issued from the main thread. In single-threaded environments, you can use stopDuration and cancelDuration to automatically terminate an algorithm after a specified duration.

Algorithm Development

When developing custom algorithms, you should query the controller for termination requests by invoking the check method at appropriate points within the algorithm. This ensures that stop and cancel requests are respected, allowing for smooth integration with the LayoutAbortController.

If a stop request is detected, ensure the algorithm completes its work in a way that keeps the graph in a consistent state. If a cancel request is detected, terminate immediately and discard any intermediate results.

Default Values of Properties

NameDefaultDescription
cancelDurationTimeSpan.MAX_VALUE
No automatic termination will occur.
stopDurationTimeSpan.MAX_VALUE
No automatic termination will occur.

See Also

Developer's Guide

Members

No filters for this type

Constructors

Initializes a new instance of the LayoutAbortController class.

Properties

Gets or sets the maximum duration an algorithm may run before being canceled automatically.
An algorithm is terminated immediately, if the time in between creating or resetting this controller and calling check exceeds the cancel duration.
Automatic termination will only occur for positive values.
conversionfinal

Property Value

the duration before canceling

Throws

Exception ({ name: 'ArgumentError' })
Thrown if the duration is negative.

Default Value

The default value is: TimeSpan.MAX_VALUE
No automatic termination will occur.

See Also

Developer's Guide
API
reset, cancel
Gets a value indicating whether a cancel request has been scheduled.
readonlyfinal
Gets or sets the maximum duration an algorithm may run before being stopped automatically.
An algorithm is terminated gracefully if the time in between creating or resetting this controller and calling check exceeds the stop duration.
conversionfinal

Property Value

the duration before stopping automatically

Throws

Exception ({ name: 'ArgumentError' })
Thrown when the duration is negative.

Default Value

The default value is: TimeSpan.MAX_VALUE
No automatic termination will occur.

See Also

Developer's Guide
API
timeToStop, reset, stop
Gets a value indicating whether a stop request has been scheduled.
readonlyfinal

Methods

Schedules a cancellation request.

Calling the check method after a cancellation request has been scheduled will result in an AlgorithmAbortedError being thrown. This immediately halts the execution of the current layout algorithm. Since the algorithm is terminated prematurely, the state of the processed graph cannot be guaranteed to be valid or consistent.

It is recommended to schedule cancellation requests only for algorithms that work on a copy of the graph, rather than the original graph structure. This prevents the risk of leaving the graph in an inconsistent or partially updated state.

The state of the associated ILayoutAlgorithm instance may become corrupted as a result of the cancellation. Therefore, it is advisable to instantiate a new layout algorithm after each cancellation to ensure subsequent executions work correctly.
final

Examples

The following example demonstrates how to create a copy of a graph and apply a layout algorithm with layout data:
Create a graph copy and apply a layout algorithm
const copiedGraph = LayoutGraph.createCopy(graph)
copiedGraph.applyLayout(layout, layoutData)
copiedGraph.context.graphCopyData?.commitLayoutToOriginalGraph()

See Also

API
check, stop
Checks if the algorithm should terminate.
This method should be called by algorithms to check whether a stop or cancel request has been made. If a stop request is detected, the algorithm should complete its work gracefully. If a cancel request is detected, an AlgorithmAbortedError will be thrown, terminating the algorithm immediately.
final

Return Value

boolean
true if the algorithm should stop gracefully, false otherwise.

Throws

Exception ({ name: 'AlgorithmAbortedError' })
Thrown if the algorithm should terminate immediately due to a cancellation.

See Also

Developer's Guide
API
cancel, stop
Resets the state of the LayoutAbortController.
This method clears any existing stop or cancel requests and resets the internal timer used to track automatic stop or cancel durations. It should be called before reusing the controller for a new algorithm run.
final

See Also

API
cancelDuration, stopDuration
Schedules a graceful termination request.

When a stop request is scheduled, the algorithm will attempt to finish its current operation and ensure that the processed graph is left in a consistent state.

If a cancel request has already been made, the stop request is ignored. If a cancel request is made later, it will override the stop request.

final

See Also

API
check, cancel
Determines the remaining time until the algorithm is automatically canceled.
final

Return Value

TimeSpan
The remaining time until the algorithm is canceled, or MAX_VALUE if no automatic cancellation is scheduled.

See Also

API
cancelDuration, reset, cancel
Determines the remaining time until the algorithm is automatically stopped.
final

Return Value

TimeSpan
The remaining time until the algorithm is stopped, or MAX_VALUE if no automatic stop is scheduled.

See Also

API
stopDuration, reset, stop