Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow optionally specifying branch lengths for trees #641

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/lib/tree.typ
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,20 @@
}
assert(draw-node != none, message: "Node draw callback must be set!")

let build-node(tree, depth: 0, sibling: 0) = {
let build-node(tree-arr, depth: 0, sibling: 0) = {
let children = ()
let content = none

let (e, tree) = if type(tree-arr) == array and tree-arr.len() == 2 and type(tree-arr.at(0)) in (int,float) {
tree-arr
} else {
(1, tree-arr)
}
let depth = depth + e

if type(tree) == array {
children = tree.slice(1).enumerate().map(
((n, c)) => build-node(c, depth: depth + 1, sibling: n)
((n, c)) => build-node(c, depth: depth, sibling: n)
)
content = tree.at(0)
} else {
Expand Down
5 changes: 5 additions & 0 deletions tests/tree/test.typ
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,8 @@
})
h(.1cm)
}

#test-case({
// Specify branch lengths
cetz.tree.tree(([], (1, ([], (1, []), (1, []))), (2, [])))
})
Loading