Flowgraph Graph
Core graph class that holds nodes, links, and pins for a single flowgraph. Manages node creation/deletion, execution planning, variable storage, and serialization. Each manager contains one or more gr
Core graph class that holds nodes, links, and pins for a single flowgraph. Manages node creation/deletion, execution planning, variable storage, and serialization. Each manager contains one or more graphs organized in a parent-child hierarchy.
No public module exports - instantiated internally by the flowgraph manager.
Purpose
A graph is the fundamental container in the flowgraph system. It holds:
- Nodes - the logic units (keyed by ID)
- Links - connections between pins (keyed by ID)
- Pins - all pin objects across all nodes (keyed by ID)
- Variables - graph-scoped variable storage
Class (C) - Key Methods
| Method | Signature | Description |
|---|---|---|
init | (mgr, name, forceId) | Sets up graph state: nodes/links/pins tables, variable storage, hook list, view position. |
getParent | () | Returns the parent graph from the manager's graph table. |
getChildren | () | Returns child graphs sorted by ID. |
getRootGraph | () | Walks up the parent chain to find the root graph. |
createNode | (nodeType, ...) | Creates a node of the given type, adds it to the graph. |
deleteNode | (node) | Removes a node and its links from the graph. |
createLink | (sourcePin, targetPin) | Creates a link between two pins. |
deleteLink | (link) | Removes a link, cleaning up pin references. |
gatherNodesAndLinks | (rNodes, rLinks, interInfo) | Recursively collects all nodes and links including integrated macros. |
plan | () | Builds execution order by analyzing node connections, flow dependencies, and colors. Generates compiled trigger functions for each root node. Only runs on root graphs (not macros or child graphs). |
clear | () | Destroys all child graphs, nodes, links, and pins. |
setDirty | (dirty, startFromRoot) | Marks the graph (and children) as needing re-planning. |
getDirtyChildren | (dirtyChildren) | Finds child graphs with dirty macros. |
clearVariableChangesChildren | () | Recursively clears variable change tracking. |
_executionStarted | () | Calls __executionStarted() on all nodes. |
_executionStopped | () | Calls __executionStopped() on all nodes and stops variable storage. |
_onClear | () | Calls _onClear() on all nodes and variable storage. |
_onSerialize | () | Serializes graph to data table (nodes, links, variables, view state). Returns {data, minId}. |
_onDeserialized | (data) | Rebuilds graph from serialized data: creates nodes, links, restores variables and view state. |
Execution Planning
The graph plans execution order by analyzing node connections and flow dependencies. Key concepts:
| Concept | Description |
|---|---|
_replan | Flag indicating the execution plan needs rebuilding. |
onUpdateNodeId | ID of the node that receives the onUpdate hook. |
hookList | List of hooks this graph's nodes subscribe to. |
Graph Hierarchy
Manager
└─ Root Graph (type = "graph")
├─ Child Graph (type = "graph")
├─ Macro (type = "macro")
└─ Instance (type = "instance", macroID = ...)Key Properties
| Property | Type | Description |
|---|---|---|
id | number | Unique graph ID within the manager. |
name | string | Display name. |
type | string | "graph", "macro", or "instance". |
parentId | number | ID of the parent graph (nil for root). |
nodes | table | {[id] = nodeObj} - all nodes in this graph. |
links | table | {[id] = linkObj} - all links in this graph. |
pins | table | {[id] = pinObj} - all pins across all nodes. |
variables | VariableStorage | Graph-scoped variable container. |
viewPos | im.ImVec2Ptr | Editor viewport position for this graph tab. |
viewZoom | im.FloatPtr | Editor viewport zoom level. |
isStateGraph | bool | Whether this graph uses state-machine nodes. |
GC Profiling
-- Each graph tracks garbage collection pressure:
self.gcprobeTable = {
total = 0,
history = {},
entries = {}, -- per-node GC stats
totalHistory = {},
}Usage Context
-- Graphs are created by the manager:
local graph = mgr:createGraph("My Graph")
local node = graph:createNode("logic/branch")
local link = graph:createLink(sourcePin, targetPin)
-- Execution is driven by the manager, which calls into graphs
-- for triggering, updating, and serialization.Additional Exports
resolveInterHops(rLinks, interInfo)
- rLinks -
any - interInfo -
any
moveNodeToGraph(node, newGraph)
- node -
any - newGraph -
any
linkExists(startPin, endPin)
- startPin -
any - endPin -
any - Returns:
boolean
hasLink(pin)
- pin -
any - Returns:
boolean
pinsCompatible(sourcePin, targetPin)
- sourcePin -
any - targetPin -
any
canCreateLink(a, b, newLinkInfo)
- a -
any - b -
any - newLinkInfo -
any - Returns:
boolean
findPin(pinId)
- pinId -
any - Returns:
any
updateChildrenTypes(t, ignoreType)
- t -
any - ignoreType -
any
getMacro()
getInstanceRoot()
getChildPosition()
- Returns:
any
getDeepChild(indexes)
- indexes -
any - Returns:
any
getRecursiveHooksAndDependencies(hooks, deps)
- hooks -
any - deps -
any - Returns:
any
findNodeInChildren(id)
- id -
any - Returns:
any
findNodeRecursive(id)
- id -
any - Returns:
any
forceRecursiveNodeUpdatePosition()
toString()
- Returns:
any
printStructure()
getParentWithStates()
- Returns:
any
getChildrenWithStates()
getSiblings()
getLocation(withIds)
- withIds -
any - Returns:
any
See Also
- Flowgraph Base Module - Related reference
- Flowgraph Base State Node - Related reference
- Flowgraph Base Node - Related reference
- FlowGraph Guide - Guide
Flowgraph Node Builder
ImGui node builder that handles the visual layout and rendering of flowgraph nodes. Manages node stages (begin → header → content → input → middle → output → end), pin layout, and header texture rende
Flowgraph Group Helper
Helper class for grouping and ungrouping nodes in the flowgraph editor. Handles converting selected nodes into subgraphs, computing bounding rectangles, centering node layouts, and managing link re-ro