Skip to content

layout.cancel()

layout.cancel — Layouts > Layout handle. Cytoscape.js signatures, parameters and return contract.

layout.cancel — Layouts › Layout handle

Preview · Layouts › Layout handle

Read in the complete API reference · All API members

// Abandon the run in flight — the alternative to stop(), which keeps what stands
layout.cancel(): this

Abandon the run in flight — the alternative to stop(), which keeps what stands. The impl is asked to cancel() (or stop() when it has no cancel), and once its run settles the scope's nodes go back to where run() found them, a tween under way is dropped where it is, the viewport is left alone, layoutstop fires with cancelled: true, and promise() rejects with CancelledError. A layout that is not running is unchanged.

Returns this

this layout, for chaining

Example

const handle = cy.layout({ impl: { async run() { await Promise.resolve(); } } });
handle.run();
handle.cancel();
let cancelled = false;
try { await handle.promise(); }
catch (error) { cancelled = error instanceof cytoscape.CancelledError; }
console.log(cancelled); // true

Example graph and handle setup