Shader Graph API / Graph
Represents a new Graph.
-
Element↳
Graph
- destroy
- selectNode
- selectEdge
- deselectItem
- createEdge
- createNode
- updateNodePosition
- updateNodeAttribute
- updateNodeType
- deleteNode
- deleteEdge
- setGraphPosition
- getGraphPosition
- setGraphScale
- getGraphScale
- getWindowToGraphPosition
- on
• new Graph(schema, options?)
Creates a new Graph.
| Name | Type | Description |
|---|---|---|
schema |
any |
The graph schema. |
options |
Object |
The graph configuration. Optional. |
options.initialData |
any |
The graph data to initialize the graph with. |
options.dom |
HTMLElement |
If supplied, the graph will be attached to this element. |
options.contextMenuItems |
any[] |
The context menu items to add to the graph. Optional. |
options.readOnly |
boolean |
Whether the graph is read only. Optional. Defaults to false. |
options.passiveUIEvents |
boolean |
If true, the graph will not update its data and view upon user interaction. Instead, these interactions can be handled explicitly by listening to fired events. Optional. Defaults to false. |
options.incrementNodeNames |
boolean |
Whether the graph should increment the node name when a node with the same name already exists. Optional. Defaults to false. |
options.restrictTranslate |
boolean |
Whether the graph should restrict the translate graph operation to the graph area. Optional. Defaults to false. |
options.edgeHoverEffect |
boolean |
Whether the graph should show an edge highlight effect when the mouse is hovering over edges. Optional. Defaults to true. |
options.includeFonts |
boolean |
If true the graph will include a default font style. Defaults to true. |
options.defaultStyles |
any |
Used to override the graph's default styling. Check ./constants.js for a full list of style properties. |
Element.constructor
• Readonly get data(): any
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.
readonly
any
▸ destroy(): void
Destroy the graph. Clears the graph from the DOM and removes all event listeners associated with the graph.
void
▸ selectNode(node): void
Select a node in the current graph.
| Name | Type | Description |
|---|---|---|
node |
any |
The node to select |
void
▸ selectEdge(edge, edgeId): void
Select an edge in the current graph.
| Name | Type | Description |
|---|---|---|
edge |
any |
The edge to select |
edgeId |
number |
The edge id of the edge to select |
void
▸ deselectItem(): void
Deselect the currently selected item in the graph.
void
▸ createEdge(edge, edgeId): void
Add an edge to the graph
| Name | Type | Description |
|---|---|---|
edge |
any |
The edge to add |
edgeId |
number |
The edge id for the new edge |
void
▸ createNode(node): void
Add a node to the graph
| Name | Type | Description |
|---|---|---|
node |
any |
The node to add |
void
▸ updateNodePosition(nodeId, pos): void
Update the position of a node
| Name | Type | Description |
|---|---|---|
nodeId |
number |
The node to add |
pos |
any |
The new position, given as an object containing x and y properties |
void
▸ updateNodeAttribute(nodeId, attributeName, value): void
Update the value of an attribute of a node
| Name | Type | Description |
|---|---|---|
nodeId |
number |
The node to update |
attributeName |
string |
The name of the attribute to update |
value |
any |
The new value for the attribute |
void
▸ updateNodeType(nodeId, nodeType): void
Update the type of a node
| Name | Type | Description |
|---|---|---|
nodeId |
number |
The node to update |
nodeType |
string |
The new type for the node |
void
▸ deleteNode(nodeId): void
Delete a node from the graph
| Name | Type | Description |
|---|---|---|
nodeId |
number |
The node to delete |
void
▸ deleteEdge(edgeId): void
Delete an edge from the graph
| Name | Type | Description |
|---|---|---|
edgeId |
string |
The edge to delete |
void
▸ setGraphPosition(posX, posY): void
Set the center of the viewport to the given position
| Name | Type | Description |
|---|---|---|
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 |
void
▸ getGraphPosition(): any
Get the current center position of the viewport in the graph
any
The current center position of the viewport in the graph as an object containing x and y
▸ setGraphScale(scale): void
Set the scale of the graph
| Name | Type | Description |
|---|---|---|
scale |
number |
The new scale of the graph |
void
▸ getGraphScale(): number
Get the current scale of the graph
number
The current scale of the graph
▸ getWindowToGraphPosition(pos): any
Convert a position in window space to a position in graph space
| Name | Type | Description |
|---|---|---|
pos |
any |
A position in the window, as an object containing x and y |
any
The position in the graph based on the given window position, as an object containing x and y
▸ on(eventName, callback): void
Add an event listener to the graph
| Name | Type | Description |
|---|---|---|
eventName |
string |
The name of the event to listen for |
callback |
Function |
The callback to call when the event is triggered |
void