path

A route through a network, named by the vertices or the edges it passes.

pathNode
On this page
A grid of nine vertices with the shortest path from the top-left corner to the bottom-right laid over it in orange, passing through the centre.A grid of nine vertices with the shortest path from the top-left corner to the bottom-right laid over it in orange, passing through the centre.

#Attributes

throughRequiredImplicit
The vertices visited, in order, as #ids: at least two. Or the edges walked, in order, each leaving from where the one before it ended; an edge is named by the id an inline edge declares. Never a mix.
Can be written as shorthand: path:value
colourAnimatable
The stroke's hue.
paint
Also written: color
Defaultorange
hiddenAnimatable
Declared but not drawn. It still derives its length. Animatable.
Defaultfalse

#Derived attributes

Computed while the element renders — read one with #id.name in attribute position or {{#id.name}} in prose, never set.

lengthDerived
The summed weight of the edges taken — the hop count on an unweighted network.
hopsDerived
How many edges the path takes.

#Allowed in

#Examples

A weighted network of six vertices, its weights shown, with the shortest path from A to F, A–B–E–F of total weight 3, laid over it.A weighted network of six vertices, its weights shown, with the shortest path from A to F, A–B–E–F of total weight 3, laid over it.
network{
    vertex#a{A}
    vertex#b{B}
    vertex#c{C}
    vertex#d{D}
    vertex#e{E}
    vertex#f{F}
    edge(from: #a; to: #b; weight: 1)
    edge(from: #b; to: #c; weight: 1)
    edge(from: #c; to: #f; weight: 2)
    edge(from: #a; to: #d; weight: 1)
    edge(from: #d; to: #e; weight: 2)
    edge(from: #e; to: #f; weight: 1)
    edge(from: #b; to: #e; weight: 1)
    path#route(through: #a, #f)
}(
    show weights
)
Three frames of the second step: a rail network of five cities, then a teal route from London through Paris to Rome drawing in.Three frames of the second step: a rail network of five cities, then a teal route from London through Paris to Rome drawing in.
network{
    vertex#london{London}
    vertex#paris{Paris}
    vertex#brussels{Brussels}
    vertex#zurich{Zurich}
    vertex#rome{Rome}
    edge(from: #london; to: #paris)
    edge(from: #london; to: #brussels)
    edge(from: #brussels; to: #zurich)
    edge(from: #paris; to: #zurich)
    edge(from: #paris; to: #rome)
    edge(from: #zurich; to: #rome)
    cue.draw{
        path(through: #london, #paris, #rome; colour: teal)
    }(
        in: 2
    )
}

#Notes

  • Through vertices, the path is the shortest route visiting them in turn: path(through: #a, #f) from a to f, path(through: #a, #c, #f) from a to c and on to f.
  • The route is weighted when the network's edges carry weights, and one-way on a directed network.
  • Where several routes are equally short, the path takes one of them, the same every time; name a vertex in between, or write the walk, where the route matters.
  • Through edges, the path is the walk along them exactly as written, path(through: #e1, #e2, #e3), and can take a self-loop, one of two parallel edges, or an edge twice.
  • Each edge of a walk must leave from where the one before it ended: 'path.through' cannot take '#e1' after '#e2' — each edge must leave from the vertex the one before it ended at, by its from: on a directed network.
  • Drawn as a broad stroke over the edges it takes and under the vertices it visits.
  • Under cue.draw the path draws along its route.
  • Where some leg has no route, nothing is drawn and nothing is derived.

Last updated