Global

Members

(constant) compound

Create a new compound node. Each compound node is itself a graph that can contain further nodes.

Source:

(constant) isomorph

Compares two graphs for structural equality (i.e. tests if they are isomorph, where it is allowed to change the ids and paths of every node).

Source:

(constant) lowestCommonAncestors

Find the lowest common ancestors (LCAs) of a set of locations.

Source:

(constant) predecessors

Return all predecessors of a node or port.

Source:

(constant) rePath

Updates all paths in the graph.

Source:

(constant) replaceByCall

Takes a subset of nodes (all of them must have the same parent) and replaces them by a lambda function, the partial application of their inputs and a call with all outputs connected to the subsets successors.

Source:

(constant) replaceByThunk

Takes a subset of nodes (all of them must have the same parent) and replaces them by a lambda function, the partial application of their inputs It will not call the lambda function and thus their outputs will not be connected. If you want to connect the outputs after the call use replaceByCall. Information about the successors is accessible via the context-callback.

Source:
Examples

replaceByCall implementation

// create call is a context-callback that creates a call node and connects it properly
export const replaceByCall = curry((subset, graph) =>
  replaceByThunk(subset, graph, createCall))

Log the not connected successors as an array.

replaceByThunk(subset, graph, curry((context, last, graph) => {
  console.log(flatten(context.outputs.map((o) => o[1])))
}))

Methods

addComponent(comp, graph) → {PortGraph}

Add a component to the graph. [Performance O(|V| + |E|)]

Parameters:
Name Type Description
comp Component

The component object that should be added.

graph PortGraph

The graph.

Source:
Returns:

A new graph that includes the component.

Type
PortGraph

addEdge(edge, graph) → {PortGraph}

Add an edge to the graph.

Parameters:
Name Type Description
edge Edge

The edge that should be added. This needn't be in standard format.

graph PortGraph

The graph.

Source:
Throws:

If:

  • the edge already exists
  • ports that the edge connects do not exists
  • nodes that the edge connects do not exists
  • the edge is not in normalizable form.
Type
Error
Returns:

A new graph containing the edge.

Type
PortGraph

addNode(node, graph, contextCallback) → {PortGraph}

Add a node to the graph (at the root level), returns a new graph. [Performance O(|V| + |E|)]

Parameters:
Name Type Description
node Node

The node object that should be added. If the node already exists in the graph it will be copied. The node object must contain at least one valid ports. This functions checks if the node has ports AND if every port is a valid port (i.e. has a name as port and the port type (output/input) as kind).

graph PortGraph

The graph.

contextCallback Callback

A context-callback that is called after the new node was inserted. It has the signature Node x Graph -> Graph. It will get the newly inserted node and the graph (that has this node). And it must return a graph (the graph will be the return value of this function).

Source:
Returns:

A new graph that includes the node.

Type
PortGraph
Examples

Inserting nodes and connecting them

Graph.Let(
  [
    Graph.addNode({ports: [{port: 'out', kind: 'output', type: 'Number'}]}),
    Graph.addNode({ports: [{port: 'in', kind: 'output', type: 'Number'}]})
  ],
  ([node1, node2], graph) =>
    Graph.addEdge({from: Node.port('out', node1), to: Node.port('in', node2)}, graph))

Printing the id of the newly inserted node

Graph.addNode({...}, graph, (newNode, graph) => {
  console.log(Node.id(newNode))
  return graph
})

addNodeByPath(parentPath, node, graph) → {PortGraph}

Add a node at a specific path.

Parameters:
Name Type Description
parentPath CompoundPath

A compound path identifying the location in the compound graph.

node Node

The node to add to the graph.

graph PortGraph

The graph that is the root for the nodePath

Source:
Returns:

A new graph that contains the node at the specific path.

Type
PortGraph

addNodeIn(parentLoc, node, graph, contextCallback) → {PortGraph}

Add a node in a given compound node.

Parameters:
Name Type Description
parentLoc Location

A location identifying the parent for the new node.

node Node

The node to add to the graph.

graph PortGraph

The graph

contextCallback Callback

A context-callback that is called after the new node was inserted. It has the signature Node x Graph -> Graph. It will get the newly inserted node and the graph (that has this node). And it must return a graph (the graph will be the return value of this function).

Source:
Returns:

A new graph that contains the node as child of parentLoc.

Type
PortGraph
Example

Printing the id of the newly inserted node

Graph.addNodeIn(parent, {...}, graph, (newNode, graph) => {
  console.log(Node.id(newNode))
  return graph
})

addNodeTuple(node, graph) → {PortGraph}

Add a node an return an array of the graph and id.

Parameters:
Name Type Description
node Node

The node object that should be added. If the node already exists in the graph it will be copied.

graph PortGraph

The graph.

Source:
Returns:

A new graph that includes the node and the id as an array in [graph, id].

Type
PortGraph

applyChangeSet(graph, changeSet) → {Graphlib}

Apply a changeSet on the given graph.

Parameters:
Name Type Description
graph Object

The graph in JSON format that should be changed.

changeSet ChangeSet

The change set that should be applied.

Source:
Throws:

If the change set is no valid change set it throws an error.

Type
Error
Returns:

A new graph with the applied change set graph.

Type
Graphlib

applyChangeSetInplace(graph, changeSet) → {Graphlib}

Apply a changeSet on the given graph inplace.

Parameters:
Name Type Description
graph PortGraph

The graph that should be changed.

changeSet ChangeSet

The change set that should be applied.

Source:
Throws:

If the change set is no valid change set it throws an error.

Type
Error
Returns:

The changed graph. Currently the changes are all made inplace so the return value is equal to the input graph.

