You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: guides/README.md
+50-22
Original file line number
Diff line number
Diff line change
@@ -1,38 +1,50 @@
1
1
# LiteGraph
2
2
3
-
Here is a list of useful info when working with LiteGraph
3
+
Here is a list of useful info when working with LiteGraph.
4
+
The library is divided in four levels:
5
+
***LGraphNode**: the base class of a node (this library uses is own system of inheritance)
6
+
***LGraph**: the container of a whole graph made of nodes
7
+
***LGraphCanvas**: the class in charge of rendering/interaction with the nodes inside the browser.
8
+
9
+
And in ```the src/``` folder there is also another class included:
10
+
***LiteGraph.Editor**: A wrapper around LGraphCanvas that adds buttons around it.
4
11
5
12
## LGraphNode
6
13
7
14
LGraphNode is the base class used for all the nodes classes.
8
15
To extend the other classes all the methods contained in LGraphNode.prototype are copyed to the classes when registered.
9
16
10
-
When you create a new node type you do not have to inherit from that class, when the node is registered all the methods are copied to your node prototype.
17
+
When you create a new node type you do not have to inherit from that class, when the node is registered all the methods are copied to your node prototype. This is done inside the functions ```LiteGraph.registerNodeType(...)```.
11
18
12
19
Here is an example of how to create your own node:
You can draw something inside a node using the callbacks ```onDrawForeground``` and ```onDrawBackground```. The only difference is that onDrawForeground gets called in Live Mode and onDrawBackground not.
121
134
122
-
You do not have to worry about the coordinates system, [0,0] is the top-left corner of the node content area (not the title).
135
+
Both functions receive the [Canvas2D rendering context](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D) and the LGraphCanvas instance where the node is being rendered.
136
+
137
+
You do not have to worry about the coordinates system, (0,0) is the top-left corner of the node content area (not the title).
123
138
124
139
```js
125
-
node.onDrawForeground=function(canvas, ctx)
140
+
node.onDrawForeground=function(ctx, graphcanvas)
126
141
{
127
142
if(this.flags.collapsed)
128
143
return;
@@ -202,6 +217,19 @@ function MyNode()
202
217
}
203
218
```
204
219
220
+
# Execution Flow
221
+
To execute a graph you must call ```graph.runStep()```.
222
+
223
+
This function will call the method ```node.onExecute()``` for every node in the graph.
224
+
225
+
The order of execution is determined by the system according to the morphology of the graph (nodes without inputs are considered level 0, then nodes connected to nodes of level 0 are level 1, and so on). This order is computed only when the graph morphology changes (new nodes are created, connections change).
226
+
227
+
It is up to the developer to decide how to handle inputs and outputs from inside the node.
228
+
229
+
The data send through outputs using ```this.setOutputData(0,data)``` is stored in the link, so if the node connected through that link does ```this.getInputData(0)``` it will receive the same data sent.
230
+
231
+
For rendering, the nodes are executed according to their order in the ```graph._nodes``` array, which changes when the user interact with the GraphCanvas (clicked nodes are moved to the back of the array so they are rendered the last).
Copy file name to clipboardexpand all lines: src/litegraph.d.ts
+3-3
Original file line number
Diff line number
Diff line change
@@ -209,11 +209,11 @@ export const LiteGraph: {
209
209
/** if set to true some nodes like Formula would be allowed to evaluate code that comes from unsafe sources (like node configuration), which could lead to exploits */
0 commit comments