Skip to content

API reference

eles.position — Collection > Position and dimensions. Cytoscape.js signatures, parameters and return contract.

eles.position — Collection › Position and dimensions

Preview · Collection › Position and dimensions

Read in the complete API reference · All API members

#ele.position()

// Get the position
ele.position(): Position | undefined

Read the first element's position in model coordinates.

Returns Position | undefined

the first element's position, or undefined when empty

Example

console.log(cy.getElementById('a').position()); // { x: 0, y: 0 }

Example graph and handle setup

#ele.position(dim)

// Get one coordinate
ele.position(dim: string): number | undefined

Read one coordinate of the first element.

Parameters
NameDescription
dim: string

the coordinate, 'x' or 'y'

Returns number | undefined

the first element's coordinate, or undefined when empty

Example

console.log(cy.getElementById('a').position('x')); // 0

Example graph and handle setup

#eles.position(position)

// Set the position
eles.position(position: Position): this

Set the position on every unlocked node.

Parameters
NameDescription
position: Position

the coordinates to write

Fields of position
NameDescription
x: number
y: number
Returns this

this collection, for chaining

Example

const result = eles.position({ x: 20, y: 10 });
console.log(result === eles); // true

Example graph and handle setup

#eles.position(dim, value)

// Set one coordinate
eles.position(dim: string, value: number): this

Set one coordinate on every unlocked node.

Parameters
NameDescription
dim: string

the coordinate, 'x' or 'y'

value: number

the coordinate to write

Returns this

this collection, for chaining

Example

const result = eles.position('x', 20);
console.log(result === eles); // true

Example graph and handle setup

Also spelled eles.modelPosition, eles.point.