Skip to content

Can't get node name in draw-node #1108

Description

@RenanElfo

I'm trying to style a tree and I'd like to be able to get a particular node's position within the tree. I can currently get it in draw-edge, since the callback function gives me a node with a name from which I can derive its position, but this does not happen for draw-node:

let ignore-number = 1
tree.tree(
  data,
  direction: "down",
  draw-node: node => {
    // Would like to write a node-index function like the one
    // in draw-edge
    circle((), radius: 0.25, stroke: white.darken(50%))
    content((), text(white, size: 0.75em, [#node.content]))
  },
  draw-edge: (parent, child) => {
    let child-index = child
      .name
      .split("-")
      .enumerate()
      .map(((index, it)) => {
        if index == 0 {
          calc.pow(2, child.depth) - 1
        } else {
          calc.pow(2, child.depth - index) * int(it)
        }
      })
      .fold(0, (acc, it) => acc + int(it))
    if child-index >= node-size(data) - ignore-number {
      return none
    }
    let (a, b) = (parent.group-name, child.group-name)
    line((a, .2, b), (b, .2, a))
  },
)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions