Skip to content

ctx.width()

ctx.width — Extensions > Layout context > Bounds. Cytoscape.js signatures, parameters and return contract.

ctx.width — Extensions › Layout context › Bounds

Preview · Extensions › Layout context › Bounds

Read in the complete API reference · All API members

// The viewport width in CSS px — what a layout sizing itself to the screen should use
ctx.width(): number

The viewport width in CSS px — what a layout sizing itself to the screen should use. Headless instances report the configured headless width, so a layout still works without a DOM.

Returns number

the viewport width

Example

// Inside a custom layout, ctx is supplied by the library.
cy.layout({ impl: { run(ctx) {
console.log(ctx.width()); // 800
} } }).run();

Example graph and handle setup