Skip to content

Compound nodes

Traverse compound containment and manage collapse state.

#eles.parent(criterion?)

// Immediate parents of every node in the collection (unique)
eles.parent(criterion?: FilterLike<NodeData, EdgeData, NodeData, NodeData | EdgeData>): Collection<NodeData, EdgeData, NodeData>

Immediate parents of every node in the collection (unique). Always returns a collection and applies the optional filter.

Parameters
NameDescription
criterion: FilterLike<NodeData, EdgeData, NodeData, NodeData | EdgeData>?

an optional query object or predicate applied to the result, exactly as filter() takes it

Fields of criterion
NameDescription
group: GroupName?

restrict to one group

selected: boolean?

require the element (not) to be selected

selectable: boolean?

whether the element may be selected by the user

locked: boolean?

whether the element is locked in place

grabbed: boolean?

whether the user is dragging the element

grabbable: boolean?

whether the element may be dragged

active: boolean?

whether the element is under an active press

hovered: boolean?

whether the pointer is over the element

emphasized: boolean?

whether the element is in the current emphasis (* cy.emphasize())

parent: boolean?

structural (nodes only): has at least one child

childless: boolean?

structural (nodes only): has no children — exactly { parent: false }

child: boolean?

structural (nodes only): has a parent

orphan: boolean?

structural (nodes only): has no parent — exactly { child: false }

collapsed: boolean?

whether this compound parent is in collapsed miniature state (nodes only)

data: QueryData<Data>?

data-sidecar conditions per key; a bare value means equality. Typed, the keys are the queried elements' fields.

Returns Collection<NodeData, EdgeData, NodeData>

the immediate parents

Example

cy.add({ data: { id: 'parent' } });
cy.getElementById('a').move({ parent: 'parent' });
cy.getElementById('b').move({ parent: 'parent' });
console.log(cy.getElementById('a').parent().map(node => node.id()).sort()); // ["parent"]

Example graph and handle setup

#eles.parents(criterion?)

// All ancestors, level by level: every nearest parent first, then the grandparents, and so on
eles.parents(criterion?: FilterLike<NodeData, EdgeData, NodeData, NodeData | EdgeData>): Collection<NodeData, EdgeData, NodeData>

All ancestors, level by level: every nearest parent first, then the grandparents, and so on.

Parameters
NameDescription
criterion: FilterLike<NodeData, EdgeData, NodeData, NodeData | EdgeData>?

an optional query object or predicate applied to the result, exactly as filter() takes it

Fields of criterion
NameDescription
group: GroupName?

restrict to one group

selected: boolean?

require the element (not) to be selected

selectable: boolean?

whether the element may be selected by the user

locked: boolean?

whether the element is locked in place

grabbed: boolean?

whether the user is dragging the element

grabbable: boolean?

whether the element may be dragged

active: boolean?

whether the element is under an active press

hovered: boolean?

whether the pointer is over the element

emphasized: boolean?

whether the element is in the current emphasis (* cy.emphasize())

parent: boolean?

structural (nodes only): has at least one child

childless: boolean?

structural (nodes only): has no children — exactly { parent: false }

child: boolean?

structural (nodes only): has a parent

orphan: boolean?

structural (nodes only): has no parent — exactly { child: false }

collapsed: boolean?

whether this compound parent is in collapsed miniature state (nodes only)

data: QueryData<Data>?

data-sidecar conditions per key; a bare value means equality. Typed, the keys are the queried elements' fields.

Returns Collection<NodeData, EdgeData, NodeData>

the ancestors, nearest first

Example

cy.add({ data: { id: 'parent' } });
cy.getElementById('a').move({ parent: 'parent' });
cy.getElementById('b').move({ parent: 'parent' });
console.log(cy.getElementById('a').parents().map(node => node.id()).sort()); // ["parent"]

Example graph and handle setup

Also spelled eles.ancestors.

#eles.children(criterion?)

// Direct children of every node, in link order per parent
eles.children(criterion?: FilterLike<NodeData, EdgeData, NodeData, NodeData | EdgeData>): Collection<NodeData, EdgeData, NodeData>

Direct children of every node, in link order per parent.

Parameters
NameDescription
criterion: FilterLike<NodeData, EdgeData, NodeData, NodeData | EdgeData>?

an optional query object or predicate applied to the result, exactly as filter() takes it

Fields of criterion
NameDescription
group: GroupName?

restrict to one group

selected: boolean?

require the element (not) to be selected

selectable: boolean?

whether the element may be selected by the user

locked: boolean?

whether the element is locked in place

grabbed: boolean?

