cytoscape.js v4 HEAD · a579fafe · built 2026-10-30 19:56Z

API reference

Preview. Generated from the JSDoc on src/ by scripts/docs-generate.mjs — the same model round 46 will build the real documentation site from. This page exists so the authoring surface can be read as a consumer reads it, not as a replacement for that site.

352 documented members.

The cytoscape factory

Entry point The cytoscape factory

cytoscape

Create a GPU-prototype cytoscape instance (issue #3486, pass 1): a columnar CPU-canonical model with a WebGPU render pipeline.

With a container, WebGPU is required — this throws synchronously when navigator.gpu is unavailable. Without a container the instance is headless (Node-friendly, never throws for a missing GPU). Adapter acquisition is asynchronous and reported separately: cy.ready rejects when no adapter can be had, which this function cannot know yet.

Beyond the constructor's work, the factory ingests options.elements through the bulk path (no per-element handles, no add events — nothing can be listening yet), runs options.layout, and attaches the renderer and pointer handler when a container is given.

This is the full build (cytoscape). Two slimmer entries carry the same core without the renderer (round 131): cytoscape/headless (no renderer, no GPU executors) and cytoscape/headless-gpu (the GPU algorithm lanes and a headless GPU force host, no renderer).

Unknown options are ignored, deliberately (decided 2026-08-04, fifth design sitting): unlike an unknown sheet key, style property or query key, a misspelled option does not throw, because strictness here resolves at the type layer — TypeScript's excess-property check rejects { motionBlur: true } against CytoscapeOptions, and v4 does not replicate at runtime what the build already checks.

Typed element data (round 140): cytoscape<NodeData, EdgeData>( … ) types the instance by the application's node and edge data shapes. data() then takes only their keys and reads their field types; the collections know their group (cy.nodes() reads NodeData, connectedEdges() reads EdgeData); events, add/patch/load/ clone payloads, queries and the stylesheet's mapper fields are checked against the same shapes. Give NodeData alone to leave the edges' keys open. The generics are never inferred from options — without them every type is exactly the untyped one.

options

the instance options; every field is optional, and an omitted container is what selects headless mode

Create a headless cytoscape instance — the cytoscape/headless build (round 131): the whole graph model, style, collection API, the CPU algorithms and every layout, with the worker pool where the platform offers workers, and neither a renderer nor any WebGPU code.

The factory ingests options.elements through the bulk path and runs options.layout, exactly as the full build's does. Unknown options are ignored, as there (the type rejects them), and the generics type the element data as there (round 140).

options

the instance options, without the renderer- and pointer-only fields (HeadlessOptions)

Create a headless cytoscape instance with the GPU executors — the cytoscape/headless-gpu build (round 131): everything cytoscape/headless carries, plus the WGSL algorithm kernels and a compute-only host for an explicit executor: 'gpu' force run, and no renderer.

The factory ingests options.elements through the bulk path and runs options.layout, exactly as the full build's does. Unknown options are ignored, as there (the type rejects them), and the generics type the element data as there (round 140).

options

the instance options, without the renderer- and pointer-only fields (HeadlessOptions)

Returns

the new core, usable synchronously — reads and writes do not wait on the device, and a rendered instance additionally resolves cy.ready

Throws
  • when container is given and navigator.gpu is missing

  • when a container is given — this build has no renderer

cytoscape.toColumnarElements

Convert classic v3-style elements JSON into the columnar bulk-load form: typed-array columns with edge endpoints as node indices.

This is the compatibility path for callers holding definition-form JSON; the columnar form is what the loader ingests fastest, since contiguous slot runs become memcpys and no per-element objects or per-edge id lookups are needed. Exposed publicly as cytoscape.toColumnarElements.

The columnar form has no column for locked, grabbable or pannable, so a def setting one of those converts without it. The factory's own definition-form load does not go through this function for that reason — it uses the internal buildColumnar, which reports the deviations so it can write them after the ingest.

defs

one element, an array, or { nodes, edges }

options

{ refs }: carry endpoints and parents the payload does not hold as node references rather than throwing (round 103)

Returns

the equivalent columnar payload — self-contained, or with refs when that option is on and something was referenced

Throws

if an edge lacks a source or target; without refs, also if an edge names a source or target that is not a node in the same payload — columnar payloads are self-contained unless they carry references; and on an unknown option

cytoscape.serializeElements

Serialize elements (definition form or columnar form) into one transferable/fetchable ArrayBuffer. deserializeElements (or passing the buffer straight to options.elements/cy.add()) reverses it.

elements

the elements to serialize, in either accepted form; a definition-form payload is converted to columnar first. A columnar payload's optional graph-level data rides along (round 39.2); the definition form has nowhere to put it, so it carries none. Its node references (refs, round 103) ride too — convert definitions with toColumnarElements( defs, { refs: true } ) first to carry cut edges

Returns

one little-endian ArrayBuffer holding the whole payload — fixed header, columns, and ids as a UTF-8 blob with prefix offsets. Every section starts at an offset aligned to its element width (8 for f64 columns), and that alignment is the encoder's contract: deserializeElements returns views over the buffer rather than copies because of it (round 110's census measured the decode at zero copies), so a reader may rely on it and a future encoder must keep it

Throws

if the platform is big-endian, or if a definition-form payload names an edge endpoint that is not a node in the same payload

cytoscape.deserializeElements

Deserialize a serializeElements buffer (or a view over one) back into the columnar elements form. Numeric columns are zero-copy views into the given buffer; a misaligned view is copied once to realign.

input

a serializeElements buffer, or a view over one

Returns

the columnar form, whose numeric columns are views into the input rather than copies — so the buffer must outlive the result, and writing into either is visible through the other. Graph-level data is the exception in two ways: it is decoded from JSON rather than viewed, and cy.add() deliberately ignores it (see ColumnarElements.data)

Throws

if the platform is big-endian, or the buffer is too short, truncated or of an unsupported format version

cytoscape.CancelledError

Thrown (as a rejection) by a cancelled run: an async algorithm whose handle's cancel() was called, a layout's promise() after layout.cancel(), or either when cy.destroy() ran while the run was in flight. error.name is 'CancelledError', so a .catch can tell a cancellation from a defect without importing the class.

cytoscape.GpuUnfitError

Thrown when something does not fit the GPU device's limits. Two places throw it:

  • cy.add(), cy.load() and cy.patch() (round 138), with a renderer mounted, when the elements would grow a table past what the device can bind (its storage binding or buffer limit over the widest per-element column) or dispatch over — thrown before anything is added, so the graph is unchanged. cy.ready rejects with it when a graph built headless is mounted on a device too small for it. - a GPU algorithm whose input does not fit (a dense matrix past the storage-binding limit, say): under executor: 'auto' the run falls back to the CPU reference, under an explicit 'gpu' the promise rejects with it — unlike every other kernel error, which always propagates.

A factory static (cytoscape.GpuUnfitError) so a catch can test instanceof; error.name is 'GpuUnfitError' for a check without the class. Defined here, not beside the kernels, so the router's instanceof needs no kernel module; algo-gpu.mts re-exports it.

Core

Lifecycle Core

cy.ready

Resolves once the render pipeline is usable (immediately when headless) — and, under an initial cy.load(), once its first chunk is drawn (round 103; headless, once it is in the model). Rejects when no adapter can be had.

Style Core

cy.style

Get the style engine, or set the stylesheet and return it.

v4's sheet is a plain { nodes, edges, parents, core } object of prop objects — there are no selector blocks and no style functions. All per-element variation is declarative: mapper objects ({ data, scale, … }) and case conditionals, which is what keeps every value analyzable, serializable and GPU-evaluable.

Inside a batch the sheet is compiled and validated immediately (so errors still throw at the call site) but applied once at the outermost endBatch().

sheet

the stylesheet to install; omit to read the engine

Returns

the style engine (also reachable as the return value when setting, so calls chain)

Throws

if the sheet references an unknown property or an invalid value

cy.legend

Read the application's shared mapping and chart metadata. The returned JSON object is detached; changing it never alters this instance. Automatic domains expose their authored auto stops in the stylesheet and their current numeric stops here. legendchange fires after a committed snapshot changes, before batchend for a batch.

Returns

detached legend entries in stylesheet definition/property order

Batching Core

cy.compact

Slot-moving compaction, explicit form (round 19.5): move live elements down to a dense slot prefix so highWater, column capacity and pass-iteration widths shrink to the current graph instead of its peak. A monotone remap keeps draw order — compaction is a visual no-op — and held refs/handles/listeners repair through forwarding (19.3). The automatic dead-slot-ratio trigger covers the common shrink/churn profiles; this call is for deterministic timing (e.g. right after a bulk filter, before an animation). Throws mid-batch; defers with a warning while a GPU force layout runs.

Also spelled cy.gc.

cy.startBatch

Open a batch: defer style application until the matching endBatch(). Pairs nest — only the outermost endBatch() flushes. Prefer batch( fn ), which cannot leak a depth on an exception.

The outermost open is a transaction and fires batchstart on the core (round 139) — before any of the batch's mutations, with batching() already true, so a listener sees the state the transaction starts from (the place to take an undo snapshot) and anything it mutates belongs to the transaction. A nested open fires nothing.

Returns

this core, for chaining

cy.endBatch

Close a batch. At the outermost close the deferred work flushes as one bulk pass — filtered to elements still live, so adding and removing within the same batch costs nothing — and the automatic slot-compaction trigger gets its boundary check. A sheet change during the batch applies once, as a diff against the sheet the columns were derived under (round 133); it writes the batch's additions in full, and the deferred data refreshes run after it unless the diff fell back to the whole-sheet pass, which subsumes them.

The outermost close then fires batchend (round 139), the transaction's last event: after every element event of the batch, after the flush (style reads are fresh, batching() is false) and after a patch summary the batch produced. It carries no diff — the element events between the pair are the transaction's content. A nested close, or an unbalanced one, fires nothing.

Unbalanced calls are a no-op rather than an error, matching v3.

Returns

this core, for chaining

cy.batch

Run fn inside a startBatch()/endBatch() pair. The batch closes even if fn throws, so this is the form to prefer. As the outermost pair it is one transaction, batchstart … batchend (round 139); v4 has no rollback, so a throwing fn still ends in batchend, with the mutations that landed before the throw.

fn

the mutations to batch; its return value is discarded

Returns

this core, for chaining

Layout Core

cy.layout

Make a layout over the whole graph. The layout does not run until you call .run() on it.

Built-ins: grid, preset, circle, concentric, breadthfirst, random, radial, pack, force (the GPU-capable spring–electric layout, round 18) and flow (the layered layout, round 112) — the set schemas/layout-options.schema.json describes. An external layout is passed directly rather than registered — v4 has no cytoscape.use and no string registry — by giving impl: a class or object implementing { run( ctx ), stop?() } (see layout/contract.mts for the LayoutContext it receives).

Lifecycle events (layoutstart/layoutready/layoutstop) fire on the core, once per run; layout instances are not emitters.

options

{ name } for a built-in or { impl } for an extension, plus that layout's own options and the shared layoutPositions plumbing (animate, spacingFactor, transform, fit, padding, …)

Also spelled cy.makeLayout, cy.createLayout.

Returns

the layout instance, unstarted

Throws

if neither a known name nor an impl is given

See

Collection#layout to lay out a subset

Graph manipulation Core

cy.add

Add elements to the graph and return them as a collection.

Takes all three input forms: the classic v3 definition form (one object, an array, or { nodes, edges }), the columnar bulk form (typed-array columns with edge endpoints as node indices), and the binary wire buffer produced by serializeElements/cy.serialize(). Nodes are added before edges, so an edge may reference a node added in the same call. Wire and columnar inputs may carry miniature state with current positions; adding them does not rescale those coordinates.

Fires add per element. Inside a batch the first style application of the new elements defers to the outermost endBatch(), so style-derived reads (width(), label()) may be stale until then.

Graph-level data() in a wire buffer is ignored here (round 39.2), where options.elements applies it: adding elements to a populated graph must not overwrite that graph's own data(). Apply it explicitly with cy.data( deserializeElements( buf ).data ) if that is what you want.

Any iterable of element definitions is accepted too (round 75.3) — a generator, a Set, a Map's values() — and is read once into an array, then added exactly as that array would be. A wire buffer's typed-array view is iterable as well, and is decoded as a wire payload, never walked as definitions.

input

elements in definition, columnar or wire form, or an iterable of element definitions

Returns

a collection of the added elements

Throws

if input is a collection: v4 does not restore removed elements (MIGRATING.md, "Removed elements are terminally dead") — add the definitions you kept, e.g. from eles.jsons() taken before the removal

cy.remove

Remove elements from the graph. Removing a node removes its connected edges, and removing a compound parent removes its descendants. Equivalent to eles.remove().

eles

the elements to remove

Returns

the removed elements

cy.patch

Reconcile a fresh payload into the live graph by id (round 107): the payload is the next state of the same graph — the next query result, a server's refresh — and the patch computes what to add, remove and update, applies it as one batch, and returns what it did. A surviving element keeps selection, bypasses, running animations, listeners and scratch. Position follows the payload when carried; miniature state and its applied factor are adopted together with those current positions. The sheet, viewport and graph-level data() are never touched — elements only.

json( obj ) restores a serialized session and is not in v4 (cy.json() is export-only); patch() is not that. It reconciles a data refresh, and it takes all three input forms — definition, columnar and wire — through the load path's one funnel.

The rules, per payload element, keyed on its id: - Survives when the graph holds the id in the same group (and, for an edge, the same source and target). Its data record is replaced, not deep-merged: a key the payload element lacks is cleared, and a value compares structurally, so a fresh payload equal to the state changes nothing. Its position is written when the payload carries one and kept when it does not — except that a locked node (or every node, under autolock) holds its position and a compound parent's derives from its children, as at load. Its parent follows the payload (none means an orphan). Its miniature state follows when carried; the payload's applied factor is installed without rescaling its already-current positions. Its selection and selectable/locked/grabbable/pannable flags are session state and are never read from the payload. - Added when the id is new, and when the payload element has no id — exactly as cy.add() would add it, flags included. - Removed and re-added when an edge's source or target changed identity (rewiring is not a patch), or when the id changed group. - Removed when the graph holds an id the payload does not name — in 'reconcile' mode, the default. In 'merge' mode it is kept, and a definition-form payload may name kept nodes as endpoints and parents. Removal cascades as remove() does.

Events: remove, add, moveout + move (a reparented survivor), data, position, and committed collapse/expand state changes fire once per element, inside the batch and after every mutation has landed; then one core-level patch event carries the diff as event.diff — for an app that only wants the summary. A patch whose payload equals the state fires no element event, writes nothing and returns an empty diff (its patch event still fires). The patch is one transaction: batchstart, the element events, patch, then batchend (round 139); inside an app's batch it joins that one, and patch fires before the app's batchend.

Cost: at 100k elements and 90% id overlap a patch is 1.7–2.4× cheaper than destroy + recreate, and a payload equal to the state costs one scan (~20 ms). Below ~70% id overlap recreating is cheaper (1.8× at 50%, 2.3× at 10%), since removals and adds run per element — reload a low-overlap refresh that has no state worth keeping. benchmark/patch.mjs and "Patch" in src/README.md have the table.

input

the payload, in definition, columnar or wire form

options

{ mode }: 'reconcile' (default) or 'merge'

Returns

the diff: the added, removed and updated collections

Throws

