forked from HEL/chronos
		
	added groups
This commit is contained in:
		| @@ -1,16 +1,10 @@ | ||||
| #import "@preview/cetz:0.2.2": canvas, draw | ||||
| #import "utils.typ": get-participants-i | ||||
|  | ||||
| #let Y-SPACE = 20 | ||||
| #let Y-SPACE = 10 | ||||
| #let PAR-PAD = (5pt, 3pt) | ||||
| #let PAR-SPACE = 10 | ||||
|  | ||||
| #let get-participants-i(participants) = { | ||||
|   let pars-i = (:) | ||||
|   for (i, p) in participants.enumerate() { | ||||
|     pars-i.insert(p.name, i) | ||||
|   } | ||||
|   return pars-i | ||||
| } | ||||
|  | ||||
| #let get-columns-width(participants, elements) = { | ||||
|   let pars-i = get-participants-i(participants) | ||||
| @@ -62,6 +56,44 @@ | ||||
|   return widths | ||||
| } | ||||
|  | ||||
| #let draw-group(x0, x1, y0, y1, group) = { | ||||
|   let m = measure(box(group.name)) | ||||
|   let w = m.width / 1pt + 15 | ||||
|   let h = m.height / 1pt + 6 | ||||
|   draw.rect( | ||||
|     (x0, y0), | ||||
|     (x1, y1) | ||||
|   ) | ||||
|   draw.merge-path( | ||||
|     fill: gray.lighten(20%), | ||||
|     close: true, | ||||
|     { | ||||
|       draw.line( | ||||
|         (x0, y0), | ||||
|         (x0 + w, y0), | ||||
|         (x0 + w, y0 - h / 2), | ||||
|         (x0 + w - 5, y0 - h), | ||||
|         (x0, y0 - h) | ||||
|       ) | ||||
|     } | ||||
|   ) | ||||
|   draw.content( | ||||
|     (x0, y0), | ||||
|     group.name, | ||||
|     anchor: "north-west", | ||||
|     padding: (left: 5pt, right: 10pt, top: 3pt, bottom: 3pt) | ||||
|   ) | ||||
|  | ||||
|   if group.desc != none { | ||||
|     draw.content( | ||||
|       (x0 + w, y0), | ||||
|       text([\[#group.desc\]], weight: "bold"), | ||||
|       anchor: "north-west", | ||||
|       padding: 3pt | ||||
|     ) | ||||
|   } | ||||
| } | ||||
|  | ||||
| #let render(participants, elements) = context canvas(length: 1pt, { | ||||
|   let pars-i = get-participants-i(participants) | ||||
|  | ||||
| @@ -85,6 +117,8 @@ | ||||
|   } | ||||
|  | ||||
|   let y = -Y-SPACE | ||||
|   let groups = () | ||||
|  | ||||
|   // Draw sequences | ||||
|   for elmt in elements { | ||||
|     if elmt.type == "seq" { | ||||
| @@ -98,12 +132,8 @@ | ||||
|         ) | ||||
|       ) | ||||
|  | ||||
|       draw.line( | ||||
|         (x1, y), | ||||
|         (x2, y), | ||||
|         ..style | ||||
|       ) | ||||
|       if elmt.comment != none { | ||||
|         y -= measure(box(elmt.comment)).height / 1pt + 6 | ||||
|         draw.content( | ||||
|           (calc.min(x1, x2), y), | ||||
|           elmt.comment, | ||||
| @@ -111,6 +141,33 @@ | ||||
|           padding: 3pt | ||||
|         ) | ||||
|       } | ||||
|  | ||||
|       draw.line( | ||||
|         (x1, y), | ||||
|         (x2, y), | ||||
|         ..style | ||||
|       ) | ||||
|       y -= Y-SPACE | ||||
|     } else if elmt.type == "grp" { | ||||
|       let m = measure( | ||||
|         box( | ||||
|           inset: (left: 5pt, right: 5pt, top: 3pt, bottom: 3pt), | ||||
|         ) | ||||
|       ) | ||||
|       groups = groups.map(g => { | ||||
|         if g.at(1).min-i == elmt.min-i { g.at(2) += 1 } | ||||
|         if g.at(1).max-i == elmt.max-i { g.at(3) += 1 } | ||||
|         g | ||||
|       }) | ||||
|       groups.push((y, elmt, 0, 0)) | ||||
|       y -= m.height / 1pt + Y-SPACE | ||||
|      | ||||
|     } else if elmt.type == "grp-end" { | ||||
|       let (start-y, group, start-lvl, end-lvl) = groups.pop() | ||||
|       let x0 = x-pos.at(group.min-i) - start-lvl * 10 - 20 | ||||
|       let x1 = x-pos.at(group.max-i) + end-lvl * 10 + 20 | ||||
|       draw-group(x0, x1, start-y, y, group) | ||||
|  | ||||
|       y -= Y-SPACE | ||||
|     } | ||||
|   } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user