This function of a JSAV instance initializes an empty graph. Options that the optional parameter can specify:
manual
, automatic
, or layered
. Defaults to manual layout. Note,
that if you use the layered
layout, you will need to load Dagre (you can also
find it in JSAV/lib/dagre.min.js
).horizontal vertical
. Possible horizontal values are “left”, “center”, “right” and vertical values “top”, “center”, “bottom”. Defaults to center center
. Only has an effect if relativeTo is
specified.center center
. Only
has an effect if relativeTo is specified.The returned graph instance is modified through a collection of methods explained next. In addition, the graph has the common
functions such as .id()
, .css(...)
, .show()
, and .hide()
.
Adds a new node with value
to the graph. Returns the new node.
Removes the given node
.
Adds edge from fromNode
to toNode
. Returns the new edge.
Supported options:
Removes edge from fromNode
to toNode
.
Removes the given edge
.
Returns true if the graph has an edge from fromNode
to toNode
.
Returns the Edge object connecting fromNode
and toNode
, or undefined
if no such edge exists.
Returns an iterable array of nodes in the graph. The returned structure can be used as a normal JavaScript array. In addition,
it has methods .next()
, .hasNext()
, and .reset()
for iterating over the values.
Returns the number of nodes in the graph.
Returns an iterable array of edges in the graph. The returned structure is similar to the one returned by .nodes()
.
Returns the number of edges in the graph.
Removes the DOM element of this structure from the document. This is useful, for example, in re-initializing exercises when the existing structure needs to be removed.
This function (re)calculates the layout for the graph. Note, that the library does not do this automatically. That means that after changing the graph, you should call this manually at the end of each animation step.
There are functions to attach event handlers for the nodes and edges in the graph. The events that can be listened for are: click, dblclick, mousedown, mousemove, mouseup, mouseenter, and mouseleave. See the tree documentation for details.
A node in a graph has the same functions as a tree node: .value([newValue])
, .highlight()/unhighlight()
, .show()/.hide()
, and .css(...)
. In addition, it has the following functions.
Returns an iterable array of the nodes that this node is connected to.
Returns the Edge object connecting this node to the given node
. Returns undefined
if no such edge exists.
Returns the Edge object connecting the given node
to this node. Returns undefined
if no such edge exists.