before anything is mutated, if the payload names an id twice, if an edge lacks a source or target or names one that is not a node (in the payload, or — merge mode — in the graph), if a column does not fit the payload's counts, or on an unknown option or mode

cy.load

Progressive ingest (round 103): load the graph chunk by chunk from an async iterable — a streamed response, a server's pages — and show a correct partial graph before the last byte arrives. Each chunk is any input form (definition, columnar or wire); a chunk may name nodes an earlier chunk loaded — by id in the definition form, and through node references (refs) in the columnar and wire forms, which is what keeps a chunk's cut edges as cheap as its own. A plain iterable (an array of chunks) works too.

Every chunk lands through the bulk load path — one bulk style pass, no per-element handle — and the renderer gets a turn between chunks, even when the source hands them over synchronously; the second chunk is not asked for until the first is drawn. Every element drawn is correct; completeness arrives — a frame may show some of the graph, never a wrong piece of it.

An initial load — one that starts on an instance holding no elements, the streamed counterpart of options.elements — holds cy.ready until its first chunk is drawn (headless: until it is in the model), fits the viewport once to that chunk and then holds it (never a re-fit per chunk; fit: false keeps the viewport as it is), and applies the graph-level data() a wire chunk carries. The load re-points cy.ready, so read it after calling load() — a reference taken before resolves on the renderer alone. A load into a populated graph is a streamed cy.add(): cy.ready, the viewport and data() are left alone. Positions are the payload's (the preset case both flagship apps stream); a layout cannot start while a load runs — run it once the promise resolves.

Events: loadstart; loadchunk after each chunk (with add per element while anyone listens for it, as the bulk path emits them); loadready once the first chunk is drawn; loadstop when the load ends — completed, failed or cancelled (event.cancelled). Each carries event.progress: { chunks, nodes, edges } so far.

