Skip to content

cy.clone(options?)

cy.clone — Core > Independent views. Cytoscape.js signatures, parameters and return contract.

cy.clone — Core › Independent views

Preview · Core › Independent views

Read in the complete API reference · All API members

// Make an independent instance holding a copy of this graph — the way to show one graph in two places, e.g
cy.clone(options?: CloneOptions<NodeData, EdgeData>): Core<NodeData, EdgeData>

Make an independent instance holding a copy of this graph — 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.

Parameters
NameDescription
options: CloneOptions<NodeData, EdgeData>?

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

Fields of options
NameDescription
follow: boolean | FollowOptions?

Keep the clone current: true, or { throttle }. Each sync is clone.patch( source.serialize() ) — the source's elements, data, positions and hierarchy; never its sheet, viewport, selection or graph-level data. Stops when either instance is destroyed.

zoom: number?
pan: Position?
container: HTMLElement | null?

Where to render. When given, WebGPU is required: the factory throws synchronously if navigator.gpu is missing. When omitted, the instance is headless (works in Node, never throws for missing GPU).

renderer: RendererOptions?
pixelRatio: number | 'auto'?

device pixel ratio override; defaults to the window's

pointerCursors: boolean | Partial<CursorMap>?

whether the canvas writes CSS cursors for the gesture affordances — grab/grabbing around dragging, pointer over an element, crosshair while boxing (default true).

false means the interaction layer never touches style.cursor, for an app that sets its own; an object overrides individual entries ({ pan: 'move' }), where '' means inherit.

wheelSensitivity: number?

wheel-zoom rate multiplier (default 1; custom values warn once — a sensitivity tuned to one mouse/OS zooms unnaturally on others).

wheelBehavior: WheelBehavior?

what a wheel does: 'zoom' (default), 'pan' (ctrl/meta — the pinch — still zooms) or 'modifier-zoom' (only a ctrl/meta wheel zooms; a plain wheel scrolls the page).

desktopTapThreshold: number?

css px a mouse/pen press may move and still count as a tap (default 4).

touchTapThreshold: number?

css px a touch press may move and still count as a tap (default 8).

tapholdDuration: number?

unmoved-press duration before 'taphold' fires, in ms (default 500).

multiClickDebounceTime: number?

the dbltap/onetap debounce window in ms (default 250)

boxSelectionEnabled: boolean?

allow box selection (default true)

boxSelectionIncludesLabels: boolean?

box selection considers label boxes too (default false). Its sense follows boxSelectionMode: it narrows a 'contain' selection and widens an 'overlap' one.

boxSelectionMode: BoxSelectionMode?

what the box-selection gesture counts as selected: 'contain' (default) takes only elements wholly inside the band; 'overlap' takes anything the band touches.

userPanningEnabled: boolean?

allow user (pointer) panning (default true)

userZoomingEnabled: boolean?

allow user (wheel/pinch) zooming (default true)

style: Stylesheet<NodeData, EdgeData>?

the stylesheet — its field references typed likewise

layout: LayoutOptions?
minZoom: number?
maxZoom: number?
autolock: boolean?

disable node dragging globally (default false)

autoungrabify: boolean?

make all nodes ungrabbable globally (default false)

autounselectify: boolean?

disable selection globally (default false)

panningEnabled: boolean?

allow panning at all — programmatic and user (default true)

zoomingEnabled: boolean?

allow zooming at all — programmatic and user (default true)

selectionType: 'single' | 'additive'?

'single' (tap/box replaces the selection) or 'additive' (taps toggle, boxes add); default 'single'

headlessWidth: number?

rendered dimensions used when headless

headlessHeight: number?
Returns Core<NodeData, EdgeData>

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

Example

const copy = cy.clone();
copy.getElementById('a').data('score', 99);
console.log(cy.getElementById('a').data('score')); // 1
copy.destroy();

Example graph and handle setup

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