Skip to content

cytoscape.toColumnarElements(defs, options?)

cytoscape.toColumnarElements — Core > Export and snapshots > Graph data and wire format. Cytoscape.js signatures, parameters and return contract.

cytoscape.toColumnarElements — Core › Export and snapshots › Graph data and wire format

Preview · Core › Export and snapshots › Graph data and wire format

Read in the complete API reference · All API members

// Convert element definitions to a compact columnar payload for bulk loading or binary serialization
cytoscape.toColumnarElements(defs: ElementsDefinition | ElementDefinition, options?: ToColumnarOptions): ColumnarElements

Convert element definitions to a compact columnar payload for bulk loading or binary serialization. Node fields use typed arrays, and edge endpoints refer to indices in the payload's node list.

This form does not preserve locked, grabbable or pannable overrides. Pass definitions directly to the constructor when those flags must survive. Use the refs option to include references to nodes already in the graph.

Parameters
NameDescription
defs: ElementsDefinition | ElementDefinition

one element, an array, or { nodes, edges }

options: ToColumnarOptions?Default: {}

{ refs }: carry endpoints and parents the payload does not hold as node references rather than throwing

Fields of defs
NameDescription
group: GroupName?

inferred from data.source/data.target when omitted

data: DefinitionData<Data>?
position: Position?

nodes only

collapsed: boolean?

nodes only: persisted miniature-compound state

appliedCollapseScale: number?

nodes only: current applied factor when collapsed; omitted uses the configured collapse-scale

selected: boolean?
selectable: boolean?
grabbable: boolean?
locked: boolean?
pannable: boolean?

dragging this element pans the graph instead (default: true for edges, false for nodes)

nodes: ElementDefinition<NodeData>[]?
edges: ElementDefinition<EdgeData>[]?
Fields of options
NameDescription
refs: boolean?

Carry what the payload names but does not hold as node references instead of throwing: an edge endpoint or a node parent that is not a node in the payload goes into the result's refs, indexed past its own nodes, to be resolved against the graph the payload loads into. This is how a chunk of a progressive cy.load() carries its cut edges in the columnar and wire forms. Default false: the payload must be self-contained.

Returns ColumnarElements

the equivalent columnar payload — self-contained, or with refs when that option is on and something was referenced

Example

const columns = cytoscape.toColumnarElements([{ data: { id: 'new' } }]);
console.log(cy.add(columns).length); // 1

Example graph and handle setup

Throws

if an edge lacks a source or target; without refs, also if an edge names a source or target that is not a node in the same payload — columnar payloads are self-contained unless they carry references; and on an unknown option