Skip to content

ctx.finish(slots, xy, overrides?)

ctx.finish — Extensions > Layout context > Writing positions and finishing. Cytoscape.js signatures, parameters and return contract.

ctx.finish — Extensions › Layout context › Writing positions and finishing

Preview · Extensions › Layout context › Writing positions and finishing

Read in the complete API reference · All API members

// Land computed positions the way a built-in does: 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
ctx.finish(slots: number[], xy: ArrayLike<number>, overrides?: LayoutBaseOptions): void

Land computed positions the way a built-in does: 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.

Parameters
NameDescription
slots: number[]

the node slots the positions land on

xy: ArrayLike<number>

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

overrides: LayoutBaseOptions?Default: {}

the impl's defaults, merged as layoutPositions merges them

Fields of overrides
NameDescription
eles: unknown?

the elements to lay out (set automatically by eles.layout()); defaults to the whole graph

fit: boolean?
padding: number?
boundingBox: BoundingBoxInput?
nodeDimensionsIncludeLabels: boolean?

include labels in the node dimensions a layout spaces by — default false. Every built-in's overlap avoidance reads the same boxes, so true keeps labels apart too. Headless label dimensions are estimates.

spacingFactor: number?
transform: (node: unknown, position: Position) => Position?

transform a computed position (e.g. to flip an axis)

animate: boolean?

whether to animate node positions into place

animationDuration: number?
animationEasing: string?
animateFilter: (node: unknown, i: number) => boolean?

which nodes animate (others jump); all by default

ready: () => void?

callback on layoutready

stop: () => void?

callback on layoutstop

zoom: number?

zoom to set when fit is false

pan: Position?

pan to set when fit is false

Returns void

Example

// Inside a custom layout, ctx is supplied by the library.
cy.layout({ impl: { run(ctx) {
const slots = Array.from(ctx.nodeSlots());
ctx.finish(slots, slots.flatMap((slot, i) => [i * 40, 0]), { fit: false });
} } }).run();
console.log(cy.getElementById('b').position('x')); // 40

Example graph and handle setup