Contents

PCUI Graph API: All Pages

The API reference of @playcanvas/pcui-graph 5.2.5: the Graph component, a node-graph editor built on PCUI.

The same pages as Markdown, for AI agents: llms-full.txt.

Contents

Graph

Class ยท extends Element

Source: https://github.com/playcanvas/pcui-graph/blob/365fae3285dc4125d4bd66338bc4e6d90628770b/src/index.ts#L64

Represents a new Graph.

Constructors

constructor

new Graph(schema: GraphSchema, options?: GraphOptions)

Creates a new Graph.

Parameters

Accessors

data

get data(): GraphData

The current graph data. Contains an object with any nodes and edges present in the graph. This can be passed into the graph constructor to reload the current graph.

selectedItem

get selectedItem(): { edgeId: string | number; id: string | number; type: string }

The currently selected item in the graph, or null if nothing is selected.

Methods

createEdge

createEdge(edge: EdgeData, edgeId: string | number, _batching?: boolean): void

Add an edge to the graph.

Parameters

createNode

createNode(node: NodeData, _nodeSchema?: NodeSchema, _batching?: boolean): void

Add a node to the graph.

Parameters

deleteEdge

deleteEdge(edgeId: Id): void

Delete an edge from the graph.

Parameters

deleteNode

deleteNode(nodeId: string | number): void

Delete a node from the graph.

Parameters

deselectItem

deselectItem(): void

Deselect the currently selected item in the graph.

destroy

destroy(): void

Destroy the graph. Clears the graph from the DOM and removes all event listeners associated with the graph.

getGraphPosition

getGraphPosition(): { x: number; y: number }

Get the current center position of the viewport in the graph.

Returns { x: number; y: number }: The current center position of the viewport in the graph as an object containing x and y.

getGraphScale

getGraphScale(): number

Get the current scale of the graph.

Returns number: The current scale of the graph.

getWindowToGraphPosition

getWindowToGraphPosition(pos: object): { x: number; y: number }

Convert a position in window space to a position in graph space.

Parameters

Returns { x: number; y: number }: The position in the graph based on the given window position, as an object containing x and y.

on

on<K extends string>(eventName: K, callback: (detail: K extends keyof GraphEventMap ? GraphEventMap[K] : unknown) => void): void

Add an event listener to the graph.

Parameters

selectEdge

selectEdge(edge: EdgeData, edgeId: string | number): void

Select an edge in the current graph.

Parameters

selectNode

selectNode(node: NodeData): void

Select a node in the current graph.

Parameters

setGraphPosition

setGraphPosition(posX: number, posY: number): void

Set the center of the viewport to the given position.

Parameters

setGraphScale

setGraphScale(scale: number): void

Set the scale of the graph.

Parameters

setNodeAttributeErrorState

setNodeAttributeErrorState(nodeId: string | number, attributeName: string, value: boolean): void

Set the error state of a node attribute.

Parameters

updateNodeAttribute

updateNodeAttribute(nodeId: string | number, attributeName: string, value: unknown): void

Update the value of an attribute of a node.

Parameters

updateNodePosition

updateNodePosition(nodeId: string | number, pos: object): void

Update the position of a node.

Parameters

updateNodeType

updateNodeType(nodeId: string | number, nodeType: string | number): void

Update the type of a node.

Parameters