typst-pinit icon indicating copy to clipboard operation
typst-pinit copied to clipboard

Usage with cetz

Open mohe2015 opened this issue 1 year ago • 3 comments

Hi,

is it somehow possible to point to something in a cetz canvas? By reading the documentation I could not find out how/whether this works.

Thank you

Kind regards Moritz

mohe2015 avatar Oct 31 '24 12:10 mohe2015

Seems like this is trivial with

content(position, pin(pinname))

mohe2015 avatar Oct 31 '24 13:10 mohe2015

#import "@preview/cetz:0.3.1": canvas, draw, tree
#import "@preview/pinit:0.2.2": *

#let data = (
  [A], ([B], [C], [D]), ([E], [F#pin(1)])
)

#canvas(length: 1cm, {
  import draw: *

  set-style(content: (padding: .2),
    fill: gray.lighten(70%),
    stroke: gray.lighten(70%))

  tree.tree(data, spread: 2.5, grow: 1.5, draw-node: (node, ..) => {
    circle((), radius: .45, stroke: none)
    content((), node.content)
  }, draw-edge: (from, to, ..) => {
    line((a: from, number: .6, b: to),
         (a: to, number: .6, b: from), mark: (end: ">"))
  }, name: "tree")

  // Draw a "custom" connection between two nodes
  let (a, b) = ("tree.0-0-1", "tree.0-1-0",)
  line((a, .6, b), (b, .6, a), mark: (end: ">", start: ">"))
})

#pinit-point-from(1)[It is simple.]

OrangeX4 avatar Oct 31 '24 13:10 OrangeX4

Thank you very much for the quick response and this library. Maybe you want to add this example to the README? After the fact this is pretty obvious but I still didn't get this idea directly.

mohe2015 avatar Oct 31 '24 13:10 mohe2015