Jollywatt / typst-fletcher

Typst package for drawing diagrams with arrows, built on top of CeTZ.
MIT License
270 stars 6 forks source link

Add support for edge labels to follow edges #27

Closed TakodaS closed 1 month ago

TakodaS commented 2 months ago

Unless I am mistaken, it is currently not possible to have edge labels follow the edge they are attached to. Unfortunately, using the builtin rotate function causes diagram to become very confused leading to spacing issues.

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

#diagram(
  debug: 3, node((0, 0), "A"), node((0, 1), "B"), edge(
    (-1, 0), (-1, 1), "->", rotate(-90deg)[Some complicated flow], label-side: right,
  ), node((0, 3), "C"), node((1, 4), "D"), edge(
    (0, 3), (1, 4), "->", rotate(45deg)[Some complicated flow], label-side: right,
  ),
)

fletcher-issue(1)

Jollywatt commented 2 months ago

Try using rotate(reflow: true)?

TakodaS commented 2 months ago

Ah it was right there in the typst documentation! Much appreciated! It is getting there but still doesn't work properly for the 45deg label

#import "@preview/fletcher:0.4.3" as fletcher: diagram, node, edge
#set page(width: 270pt, height: 320pt)

#diagram(
  debug: 3, node((0, 0), "A"), node((0, 1), "B"), edge(
    (-1, 0), (-1, 1), "->", rotate(-90deg, reflow: true)[Some complicated flow], label-side: right,
  ), node((0, 3), "C"), node((2, 5), "D"), edge(
    (0, 3), (2, 5), "->", rotate(45deg, reflow: true)[Some complicated flow], label-side: left,
  ),
)

fletcher-issue(3)

I think this behavior should be by default in fletcher, maybe eventually leading to "text along path" functionality like in latex. What do you think?

Jollywatt commented 2 months ago

Yeah, that looks wrong - and worse I can't seem to fix it by playing around. Since this is so hard, automatic rotation of labels along (straight) edges would be a good feature to add.

Jollywatt commented 1 month ago

This has been added in 7ba5655!