whether the user is dragging the element

grabbable: boolean?

whether the element may be dragged

active: boolean?

whether the element is under an active press

hovered: boolean?

whether the pointer is over the element

emphasized: boolean?

whether the element is in the current emphasis (* cy.emphasize())

parent: boolean?

structural (nodes only): has at least one child

childless: boolean?

structural (nodes only): has no children — exactly { parent: false }

child: boolean?

structural (nodes only): has a parent

orphan: boolean?

structural (nodes only): has no parent — exactly { child: false }

collapsed: boolean?

whether this compound parent is in collapsed miniature state (nodes only)

data: QueryData<Data>?

data-sidecar conditions per key; a bare value means equality. Typed, the keys are the queried elements' fields.

Returns Collection<NodeData, EdgeData, NodeData>

the children

Example

cy.add({ data: { id: 'parent' } });
cy.getElementById('a').move({ parent: 'parent' });
cy.getElementById('b').move({ parent: 'parent' });
console.log(cy.getElementById('parent').children().map(node => node.id()).sort()); // ["a","b"]

Example graph and handle setup

#eles.descendants(criterion?)

// The subtree below every node in pre-order, excluding the nodes themselves
eles.descendants(criterion?: FilterLike<NodeData, EdgeData, NodeData, NodeData | EdgeData>): Collection<NodeData, EdgeData, NodeData>

The subtree below every node in pre-order, excluding the nodes themselves.

Parameters
NameDescription
criterion: FilterLike<NodeData, EdgeData, NodeData, NodeData | EdgeData>?

an optional query object or predicate applied to the result, exactly as filter() takes it

Fields of criterion
NameDescription
group: GroupName?

restrict to one group

selected: boolean?

require the element (not) to be selected

selectable: boolean?

whether the element may be selected by the user

locked: boolean?

whether the element is locked in place

grabbed: boolean?

whether the user is dragging the element

grabbable: boolean?

whether the element may be dragged

active: boolean?

whether the element is under an active press

hovered: boolean?

whether the pointer is over the element

emphasized: boolean?

whether the element is in the current emphasis (* cy.emphasize())

parent: boolean?

structural (nodes only): has at least one child

childless: boolean?

structural (nodes only): has no children — exactly { parent: false }

child: boolean?

structural (nodes only): has a parent

orphan: boolean?

structural (nodes only): has no parent — exactly { child: false }

collapsed: boolean?

whether this compound parent is in collapsed miniature state (nodes only)

data: QueryData<Data>?

data-sidecar conditions per key; a bare value means equality. Typed, the keys are the queried elements' fields.

Returns Collection<NodeData, EdgeData, NodeData>

the descendants

Example

cy.add({ data: { id: 'parent' } });
cy.getElementById('a').move({ parent: 'parent' });
cy.getElementById('b').move({ parent: 'parent' });
console.log(cy.getElementById('parent').descendants().map(node => node.id()).sort()); // ["a","b"]

Example graph and handle setup

#eles.collapse(timing?)

// Scale each compound parent’s descendants into a miniature around the parent’s current centre
eles.collapse(timing?: Pick<AnimateOptions, 'duration' | 'easing'>): this

Scale each compound parent’s descendants into a miniature around the parent’s current centre. Pass { duration, easing } to animate the scale; without options, the operation is immediate. The original nodes, edges and explicit visibility state remain unchanged.

Parameters
NameDescription
timing: Pick<AnimateOptions, 'duration' | 'easing'>?

optional animation duration and easing

Returns this

this collection, for chaining

Example

const parent = cy.add({ data: { id: 'parent' } });
cy.getElementById('a').move({ parent: 'parent' });
parent.collapse();
console.log(parent.collapsed()); // true

Example graph and handle setup

#eles.expand(timing?)

// Restore each collapsed compound parent’s descendants by reversing its currently applied scale around the parent’s current centre
eles.expand(timing?: Pick<AnimateOptions, 'duration' | 'easing'>): this

Restore each collapsed compound parent’s descendants by reversing its currently applied scale around the parent’s current centre. Pass { duration, easing } to animate the restoration; without options, the operation is immediate.

Parameters
NameDescription
timing: Pick<AnimateOptions, 'duration' | 'easing'>?

optional animation duration and easing

Returns this

this collection, for chaining

Example

const parent = cy.add({ data: { id: 'parent' } });
cy.getElementById('a').move({ parent: 'parent' });
parent.collapse();
parent.expand();
console.log(parent.collapsed()); // false

Example graph and handle setup

#eles.siblings(criterion?)

