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.
Class ยท extends Element
Represents a new Graph.
new Graph(schema: GraphSchema, options?: GraphOptions)
Creates a new Graph.
Parameters
schema (GraphSchema): The graph schema.options (GraphOptions, optional, default {}): The graph configuration. Optional.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.
get selectedItem(): { edgeId: string | number; id: string | number; type: string }
The currently selected item in the graph, or null if nothing is selected.
createEdge(edge: EdgeData, edgeId: string | number, _batching?: boolean): void
Add an edge to the graph.
Parameters
edge (EdgeData): The edge to add.edgeId (string | number): The edge id for the new edge._batching (boolean, optional): Internal flag, unused.createNode(node: NodeData, _nodeSchema?: NodeSchema, _batching?: boolean): void
Add a node to the graph.
Parameters
node (NodeData): The node to add._nodeSchema (NodeSchema, optional): Internal, unused._batching (boolean, optional): Internal, unused.deleteEdge(edgeId: Id): void
Delete an edge from the graph.
Parameters
edgeId (Id): The edge to delete.deleteNode(nodeId: string | number): void
Delete a node from the graph.
Parameters
nodeId (string | number): The node to delete.deselectItem(): void
Deselect the currently selected item in the graph.
destroy(): void
Destroy the graph. Clears the graph from the DOM and removes all event listeners associated with the graph.
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(): number
Get the current scale of the graph.
Returns number: The current scale of the graph.
getWindowToGraphPosition(pos: object): { x: number; y: number }
Convert a position in window space to a position in graph space.
Parameters
pos (object): A position in the window, as an object containing x and y.
pos.x (number): The x position.pos.y (number): The y position.Returns { x: number; y: number }: The position in the graph based on the given window position, as an object
containing x and y.
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
eventName (K): The name of the event to listen for.callback ((detail: K extends keyof GraphEventMap ? GraphEventMap[K] : unknown) => void): The callback to call when the event is triggered.selectEdge(edge: EdgeData, edgeId: string | number): void
Select an edge in the current graph.
Parameters
edge (EdgeData): The edge to selectedgeId (string | number): The edge id of the edge to selectselectNode(node: NodeData): void
Select a node in the current graph.
Parameters
node (NodeData): The node to selectsetGraphPosition(posX: number, posY: number): void
Set the center of the viewport to the given position.
Parameters
posX (number): The x position to set the center of the viewport to.posY (number): The y position to set the center of the viewport to.setGraphScale(scale: number): void
Set the scale of the graph.
Parameters
scale (number): The new scale of the graph.setNodeAttributeErrorState(nodeId: string | number, attributeName: string, value: boolean): void
Set the error state of a node attribute.
Parameters
nodeId (string | number): The node to update.attributeName (string): The name of the attribute to update.value (boolean): Whether the attribute should be set in the error state.updateNodeAttribute(nodeId: string | number, attributeName: string, value: unknown): void
Update the value of an attribute of a node.
Parameters
nodeId (string | number): The node to update.attributeName (string): The name of the attribute to update.value (unknown): The new value for the attribute.updateNodePosition(nodeId: string | number, pos: object): void
Update the position of a node.
Parameters
nodeId (string | number): The node to add.pos (object): The new position, given as an object containing x and y properties.
pos.x (number): The x position.pos.y (number): The y position.updateNodeType(nodeId: string | number, nodeType: string | number): void
Update the type of a node.
Parameters
nodeId (string | number): The node to update.nodeType (string | number): The new type for the node.