Jollywatt / typst-fletcher

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

Add support for anchors #59

Open iverks opened 2 days ago

iverks commented 2 days ago

Problem

When adding a slightly too high bend to an edge going to a very wide node, I get some weird effects.

image

#figure(
  diagram(
    node-fill: color.transparentize(red, 60%),
    node-stroke: color.transparentize(red, 20%),
    // cell-size: 0mm,
    node((0, 0), [Initial structure model], name: <sm>),
    edge("-|>"),
    node((0, 1), [Calculate intensities $Fc^2$], name: <ci>),
    edge("-|>"),
    node((0, 2), [Calculate difference\ between $Fo^2$ and $Fc^2$], name: <cd>),
    edge("-|>"),
    node((0, 3), [Convergence], name: <conv>),
    edge(text(eastern,[yes]), "-|>"),
    node((0, 4), [Final model], name: <fin>),

    edge((0, 3), (1, 2), text(red, [no]), "-|>", bend: -25deg),
    node((1, 2), [Calculate corrections\ (add/remove atoms)], name: <cc>),
    edge(<cc>, <ci>, "-|>", bend: -30deg), // THIS IS THE ONE
  ),
  caption: [Flow chart of refinement],
) <refinement_flowchart>

Proposed solution

By adding support for CeTZ style anchors, I would be able to specify that the arrow should start at the first node's north position and end at the second node's east position

...
   edge((name: <cc>, anchor: 90deg), (name: <ci>, anchor: 0deg), "-|>", bend: -30deg), // THIS IS THE ONE
...
Jollywatt commented 1 day ago

By the way, you get fix this manually using the shift option of edge() like this:

edge(<cc>, <ci>, "-|>", bend: -30deg, shift: (0, 10pt))

or by offsetting coordinates slightly like this:

edge(<cc>, (to: <ci>, rel: (.4, 0)), "-|>", bend: -30deg)

but yeah, this should maybe be done automatically.