Skip to content

API reference

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

eles.relativePosition — Collection › Position and dimensions

Preview · Collection › Position and dimensions

Read in the complete API reference · All API members

#ele.relativePosition()

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

Read the first element's position relative to its immediate compound parent. For orphans this equals the model position.

Returns Position | undefined

the first element's position, or undefined when empty

Example

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

Example graph and handle setup

#ele.relativePosition(dim)

// Get one coordinate
ele.relativePosition(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').relativePosition('x')); // 0

Example graph and handle setup

#eles.relativePosition(position)

// Set the position
eles.relativePosition(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.relativePosition({ x: 20, y: 10 });
console.log(result === eles); // true

Example graph and handle setup

#eles.relativePosition(dim, value)

// Set one coordinate
eles.relativePosition(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.relativePosition('x', 20);
console.log(result === eles); // true

Example graph and handle setup

Also spelled eles.relativePoint.