Skip to content

cy.viewport(opts)

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

cy.viewport — 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

// Set zoom and/or pan together, emitting once
cy.viewport(opts: { zoom?: number; pan?: Position }): this

Set zoom and/or pan together, emitting once.

Parameters
NameDescription
opts: { zoom?: number; pan?: Position }

the zoom and/or pan to apply; omitted keys are left as they are

Fields of opts
NameDescription
zoom: number?
pan: Position?
Returns this

this core, for chaining

Example

cy.viewport({ zoom: 2, pan: { x: 40, y: 20 } });
console.log(cy.zoom()); // 2

Example graph and handle setup