Newton Graph Library

Newton Graph Library

Class

Network

Data Wrapper for Graphs, useful for dynamically calculating links between nodes. As describe in the WebCola Wiki, the layout adapter follows d3.layout.force conventions and joins nodes via (JavaScript) reference or array indexes, which normally looks like this:

const links = [
	{ source: 0, target: 1 },
	{ source: 3, target: 5 }
]

This wrapper lets you calculate links dynamically based on a reference key, e.g. id, so we can use this kind of structure instead:

const links = [
	{ source: 'A', target: 'B' },
	{ source: 'frontend', target: 'middleware' }
]

Constructor

new Network(nodes, links, options)

Creates a Network

Parameters

  • nodes Array

    Array of Nodes

  • links Array

    Array of Links - relationships between nodes using the reference key, or array indexes

  • options Object

    Properties

    • uid String

      name of the property of unique identifier, e.g. 'id'

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 Node

    node to get source tree

  • sources Array <optional>
    []
  • level Array <optional>
    0

Source

Finds links a given node has. Example results are [{source: node, target: node}]

Parameters

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 | Object

    id or data object

Source

findSources(n) → {Array}

Returns Array of nodes in the source tree of a specific node.

Parameters

  • n Node

    node to get source tree

Source

get(attr) → {Object|Array|null}

Fetches network attributes Currently used for first binding or rendering

Parameters

  • attr String

    attribute to return. Valid attributes are links or nodes.

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

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

  • a Node

    potential source node

  • b Node

    potential target node

Source

isEqualNode(a, b) → {Boolean}

Returns true if the nodes examined are equal, i.e. the same node

Parameters

  • a String

    id of node A

  • b String

    id 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

  • a Node

    potential target node

  • b Node

    potential source node

Source

updateData(nodes, links)

Updates entire network data set

Parameters

  • nodes Array

    nodes data

  • links Array

    links data

  • opts.event String <optional>
    'update'

    event name after setting data

  • opts.publish Boolean <optional>
    true

    publish event after resetting data?

Source

updateNode(n, attrs) → {this}

Updates data on a specific node

Parameters

  • n String | Node

    either id of node, or the object itself to update

  • attrs Object

    node 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

Listeners of this event