Skip to contents

Turns an as_dag() dag into a dag_layout, the plain data that dag_layers() and ggplot_dag() draw from. Coordinates are in dagviz's SVG pixel space, with y growing downward (dag_theme() reverses the y scale to match).

Usage

dag_layout(dag, style = style_metro())

Arguments

dag

A dag, as returned by as_dag() or tar_dag().

style

A style_metro() object.

Value

A dag_layout: a classed list of

  • nodes: one row per node, in row order - name, label, row, col, x, y, color_index, plus the dag's extra node columns. Those can't be named row, col, x, y or color_index: the layout needs these, so such a column is an error.

  • segments: straight lines, layer ("leader", "vline", "bridge" or "hline"), x, y, xend, yend, from, to and order (dagviz's draw order, shared with arcs).

  • arcs: one point path per arc (id), with x, y, from, to and order.

  • labels: name, label, x, y.

  • edge_paths: one full point path per graph edge - from, to, piece ("vline", "arc" or "hline"), x, y, and order (point order along the path) - used for edge_color other than "source", for any edge_width, and for highlighting paths.

  • edges: the dag's edges as they are - from, to, plus any extra edge columns, such as the n of dag_collapse(), which edge_width of dag_layers() can name. (They are kept apart from edge_paths, so that no column of yours can overwrite a coordinate there.)

  • viewbox: a list of left, top, bottom, right, width and height.

  • style: the style_metro() object.

Examples

dag <- as_dag(data.frame(from = c("a", "a", "b"), to = c("b", "c", "c")))
lay <- dag_layout(dag, style_metro())
print(lay)
#> <dag_layout> 3 nodes, 3 edges, 2 columns
lay$nodes
#>   name label row col  x  y color_index
#> 1    a     a   0   0 55 15           0
#> 2    b     b   1  -1 35 35           1
#> 3    c     c   2  -1 35 55           2