Skip to content

cy.nodeAt(x, y)

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

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

Preview · Core › Viewport manipulation › Picking and visible counts

Read in the complete API reference · All API members

// Find the topmost node at a rendered position, measured in CSS pixels from the container's top-left corner
cy.nodeAt(x: number, y: number): Collection<NodeData, EdgeData, NodeData> | null

Find the topmost node at a rendered position, measured in CSS pixels from the container's top-left corner. Returns null when no node is hit. Use pick() to test both nodes and edges asynchronously.

Node visibility and level of detail affect the result. In a headless core, the calculation uses the viewport and default rendering thresholds at a device-pixel ratio of 1.

Parameters
NameDescription
x: number

rendered (CSS px) x, relative to the container

y: number

rendered (CSS px) y

Returns Collection<NodeData, EdgeData, NodeData> | null

the node under the point, or null (background, an edge only, or a destroyed instance)

Example

cy.zoom(1); cy.pan({ x: 0, y: 0 });
console.log(cy.nodeAt(0, 0)?.id()); // 'a'

Example graph and handle setup

Also spelled cy.pickNode.

See

Core#pick for edges and the full draw-order answer