Skip to content

eles.layoutPositions(layout, options, fn)

eles.layoutPositions — Collection > Layout. Cytoscape.js signatures, parameters and return contract.

eles.layoutPositions — Collection › Layout

Preview · Collection › Layout

Read in the complete API reference · All API members

// 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
eles.layoutPositions(layout: object, options: LayoutBaseOptions, fn: (node: Collection<NodeData, EdgeData, Data>, i: number) => Position): this

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. With animate: true the viewport animates concurrently (a fit targets the bounding box at the final positions).

Parameters
NameDescription
layout: object

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

options: LayoutBaseOptions

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

fn: (node: Collection<NodeData, EdgeData, Data>, i: number) => Position

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

Fields of options
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 this

this collection, for chaining

Example

cy.layout({ impl: { run(ctx) {
ctx.eles.layoutPositions({}, { fit: false }, (node, i) => ({ x: i * 40, y: 0 }));
} } }).run();
console.log(cy.getElementById('b').position('x')); // 40

Example graph and handle setup