-
Notifications
You must be signed in to change notification settings - Fork 1
API
The graphtools package contains a collection of useful tools for working with Buggy graphs.
A path is a sequence of nodes or a sequence of objects where the nodes are all adjacent. If the sequence is given as an object those have the following form:
{ "node": "NODE_ID", "port": "PORT_ID", ["edge": EDGE_OBJ] }
It specifies over which port (PORT_ID) one arrived at the specific node (so PORT_ID must be a port of the node with NODE_ID). The edge identifies how to get to this node from the predecessor. The edge object is available for all but the first element on a path.
For pathes there are the following functions:
equal(path1, path2)
: Tests if the two pathes are equal (start and end in the same nodes and go through the exact same nodes on their way). It does not check if the taken ports are always the same.
latestSplit(graph, path1, path2)
: Returns the latest common node, that separates the two pathes. If both paths are equal it returns undefined
.
clone(graph)
: Creates a new graph that has the exact same nodes and edges.
edit(graph)
: Returns the pure JSON representation of the graph without all the graphlib features.
finalize(graph)
: Parses the pure JSON format to return a graphlib version of the graph.
prefix(prefix, name)
: Applies the name prefixing for e.g. path names or similar stuff.
isNPG(graph)
: Returns whether the graph is a network-port-graph (i.e. has nodes that have ports).
isNG(graph)
: Checks whether the graph is a network-graph (i.e. process nodes and port nodes).
isPortNode(nodeName)
: Returns true
if the node is a port node (in an NG), false
otherwise.
portNodePort(nodeName)
: Returns the name of the port that the port node represents.
portNodeName(nodeName)
: Returns the name of the node that the port node is connected to.
nthInput(graph, node, n)
: Returns the n-th input of the given node (as a name) in the graph.
nthOutput(graph, node, n)
: Returns the n-th output of the given node (as a name) in the graph.
prefixNode(prefix, node)
: Creates a new node whose name has the prefix prefix
.
addParent(parent, node)
: Adds a reference to parent
to the node node
(given as a node object). Returns the new node, does not change the old one.
hierarchy(graph, node)
: Returns an array of all the parents and the parents parents of the given node.
hierarchyConnection(graph, link)
: Returns all hierarchy borders that lie between two nodes connected by an link ({v: 'NODE_FROM', w: 'NODE_TO'}
). It returns an array of compounds between the two nodes.
rawHierarchyConnection(graph, link)
: Returns all hierarchy borders that lie between two nodes connected by an link ({v: 'NODE_FROM', w: 'NODE_TO'}
). It returns an array of objects that all are in the format: {node: 'COMPOUND_ID', type: 'in/out'}
. The type indicates if the edge is going into or out of the compound.
linkName(link)
: Generates a name for the link (a connection between nodes that not necessarily have the same parent.
getAll(graph, id)
: Returns all nodes (as names) in the graph that have the given id
(e.g. all math/add
nodes).
ports(graph, node)
: Returns all ports (input and output) of a given node.
portType(graph, node, port)
: Returns the type of the given port of node
independent of its type (input or output).
setPortType(graph, node, port, type)
: Sets the type of the given port of node
to type
. It automatically determines if it is an input or output port.
portDirectionType(graph, node, port)
: Gets the direction type of a port. I.e. it returns inputPorts
or outputPorts
.
predecessor(graph, node, port)
: Gets the predecessor of the node over the port port
. It returns an array of objects in the following format: {node: 'NODE_ID', port: 'OUTPUT_PORT', edge: EDGE}
. It contains the predecessor node, the output port it came in through (the port is always one of the predecessor) and the edge.
successor(graph, node, port)
: Gets the successor of the node over the port port
. It returns an array of objects in the following format: {node: 'NODE_ID', port: 'INPUT_PORT', edge: EDGE}
. It contains the successor node, the input port it came in through (the port is always one of the predecessor) and the edge.
walk(graph, node, path, options)
: Tries to follows a given path through the graph starting at node
and returns the list of nodes on the path. It uses the successor
function to track the neighbors. Where the node
can either be
- the name of the starting node
- an object
{node: 'START', port: 'USE_PORT'}
that forces the walk to useUSE_PORT
for the first node. The path itself can be - an array of ports that should be followed (even if the USE_PORT field is set, you must start with it as the first port). If it is not possible to follow the port a empty list of paths is returned.
- a function that is called for every node on the path and that returns
- a list of ports to continue with
- an empty list to stop the walk
-
null
to discard the branch. The function takes three arguments:graph, node, port
, where the node is the name of the current node on the path. The port is the port it used to get tonode
.
- An optional object that can have the following properties:
-
keepPorts
: If this field is true,walk
will return a list of objects that each have the format:{node: 'NODE_ID', port: 'INPUT_PORT', edge: EDGE}
. It will not have an edge object for the first node on the path.
-
walkBack(graph, node, path, options)
: Similar to walk
but it uses the predecessor
function to track neighbors.