// Nodes sharing a parent with the collection's nodes, excluding them; orphans are nobody's siblings
eles.siblings(criterion?: FilterLike<NodeData, EdgeData, NodeData, NodeData | EdgeData>): Collection<NodeData, EdgeData, NodeData>

Nodes sharing a parent with the collection's nodes, excluding them; orphans are nobody's siblings.

Parameters
NameDescription
criterion: FilterLike<NodeData, EdgeData, NodeData, NodeData | EdgeData>?

an optional query object or predicate applied to the result, exactly as filter() takes it

Fields of criterion
NameDescription
group: GroupName?

restrict to one group

selected: boolean?

require the element (not) to be selected

selectable: boolean?

whether the element may be selected by the user

locked: boolean?

whether the element is locked in place

grabbed: boolean?

whether the user is dragging the element

grabbable: boolean?

whether the element may be dragged

active: boolean?

whether the element is under an active press

hovered: boolean?

whether the pointer is over the element

emphasized: boolean?

whether the element is in the current emphasis (* cy.emphasize())

parent: boolean?

structural (nodes only): has at least one child

childless: boolean?

structural (nodes only): has no children — exactly { parent: false }

child: boolean?

structural (nodes only): has a parent

orphan: boolean?

structural (nodes only): has no parent — exactly { child: false }

collapsed: boolean?

whether this compound parent is in collapsed miniature state (nodes only)

data: QueryData<Data>?

data-sidecar conditions per key; a bare value means equality. Typed, the keys are the queried elements' fields.

Returns Collection<NodeData, EdgeData, NodeData>

the siblings

Example

cy.add({ data: { id: 'parent' } });
cy.getElementById('a').move({ parent: 'parent' });
cy.getElementById('b').move({ parent: 'parent' });
console.log(cy.getElementById('a').siblings().map(node => node.id()).sort()); // ["b"]

Example graph and handle setup

#eles.orphans(criterion?)

// The collection's nodes without a parent
eles.orphans(criterion?: FilterLike<NodeData, EdgeData, NodeData, NodeData | EdgeData>): Collection<NodeData, EdgeData, NodeData>

The collection's nodes without a parent.

Parameters
NameDescription
criterion: FilterLike<NodeData, EdgeData, NodeData, NodeData | EdgeData>?

an optional query object or predicate applied to the result, exactly as filter() takes it

Fields of criterion
NameDescription
group: GroupName?

restrict to one group

selected: boolean?

require the element (not) to be selected

selectable: boolean?

whether the element may be selected by the user

locked: boolean?

whether the element is locked in place

grabbed: boolean?

whether the user is dragging the element

grabbable: boolean?

whether the element may be dragged

active: boolean?

whether the element is under an active press

hovered: boolean?

whether the pointer is over the element

emphasized: boolean?

whether the element is in the current emphasis (* cy.emphasize())

parent: boolean?

structural (nodes only): has at least one child

childless: boolean?

structural (nodes only): has no children — exactly { parent: false }

child: boolean?

structural (nodes only): has a parent

orphan: boolean?

structural (nodes only): has no parent — exactly { child: false }

collapsed: boolean?

whether this compound parent is in collapsed miniature state (nodes only)

data: QueryData<Data>?

data-sidecar conditions per key; a bare value means equality. Typed, the keys are the queried elements' fields.

Returns Collection<NodeData, EdgeData, NodeData>

the parentless nodes

Example

console.log(eles.orphans().map(ele => ele.id())); // ["a","b","c"]

Example graph and handle setup

#eles.nonorphans(criterion?)

// The collection's nodes that have a parent
eles.nonorphans(criterion?: FilterLike<NodeData, EdgeData, NodeData, NodeData | EdgeData>): Collection<NodeData, EdgeData, NodeData>

The collection's nodes that have a parent.

Parameters
NameDescription
criterion: FilterLike<NodeData, EdgeData, NodeData, NodeData | EdgeData>?

an optional query object or predicate applied to the result, exactly as filter() takes it

Fields of criterion
NameDescription
group: GroupName?

restrict to one group

selected: boolean?

require the element (not) to be selected

selectable: boolean?

whether the element may be selected by the user

locked: boolean?

whether the element is locked in place

grabbed: boolean?

whether the user is dragging the element

grabbable: boolean?

whether the element may be dragged

active: boolean?

whether the element is under an active press

hovered: boolean?

whether the pointer is over the element

emphasized: boolean?

whether the element is in the current emphasis (* cy.emphasize())

parent: boolean?

structural (nodes only): has at least one child

childless: boolean?

structural (nodes only): has no children — exactly { parent: false }

