Skip to content

cy.viewportCounts()

cy.viewportCounts — Core > Viewport manipulation > Picking and visible counts. Cytoscape.js signatures, parameters and return contract.

cy.viewportCounts — Core › Viewport manipulation › Picking and visible counts

Preview · Core › Viewport manipulation › Picking and visible counts

Read in the complete API reference · All API members

// Count visible nodes and edges at each level of detail in the current viewport
cy.viewportCounts(): Promise<ViewportCounts | null>

Count visible nodes and edges at each level of detail in the current viewport. Resolves after the renderer computes the counts for a frame. Resolves null when headless, destroyed, or when the device is lost before that frame completes.

For synchronous geometric containment, use elementsInBox() with the bounds returned by extent(). That query includes elements regardless of whether they are large enough to draw.

Returns Promise<ViewportCounts | null>

{ nodes, edges } for the next frame drawn, or null

Example

// A headless core has no rendered frame to count.
console.log(await cy.viewportCounts()); // null

Example graph and handle setup