ms-dag-ts v1.0.3
ms-dag-ts
Just a directed acyclic graph implementation.
Directed Acyclic Graph
Usage
To install, run npm install ms-dag-ts.
Graph
new Graph()
Instantiates a new instance of graph.
addVertex(...uplinks: Vertex[]): Vertex
Adds a new
Vertexto the graph, optionally uplinking it to the given vertices.
addEdge(top: Vertex, bottom: Vertex): Edge
Adds a new
Edgeto the graph, creating a downlink fromtoptobottom.
availableEdges(): ProtoEdge[]
Returns an array
ProtoEdgeobjects which describe eachEdgethat could be connected without breaking the graph.
traverse(cb: TraversalCallback): void
Traverses the graph in order, calling
cbat eachVertex.
Vertex
new Vertex(id?: number)
Instantiates a new instance of
Vertex, optionally assigning itid.
id+get: number
Gets the id of this
Vertex.
uplinks+get: Edge[]
Gets the array of
Edgeobjects which describe every connection to thisVertex.
downlinks+get: Edge[]
Gets the array of
Edgeobjects which describe every connection from thisVertex.
first+get: Vertex
Gets the first
Vertexin the chain.
before+get: Vertex[]
Gets an array of
Vertexobjects which includes only the vertices which appear before thisVertexin the chain.
previous+get: Vertex
Gets the
Vertexwhich appears immediately before thisVertexin the chain.
next+get: Vertex
Gets the
Vertexwhich appears immmediately after thisVertexin the chain.
after+get: Vertex
Gets an array of
Vertexobjects which include only the vertices which appear after thisVertexin the chain.
last+get: Vertex
Gets the last
Vertexin the chain.
remove(): Vertex
Removes this
Vertexfrom the chain, stitching together the previous and next vertices and returning thisVertex.
insertBefore(vertex: Vertex): Vertex
Inserts the given
Verteximmediately before thisVertexin the chain.
insertAfter(vertex: Vertex): Vertex
Insert the given
Verteximmediately after thisVertexin the chain.
isBefore(vertex: Vertex): boolean
Returns a boolean value indicating if this
Vertexis before the givenVertexin the chain.
isAfter(vertex: Vertex): boolean
Returns a boolean value indicating if this
Vertexis after the givenVertexin the chain.
above(): Vertex[]
Returns an array of
Vertexobjects for which thisVertexis a direct or indirect downlink.
directlyAbove(): Vertex[]
Returns an array of
Vertexobjects for which thisVertexis a direct downlink.
isAbove(vertex: Vertex): boolean
Returns a boolean value indicating if this
Vertexis a direct or indirect downlink of the givenVertex.
below(): Vertex[]
Returns an array of
Vertexobjects for which thisVertexis a direct or indirect uplink.
directlyBelow(): Vertex[]
Returns an array of
Vertexobjects for which thisVertexis a direct uplink.
isBelow(vertex: Vertex): boolean
Returns a boolean value indicating if this
Vertexis a direct or indirect uplink of the givenVertex.
connectTo(vertex: Vertex, id?: number): Edge
Connects this
Vertexto the givenVertexreturning a new instance ofEdgewhich defines the relationship and optionally assigning it the given id.
reflow(): void
Moves this
Vertexup the chain such that it is above all of its downlinks. Callsreflow()for each uplink.
availableConnections(): ProtoEdge[]
Returns an array of
ProtoEdgeobjects which describe every possible connection which could be made without causing a cyclic flow.