Skip to content

API reference

eles.scratch — Collection > Data and scratch. Cytoscape.js signatures, parameters and return contract.

eles.scratch — Collection › Data and scratch

Preview · Collection › Data and scratch

Read in the complete API reference · All API members

#ele.scratch()

// Get all scratch data
ele.scratch(): Record<string, unknown> | undefined

Read all scratch data from the first element. Scratch is never exported and writes emit no events.

Returns Record<string, unknown> | undefined

the scratch object or value; undefined when empty or unset

Example

eles.scratch('ui', 1);
console.log(eles.first().scratch().ui); // 1

Example graph and handle setup

#ele.scratch(key)

// Get scratch data by key
ele.scratch(key: string): unknown

Read one scratch namespace from the first element. Scratch is never exported and writes emit no events.

Parameters
NameDescription
key: string

the namespace to read or write

Returns unknown

the scratch object or value; undefined when empty or unset

Example

eles.scratch('ui', 1);
console.log(eles.first().scratch('ui')); // 1

Example graph and handle setup

#eles.scratch(key, value)

// Set scratch data by key
eles.scratch(key: string, value: unknown): this

Write one scratch namespace on every element. Scratch is never exported and writes emit no events.

Parameters
NameDescription
key: string

the namespace to read or write

value: unknown

the transient value to store

Returns this

this collection, for chaining

Example

const result = eles.scratch('ui', 1);
console.log(result === eles); // true

Example graph and handle setup

#eles.scratch(patch)

// Set several scratch data fields
eles.scratch(patch: Record<string, unknown>): this

Merge scratch namespaces on every element. Scratch is never exported and writes emit no events.

Parameters
NameDescription
patch: Record<string, unknown>

the namespaces to merge

Returns this

this collection, for chaining

Example

eles.scratch({ ui: 1 });
console.log(eles.first().scratch('ui')); // 1

Example graph and handle setup