@gausszhou/litegraph-core / LGraph
Class: LGraph
Defined in: packages/core/src/LGraph.ts:70
Constructors
Constructor
new LGraph(o?): LGraph;Defined in: packages/core/src/LGraph.ts:74
Parameters
o?
SerializedLGraph<SerializedLGraphNode<LGraphNode>, SerializedLLink, SerializedLGraphGroup>
Returns
LGraph
Properties
_groups
_groups: LGraphGroup[] = [];Defined in: packages/core/src/LGraph.ts:110
_is_subgraph
_is_subgraph: boolean = false;Defined in: packages/core/src/LGraph.ts:121
_last_trigger_time
_last_trigger_time: number = 0;Defined in: packages/core/src/LGraph.ts:120
_nodes
_nodes: LGraphNode[] = [];Defined in: packages/core/src/LGraph.ts:109
_nodes_by_id
_nodes_by_id: Record<NodeID, LGraphNode> = {};Defined in: packages/core/src/LGraph.ts:111
_nodes_executable
_nodes_executable:
| LGraphNodeExecutable[]
| null = null;Defined in: packages/core/src/LGraph.ts:113
nodes that are executable sorted in execution order
_nodes_in_order
_nodes_in_order: LGraphNode[] = [];Defined in: packages/core/src/LGraph.ts:117
nodes that contain onExecute
_subgraph_node
_subgraph_node: Subgraph | null = null;Defined in: packages/core/src/LGraph.ts:122
_version
_version: number = -1;Defined in: packages/core/src/LGraph.ts:119
used to detect changes
catch_errors
catch_errors: boolean;Defined in: packages/core/src/LGraph.ts:87
config
config: LGraphConfig;Defined in: packages/core/src/LGraph.ts:89
custom data
elapsed_time
elapsed_time: number;Defined in: packages/core/src/LGraph.ts:93
errors_in_execution
errors_in_execution: boolean = false;Defined in: packages/core/src/LGraph.ts:130
execution_time
execution_time: number = 0;Defined in: packages/core/src/LGraph.ts:129
execution_timer_id
execution_timer_id: number = -1;Defined in: packages/core/src/LGraph.ts:128
extra
extra: Record<string, any> = {};Defined in: packages/core/src/LGraph.ts:92
to store custom data
filter
filter: string;Defined in: packages/core/src/LGraph.ts:86
fixedtime
fixedtime: number;Defined in: packages/core/src/LGraph.ts:94
fixedtime_lapse
fixedtime_lapse: number;Defined in: packages/core/src/LGraph.ts:95
globaltime
globaltime: number;Defined in: packages/core/src/LGraph.ts:96
inputs
inputs: Record<string, LGraphInput> = {};Defined in: packages/core/src/LGraph.ts:97
iteration
iteration: number;Defined in: packages/core/src/LGraph.ts:99
last_link_id
last_link_id: number;Defined in: packages/core/src/LGraph.ts:100
last_node_id
last_node_id: number;Defined in: packages/core/src/LGraph.ts:101
last_update_time
last_update_time: number;Defined in: packages/core/src/LGraph.ts:102
links
links: Record<LinkID, LLink> = {};Defined in: packages/core/src/LGraph.ts:103
list_of_graphcanvas
list_of_graphcanvas: LGraphCanvas[] = [];Defined in: packages/core/src/LGraph.ts:104
nodes_actioning
nodes_actioning: Record<NodeID, string | boolean> = {};Defined in: packages/core/src/LGraph.ts:125
nodes_executedAction
nodes_executedAction: Record<NodeID, string> = {};Defined in: packages/core/src/LGraph.ts:126
nodes_executing
nodes_executing: Record<NodeID, boolean> = {};Defined in: packages/core/src/LGraph.ts:124
outputs
outputs: Record<string, LGraphOutput> = {};Defined in: packages/core/src/LGraph.ts:98
runningtime
runningtime: number;Defined in: packages/core/src/LGraph.ts:105
starttime
starttime: number;Defined in: packages/core/src/LGraph.ts:106
status
status: LGraphStatus;Defined in: packages/core/src/LGraph.ts:107
supported_types
supported_types: string[] | null = null;Defined in: packages/core/src/LGraph.ts:72
vars
vars: Record<string, any> = {};Defined in: packages/core/src/LGraph.ts:90
DEFAULT_SUPPORTED_TYPES
static DEFAULT_SUPPORTED_TYPES: string[];Defined in: packages/core/src/LGraph.ts:71
Methods
add()
add(node, options?): LGraphNode | null;Defined in: packages/core/src/LGraph.ts:805
Adds a new node instance to this graph
Parameters
node
the instance of the node
options?
LGraphAddNodeOptions = {}
Returns
LGraphNode | null
addGroup()
addGroup(group): LGraphGroup;Defined in: packages/core/src/LGraph.ts:792
Parameters
group
Returns
addInput()
addInput(
name,
type,
value?
): void;Defined in: packages/core/src/LGraph.ts:1218
Tell this graph it has a global graph input of this type
Parameters
name
string
type
value?
any
Returns
void
addOutput()
addOutput(
name,
type,
value
): void;Defined in: packages/core/src/LGraph.ts:1341
Creates a global graph output
Parameters
name
string
type
value
any
Returns
void
afterChange()
afterChange(info?): void;Defined in: packages/core/src/LGraph.ts:1471
used to resend actions, called after any change is made to the graph
Parameters
info?
Returns
void
arrange()
arrange(margin?, layout?): void;Defined in: packages/core/src/LGraph.ts:616
Positions every node in a more readable manner
Parameters
margin?
number = 100
layout?
LayoutDirection = LayoutDirection.HORIZONTAL_LAYOUT
Returns
void
attachCanvas()
attachCanvas(graphCanvas): void;Defined in: packages/core/src/LGraph.ts:221
Attach Canvas to this graph
Parameters
graphCanvas
Returns
void
beforeChange()
beforeChange(info?): void;Defined in: packages/core/src/LGraph.ts:1463
used for undo, called before any change is made to the graph
Parameters
info?
Returns
void
change()
change(): void;Defined in: packages/core/src/LGraph.ts:1520
Returns
void
changeInputType()
changeInputType(name, type): boolean | undefined;Defined in: packages/core/src/LGraph.ts:1294
Changes the type of a global graph input
Parameters
name
string
type
Returns
boolean | undefined
changeOutputType()
changeOutputType(name, type): boolean | undefined;Defined in: packages/core/src/LGraph.ts:1403
Changes the type of a global graph output
Parameters
name
string
type
Returns
boolean | undefined
checkNodeTypes()
checkNodeTypes(): boolean;Defined in: packages/core/src/LGraph.ts:1163
Checks that the node type matches the node type registered, used when replacing a nodetype by a newer version during execution this replaces the ones using the old version with the new version
Returns
boolean
Method
checkNodeTypes
clear()
clear(): void;Defined in: packages/core/src/LGraph.ts:156
Removes all nodes from this graph
Returns
void
clearTriggeredSlots()
clearTriggeredSlots(): void;Defined in: packages/core/src/LGraph.ts:1505
clears the triggered slot animation in all links (stop visual animation)
Returns
void
computeExecutionOrder()
computeExecutionOrder<T>(only_onExecute?, set_level?): T[];Defined in: packages/core/src/LGraph.ts:436
This is more internal, it computes the executable nodes in order and returns it
Type Parameters
T
T extends LGraphNode
Parameters
only_onExecute?
boolean = false
set_level?
any
Returns
T[]
computeExecutionOrderRecursive()
computeExecutionOrderRecursive<T>(only_onExecute?, set_level?): Iterable<T>;Defined in: packages/core/src/LGraph.ts:424
Type Parameters
T
T extends LGraphNode
Parameters
only_onExecute?
boolean = false
set_level?
any
Returns
Iterable<T>
configure()
configure(data, keep_old?): boolean | undefined;Defined in: packages/core/src/LGraph.ts:1604
Configure a graph from a JSON string
Parameters
data
configure a graph from a JSON string
keep_old?
boolean
Returns
boolean | undefined
if there was any error parsing
connectionChange()
connectionChange(node, linkInfo?): void;Defined in: packages/core/src/LGraph.ts:1480
Parameters
node
linkInfo?
Returns
void
detachCanvas()
detachCanvas(graphCanvas): void;Defined in: packages/core/src/LGraph.ts:238
Detach Canvas to this graph
Parameters
graphCanvas
Returns
void
findNodeByTitle()
findNodeByTitle(title): LGraphNode | null;Defined in: packages/core/src/LGraph.ts:1093
Returns the first node that matches a name in its title
Parameters
title
string
the name of the node to search
Returns
LGraphNode | null
the node or null
findNodesByClass()
findNodesByClass<T>(type, result?): T[];Defined in: packages/core/src/LGraph.ts:1037
Returns a list of nodes that matches a class
Type Parameters
T
T extends LGraphNode
Parameters
type
new () => T
result?
T[] = []
Returns
T[]
a list with all the nodes of this type
findNodesByClassRecursive()
findNodesByClassRecursive<T>(type, result?): T[];Defined in: packages/core/src/LGraph.ts:1066
Returns a list of nodes that matches a class
Type Parameters
T
T extends LGraphNode
Parameters
type
new () => T
result?
T[] = []
Returns
T[]
a list with all the nodes of this type
findNodesByTitle()
findNodesByTitle(title): LGraphNode[];Defined in: packages/core/src/LGraph.ts:1107
Returns a list of nodes that matches a name
Parameters
title
string
the name of the node to search
Returns
a list with all the nodes with this name
findNodesByType()
findNodesByType(type, result?): LGraphNode[];Defined in: packages/core/src/LGraph.ts:1050
Returns a list of nodes that matches a type
Parameters
type
string
the name of the node type
result?
LGraphNode[] = []
Returns
a list with all the nodes of this type
findNodesByTypeRecursive()
findNodesByTypeRecursive(type, result?): LGraphNode[];Defined in: packages/core/src/LGraph.ts:1079
Returns a list of nodes that matches a type
Parameters
type
string
the name of the node type
result?
LGraphNode[] = []
Returns
a list with all the nodes of this type
getAncestors()
getAncestors(node): LGraphNode[];Defined in: packages/core/src/LGraph.ts:581
Returns all the nodes that could affect this one (ancestors) by crawling all the inputs recursively. It doesn't include the node itself
Parameters
node
Returns
an array with all the LGraphNodes that affect this node, in order of execution
getElapsedTime()
getElapsedTime(): number;Defined in: packages/core/src/LGraph.ts:677
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()
getFixedTime(): number;Defined in: packages/core/src/LGraph.ts:667
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
getGroupOnPos()
getGroupOnPos(x, y): LGraphGroup | null;Defined in: packages/core/src/LGraph.ts:1148
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 | null
the group or null
getInputData()
getInputData<T>(name): T | null;Defined in: packages/core/src/LGraph.ts:1251
Returns the current value of a global graph input
Type Parameters
T
T = any
Parameters
name
string
Returns
T | null
getNodeById()
getNodeById<T>(id): T | null;Defined in: packages/core/src/LGraph.ts:1010
Returns a node by its id.
Type Parameters
T
T extends LGraphNode = LGraphNode
Parameters
id
Returns
T | null
getNodeByIdRecursive()
getNodeByIdRecursive<T>(id): T | null;Defined in: packages/core/src/LGraph.ts:1018
Returns a node by its id.
Type Parameters
T
T extends LGraphNode = LGraphNode
Parameters
id
Returns
T | null
getNodeOnPos()
getNodeOnPos(
x,
y,
nodesList?,
margin?
): LGraphNode | null;Defined in: packages/core/src/LGraph.ts:1124
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
nodesList?
a list with all the nodes to search from, by default is all the nodes in the graph
margin?
number
Returns
LGraphNode | null
the node at this position or null
getOutputData()
getOutputData<T>(name): T | null;Defined in: packages/core/src/LGraph.ts:1364
Returns the current value of a global graph output
Type Parameters
T
T = any
Parameters
name
string
Returns
T | null
getRootGraph()
getRootGraph(): LGraph | null;Defined in: packages/core/src/LGraph.ts:139
Returns
LGraph | null
getSupportedTypes()
getSupportedTypes(): string[];Defined in: packages/core/src/LGraph.ts:132
Returns
string[]
getTime()
getTime(): number;Defined in: packages/core/src/LGraph.ts:658
Returns the amount of time the graph has been running in milliseconds
Returns
number
number of milliseconds the graph has been running
isLive()
isLive(): boolean;Defined in: packages/core/src/LGraph.ts:1490
returns if the graph is in live mode
Returns
boolean
iterateNodesInOrder()
iterateNodesInOrder(): Iterable<LGraphNode>;Defined in: packages/core/src/LGraph.ts:684
Iterates all nodes in this graph excluding subgraphs.
Returns
Iterable<LGraphNode>
iterateNodesInOrderRecursive()
iterateNodesInOrderRecursive(): Iterable<LGraphNode>;Defined in: packages/core/src/LGraph.ts:694
Iterates all nodes in this graph and subgraphs.
Returns
Iterable<LGraphNode>
iterateNodesOfClass()
iterateNodesOfClass<T>(ctor): Iterable<T>;Defined in: packages/core/src/LGraph.ts:709
Iterates all nodes in this graph excluding subgraphs.
Type Parameters
T
T extends LGraphNode
Parameters
ctor
new () => T
Returns
Iterable<T>
iterateNodesOfClassRecursive()
iterateNodesOfClassRecursive<T>(ctor): Iterable<T>;Defined in: packages/core/src/LGraph.ts:723
Iterates all nodes in this graph excluding subgraphs.
Type Parameters
T
T extends LGraphNode
Parameters
ctor
new () => T
Returns
Iterable<T>
iterateNodesOfTypeRecursive()
iterateNodesOfTypeRecursive<T>(type): Iterable<T>;Defined in: packages/core/src/LGraph.ts:737
Iterates all nodes in this graph excluding subgraphs.
Type Parameters
T
T extends LGraphNode
Parameters
type
string
Returns
Iterable<T>
iterateParentGraphs()
iterateParentGraphs(): Iterable<LGraph>;Defined in: packages/core/src/LGraph.ts:147
Returns
Iterable<LGraph>
load()
load(url, callback?): void;Defined in: packages/core/src/LGraph.ts:1695
Parameters
url
string
callback?
(data) => void
Returns
void
onAction()
onAction(
action,
param,
options?
): void;Defined in: packages/core/src/LGraph.ts:1191
Parameters
action
any
param
any
options?
action_call?
string
Returns
void
onAfterChange()?
onAfterChange?(graph, info): void;Defined in: packages/core/src/LGraph.ts:882
Called after the graph is changed
Parameters
graph
LGraph
info
any
Returns
void
onAfterExecute()?
onAfterExecute?(): void;Defined in: packages/core/src/LGraph.ts:901
Returns
void
onAfterStep()?
onAfterStep?(): void;Defined in: packages/core/src/LGraph.ts:899
Returns
void
onBeforeChange()?
onBeforeChange?(graph, info): void;Defined in: packages/core/src/LGraph.ts:877
Called before the graph is changed
Parameters
graph
LGraph
info
any
Returns
void
onBeforeStep()?
onBeforeStep?(): void;Defined in: packages/core/src/LGraph.ts:898
Returns
void
onChange()?
onChange?(graph): void;Defined in: packages/core/src/LGraph.ts:1517
Parameters
graph
LGraph
Returns
void
onConfigure()?
onConfigure?(data): void;Defined in: packages/core/src/LGraph.ts:917
Called by LGraph.configure
Parameters
data
Returns
void
onConnectionChange()?
onConnectionChange?(node): void;Defined in: packages/core/src/LGraph.ts:1478
Parameters
node
Returns
void
onExecuteStep()?
onExecuteStep?(): void;Defined in: packages/core/src/LGraph.ts:900
Returns
void
onGetLinkMenuOptions()?
onGetLinkMenuOptions?(options, link): ContextMenuItem[];Defined in: packages/core/src/LGraph.ts:904
Parameters
options
link
Returns
onGetNodeMenuOptions()?
onGetNodeMenuOptions?(options, node): ContextMenuItem[];Defined in: packages/core/src/LGraph.ts:903
Parameters
options
node
Returns
onInputAdded()?
onInputAdded?(
name,
type,
value
): void;Defined in: packages/core/src/LGraph.ts:1239
Parameters
name
string
type
value
any
Returns
void
onInputRemoved()?
onInputRemoved?(name): void;Defined in: packages/core/src/LGraph.ts:1317
Parameters
name
string
Returns
void
onInputRenamed()?
onInputRenamed?(oldName, newName): void;Defined in: packages/core/src/LGraph.ts:1259
Parameters
oldName
string
newName
string
Returns
void
onInputsOutputsChange()?
onInputsOutputsChange?(): void;Defined in: packages/core/src/LGraph.ts:1203
Returns
void
onInputTypeChanged()?
onInputTypeChanged?(
name,
oldType,
newType
): void;Defined in: packages/core/src/LGraph.ts:1291
Parameters
name
string
oldType
newType
Returns
void
onNodeAdded()?
onNodeAdded?(node, options): void;Defined in: packages/core/src/LGraph.ts:888
Called when a new node is added
Parameters
node
the instance of the node
options
Returns
void
onNodeConnectionChange()?
onNodeConnectionChange?(
kind,
node,
slot,
target_node?,
target_slot?
): void;Defined in: packages/core/src/LGraph.ts:910
Called when a node's connection is changed
Parameters
kind
node
the instance of the node
slot
number
target_node?
target_slot?
number
Returns
void
onNodeRemoved()?
onNodeRemoved?(node, options): void;Defined in: packages/core/src/LGraph.ts:894
Called when a node is removed
Parameters
node
the instance of the node
options
Returns
void
onNodeTrace()?
onNodeTrace?(node, message): void;Defined in: packages/core/src/LGraph.ts:919
Parameters
node
message
string
Returns
void
onOutputAdded()?
onOutputAdded?(
name,
type,
value
): void;Defined in: packages/core/src/LGraph.ts:1338
Parameters
name
string
type
value
any
Returns
void
onOutputRemoved()?
onOutputRemoved?(name): void;Defined in: packages/core/src/LGraph.ts:1426
Parameters
name
string
Returns
void
onOutputRenamed()?
onOutputRenamed?(oldName, newName): void;Defined in: packages/core/src/LGraph.ts:1372
Parameters
oldName
string
newName
string
Returns
void
onOutputTypeChanged()?
onOutputTypeChanged?(
name,
oldType,
newType
): void;Defined in: packages/core/src/LGraph.ts:1400
Parameters
name
string
oldType
newType
Returns
void
onPlayEvent()?
onPlayEvent?(): void;Defined in: packages/core/src/LGraph.ts:896
Returns
void
onSerialize()?
onSerialize?(data): void;Defined in: packages/core/src/LGraph.ts:1546
Parameters
data
Returns
void
onStopEvent()?
onStopEvent?(): void;Defined in: packages/core/src/LGraph.ts:897
Returns
void
onTrigger()?
onTrigger?(action, param): void;Defined in: packages/core/src/LGraph.ts:1202
Parameters
action
any
param
any
Returns
void
remove()
remove(node, options?): void;Defined in: packages/core/src/LGraph.ts:922
Removes a node from the graph
Parameters
node
options?
Returns
void
removeInput()
removeInput(name): boolean;Defined in: packages/core/src/LGraph.ts:1320
Removes a global graph input
Parameters
name
string
Returns
boolean
removeLink()
removeLink(linkId): void;Defined in: packages/core/src/LGraph.ts:1535
Destroys a link
Parameters
linkId
Returns
void
removeOutput()
removeOutput(name): boolean;Defined in: packages/core/src/LGraph.ts:1429
Removes a global graph output
Parameters
name
string
Returns
boolean
renameInput()
renameInput(old_name, name): boolean | undefined;Defined in: packages/core/src/LGraph.ts:1262
Changes the name of a global graph input
Parameters
old_name
string
name
string
Returns
boolean | undefined
renameOutput()
renameOutput(old_name, name): boolean | undefined;Defined in: packages/core/src/LGraph.ts:1375
Renames a global graph output
Parameters
old_name
string
name
string
Returns
boolean | undefined
runStep()
runStep(
num?,
do_not_catch_errors?,
limit?
): void;Defined in: packages/core/src/LGraph.ts:327
Run N steps (cycles) of the graph
Parameters
num?
number = 1
number of steps to run, default is 1
do_not_catch_errors?
boolean = false
if you want to try/catch errors
limit?
number
Returns
void
sendActionToCanvas()
sendActionToCanvas(action, params?): void;Defined in: packages/core/src/LGraph.ts:778
Parameters
action
any
params?
any[] = []
Returns
void
sendEventToAllNodes()
sendEventToAllNodes(
eventName,
params?,
mode?
): void;Defined in: packages/core/src/LGraph.ts:749
Sends an event to all the nodes, useful to trigger stuff
Parameters
eventName
string
the name of the event (function to be called)
params?
any[] = []
parameters in array format
mode?
NodeMode = NodeMode.ALWAYS
Returns
void
serialize()
serialize<T>(): T;Defined in: packages/core/src/LGraph.ts:1549
Creates a Object containing all the info about this graph, it can be serialized
Type Parameters
T
T extends SerializedLGraph<SerializedLGraphNode<LGraphNode>, SerializedLLink, SerializedLGraphGroup>
Returns
T
setDirtyCanvas()
setDirtyCanvas(fg?, bg?): void;Defined in: packages/core/src/LGraph.ts:1530
Parameters
fg?
boolean = false
bg?
boolean = false
Returns
void
setInputData()
setInputData(name, data): void;Defined in: packages/core/src/LGraph.ts:1242
Assign a data to the global graph input
Parameters
name
string
data
any
Returns
void
setOutputData()
setOutputData(name, value): void;Defined in: packages/core/src/LGraph.ts:1355
Assign a data to the global output
Parameters
name
string
value
string
Returns
void
start()
start(interval?): void;Defined in: packages/core/src/LGraph.ts:255
Starts running this graph every interval milliseconds.
Parameters
interval?
number
amount of milliseconds between executions, if 0 then it renders to the monitor refresh rate
Returns
void
stop()
stop(): void;Defined in: packages/core/src/LGraph.ts:301
Stops the execution loop of the graph
Returns
void
trigger()
trigger(action, param): void;Defined in: packages/core/src/LGraph.ts:1205
Parameters
action
any
param
any
Returns
void
triggerSlot()
triggerSlot(action, param): void;Defined in: packages/core/src/LGraph.ts:1211
Parameters
action
any
param
any
Returns
void
updateExecutionOrder()
updateExecutionOrder(): void;Defined in: packages/core/src/LGraph.ts:413
Updates the graph execution order according to relevance of the nodes (nodes with only outputs have more relevance than nodes with only inputs.
Returns
void