Skip to content

API reference

cy.scratch — Core > Data and scratch. Cytoscape.js signatures, parameters and return contract.

cy.scratch — Core › Data and scratch

Preview · Core › Data and scratch

Read in the complete API reference · All API members

#cy.scratch()

// Get all scratch data
cy.scratch(): Record<string, unknown>

Read all graph-level scratch data. Namespace extension keys, for example '_myExtension'. Scratch is transient, never exported, and emits no events.

Returns Record<string, unknown>

the graph's scratch data object

Example

cy.scratch('title', 'Example graph');
console.log(cy.scratch().title); // 'Example graph'

Example graph and handle setup

#cy.scratch(key)

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

Read one graph-level scratch data value.

Parameters
NameDescription
key: string

the application field to read or write

Returns unknown

the value, or undefined when the key is unset

Example

cy.scratch('title', 'Example graph');
console.log(cy.scratch('title')); // 'Example graph'

Example graph and handle setup

#cy.scratch(key, value)

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

Write one graph-level scratch data value. Scratch writes do not emit events and are never exported.

Parameters
NameDescription
key: string

the application field to read or write

value: unknown

the value to store

Returns this

this core, for chaining

Example

const result = cy.scratch('title', 'Example graph');
console.log(result === cy); // true

Example graph and handle setup

#cy.scratch(patch)

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

Merge several graph-level scratch data fields. Scratch writes do not emit events and are never exported.

Parameters
NameDescription
patch: Record<string, unknown>

the fields to merge; other fields stay unchanged

Returns this

this core, for chaining

Example

cy.scratch({ title: 'Example graph' });
console.log(cy.scratch('title')); // 'Example graph'

Example graph and handle setup