#import "@preview/fletcher:0.5.8" as fletcher: diagram, node, edge 
#import fletcher.shapes: pill
#import "@preview/touying:0.6.1": *

#let fletcher-diagram = touying-reducer.with(reduce: fletcher.diagram, cover: fletcher.hide)

#fletcher-diagram(
  spacing: (-3mm, 8mm), // wide columns, narrow rows
  node-stroke: 1pt, // outline node shapes
  edge-stroke: 1pt, // make lines thicker
  mark-scale: 60%, // make arrowheads smaller
  node((0,0), [Start], name: <start>),
  pause,
  
  node((-4, 1), [u1], name: <u1>),
  node((4, 1), [u2], name: <u2>),
  node(enclose: (<u1>, <u2>), stroke: aqua, fill: aqua.lighten(90%), name: <iter1>),
  edge(<start>, <u1.north>, "->"),
  edge(<start>, <u2.north>, "->"),
  node((-20mm, 39mm), [n1], shape: pill, name: <n1>),
  edge(<n1.east>, <iter1.west>, "->"),
  pause,

  node((-6, 2), [u11], name: <u11>),
  node((-2, 2), [u12], name: <u12>),
  node((2, 2), [u21], name: <u21>),
  node((6, 2), [u22], name: <u22>),
  node(enclose: (<u11>, <u22>), stroke: teal, fill: teal.lighten(90%), name: <iter2>),
  node((-20mm, 21.9mm), [n2], shape: pill, name: <n2>),
  edge(<n2.east>, <iter2.west>, "->"),
  edge(<u1>, <u11.north>, "->"),
  edge(<u1>, <u12.north>, "->"),
  edge(<u2>, <u21.north>, "->"),
  edge(<u2>, <u22.north>, "->"),
  pause,

  node((-7, 3), [u111], name: <u111>),
  node((-5, 3), [u112], name: <u112>),
  node((-3, 3), [u121], name: <u121>),
  node((-1, 3), [u122], name: <u122>),
  node((1, 3), [u211], name: <u211>),
  node((3, 3), [u212], name: <u212>),
  node((5, 3), [u221], name: <u221>),
  node((7, 3), [u222], name: <u222>),

  node((-20mm, 4.6mm), [n3], shape: pill, name: <n3>),

  
  edge(<n3.east>, <iter3.west>, "->"),

  

  edge(<u11>, <u111.north>, "->"),
  edge(<u11>, <u112.north>, "->"),
  edge(<u12>, <u121.north>, "->"),
  edge(<u12>, <u122.north>, "->"),
  edge(<u21>, <u211.north>, "->"),
  edge(<u21>, <u212.north>, "->"),
  edge(<u22>, <u221.north>, "->"),
  edge(<u22>, <u222.north>, "->"),

  
    node(enclose: (<u111>, <u222>), stroke: eastern, fill: eastern.lighten(90%), name: <iter3>)

)
