LGraphCanvas

LGraphCanvas

LGraphCanvas

Constructor

# new LGraphCanvas(canvas, graph, options)

Parameters:
Name Type Description
canvas HTMLCanvasElement the canvas where you want to render (it accepts a selector in string format or the canvas element itself)
graph LGraph [optional]
options Object [optional] { skip_rendering, autoresize }

Methods

# (static) adjustMouseEvent()

adds some useful properties to a mouse event, like the position in graph coordinates

# (static) bindEvents()

binds mouse, keyboard, touch and drag events to the canvas

# (static) blockClick()

used to block future mouse events (because of im gui)

# (static) bringToFront(node)

brings a node to front (above all other nodes)
Parameters:
Name Type Description
node LGraphNode

# (static) centerOnNode()

centers the camera on a given node

# (static) clear()

clears all the data inside

# (static) closeSubgraph()

closes a subgraph contained inside a node

# (static) computeConnectionPoint(a, b, t, startDiropt, endDiropt) → {Array.<number>}

returns the link center point based on curvature
Parameters:
Name Type Attributes Description
a
b
t
startDir <optional>
endDir <optional>
Returns:
Type
Array.<number>

# (static) computeVisibleNodes(nodesopt, outopt) → {Array.<LGraphNode>}

checks which nodes are visible (inside the camera area)
Parameters:
Name Type Attributes Description
nodes Array.<LGraphNode> <optional>
out Array.<LGraphNode> <optional>
Returns:
Type
Array.<LGraphNode>

# (static) convertCanvasToOffset()

converts a coordinate from Canvas2D coordinates to graph space

# (static) convertEventToCanvasOffset(e) → {Array}

converts event coordinates from canvas2D to graph coordinates
Parameters:
Name Type Description
e
Returns:
Type
Array

# (static) convertOffsetToCanvas()

converts a coordinate from graph coordinates to canvas2D coordinates

# (static) deleteSelectedNodes()

deletes all nodes in the current selection from the graph

# (static) deselectAllNodes()

removes all nodes from the current selection

# (static) deselectNode()

removes a node from the current selection

# (static) draw(force_canvasopt, force_bgcanvasopt)

renders the whole canvas content, by rendering in two separated canvas, one containing the background grid and the connections, and one containing the nodes)
Parameters:
Name Type Attributes Description
force_canvas boolean <optional>
force_bgcanvas boolean <optional>

# (static) drawBackCanvas()

draws the back canvas (the one containing the background and the connections)

# (static) drawButton(x, y, w, h, text, bgcoloropt, hovercoloropt, textcoloropt) → {*|boolean}

Draws a button into the canvas overlay and computes if it was clicked using the immediate gui paradigm
Parameters:
Name Type Attributes Description
x
y
w
h
text
bgcolor <optional>
hovercolor <optional>
textcolor <optional>
Returns:
Type
* | boolean

# (static) drawConnections()

draws every connection visible in the canvas OPTIMIZE THIS: pre-catch connections position instead of recomputing them every time

# (static) drawFrontCanvas()

draws the front canvas (the one containing all the nodes)

# (static) drawGroups()

draws every group area in the background

# (static) drawNode()

draws the given node inside the canvas

# (static) drawNodeShape()

draws the shape of the given node in the canvas

# (static) drawNodeWidgets()

draws the widgets stored inside a node

# (static) drawSubgraphPanel()

draws the panel in the corner that shows subgraph properties

# (static) enableWebGL()

this function allows to render the canvas using WebGL instead of Canvas2D this is useful if you plant to render 3D objects inside your nodes, it uses litegl.js for webgl and canvas2DtoWebGL to emulate the Canvas2D calls in webGL

# (static) getCanvasWindow() → {Window}

Used to attach the canvas in a popup
Returns:
returns the window where the canvas is attached (the DOM root node)
Type
Window

# (static) getCurrentGraph() → {LGraph}

returns the visualy active graph (in case there are more in the stack)
Returns:
the active graph
Type
LGraph

# (static) getTopGraph() → {LGraph}

returns the top level graph (in case there are subgraphs open on the canvas)
Returns:
graph
Type
LGraph

# (static) isOverNodeBox()

returns true if a position (in graph space) is on top of a node little corner box

# (static) isOverNodeInput()

returns true if a position (in graph space) is on top of a node input slot

# (static) onGroupAdd(info, entry, mouseEvent)

Parameters:
Name Type Description
info
entry
mouseEvent MouseEvent

# (static) onMenuCollapseAll()

To Do:
  • Need create event

# (static) onMenuNodeEdit()

To Do:
  • Need create event

# (static) onNodeSelectionChange(node)

Parameters:
Name Type Description
node
To Do:
  • Need create event

# (static) openSubgraph(graph)

opens a graph contained inside a node in the current graph
Parameters:
Name Type Description
graph LGraph

# (static) processDrop()

process a item drop event on top the canvas

# (static) processKey()

process a key event

# (static) processMouseMove()

Called when a mouse move event has to be processed

# (static) processMouseUp()

Called when a mouse up event has to be processed

# (static) processMouseWheel()

Called when a mouse wheel event has to be processed

# (static) processNodeWidgets()

process an event on widgets

# (static) renderFrame()

render a frame

# (static) renderInfo()

draws some useful stats in the corner of the canvas
draws a link between two points
Parameters:
Name Type Description
a vec2 start pos
b vec2 end pos
link Object the link object with all the link info
skipBorder boolean ignore the shadow of the link
flow boolean show flow animation (for events)
color string the color for the link
startDir number the direction enum
endDir number the direction enum
numSubline number number of sublines (useful to represent vec3 or rgb)

# (static) resize()

resizes the canvas to a given size, if no size is passed, then it tries to fill the parentNode

# (static) selectNode(node, addToCurrentSelection)

selects a given node (or adds it to the current selection)
Parameters:
Name Type Description
node LGraphNode
addToCurrentSelection boolean

# (static) selectNodes()

selects several nodes (or adds them to the current selection)

# (static) sendToBack(node)

sends a node to the back (below all other nodes)
Parameters:
Name Type Description
node LGraphNode

# (static) setCanvas(canvas, skipEvents)

assigns a canvas
Parameters:
Name Type Description
canvas HTMLCanvasElement | string | HTMLElement assigns a canvas (also accepts the ID of the element (not a selector))
skipEvents boolean

# (static) setDirty(fgcanvasopt, bgcanvasopt)

marks as dirty the canvas, this way it will be rendered again
Parameters:
Name Type Attributes Description
fgcanvas boolean <optional>
if the foreground canvas is dirty (the one containing the nodes)
bgcanvas boolean <optional>
if the background canvas is dirty (the one containing the wires)

# (static) setGraph(graph, skipClearopt)

assigns a graph, you can reassign graphs to the same canvas
Parameters:
Name Type Attributes Description
graph LGraph
skipClear boolean <optional>

# (static) setZoom()

changes the zoom level of the graph (default is 1), you can pass also a place used to pivot the zoom

# (static) startRendering()

starts rendering the content of the canvas when needed

# (static) stopRendering()

stops rendering the content of the canvas (to save resources)

# (static) switchLiveMode()

switches to live mode (node shapes are not rendered, only the content) this feature was designed when graphs where meant to create user interfaces

# (static) touchHandler(event)

Parameters:
Name Type Description
event TouchEvent

# (static) unbindEvents()

unbinds mouse events from the canvas