Skip to content

Collection

Collections are ordered sets of handles tied to one core; scalar reads and bulk writes have distinct contracts.

The public collection abstraction represents an ordered set of handles tied to one core. cy.elements() returns all live elements with nodes first and edges second; cy.nodes() and cy.edges() narrow the result. An element lookup returns a collection of length zero or one, so the same methods work for a missing id, one element or a larger traversal result. Empty collections are valid values.

Collection APIs make the unit of work explicit. Methods such as forEach() visit length-one element collections. map() returns a plain array in collection order. first(), last() and eq(i) return collections, not unwrapped element objects. Scalar queries such as id(), position() and data() read from the first element; they answer undefined when there is no first element. Bulk mutators apply to every element and typically return the same collection for chaining.

const a = cy.getElementById('a');
const adjacentNodes = a.neighborhood().nodes();
const ids = adjacentNodes.map(node => node.id());
const totalWeight = cy.edges().reduce(
(sum, edge) => sum + edge.data('weight'),
0,
);

#Function categories

  • Metadata and identity — Inspect identity and collection membership.
  • Iteration and aggregation — Visit, map, reduce and aggregate elements in collection order.
  • Comparison — Compare collections without mutating the graph.
  • Building and filtering — Build ordered sets and filter with queries or predicates.
  • Data and scratch — Read and update application data or transient scratch on elements.
  • Graph manipulation — Remove elements or change topology while respecting terminal removed handles.
  • Position and dimensions — Read geometry and write node positions in the documented coordinate space.
  • Edge points — Read rendered or model-space endpoints and route geometry.
  • Selection — Inspect and change element selection and selectability.
  • Grab, lock and pannability — Inspect active state and control which elements can move through gestures.
  • Visibility and emphasis — Inspect visibility and core-owned emphasis state.
  • Style — Read resolved styling and manage supported bypasses.
  • Events — Bind event handlers to each element in a collection.
  • Animation — Animate model position and supported style channels, with promise-based sequencing.
  • Layout — Scope a layout to a collection and use shared placement helpers.
  • Traversing — Follow incidence, directed reachability, edge relations and connectivity.
  • Compound nodes — Traverse compound containment and manage collapse state.
  • Algorithms — Choose graph algorithms by task; read each executor and cancellation contract.
Links from earlier versions of this guide

Metadata and identity

eles.length()

eles.cy()

eles.collection()

eles.hasElementWithId()

eles.indexOf()

eles.indexOfId()

eles.id()

eles.group()

eles.json()

eles.jsons()

eles.isNode()

eles.isEdge()

eles.isLoop()

eles.isSimple()

eles.removed()

eles.inside()

Iteration and aggregation

eles.size()

eles.empty()

eles.nonempty()

eles.forEach()

eles.toArray()

eles.slice()

eles.sort()

eles.eq()

eles.first()

eles.last()

eles.map()

eles.some()

eles.every()

eles.reduce()

eles.max()

eles.min()

Comparison

eles.same()

eles.anySame()

eles.contains()

eles.allAreNeighbors()

eles.allAre()

eles.is()

Building and filtering

eles.union()

eles.difference()

eles.intersection()

eles.symmetricDifference()

eles.filter()

eles.nodes()

eles.edges()

eles.getElementById()

eles.absoluteComplement()

eles.diff()

Data and scratch

eles.data()

eles.removeData()

eles.scratch()

eles.removeScratch()

Graph manipulation

eles.remove()

eles.move()

Position and dimensions

eles.position()

eles.positions()

eles.shift()

eles.relativePosition()

eles.renderedPosition()

eles.width()

eles.height()

eles.padding()

eles.paddedWidth()

eles.paddedHeight()

eles.outerWidth()

eles.outerHeight()

eles.boundingBox()

eles.labelBoundingBox()

eles.renderedBoundingBox()

eles.renderedWidth()

eles.renderedHeight()

eles.renderedOuterWidth()

eles.renderedOuterHeight()

Edge points

eles.midpoint()

eles.renderedMidpoint()

eles.sourceEndpoint()

eles.targetEndpoint()

eles.renderedSourceEndpoint()

eles.renderedTargetEndpoint()

eles.controlPoints()

eles.renderedControlPoints()

eles.segmentPoints()

eles.renderedSegmentPoints()

Selection

eles.selected()

eles.selectable()

eles.select()

eles.unselect()

eles.selectify()

eles.unselectify()

Grab, lock and pannability

eles.grabbable()

eles.grabbed()

eles.grabify()

eles.ungrabify()

eles.locked()

eles.lock()

eles.unlock()

eles.active()

eles.pannable()

eles.panify()

eles.unpanify()

Visibility and emphasis

eles.visible()

eles.hidden()

eles.show()

eles.hide()

eles.emphasized()

Style

eles.style()

eles.removeStyle()

eles.renderedStyle()

eles.numericStyle()

eles.effectiveOpacity()

eles.transparent()

eles.takesUpSpace()

eles.interactive()

eles.label()

Events

eles.on()

eles.one()

eles.off()

eles.emit()

eles.promiseOn()

Animation

eles.animate()

eles.animation()

eles.delay()

eles.delayAnimation()

eles.animated()

eles.stop()

Layout

eles.layoutDimensions()

eles.layoutPositions()

eles.layout()

Traversing

Incidence and neighbourhood

eles.source()

eles.target()

eles.sources()

eles.targets()

eles.connectedEdges()

eles.connectedNodes()

eles.outgoers()

eles.incomers()

eles.neighborhood()

eles.closedNeighborhood()

Directed reachability

eles.roots()

eles.leaves()

eles.successors()

eles.predecessors()

Edge relations

eles.edgesWith()

eles.edgesTo()

eles.parallelEdges()

eles.codirectedEdges()

Connected components

eles.components()

eles.component()

Compound nodes

eles.parent()

eles.parents()

eles.children()

eles.descendants()

eles.collapse()

eles.expand()

eles.siblings()

eles.orphans()

eles.nonorphans()

eles.commonAncestors()

eles.isParent()

eles.isChildless()

eles.isChild()

eles.collapsed()

eles.insideCollapsed()

eles.isOrphan()

Algorithms

eles.breadthFirstSearch()

eles.depthFirstSearch()

eles.dijkstra()

eles.aStar()

eles.bellmanFord()

eles.floydWarshall()

Spanning

eles.kruskal()

Connectivity and Eulerian paths

eles.tarjanStronglyConnected()

eles.hopcroftTarjanBiconnected()

eles.hierholzer()

Cut

eles.kargerStein()

Centrality

eles.pageRank()

eles.degreeCentrality()

eles.degreeCentralityNormalized()

eles.closenessCentrality()

eles.closenessCentralityNormalized()

eles.betweennessCentrality()

eles.katzCentrality()

Similarity, diffusion and resistance

eles.neighborhoodSimilarity()

eles.simRank()

eles.randomWalkWithRestart()

eles.randomWalkWithRestartProximity()

eles.heatDiffusion()

eles.heatKernel()

eles.effectiveResistance()

Structural measures

eles.triangleCount()

eles.motifCensus()

eles.degree()

eles.outdegree()

eles.indegree()

eles.minDegree()

eles.maxDegree()

eles.minIndegree()

eles.maxIndegree()

eles.minOutdegree()

eles.maxOutdegree()

eles.totalDegree()

Clustering

eles.kMeans()

eles.kMedoids()

eles.fuzzyCMeans()

eles.hierarchicalClustering()

eles.markovClustering()

eles.affinityPropagation()

All guides · Alphabetical API index · Read continuously