Skip to content

cy.elementsInBox(x1, y1, x2, y2)

cy.elementsInBox — Core > Accessing elements. Cytoscape.js signatures, parameters and return contract.

cy.elementsInBox — Core › Accessing elements

Preview · Core › Accessing elements

Read in the complete API reference · All API members

// Live, visible elements contained in the model-coordinate box (corners in any order): the box-selection query, answered by one columnar scan
cy.elementsInBox(x1: number, y1: number, x2: number, y2: number): Collection<NodeData, EdgeData>

Live, visible elements contained in the model-coordinate box (corners in any order): the box-selection query, answered by one columnar scan. Nodes count when their bounding box lies fully inside; edges when both endpoint node centers do (straight-edge endpoints are taken at the node centers).

boxSelectionMode does not reach here: this stays the pure geometric containment query whatever the gesture is set to. For the overlap question, boxSelectionMode( 'overlap') and drag a box, or test intersection yourself against eles.boundingBox(). (boxSelectionIncludesLabels is the one interaction setting that does reach here: with it on, a node's label box must be contained too.)

Parameters
NameDescription
x1: number

one corner's model x

y1: number

that corner's model y

x2: number

the opposite corner's model x

y2: number

that corner's model y

Returns Collection<NodeData, EdgeData>

the contained elements

Example

console.log(cy.elementsInBox(-50, -50, 50, 50).length); // 2

Example graph and handle setup