How can I place a node relative to another node or its outline in fletcher?

Hi everyone,
i am trying to place rectangular nodes in a fletcher diagram and want each node to also have a smaller circular node on its corner with a number inside. I can of course place them by hand as shown below, but if change the content of the larger node, the smaller node is not placed correctly anymore. I have not been able to find out how to place one node relative to another node (or in this case, relative to the outline), so any insight would be appreciated.

#import "@preview/fletcher:0.5.7" as fletcher: diagram, node, edge
#diagram({
  node((0, 0), text("test"), shape: rect, stroke: 1pt)
  node((0.25, -0.18), text(size: 10pt)[2], shape: circle, stroke: 1pt, fill: white, inset: 2pt)
})

Screenshot_2025-05-20_13-09-24

Hi. This is covered in the “Node anchors” section of the manual.

#import "@preview/fletcher:0.5.7": diagram, edge, node

#let badge(pos, body, ..args) = {
  body = text(size: 10pt, body)
  node(pos, shape: circle, fill: white, inset: 2pt, ..args, body)
}

#diagram({
  node((0, 0), name: <this>, shape: rect, stroke: 1pt)[test]
  badge(<this.north-east>, stroke: 1pt)[2]
})

image

2 Likes

Thanks, i somehow missed this section, was looking all over the manual…