#

API Docs for:
Show: Inherited Protected Private Deprecated

# LGraph Class

Defined in: `../src/litegraph.js:274`

LGraph is the class that contain a full graph. We instantiate one and add nodes to it, and then we can run the execution loop.

## Constructor

### `LGraph`

()

Defined in `../src/litegraph.js:274`

- Index
- Methods

## Item Index

### Methods

- add
- attachCanvas
- clear
- configure
- detachCanvas
- findNodesByClass
- findNodesByName
- findNodesByType
- getElapsedTime
- getFixedTime
- getNodeById
- getNodeOnPos
- getTime
- isLive
- remove
- runStep
- sendEventToAllNodes
- serialize
- setInputData
- setInputData
- start
- stop execution
- updateExecutionOrder

## Methods

### `add`

(

- `node`

)

Defined in `../src/litegraph.js:660`

Adds a new node instasnce to this graph

#### Parameters:

- `node` LGraphNode

  the instance of the node

### `attachCanvas`

(

- `graph_canvas`

)

Defined in `../src/litegraph.js:343`

Attach Canvas to this graph

#### Parameters:

- `graph_canvas` GraphCanvas

### `clear`

()

Defined in `../src/litegraph.js:298`

Removes all nodes from this graph

### `configure`

(

- `str`

)

Defined in `../src/litegraph.js:1154`

Configure a graph from a JSON string

#### Parameters:

- `str` String

  configure a graph from a JSON string

### `detachCanvas`

(

- `graph_canvas`

)

Defined in `../src/litegraph.js:362`

Detach Canvas from this graph

#### Parameters:

- `graph_canvas` GraphCanvas

### `findNodesByClass`

(

- `classObject`

)
Array

Defined in `../src/litegraph.js:790`

Returns a list of nodes that matches a class

#### Parameters:

- `classObject` Class

  the class itself (not an string)

#### Returns:

Array:

a list with all the nodes of this type

### `findNodesByName`

(

- `name`

)
Array

Defined in `../src/litegraph.js:823`

Returns a list of nodes that matches a name

#### Parameters:

- `name` String

  the name of the node to search

#### Returns:

Array:

a list with all the nodes with this name

### `findNodesByType`

(

- `type`

)
Array

Defined in `../src/litegraph.js:806`

Returns a list of nodes that matches a type

#### Parameters:

- `type` String

  the name of the node type

#### Returns:

Array:

a list with all the nodes of this type

### `getElapsedTime`

() Number

Defined in `../src/litegraph.js:605`

Returns the amount of time it took to compute the latest iteration. Take into account that this number could be not correct if the nodes are using graphical actions

#### Returns:

Number:

number of milliseconds it took the last cycle

### `getFixedTime`

() Number

Defined in `../src/litegraph.js:594`

Returns the amount of time accumulated using the fixedtime_lapse var. This is used in context where the time increments should be constant

#### Returns:

Number:

number of milliseconds the graph has been running

### `getNodeById`

(

- `id`

)

Defined in `../src/litegraph.js:778`

Returns a node by its id.

#### Parameters:

- `id` String

### `getNodeOnPos`

(

- `x`
- `y`
- `nodes_list`

)
Array

Defined in `../src/litegraph.js:839`

Returns the top-most node in this position of the canvas

#### Parameters:

- `x` Number

  the x coordinate in canvas space

- `y` Number

  the y coordinate in canvas space

- `nodes_list` Array

  a list with all the nodes to search from, by default is all the nodes in the graph

#### Returns:

Array:

a list with all the nodes that intersect this coordinate

### `getTime`

() Number

Defined in `../src/litegraph.js:583`

Returns the amount of time the graph has been running in milliseconds

#### Returns:

Number:

number of milliseconds the graph has been running

### `isLive`

()

Defined in `../src/litegraph.js:1081`

returns if the graph is in live mode

### `remove`

(

- `node`

)

Defined in `../src/litegraph.js:709`

Removes a node from the graph

#### Parameters:

- `node` LGraphNode

  the instance of the node

### `runStep`

(

- `num`

)

Defined in `../src/litegraph.js:429`

Run N steps (cycles) of the graph

#### Parameters:

- `num` Number

  number of steps to run, default is 1

### `sendEventToAllNodes`

(

- `eventname`
- `params`

)

Defined in `../src/litegraph.js:617`

Sends an event to all the nodes, useful to trigger stuff

#### Parameters:

- `eventname` String

  the name of the event (function to be called)

- `params` Array

  parameters in array format

### `serialize`

() Object

Defined in `../src/litegraph.js:1118`

Creates a Object containing all the info about this graph, it can be serialized

#### Returns:

Object:

value of the node

### `setInputData`

(

- `name`
- `value`

)

Defined in `../src/litegraph.js:1026`

Assigns a value to all the nodes that matches this name. This is used to create global variables of the node that can be easily accesed from the outside of the graph

#### Parameters:

- `name` String

  the name of the node

- `value`

  value to assign to this node

### `setInputData`

(

- `name`

)

Defined in `../src/litegraph.js:1041`

Returns the value of the first node with this name. This is used to access global variables of the graph from the outside

#### Parameters:

- `name` String

  the name of the node

#### Returns:

:

value of the node

### `start`

(

- `interval`

)

Defined in `../src/litegraph.js:380`

Starts running this graph every interval milliseconds.

#### Parameters:

- `interval` Number

  amount of milliseconds between executions, default is 1

### `stop execution`

()

Defined in `../src/litegraph.js:407`

Stops the execution loop of the graph

### `updateExecutionOrder`

()

Defined in `../src/litegraph.js:485`

Updates the graph execution order according to relevance of the nodes (nodes with only outputs have more relevance than nodes with only inputs.