Represents a path between two nodes.
Inheritance Hierarchy
Path
Remarks
The path is defined by an ordered list of edges. The nodes along the path are also provided, but may be ambiguous if there are multi-edges between certain nodes.
This class cannot be instantiated
Type Details
- yFiles module
- view-layout-bridge
Properties
Gets the distance or length of the path.
Remarks
Some algorithms support edge weights (or costs), which makes the path's distance the sum of all edge weights along the path. If no explicit weights are provided, usually a uniform weight of
1
is assumed, which makes the path's distance merely the number of edges that comprise it.Examples
algorithm.source = startNode
algorithm.sink = endNode
const result = algorithm.run(graph)
console.log(result.distance) // the distance between startNode and endNode
Gets an ordered collection of edges defining this path.
Examples
// configure the shortest path algorithm
const algorithm = new SingleSourceShortestPaths({
// single source
source: startNode,
// add edge cost mapping which returns the actual length of the edge
costs: (edge) =>
edge.style.renderer
.getPathGeometry(edge, edge.style)
.getPath()!
.getLength(),
})
// run the algorithm:
// calculate paths from startNode to all nodes in the graph
const result = algorithm.run(graph)
// for each end node
for (const targetNode of targetNodes) {
// set its distance to the startNode as label text
graph.setLabelText(
targetNode.labels.get(0),
`${result.getPathTo(targetNode)!.distance}`,
)
// and mark the edge path from start to the end node
for (const edge of result.getPathTo(targetNode)!.edges) {
graph.setStyle(edge, highlightPathStyle)
}
}
Gets the end node of the path.
Gets the start node of the path.