Skip to content

cy.fit(eles?, padding?)

cy.fit — Core > Viewport manipulation > Pan, zoom, fit and bounds. Cytoscape.js signatures, parameters and return contract.

cy.fit — Core › Viewport manipulation › Pan, zoom, fit and bounds

Preview · Core › Viewport manipulation › Pan, zoom, fit and bounds

Read in the complete API reference · All API members

// Pan and zoom so the given elements fill the viewport
cy.fit(eles?: Collection, padding?: number): this

Pan and zoom so the given elements fill the viewport.

Bounds include labels by default, so a fit never clips the text it was asked to show; edge-label terms are conservative, so a fit may slightly over-fit but never under-fits.

Parameters
NameDescription
eles: Collection?

the elements to fit; omit for the whole graph

padding: number?Default: 0

rendered-space padding around the box

Returns this

this core, for chaining

Example

cy.fit(cy.nodes(), 20);
console.log(cy.zoom() > 0); // true

Example graph and handle setup