Constructor
new Network(nodes, links, options)
Creates a Network
Parameters
-
nodes
ArrayArray of Nodes
-
links
ArrayArray of Links - relationships between nodes using the reference key, or array indexes
-
options
ObjectProperties
-
uid
Stringname of the property of unique identifier, e.g. 'id'
-
uid
Source
Methods
areNeighbors(a, b) → {Boolean}
Examines the a relationship between the two given nodes. Will return true if there is a a source<->target relationship or if the nodes are equal, i.e. the same.
Parameters
Source
findDeepSources(n, sourcesopt, levelopt) → {Array}
Recursively finds all deep sources of a node, i.e. does not include direct source.
Parameters
-
n
Nodenode to get source tree
-
sources
Array<optional>
[] -
level
Array<optional>
0
Source
findLinks(node) → {Array}
Finds links a given node has. Example results are [{source: node, target: node}]
Parameters
-
node
Node
Source
findNodeById(id) → {Node}
Find node by id
Parameters
-
id
String
Source
findNodeIndex(node) → {Integer}
Finds index of node either by it's unique identifier, e.g. id or the node data object itself.
Parameters
-
node
String|Objectid or data object
Source
findSources(n) → {Array}
Returns Array of nodes in the source tree of a specific node.
Parameters
-
n
Nodenode to get source tree
Source
get(attr) → {Object|Array|null}
Fetches network attributes Currently used for first binding or rendering
Parameters
-
attr
Stringattribute to return. Valid attributes are
linksornodes.
Source
getRelationship(node, neighbor) → {String}
Returns relationship type between node and its neighbor. Will return one of the following:
| Key | Relationship type |
|---|---|
'is-source' |
node -> neighbor |
'is-deep-source' |
node -> … -> neighbor |
'is-target' |
neighbor -> node |
'is-same-node' |
node === neighbor |
'has-no-relationship' |
There is no relationship between the two nodes |
Parameters
Source
isDeepSourceLink(link, n) → {Boolean}
Returns true if link can be found in the node's source tree.
Parameters
Source
isDeepSourceNeighbor(a, b) → {Boolean}
Examines if node a is includeed in node b's source tree, i.e. if a source -> ... -> target relationship between the two nodes.
Parameters
Source
isEqualNode(a, b) → {Boolean}
Returns true if the nodes examined are equal, i.e. the same node
Parameters
-
a
Stringid of node A
-
b
Stringid of node B
Source
isSourceNeighbor(a, b) → {Boolean}
Examines if there is a source -> target relationship between two specific nodes.
Parameters
Source
isTargetNeighbor(a, b) → {Boolean}
Examines if there is a b -> a relationship between two specific nodes.
Parameters
Source
removeLinks(node)
Removes links for a given node
Parameters
-
node
Node
Source
removeNode(node)
Removes node and its links from the graph.
Parameters
-
node
Node
Source
removeNodeById(id)
Removes node by its id.
Parameters
-
id
Stringid of node to remove
Source
updateData(nodes, links)
Updates entire network data set
Parameters
-
nodes
Arraynodes data
-
links
Arraylinks data
-
opts.event
String<optional>
'update'event name after setting data
-
opts.publish
Boolean<optional>
truepublish event after resetting data?
Source
updateNode(n, attrs) → {this}
Updates data on a specific node
Parameters
-
n
String|Nodeeither
idof node, or the object itself to update -
attrs
Objectnode data attributes to change. This is merged onto existing attributes, so you only need to pass in updated values.
Source
Events
update
Update event which passes on network data so graph elements, nodes and links can update themselves based on latest real-time data.
Type
-
Object
Properties
-
nodes
Array -
links
Array