#

API Docs for:
Show: Inherited Protected Private Deprecated

# LGraph Class

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

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`

(

- `o`

)

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

#### Parameters:

- `o` Object

  data from previous serialization [optional]

- Index
- Methods

## Item Index

### Methods

- add
- addGlobalInput
- addGlobalOutput
- arrange
- attachCanvas
- changeGlobalInputType
- changeGlobalOutputType
- clear
- configure
- detachCanvas
- findNodesByClass
- findNodesByTitle
- findNodesByType
- getAncestors
- getElapsedTime
- getFixedTime
- getGlobalInputData
- getGlobalOutputData
- getGroupOnPos
- getNodeById
- getNodeOnPos
- getOutputData
- getTime
- isLive
- remove
- removeGlobalInput
- removeGlobalOutput
- renameGlobalInput
- renameGlobalOutput
- runStep
- sendEventToAllNodes
- serialize
- setGlobalInputData
- setGlobalOutputData
- setInputData
- start
- stop execution
- updateExecutionOrder

## Methods

### `add`

(

- `node`

)

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

Adds a new node instasnce to this graph

#### Parameters:

- `node` LGraphNode

  the instance of the node

### `addGlobalInput`

(

- `name`
- `type`
- `value`

)

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

Tell this graph it has a global graph input of this type

#### Parameters:

- `name` String
- `type` String
- `value`

  [optional]

### `addGlobalOutput`

(

- `name`
- `type`
- `value`

)

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

Creates a global graph output

#### Parameters:

- `name` String
- `type` String
- `value`

### `arrange`

()

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

Positions every node in a more readable manner

### `attachCanvas`

(

- `graph_canvas`

)

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

Attach Canvas to this graph

#### Parameters:

- `graph_canvas` GraphCanvas

### `changeGlobalInputType`

(

- `name`
- `type`

)

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

Changes the type of a global graph input

#### Parameters:

- `name` String
- `type` String

### `changeGlobalOutputType`

(

- `name`
- `type`

)

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

Changes the type of a global graph output

#### Parameters:

- `name` String
- `type` String

### `clear`

()

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

Removes all nodes from this graph

### `configure`

(

- `str`
- `returns`

)

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

Configure a graph from a JSON string

#### Parameters:

- `str` String

  configure a graph from a JSON string

- `returns` Boolean

  if there was any error parsing

### `detachCanvas`

(

- `graph_canvas`

)

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

Detach Canvas from this graph

#### Parameters:

- `graph_canvas` GraphCanvas

### `findNodesByClass`

(

- `classObject`

)
Array

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

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

### `findNodesByTitle`

(

- `name`

)
Array

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

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:1121`

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

### `getAncestors`

() Array

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

Returns all the nodes that could affect this one (ancestors) by crawling all the inputs recursively. It doesnt include the node itself

#### Returns:

Array:

an array with all the LGraphNodes that affect this node, in order of execution

### `getElapsedTime`

() Number

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

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:881`

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

### `getGlobalInputData`

(

- `name`

)

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

Returns the current value of a global graph input

#### Parameters:

- `name` String

#### Returns:

:

the data

### `getGlobalOutputData`

(

- `name`

)

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

Returns the current value of a global graph output

#### Parameters:

- `name` String

#### Returns:

:

the data

### `getGroupOnPos`

(

- `x`
- `y`

)
LGraphGroup

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

Returns the top-most group in that position

#### Parameters:

- `x` Number

  the x coordinate in canvas space

- `y` Number

  the y coordinate in canvas space

#### Returns:

LGraphGroup:

the group or null

### `getNodeById`

(

- `id`

)

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

Returns a node by its id.

#### Parameters:

- `id` Number

### `getNodeOnPos`

(

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

)
LGraphNode

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

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:

LGraphNode:

the node at this position or null

### `getOutputData`

(

- `name`

)

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

Returns the current value of a global graph output (sames as getGlobalOutputData)

#### Parameters:

- `name` String

#### Returns:

:

the data

### `getTime`

() Number

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

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:1471`

returns if the graph is in live mode

### `remove`

(

- `node`

)

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

Removes a node from the graph

#### Parameters:

- `node` LGraphNode

  the instance of the node

### `removeGlobalInput`

(

- `name`
- `type`

)

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

Removes a global graph input

#### Parameters:

- `name` String
- `type` String

### `removeGlobalOutput`

(

- `name`

)

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

Removes a global graph output

#### Parameters:

- `name` String

### `renameGlobalInput`

(

- `old_name`
- `new_name`

)

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

Changes the name of a global graph input

#### Parameters:

- `old_name` String
- `new_name` String

### `renameGlobalOutput`

(

- `old_name`
- `new_name`

)

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

Renames a global graph output

#### Parameters:

- `old_name` String
- `new_name` String

### `runStep`

(

- `num`

)

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

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:904`

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:1506`

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

#### Returns:

Object:

value of the node

### `setGlobalInputData`

(

- `name`
- `data`

)

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

Assign a data to the global graph input

#### Parameters:

- `name` String
- `data`

### `setGlobalOutputData`

(

- `name`
- `value`

)

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

Assign a data to the global output

#### Parameters:

- `name` String
- `value` String

### `setInputData`

(

- `name`
- `data`

)

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

Assign a data to the global graph input (same as setGlobalInputData)

#### Parameters:

- `name` String
- `data`

### `start`

(

- `interval`

)

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

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:554`

Stops the execution loop of the graph

### `updateExecutionOrder`

()

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

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