child: boolean?

structural (nodes only): has a parent

orphan: boolean?

structural (nodes only): has no parent — exactly { child: false }

collapsed: boolean?

whether this compound parent is in collapsed miniature state (nodes only)

data: QueryData<Data>?

data-sidecar conditions per key; a bare value means equality. Typed, the keys are the queried elements' fields.

Returns Collection<NodeData, EdgeData, NodeData>

the parented nodes

Example

cy.add({ data: { id: 'parent' } });
cy.getElementById('a').move({ parent: 'parent' });
cy.getElementById('b').move({ parent: 'parent' });
console.log(cy.getElementById('a').nonorphans().map(node => node.id()).sort()); // ["a"]

Example graph and handle setup

#eles.commonAncestors(criterion?)

// Ancestors common to every element, closest first (an edge in the collection has no ancestors, so it empties the result)
eles.commonAncestors(criterion?: FilterLike<NodeData, EdgeData, NodeData, NodeData | EdgeData>): Collection<NodeData, EdgeData, NodeData>

Ancestors common to every element, closest first (an edge in the collection has no ancestors, so it empties the result).

Parameters
NameDescription
criterion: FilterLike<NodeData, EdgeData, NodeData, NodeData | EdgeData>?

an optional query object or predicate applied to the result, exactly as filter() takes it

Fields of criterion
NameDescription
group: GroupName?

restrict to one group

selected: boolean?

require the element (not) to be selected

selectable: boolean?

whether the element may be selected by the user

locked: boolean?

whether the element is locked in place

grabbed: boolean?

whether the user is dragging the element

grabbable: boolean?

whether the element may be dragged

active: boolean?

whether the element is under an active press

hovered: boolean?

whether the pointer is over the element

emphasized: boolean?

whether the element is in the current emphasis (* cy.emphasize())

parent: boolean?

structural (nodes only): has at least one child

childless: boolean?

structural (nodes only): has no children — exactly { parent: false }

child: boolean?

structural (nodes only): has a parent

orphan: boolean?

structural (nodes only): has no parent — exactly { child: false }

collapsed: boolean?

whether this compound parent is in collapsed miniature state (nodes only)

data: QueryData<Data>?

data-sidecar conditions per key; a bare value means equality. Typed, the keys are the queried elements' fields.

Returns Collection<NodeData, EdgeData, NodeData>

the shared ancestors, closest first

Example

cy.add({ data: { id: 'parent' } });
cy.getElementById('a').move({ parent: 'parent' });
cy.getElementById('b').move({ parent: 'parent' });
console.log(cy.getElementById('a').commonAncestors().map(node => node.id()).sort()); // ["parent"]

Example graph and handle setup

#ele.isParent()

// Whether the first element is a node with at least one child
ele.isParent(): boolean

Whether the first element is a node with at least one child.

Returns boolean

true for a parent node; false for edges and for removed elements, which are nodes of no hierarchy

Example

console.log(eles.isParent()); // false

Example graph and handle setup

#ele.isChildless()

// Whether the first element is a node with no children
ele.isChildless(): boolean

Whether the first element is a node with no children.

Returns boolean

true for a node with no children; false for edges, so it is not the plain negation of isParent()

Example

console.log(eles.isChildless()); // true

Example graph and handle setup

#ele.isChild()

// Whether the first element is a node with a parent
ele.isChild(): boolean

Whether the first element is a node with a parent.

Returns boolean

true for a node with a parent; false for edges and removed elements

Example

console.log(eles.isChild()); // false

Example graph and handle setup

#ele.collapsed()

// Whether the first live node is a collapsed compound parent
ele.collapsed(): boolean

Whether the first live node is a collapsed compound parent.

Returns boolean

true from collapse start until expansion completes; false for leaves, edges and removed elements

Example

console.log(eles.collapsed()); // false

Example graph and handle setup

#ele.insideCollapsed()

// Whether the first live node has a collapsed strict ancestor
ele.insideCollapsed(): boolean

Whether the first live node has a collapsed strict ancestor. The collapsed parent itself answers false.

Returns boolean

true when the node is a descendant of a collapsed parent

Example

console.log(eles.insideCollapsed()); // false

Example graph and handle setup

#ele.isOrphan()

// Whether the first element is a node without a parent
ele.isOrphan(): boolean

Whether the first element is a node without a parent.

Returns boolean

true for a node with no parent; false for edges, so it is not the plain negation of isChild()

Example

console.log(eles.isOrphan()); // true

Example graph and handle setup

All guides · Alphabetical API index · Read continuously