diff --git a/gallery/example2.typ b/gallery/example2.typ index 1496b46..5eb59dd 100644 --- a/gallery/example2.typ +++ b/gallery/example2.typ @@ -13,8 +13,8 @@ #chronos.diagram({ import chronos: * - _seq("User", "A", comment: "DoWork", enable-dst: true) - _seq("A", "A", comment: "Internal call", enable-dst: true) + _seq("User", "A", comment: "DoWork", enable-dst: true, lifeline-style: (fill: rgb("#FFBBBB"))) + _seq("A", "A", comment: "Internal call", enable-dst: true, lifeline-style: (fill: rgb("#E9967A"))) _seq("A", "B", comment: [#sym.quote.angle.l createRequest #sym.quote.angle.r], enable-dst: true) _seq("B", "A", comment: "RequestCreated", disable-src: true, disable-dst: true, dashed: true) _seq("A", "User", comment: "Done", disable-src: true) @@ -24,8 +24,8 @@ import chronos: * _seq("alice", "bob", comment: "hello", enable-dst: true) _seq("bob", "bob", comment: "self call", enable-dst: true) - _seq("bill", "bob", comment: "hello from thread 2", enable-dst: true) - _seq("bob", "george", comment: "create", enable-dst: true) + _seq("bill", "bob", comment: "hello from thread 2", enable-dst: true, lifeline-style: (fill: rgb("#005500"))) + _seq("bob", "george", comment: "create", create-dst: true) _seq("bob", "bill", comment: "done in thread 2", disable-src: true, dashed: true) _seq("bob", "bob", comment: "rc", disable-src: true, dashed: true) _seq("bob", "george", comment: "delete", destroy-dst: true) diff --git a/src/renderer.typ b/src/renderer.typ index 07e1341..7c6b951 100644 --- a/src/renderer.typ +++ b/src/renderer.typ @@ -1,5 +1,5 @@ #import "@preview/cetz:0.2.2": canvas, draw -#import "utils.typ": get-participants-i +#import "utils.typ": get-participants-i, get-style #import "group.typ" #import "sequence.typ" #import "separator.typ" @@ -209,10 +209,12 @@ // Draw lifeline rectangles (reverse for bottom to top) for rect in rects.rev() { - let (cx, y0, y1) = rect + let (cx, y0, y1, style) = rect + let style = get-style("lifeline", style) draw.rect( (cx - LIFELINE-W / 2, y0), - (cx + LIFELINE-W / 2, y1) + (cx + LIFELINE-W / 2, y1), + ..style ) } diff --git a/src/sequence.typ b/src/sequence.typ index beb2256..aae21ac 100644 --- a/src/sequence.typ +++ b/src/sequence.typ @@ -10,10 +10,12 @@ color: black, flip: false, enable-dst: false, + create-dst: false, disable-dst: false, destroy-dst: false, disable-src: false, destroy-src: false, + lifeline-style: auto ) = { return (( type: "seq", @@ -25,10 +27,12 @@ color: color, flip: flip, enable-dst: enable-dst, + create-dst: create-dst, disable-dst: disable-dst, destroy-dst: destroy-dst, disable-src: disable-src, destroy-src: destroy-src, + lifeline-style: lifeline-style, ),) } @@ -45,7 +49,7 @@ if elmt.disable-src { let src-line = lifelines.at(i1) src-line.level -= 1 - src-line.lines.push(("disable", y, auto)) + src-line.lines.push(("disable", y)) lifelines.at(i1) = src-line } if elmt.destroy-src { @@ -142,7 +146,12 @@ } if elmt.enable-dst { let dst-line = lifelines.at(i2) - dst-line.lines.push(("enable", y, auto)) + dst-line.lines.push(("enable", y, elmt.lifeline-style)) + lifelines.at(i2) = dst-line + } + if elmt.create-dst { + let dst-line = lifelines.at(i2) + dst-line.lines.push(("create", y)) lifelines.at(i2) = dst-line } y -= Y-SPACE diff --git a/src/utils.typ b/src/utils.typ index bbe073f..8e82d0e 100644 --- a/src/utils.typ +++ b/src/utils.typ @@ -24,4 +24,20 @@ } } return (min-i, max-i) +} + +#let get-style(base-name, mods) = { + let style = if base-name == "lifeline" {( + fill: white, + stroke: black + 1pt + )} + + if mods == auto { + return style + } + if type(mods) == dictionary { + return style + mods + } + + panic("Invalid type for parameter mods, expected auto or dictionary, got " + str(type(mods))) } \ No newline at end of file