Skip to content

API reference

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

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

Change the zoom level or zoom about a fixed position.

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

Read in the complete API reference · All API members

#cy.zoom()

// Get the zoom level
cy.zoom(): number

Read the current zoom level.

Returns number

the current zoom level as a number

Example

cy.zoom(1);
console.log(cy.zoom()); // 1

Example graph and handle setup

#cy.zoom(level)

// Set the zoom level
cy.zoom(level: number): this

Set the zoom level, clamped to zoomRange(). Does nothing when zoomingEnabled() is false. A changed viewport emits a zoom event and a viewport event.

Parameters
NameDescription
level: number

the new zoom level

Returns this

this core, for chaining

Example

const result = cy.zoom(2);
console.log(result === cy); // true

Example graph and handle setup

#cy.zoom(options)

// Zoom about a position
cy.zoom(options: ZoomOptions): this

Zoom about a fixed model or rendered position. Does nothing when zoomingEnabled() is false. A changed viewport emits a zoom event and a viewport event.

Parameters
NameDescription
options: ZoomOptions

the level and the position to keep fixed

Fields of options
NameDescription
level: number

New zoom level, clamped to the graph's zoomRange().

position: Position?

model point to keep fixed while zooming

renderedPosition: Position?

rendered (on-screen) point to keep fixed while zooming

Returns this

this core, for chaining

Example

cy.zoom({ level: 2, renderedPosition: { x: 0, y: 0 } });
console.log(cy.zoom()); // 2

Example graph and handle setup