#Simple diagram with circles and arrows

5 messages · Page 1 of 1 (latest)

strong hill
#

Hi, I am trying to make a similar diagram as in the picture, with 2 pairs of nested circles, with an arrow between each pair of same-level circles. With native Typst, I was able to make the nested circles, but don't know how to draw the arrows (diagram on top of 2nd picture). With Fletcher package I was able to draw all elements, but nested nodes sit on top of text of parent node (diagram on the bottom of 2nd picture).

I would love to hear any advice to achieve my goal, using one of those methods or another 🙏

Here is the code for the 2 Typst diagrams:

#let lang_colors = (
  gleam: rgb("#f0a8ec"),
  js: rgb(245, 234, 113),
)


#set align(center + horizon)
#set par(justify: false)
#set text(weight: "bold")

#let c1(fill, content) = circle(
  radius: 3cm,
  stroke: white + 3pt,
  fill: fill,
  content,
)
#let c2(fill, content) = circle(
  radius: 1.5cm,
  stroke: white + 3pt,
  fill: fill,
  content,
)

#let circles1 = c1(lang_colors.gleam, [
  #c2(lang_colors.gleam, [Gleam])
  API Cypress en Gleam
])

#let circles2 = c1(lang_colors.js, [
  #c2(lang_colors.js, [JavaScript])
  API Cypress en JavaScript
])

#grid(
  columns: 2,
  circles1, circles2,
)
#import "@preview/fletcher:0.5.8" as fletcher: diagram, edge, node

#diagram(
  node-stroke: 3pt + white,
  node-shape: circle,
  node-fill: luma(200),
  node((0, 0), "Gleam", fill:lang_colors.gleam, name: <n1>),
  node("API Cypress en Gleam", fill:lang_colors.gleam, name: <n2>, enclose: (<n1>,)),
  node((1, 0), "JavaScript", fill:lang_colors.js, name: <n3>),
  node("API Cypress en JavaScript", fill:lang_colors.js, name: <n4>, enclose: (<n3>,)),
  edge(<n1>, <n3>, "->"),
  edge(<n2>, <n4>, "->"),
)
strong hill
#

Making a simple diagram with circles and arrows

#

Simple diagram with circles and arrows

strong hill
#

I manage to overcome the pb with Fletcher by adding break lines by hand so that the node text isn't under the nested circle. Not a great workaround, but it works...

#diagram(
  node-stroke: 3pt + white,
  node-shape: circle,
  node-fill: luma(200),
  node-outset: 1pt,
  edge-stroke: 1.5pt,
  node((0, 0), "Gleam", radius: 1.5cm, fill: lang_colors.gleam, name: <n1>),
  node(
    [
      \ \ \ \ \
      API Cypress \ en Gleam
    ],
    radius: 2.8cm,
    fill: lang_colors.gleam,
    stroke: lang_colors.gleam,
    name: <n2>,
    enclose: (
      <n1>,
      (0, 0.8),
    ),
  ),

  node((2, 0), "JavaScript", radius: 1.5cm, fill: lang_colors.js, name: <n3>),
  node(
    [
      \ \ \ \ \
      API Cypress \ en JavaScript
    ],
    radius: 2.8cm,
    fill: lang_colors.js,
    stroke: lang_colors.js,
    name: <n4>,
    enclose: (
      <n3>,
      (2, 0.8),
    ),
  ),
  edge(<n1>, <n3>, "-|>", bend: 20deg, [compilation Gleam]),
  edge(<n2>, <n4>, "-|>", bend: 10deg, [?]),
)
cursive basin
#

You can also use move do manually adjust node labels, as in:

node(
    move(dy: 4em)[API Cypress \ en JavaScript],
    ...