Skip to content

Style and legends

Apply a declarative stylesheet and inspect its legend.

#cy.style()

// Get the style engine
cy.style(): StyleEngine

Read the style engine for this graph.

Returns StyleEngine

this graph's style engine

Example

console.log(typeof cy.style().update); // 'function'

Example graph and handle setup

#cy.style(sheet)

// Install a stylesheet
cy.style(sheet: Stylesheet<NodeData, EdgeData>): StyleEngine

Get the style engine, or set the stylesheet and return it.

The sheet is a plain { nodes, edges, parents, core } object of prop objects — there are no selector blocks and no style functions. All per-element variation is declarative: mapper objects ({ data, scale, … }) and case conditionals, which is what keeps every value analyzable, serializable and GPU-evaluable.

Inside a batch the sheet is compiled and validated immediately (so errors still throw at the call site) but applied once at the outermost endBatch().

Parameters
NameDescription
sheet: Stylesheet<NodeData, EdgeData>

the stylesheet to install

Fields of sheet
NameDescription
nodes: StyleProps<NodeData>?

node props; typed, a mapper's field is a node field

edges: StyleProps<EdgeData>?

edge props; typed, a mapper's field is an edge field

parents: StyleProps<NodeData>?

Compound-parent overlay: node props that apply to parent nodes on top of the nodes group and the parent defaults (rectangle, #eee fill, 1px #ccc border, padding 10) — constants or mappers — plus the compound props padding, padding-relative-to, min-width, min-height and compound-sizing-wrt-labels (constants only; sizing is 'exclude' by default, or 'include' to add visible direct-child label bounds in model space before padding. A parent's own label never sizes itself, and zoom LOD does not affect the geometry).

core: StyleProps?

Core (viewport-level) theming props (A2), constants only: selection-box-color/-opacity/-border-color/-border-width (the DOM selection box) and active-bg-color/-opacity/-size (the background-grab indicator circle) — plus dim-opacity (the rest of the graph while cy.emphasize() is set) and label-declutter ('none', the default, or 'cull' — hide each node label that would overlap a higher-label-priority one).

bypasses: Record<string, StyleProps>?

Per-element bypasses: id → prop → constant. A bypass beats everything — the user's group blocks and the default sheet's state conditionals included — and is an id-keyed declaration rather than element state: it survives remove/re-add of its element, may name an id that does not exist yet (inert until it does), and round-trips through cy.json(). Values are constants only — mappers belong in the group blocks — and prop keys take dash-case or camelCase like every prop surface. A full cy.style( sheet) replaces the section like any other; the ele.style( name, value) / removeStyle() methods are sugar over it.

Returns StyleEngine

the style engine (also reachable as the return value when setting, so calls chain)

Example

cy.style({ nodes: { 'background-color': '#369', width: 40 } });
console.log(cy.nodes().first().numericStyle('width')); // 40

Example graph and handle setup

Throws

if the sheet references an unknown property or an invalid value

#cy.legend()

// Read the application's shared mapping and chart metadata
cy.legend(): Legend

Read the application's shared mapping and chart metadata. The returned JSON object is detached; changing it never alters this instance. Automatic domains expose their authored auto stops in the stylesheet and their current numeric stops here. legendchange fires after a committed snapshot changes, before batchend for a batch.

Returns Legend

detached legend entries in stylesheet definition/property order

Example

console.log(cy.legend().entries.length); // 0

Example graph and handle setup

All guides · Alphabetical API index · Read continuously