Tree
tree()
Lays out and renders tree nodes.
For each node, the tree function creates an anchor of the format "[<child-index>-]<child-index>" (the root is "0", its first child "0-0", second "0-1" and so on) that can be used to query a nodes position on the canvas.
The node object passed to callbacks contains the following keys:
name(str): Name of the node’s anchorgroup-name(str): Name of the node’s group elementdepth(int): Depth of the noden(int): Sibling index of the nodecontent(any): Content of the node
import cetz.tree
set-style(content: (padding: .1))
tree.tree(([Root], ([A], [A.A], [A.B]), ([B], [B.A])))
A nested array of content that describes the structure the tree should take. Example: ([root], [child 1], ([child 2], [grandchild 1]))
The function to call to draw a node. The function will be passed the node to draw (a dictionary with a content key) and is expected to return elements ((node) => elements). The node must be drawn at the (0,0) coordinate. If auto is given, just the node’s value will be drawn as content.
The function to call draw an edge between two nodes. The function will be passed the name of the starting node, the name of the ending node, the start node, the end node, and is expected to return elements ((parent-node, child-node) => elements). If auto is given, a straight line will be drawn between nodes.
A string describing the direction the tree should grow in (“up”, “down”, “left”, “right”)
Name of the anchor to align the tree to. Use the root node anchor ("0") to align the tree to the root nodes position.