Type
Graphlib

applyChangeSets(graph, changeSets) → {Graphlib}

Apply an array of changeSets on the given graph. All changes are applied sequentially.

Parameters:
Name Type Description
graph PortGraph

The graph that should be changed.

changeSets Array.<ChangeSet>

The change sets that should be applied. The order might influence the resulting graph, they are processesed sequentially.

Source:
Throws:

If the change set is no valid change set it throws an error.

Type
Error
Returns:

A new graph with the applied change set graph.

Type
Graphlib

areConnected(nodeFrom, nodeTo, graph) → {boolean}

Checks whether the two nodes or ports are connected via an edge.

Parameters:
Name Type Description
nodeFrom Location

The starting point of our connection.

nodeTo Location

The target of our connection.

graph PortGraph

The graph in which we want to find the connection.

Source:
Returns:

True if the graph has an edge going from "nodeFrom" to "nodeTo".

Type
boolean

atomics(graph) → {Array.<References>}

Gets a list of all atomic nodes.

Parameters:
Name Type Description
graph PortGraph

The graph.

Source:
Returns:

A list of all defined atomic nodes in the graph.

Type
Array.<References>

blocked()

Checks whether a node is blocked inside a subset or not. A node is blocked by a subset when it as at least one predecessor that is part of the subset and at least one successor that is part of the subset. In the following example, b is blocked as a is a predecessor and b is a successor and thus it is not possible to compoundify a and c.

+------------------+ |Compound | | +---+ | | | a | | | +-+-+ | | | | | +------------+ | | | | | +-v-+ | | | b | | | +-+-+ | | | | +------------+ | | | | +-v-+ | | | c | | | +---+ | | | +------------------+

Source:

childrenOf(parent, locations, graph) → {Boolean}

Checks whether the locations are all children of the given parent.

Parameters:
Name Type Description
parent Location

The parent of the locations.

locations Array.<Location>

An array of locations to check

graph Portgraph

The graph

Source:
Returns:

True if they have the same parents, false otherwise.

Type
Boolean

clone(graph) → {PortGraph}

Creates a new graph that has the exact same nodes and edges.

Parameters:
Name Type Description
graph PortGraph

The graph to clone

Source:
Returns:

A clone of the input graph.

Type
PortGraph

component(comp, graph) → {Component}

Returns the component with the given component id. [Performance O(|V|)]

Parameters:
Name Type Description
comp Component | string

The component or its component id.

graph PortGraph

The graph.

Source:
Throws:

If the queried component does not exist in the graph.

Type
Error
Returns:

The component in the graph

Type
Component

componentIds(graph) → {Array.<string>}

Returns a list of component ids. [Performance O(|V|)]

Parameters:
Name Type Description
graph PortGraph

The graph.

Source:
Returns:

A list of component ids.

Type
Array.<string>

components(graph) → {Array.<Components>}

Returns a list of defined components. Components are not part of the program flow, but are defined procedures that can be used in the resolve process.

Parameters:
Name Type Description
graph PortGraph

The graph.

Source:
Returns:

A list of components that are defined in the graph.

Type
Array.<Components>

compoundify(parent, nodes, graph) → {Portgraph}

Takes a list of nodes and tries to combine them in one compound.

Parameters:
Name Type Description
parent Location

The parent of the nodes

nodes Array.<Location>

An array of node locations (ids, node objects.. etc.) that should be included in the compound

graph Portgraph

The graph

Source:
Throws:

If it is not possible to combine the nodes in one compound.

Type
Error
Returns:

A new graph in which the list of nodes is combined inside one compound.

Type
Portgraph

compounds(graph) → {Array.<References>}

Gets a list of all compound nodes.

Parameters:
Name Type Description
graph PortGraph

The graph.

Source:
Returns:

A list of all defined compound nodes in the graph.

Type
Array.<References>

convertToLambda(parent, subset, graph, cbopt) → {Portgraph}

Create a lambda node that contains the given subset of nodes. It will not connect the inputs and outputs use createCall for that.

Parameters:
Name Type Attributes Description
parent Location

The parent of the subset.

subset Array.<Location>

A subset of nodes in the graph that should be included in the lambda node.

graph Portgraph

The graph

cb Callback <optional>

A callback that is called after the lambda node is created. The context will be an object that contains the lambda node, the predecessors of the subset and the successors of that subset. I.e. the context object will look like this:

{
  "lambda": "<The lambda node>",
  "inputs": [[<inputPort>, <predecessor>], ...],
  "outputs": [[<outputPort, [<successors>, ...]],...]
}

The graph is the new graph which includes the lambda nodes and in which the subset has been removed. The return value of the callback function must be a graph (i.e. a graph in which you connect the remaining parts).

Source:
Returns:

A new graph that replaced the subset with a lambda node. If a callback is given, the callback is applied to the graph before convertToLambda returns and the return value of that callback is returned.

Type
Portgraph

criticalNodes()

Find alls critical nodes for compoundify. The critical nodes are those, that are in the topological between the first node of the subset and the last node of the subset and not part of the subset. Those nodes can have a successor and a predecessor in the subset and thus making it impossible to compoundify the subset. If we have the following topological sorting and subset

topo: a b c d subset: x x x

The node c would be a critical node as it can have the predecessor b (or a) and successor d.

Source:

distribute()

Distributes an argument parallel. (Alias for distributeWith(parallel)).

Source:
See:

distributeSequential()

Distributes an argument parallel. (Alias for distributeWith(sequential)).

Source:
See:

distributeWith(reducer, fns) → {GraphAction}

Distributes an argument over multiple Graph actions. After distributing it calls a reducer function.

Parameters:
Name Type Description
reducer Reducer

