LGraphCanvas Class
marks as dirty the canvas, this way it will be rendered again
Constructor
LGraphCanvas
-
canvas
-
graph
-
options
Parameters:
-
canvas
HTMLCanvasthe 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 }
Item Index
Methods
- adjustMouseEvent
- bindEvents
- bringToFront
- centerOnNode
- clear
- closeSubgraph
- computeVisibleNodes
- convertCanvasToOffset
- convertOffsetToCanvas
- deleteSelectedNodes
- deselectAllNodes
- deselectNode
- draw
- drawBackCanvas
- drawConnections
- drawFrontCanvas
- drawGroups
- drawNode
- drawNodeShape
- drawNodeWidgets
- enableWebGL
- getCanvasWindow
- isOverNodeBox
- isOverNodeInput
- openSubgraph
- processDrop
- processKey
- processMouseMove
- processMouseUp
- processMouseWheel
- processNodeWidgets
- renderInfo
- renderLink
- resize
- selectNode
- selectNodes
- sendToBack
- setCanvas
- setGraph
- setZoom
- startRendering
- stopRendering
- switchLiveMode
- unbindEvents
Methods
adjustMouseEvent
()
adds some useful properties to a mouse event, like the position in graph coordinates
bindEvents
()
binds mouse, keyboard, touch and drag events to the canvas
bringToFront
()
brings a node to front (above all other nodes)
centerOnNode
()
centers the camera on a given node
clear
()
clears all the data inside
closeSubgraph
-
assigns
closes a subgraph contained inside a node
Parameters:
-
assigns
LGrapha graph
computeVisibleNodes
()
checks which nodes are visible (inside the camera area)
convertCanvasToOffset
()
converts a coordinate from Canvas2D coordinates to graph space
convertOffsetToCanvas
()
converts a coordinate from graph coordinates to canvas2D coordinates
deleteSelectedNodes
()
deletes all nodes in the current selection from the graph
deselectAllNodes
()
removes all nodes from the current selection
deselectNode
()
removes a node from the current selection
draw
()
renders the whole canvas content, by rendering in two separated canvas, one containing the background grid and the connections, and one containing the nodes)
drawBackCanvas
()
draws the back canvas (the one containing the background and the connections)
drawConnections
()
draws every connection visible in the canvas OPTIMIZE THIS: precatch connections position instead of recomputing them every time
drawFrontCanvas
()
draws the front canvas (the one containing all the nodes)
drawGroups
()
draws every group area in the background
drawNode
()
draws the given node inside the canvas
drawNodeShape
()
draws the shape of the given node in the canvas
drawNodeWidgets
()
draws the widgets stored inside a node
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
getCanvasWindow
()
Window
Used to attach the canvas in a popup
Returns:
returns the window where the canvas is attached (the DOM root node)
isOverNodeBox
()
retuns true if a position (in graph space) is on top of a node little corner box
isOverNodeInput
()
retuns true if a position (in graph space) is on top of a node input slot
openSubgraph
-
graph
opens a graph contained inside a node in the current graph
Parameters:
-
graph
LGraph
processDrop
()
process a item drop event on top the canvas
processKey
()
process a key event
processMouseMove
()
Called when a mouse move event has to be processed
processMouseUp
()
Called when a mouse up event has to be processed
processMouseWheel
()
Called when a mouse wheel event has to be processed
processNodeWidgets
()
process an event on widgets
renderInfo
()
draws some useful stats in the corner of the canvas
renderLink
-
a
-
b
-
link
-
skip_border
-
flow
-
color
-
start_dir
-
end_dir
-
num_sublines
draws a link between two points
Parameters:
-
a
Vec2start pos
-
b
Vec2end pos
-
link
Objectthe link object with all the link info
-
skip_border
Booleanignore the shadow of the link
-
flow
Booleanshow flow animation (for events)
-
color
Stringthe color for the link
-
start_dir
Numberthe direction enum
-
end_dir
Numberthe direction enum
-
num_sublines
Numbernumber of sublines (useful to represent vec3 or rgb)
resize
()
resizes the canvas to a given size, if no size is passed, then it tries to fill the parentNode
selectNode
()
selects a given node (or adds it to the current selection)
selectNodes
()
selects several nodes (or adds them to the current selection)
sendToBack
()
sends a node to the back (below all other nodes)
setCanvas
-
assigns
assigns a canvas
Parameters:
-
assigns
Canvasa canvas (also accepts the ID of the element (not a selector)
setGraph
-
graph
assigns a graph, you can reasign graphs to the same canvas
Parameters:
-
graph
LGraph
setZoom
()
changes the zoom level of the graph (default is 1), you can pass also a place used to pivot the zoom
startRendering
()
starts rendering the content of the canvas when needed
stopRendering
()
stops rendering the content of the canvas (to save resources)
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
unbindEvents
()
unbinds mouse events from the canvas