Skip to content

cy.compact()

cy.compact — Core > Graph manipulation > Batching and compaction. Cytoscape.js signatures, parameters and return contract.

cy.compact — Core › Graph manipulation › Batching and compaction

Preview · Core › Graph manipulation › Batching and compaction

Read in the complete API reference · All API members

// Reclaim unused storage after removing many elements
cy.compact(): this

Reclaim unused storage after removing many elements. Existing element handles, listeners and drawing order are preserved.

Compaction normally happens automatically. Call this method to choose when its work occurs, for example after a bulk removal. It throws during a batch and defers with a warning while a GPU force layout is running.

Returns this

Example

cy.remove(cy.getElementById('c'));
cy.compact();
console.log(cy.nodes().map(node => node.id())); // ['a', 'b']

Example graph and handle setup

Also spelled cy.gc.