Completion is the returned promise, resolving with the final progress; it carries cancel() (round 128's contract): cancelling stops pulling chunks, closes the source's iterator, keeps what has landed, and rejects with a CancelledError. cy.destroy() cancels a running load. A chunk that fails to ingest rejects the load; the chunks before it stay, and a node reference that names no node fails its chunk before anything of it is added.

Cost (benchmark/progressive.mjs, ndex-x-large, 19.6k nodes / 465k edges): see "Progressive ingest" in src/README.md for the first-chunk and total times by chunk count and form.

source

an async iterable (or iterable) of chunks, each a definition, columnar or wire payload

options

{ fit, padding }: fit once to the first chunk (default: on for an initial load), and that fit's padding

Returns

the load's completion: a promise of the final { chunks, nodes, edges }, with cancel()

Throws

synchronously, when source is not an (async) iterable of chunks (a single payload is refused — pass [ payload ]), on an unknown option, while another load is running on this instance, or on a destroyed instance

Collections Core

cy.collection

An empty collection bound to this core — the accumulator for union/add chains.

Takes no arguments, and throws if given any (round 64, closing ledger item 28): v3's collection( eles, opts ) also built from a string, an array or a collection, so the v3-shaped call used to return the empty collection silently — the one method boundary where a typo did nothing, against the unknown-key/unknown-prop throws everywhere else. Build a set with union() over this accumulator, or query with cy.$( query ) / cy.filter( query ).

Returns

a collection of zero elements

Throws

if called with any argument — v3's building forms are not ported; the message names the replacements

cy.getElementById

Look up one element by id through the O(1) id index.

id

the element id

Also spelled cy.$id, cy.byId.

Returns

a collection of one element, or an empty collection when no element has that id

cy.elements

All elements, optionally filtered — nodes (in insertion order) then edges.

v4 has no selector strings: pass a structured query object ({ group, selected, parent, data: { weight: { gt: 0.5 } } }), which compiles to per-group flag tests answered by one columnar scan, or a predicate function for anything richer. Unknown query keys throw, so a typo cannot silently match everything.

Called with no query, the result is memoized until the graph next gains or loses an element (round 34.2), so repeated calls are O(1) and two of them return the same collection object. A v4 collection is an immutable snapshot holding refs into the columns, so it still reads live values — a style, position or data write neither invalidates it nor goes unseen through it.

query

a query object or an ( ele ) => boolean predicate; omit for everything

Returns

the matching elements

cy.nodes

The graph's nodes, optionally filtered. Same query forms as elements(), restricted to the node group — and, with no query, the same memo (34.2).

query

a query object or an ( ele ) => boolean predicate

Returns

the matching nodes

cy.edges

The graph's edges, optionally filtered. Same query forms as elements(), restricted to the edge group — and, with no query, the same memo (34.2).

query

a query object or an ( ele ) => boolean predicate

Returns

the matching edges

cy.filter

Filter the whole graph. Identical to elements( query ), kept for symmetry with eles.filter().

query

a query object or an ( ele ) => boolean predicate

Also spelled cy.$.

Returns

the matching elements

cy.elementsInBox

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 (v3's default 'contain' semantics, with straight-edge endpoints taken at the node centers).

boxSelectionMode does not reach here (round 39.1): 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.)

x1

one corner's model x

y1

that corner's model y

x2

the opposite corner's model x

y2

that corner's model y

Returns

the contained elements

Emphasis Core

cy.emphasize

Emphasize exactly eles and dim everything else — the hover highlight every graph app implements, as view state rather than a restyle. The call replaces the previous emphasis (only elements entering or leaving the set are written), so a hover handler is one line: cy.emphasize( node.closedNeighborhood() ) on mouseover, cy.unemphasize() on mouseout.

What it looks like is split by cost. The emphasized elements carry a state the sheet can style — { when: { emphasized: true } }, and the query key { emphasized: true } — restyled in O(set) like any state flip. Everything else is dimmed by the renderer: the scene draws in two tiers, the rest composited at the core dim-opacity (default 0.15), then the emphasized elements above it at full strength — so an emphasized edge is never hidden under a dimmed node. The dim is a composite, not a style: style() reads a dimmed element's own values, and there is no dimmed state to condition on (a per-element dim rewrites every element whenever an emphasis turns on or off — measured at 1.1 s per hover change on a 484k-element graph, against O(set) here).

An empty collection is a valid emphasis: everything dims. The emphasis stays set until unemphasize(), through removals and adds (a new element is not emphasized). It is per instance and never serialized: a clone() does not share it and a patch() keeps it on surviving elements. png()/jpg() draw it as the screen does, the rest composited over the export's bg. Picking ignores it: a dimmed node still answers pick() and hover, and where an emphasized edge is raised over a dimmed node the node wins the pick, by the structural order pick() documents. v4's own — v3 has no equivalent (apps spelled it with classes and an opacity rule over the whole graph).

eles

the elements to emphasize, from this instance

Returns

this core, for chaining

Throws

when eles is not a collection, or is one from another instance

cy.unemphasize

End the emphasis: clear the emphasized set and stop dimming. A no-op when no emphasis is set.

Returns

this core, for chaining

Events Core

cy.on

Listen for events on the core.

Delegation is predicate-based — there are no selector strings. With a trailing callback the middle argument is a predicate over the event target: cy.on( 'tap', ele => ele.isNode(), handler ).

Any name registers, and that is deliberate (decided 2026-08-04, fifth design sitting). Custom events are supported API — emit( 'foo' ) fires handlers bound to 'foo' — so event names cannot be validated against a list without breaking them. The consequence is worth stating plainly, because it is a silent one: a name v4 never emits registers cleanly and then never fires. That covers the round-17 drops — the vmouse* aliases and v3's raw mouse/touch re-emits (mousedown, click, touchstart, …), for which pointer* is the one modern spelling; mouseover/mouseout do still fire. A ported v3 handler does nothing at all rather than erroring, so port event names by the vocabulary in src/README.md rather than by trying them.

Namespaces are exactly that rule, not an exception to it (round 41.2). There is no namespace machinery: a type is matched whole, so 'tap.ns' is one literal name that emit( 'tap' ) does not reach and off( 'tap.ns' ) removes on its own. Until round 41 v4 imported v3's emitter and so inherited v3's namespace semantics in full, against its own design — measured in 37.4 and closed in 41.2.

events

one or more space-separated event names

predicateOrCb

the delegation predicate when callback is given, otherwise the handler itself

callback

the handler, when delegating

Listen with predicate delegation: the handler runs only for events whose target satisfies predicate.

events

one or more space-separated event names

predicate

( ele ) => boolean over the event target; only runs for element targets

callback

the handler

Also spelled cy.addListener.

Returns

this core, for chaining

See

Core#off — removing a delegated handler takes the same ( events, predicate, handler ) triple, since predicates compare by function identity

cy.one

Like on(), but the handler runs at most once and then removes itself.

events

one or more space-separated event names

predicateOrCb

the delegation predicate when callback is given, otherwise the handler itself

callback

the handler, when delegating

Like on() with delegation, but the handler runs at most once.

events

one or more space-separated event names

predicate

( ele ) => boolean over the event target

callback

the handler

Also spelled cy.once.

Returns

this core, for chaining

cy.off

Stop listening. Removing a delegated handler takes the same ( events, predicate, handler ) triple it was added with — predicates compare by function identity, so the predicate must be the same function object, not an equivalent one.

events

one or more space-separated event names

predicateOrCb

the delegation predicate when callback is given, otherwise the handler itself; omit both to remove every handler for events

callback

the handler, when delegating

Remove a delegated handler. The predicate must be the same function object it was registered with — predicates compare by identity, not by structure.

events

one or more space-separated event names

predicate

the predicate the handler was added with

callback

the handler to remove

Also spelled cy.removeListener.

Returns

this core, for chaining

cy.removeAllListeners

Remove every listener on the core, including element-bound and delegated ones.

Returns

this core, for chaining

cy.emit

Emit an event on the core.

Custom event names are supported API, which is why on() validates none: cy.emit( 'myevent' ) runs handlers registered for 'myevent', and the same holds on elements. Names v4 itself never emits are therefore legal to register and simply never fire — see on() for which those are, and PLAN.md's open-call record for why no denylist exists.

events

one or more space-separated event names, or an event props object

extraParams

extra arguments passed to each handler after the event object

Also spelled cy.trigger.

Returns

this core, for chaining

cy.promiseOn

Resolve once the next matching event fires — the promise form of one().

events

one or more space-separated event names

predicate

an optional delegation predicate over the target

Also spelled cy.pon.

Returns

a promise for the event object

Viewport Core

cy.zoom

Get the zoom level, or set it. Setting is a no-op while zoomingEnabled() is false, and the level is clamped to zoomRange().

zoom

the new level, or { level, position | renderedPosition } to zoom about a fixed point; omit to read

Returns

the current zoom when reading, this core when setting

cy.pan

Get the pan offset, or set it. Setting is a no-op while panningEnabled() is false.

pan

the new rendered-space offset; omit to read

Returns

the current pan when reading, this core when setting

cy.panBy

Shift the pan by a delta. A no-op while panningEnabled() is false.

delta

the rendered-space offset to add

Returns

this core, for chaining

cy.fit

Pan and zoom so the given elements fill the viewport.

Bounds include labels by default (round 16), so a fit never clips the text it was asked to show; edge-label terms are conservative, so a fit may slightly over-fit but never under-fits.

eles

the elements to fit; omit for the whole graph

padding

rendered-space padding around the box

Returns

this core, for chaining

cy.center

Pan so the given elements are centred, leaving the zoom alone. Bounds include labels, as in fit().

eles

the elements to centre on; omit for the whole graph

Also spelled cy.centre.

Returns

this core, for chaining

Animation (viewport) Core

cy.animate

Animate the viewport (pan/zoom) over duration ms. Element animation is on the collection (eles.animate). Tweens are CPU-canonical; a data write / manual pan mid-animation is not prevented but will be overwritten by the next tick.

opts

the viewport targets (pan, panBy, zoom, fit, center) plus duration, easing and complete; fit beats center beats panBy beats pan, and panBy with pan throws

Returns

this core, for chaining

cy.animation

Like animate, but returns a handle with play/stop/promise — the viewport counterpart of eles.animation.

opts

as animate; the animation does not start until play()

Returns

the handle

cy.animated

True while the viewport is animating.

Returns

whether a viewport animation (pan/zoom/fit/center) is running; element animations do not count here — those are eles.animated()

cy.stop

Stop every running viewport animation (round 21: no queue — the v3 clearQueue argument is gone).

jumpToEnd

apply each animation's final values instead of freezing the viewport where the tween reached

Returns

this core, for chaining

cy.extent

The model-space rectangle currently visible, as { x1, y1, x2, y2, w, h } — the inverse of the pan/zoom transform applied to the viewport box.

Returns

the visible extent in model coordinates

See

Core#renderedExtent for the same box in rendered coordinates

cy.renderedExtent

The rendered (on-screen) viewport rectangle.

Returns

the container's box in rendered px, anchored at the origin — the rendered-space counterpart of extent(), which is the same box projected into model coordinates

See

Core#extent for the model-coordinate form

cy.size

Rendered dimensions as { width, height }.

cy.minZoom

Get the minimum zoom, or set it. Setting re-clamps the current zoom.

zoom

the new minimum; omit to read

Returns

the current minimum when reading, this core when setting

cy.maxZoom

Get the maximum zoom, or set it. Setting re-clamps the current zoom.

zoom

the new maximum; omit to read

Returns

the current maximum when reading, this core when setting

cy.zoomRange

Set both zoom bounds; accepts (min, max) or { min, max }.

Public in v4 by decision (round 90) — v3 kept its counterpart internal.

min

the minimum zoom, or an object carrying both bounds

max

the maximum zoom, when min is a number

Returns

this core, for chaining

cy.viewport

Set zoom and/or pan together, emitting once.

opts

the zoom and/or pan to apply; omitted keys are left as they are

Returns

this core, for chaining

cy.reset

Reset the viewport to zoom 1, pan (0, 0).

cy.pick

Async GPU pick at a rendered (CSS px) position; resolves with the element under the point or null (always null when headless — the sync, node-only cy.nodeAt() computes headless).

Exact: a hit is a point on the drawn element. The pointer gestures additionally apply v3's hit halos (8 rendered px around edges for a mouse, 24 for touch; 2/8 around nodes — round 57.9), so a press can land where this method answers null; the halo belongs to the gesture, not the API.

What wins when elements overlap, as contract (round 97.1): a non-parent node, then an edge, then a compound parent — the reverse of the order v4 draws them in (parents, edges, leaves), so the answer is always the topmost thing drawn at that point. Nesting depth does not change it: a parent inside another parent still draws under every edge, and among parents the deepest wins. v3 ordered these by z-index / z-compound-depth instead, which v4 does not have, so a deeply nested v3 parent could beat a shallower edge where v4's edge wins.

x

rendered (CSS px) x, relative to the container

y

rendered (CSS px) y

Returns

the element under the point, or null

cy.nodeAt

The node at a rendered (CSS px) position, synchronously — or null (round 75.4, #1209). The sync half of the pick pair: cy.pick() is async because an edge hit is a GPU question, while a node hit is answered on the CPU from the canonical columns, in the same microtask — the pick the pointer's own pan-vs-grab decision trusts.

Nodes only, and exact. Edges never answer here — ask cy.pick(), which resolves the whole leaf > edge > parent order — so over a node that an edge crosses, nodeAt answers the node where pick may answer the edge only when the node is a compound parent (parents draw under edges; a leaf draws over them and both agree). Among nodes the topmost drawn wins, leaves over parents, as in cy.pick(). No hit halo: the gestures' 2/8 px node halos (57.9) belong to the gesture, not the API. What is not drawn is not picked — visibility: hidden, a hidden (hide()) node, and a node smaller than the renderer's hidePx at the current zoom.

Headless, it computes (the eleventh sitting) from the store and the viewport at a device-pixel ratio of 1 with the renderer's default thresholds, so a test or a server-side hit test gets the answer a default renderer would give at dpr 1.

x

rendered (CSS px) x, relative to the container

y

rendered (CSS px) y

Also spelled cy.pickNode.

Returns

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

See

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

cy.viewportCounts

How many nodes and edges the renderer draws — the visible counts of the next frame, after the viewport test, visibility and the level of detail (round 75.6, #2283). Async because the counts live on the GPU: the cull writes them into its indirect draw arguments, and this reads them back. Schedules a frame when nothing is pending, so it resolves on a graph at rest too; concurrent calls share one readback. Compound parents count as nodes; labels are not counted (the glyph streams count glyphs, not labels).

Resolves null headless (the eleventh sitting: an honest "no renderer", as cy.pick() answers), and on destroy or device loss before a frame answered. The synchronous, geometric alternative is cy.elementsInBox( e.x1, e.y1, e.x2, e.y2 ) with e = cy.extent(): model-space containment, which sees no hide or level-of-detail thresholds — a node too small to draw is in the box and not in these counts.

Returns

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

Renderer Core

cy.stats

The renderer's frame statistics, or null when headless. The snapshot carries the frame timings, cache hit rates and pass counters — note that cpuFrameMs is encode/submit cost only (submission is fire-and-forget), so reconcile fps against gpuFrameMs.

Returns

a RendererStats snapshot, or null on a headless instance

cy.resize

Re-measure the container, redraw and emit 'resize' (the redraw is a no-op when headless; the event still fires).

Rarely needed in v4 (round 75.1): a ResizeObserver on the container re-measures on every size change and emits 'resize' itself — once per change, and not again for a change this call already applied — so v3's "call cy.resize() after resizing the container" is automatic. Call it where no observer exists or none can see the change.

Also spelled cy.invalidateSize.

Returns

this core

Image export Core

cy.png

Export the rendered graph as a PNG. Async — the pixels live on the GPU (offscreen render + readback), unlike v3's synchronous base64 form; every output form resolves through the returned promise. Options as in v3: bg, full, scale or maxWidth/maxHeight, output ('base64uri' default | 'base64' | 'blob'; 'blob-promise' is an accepted alias of 'blob'). Headless instances reject — there is no renderer to export from.

options

the v3 export options named above

Returns

the encoded image in the requested output form

cy.jpg

Export as JPEG: as png, plus quality (0..1) and a white default bg (JPEG has no alpha channel).

options

as png, plus quality

Also spelled cy.jpeg.

Returns

the encoded image in the requested output form

Graph-level data & scratch (plain objects, not columns) Core

cy.data

Graph-level data — read all, read one key, or write. This is a plain object, not a columnar sidecar (which is ele.data()). It is carried by the wire format since round 39.2: serialize() writes it and options.elements applies it, while cy.add( buffer ) deliberately ignores it. Writing emits data.

args

() for the whole object, ( key ) to read one, ( key, value ) or ( patchObject ) to write

Also spelled cy.attr.

Returns

the data object or value when reading, this core when writing

cy.removeData

Delete graph-level data keys. Emits data when anything was removed.

names

space-separated key names; omit to clear everything

Also spelled cy.removeAttr.

Returns

this core, for chaining

cy.scratch

Graph-level scratchpad — like data(), but for transient state that is never exported and never emits. Namespace your keys (an extension convention: '_myExtension').

args

() for the whole object, ( key ) to read one, ( key, value ) or ( patchObject ) to write

Returns

the scratch object or value when reading, this core when writing

cy.removeScratch

Delete graph-level scratch keys.

names

space-separated key names; omit to clear everything

Returns

this core, for chaining

Interaction gating Core

cy.autolock

Get or set whether every node is locked (immovable) regardless of its own locked flag — the graph-wide override. Turned on mid-tween, every running position tween holds where it got to (round 144), as a node locked mid-tween does.

bool

the new setting; omit to read

Also spelled cy.autolockNodes.

Returns

the current setting when reading, this core when setting

cy.autoungrabify

Get or set whether every node is ungrabbable regardless of its own grabbable flag. Unlike autolock(), this blocks only user dragging; programmatic position writes still apply.

bool

the new setting; omit to read

Also spelled cy.autoungrabifyNodes.

Returns

the current setting when reading, this core when setting

cy.autounselectify

Get or set whether every element is unselectable regardless of its own selectable flag. Programmatic select() still applies.

bool

the new setting; omit to read

Returns

the current setting when reading, this core when setting

cy.panningEnabled

Get or set whether panning is allowed at all — programmatic pan() included. Use userPanningEnabled() to block only the gesture.

bool

the new setting; omit to read

Returns

the current setting when reading, this core when setting

cy.userPanningEnabled

Get or set whether the user may pan by dragging. Programmatic pan() is unaffected.

bool

the new setting; omit to read

Returns

the current setting when reading, this core when setting

cy.zoomingEnabled

Get or set whether zooming is allowed at all — programmatic zoom() included. Use userZoomingEnabled() to block only the gesture.

bool

the new setting; omit to read

Returns

the current setting when reading, this core when setting

cy.userZoomingEnabled

Get or set whether the user may zoom by wheel or pinch. Programmatic zoom() is unaffected.

bool

the new setting; omit to read

Returns

the current setting when reading, this core when setting

cy.boxSelectionIncludesLabels

Whether box selection considers label boxes as well as node bodies (round 16.5; v3's box-select-labels, reshaped as a core option — default off). Its sense follows boxSelectionMode: under 'contain' the label box must also be inside the band, under 'overlap' a label that merely crosses the band is enough.

bool

the setting to apply; omit to read it

Returns

the setting, or this when setting

cy.boxSelectionMode

What the box-selection gesture counts as caught: 'contain' (default, v3's) selects only elements wholly inside the band; 'overlap' selects anything the band touches — a node whose box intersects it, an edge any part of whose drawn path crosses it. Round 39.1.

Two notes on the boundary. This setting is read by the gesture only: cy.elementsInBox() stays the pure geometric containment query it has always been, so a programmatic caller's results do not change under this setting. And boxSelectionIncludesLabels reverses sense with the mode, because it can only mean one thing in each: under 'contain' the label box must also be inside, under 'overlap' a label that crosses the band is enough.

mode

the mode to set; omit to read the current one

Returns

the mode, or this when setting

Throws

if mode is neither 'contain' nor 'overlap'

cy.boxSelectionEnabled

Get or set whether the box-selection gesture is available.

bool

the new setting; omit to read

Returns

the current setting when reading, this core when setting

cy.pointerCursors

Get or set whether the canvas writes CSS cursors for the gesture affordances (round 89): grab over a draggable node and grabbing while it or the background is being dragged, pointer over any other interactive element, crosshair while box-selecting.

Three shapes. true (the default) takes the built-in map; false means the interaction layer never touches style.cursor at all — for an app that sets its own, which is what every v3 app did, since v3 set no cursors and left the affordance to userland. An object overrides individual entries ({ pan: 'move' }) and falls back to the defaults for the rest, where '' means inherit.

Idle over background is '' rather than default for that same reason: v4's canvas fills its container, so an inline cursor would override the app's own, and a v4 instance with nothing to say says nothing. A touch pointer never gets a cursor either way.

cursors

the setting to apply; omit to read the current one

Returns

the setting, or this core when setting

cy.selectionType

How user selection composes: 'single' (a tap or box replaces the selection) or 'additive' (taps toggle and boxes add, as if a multiple-select key were always held).

type

the mode to set; omit to read the current one

Returns

the mode, or this when setting

Throws

if type is neither 'single' nor 'additive'

cy.multiClickDebounceTime

The dbltap/onetap debounce window in ms (v3 parity; default 250).

Public in v4 by decision (round 90) — v3 kept its counterpart internal.

ms

the window to set; omit to read it

Returns

the window, or this when setting

Throws

if ms is not a finite non-negative number

cy.wheelSensitivity

Wheel-zoom sensitivity: a multiplier on the zoom-per-wheel-tick exponent (v3 parity; default 1). Non-default values warn once per instance, as v3 does — a custom sensitivity tuned on one mouse/OS zooms unnaturally on others.

mult

the multiplier to set; omit to read it

Returns

the multiplier, or this when setting

Throws

if mult is not a finite positive number (0 would freeze the zoom, so the bound is strict where the threshold setters allow 0)

cy.wheelBehavior

What a wheel over the canvas does (round 75.5): 'zoom' (the default, v3's) zooms about the cursor; 'pan' pans by the wheel's delta and emits scrollpan, while a ctrl- or meta-wheel — the encoding a trackpad pinch arrives in — still zooms; 'modifier-zoom' leaves the plain wheel to the page (it scrolls past the graph) and zooms only on a ctrl- or meta-wheel. Every mode honours the toggles (userZoomingEnabled gates a zoom, userPanningEnabled a pan), and a wheel the settings leave inert is not preventDefault()ed, so the page scrolls — v3's contract, restored in the same round.

mode

the behaviour to set; omit to read it

Returns

the behaviour, or this when setting

Throws

if mode is not 'zoom', 'pan' or 'modifier-zoom'

cy.desktopTapThreshold

Css px a mouse/pen press may move and still count as a tap (v3 parity; default 4).

px

the threshold to set; omit to read it

Returns

the threshold, or this when setting

Throws

if px is not a finite non-negative number

cy.touchTapThreshold

Css px a touch press may move and still count as a tap (v3 parity; default 8).

px

the threshold to set; omit to read it

Returns

the threshold, or this when setting

Throws

if px is not a finite non-negative number

cy.tapholdDuration

Unmoved-press duration before 'taphold' fires, ms (default 500 — v3's constant, configurable in v4).

ms

the duration to set; omit to read it

Returns

the duration, or this when setting

Throws

if ms is not a finite non-negative number

Environment Core

cy.isReady

Whether the render pipeline is usable yet. Always true on a headless instance; on a rendered one this flips when cy.ready resolves.

Public in v4 by decision (round 90) — v3 kept its counterpart internal.

Returns

true once rendering can proceed

cy.headless

Whether this instance has no container and therefore no GPU — the Node-testable mode, in which every model API works and the render, pick and image-export paths are no-ops or reject.

Public in v4 by decision (round 90) — v3 kept its counterpart internal.

Returns

true when running headless

cy.styleEnabled

Always true: v4 has no style-disabled mode, since the columnar model derives geometry from stored style channels rather than treating style as an optional layer. Kept so v3 code that checks it works.

Public in v4 by decision (round 90) — v3 kept its counterpart internal.

Returns

true

cy.hasCompoundNodes

Whether any node currently has a parent. Worth checking because the compound tier changes paint evaluation and draw order; the renderer pays nothing for compounds while this is false.

Public in v4 by decision (round 90) — v3 kept its counterpart internal.

Returns

true when the graph has at least one parent/child relation

cy.hasElementWithId

Whether an element with this id exists, via the O(1) id index — cheaper than getElementById( id ).nonempty() because no handle is materialized.

Public in v4 by decision (round 90) — v3 kept its counterpart internal.

id

the element id

Returns

true when the graph holds that element

cy.window

The window this instance renders into, or null when there is no DOM (Node). v3 parity, for extensions that need the hosting realm.

Public in v4 by decision (round 90) — v3 kept its counterpart internal.

Returns

the global window, or null outside a browser

cy.options

The options the instance was constructed with.

Public in v4 by decision (round 90) — v3 kept its counterpart internal.

Returns

the caller's own options object, held by reference — not a copy and not a defaults-resolved view, so an option the caller omitted reads back absent rather than as the default in force

cy.serialize

Export the live graph as the binary wire format (the buffer options.elements/add() accept directly): the columnar counterpart of json(). Carries ids, positions, selection state, the data() sidecar and — since round 39.2 — graph-level data(); style, viewport and scratch are not part of the wire.

Note the asymmetry in loading that graph data back: options. elements applies it, cy.add( buffer ) ignores it. Adding elements to a populated graph must not overwrite that graph's own data(), and there is no third answer that is right in both places.

Returns

a fresh little-endian buffer, self-contained (every edge endpoint indexes a node in the same payload) and directly loadable — derived geometry is flushed first, so parent boxes are the current ones rather than whatever was last materialized

cy.json

Export the graph as a plain object — elements, stylesheet, viewport, gating flags and graph-level data.

Export-only: the v3 import/restore form (json( obj )) is not supported, because rebuilding from a snapshot needs the stored element definitions that the columnar model deliberately does not keep. Use serialize() for the compact binary counterpart, which can be fed back in.

flat

when true, elements export as one flat array instead of { nodes, edges } (v3's option)

Returns

the exported graph

Throws

if given anything but a boolean — the guard that catches an attempted json( obj ) import

cy.clone

Make an independent instance holding a copy of this graph (round 106) — the way to show one graph in two places, e.g. a minimap beside the main view. A second view is a second instance, never a second renderer over one model: each clone has its own sheet, viewport, selection, hover, listeners and png().

What is carried: every element through the wire format — ids, data, positions, parents, endpoints, selected/selectable — plus each element's locked/grabbable/pannable flags, graph-level data(), the stylesheet with its bypasses, the viewport (zoom, pan, limits), the gating flags and interaction settings, and the options this instance was built with. options overrides any of it: a container for the clone (never carried; one container, one renderer), a style (the minimap's simplified sheet — which replaces the bypasses too), a zoom or pan, a layout to run on the copy. What is not carried, by design: scratch, running animations and layouts, listeners, and the transient hover/active/grabbed state.

follow keeps the clone current: each sync is clone.patch( this.serialize() ), driven by a dirty-stream consumer on this instance and throttled ({ throttle } ms, default 50, and never more often than the last sync took). A sync runs only after a change the payload carries — an add, remove, move, data write or reparent; a restyle, hover or selection here costs the clone nothing. The clone owns its state: patch never reads selection or flags for a surviving element, so selecting in one view does not select in the other (linked brushing is app wiring over the two instances' events). Positions are this instance's to set: a sync moves a clone's node even where the clone locks it (autolock, a locked node). Its own edits to elements are reconciled away at the next sync; its sheet, viewport, bypasses and graph data are never touched. Following stops when either instance is destroyed.

Cost: a clone is one serialize() plus a load from the wire — ~25 ms at 10k elements, ~230 ms at 100k — and duplicates the model (~50 MB per 100k elements); a follow sync is one serialize plus one patch — ~8 ms at 10k elements, ~50 ms at 100k from the source's write to the clone's patch event — so a follower lags by a burst, not a frame, on a large graph. benchmark/clone.mjs and "N viewers" in src/README.md have the numbers.

options

construction options over the carried ones, plus follow (true or { throttle })

Returns

the new instance, built by the same entry as this one

Throws

if options carries elements (a clone's elements are this instance's), on a malformed follow, and wherever construction throws — a container in a build with no renderer, or without WebGPU

cy.unmount

Detach the renderer: the instance becomes headless (the model is CPU-canonical, so nothing is lost). No-op when already headless.

cy.mount

(Re)attach a renderer to a container. Re-mounting to a different container unmounts first; the fresh renderer re-uploads every column from the CPU-canonical model and rebuilds all glyph runs.

container

the element to render into

Returns

this

Throws

if no container is given, if the instance was built directly rather than through the cytoscape factory (there is no renderer to attach), if it was built by cytoscape/headless or cytoscape/headless-gpu (a build with no renderer — round 131), or if WebGPU is unavailable — mounting is the one way a headless instance can demand a GPU after construction

cy.container

The DOM element this instance renders into, or null when headless or unmounted.

Returns

the container element, or null

cy.width

The rendered width in CSS px. Headless instances report the configured headlessWidth (default 800), so viewport maths works without a DOM.

Returns

the viewport width in CSS px

cy.height

The rendered height in CSS px. Headless instances report the configured headlessHeight (default 600).

Returns

the viewport height in CSS px

cy.destroy

Tear the instance down: emit destroy, drop every listener, and release the pointer handler and the renderer (with its GPU resources). Idempotent. The store is left intact but the instance must not be used afterwards.

Returns

this core

cy.destroyed

Whether destroy() has run.

Returns

true once destroyed

Collection

Basics Collection

eles.length

How many elements this collection holds.

Core reference & identity Collection

eles.cy

The core this collection belongs to.

Returns

the instance that owns these elements — a collection cannot span two cores, so this is also the identity a set operation against a foreign collection would violate

eles.collection

An empty collection in the same core.

Takes no arguments, and throws if given any — the same round-64 guard as cy.collection(), since this delegate shared the same silently-ignored-argument shape.

Returns

a fresh empty collection bound to this core — the seed for building a set up by union

Throws

if called with any argument (v3's building forms are not ported; the message names the replacements)

eles.hasElementWithId

Whether this collection contains an element with the given id.

Public in v4 by decision (round 90) — v3 kept its counterpart internal.

id

the element id

Returns

true when a member has that id

eles.indexOf

Index of an element within this collection.

Public in v4 by decision (round 90) — v3 kept its counterpart internal.

ele

the element to find; only its first element is used

Returns

the index, or -1 when it is not in this collection

eles.indexOfId

Position of the element with this id within the collection.

Public in v4 by decision (round 90) — v3 kept its counterpart internal.

id

the element id

Returns

the index, or -1 when absent

Iteration Collection

eles.size

The number of elements — the method form of length.

Returns

the element count

eles.empty

Whether the collection holds no elements.

Returns

true when empty

eles.nonempty

Whether the collection holds at least one element.

Returns

true when non-empty

eles.forEach

Call fn for each element. Returning false from the callback stops the iteration early, as in v3.

With no thisArg the callback is plain-called, so this is undefined inside it — v3's semantics, and deliberate: rebinding the receiver per element costs about 2x on large collections.

fn

( ele, i, eles ); return false to stop

thisArg

optional receiver for the callback

Also spelled eles.each.

Returns

this collection, for chaining

eles.toArray

The elements as a plain array of length-1 collections.

Returns

a new array of the members

eles.slice

A sub-range of the collection, with Array#slice semantics (negative indices count from the end).

start

first index, inclusive

end

last index, exclusive

Returns

the sub-range as a new collection

eles.sort

A copy sorted by a comparator. Note that sort order is a property of the collection, not of drawing: v4 draw order is structural and there is no z-index.

sortFn

( a, b ) comparator over length-1 collections; a non-function is ignored and returns this collection unchanged

Returns

a new, sorted collection

eles.eq

The element at an index, as a length-1 collection.

i

the index

Returns

that element, or an empty collection when out of range

eles.first

The first element, as a length-1 collection.

Returns

the first element, or an empty collection

eles.last

The last element, as a length-1 collection.

Returns

the last element, or an empty collection

eles.map

Map each element through fn into a plain array.

fn

( ele, i, eles )

thisArg

optional receiver for the callback

Returns

an array of the results

eles.some

Whether any element satisfies the predicate. Short-circuits.

fn

( ele, i, eles ) => boolean

thisArg

optional receiver for the callback

Returns

true when at least one element matches

eles.every

Whether every element satisfies the predicate. Short-circuits, and is vacuously true for an empty collection.

fn

( ele, i, eles ) => boolean

thisArg

optional receiver for the callback

Returns

true when all elements match

Identity Collection

eles.id

The first element's id. Cached on the handle, so it stays readable after the element is removed.

Returns

the id, or undefined when the collection is empty

eles.group

The first element's group. Cached on the handle, so it stays readable after removal.

Returns

'nodes' or 'edges', or undefined when empty

eles.json

Plain-object form of the first element (undefined when empty).

Returns

the definition-form object for the first element, or undefined when the collection is empty; it round-trips through cy.add(), which is the supported restore path since cy.json()'s import form is not in v4

eles.jsons

Plain-object form of every element.

Returns

one object per element, in collection order — the plural of json(), not a graph-level export

eles.isNode

Whether the first element is a node.

Returns

true for a node

eles.isEdge

Whether the first element is an edge.

Returns

true for an edge

eles.isLoop

Whether the first element is a self-loop — an edge whose source and target are the same node.

Returns

true for a loop edge; false for nodes and removed elements

eles.isSimple

Whether the first element is a non-loop edge.

Returns

true for an edge between two distinct nodes

eles.removed

Whether the first element has been removed from the graph. A removed element's handle stays usable — reads are no-ops or undefined, and the cached id()/group() remain readable.

Returns

true when the element is no longer in the graph

eles.inside

Whether the first element is still in the graph — the complement of removed().

Returns

true when the element is live

Comparison Collection

eles.same

Whether both collections hold exactly the same elements, ignoring order.

other

the collection to compare against

Also spelled eles.equal, eles.equals.

Returns

true when the element sets are equal

eles.anySame

Whether the two collections share at least one element.

other

the collection to compare against

Returns

true when the sets intersect

eles.contains

Whether every element of other is also in this collection.

other

the candidate subset

Also spelled eles.has.

Returns

true when other is contained

eles.allAreNeighbors

Whether every element of other is in this collection's neighborhood.

other

the elements to test

Also spelled eles.allAreNeighbours.

Returns

true when all of them are neighbors

eles.allAre

Whether every element matches the criterion.

criterion

a query object or an ( ele ) => boolean predicate (there are no selector strings in v4)

Returns

true when all elements match

eles.is

Whether any element matches the criterion.

criterion

a query object or an ( ele ) => boolean predicate

Returns

true when at least one element matches

Building and filtering Collection

eles.union

The union of the two collections, deduped.

other

the collection to add

Also spelled eles.u, eles.or, eles.add, eles.merge.

Returns

a new collection holding both sets

eles.difference

This collection's elements that are not in other.

other

the collection to subtract

Also spelled eles.not, eles.subtract, eles.unmerge, eles.relativeComplement.

Returns

a new collection

eles.intersection

The elements present in both collections.

other

the collection to intersect with

Also spelled eles.intersect, eles.and.

Returns

a new collection

eles.symmetricDifference

The elements in exactly one of the two collections.

other

the other collection

Also spelled eles.symdiff, eles.xor.

Returns

a new collection

eles.filter

The subset matching the criterion.

A structured query object is answered directly off the flags column — no per-element handles and no closures — while a predicate function is called per element. v4 has no selector strings, so those two forms cover what v3 spelled with a selector.

criterion

a query object ({ selected: true }, { data: { weight: { gt: 0.5 } } }, …) or an ( ele, i, eles ) => boolean predicate

thisArg

optional receiver, for the predicate form

Returns

a new collection of the matching elements

Throws

if a query object carries an unknown key — a typo must not silently match everything

eles.nodes

The nodes in this collection, optionally filtered.

criterion

a query object or predicate; omit for all nodes

Returns

a new collection of nodes

eles.edges

The edges in this collection, optionally filtered.

criterion

a query object or predicate; omit for all edges

Returns

a new collection of edges

eles.getElementById

Find a member by id. This is a linear scan of the collection; use cy.$id( id ) for the O(1) whole-graph index.

id

the element id

Returns

a collection of one element, or an empty collection

eles.absoluteComplement

All elements of the graph not in this collection.

Also spelled eles.complement, eles.abscomp.

Returns

the complement against the whole graph, not against any enclosing collection — which is what the absolute in the name is distinguishing

eles.diff

Three-way set difference against another collection.

other

the collection to compare with

Returns

{ left: only in this, right: only in other, both: in both }

eles.reduce

Fold the collection into a single value.

fn

( accumulator, ele, i, eles )

initial

the starting accumulator (required, unlike Array#reduce)

Returns

the final accumulator

eles.max

The element maximizing valFn, with its value.

valFn

( ele, i, eles ) => number

thisArg

optional receiver for the callback

Returns

{ value, ele }, or { value: -Infinity, ele: undefined } when the collection is empty

eles.min

The element minimizing valFn, with its value.

valFn

( ele, i, eles ) => number

thisArg

optional receiver for the callback

Returns

{ value, ele }, or { value: Infinity, ele: undefined } when the collection is empty

Position and dimensions Collection

eles.position

Get or set the first element's model-space position (nodes only).

Reading a compound parent settles pending auto-bounds first, so the derived centre is current. Reading a node under an offloaded position animation — an animated layout's tween included — reports the value the last frame drew (round 144; v3's answer, and the CPU path's), though the CPU column holds the start until the tween settles, so column scans (bounding boxes, box selection) read that. Under a live GPU force layout it reports the stale column until the run settles — the motion-staleness rule; geometry channels like width() never go stale.

dim

'x' or 'y' to read/write one axis, or a { x, y } object to write both; omit to read the pair

value

the new coordinate, with the 'x'/'y' form

Also spelled eles.modelPosition, eles.point.

Returns

the position or coordinate when reading (undefined for edges and removed elements), this collection when writing

eles.positions

Set every node's position, from a constant or per-element function.

pos

a { x, y } for all of them, or ( ele, i ) => ( { x, y } )

Also spelled eles.modelPositions, eles.points.

Returns

this collection, for chaining

Animation Collection

eles.animate

Animate these elements' style and/or position to explicit targets over duration ms, easing the normalized time.

There is no queue (round 21): the animation starts immediately, animations on disjoint channels run concurrently, and starting one that overlaps a running animation's channels stops the older one in place — its promise resolves, its values freeze, and the new animation captures from there. Sequence with await animation( … ).play() rather than by queueing.

Animatable: position; opacity (both groups); node background-color/border-color/border-width, edge line-color; and — since round 25 — the geometry numerics node width/height, edge width, compound padding and font-size. Colours interpolate in OKLab, matching the colour mappers, which deliberately differs from v3's per-channel sRGB tweening.

Easings are names, not functions: v3's full enum plus cubic-bezier( … ), CSS linear( … ) and spring( bounce ). A custom easing function is rejected — a closure cannot cross to the GPU, so accepting one would mean a curve that silently depended on whether the animation got offloaded.

opts

targets (position, style, or collapsed for compound parents; viewport forms apply on cy.animate), duration, easing, delay, complete

Returns

this collection, for chaining; use animation() when you want the handle

See

Collection#animation for the handle form with promise/pause/resume/reverse

eles.animation

Build an animation for these elements without starting it.

opts

the tween targets (position, style, or compound collapsed state) plus duration, delay, easing and complete

Returns

the handle; nothing runs until play()

eles.delay

A no-op tween — a timed pause that touches no channels, so it composes with any running animation (round 21: use delayAnimation().play() + await to sequence).

duration

the pause in ms

complete

called when it elapses

Returns

this collection, for chaining

eles.delayAnimation

Like delay, but returns the handle instead of chaining.

duration

the pause in ms

complete

called when it elapses

Returns

the handle; nothing runs until play()

eles.animated

True when any of these elements has a running animation.

Returns

whether any element here is animating — not whether all are, and not whether the viewport is (that is cy.animated())

eles.stop

Stop every running animation on these elements (round 21: no queue — the v3 clearQueue argument is gone).

jumpToEnd

apply each animation's final values instead of freezing each channel where its tween reached

Returns

this collection, for chaining

eles.shift

Offset positions by a vector or along one axis.

dim

a { x, y } delta, or 'x' / 'y' with value

value

the offset, when dim names an axis

Returns

this collection, for chaining

eles.relativePosition

Compound-relative position: the model position minus the immediate parent's (derived) position — the model position for orphans and compound-free graphs (round 14.3, v3 semantics).

dim

omit to read the pair, 'x' / 'y' to read one axis, or pass a { x, y } (with no value) to write both

value

the relative coordinate to write, when dim names an axis

Also spelled eles.relativePoint.

Returns

the position or coordinate when reading, this when writing

eles.renderedPosition

Get or set the first element's position in rendered (CSS px) space — position() put through the current pan and zoom. Writing unprojects back to model space, so the element lands under the given screen point at the current viewport.

dim

'x'/'y', or a { x, y } object to write both; omit to read the pair

value

the new coordinate, with the 'x'/'y' form

Also spelled eles.renderedPoint.

Returns

the rendered position when reading, this collection when writing

eles.width

The first element's width — a node's model-space width, or an edge's stroke width.

For a compound parent this is the content width, with the padding subtracted from the stored drawn box (v3's autoWidth). Mid-tween this reads the exact current value: geometry tweens are CPU-canonical every tick and never leased to the GPU (round 25), so unlike a position tween there is no staleness window.

Returns

the width, or undefined when empty or removed

See

Collection#outerWidth to include the border

eles.height

The first element's height — a node's model-space height, or an edge's stroke width (as in v3, where an edge's height is its width).

For a compound parent this is the content height: the column stores the padded drawn box, so the padding is subtracted here (v3's autoHeight). Mid-tween this reads the exact current value: geometry tweens are CPU-canonical every tick and never leased to the GPU (round 25).

Returns

the height, or undefined when empty or removed

eles.data

data() over the sidecar columns. id (and source/target on edges) are first-class and immutable — reading them works, writing them throws. Setters apply to every element in the collection and emit data per element; a write refreshes data-mapped labels. The whole-object read returns a built snapshot, not the store's internals — and the same snapshot until a data write (or a reparent/re-point) invalidates it, so mutating it never corrupts the store but is visible to the mutator until the next write (v3 hands out its live internal object here, where mutation corrupts the actual store — v4's exposure is strictly narrower).

Typed (round 140) when the instance was made with cytoscape<NodeData, EdgeData>( … ): a key must name a field of the collection's shape (or a first-class one), the read answers that field's type, and a write takes it. A mixed collection's shape is the union, whose keys are the fields the two share. Untyped, every form keeps its pre-140 type — any key, an unknown read.

With no argument, reads the first element's whole object.

Read a first-class field of the first element (see the whole-object form): 'id', 'source'/'target' on an edge, 'parent' on a child node.

key

the first-class field to read

Read one data key of the first element (see the whole-object form).

key

the key to read; typed, one of the collection's fields (a mixed collection's common fields — narrow it with nodes() or edges() to read the rest)

Write one data key on every element (see the whole-object form).

key

the key to write

value

the value; an explicit undefined clears the key

Merge keys into every element's data (see the whole-object form).

patch

the keys to write

Also spelled eles.attr.

Returns

the first element's data — the collection's shape when typed — or undefined when the collection is empty

Throws
  • when key is 'id', or 'source'/'target' on an edge — first-class fields are immutable (typed, not a key it accepts)

  • when the patch names 'id', or 'source'/'target' on an edge — first-class fields are immutable

eles.removeData

Remove sidecar data keys.

names

space-separated key names; omit to clear every key

Also spelled eles.removeAttr.

Returns

this collection, for chaining

eles.scratch

Per-element scratchpad (plain JS, not a column): scratch() reads the first element's whole object, scratch(ns) one namespace, scratch(ns, val) / scratch(obj) write to every element.

args

the form to take: nothing (read the whole object), a namespace (read it), a namespace and a value (write it to every element), or one object (merge its keys into every element)

Returns

the reader forms answer the first element — the whole scratch object under no argument, one namespace's value under scratch(ns), undefined when the collection is empty — while the writer forms return this collection for chaining

eles.removeScratch

Delete scratchpad keys from every element.

namespace

the key to remove; omit to clear each element's whole scratchpad

Returns

this collection, for chaining

Style (read-only) Collection

eles.style

Resolved style read off the stored channels — all of the first element's group props.

Resolved style read off the stored channels — one value. A bypassed prop reads its bypass value, since a bypass writes stored truth (round 63).

name

the property to read, dash-case or camelCase

Set a per-element style bypass on every element (round 63.4 — the v3 spelling, returned). Sugar over the stylesheet's bypasses section: the value must be a constant (mappers belong in the sheet's group blocks), the entry is keyed by the element's id and survives remove/re-add, it beats every sheet rule including the default sheet's selection color, and it exports from cy.json().

name

the property to bypass, dash-case or camelCase

value

the constant value to pin

Set several per-element style bypasses on every element (round 63.4). The object form of the setter: each key–value pair joins the element's bypass declaration.

props

prop → constant value, dash-case or camelCase keys

Also spelled eles.css.

Returns

the whole group's props (numbers for numeric props, rgb()/rgba() strings for colors, keywords otherwise), or undefined when the collection is empty

Throws
  • on a mapper value, a global font prop, a transition config prop, a wrong-group prop, or an invalid value

  • as the name/value form does, per prop

eles.removeStyle

Remove per-element style bypasses from every element (round 63.4 — v3's removeStyle). The sheet-resolved values return through the normal apply, transitions included.

name

the property to un-bypass, dash-case or camelCase; omit to clear each element's whole bypass declaration

Also spelled eles.removeCss.

Returns

this collection, for chaining

eles.renderedStyle

Like style(), but with length props (width, height, border-width, font-size) scaled into rendered (on-screen) px by the zoom.

name

a property name; omit for the whole group

Also spelled eles.renderedCss.

Returns

the rendered-space value, or the whole group's props

eles.numericStyle

The numeric value of a numeric style prop.

name

a numeric style property

Returns

the number, or undefined when the collection is empty or the prop belongs to the other group

Throws

if the prop resolves to a colour or a keyword rather than a number

eles.effectiveOpacity

The rendered opacity: a node's own opacity times its ancestors' (v3's product rule — the store keeps the folded value in the column, round 14.4); an edge's own opacity (edges have no parent).

Returns

the opacity actually rendered, which is what transparent() tests against 0 — not the declared opacity style value, which style('opacity') reads; undefined when empty or removed

eles.transparent

Whether the first element is fully transparent — its effective opacity, with compound ancestors folded in, is exactly 0.

Returns

true when invisible through opacity

eles.takesUpSpace

The space tier (round 22): shown elements occupy space — they join bb/fit and size their compound parents — even when visibility: 'hidden' keeps them from rendering. display-tier hide() clears it.

Public in v4 by decision (round 90) — v3 kept its counterpart internal.

Returns

whether the element occupies space — since round 22 this can differ from visible(), which is the paint tier

eles.interactive

Whether the element can be interacted with: visible and not pointer-transparent (events: 'no' — round 20.2).

Public in v4 by decision (round 90) — v3 kept its counterpart internal.

Returns

whether any pointer path will resolve to this element; it rides visible(), so an element hidden either way is inert

eles.label

The node's resolved label text ('' when none); read-only in the prototype.

Returns

the resolved text of the first element's label — '' when it has none (a labelled-but-empty label reads the same), and undefined when the collection is empty or the element was removed

eles.padding

v3-parity accessor: node padding. Leaves have no padding in v4 (no compound-free padding prop); parents answer the resolved auto-bounds padding (round 14.3).

Public in v4 by decision (round 90) — v3 kept its counterpart internal.

Returns

the resolved padding in model px — 0 for leaves and for any graph with no compounds at all, the derived value for a parent; undefined when the collection is empty

eles.paddedWidth

The drawn box: core dims + 2 x padding (v3's paddedWidth).

Public in v4 by decision (round 90) — v3 kept its counterpart internal.

Returns

the padded width — identical to width() for leaves, which have no padding; undefined when empty or removed

eles.paddedHeight

The drawn box height: content height plus twice the padding (v3's paddedHeight). Identical to height() for leaves, which have no padding.

Public in v4 by decision (round 90) — v3 kept its counterpart internal.

Returns

the padded height, or undefined when empty or removed

eles.outerWidth

The full drawn width including the border — padded width plus the border width. This is the box bounds and endpoint clipping use.

Returns

the outer width, or undefined when empty or removed

eles.outerHeight

The full drawn height including the border.

Returns

the outer height, or undefined when empty or removed

eles.boundingBox

The model-space box enclosing every element of the collection.

Labels are included by default (round 16.4) — v3 excluded them unless asked. Node label terms are exact (the laid text block at its anchor plus text-box padding); edge label terms are conservative (a rotation-safe radius about both endpoints), so a box may be slightly larger than the ink but never smaller. The box also covers ghost offsets, overlay/underlay padding and outlines.

options

{ includeLabels } (default true)

Returns

{ x1, y1, x2, y2, w, h } in model coordinates

Throws

on an unknown option key — a typo must not silently change fit semantics

See

Collection#labelBoundingBox for the label box alone

eles.labelBoundingBox

The exact laid label boxes of this collection's elements, unioned (round 16.4 — the v4 form of v3's text-metrics surface): node labels at their anchors, edge mid-labels at the drawn midpoint, end labels conservatively about their endpoint. Empty (zero) when nothing is labelled. Headless dims are estimates (recorded).

eles.renderedBoundingBox

boundingBox() transformed into rendered (on-screen) coordinates.

options

as boundingBox(): { includeLabels }, default true; an unknown key throws

Also spelled eles.renderedBoundingbox.

Returns

the rendered-space box

eles.renderedWidth

width() scaled by the current zoom — the on-screen width in CSS px.

Returns

the rendered width, or undefined when empty or removed

eles.renderedHeight

height() scaled by the current zoom.

Returns

the rendered height, or undefined when empty or removed

eles.renderedOuterWidth

outerWidth() scaled by the current zoom.

Returns

the rendered outer width, or undefined when empty or removed

eles.renderedOuterHeight

outerHeight() scaled by the current zoom.

Returns

the rendered outer height, or undefined when empty or removed

eles.midpoint

Midpoint of the edge: the curve/route midpoint for curved edges (v3's rs.mid rules per family), the endpoint-center average for straight ones.

Returns

the point a mid-label and a mid-arrow anchor at, in model space; undefined for non-edges. Mid-tween it inherits the position lease's staleness, like the endpoints it derives from

eles.renderedMidpoint

midpoint() in rendered (CSS px) space.

Returns

the rendered midpoint, or undefined for non-edges

eles.sourceEndpoint

The edge's source-side endpoint in model space, resolved through the route evaluator — so it accounts for curve family, node boundary clipping, haystack offsets and any manual source-endpoint.

A straight edge answers the node boundary along the chord between the node centres, pulled back by the arrow shape's spacing (round 55 landed the boundary, round 56 the spacing) — v3's rs.arrowStartX/Y. That is the arrow point, not the drawn line's end: the line stops gap behind the boundary, further back again, which is what makes a hollow head read as one shape.

Returns

the endpoint, or undefined for non-edges

eles.targetEndpoint

The edge's target-side endpoint in model space, resolved through the route evaluator — so it accounts for curve family, node boundary clipping, haystack offsets and any manual target-endpoint.

A straight edge answers the node boundary along the chord between the node centres, pulled back by the arrow shape's spacing (round 55 landed the boundary, round 56 the spacing) — v3's rs.arrowStartX/Y. That is the arrow point, not the drawn line's end: the line stops gap behind the boundary, further back again, which is what makes a hollow head read as one shape.

Returns

the endpoint, or undefined for non-edges

eles.renderedSourceEndpoint

sourceEndpoint() in rendered (CSS px) space.

Returns

the rendered endpoint, or undefined for non-edges

eles.renderedTargetEndpoint

targetEndpoint() in rendered (CSS px) space.

Returns

the rendered endpoint, or undefined for non-edges

eles.controlPoints

The edge's curve control points (model coords): one for a bundled bezier, two for a self-loop, the control list for an unbundled bezier, undefined otherwise — v3's getControlPoints surface (segments/taxi answer segmentPoints() instead).

Returns

the control points in model space, or undefined when the edge has none — which covers straight edges, segments/taxi routes, and a straight edge carrying manual endpoints (the 12c n = 0 chord)

eles.renderedControlPoints

controlPoints() in rendered (CSS px) space.

Returns

the rendered control points, or undefined when the edge has none

eles.segmentPoints

The edge's segment points (model coords) — v3's getSegmentPoints: defined for segments and taxi edges (taxi derives its points), undefined otherwise.

Returns

the interior route points in model space — derived ones for taxi, which computes rather than declares them — or undefined for every other family

eles.renderedSegmentPoints

segmentPoints() in rendered (CSS px) space.

Returns

the rendered segment points, or undefined when the edge has none

Selection Collection

eles.selected

Whether the first element is selected.

Returns

true when selected

eles.selectable

Whether the first element may be selected by the user. The graph-wide cy.autounselectify() overrides this for user gestures.

Returns

true when selectable

eles.select

Select every selectable element, emitting select for each one that changed. Unselectable elements are skipped.

Returns

this collection, for chaining

eles.unselect

Deselect every element, emitting unselect for each one that changed.

Also spelled eles.deselect.

Returns

this collection, for chaining

eles.selectify

Make these elements selectable.

Returns

this collection, for chaining

eles.unselectify

Make these elements unselectable. Does not deselect them; call unselect() for that.

Returns

this collection, for chaining

Grab / lock Collection

eles.grabbable

Pannable elements are not draggable, so pannable overrides grabbable (as in v3).

Returns

whether a drag gesture would move this element — the effective answer, so a grabbable-but-pannable element reads false here while json() reports the raw field

eles.grabbed

Whether the first element is currently held by a drag gesture.

Returns

true while grabbed

eles.grabify

Make these elements grabbable.

Returns

this collection, for chaining

eles.ungrabify

Make these elements ungrabbable — the user can no longer drag them, while programmatic position writes still apply.

Returns

this collection, for chaining

Visibility Collection

eles.visible

Whether the first element renders (round 22: the derived FLAG_DRAWN — shown AND not visibility: 'hidden' on self or, for nodes, any ancestor; edges additionally fold their endpoints, v3's rule). The renderer's cull pass and CPU picking mask on the same bit, so an element that is not visible() neither draws nor picks. For space-tier state (in the bb, sizing its compound parent) see takesUpSpace() — an invisible element keeps its space.

Returns

whether the element draws and picks; false for a removed element, for an edge either of whose endpoints is hidden, and for a node under a hidden or invisible ancestor

eles.hidden

The complement of visible().

Returns

true when the first element does not draw

eles.show

Show these elements — the display tier, v3's structural display: element. Shown elements take up space again, rejoin bounds and fit, and re-fan their bezier bundles.

For paint-only invisibility that keeps space and bundle ranks, use the visibility style property instead (round 22), and for a fade use an opacity transition.

Public in v4 by decision (round 90) — v3 kept its counterpart internal.

Returns

this collection, for chaining

eles.hide

Hide these elements structurally — v3's display: none. They stop drawing and picking, leave the bounding box and their ancestors' auto-bounds, and their bezier bundles re-fan without them. Descendants of a hidden node are gated too.

Public in v4 by decision (round 90) — v3 kept its counterpart internal.

Returns

this collection, for chaining

eles.locked

Whether the first element is locked — immovable, by layouts, position writes and position tweens alike (one rule since round 114.3: every layout holds a locked node where it is and keeps it in the layout's structure; force treats it as an obstacle its settle separates the others from). A locked child stays where it is when its compound parent is positioned, shifted or dragged — its own subtree with it — and the parent re-derives about the stayers and the movers (116.3, v3's rule). True for every node while cy.autolock( true ) is set, as in v3; the flag column alone is what { locked: true } filters read.

Returns

true when locked

eles.lock

Lock these elements against movement. A node locked mid-tween holds where its position tween got to (round 144, as v3's animation step skips a locked node); the rest of the animation — other nodes, and this node's paint channels — runs on, and unlocking does not resume it.

Returns

this collection, for chaining

eles.unlock

Unlock these elements.

Returns

this collection, for chaining

Active / pannable Collection

eles.active

Whether the first element is in the transient pressed ("active") state.

Returns

the pressed flag the pointer layer sets while a press is held — transient interaction state, not a persisted property

eles.pannable

Whether dragging the first element pans the graph instead of grabbing it.

Returns

the raw pannable flag; because pannable overrides grabbable, a true here forces grabbable() false

eles.panify

Make dragging these elements pan the viewport instead of moving them. Pannable overrides grabbable, as in v3.

Returns

this collection, for chaining

eles.unpanify

Stop these elements from panning the viewport when dragged, so a grabbable one becomes draggable again.

Returns

this collection, for chaining

Emphasis Collection

eles.emphasized

Whether the first element is in the current emphasis — the set the last cy.emphasize( eles ) named.

Returns

the element's emphasized flag; false for a removed element and while no emphasis is set. An element outside a set emphasis is the one the renderer dims — derived, so there is no dimmed()

Graph manipulation Collection

eles.remove

Remove these elements from the graph; incident edges of removed nodes cascade. Already-removed elements are skipped (no second remove event).

Returns

the elements actually removed — the closure, so it can be larger than the receiver: removing a parent brings its descendants, and removing a node brings its incident edges. The returned refs are dead by construction (v4 removals are terminal), so only their cached id()/group() still read

eles.move

Move elements in place, keeping slot, id and data: { parent } re-parents nodes (null orphans them; the compound move, round 14.2 — emits moveout before and move after per changed node), while { source, target } re-points edges. As in v3 the modes are exclusive — a parent key takes precedence. An unknown parent id is a silent no-op (v3); a cyclic assignment warns and drops (the hierarchy rule).

opts

{ parent } to re-parent nodes (null orphans them), or { source, target } to re-point edges; parent wins if both are given

Returns

this collection, for chaining

Traversal Collection

eles.source

The source node of the first edge.

Returns

the source node, or an empty collection for a non-edge

eles.target

The target node of the first edge.

Returns

the target node, or an empty collection for a non-edge

eles.sources

The source nodes of every edge in the collection, deduped.

Returns

the source nodes

eles.targets

The target nodes of every edge in the collection, deduped.

Returns

the target nodes

eles.connectedEdges

Every edge incident on the nodes in this collection, deduped — answered off the CSR adjacency index, so it is O(incident edges) rather than a scan. Loops appear once.

criterion

an optional query object or predicate to filter the result

Returns

the incident edges

eles.connectedNodes

The endpoint nodes of every edge in this collection, deduped.

criterion

an optional query object or predicate to filter the result

Returns

the endpoint nodes

eles.outgoers

The immediate outgoing neighbourhood: the edges leaving these nodes plus the nodes they point at. One hop only — use successors() for the transitive closure.

criterion

an optional query object or predicate to filter the result

Returns

the outgoing edges and their target nodes

eles.incomers

The immediate incoming neighbourhood: the edges arriving at these nodes plus the nodes they come from. One hop only — use predecessors() for the transitive closure.

criterion

an optional query object or predicate to filter the result

Returns

the incoming edges and their source nodes

eles.neighborhood

The open neighbourhood: the incident edges and the nodes on their far ends, ignoring edge direction, excluding the collection's own elements.

criterion

an optional query object or predicate to filter the result

Also spelled eles.openNeighborhood.

Returns

the neighbouring edges and nodes

See

Collection#closedNeighborhood to include these nodes

eles.closedNeighborhood

The open neighbourhood plus this collection's own nodes.

criterion

an optional query object or predicate to filter the result

Returns

the closed neighbourhood

Compound hierarchy Collection

eles.parent

Immediate parents of every node in the collection (unique). v4 always returns a proper collection — v3's single-element raw-ref shortcut (which also ignored the selector argument) is not ported. *

criterion

an optional query object or predicate applied to the result, exactly as filter() takes it

Returns

the immediate parents

eles.parents

All ancestors, level by level: every nearest parent first, then the grandparents, and so on (v3's iterated-parent() order). *

criterion

an optional query object or predicate applied to the result, exactly as filter() takes it

Also spelled eles.ancestors.

Returns

the ancestors, nearest first

eles.children

Direct children of every node, in link order per parent. *

criterion

an optional query object or predicate applied to the result, exactly as filter() takes it

Returns

the children

eles.descendants

The subtree below every node in pre-order, excluding the nodes themselves. *

criterion

an optional query object or predicate applied to the result, exactly as filter() takes it

Returns

the descendants

eles.collapse

Scale each compound parent’s descendants into a miniature around the parent’s current centre. Pass { duration, easing } to animate the scale; without options, the operation is immediate. The original nodes, edges and explicit visibility state remain unchanged.

timing

optional animation duration and easing

Returns

this collection, for chaining

eles.expand

Restore each collapsed compound parent’s descendants by reversing its currently applied scale around the parent’s current centre. Pass { duration, easing } to animate the restoration; without options, the operation is immediate.

timing

optional animation duration and easing

Returns

this collection, for chaining

eles.siblings

Nodes sharing a parent with the collection's nodes, excluding them; orphans are nobody's siblings (v3). *

criterion

an optional query object or predicate applied to the result, exactly as filter() takes it

Returns

the siblings

eles.orphans

The collection's nodes without a parent. *

criterion

an optional query object or predicate applied to the result, exactly as filter() takes it

Returns

the parentless nodes

eles.nonorphans

The collection's nodes that have a parent. *

criterion

an optional query object or predicate applied to the result, exactly as filter() takes it

Returns

the parented nodes

eles.commonAncestors

Ancestors common to every element, closest first (an edge in the collection has no ancestors, so it empties the result — v3). *

criterion

an optional query object or predicate applied to the result, exactly as filter() takes it

Returns

the shared ancestors, closest first

eles.isParent

Whether the first element is a node with at least one child.

Returns

v3's :parent as a predicate; false for edges and for removed elements, which are nodes of no hierarchy

eles.isChildless

Whether the first element is a node with no children.

Returns

v3's :childless; false for edges, so it is not the plain negation of isParent()

eles.isChild

Whether the first element is a node with a parent.

Returns

v3's :child; false for edges and removed elements

eles.collapsed

Whether the first live node is a collapsed compound parent.

Returns

true from collapse start until expansion completes; false for leaves, edges and removed elements

eles.insideCollapsed

Whether the first live node has a collapsed strict ancestor. The collapsed parent itself answers false.

Returns

true when the node is a descendant of a collapsed parent

eles.isOrphan

Whether the first element is a node without a parent.

Returns

v3's :orphan; false for edges, so it is not the plain negation of isChild()

DAG traversal Collection

eles.roots

Collection nodes with no non-loop incoming edge (whole-graph incidence, as in v3). *

criterion

an optional query object or predicate applied to the result, exactly as filter() takes it

Returns

the source nodes

eles.leaves

Collection nodes with no non-loop outgoing edge. *

criterion

an optional query object or predicate applied to the result, exactly as filter() takes it

Returns

the sink nodes

eles.successors

Everything reachable by following outgoing edges, transitively — the edges and nodes of the forward closure, excluding these nodes themselves (unless a cycle reaches them).

criterion

an optional query object or predicate to filter the result

Returns

the reachable edges and nodes

eles.predecessors

Everything that reaches these nodes by following incoming edges, transitively.

criterion

an optional query object or predicate to filter the result

Returns

the edges and nodes of the backward closure

Edge relations Collection

eles.edgesWith

The edges connecting this collection's nodes with others, in either direction.

others

the nodes on the far side (a collection, never a selector string)

Returns

the connecting edges

eles.edgesTo

The edges running from this collection's nodes to others — edgesWith() restricted by direction.

others

the target-side nodes

Returns

the directed connecting edges

eles.parallelEdges

The edges sharing endpoints with these edges, in either direction — including each edge itself. These are the edges a bezier bundle fans apart.

criterion

an optional query object or predicate to filter the result

Returns

the parallel edges

eles.codirectedEdges

The parallel edges pointing the same way — same source and same target — including each edge itself.

criterion

an optional query object or predicate to filter the result

Returns

the codirected edges

Connected components Collection

eles.components

Connected components within this collection (undirected), each as a collection of the reached nodes plus the collection's edges internal to that component.

root

restricts the seed nodes; omit to seed from every node

Also spelled eles.componentsOf.

Returns

one collection per component

eles.component

The whole-graph connected component containing the first element.

Returns

the component as nodes and their connecting edges, computed over the whole graph rather than within this collection; an empty collection when this one is empty

Layouts Collection

eles.layoutDimensions

Node dimensions for layout spacing, as v3's layoutDimensions — the body, plus the label box under nodeDimensionsIncludeLabels: true (114.1 made labels the default; 115 restored v3's body-only default).

options

{ nodeDimensionsIncludeLabels: true } to include the label box

Returns

the first element's { w, h }

eles.layoutPositions

Apply a layout's position function to this collection's nodes with the standard layout options (spacingFactor, transform, fit/zoom/pan, animate) and the layoutstart/layoutready/layoutstop event flow — v3's helper. With animate: true the viewport animates concurrently (a fit targets the bounding box at the final positions, as v3 does).

layout

the layout instance the lifecycle events carry as event.layout; it is not called back, only reported

options

the standard layout options (spacingFactor, transform, fit/padding, zoom/pan, animate, animationDuration, animateFilter)

fn

( node, i ) => position, evaluated once per positioned node; parents are excluded (auto-bounds derive them)

Returns

this collection, for chaining

eles.layout

A layout scoped to this collection.

options

the layout options, as cy.layout(); eles is set to this collection

Also spelled eles.makeLayout, eles.createLayout.

Returns

the layout instance; nothing runs until run()

Graph algorithms Collection

eles.breadthFirstSearch

Breadth-first search over this collection's subgraph. Roots are visited in breadth-first order. Multiple callback roots are visited in reverse input order because the initial queue prepends each root; with no roots, the result is empty.

args

{ roots, visit, directed } (or singular root) or the positional form. Roots must be node collections; selector strings are not supported. visit receives (node, edge, previous, index, depth); index counts callback calls and depth is the number of discovery edges from a root. The edge and previous node are undefined at a root. Return true to stop and set found to the current node, false to stop without a match, or nothing to continue. directed: true follows outgoing edges.

Also spelled eles.bfs.

Returns

{ path, found }: path records roots in input order and discoveries in breadth-first insertion order, with each discovery edge before its node. It can include nodes queued but not visited when the callback stops early. found is the matched node or an empty collection when no callback returned true.

Throws

if a root is given as a selector string

eles.depthFirstSearch

Depth-first search over this collection's subgraph. It shares the root, callback, direction and result contract of breadthFirstSearch, but explores the most recently discovered branch first.

args

{ roots, visit, directed } (or singular root) or the positional form. The callback receives (node, edge, previous, index, depth), where index counts callbacks and depth counts discovery edges from a root. It may return true to stop with a match, false to stop without a match, or nothing to continue. Roots must be node collections.

Also spelled eles.dfs.

Returns

{ path, found }; path contains visited nodes and their discovery edges in depth-first callback order

Throws

if a root is given as a selector string

eles.dijkstra

Compute single-source shortest paths from a root over this collection's subgraph using Dijkstra's algorithm. The caller is responsible for using non-negative edge weights; v4 does not validate the weight function's mathematical properties.

args

{ root, weight, directed } or the positional form. The root must be a node in this collection. weight(edge) returns a number and defaults to 1; directed: true follows outgoing edges only.

Returns

{ distanceTo, pathTo }; an unreachable node has infinite distance and its pathTo() collection contains that node alone. A node outside this subgraph has undefined distance and an empty path.

Throws

if root is missing or is not a node in this collection

eles.aStar

Find an A* path between two nodes in this collection's subgraph. The heuristic defaults to zero, reducing the search to Dijkstra's ordering. The search closes nodes without reopening them; shortest-path guarantees require non-negative costs and a consistent heuristic. v4 does not validate those mathematical properties.

options

{ root, goal, weight, heuristic, directed }. Root and goal must belong to this collection; weight(edge) defaults to 1, heuristic(node) defaults to 0, and directed: true follows outgoing edges only.

Returns

{ found, distance, path, steps }; when no path exists, found is false and distance and path are undefined

Throws

if root or goal is missing or outside this collection

eles.bellmanFord

Compute single-source shortest paths with Bellman–Ford. Unlike dijkstra(), this algorithm supports negative edge weights and reports reachable negative-weight cycles. Undirected, every edge is both arcs, so a negative edge reachable from the root is itself a negative cycle (v3 never relaxed back over the edge that reached a node, and missed it).

options

{ root, weight, directed, findNegativeWeightCycles }. The root must belong to this collection; weight(edge) defaults to 1 and directed: true follows outgoing edges only. Set findNegativeWeightCycles: false to stop after detecting a cycle without constructing cycle collections.

Returns

distance and path accessors, hasNegativeWeightCycle, and negativeWeightCycles (collections describing detected cycles); unreachable nodes have infinite distance and an empty path

Throws

if root is missing or does not contain a node

eles.floydWarshall

Floyd–Warshall all-pairs shortest paths. O(n³) — for a single source prefer dijkstra/bellmanFord. Async (round 65): the expensive whole-graph tier returns promises, and executor ('cpu' | 'gpu' | 'auto', default 'auto'; 'workers' runs the reference on one pool worker, round 129.1) picks where the maths runs; 'cpu' is the reproducible reference.

options

{ weight, directed, executor }

Returns

a promise of the { distance, path } accessors — with cancel() on it (round 128): a pending run rejects with CancelledError, a 'cpu' run has already completed

Throws

if executor is invalid; rejects if executor: 'gpu' is unavailable in this environment

eles.kruskal

Build a minimum spanning forest of this collection, treating its edges as undirected. Equal-weight edges retain collection order. Disconnected input produces one tree per connected component.

weight

(edge) => number; defaults to unit weights

Returns

a collection containing all input nodes and the accepted forest edges, in acceptance order

eles.tarjanStronglyConnected

Partition this collection's directed subgraph into strongly connected components. Traversal follows edge direction; self-loops do not join otherwise separate nodes. The implementation is iterative, so deep graphs do not consume the JavaScript call stack.

Also spelled eles.tsc, eles.tscc, eles.tarjanStronglyConnectedComponents.

Returns

{ components, cut }: each component collection contains its nodes and internal edges; cut contains edges between components

eles.hopcroftTarjanBiconnected

Find undirected biconnected components and articulation points in this collection's subgraph. The component partition follows the v4 port's parent-edge rule: all edges back to the DFS parent are skipped, including parallel edges.

Also spelled eles.htbc, eles.htb, eles.hopcroftTarjanBiconnectedComponents.

Returns

{ components, cut }: each component is a collection of its nodes and edges, and cut contains articulation-point nodes. Each component also absorbs subgraph edges incident to its non-cut nodes, as this implementation defines its component sets.

eles.hierholzer

Find an Eulerian trail or circuit over this collection's edges. The directed mode checks directed degree balance; the default treats edges as undirected. A requested root must be a valid starting node for the trail.

args

{ root, directed } or the positional form

Returns

{ found, trail }; trail is undefined when no trail exists. Collections are sets, so a node visited more than once appears only once in the trail collection.

Throws

if a supplied root is a selector string

eles.kargerStein

Estimate an undirected global minimum cut with the randomized Karger–Stein contraction algorithm. Connected input is required for its guarantee. Random choices mean repeated runs may produce different partitions; the minimum-cut result is probabilistic.

Returns

{ cut, components, partition1, partition2 }; cut contains crossing edges and the two partitions contain the corresponding nodes

Throws

if fewer than two nodes are present or a contraction reaches a graph with no edges

eles.pageRank

PageRank over the subgraph. Undirected by default since round 150 — each edge is walked both ways, as NetworkX and igraph do — and directed: true follows source → target only, v3's sole behaviour. Async (round 65): returns a promise, and executor ('cpu' | 'gpu' | 'auto', default 'auto'; 'workers' runs the reference on one pool worker, round 129.1) picks where the power method runs; 'cpu' is the reproducible reference.

options

{ dampingFactor, precision, iterations, weight, directed, executor }; dampingFactor is the textbook α in (0, 1], default 0.85 (v3's d was α = 1/(2 − d), default 0.8)

Returns

a promise of { rank }, a per-node accessor — with cancel() on it (round 128): a pending run rejects with CancelledError, a 'cpu' run has already completed

Throws

if executor or dampingFactor is invalid; rejects if executor: 'gpu' is unavailable in this environment

eles.degreeCentrality

Compute Opsahl's generalized degree for one node in this collection. alpha interpolates between counting edges (0) and summing their weights (1); intermediate values combine both. Directed results separate incoming and outgoing degree.

options

{ root, weight, alpha, directed }; root is required, weight(edge) defaults to 1, alpha defaults to 0, and directed defaults to false

Also spelled eles.dc.

Returns

{ degree }, or { indegree, outdegree } when directed

Throws

if root is missing or does not contain a node

eles.degreeCentralityNormalized

Compute each node's Opsahl generalized degree and normalize against the maximum in this collection (default) or, under normalization: 'size', against n − 1 — NetworkX's degree_centrality and igraph's normalized = TRUE (round 150; a lone node scores 1, as in NetworkX). Directed in- and out-degree are normalized independently. Nodes outside the collection's captured subgraph read as zero.

options

{ weight, alpha, directed, normalization }; the shared option type also allows root, which this all-node method ignores. weight(edge) defaults to 1, alpha defaults to 0, directed defaults to false and normalization to 'max'

Also spelled eles.dcn, eles.degreeCentralityNormalised.

Returns

a degree(node) accessor, or indegree(node) and outdegree(node) accessors when directed. Each divides by its corresponding maximum or by n − 1; under 'max' results are in [0, 1] when weights and alpha produce nonnegative finite degrees. These numeric constraints are not validated.

Throws

if normalization is neither 'max' nor 'size'

eles.closenessCentrality

Closeness centrality of one node — how near it is, by shortest path, to the rest of the collection. Harmonic (default): Σ 1/d, an unreachable node contributing 0. harmonic: false: the classic (n − 1)/Σd, and over r reachable nodes the Wasserman–Faust (r/Σd)·(r/(n − 1)) — NetworkX's definition (round 150; v3's 1/Σd was n − 1 times smaller, and 0 once any node was unreachable). Directed runs sum distances from the node (direction: 'out', default, as R igraph and graph-tool) or to it ('in', as NetworkX and Neo4j GDS).

options

{ root, weight, directed, direction, harmonic }

Also spelled eles.cc.

Returns

the closeness score

Throws

if root is not a node of the collection, or direction is neither 'out' nor 'in'

eles.closenessCentralityNormalized

Closeness centrality for every node, normalized to [0, 1]. Async (round 69): the whole-collection form is the all-pairs tier, so like floydWarshall it returns a promise and executor ('cpu' | 'gpu' | 'workers' | 'auto', default 'auto') picks where it runs; 'cpu' is the reproducible reference. Unweighted runs walk a BFS per source, O(n·(n+E)) (round 72.3) — on the worker pool too (round 74: one source range per worker, bit-identical to 'cpu'; under 'auto' a sparse graph takes the pool first from 512 nodes, since it measured ahead of the GPU's batched BFS at every size, and a dense one the GPU first); weighted runs relax Floyd–Warshall, O(n³), and take the offload lane (round 129.1: one pool worker). The single-root closenessCentrality stays synchronous.

Each score is closenessCentrality's for that node (the same harmonic and direction), divided by the largest.

normalization: 'size' divides a harmonic score by n − 1 instead, igraph's and graph-tool's normalized harmonic centrality, and leaves a classic score, which already carries n − 1, as is (round 150).

options

{ weight, directed, direction, harmonic, normalization, executor }

Also spelled eles.ccn, eles.closenessCentralityNormalised.

Returns

a promise of a closeness accessor — with cancel() on it (round 128): a pending run rejects with CancelledError, a 'cpu' run has already completed

Throws

if executor, direction or normalization is invalid; rejects if executor: 'gpu' or 'workers' is unavailable in this environment, or 'workers' is asked of a weighted run

eles.betweennessCentrality

Betweenness centrality — how often each node lies on shortest paths between other pairs: the sum over pairs s ≠ v ≠ t of the share of shortest s–t paths through v, each unordered pair counted once when undirected (Freeman's definition, NetworkX's and igraph's unnormalized score; v3 counted it twice — round 150, #3543). betweennessNormalized divides by the largest score. Async (round 65): returns a promise, and executor ('cpu' | 'gpu' | 'workers' | 'auto', default 'auto') picks where the Brandes sweep runs. Weighted runs have no GPU path: 'auto' takes the worker pool (round 74 — one source range per worker, f64-tight to 'cpu' and bit-stable across pool sizes) from 128 nodes and an explicit 'gpu' rejects; unweighted runs keep the GPU first under 'auto', then the pool from 256 nodes where no adapter fits.

betweennessNormalized divides by the largest score, or under normalization: 'size' by the pairs a node can sit between — (n − 1)(n − 2)/2 undirected, (n − 1)(n − 2) directed — as NetworkX's normalized=True and igraph's normalized = TRUE (round 150).

options

{ weight, directed, normalization, executor }

Also spelled eles.bc.

Returns

a promise of the { betweenness, betweennessNormalized } accessors — with cancel() on it (round 128): a pending run rejects with CancelledError, a 'cpu' run has already completed

Throws

if executor or normalization is invalid; rejects if executor: 'gpu' is unavailable or the run is weighted

eles.katzCentrality

Katz centrality — attenuated walk counting, where a node is central when many short walks end at it and a walk of length k is worth alphaᵏ. Async (round 69): returns a promise, and executor ('cpu' | 'gpu' | 'auto', default 'auto'; 'workers' runs the reference on one pool worker, round 129.1) picks where the iteration runs; like pageRank, 'auto' always uses the sparse CPU iteration and the GPU path serves an explicit 'gpu'. v4-only — v3 has no counterpart. katzNormalized divides by the largest score, or by the scores' Euclidean norm under normalization: 'l2' — NetworkX's normalized=True (round 150).

options

{ alpha, beta, maxIterations, tolerance, directed, weight, normalization, executor }

Returns

a promise of the { katz, katzNormalized } accessors — with cancel() on it (round 128): a pending run rejects with CancelledError, a 'cpu' run has already completed

Throws

if executor, alpha, beta or normalization is invalid; rejects if executor: 'gpu' is unavailable in this environment

eles.triangleCount

Triangle counting: per-node triangle counts, local clustering coefficients, and the collection's transitivity, read over the simple undirected graph (direction ignored, parallel edges collapsed, loops excluded). Async (round 69): returns a promise, and executor ('cpu' | 'gpu' | 'auto', default 'auto'; 'workers' runs the reference on one pool worker, round 129.1) picks where the counting runs — under 'auto' the GPU's A²∘A matmul is used only on graphs dense enough to beat the CPU's sparse walk (a mean degree of 64, round 72.6). v4-only — v3 has no counterpart.

options

{ executor }

Returns

a promise of { triangles, clusteringCoefficient, totalTriangles, transitivity } — with cancel() on it (round 128): a pending run rejects with CancelledError, a 'cpu' run has already completed

Throws

if executor is invalid; rejects if executor: 'gpu' is unavailable in this environment

eles.neighborhoodSimilarity

Neighborhood similarity — pairwise Jaccard, cosine or overlap coefficients over neighbor sets (deduped; loops excluded; directed: true compares out-neighborhoods). The result is all-pairs, so it holds O(n²) counts like floydWarshall. Async (round 69): returns a promise, and executor ('cpu' | 'gpu' | 'auto', default 'auto') picks where the shared-neighbor counts are computed — under 'auto' the GPU's A·Aᵀ matmul is used only on graphs dense enough to beat the CPU's wedge walk (a mean degree of 64, round 72.6). v4-only — v3 has no counterpart.

options

{ metric, directed, executor }

Returns

a promise of the { similarity } accessor — with cancel() on it (round 128): a pending run rejects with CancelledError, a 'cpu' run has already completed

Throws

if executor or metric is invalid; rejects if executor: 'gpu' is unavailable in this environment

eles.simRank

SimRank — "two nodes are similar when their neighbors are similar", the Jeh–Widom recursive fixed point, iterated as dense products S′ = C·Q·S·Qᵀ. Async (round 70): returns a promise, and executor ('cpu' | 'gpu' | 'auto', default 'auto'; 'workers' runs the reference on one pool worker, round 129.1) picks where the iteration runs — under 'auto' the GPU from 256 nodes at any density (round 72.6 measured it ahead everywhere). The undirected default compares all neighbors; directed: true compares the classic in-neighborhoods. All-pairs (O(n²) memory). v4-only — v3 has no counterpart.

options

{ dampingFactor, maxIterations, tolerance, directed, executor }

Returns

a promise of the { similarity } accessor — with cancel() on it (round 128): a pending run rejects with CancelledError, a 'cpu' run has already completed

Throws

if executor or dampingFactor is invalid; rejects if executor: 'gpu' is unavailable in this environment

eles.randomWalkWithRestart

Random walk with restart — network propagation from a seeds collection: a walker follows edges with probability 1−c and restarts at the seeds with probability c, and the stationary distribution scores every node by proximity to the seeds. Async (round 70); the vector iteration is O(E) per step on the CPU, so there is no GPU path — an explicit executor: 'gpu' rejects and points at randomWalkWithRestartProximity. A node with no out-edges sends the walker back to the seeds (dangling: 'restart', default since round 150 — NetworkX's personalised PageRank), so scores sum to 1; dangling: 'absorb' ends the walk there instead, round 70's behaviour, and scores can sum below 1. v4-only — v3 has no counterpart.

options

{ seeds, restartProbability, maxIterations, tolerance, directed, weight, dangling, executor }

Returns

a promise of the { score } accessor — with cancel() on it (round 128): a pending run rejects with CancelledError, a 'cpu' run has already completed

Throws

if executor, restartProbability or dangling is invalid, or if seeds holds no node of the collection

eles.randomWalkWithRestartProximity

All-pairs random-walk-with-restart proximity — the full matrix S = c·(I − (1−c)·W)⁻¹, whose column s is the walk restarting at s. Async (round 70): executor ('cpu' | 'gpu' | 'workers' | 'auto', default 'auto') picks between one sparse solve per column on the CPU, the same solves spread over the worker pool (round 74 — bit-identical to 'cpu') and the dense Neumann iteration on the GPU — under 'auto' the GPU from 256 nodes at any density (round 72.6 measured it ahead everywhere), else the pool from 128. All-pairs (O(n²) memory). dangling is the seed form's: dead ends restart at the column's node by default (round 150), or absorb. v4-only — v3 has no counterpart.

options

{ restartProbability, maxIterations, tolerance, directed, weight, dangling, executor }

Returns

a promise of the { proximity } accessor — with cancel() on it (round 128): a pending run rejects with CancelledError, a 'cpu' run has already completed

Throws

if executor, restartProbability or dangling is invalid; rejects if executor: 'gpu' is unavailable in this environment

eles.heatDiffusion

Heat diffusion from a seeds collection: unit heat spread over the seeds flows along edges for time, through the kernel exp(−t·L) of the weighted Laplacian. Total heat is conserved under the default laplacian: 'combinatorial'; 'normalized' (round 72.4) diffuses over I − D^{-½}AD^{-½} instead, whose spectrum is bounded whatever the degrees — hubs neither hoard nor flood — at the price of conservation. Async (round 70); the vector form is O(E) per series term on the CPU, so there is no GPU path — an explicit executor: 'gpu' rejects and points at heatKernel. Edges are read undirected with positive weights. v4-only — v3 has no counterpart.

options

{ seeds, time, weight, laplacian, executor }

Returns

a promise of the { score } accessor — with cancel() on it (round 128): a pending run rejects with CancelledError, a 'cpu' run has already completed

Throws

if executor, time or laplacian is invalid, if seeds holds no node of the collection, or if an edge weight is not positive

eles.heatKernel

The all-pairs heat kernel exp(−t·L) — heat(from, to) is the heat at to after unit heat starts at from (symmetric). Async (round 70): executor ('cpu' | 'gpu' | 'workers' | 'auto', default 'auto') picks between per-column sparse series on the CPU, the same columns spread over the worker pool (round 74 — bit-identical to 'cpu') and the dense scaling-and-squaring chain on the GPU — under 'auto' the GPU from 256 nodes at any density (round 72.6), else the pool from 256. laplacian ('combinatorial' | 'normalized', default 'combinatorial') picks L = D − A or I − D^{-½}AD^{-½} (round 72.4). All-pairs (O(n²) memory). v4-only — v3 has no counterpart.

options

{ time, weight, laplacian, executor }

Returns

a promise of the { heat } accessor — with cancel() on it (round 128): a pending run rejects with CancelledError, a 'cpu' run has already completed

Throws

if executor, time or laplacian is invalid, or if an edge weight is not positive

eles.effectiveResistance

Effective resistance and commute time — the graph as a resistor network. Weights are conductances by default, the convention of the papers that define the weighted measure; weightAs: 'resistance' reads them as resistances, NetworkX's default (round 150). resistance(a, b) comes from the Laplacian pseudo-inverse, commuteTime(a, b) the expected round-trip steps of the random walk (component volume × resistance). Pairs in different components answer Infinity. Async (round 70): executor ('cpu' | 'gpu' | 'auto', default 'auto') picks between dense f64 elimination on the CPU and Newton–Schulz matmul iteration on the GPU; both are O(n³), so 'auto' takes the GPU on size alone. v4-only — v3 has no counterpart.

options

{ weight, weightAs, executor }

Returns

a promise of the { resistance, commuteTime } accessors — with cancel() on it (round 128): a pending run rejects with CancelledError, a 'cpu' run has already completed

Throws

if executor or weightAs is invalid; rejects if an edge weight is not positive or executor: 'gpu' is unavailable

eles.motifCensus

The triad census — every three-node subgraph classified into the sixteen Holland–Leinhardt classes ('003' … '300'; '030T' is the feed-forward loop). The counts sum to C(n, 3). Async (round 70): executor ('cpu' | 'gpu' | 'auto', default 'auto'; 'workers' runs the reference on one pool worker, round 129.1) picks between sparse wedge walks on the CPU and matmul trace products on the GPU — under 'auto' the GPU only on dense graphs (a mean degree of 64, round 72.6). directed: false reads every edge as mutual, so only 003 / 102 / 201 / 300 (empty / one-edge / path / triangle) can be non-zero. v4-only — v3 has no counterpart.

options

{ directed, executor }

Returns

a promise of { counts } — with cancel() on it (round 128): a pending run rejects with CancelledError, a 'cpu' run has already completed

Throws

if executor is invalid; rejects if executor: 'gpu' is unavailable in this environment

eles.kMeans

k-means clustering in attribute space. Like v3's clustering algorithms this works on handles and attributes accessors rather than on graph structure.

Async (round 65): returns a promise, and executor ('cpu' | 'gpu' | 'auto', default 'auto'; 'workers' runs the reference on one pool worker for a named distance, round 134) picks where the iteration runs; 'cpu' is the reproducible reference. A custom distance function is called inside the iteration, so it runs on the calling thread under 'cpu' and 'auto', and 'workers' rejects it.

options

{ k, attributes, distance, maxIterations, sensitivityThreshold, executor }, with attributes as plain functions

Returns

a promise of one collection per cluster — with cancel() on it (round 128): a pending run rejects with CancelledError, a 'cpu' run has already completed

Throws

if executor is invalid; rejects if executor: 'gpu' is unavailable in this environment, or executor: 'workers' is given a custom distance function

eles.kMedoids

k-medoids clustering — like k-means, but cluster centres are actual elements, which makes it robust to outliers. Async, with the same executor contract as kMeans.

options

as kMeans

Returns

a promise of one collection per cluster — with cancel() on it (round 128): a pending run rejects with CancelledError, a 'cpu' run has already completed

Throws

if executor is invalid; rejects if executor: 'gpu' is unavailable, if executor: 'workers' is given a custom distance function, or if k exceeds the node count

eles.fuzzyCMeans

Fuzzy c-means clustering: each element gets a degree of membership in every cluster rather than one hard assignment. Async, with the same executor contract as kMeans.

options

as kMeans, plus the fuzziness exponent

Also spelled eles.fcm.

Returns

a promise of { clusters, degreeOfMembership } — with cancel() on it (round 128): a pending run rejects with CancelledError, a 'cpu' run has already completed

Throws

if executor is invalid; rejects if executor: 'gpu' is unavailable in this environment, or executor: 'workers' is given a custom distance function

eles.hierarchicalClustering

Agglomerative hierarchical clustering. Async (round 65): returns a promise, and executor ('cpu' | 'gpu' | 'auto', default 'auto'; 'workers' runs the reference on one pool worker, round 134) picks where the distance matrix is built; the merge chain itself is sequential and runs with the reference — in-thread, or on the pool worker for a named distance and a 'min' / 'max' / 'mean' linkage. A custom distance function or a per-pair linkage consults the metric inside the run, on the calling thread, and 'workers' rejects them. Threshold mode merges every closest pair at most threshold apart, a merge at exactly threshold included, as SciPy's fcluster and R's cutree (round 150; v3 stopped there).

options

{ attributes, distance, linkage, mode, threshold, dendrogramDepth, executor }

Also spelled eles.hca.

Returns

a promise of one collection per cluster — with cancel() on it (round 128): a pending run rejects with CancelledError, a 'cpu' run has already completed

Throws

if executor is invalid; rejects if executor: 'gpu' is unavailable in this environment, or executor: 'workers' is given a custom distance function or a per-pair linkage

eles.markovClustering

Markov clustering (MCL) — flow simulation over the graph, so unlike the attribute-space algorithms this one clusters by structure.

Async (round 65): returns a promise, and executor ('cpu' | 'gpu' | 'auto', default 'auto'; 'workers' runs the reference on one pool worker, round 129.1) picks where the expand/inflate iteration runs; 'cpu' is the reproducible reference. maxIterations defaults to 100 (round 150, as Python markov_clustering and R MCL; v3's 20 could stop short of the fixed point), and pruneThreshold (default 0) drops each inflated matrix's entries under it, keeping each column's largest, as markov_clustering's pruning_threshold does.

options

{ attributes, expandFactor, inflateFactor, multFactor, maxIterations, pruneThreshold, executor }

Also spelled eles.mcl.

Returns

a promise of one collection per cluster — with cancel() on it (round 128): a pending run rejects with CancelledError, a 'cpu' run has already completed

Throws

if executor or pruneThreshold is invalid; rejects if executor: 'gpu' is unavailable in this environment

eles.affinityPropagation

Affinity propagation, which picks exemplars by message passing and so needs no target cluster count.

Async (round 65): returns a promise, and executor ('cpu' | 'gpu' | 'auto', default 'auto'; 'workers' runs the reference on one pool worker, round 129.1) picks where the message passing runs; 'cpu' is the reproducible reference.

options

{ attributes, distance, preference, damping, minIterations, maxIterations, executor }

Also spelled eles.ap.

Returns

a promise of one collection per cluster — with cancel() on it (round 128): a pending run rejects with CancelledError, a 'cpu' run has already completed

Throws

if executor is invalid; rejects if executor: 'gpu' is unavailable, or if damping/preference are invalid

Degree Collection

eles.degree

The first element's total degree, in + out, answered in O(1) off the adjacency index.

This is a singular accessor, as in v3 — it reports one node's degree, not a collection-wide figure. For the sum over the whole collection use totalDegree().

includeLoops

whether self-loops count (each contributes 2)

Returns

the degree, or undefined when the first element is not a live node

eles.outdegree

The first element's out-degree, in O(1). Singular, like degree().

includeLoops

whether self-loops count

Returns

the out-degree, or undefined when not a live node

eles.indegree

The first element's in-degree, in O(1). Singular, like degree().

includeLoops

whether self-loops count

Returns

the in-degree, or undefined when not a live node

eles.minDegree

The smallest total degree among the collection's nodes.

includeLoops

whether self-loops count

Returns

the minimum degree, or undefined when there are no nodes

eles.maxDegree

The largest total degree among the collection's nodes.

includeLoops

whether self-loops count

Returns

the maximum degree, or undefined when there are no nodes

eles.minIndegree

The smallest in-degree among the collection's nodes.

includeLoops

whether self-loops count

Returns

the minimum in-degree, or undefined when there are no nodes

eles.maxIndegree

The largest in-degree among the collection's nodes.

includeLoops

whether self-loops count

Returns

the maximum in-degree, or undefined when there are no nodes

eles.minOutdegree

The smallest out-degree among the collection's nodes.

includeLoops

whether self-loops count

Returns

the minimum out-degree, or undefined when there are no nodes

eles.maxOutdegree

The largest out-degree among the collection's nodes.

includeLoops

whether self-loops count

Returns

the maximum out-degree, or undefined when there are no nodes

eles.totalDegree

The summed degree of every node in the collection — the whole-collection figure that degree() deliberately is not.

includeLoops

whether self-loops count

Returns

the total degree (0 when there are no nodes)

Events Collection

eles.on

Listen for events on each element of this collection. The handler is bound per element, and keeps firing across slot compaction — listeners repair with their elements rather than going stale.

Events bubble from an element through its compound ancestors to the core (round 14.5), with stopPropagation() honoured.

Any name registers, as on the core and for the same reason — custom events are supported API (ele.emit( 'foo' )), so names cannot be gated. A name v4 never emits registers cleanly and never fires: that is v3's vmouse* aliases and its raw mouse/touch re-emits — and, since round 41.2, any name containing a dot: there is no namespace machinery, so 'data.ns' is a literal type v4 never raises. See Core#on.

events

one or more space-separated event names

callback

the handler

Also spelled eles.addListener.

Returns

this collection, for chaining

eles.one

Like on(), but each element's handler runs at most once.

events

one or more space-separated event names

callback

the handler

Also spelled eles.once.

Returns

this collection, for chaining

eles.off

Stop listening on each element of this collection.

events

one or more space-separated event names

callback

the handler to remove; omit to remove every handler these elements have for events

Also spelled eles.removeListener.

Returns

this collection, for chaining

eles.emit

Emit an event on each element, bubbling through compound ancestors to the core.

events

one or more space-separated event names

extraParams

extra arguments passed to each handler after the event object

Also spelled eles.trigger.

Returns

this collection, for chaining

eles.promiseOn

Resolve once the next matching event fires on any element of this collection — the promise form of one().

events

one or more space-separated event names

Also spelled eles.pon.

Returns

a promise for the event object

Animation

General Animation

ani.play

Enqueue and start.

Returns

resolves when the animation completes (or is stopped)

ani.stop

Stop in place, or at the targets with jumpToEnd — the whole animation, whatever elements it spans. Through the manager, so a GPU-driven one releases its batch (round 144).

jumpToEnd

apply the final values instead of freezing

ani.promise

The completion promise.

Returns

resolves when the animation completes (or is stopped)

ani.playing

Whether the animation is running and not paused.

Returns

true while playing

ani.pause

Round 24.3: freeze in place; the paused span leaves the timeline.

Returns

this handle, for chaining

ani.resume

Resume a paused animation with the clock shifted (round 24.3).

Returns

this handle, for chaining

ani.reverse

Swap the tween's ends with elapsed remapped (round 24.3).

Returns

this handle, for chaining

ani.progress

Elapsed fraction of the duration (read-only — no scrubbing).

Returns

the fraction in [0, 1]

ani.paused

Whether the animation is paused (round 24.3).

Returns

true while paused

Layout context

Scope Layout context

ctx.cy

the core being laid out

ctx.options

the resolved layout options (custom knobs included)

ctx.eles

The layout scope (handles tier); the whole graph unless this run came from eles.layout().

Lazy since round 34.4. It used to be assigned in the constructor, which meant every run of every layout materialized cy.elements() — a handle per element — including for the columnar-first layouts this contract exists to encourage, which never touch it. That cost 333 µs per run at 25k elements for an impl that does nothing. Reading it still costs what it always did; not reading it is now free.

Returns

the scope's handles — eles.layout()'s collection, or the whole graph's elements when the layout was started from the core. Materialized on first read and cached for the run

ctx.nodes

The scope's node handles (lazy — see eles).

Returns

the node subset of eles, unfiltered — unlike nodeSlots(), this keeps locked nodes and compound parents, so a layout iterating it must apply its own rules

ctx.refreshScope

Drop the cached scope so the next eles / nodes read the graph as it now is (118.3): a whole-graph scope is materialized once per run, and a force layout's infinite run rebuilds its sim on an add or remove. A subset scope (eles.layout()) is the caller's collection and stays what it was.

Columnar reads Layout context

ctx.nodeSlots

The slots to lay out: the scope's unlocked leaves, plus a collapsed parent when no scoped node lies below it. Locked nodes hold their place; parents with scoped descendants derive from those descendants. Scope order.

Returns

the slots to place, in exactly cy.nodes() order — which is load-bearing rather than incidental, since grid and circle assign positions by index, so a different enumeration order is a different layout

ctx.edgeSlots

The scope's edge slots.

Returns

every live edge of the scope in cy.edges() order, with no filtering — the counterpart of nodeSlots(), which does filter

ctx.positions

The live position column (x,y interleaved by slot) — read it, write through setPositions.

Returns

the store's own column, not a copy: it changes underneath a held reference as positions are written, and writing into it directly bypasses the dirty tracking the renderer depends on

ctx.endpoints

The live edge endpoint column (source,target node slots).

Returns

the store's own column, indexed by edge slot — node slots, not ids, so it pairs directly with positions() without a lookup

ctx.degreeOf

O(1) degree off the CSR adjacency.

slot

a node slot, as handed out by nodeSlots()

Returns

its whole-graph degree, loops counted as v3 counts them

ctx.nodeDimensions

The layout boxes of the scope's nodes (round 114.1): slot-parallel node-local extents read off the size, border and label columns — the one reading every built-in spaces by. Labels are included when the run's nodeDimensionsIncludeLabels is true (115: v3's default again), making the box asymmetric when a label hangs below the body; take max( -y1, y2 ) for a symmetric half. Headless label dimensions are estimates (16.4), exact once a renderer has laid the glyphs.

slots

the node slots to measure (default nodeSlots())

options

includeLabels (default: the run's option, itself defaulting to false) and padding (split half per side)

Returns

the boxes, parallel to slots

Bounds Layout context

ctx.boundingBox

The scope's current bounding box, labels included.

Returns

{ x1, y1, x2, y2, w, h } in model coordinates

ctx.width

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

the viewport width

ctx.height

The viewport height in CSS px.

Returns

the viewport height

Writing positions Layout context

ctx.setPositions

The bulk write: xy[i2], xy[i2+1] land on slots[i] — one dirty span, no handles (the round-5 slot path; under compounds it takes the per-slot sequential path so auto-bounds stay exact).

slots

the node slots to move

xy

the packed positions: xy[i*2], xy[i*2+1] land on slots[i]

ctx.components

The scope's connected components over nodeSlots() (round 114.4, factored out of packComponents for layouts that pack their own arrays): union-find over the scope's own edges — an edge with an endpoint outside the scope connects nothing here — indexed by position in nodeSlots().

Returns

the component assignment, ids in first-seen node order

ctx.packComponents

Separate the scope's disconnected components (round 87.1): v3's separateComponents as a one-call, translation-only post-pass. Per-component bounding boxes at the current positions are shelf-packed largest-first with spacing between them, every member translated with its component, and the largest component's centre held fixed — the dominant structure keeps its place and the strays come to it.

The boxes are body boxes since round 114.4 (nodeDimensions(), labels included by the run's option), so two singleton components end up spacing apart edge to edge rather than centre to centre; bodies: false restores the 87.1 point boxes.

Components are computed over the scope's own edges (an edge with an endpoint outside the scope connects nothing here), and only the nodeSlots() nodes move — a locked node neither moves nor holds its component in place, so a scope mixing locked and unlocked members of one component can separate them. The write lands through setPositions (one dirty span).

spacing

the gap between packed component boxes (default 40, the force layout's componentSpacing default)

options

bodies (default true) packs the nodes' boxes rather than their positions; includeLabels overrides the run's nodeDimensionsIncludeLabels for those boxes; positions packs that array (2n, parallel to nodeSlots()) in place instead of the store — for a layout that lands through finish() and must not write positions before the tween starts

ctx.layoutPositions

The discrete finisher: v3's layoutPositions plumbing over the scope — spacingFactor, transform, animate (with the fit-at-final-positions viewport animation), fit/zoom/pan, and the layoutready/layoutstop events. The wrapper's layoutstart covers the start (no double emit).

fn

called per scoped node with the node and its index, returning the model position to place it at

overrides

an impl's own defaults, merged over the run's options (round 114.2: flow's fit: true default never reached the finisher before this). ready and stop are never overridden — the wrapper's stop is what resolves promise()

ctx.finish

Land computed positions the way a built-in does (round 114.2): the finisher when the run asks for anything it owns — animate, animateFilter, transform, spacingFactor — and otherwise the bulk slot write followed by fit / zoom / pan. One rule for flow, force and any extension that computes into an array.

slots

the node slots the positions land on

xy

the packed positions: xy[i*2], xy[i*2+1] for slots[i]

overrides

the impl's defaults, merged as layoutPositions merges them

Layout

Running a layout Layout

layout.options

the resolved options this run was created with

layout.run

Start the layout. Emits layoutstart on the core, calls impl.run( ctx ) and awaits it if it returns a promise (the shape a GPU-resident layout needs).

The lifecycle fires exactly once per run either way: an impl that finishes through ctx.layoutPositions() lets the finisher emit layoutready/layoutstop, and one that writes positions directly has them emitted here instead.

Returns

this layout, for chaining; await promise() for completion

layout.promise

Resolves at this run's layoutstop (immediately when never run); rejects with CancelledError when the run was cancelled (round 128) — by cancel() or by cy.destroy().

Returns

the run's promise

layout.stop

Ask the layout to stop early, by calling the impl's optional stop(). An impl without one simply runs to completion. Once the impl has settled and only its finisher tween is in flight (round 144), the tween stops where it got to and layoutstop fires now, as a built-in's stop() does.

Returns

this layout, for chaining

layout.cancel

Abandon the run in flight (round 128) — the alternative to stop(), which keeps what stands. The impl is asked to cancel() (or stop() when it has no cancel), and once its run settles the scope's nodes go back to where run() found them, a tween under way is dropped where it is, the viewport is left alone, layoutstop fires with cancelled: true, and promise() rejects with CancelledError. A layout that is not running is unchanged.

Returns

this layout, for chaining

layout.reheat

Heat a running layout back up (118.3), by calling the impl's optional reheat(). A force layout's infinite run ticks only while its field is moving and reheats itself on a drag, a moved node and an added or removed element; this is for a change it cannot see — an edge length that changed under a data mapping, a style that resized the boxes. An impl without one ignores it.

alpha

the temperature to restore; the force layout's default is 0.3, d3's drag convention

Returns

this layout, for chaining

Event

What happened Event

event.type

the event type, e.g. 'tap' — never namespaced (round 41.1)

event.target

the core for core-level events, the element for element events

event.cy

the core the event was raised on

event.position

model-space position, on pointer-derived events

event.renderedPosition

rendered-space position; derived from position and the viewport

event.originalEvent

the DOM event behind a gesture, when there was one (round 41.4)

event.layout

the layout instance, on the layout lifecycle events

event.cancelled

on layoutstop, whether the run was cancelled (round 128); on loadstop, whether the load was (round 103)

event.diff

on patch, what the patch added, removed and updated (round 107)

event.progress

on the load lifecycle events, the chunks and elements so far (round 103)

event.timeStamp

when the event was built, Date.now() unless the caller supplied one

event.isDefaultPrevented

Whether preventDefault() has been called.

Recorded, never read by v4: by decided design preventDefault() suppresses no gesture default — it forwards to the DOM event when one is attached, and gesture defaults are controlled by their explicit toggles instead. See the module comment.

event.isPropagationStopped

Whether stopPropagation() has been called — read by the compound bubbling walk (round 14.5), where it halts the phase sequence.

Controlling propagation Event

event.preventDefault

Mark the event's default as prevented, and prevent the DOM event's default when one is attached.

Browser-level only, by decided design — no v4 code reads isDefaultPrevented(), so this cannot stop a tap from selecting or a grab from starting; use the explicit toggles (autoungrabify, autounselectify, boxSelectionEnabled, …) for gesture control. With originalEvent populated (round 41.4) this reaches the browser's default.

event.stopPropagation

Stop the event bubbling to further phases: the remaining ancestors and the core do not see it (round 14.5). Returning false from a handler does the same. With originalEvent attached (round 41.4) this also calls the DOM event's stopPropagation(), so an outer DOM listener stops seeing it too.