API Docs for:
Show:

LGraphCanvas Class

marks as dirty the canvas, this way it will be rendered again

Constructor

LGraphCanvas

(
  • canvas
  • graph
  • options
)

Parameters:

  • canvas HTMLCanvas

    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

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:

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:

Window:

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:

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

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 Canvas

    a 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:

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