On this page

subgraph module

Use subgraph to construct and inspect opaque zero-copy selections of half-edges. Pass those selections to graph queries, drawing, and layout functions that accept a subgraph argument.

Concepts

Subgraphs

Subgraph objects are opaque zero-copy values.

  • subgraph.label(g, label) constructs a subgraph from a base62 label.
  • subgraph.bits(g, bits) constructs a subgraph from a boolean hedge array.
  • subgraph.compass(g, compass) selects half edges with a DOT compass point.
  • subgraph.to-label(sg) returns the base62 label.
  • subgraph.hedges(sg) returns included hedge indices.
  • subgraph.contains(sg, hedge) tests hedge membership.

subgraph

  • label()
  • bits()
  • compass()
  • to-label()
  • hedges()
  • contains()
  • complement()
  • contains-edge()
  • node-depths()

label

Construct a subgraph object from a base62 label.

#let g = graph.build({
  graph.node(<a>)
  graph.node(<b>)
  graph.edge(graph.source(<a>, compass: "e"), graph.sink(<b>))
})
#let east = subgraph.compass(g, "e")
#let same = subgraph.label(g, subgraph.to-label(east))
#subgraph.hedges(same).len()

Parameters

graph

dictionary

Graph object whose half-edge set the label refers to.

label

string

Base62 subgraph label returned by to-label or produced by Linnest.

bits

Construct a subgraph object from a boolean hedge array.

#let g = graph.build({
  graph.node(<a>)
  graph.node(<b>)
  graph.edge(graph.source(<a>), graph.sink(<b>))
})
#let first = subgraph.bits(g, (true, false))
#subgraph.contains(first, 0)

Parameters

graph

dictionary

Graph object whose half-edge order defines the bit array.

bits

array

Boolean array selecting half edges by graph half-edge index.

compass

Construct a subgraph object from a DOT compass point such as "n" or "s".

#let g = graph.build({
  graph.node(<a>)
  graph.node(<b>)
  graph.edge(graph.source(<a>, compass: "e"), graph.sink(<b>))
})
#subgraph.hedges(subgraph.compass(g, "e")).len()

Parameters

graph

dictionary

Graph object to filter by half-edge compass statement.

compass

string

DOT compass point such as "n", "s", "e", or "w".

to-label

Convert a subgraph object to its base62 label.

#let g = graph.build({
  graph.node(<a>)
  graph.node(<b>)
  graph.edge(graph.source(<a>), graph.sink(<b>))
})
#subgraph.to-label(subgraph.bits(g, (true, false)))

Parameters

subgraph

bytes

Subgraph object returned by this module or by graph.cycles/graph.forests.

hedges

Return the hedge indices included in a subgraph object.

#let g = graph.build({
  graph.node(<a>)
  graph.node(<b>)
  graph.edge(graph.source(<a>), graph.sink(<b>))
})
#subgraph.hedges(subgraph.bits(g, (true, false)))

Parameters

subgraph

bytes

Subgraph object to inspect.

contains

Test whether a subgraph object includes a hedge.

#let g = graph.build({
  graph.node(<a>)
  graph.node(<b>)
  graph.edge(graph.source(<a>), graph.sink(<b>))
})
#subgraph.contains(subgraph.bits(g, (true, false)), 0)

Parameters

subgraph

bytes

Subgraph object to inspect.

hedge

int

Half-edge index to test.

complement

Return the complement of a subgraph’s selected half edges.

Parameters

graph

dictionary

Graph object whose half-edge order defines the result.

selected

bytes

Subgraph object to invert.

contains-edge

Test whether either half-edge of an edge record is selected.

Parameters

subgraph

bytes

Subgraph object to inspect.

edge

dictionary

Edge record from graph.edges(...) or draw callback data.

node-depths

Compute breadth-first node depths inside a selected edge set.

Parameters

graph

dictionary

Graph object to inspect.

selected

bytes

Subgraph whose selected half edges define the traversal edges.

root

int

Root node index.

Default: 0