The reducer function that takes multiple graph actions and creates one action out of them. This could be the sequential reducer that runs the actions sequentially (after distributing an argument).

fns Array.<GraphActions>

An array of actions onto which the given callback argument should be distributed.

Source:
Returns:

A function that takes a graph and returns a new graph. As with every GraphAction it is possible to add a callback to the arguments to process the result with context information

Type
GraphAction
Example
Connecting a nodes inputs and outputs
// Add a graph (`distributeWith(parallel)` is defined as `distribute`)
Graph.addNode({...}, distributeWith(parallel, [
   (newNode) => Graph.addEdge({from: '@from', to: Node.port('input', newNode)}),
   (newNode) => Graph.addEdge({from: Node.port('output', newNode), to: '@output'})
])(graph)

edge() → {Edge}

Returns the queried edge. This needn't be in standard format.

Source:
Throws:

If the edge is not contained in the graph.

Type
Error
Returns:

The edge as it is stored in the graph.

Type
Edge

edges(graph) → {Array.<Edges>}

Returns a list of edges in the graph layer. Each edge also has an extra field identifying the parent node to which the edge belongs in the hierarchy. This function will not recurse into compounds, use edgesDeep for that.

Parameters:
Name Type Description
graph PortGraph

The graph.

Source:
Returns:

A list of edges.

Type
Array.<Edges>
Example

Getting the edges in a graph

edges(graph) // -> [{from: ..., to: ..., layer: ..., parent: '#...'}, ...]

edgesDeep(graph) → {Array.<Edges>}

Returns a list of edges in the graph. Each edge also has an extra field identifying the parent node to which the edge belongs in the hierarchy.

Parameters:
Name Type Description
graph PortGraph

The graph.

Source:
Returns:

A list of edges.

Type
Array.<Edges>
Example

Getting all the edges in a graph

edgesDeep(graph) // -> [{from: ..., to: ..., layer: ..., parent: '#...'}, ...]

empty() → {PortGraph}

Returns a new empty graph.

Source:
Returns:

A new empty port graph.

Type
PortGraph

excludeNode(node, graph) → {PortGraph}

Moves a node from its compound to the parent compound node. Changes the compound node to ensure it takes the correct number of inputs etc. This method only works if the node has no predecessor in the compound node.

Parameters:
Name Type Description
node Node

A node identifier for the node that should be moved out of the compound node.

graph PortGraph

The graph

Source:
Throws:

If the node has a predecessor in the compound and thus cannot be moved out of the compound node.

Type
Error
Returns:

A new graph in which the node is moved out of its parent compound into the parent of its parent.

Type
PortGraph

flow() → {function}

Parameters:
Name Type Description
...args function | Array

An arbitrary number of arguments of that are either functions that take one argument and return this argument. Or an array of functions that each take an argument and return one. The functions must be composable.

Source:
Returns:

A function that takes an object that is fed into the first function in the arguments.

Type
function

flowCallback(cbs)

Utility function to get the callback function from an optional callbacks array. This function should be used to allow for additional, optional arguments in curried functions.

Parameters:
Name Type Description
cbs

The callbacks array (possibly empty).

Source:
Returns:

The callback function for the callbacks array.

fromFile(path) → {PortGraph}

Load a graph from a JSON file

Parameters:
Name Type Description
path String

The JSON file representing the port graph.

Source:
Throws:

If the file does not represent a valid JSON document.

Type
Error
Returns:

The port graph.

Type
PortGraph

fromJSON(jsonGraph) → {PortGraph}

Load a graph encoded as a JSON document

Parameters:
Name Type Description
jsonGraph object

The json representing the port graph.

Source:
Returns:

The port graph with its functions.

Type
PortGraph

fromJSONUnsafe(jsonGraph) → {PortGraph}

Load a graph encoded as a JSON document

Parameters:
Name Type Description
jsonGraph object

The json representing the port graph.

Source:
Returns:

The port graph with its functions.

Type
PortGraph

fromString(graphStr) → {PortGraph}

Load a graph encoded as a string

Parameters:
Name Type Description
graphStr String

The string representing a json document for the port graph.

Source:
Throws:

If the string does not represent a valid JSON document.

Type
Error
Returns:

The port graph.

Type
PortGraph

fromString()

Creates a location object from the string representation

Source:

get(key, loc, graph)

Get a property of a node.

Parameters:
Name Type Description
key String

The key of the property like 'recursion'

loc Location

The location identifying the node for which the property is queried.

graph PortGraph

The graph.

Source:
Returns:

The value of the property or undefined if the property does not exist in the node.

Example
* var graph = ...
var newGraph = Graph.set({property: value}, '#nodeIDOrLocation', graph)
// you can get the value via get in the newGraph
var propertyValue = Graph.get('property', '#nodeIDOrLocation', graph)

getMetaKey(key, graph)

Gets the meta information in the graph for the given key

Parameters:
Name Type Description
key string

The meta key for the value.

graph PortGraph

The graph.

Source:
Returns:

The value of the meta key of undefined if the key does not exist.

getNodeMetaKey(key, loc, graph)

Gets the meta information for a node in the graph for the given key

Parameters:
Name Type Description
key string

The meta key for the value.

loc Location

The location identifying the node.

graph PortGraph

The graph.

Source:
Returns:

The value of the meta key of undefined if the key does not exist.

hasComponent(graph, comp) → {boolean}

Checks whether the graph has a component with the given component id. [Performance O(|V|)]

Parameters:
Name Type Description
graph PortGraph

The graph.

comp Component | string

The component or its component id you want to check for.

Source:
Returns:

True if the graph has a component with the given component id, false otherwise.

Type
boolean

hasEdge() → {boolean}

Checks whether the graph has the given edge.

Source:
Returns:

True if the edge is contained in the graph, false otherwise.

Type
boolean

hasNode(loc, graph) → {boolean}

Checks whether the graph has a node. [Performance O(|V|)]

Parameters:
Name Type Description
loc Location

A location identifying the node

graph PortGraph

The graph.

Source:
Returns:

True if the graph has a node with the given id, false otherwise.

Type
boolean

identifies()

Checks whether a location identifies the given object. This is true if for example the location points to a node and the other object is the node. Or if the other object is simply the ID of the node. It also identifies a node if the location specifies the port. If you don't want this behavior use equals (it is the strict version of identifies).

Source:
Returns:

True if the location identifies the object stored in other.

idToPath(id, graph) → {CompoundPath|null}

Returns the path that points to the node in the graph by its id. The id is preserved when moving or editing nodes. The path might change. To fixate a node one can use the ID.

Parameters:
Name Type Description
id string

The id of the node

graph PortGraph

The graph to search in

Source:
Returns:

The path to the node with the given ID.

Type
CompoundPath | null

incidents(loc, graph) → {Array.<Edge>}

All incident edges to the given input.

Parameters:
Name Type Description
loc Location

The node or port.

graph PortGraph

The graph

Source:
Returns:

An array of all incident edges to the given location.

Type
Array.<Edge>

includePredecessor(port, graph) → {PortGraph}

Moves the predecessor of a port into the compound node. It changes the signature of the compound node. It has to ensure that the inputs are correct. This only works if the predecessor has only one successor (i.e. the compound node it will move into).

Parameters:
Name Type Description
port Port

A port identifier. This also specifies the node.

graph PortGraph

The graph in which the change will happen.

Source:
Throws:

If the predecessor has more than one successor.

Type
Error
Returns:

A new port graph that includes the predecessor of the port in the compound.

Type
PortGraph

inIncident(target, graph, configopt) → {Edge}

Gets the ingoing incident edge to a port. Each port can only have one ingoing edge.

Parameters:
Name Type Attributes Description
target Location

The node or port to which the edge is incident. This is the target node or port of the edge.

graph PortGraph

The graph

config Object <optional>

Optional config object

Properties
Name Type Attributes Default Description
layers Array.<String> <optional>
['dataflow']

Filter the edge based on the selected layers

goIntoCompounds Boolean <optional>
false

Optional argument that activates looking for edges inside compounds. If you specify a node as the location it will not go inside the node (if it is a compound) and look for ingoing edges inside the compound.

Source:
Returns:

The ingoing incident edge.

Type
Edge

inIncidents(target, graph, configopt) → {Array.<Edge>}

Gets all ingoing incident edges to a port

Parameters:
Name Type Attributes Description
target Location

The port to which the edges are incident. This is the target node or port of each edge.

graph PortGraph

The graph

config Object <optional>

Optional config object

Properties
Name Type Attributes Default Description
layers Array.<String> <optional>
['dataflow']

Filter the edge based on the selected layers

goIntoCompounds Boolean <optional>
false

Optional argument that activates looking for edges inside compounds. If you specify a node as the location it will not go inside the node (if it is a compound) and look for ingoing edges inside the compound.

Source:
Returns:

An array of all ingoing (i.e. pointsTo(port)) incident edges.

Type
Array.<Edge>

insertComponent(value) → {ChangeSet}

Creates a change set that creates a new component.

Parameters:
Name Type Description
value Object

The new component.

Source:
Returns:

A change set containing the new component.

Type
ChangeSet

insertEdge(newEdge) → {ChangeSet}

Creates a change set that inserts a new edge into the edge list

Parameters:
Name Type Description
newEdge Object

The edge that should be inserted.

Source:
Returns:

A change set containing the insertion operation.

Type
ChangeSet

insertNode(value) → {ChangeSet}

Creates a change set that creates a new node.

Parameters:
Name Type Description
value Object

The new node.

Source:
Returns:

A change set containing the new node.

Type
ChangeSet

isChangeSet(changeSet)

Checks whether a value is a change set or not.

Parameters:
Name Type Description
changeSet

The value that should be checked.

Source:
Returns:

True if it is a changeSet, false otherwise.

isFrom(target, graph, edge) → {boolean}

Checks whether an edge is from a given source.

Parameters:
Name Type Description
target Location

The source the edge should come from. This can either be a node or a port.

graph PortGraph

The graph

edge Edge

The edge to check

Source:
Returns:

True if the edge comes from the source, false otherwise.

Type
boolean

isPortNotation()

A port notation can have every of the other notations for the node and as such it is necessary to check first if it is a port notation. The symbol '@' is only used in port notations.

Source:

Let(fn, cb) → {GraphAction}

Handle the context information of an action in a separate callback. This is especially useful in flow chains to preserve the monadic structure. This is similar to the monadic let in haskell (in do notations). As let is already a JS keyword it is written in uppercase.

Parameters:
Name Type Description
fn GraphAction

A graph action that might produce some contextual information.

cb Callback

A function that takes a context information and returns a graph action.

Source:
Returns:

A graph action that takes a graph an produces a new graph.

Type
GraphAction
Example
Creating a node and using it in further actions
flow(
  Let(Graph.addNode({...}), (newNode, newGraph) =>
     Graph.addEdge({from: Node.port('x', newNode), to: '@out'})(newGraph))
)(graph)

location(loc, graph) → {Location}

Create a new location from a given object

Parameters:
Name Type Description
loc

Any processable form of location. TODO: list alle formats.

graph PortGraph

The graph in which the location is valid.

Source:
Returns:

A location object

Type
Location

mergeNodes(oldNode, newNode, graph, cbopt) → {PortGraph}

Merges the contents of a node with the given data. This CAN destroy the structure of the graph so be cautious and prefer updateNode whenever possible.

Parameters:
Name Type Attributes Description
oldNode Node

The old node that should get updated

newNode Object

New values for the old node as an object that gets merged into the node.

graph PortGraph

The graph

cb Callback <optional>

A callback function that is called with the newly inserted node.

Source:
Returns:

The new graph with the merged nodes.

Type
PortGraph

meta(graph) → {object}

Returns the meta information encoded in the graph

Parameters:
Name Type Description
graph PortGraph

The graph.

Source:
Returns:

An object with all meta information keys.

Type
object

module:Algorithm(compound, graph) → {Array.<Node>}

Returns a topological sorting of the graph.

Parameters:
Name Type Description
compound Node

A compound node to perform the topological sort in. The sorting is only considering nodes directly inside the compound. It does not go into further compounds.

graph PortGraph

The graph.

Source:
Throws:

If the graph has loops.

Type
Error
Returns:

A sorting of the nodes given as an array of nodes.

Type
Array.<Node>

namedFlow()

Deprecated:
  • This function is deprecated. Use `flow` with and set the names via the optional parameter.
Source:

node(loc, graph) → {Node}

Returns the node at the given location. [Performance O(|V|)]

Parameters:
Name Type Description
loc Location

A location identifying the node.

graph PortGraph

The graph.

Source:
Throws:

If the queried node does not exist in the graph.

Type
Error
Returns:

The node in the graph

Type
Node

nodeBy(fn, graph) → {Node|undefined}

Find a node using a predicate.

Parameters:
Name Type Description
fn function

A function that decides for each node if it should be rejected or not

graph PortGraph

The graph

Source:
Returns:

The first node that matches the predicate.

Type
Node | undefined

nodeByPath(path, graph) → {Node|undefined}

Returns a node that is located at a specific path in the graph.

Parameters:
Name Type Description
path CompoundPath

The path to the wanted node.

graph PortGraph

The graph

Source:
Returns:

The node or undefined if the path does not exist.

Type
Node | undefined

nodeNames(graph) → {Array.<string>}

Returns a list of node names. [Performance O(|V|)]

Parameters:
Name Type Description
graph PortGraph

The graph.

Source:
Returns:

A list of node names.

Type
Array.<string>

nodes(graph, predicateopt) → {Array.<Nodes>}

Returns a list of nodes on the root level.

Parameters:
Name Type Attributes Description
graph PortGraph

The graph.

predicate function <optional>

An optional function that filters nodes. If no predicate function is given, all nodes are returned.

Source:
Returns:

A list of nodes.

Type
Array.<Nodes>

nodes(graph) → {Array.<Nodes>}

Returns a list of nodes on the root level.

Parameters:
Name Type Description
graph PortGraph

The graph.

Source:
Returns:

A list of nodes.

Type
Array.<Nodes>

nodesBy(predicate, graph) → {Array.<Nodes>}

Returns a list of nodes on the root level selected by a given predicate.

Parameters:
Name Type Description
predicate function | Location

A function that filters nodes. Or alternatively you can use a location query.

graph PortGraph

The graph.

Source:
Returns:

A list of nodes.

Type
Array.<Nodes>
Examples

Select by function

// all nodes that have the name select
nodesBy((node) => node.name === 'select', graph)

Select by location query

// selects all if components in the current layer.
nodesBy('/if', graph)

nodesDeep(graph) → {Array.<Node>}

Get all nodes at all depths. It will go into every compound node and return their nodes and the nodes of their compound nodes, etc.

Parameters:
Name Type Description
graph PortGraph

The graph to work on

Source:
Returns:

A list of nodes.

Type
Array.<Node>

nodesDeepBy(predicate, graph) → {Array.<Node>}

Get all nodes at all depths that fulfill the given predicate. It will go into every compound node and return their nodes and the nodes of their compound nodes, etc.

Parameters:
Name Type Description
predicate function | Location

A function that filters nodes. Or alternatively you can use a location query.

graph PortGraph

The graph to work on

Source:
Returns:

A list of nodes that fulfill the predicate.

Type
Array.<Node>

outIncidents(source, graph, configopt) → {Array.<Edge>}

Gets all outgoing incident edges to a port. The given port or node is the source of each edge.

Parameters:
Name Type Attributes Description
source Location

The port from which the edge comes. This is the source node or port of the edge.

graph PortGraph

The graph

config Object <optional>

Optional config object

Properties
Name Type Attributes Default Description
layers Array.<String> <optional>
['dataflow']

Filter the edge based on the selected layers

goIntoCompounds Boolean <optional>
false

Optional argument that activates looking for edges inside compounds. If you specify a node as the location it will not go inside the node (if it is a compound) and look for outgoing edges inside the compound.

Source:
Returns:

An array of all outgoing (i.e. isFrom(port)) incident edges.

Type
Array.<Edge>

parent(loc, graph) → {Node}

Gets the parent of a node.

Parameters:
Name Type Description
loc Location

A location identifying the node whose parent is wanted.

graph PortGraph

The graph.

Source:
Returns:

The node id of the parent node or undefined if the node has no parent.

Type
Node

parseCompoundPath(compoundPathStr) → {Array.<String>}

Converts a compound path string into its array representation. The seperate parts must be divided by a '»'.

Parameters:
Name Type Description
compoundPathStr String

A string reperesenting the compound path divded by '»'.

Source:
Returns:

An array of node IDs representing the compound path.

Type
Array.<String>

pointsTo(target, graph, edge) → {boolean}

Checks whether an edge points to a given target.

Parameters:
Name Type Description
target Location

The target the edge should point to. This can either be a node or a port.

graph PortGraph

The graph

edge Edge

The edge to check

Source:
Returns:

True if the edge points to the target, false otherwise.

Type
boolean

port(port, graph) → {Node}

Returns a port specified by the short notation or a port query object. [Performance O(|V|)]

Parameters:
Name Type Description
port Port

A port object or a short notation for a port.

graph PortGraph

The graph.

Source:
Throws:

If the queried port does not exist in the graph.

Type
Error
Returns:

The actual port object with type information.

Type
Node

predecessor(target, graph, configopt) → {Port}

Returns the predecessors for a node or a port. Each node can only have exactly one predecessor for every port.

Parameters:
Name Type Attributes Description
target Location

The target to which the predecessors points.

graph PortGraph

The graph.

config Object <optional>

Optional config object

Properties
Name Type Attributes Default Description
layers Array.<String> <optional>
['dataflow']

Filter the edge based on the selected layers

goIntoCompounds Boolean <optional>
false

Optional argument that activates looking for edges inside compounds. If you specify a node as the location it will not go inside the node (if it is a compound) and look for a predecessor inside the compound.

Source:
Returns:

The preceeding port

Type
Port

predecessorNode(source, graph) → {Array.<Port>}

Get the dataflow predecessor of a node in the graph. This method works in O(1) when the cache is initialized.

Parameters:
Name Type Description
source Node | String

The target node as an ID or a node object.

graph PortGraph

The graph

Source:
Returns:

The ports that preceedes the node.

Type
Array.<Port>

predecessorPort(source, graph) → {Array.<Port>}

Get the dataflow predecessor of a node in the graph. This method works in O(1) when the cache is initialized.

Parameters:
Name Type Description
source Port | String

The target port as an ID or a node object.

graph PortGraph

The graph

Source:
Returns:

The ports that preceedes the node.

Type
Array.<Port>

predecessors(target, graph, configopt) → {Array.<Port>}

Returns a list of predecessors for a node or a port. Each node can only have exactly one predecessor for every port but this function always returns a list.

Parameters:
Name Type Attributes Description
target Location

The target to which the predecessors point.

graph PortGraph

The graph.

config Object <optional>

Optional config object

Properties
Name Type Attributes Default Description
layers Array.<String> <optional>
['dataflow']

Filter the edge based on the selected layers

goIntoCompounds Boolean <optional>
false

Optional argument that activates looking for edges inside compounds. If you specify a node as the location it will not go inside the node (if it is a compound) and look for predecessors inside the compound.

Source:
Returns:

A list of ports with that are predecessors of target

Type
Array.<Port>

predecessorsNode(source, graph) → {Array.<Port>}

Get the dataflow predecessors of a node in the graph. This method works in O(1) when the cache is initialized.

Parameters:
Name Type Description
source Node | String

The target node as an ID or a node object.

graph PortGraph

The graph

Source:
Returns:

A list of ports that preceedes the node.

Type
Array.<Port>

predecessorsNodePort(source, graph) → {Array.<Port>}

Get the dataflow predecessors of a node in the graph. This method works in O(1) when the cache is initialized.

Parameters:
Name Type Description
source Port | String

The target port as an ID or a node object.

graph PortGraph

The graph

Source:
Returns:

A list of ports that preceedes the node.

Type
Array.<Port>

predecessorsPort(source, graph) → {Array.<Port>}

Get the dataflow predecessors of a node in the graph. This method works in O(1) when the cache is initialized.

Parameters:
Name Type Description
source Port | String

The target port as an ID or a node object.

graph PortGraph

The graph

Source:
Returns:

A list of ports that preceedes the node.

Type
Array.<Port>

predecessorsUntil(node, predicate, graph) → {Array.<Node>}

Return all predecessors of a node or port, until a given subset.

Parameters:
Name Type Description
node Location | Array.<Location>

Look for predecessors of this location(s).

predicate Predicate

A predicate function (Node -> Boolean) that decides whether a node should be included in the predecessor chain (true) or if it should be left out (false).

graph Portgraph

The graph

Source:
Returns:

The nodes between the input node and other without both inputs.

Type
Array.<Node>

predecessorsUpTo(node, other, graph) → {Array.<Node>}

Return all predecessors of a node or port, until a given subset.

Parameters:
Name Type Description
node Location | Array.<Location>

Look for predecessors of this location(s).

other Node | Array.<Node>

A node or an array of node indicating where to stop

graph Portgraph

The graph

Source:
Returns:

The nodes between the input node and other without both inputs.

Type
Array.<Node>

query(loc, graph) → {function}

Create a query function for a location.

Parameters:
Name Type Description
loc Location

A location identifier.

graph PortGraph

The graph in which the location is valid.

Source:
Returns:

A function that takes another location or location identifier and compares it to the specified location loc. See Location.identifies.

Type
function

realizeEdgesForNode(loc, graph) → {Portgraph}

This goes through all edges that are connected to the given node and realizes them, if a node reference was replaced by an actual node. If it was replaced by another reference nothing will happen.

Parameters:
Name Type Description
loc Location

A location identifier for the node whose edges should be updated.

graph Portgraph

The graph to perform the operation on

Source:
Returns:

A new graph in which the edges for the given node are realized (if possible).

Type
Portgraph
Example

Where it is used, when modifying graphs.

var graph = Graph.flow(
  Graph.addNode({ref: 'a', name: 'a', ports: []}),
  Graph.addNode({ref: 'b', name: 'b', ports: []}),
  Graph.addEdge({from: 'a@0', to: 'b@0'}),
  // the following command will call realizeEdgesForNode
  // it will replace the 0-th port in the edge with the 'outA' port.
  Graph.replaceNode('a', {componentId: 'a', ports: [{port: 'outA', kind: 'input', type: 'generic'}]})
  // the following command will call realizeEdgesForNode
  // it will replace the 0-th port in the edge with the 'outA' port.
  Graph.replaceNode('b', {componentId: 'b', ports: [{port: 'inB', kind: 'input', type: 'generic'}]})
)()
// after this the graph will have an edge {from: 'a@outA', to: 'b@inB'} and not {from: 'a@0', to: 'b@0'} anymore.

references(graph) → {Array.<References>}

Gets a list of all reference nodes.

Parameters:
Name Type Description
graph PortGraph

The graph.

Source:
Returns:

A list of all defined reference nodes in the graph.

Type
Array.<References>

removeComponent(comp, graph) → {PortGraph}

Removes a component from the graph. [Performance O(|V| + |E|)]

Parameters:
Name Type Description
comp Component | string

The component that shall be removed, either the component object or the component id.

graph PortGraph

The graph.

Source:
Returns:

A new graph without the given component.

Type
PortGraph

removeEdge(edge) → {ChangeSet}

Creates a change set that removes the edge edge.

Parameters:
Name Type Description
edge Object

The edge to remove.

Source:
Returns:

The change set containing the deletion operation.

Type
ChangeSet

removeEdge(edge, graph) → {PortGraph}

Remove an edge in the graph

Parameters:
Name Type Description
edge Edge

The edge that should be removed. This needn't be in standard format.

graph PortGraph

The graph

Source:
Throws:

If there is no such edge in the graph.

Type
Error
Returns:

A new graph that does not contain the edge anymore.

Type
PortGraph

removeMetaKey(key, graph)

Removes the meta information in the graph for the given key to the value

Parameters:
Name Type Description
key string

The meta key that gets removed.

graph PortGraph

The graph.

Source:
Returns:

A new graph with the applied changes. The key will be undefined from in the graph.

removeNode(loc, graph) → {PortGraph}

Removes a node from the graph. [Performance O(|V| + |E|)]

Parameters:
Name Type Description
loc Location

The location identifying the node to delete.

graph PortGraph

The graph.

Source:
Returns:

A new graph without the given node.

Type
PortGraph

removeNodeMetaKey(key, loc, graph)

Removes the meta information for a node in the graph for the given key to the value

Parameters:
Name Type Description
key string

The meta key that gets removed.

loc Location

A location identifying the node.

graph PortGraph

The graph.

Source:
Returns:

A new graph with the applied changes. The key will be undefined from in the graph.

replaceNode(loc, newNode, graph) → {PortGraph}

Replace a node in the graph with another one. It tries to keep all edges.

Parameters:
Name Type Description
loc Location

A location specifying the node to replace

newNode Node

The new node that replaces the old one.

graph PortGraph

The graph

Source:
Returns:

A new graph in which the old node was replaces by the new one.

Type
PortGraph

replacePort(oldPort, newPort) → {Portgraph}

Replaces a port of a node in a graph

Parameters:
Name Type Description
oldPort Port

Port object to be replaced

newPort Port

Port object to replace with. It will update the old port. Old attributes will not be overwritten.

Source:
Returns:

Updated graph with oldPort replaced by newPort

Type
Portgraph

sameParents(locations, graph) → {Boolean}

Checks whether the locations have the same parent.

Parameters:
Name Type Description
locations Array.<Location>

An array of locations to check

graph Portgraph

The graph

Source:
Returns:

True if they have the same parents, false otherwise.

Type
Boolean

sameParentsNodes(locations, graph) → {Boolean}

Checks whether the locations have the same parent.

Parameters:
Name Type Description
locations Array.<Location>

An array of locations to check

graph Portgraph

The graph

Source:
Returns:

True if they have the same parents, false otherwise.

Type
Boolean

sequential(fns) → {GraphAction}

Create a sequence of actions. Each action takes the result of the preceeding action and the current graph.

Parameters:
Name Type Description
fns Array.<GraphActions>

An array of actions that are applied in sequence to the graph.

Source:
Returns:

A function that takes a graph and returns a new graph. As with every GraphAction it is possible to add a callback to the arguments to process the result with context information

Type
GraphAction
Example
Adding and removing a node
// in the first action, we specify the contents of the node.
// the second action gets the context information of the addNode (which is the added node)
// and the graph (i.e. it calls `Graph.removeNode(newNode, newGraph)`)
sequential([Graph.addNode({...}), Graph.removeNode])(graph)

set(value, loc, graph) → {PortGraph}

Sets properties for node.

Parameters:
Name Type Description
value Object

The properties to set, e.g. {recursion: true, recursiveRoot: true}

loc Location

The location identifying the node in which the property should be changed.

graph PortGraph

The graph

Source:
Returns:

A graph in which the change is realized.

Type
PortGraph
Example
var graph = ...
var newGraph = Graph.set({property: value}, '#nodeIDOrLocation', graph)
// you can get the value via get in the newGraph
var propertyValue = Graph.get('property', '#nodeIDOrLocation', graph)

setMeta(obj, graph) → {PortGraph}

Set meta information in the graph

Parameters:
Name Type Description
obj Object

An object with all keys that shall be changed.

graph PortGraph

The graph.

Source:
Returns:

A new graph with the applied changes.

Type
PortGraph

setMetaKey(key, value, graph)

Sets the meta information in the graph for the given key to the value

Parameters:
Name Type Description
key string

The meta key for the value.

value

Any possible value for the key.

graph PortGraph

The graph.

Source:
Returns:

A new graph with the applied changes. If there was already an value with this key it gets overwritten. Use updateMetaKey to only change specific parts.

setNode(node, mergeValue) → {ChangeSet}

Creates a change set to replace a node with a given value

Parameters:
Name Type Description
node string

The identifier of the node.

mergeValue Object

An object that contains a whole node that should be set. E.g. {recursive: true} will update the field recursive in the node and sets it to true.

Source:
Returns:

A change set containing the operation.

Type
ChangeSet

setNodeMeta(obj, loc, graph) → {PortGraph}

Set meta information for a node in the graph

Parameters:
Name Type Description
obj Object

An object with all keys that shall be changed.

loc Location

The location identifying the node.

graph PortGraph

The graph.

Source:
Returns:

A new graph with the applied changes.

Type
PortGraph

setNodeMetaKey(key, value, loc, graph)

Sets the meta information in the graph for the given key to the value

Parameters:
Name Type Description
key string

The meta key for the value.

value

Any possible value for the key.

loc Location

A location identifying the node.

graph PortGraph

The graph.

Source:
Returns:

A new graph with the applied changes. If there was already an value with this key it gets overwritten. Use updateNodeMetaKey to only change specific parts.

setPortName(loc, port, portUpdate, graph) → {PortGraph}

Updates a port of a node.

Parameters:
Name Type Description
loc Location

A location specifying the node to update.

port port

The port name or its index.

portUpdate Port

The new port object or parts of the new object (it will merge with the existing values).

graph PortGraph

The graph

Source:
Throws:

If the location does not specify a node in the graph.

Type
Error
Returns:

A new graph in which the port has been updated.

Type
PortGraph

successors(source, graph, configopt) → {Array.<Port>}

Get the successors of one node in the graph, optionally for a specific port.

Parameters:
Name Type Attributes Description
source Location

The source from which to follow the edges.

graph PortGraph

The graph.

config Object <optional>

Optional config object

Properties
Name Type Attributes Default Description
layers Array.<String> <optional>
['dataflow']

Filter the edge based on the selected layers

goIntoCompounds Boolean <optional>
false

Optional argument that activates looking for edges inside compounds. If you specify a node as the location it will not go inside the node (if it is a compound) and look for successors inside the compound.

Source:
Returns:

A list of ports that succeed the node.

Type
Array.<Port>

successorsNode(source, graph) → {Array.<Port>}

Get the dataflow successor of a node in the graph. This method works in O(1) when the cache is initialized.

Parameters:
Name Type Description
source Node | String

The source node as an ID or a node object.

graph PortGraph

The graph

Source:
Returns:

A list of ports that succeed the node.

Type
Array.<Port>

successorsPort(source, graph) → {Array.<Port>}

Get the dataflow successor of a node in the graph. This method works in O(1) when the cache is initialized.

Parameters:
Name Type Description
source Port | String

The target port as an ID or a node object.

graph PortGraph

The graph

Source:
Returns:

A list of ports that succeed the node.

Type
Array.<Port>

toJSON(graph) → {object}

Returns a JSON object for the graph

Parameters:
Name Type Description
graph PortGraph

The graph to convert

Source:
Returns:

A JSON representation of the graph.

Type
object

unCompound(node, graph) → {PortGraph}

Takes a compound node and moves all nodes out of the compound node and removes then removes the empty compound.

Parameters:
Name Type Description
node Compound

The compound node

graph PortGraph

The graph in which the compound node lies.

Source:
Returns:

The new graph where all nodes were moved out of the compound node.

Type
PortGraph

updateComponent(comp, merge, graph)

Update an existing component in the graph.

Parameters:
Name Type Description
comp Component | string

The component that will be update, either the component object or the component id.

merge Object

Updated values of the component. It is not possible to change the component id with this method.

graph PortGraph

The graph

Source:

updateComponent(compId, mergeValue) → {ChangeSet}

Creates a change set to update a component with a given value

Parameters:
Name Type Description
compId string

The componentId of the component.

mergeValue Object

An object that contains parts of a component that should be set. E.g. {isType: true} will update the field isType in the component and sets it to true.

Source:
Returns:

A change set containing the operation.

Type
ChangeSet

updateEdge(newEdge) → {ChangeSet}

Creates a change set that inserts a new edge into the edge list

Parameters:
Name Type Description
newEdge Object

The edge that should be inserted.

Source:
Returns:

A change set containing the insertion operation.

Type
ChangeSet

updateMetaKey(key, value, graph)

Updates the meta information in the graph for the given key to the value

Parameters:
Name Type Description
key string

The meta key for the value.

value

Any possible value for the key.

graph PortGraph

The graph.

Source:
Returns:

A new graph with the applied changes. If there was already an value with this key it gets updated. If there was no value at this key, the key will be created. If you want to replace the existing value use setMetaKey.

updateNode(node, mergeValue) → {ChangeSet}

Creates a change set to update a node with a given value

Parameters:
Name Type Description
node string

The identifier of the node.

mergeValue Object

An object that contains parts of a node that should be set. E.g. {recursive: true} will update the field recursive in the node and sets it to true.

Source:
Returns:

A change set containing the operation.

Type
ChangeSet

updateNodeMetaKey(key, value, loc, graph)

Updates the meta information in the graph for the given key to the value

Parameters:
Name Type Description
key string

The meta key for the value.

value

Any possible value for the key.

loc Location

A location identifying the node.

graph PortGraph

The graph.

Source:
Returns:

A new graph with the applied changes. f there was already an value with this key it gets updated. If there was no value at this key, the key will be created. If you want to replace the existing value use setNodeMetaKey.