Jollywatt / typst-fletcher

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

support relative coordinates? #40

Closed Kreijstal closed 3 months ago

Kreijstal commented 4 months ago

I tried (rel:,to:) in cetz, but it seems no dice, why isn't this supported?

Jollywatt commented 4 months ago

Unfortunately, this is because fletcher uses its own coordinate system ("elastic coordinates"), and I simply haven't replicated everything cetz can do with coordinate transformations.

  1. I could reimplement all of cetz special coordinates (relative, polar, tangent, etc), but I don't want to duplicate all that functionality in a separately maintained package.
  2. Alternatively, fletcher could integrate more closely with cetz in order to fully support cetz's special coordinates and anchors. However, I don't know how to do that.

The reason fletcher doesn't integrate with cetz more closely is because the order of operations makes it difficult:

  1. First, the physical dimensions of nodes in a diagram are determined from measure().
  2. The nodes' row and column positions (elastic coordinates), combined with their sizes, then determines the diagram's grid layout (the row and column sizes, or how elastic coordinates map to physical positions).
  3. Then, the physical positions of nodes (and edges) are calculated and these are given to cetz to draw.

In order to fully support cetz coordinates (to enable e.g., node((rel: (1, -1), to: "anchor"), [Hi]) where the (1, -1) are in the diagram's coordinates), cetz needs to know how to fully resolve the coordinates, which means the conversion from elastic to physical coordinates must be defined. However, this coordinate transformation is not known until all the nodes in the diagram are measured and their row/colum positions (elastic coordinates) are known.

Jollywatt commented 4 months ago

Near-duplicate: #37

Jollywatt commented 3 months ago

CeTZ-style coordinate expressions (including (rel:, to:) have been added in v0.5.0