DEMOS
DOCS
FEATURES
DOWNLOAD
PURCHASE
CONTACT
BLOG
Show:

Node Class

This is a Node in the Graph. Each Node can have one or more Edges to any other Node; this Edge may be directed. A Node may also have zero or more Ports, which themselves may have one or more Edges to other Nodes or to Ports on other Nodes.

Every Node has an associated indegree centrality and outdegree centrality. These are measurements of the number of links to and from the Node. Whenever an Edge is added or removed the indegree and outdegree centrality values for the Node are recomputed. For further reading we suggest Wikipedia.

You can instantiate a Node with any type of backing data you wish. If you supply a String, that value is assumed to be the Node's ID. If you supply a JSON object, an ID is extracted from that object, either with the supplied idFunction, or, if that is null, by assuming that the ID exists in the JSON as the id member.

Constructor

Node

(
  • [data]
  • [idFunction]
  • graph
)

Parameters:

  • [data] Object | String optional

    Optional data backing the node. This object can be of any type you like, but if you supply a String, that value will be assumed to be the Node's ID.

  • [idFunction] Function optional

    Optional function that can take a Node's data and return its ID. By default this looks for an id member in the backing data.

  • graph Graph

    Graph the Vertex belongs to.

Methods

addEdge

(
  • edge
)

Adds an Edge to the Node.

Parameters:

  • edge Edge

    The Edge to add.

addGraph

(
  • g
)
Graph

Adds a sub-graph to this node. If you provide an existing Graph instance that does not have an id, one will be assigned.

Parameters:

  • g Graph | String

    Either a Graph instance, or the id you wish to assign to a new Graph.

Returns:

Graph:

The Graph that was added.

addPort

(
  • [data]
  • [idFunction]
)
Port

Adds a Port to the Node.

Parameters:

  • [data] Object optional

    Optional data backing the Port. This object can be of any type you like.

  • [idFunction] Function optional

    Optional function that can take a Port's data and return its ID. By default this looks for an id member in the backing data.

Returns:

Port:

The newly created Port.

deleteEdge

(
  • edge
)

Deletes an Edge from the Node.

Parameters:

  • edge Edge

    The Edge to delete.

filter

(
  • spec
  • [includePartials=false]
)
Selection

Gets a Selection that is a filtered set of Nodes and Edges.

Parameters:

  • spec Object | Function

    Either a function, which will be passed each Edge and Node and is expected to return true to indicate inclusion, or an object consisting of key/value pairs, all of which are expected to match the data for any Edge or Node that should be included in the output.

  • [includePartials=false] Boolean optional

    If true, and you're using a match object, the results will include any objects that match at least one key in the match object.

Returns:

Selection:

A Selection.

getAllEdges

(
  • [params]
)
Edge[]

Parameters:

  • [params] Object optional

    Method parameters.

    • [filter] Function optional

      Optional Edge filter.

Returns:

Edge[]:

List of Edges.

getEdges

(
  • params
)
Edge[]

Gets all Edges where this Node is either the source or the target of the Edge. Note that this does not retrieve Edges on any Ports associated with this Node - for that, @see #getAllEdges.

Parameters:

  • params Object

    Method parameters.

    • [filter] Function optional

      Optional Edge filter.

Returns:

Edge[]:

List of edges.

getFullId

() String

Gets the Node's id, which, for Nodes, is just the id property. This method is overridden by Ports.

Returns:

String:

Node's id.

getGraph

() Graph

Retrieves a sub-graph by id.

Returns:

Graph:

Sub-graph with the given id, null if not found.

getIndegreeCentrality

() Float

Gets this Node's "indegree" centrality; a measure of how many other Nodes are connected to this Node as the target of some Edge.

Returns:

Float:

Indegree centrality for the Node.

getInternalEdge

(
  • source
  • target
)
Object

Gets an "internal" Edge from one Port to another.

Parameters:

  • source Port | String

    Source Port.

  • target Port | String

    Target Port.

Returns:

Object:

An object containing \{ source:..., target:..., cost:..., directed:... \}.

getOutdegreeCentrality

() Float

Gets this Node's "outdegree" centrality; a measure of how many other Nodes this Node is connected to as the source of some Edge.

Returns:

Float:

Outdegree centrality for the Node.

getPort

(
  • id
)
Port

Gets the Port with the given id, null if nothing found.

Parameters:

  • id String

    Port id.

Returns:

Port:

Port with the given id, or null if not found.

getPorts

() Port[]

Gets all Ports associated with this Node.

Returns:

Port[]:

List of Ports, empty list if none registered.

getSourceEdges

() Edge[]

Gets all Edges where this Node is the source.

Returns:

getTargetEdges

() Edge[]

Gets all Edges where this Node is the target.

Returns:

inspect

() String

Returns a string representation of the Node.

Returns:

String:

Node dumped to a string.

removePort

(
  • Either
)

Removes the given Port.

Parameters:

  • Either Port | String

    a Port, or a Port id.

setDefaultInternalCost

(
  • cost
)

Sets the default cost of travelling from one Port to another inside some Node. When a Node is created, this value is set to 1.

Parameters:

  • cost Number

    Default internal cost.

setInternalEdge

(
  • source
  • target
  • cost
  • [directed]
)

Sets the cost and directedness of some internal Edge.

Parameters:

  • source Port | String

    Source Port.

  • target Port | String

    Target Port.

  • cost Number

    Cost to set. If you leave this as null, the default will be used.

  • [directed] Boolean optional

    Whether or not the internal Edge is directed.

setPort

(
  • id
  • data
)

Sets the underlying data for the Port with the given id. If the Port does not yet exist, it is created.

Parameters:

  • id String

    Id of the Port for which to set data.

  • data Object

    Data to set for the Port.

Properties

data

Object

Data associated with the Node.

id

String

The Node's id. A String.