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 multiple edges between certain nodes.
Type Details
- yfiles module
- view-layout-bridge
- yfiles-umd modules
- view-layout-bridge
- Legacy UMD name
- yfiles.analysis.Path
See Also
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
See Also
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)
}
}
// 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)
}
}