Skip to main content

Path

Models the path between two vertices, which consists of a series of vertices connected by edges.

Extends​

Methods​

contains()​

contains(obj, doNotFuzzyMatchNodes?): boolean

Returns true if the path contains the given object (a node, group, port or edge), false otherwise.

Parameters​

obj​

Node/Port/Edge, or object id, of the element to test for.

Edge | Vertex

doNotFuzzyMatchNodes?​

boolean

By default, if you pass a node/group in to this method and the path passes through a port on that node/group, this method returns true. But if you set doNotFuzzyMatchNodes to true, then this method will return true only if the node/group itself is on the path.

Returns​

boolean

True if Path contains the object, false otherwise.


deleteAll()​

deleteAll(): void

Removes all vertices and edges in this path from the underlying Toolkit. This is an alias for deleteVertices, since deleting a vertex causes its edges to also be deleted.

Returns​

void


deleteEdges()​

deleteEdges(): void

Deletes, from the underlying model, all of the edges in this path.

Returns​

void


deleteVertices()​

deleteVertices(): void

Deletes, from the underlying model, all the nodes/groups in this path. As with the contains method, there is a special consideration here: if a path passes through ports on a node/group, then that node/group will be, for the purposes of this method, considered to be part of the path and it will be deleted. If you instead wish to delete only the ports in a path, use deletePorts. Note that this method will, of course, have the effect of also deleting all the edges, since the nodes/groups for those edges will no longer exist.

Returns​

void


each()​

each(fn): void

Iterates through the path one step at a time. Each step consists of an object containing a vertex, and, for all entries except the first, an edge member, which supplies the Edge that links to the Vertex (which is why it is null for the first entry).

Parameters​

fn​

(i, p) => any

Function to call for each step.

Returns​

void


eachEdge()​

eachEdge(fn): void

Invoke the given function on each edge in the dataset

Parameters​

fn​

(i, e) => void

Returns​

void

Inherited from​

FilterableDataset.eachEdge


eachGroup()​

eachGroup(fn): void

Invoke the given function on each group in the dataset

Parameters​

fn​

(i, e) => void

Returns​

void

Inherited from​

FilterableDataset.eachGroup


eachNode()​

eachNode(fn): void

Invoke the given function on each node in the dataset

Parameters​

fn​

(i, n) => void

Returns​

void

Inherited from​

FilterableDataset.eachNode


eachVertex()​

eachVertex(fn): void

Invoke the given function on each vertex (node or group) in the dataset

Parameters​

fn​

(i, e) => void

Returns​

void

Inherited from​

FilterableDataset.eachVertex


exists()​

exists(): boolean

Returns whether or not a given path exists.

Returns​

boolean

True if path exists, false otherwise.


filter()​

filter(spec, includePartials?): any

Filter the dataset and return a filtered copy.

Parameters​

spec​

any

includePartials?​

boolean

Returns​

any

Inherited from​

FilterableDataset.filter


getAllEdgesFor()​

getAllEdgesFor(v): Edge[]

Gets all the edges in the path that are connected to the given vertex.

Parameters​

v​

Vertex

Vertex to get edges for.

Returns​

Edge[]


getCost()​

getCost(): number

Gets the cost of the given path. Edges in VisuallyJs can have a cost associated with them (the default is 1), and so the cost of any given path is the sum of the cost of all of the edges in the path.

Returns​

number

Total cost of the Path. Null if path does not exist.


getEdgeAt()​

getEdgeAt(idx): Edge

Gets the Edge at the given index in the Path.

Parameters​

idx​

number

Index of the Edge to retrieve. You can use negative numbers here: an index of -1 means get the last edge. An index of -2 means get the last but one. etc.

Returns​

Edge


getEdgeCount()​

getEdgeCount(): number

Counts the number of edges in the path. This may be zero, if the given path spec did not select a valid path in the model.

Returns​

number


getNodeAt()​

getNodeAt(idx): Vertex

Gets the Vertex at the given index in the path.

Parameters​

idx​

number

Index of the vertex to retrieve.

Returns​

Vertex

vertex at the given index, or null if no vertex exists at the given index.


getVertex()​

getVertex(obj): Vertex

Retrieve the specified vertex from the path

Parameters​

obj​

Either a vertex ID or a node/group/port.

string | Vertex

Returns​

Vertex

A Vertex, if the given vertex is in the path, otherwise null.


getVertexCount()​

getVertexCount(): number

Counts the number of vertices in the Path (including the start and end nodes/groups). Note that for the purposes of this calculation, a Port is considered a vertex, as is a Group.

Returns​

number


getVertices()​

getVertices(): Vertex[]

Get all the vertices in the path.

Returns​

Vertex[]


isEmpty()​

isEmpty(): boolean

Returns whether or not a given path is empty

Returns​

boolean

True if path is empty, false otherwise.