@nowline/renderer 0.8.6 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/dist/image-size.d.ts +9 -0
  2. package/dist/image-size.d.ts.map +1 -0
  3. package/dist/image-size.js +104 -0
  4. package/dist/image-size.js.map +1 -0
  5. package/dist/index.d.ts +4 -1
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +4 -1
  8. package/dist/index.js.map +1 -1
  9. package/dist/logo.d.ts +24 -0
  10. package/dist/logo.d.ts.map +1 -0
  11. package/dist/logo.js +60 -0
  12. package/dist/logo.js.map +1 -0
  13. package/dist/stage.d.ts +78 -0
  14. package/dist/stage.d.ts.map +1 -0
  15. package/dist/stage.js +88 -0
  16. package/dist/stage.js.map +1 -0
  17. package/dist/svg/edges.d.ts +3 -0
  18. package/dist/svg/edges.d.ts.map +1 -0
  19. package/dist/svg/edges.js +144 -0
  20. package/dist/svg/edges.js.map +1 -0
  21. package/dist/svg/footnotes.d.ts +4 -0
  22. package/dist/svg/footnotes.d.ts.map +1 -0
  23. package/dist/svg/footnotes.js +81 -0
  24. package/dist/svg/footnotes.js.map +1 -0
  25. package/dist/svg/header.d.ts +6 -0
  26. package/dist/svg/header.d.ts.map +1 -0
  27. package/dist/svg/header.js +215 -0
  28. package/dist/svg/header.js.map +1 -0
  29. package/dist/svg/include-region.d.ts +4 -0
  30. package/dist/svg/include-region.d.ts.map +1 -0
  31. package/dist/svg/include-region.js +157 -0
  32. package/dist/svg/include-region.js.map +1 -0
  33. package/dist/svg/item.d.ts +36 -0
  34. package/dist/svg/item.d.ts.map +1 -0
  35. package/dist/svg/item.js +549 -0
  36. package/dist/svg/item.js.map +1 -0
  37. package/dist/svg/markers.d.ts +7 -0
  38. package/dist/svg/markers.d.ts.map +1 -0
  39. package/dist/svg/markers.js +151 -0
  40. package/dist/svg/markers.js.map +1 -0
  41. package/dist/svg/nowline.d.ts +4 -0
  42. package/dist/svg/nowline.d.ts.map +1 -0
  43. package/dist/svg/nowline.js +133 -0
  44. package/dist/svg/nowline.js.map +1 -0
  45. package/dist/svg/primitives.d.ts +7 -0
  46. package/dist/svg/primitives.d.ts.map +1 -0
  47. package/dist/svg/primitives.js +70 -0
  48. package/dist/svg/primitives.js.map +1 -0
  49. package/dist/svg/render.d.ts +13 -7
  50. package/dist/svg/render.d.ts.map +1 -1
  51. package/dist/svg/render.js +64 -1701
  52. package/dist/svg/render.js.map +1 -1
  53. package/dist/svg/sanitize.d.ts +10 -0
  54. package/dist/svg/sanitize.d.ts.map +1 -1
  55. package/dist/svg/sanitize.js +264 -16
  56. package/dist/svg/sanitize.js.map +1 -1
  57. package/dist/svg/swimlanes.d.ts +5 -0
  58. package/dist/svg/swimlanes.d.ts.map +1 -0
  59. package/dist/svg/swimlanes.js +228 -0
  60. package/dist/svg/swimlanes.js.map +1 -0
  61. package/dist/svg/timeline.d.ts +24 -0
  62. package/dist/svg/timeline.d.ts.map +1 -0
  63. package/dist/svg/timeline.js +284 -0
  64. package/dist/svg/timeline.js.map +1 -0
  65. package/dist/svg/waves.d.ts +62 -0
  66. package/dist/svg/waves.d.ts.map +1 -0
  67. package/dist/svg/waves.js +397 -0
  68. package/dist/svg/waves.js.map +1 -0
  69. package/package.json +6 -6
  70. package/src/image-size.ts +113 -0
  71. package/src/index.ts +10 -1
  72. package/src/logo.ts +82 -0
  73. package/src/stage.ts +191 -0
  74. package/src/svg/edges.ts +154 -0
  75. package/src/svg/footnotes.ts +115 -0
  76. package/src/svg/header.ts +285 -0
  77. package/src/svg/include-region.ts +201 -0
  78. package/src/svg/item.ts +672 -0
  79. package/src/svg/markers.ts +178 -0
  80. package/src/svg/nowline.ts +152 -0
  81. package/src/svg/primitives.ts +86 -0
  82. package/src/svg/render.ts +94 -2110
  83. package/src/svg/sanitize.ts +286 -16
  84. package/src/svg/swimlanes.ts +317 -0
  85. package/src/svg/timeline.ts +343 -0
  86. package/src/svg/waves.ts +502 -0
package/src/svg/render.ts CHANGED
@@ -1,90 +1,51 @@
1
- import type {
2
- InlineDatePin,
3
- Point,
4
- PositionedAnchor,
5
- PositionedCapacity,
6
- PositionedDependencyEdge,
7
- PositionedFootnoteArea,
8
- PositionedGroup,
9
- PositionedHeader,
10
- PositionedIncludeRegion,
11
- PositionedItem,
12
- PositionedMilestone,
13
- PositionedNowline,
14
- PositionedParallel,
15
- PositionedRoadmap,
16
- PositionedSwimlane,
17
- PositionedTimelineScale,
18
- PositionedTrackChild,
19
- ResolvedStyle,
20
- Theme,
21
- } from '@nowline/layout';
22
- import {
23
- ACCENT_DASH_PATTERN,
24
- ATTRIBUTION_BAR_LOGICAL_WIDTH,
25
- ATTRIBUTION_BAR_LOGICAL_X,
26
- ATTRIBUTION_INE_LOGICAL_X,
27
- ATTRIBUTION_LINK,
28
- ATTRIBUTION_NOW_LOGICAL_X,
29
- ATTRIBUTION_PREFIX_FONT_SIZE,
30
- ATTRIBUTION_SCALE,
31
- ATTRIBUTION_TEXT,
32
- ATTRIBUTION_WORDMARK_FONT_SIZE,
33
- CORNER_RADIUS_PX,
34
- EDGE_CORNER_RADIUS,
35
- estimateCapacitySuffixWidth,
36
- FONT_STACK,
37
- FOOTNOTE_HEADER_BASELINE_OFFSET_PX,
38
- FOOTNOTE_HEADER_HEIGHT_PX,
39
- FOOTNOTE_PANEL_PADDING_PX,
40
- FOOTNOTE_ROW_HEIGHT,
41
- FRAME_TAB_HEIGHT_PX,
42
- FRAME_TAB_LABEL_BASELINE_OFFSET_PX,
43
- frameTabGeometry,
44
- GROUP_BRACKET_LABEL_OVERHANG_PX,
45
- GROUP_TITLE_TAB_CHAR_WIDTH_PX,
46
- GROUP_TITLE_TAB_HEIGHT_PX,
47
- GROUP_TITLE_TAB_LABEL_BASELINE_OFFSET_PX,
48
- GROUP_TITLE_TAB_LABEL_FONT_SIZE_PX,
49
- GROUP_TITLE_TAB_PAD_X_PX,
50
- HEADER_AUTHOR_FONT_SIZE_PX,
51
- HEADER_AUTHOR_LINE_HEIGHT_PX,
52
- HEADER_CARD_PADDING_TOP,
53
- HEADER_CARD_PADDING_X,
54
- HEADER_TITLE_FONT_SIZE_PX,
55
- HEADER_TITLE_LINE_HEIGHT_PX,
56
- HEADER_TITLE_TO_AUTHOR_GAP_PX,
57
- ITEM_CAPTION_INSET_X_PX,
58
- ITEM_CAPTION_META_BASELINE_OFFSET_PX,
59
- ITEM_CAPTION_META_FONT_SIZE_PX,
60
- ITEM_CAPTION_SPILL_GAP_PX,
61
- ITEM_CAPTION_TITLE_BASELINE_OFFSET_PX,
62
- ITEM_CAPTION_TITLE_FONT_SIZE_PX,
63
- ITEM_DECORATION_SPILL_GAP_PX,
64
- ITEM_FOOTNOTE_INDICATOR_BASELINE_OFFSET_PX,
65
- ITEM_FOOTNOTE_INDICATOR_INSET_RIGHT_PX,
66
- ITEM_FOOTNOTE_INDICATOR_STEP_PX,
67
- ITEM_LINK_ICON_INSET_PX,
68
- ITEM_LINK_ICON_TILE_SIZE_PX,
69
- ITEM_STATUS_DOT_INSET_RIGHT_PX,
70
- ITEM_STATUS_DOT_INSET_TOP_PX,
71
- ITEM_STATUS_DOT_RADIUS_PX,
72
- includeChromeGeometry,
73
- NOW_PILL_CORNER_RADIUS_PX,
74
- NOW_PILL_HEIGHT_PX,
75
- NOW_PILL_LABEL_BASELINE_OFFSET_PX,
76
- NOW_PILL_LABEL_FONT_SIZE_PX,
77
- NOW_PILL_LABEL_INSET_X_PX,
78
- NOWLINE_STROKE_WIDTH_PX,
79
- PROGRESS_STRIP_HEIGHT_PX,
80
- TEXT_SIZE_PX,
81
- TIMELINE_TICK_LABEL_BASELINE_OFFSET_PX,
82
- } from '@nowline/layout';
83
- import { BUILTIN_ICON_SVG, CAPACITY_ICON_SVG } from './icons.js';
1
+ // Entry point of the SVG renderer: the option types, `renderSvg` and the
2
+ // `__internal` test hook. `renderSvg` draws the layer modules bottom to top:
3
+ // shadow.ts defs, waves.ts hatch patterns, then the background;
4
+ // timeline.ts header strip; waves.ts strip; swimlanes.ts lane backgrounds;
5
+ // timeline.ts non-working bands; waves.ts tints; timeline.ts grid lines;
6
+ // waves.ts boundaries and labels; edges.ts dependency arrows;
7
+ // swimlanes.ts lanes (their bars come from item.ts); include-region.ts;
8
+ // waves.ts crossings; markers.ts cut lines; timeline.ts non-working labels;
9
+ // markers.ts anchors and milestones; nowline.ts now-line;
10
+ // footnotes.ts panel; waves.ts legend; header.ts card, attribution mark
11
+ // and logo.
12
+ // Shared helpers live in primitives.ts.
13
+
14
+ import type { PositionedRoadmap } from '@nowline/layout';
15
+ import { FONT_STACK } from '@nowline/layout';
16
+ import type { LoadedLogo } from '../logo.js';
17
+ import { renderEdge } from './edges.js';
18
+ import { renderFootnotes } from './footnotes.js';
19
+ import { embedLogo, renderAttributionMark, renderHeader } from './header.js';
84
20
  import { IdGenerator } from './ids.js';
85
- import { sanitizeSvg } from './sanitize.js';
86
- import { allShadowDefs, shadowFilterUrl } from './shadow.js';
87
- import { attrs, escAttr, escText, num, tag, textTag } from './xml.js';
21
+ import { renderIncludeRegion } from './include-region.js';
22
+ import { renderItem } from './item.js';
23
+ import {
24
+ renderAnchor,
25
+ renderAnchorCutLine,
26
+ renderMilestone,
27
+ renderMilestoneCutLine,
28
+ } from './markers.js';
29
+ import { renderNowline } from './nowline.js';
30
+ import { allShadowDefs } from './shadow.js';
31
+ import { renderSwimlane, renderSwimlaneBg } from './swimlanes.js';
32
+ import {
33
+ renderGridLines,
34
+ renderNonWorkingBands,
35
+ renderNonWorkingLabels,
36
+ renderTimeline,
37
+ } from './timeline.js';
38
+ import {
39
+ renderWaveBoundaries,
40
+ renderWaveCrossings,
41
+ renderWaveLabels,
42
+ renderWaveLegend,
43
+ renderWaveStrip,
44
+ renderWaveTints,
45
+ usedWaveHatchKinds,
46
+ waveHatchPatternDef,
47
+ } from './waves.js';
48
+ import { attrs, num, tag } from './xml.js';
88
49
 
89
50
  // Browser-safe types. The renderer never touches `fs`, `path`, or `Buffer`.
90
51
  // Callers inject an AssetResolver when they want logos embedded.
@@ -107,6 +68,12 @@ export type FontFamilies = Record<'sans' | 'serif' | 'mono', string>;
107
68
 
108
69
  export interface RenderOptions {
109
70
  assetResolver?: AssetResolver;
71
+ /**
72
+ * The logo `loadLogo` already read. Its bytes are embedded as they are,
73
+ * so the asset is not resolved a second time. Omitted: `renderSvg`
74
+ * resolves the logo through `assetResolver`.
75
+ */
76
+ logo?: LoadedLogo;
110
77
  noLinks?: boolean;
111
78
  strict?: boolean;
112
79
  warn?: (message: string) => void;
@@ -119,1996 +86,6 @@ export interface RenderOptions {
119
86
  fontFamilies?: FontFamilies;
120
87
  }
121
88
 
122
- // `TEXT_SIZE_PX`, `CORNER_RADIUS_PX`, `FONT_STACK` come from
123
- // `@nowline/layout` (themes/shared) so a typography or radius change
124
- // flows from one place to both layout and renderer.
125
- //
126
- // `WEIGHT_NUM` lives here only because no DSL `weight` table exists in
127
- // shared yet. If/when it does, hoist this alongside `FONT_STACK`.
128
- const WEIGHT_NUM: Record<string, number> = {
129
- thin: 100,
130
- light: 300,
131
- normal: 400,
132
- bold: 700,
133
- };
134
-
135
- // `style.textSize` is `SizeBucket` which includes `'full'`; the shared
136
- // `TEXT_SIZE_PX` table only carries the size buckets (no `'full'` —
137
- // that's a corner-radius-only value). Widen the lookup so a stray
138
- // `'full'` falls through to the `?? 14` fallback instead of compiling.
139
- function textSizePx(bucket: ResolvedStyle['textSize']): number {
140
- return (TEXT_SIZE_PX as Record<string, number>)[bucket] ?? 14;
141
- }
142
-
143
- function fontAttrs(
144
- style: ResolvedStyle,
145
- fonts: FontFamilies,
146
- overrideSize?: number,
147
- ): Record<string, string | number> {
148
- return {
149
- 'font-family': fonts[style.font],
150
- 'font-size': overrideSize ?? textSizePx(style.textSize),
151
- 'font-weight': WEIGHT_NUM[style.weight] ?? 400,
152
- 'font-style': style.italic ? 'italic' : 'normal',
153
- fill: style.text,
154
- };
155
- }
156
-
157
- function strokeDash(style: ResolvedStyle): string | undefined {
158
- if (style.border === 'dashed') return '4 3';
159
- if (style.border === 'dotted') return '1 3';
160
- return undefined;
161
- }
162
-
163
- /**
164
- * sRGB → relative luminance per WCAG 2.x. Input may be `#rrggbb`,
165
- * `#rgb`, or a non-hex token like `none` / `transparent`. Non-hex
166
- * inputs return 1 (treated as light) so a transparent bar reuses
167
- * the chart's light bg. Mostly used to choose between two
168
- * status-dot palettes (`onLight` vs `onDark`) so the dot reads on
169
- * any bar fill — see `pickStatusDotPalette` and
170
- * `specs/rendering.md`'s status-dot section.
171
- */
172
- function relativeLuminance(hex: string): number {
173
- if (!hex || hex === 'none' || hex === 'transparent') return 1;
174
- let h = hex.startsWith('#') ? hex.slice(1) : hex;
175
- if (h.length === 3) {
176
- h = h
177
- .split('')
178
- .map((c) => c + c)
179
- .join('');
180
- }
181
- if (h.length !== 6) return 1;
182
- const r = parseInt(h.slice(0, 2), 16) / 255;
183
- const g = parseInt(h.slice(2, 4), 16) / 255;
184
- const b = parseInt(h.slice(4, 6), 16) / 255;
185
- const lin = (c: number): number => (c <= 0.03928 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4);
186
- return 0.2126 * lin(r) + 0.7152 * lin(g) + 0.0722 * lin(b);
187
- }
188
-
189
- /**
190
- * Pick the status-dot palette whose tone contrasts best with the
191
- * given bar bg.
192
- *
193
- * The crossover threshold is the bar luminance at which a deep dot
194
- * (avg luminance ≈ 0.045 across `onLight` palette entries) and a
195
- * pale dot (avg ≈ 0.85 across `onDark` entries) give equal WCAG
196
- * contrast. Solving `(L_bar + 0.05)² ≈ 0.86 × 0.095` gives
197
- * `L_bar ≈ 0.24`, so:
198
- * - bars with luminance ≥ 0.24 (most label-driven mid-tones AND
199
- * all pale status-tint bars) → `onLight` deep dot
200
- * - bars with luminance < 0.24 (dark status-tint bars in dark
201
- * theme, e.g. `#172554`) → `onDark` pale dot
202
- */
203
- function pickStatusDotPalette(bg: string, palette: Theme): Theme['statusDot']['onLight'] {
204
- return relativeLuminance(bg) >= 0.24 ? palette.statusDot.onLight : palette.statusDot.onDark;
205
- }
206
-
207
- /**
208
- * Approx. rendered width (px) of `text` at `fontSizePx`. Mirrors the
209
- * `0.58 em / char` heuristic the layout uses for spill detection so the
210
- * renderer's positioning of the capacity suffix lines up with what the
211
- * layout reserved.
212
- */
213
- function estimateCaptionWidthPx(text: string, fontSizePx: number): number {
214
- return text.length * fontSizePx * 0.58;
215
- }
216
-
217
- /**
218
- * Paint an item / lane capacity suffix starting at `(x0, baselineY)`. The
219
- * capacity model arrives pre-resolved from layout (`PositionedCapacity`):
220
- * `text` is the formatted number, `icon` is either `null` (no glyph), a
221
- * built-in name, or an inline literal string.
222
- *
223
- * Three rendering paths:
224
- *
225
- * 1. `icon === null` (the resolved `capacity-icon` was `'none'`): paint
226
- * the bare number as a single `<text>` node.
227
- * 2. `icon.kind === 'builtin'` and `name === 'multiplier'`: paint
228
- * `5×` as a single `<text>` node — the multiplication sign is a
229
- * typographic operator with consistent rendering across system
230
- * fonts and built-in side bearing, so no `<tspan dx>` separator.
231
- * 3. `icon.kind === 'builtin'` and `name` ∈ {person, people, points,
232
- * time}: paint the number as `<text>`, then drop the curated SVG
233
- * icon at the next column (`0.1em` gap, sized to one em). The
234
- * icon's `style="color:..."` propagates through the
235
- * `currentColor`-bound paths in the icon library.
236
- * 4. `icon.kind === 'literal'` (inline Unicode literal or
237
- * dereferenced custom `symbol`): paint number + glyph in a single
238
- * `<text>`, with a `<tspan dx="0.1em">` separator before the
239
- * glyph payload.
240
- *
241
- * `precedingText` is the existing meta-line text (or `undefined` when the
242
- * suffix is standalone). When present, the suffix's left edge starts one
243
- * space's width past the meta text's estimated right edge so `2w 5×`
244
- * reads as a single caption rather than running text together.
245
- */
246
- function renderCapacitySuffix(
247
- capacity: PositionedCapacity,
248
- precedingText: string | undefined,
249
- x0: number,
250
- baselineY: number,
251
- fontSize: number,
252
- fontFamily: string,
253
- color: string,
254
- ): string {
255
- const charWidthPx = fontSize * 0.58;
256
- const precedingWidthPx = precedingText ? estimateCaptionWidthPx(precedingText, fontSize) : 0;
257
- const separatorPx = precedingText ? charWidthPx : 0;
258
- const numberX = x0 + precedingWidthPx + separatorPx;
259
- const { text: numberStr, icon } = capacity;
260
- const numberWidthPx = estimateCaptionWidthPx(numberStr, fontSize);
261
- const baseAttrs = {
262
- 'font-family': fontFamily,
263
- 'font-size': fontSize,
264
- fill: color,
265
- } as const;
266
-
267
- if (!icon) {
268
- return textTag({ x: num(numberX), y: num(baselineY), ...baseAttrs }, numberStr);
269
- }
270
-
271
- if (icon.kind === 'builtin' && icon.name === 'multiplier') {
272
- return textTag({ x: num(numberX), y: num(baselineY), ...baseAttrs }, `${numberStr}\u00D7`);
273
- }
274
-
275
- if (icon.kind === 'builtin') {
276
- const def = CAPACITY_ICON_SVG[icon.name];
277
- // Render `<text>5</text>` followed by the curated SVG icon. The
278
- // icon sits at one font-em wide and tall, with a 0.1em separator
279
- // gap. Vertical positioning lifts the icon so its visual center
280
- // sits on the text x-height (`baselineY - fontSize * 0.85`); this
281
- // matches how Lucide-style outline icons read in inline text.
282
- const numberSvg = textTag({ x: num(numberX), y: num(baselineY), ...baseAttrs }, numberStr);
283
- const gapPx = fontSize * 0.1;
284
- const iconSize = fontSize;
285
- const iconX = numberX + numberWidthPx + gapPx;
286
- const iconY = baselineY - fontSize * 0.85;
287
- const iconSvg = `<svg x="${num(iconX)}" y="${num(iconY)}" width="${num(iconSize)}" height="${num(iconSize)}" viewBox="${def.viewBox}" style="color:${escAttr(color)}" aria-hidden="true">${def.body}</svg>`;
288
- return numberSvg + iconSvg;
289
- }
290
-
291
- // Literal glyph (inline Unicode literal or dereferenced custom glyph).
292
- // Single <text> node with the number + a tspan-separated glyph.
293
- const dx = num(fontSize * 0.1);
294
- return (
295
- `<text x="${num(numberX)}" y="${num(baselineY)}" font-family="${escAttr(fontFamily)}"` +
296
- ` font-size="${fontSize}" fill="${escAttr(color)}">` +
297
- `${escText(numberStr)}<tspan dx="${dx}">${escText(icon.text)}</tspan>` +
298
- '</text>'
299
- );
300
- }
301
-
302
- /**
303
- * Em-distance the renderer reserves between an item's metaText and its
304
- * capacity suffix (or any inline trailing token). Half a space's worth
305
- * — wide enough to read as a separator, narrow enough not to look like
306
- * a stray gap. SVG `<tspan dx>` honors this exactly so we don't depend
307
- * on per-character estimation for the gap itself.
308
- */
309
- const META_SUFFIX_DX_EM = 0.6;
310
-
311
- /**
312
- * Tighter em-per-char width estimate used inside `renderItemMetaLine`
313
- * for positioning a built-in SVG icon after a metaText + number. Layout
314
- * still uses 0.58 em/char to pessimistically reserve bar width for
315
- * spill detection (so `metaText 5×` always fits its row); the renderer
316
- * paints the icon at a tighter offset so there's no visible
317
- * dead-space between the rendered number and its glyph. Lands inside
318
- * the layout reservation either way (`0.5 < 0.58`).
319
- */
320
- const META_ICON_EM_PER_CHAR = 0.5;
321
-
322
- /**
323
- * Paint the item meta line (metaText plus optional capacity suffix) as
324
- * a single SVG fragment. Call sites used to emit metaText and the
325
- * suffix as two unrelated `<text>` nodes whose horizontal offsets came
326
- * from `estimateCaptionWidthPx` — fine for short metas like `2w`, but
327
- * the per-character estimate over-reserves for longer captions like
328
- * `L 1w — 1w remaining`, leaving a visible gap before `2×`.
329
- *
330
- * The fix flows the suffix INSIDE the same `<text>` element via
331
- * `<tspan dx>` whenever the suffix is pure inline text (multiplier,
332
- * literal glyph, or no glyph). Browsers compute the dx anchor relative
333
- * to the previously rendered glyph so the gap matches the spec
334
- * regardless of how wide metaText actually rendered.
335
- *
336
- * Built-in SVG icons (person/people/points/time) still need an `<svg>`
337
- * sibling outside `<text>`, so the icon's x is computed via the
338
- * tighter `META_ICON_EM_PER_CHAR` constant — which still lands inside
339
- * the layout's pessimistic spill reservation.
340
- */
341
- function renderItemMetaLine(opts: {
342
- metaText: string | undefined;
343
- capacity: PositionedCapacity | null;
344
- x: number;
345
- baselineY: number;
346
- fontSize: number;
347
- fontFamily: string;
348
- color: string;
349
- }): string {
350
- const { metaText, capacity, x, baselineY, fontSize, fontFamily, color } = opts;
351
- if (!metaText && !capacity) return '';
352
- const baseAttrs = {
353
- 'font-family': fontFamily,
354
- 'font-size': fontSize,
355
- fill: color,
356
- } as const;
357
- if (!capacity) {
358
- return textTag({ x: num(x), y: num(baselineY), ...baseAttrs }, metaText!);
359
- }
360
- if (!metaText) {
361
- return renderCapacitySuffix(capacity, undefined, x, baselineY, fontSize, fontFamily, color);
362
- }
363
- const sepDx = num(fontSize * META_SUFFIX_DX_EM);
364
- const openText =
365
- `<text x="${num(x)}" y="${num(baselineY)}" font-family="${escAttr(fontFamily)}"` +
366
- ` font-size="${fontSize}" fill="${escAttr(color)}">`;
367
- const { text: numberStr, icon } = capacity;
368
- if (!icon) {
369
- return (
370
- openText +
371
- escText(metaText) +
372
- `<tspan dx="${sepDx}">${escText(numberStr)}</tspan>` +
373
- '</text>'
374
- );
375
- }
376
- if (icon.kind === 'builtin' && icon.name === 'multiplier') {
377
- return (
378
- openText +
379
- escText(metaText) +
380
- `<tspan dx="${sepDx}">${escText(numberStr)}\u00D7</tspan>` +
381
- '</text>'
382
- );
383
- }
384
- if (icon.kind === 'literal') {
385
- const glyphDx = num(fontSize * 0.1);
386
- return (
387
- openText +
388
- escText(metaText) +
389
- `<tspan dx="${sepDx}">${escText(numberStr)}</tspan>` +
390
- `<tspan dx="${glyphDx}">${escText(icon.text)}</tspan>` +
391
- '</text>'
392
- );
393
- }
394
- // Built-in SVG icon — text element holds metaText + tspan-separated
395
- // number, then the icon SVG sits at an estimated position. Tighter
396
- // per-character estimate than layout's spill detector so the icon
397
- // visually hugs the number.
398
- const def = CAPACITY_ICON_SVG[icon.name];
399
- const tightWidth = (s: string) => s.length * fontSize * META_ICON_EM_PER_CHAR;
400
- const numberStartX = x + tightWidth(metaText) + fontSize * META_SUFFIX_DX_EM;
401
- const iconGapPx = fontSize * 0.1;
402
- const iconSize = fontSize;
403
- const iconX = numberStartX + tightWidth(numberStr) + iconGapPx;
404
- const iconY = baselineY - fontSize * 0.85;
405
- const textPart =
406
- openText +
407
- escText(metaText) +
408
- `<tspan dx="${sepDx}">${escText(numberStr)}</tspan>` +
409
- '</text>';
410
- const iconPart = `<svg x="${num(iconX)}" y="${num(iconY)}" width="${num(iconSize)}" height="${num(iconSize)}" viewBox="${def.viewBox}" style="color:${escAttr(color)}" aria-hidden="true">${def.body}</svg>`;
411
- return textPart + iconPart;
412
- }
413
-
414
- /**
415
- * Paint one inline-date pin (`after:DATE` / `before:DATE`) as a small
416
- * `calendar` glyph from the curated icon library. Wrapped in a `<g>`
417
- * carrying `<title>YYYY-MM-DD</title>` so browsers surface the date as
418
- * a native hover tooltip; non-interactive exports (PDF / PNG) still
419
- * carry the date in the title text. Z-order: above the bar fill,
420
- * alongside status dot and footnote indicators, below dependency
421
- * arrowheads.
422
- *
423
- * Shared by item, group, and parallel render paths so the visual is
424
- * identical across every entity type.
425
- */
426
- function renderInlineDatePin(pin: InlineDatePin, color: string): string {
427
- const def = BUILTIN_ICON_SVG.calendar;
428
- const inner =
429
- `<svg x="${num(pin.glyphTopLeft.x)}" y="${num(pin.glyphTopLeft.y)}"` +
430
- ` width="${num(pin.glyphSize)}" height="${num(pin.glyphSize)}"` +
431
- ` viewBox="${def.viewBox}" style="color:${escAttr(color)}" aria-hidden="true">${def.body}</svg>`;
432
- const titleEl = `<title>${escText(pin.isoDate)}</title>`;
433
- return tag(
434
- 'g',
435
- {
436
- 'data-layer': 'inline-date-pin',
437
- 'data-side': pin.side,
438
- 'data-date': pin.isoDate,
439
- 'data-spilled': pin.spilled ? 'true' : null,
440
- },
441
- titleEl + inner,
442
- );
443
- }
444
-
445
- function renderInlineDatePins(pins: InlineDatePin[] | undefined, color: string): string {
446
- if (!pins || pins.length === 0) return '';
447
- return pins.map((pin) => renderInlineDatePin(pin, color)).join('');
448
- }
449
-
450
- function rectFrame(
451
- x: number,
452
- y: number,
453
- w: number,
454
- h: number,
455
- style: ResolvedStyle,
456
- extra: Record<string, string | number | undefined | null | boolean> = {},
457
- ): string {
458
- const rx = Math.min(CORNER_RADIUS_PX[style.cornerRadius] ?? 4, h / 2);
459
- return tag('rect', {
460
- x: num(x),
461
- y: num(y),
462
- width: num(w),
463
- height: num(h),
464
- rx: num(rx),
465
- ry: num(rx),
466
- fill: style.bg === 'none' ? 'transparent' : style.bg,
467
- stroke: style.fg,
468
- 'stroke-width': 1,
469
- 'stroke-dasharray': strokeDash(style) ?? null,
470
- ...extra,
471
- });
472
- }
473
-
474
- function renderHeader(
475
- h: PositionedHeader,
476
- idPrefix: string,
477
- palette: Theme,
478
- fonts: FontFamilies,
479
- ): string {
480
- // The layout has already sized the card to its (wrapped) text content
481
- // and stashed the bounds in `h.cardBox`, with `h.titleLines` /
482
- // `h.authorLines` ready to render line-by-line. See sizeBesideHeader
483
- // in @nowline/layout.
484
- const cardX = h.box.x + h.cardBox.x;
485
- const cardY = h.box.y + h.cardBox.y;
486
- const cardWidth = h.cardBox.width;
487
- const cardHeight = h.cardBox.height;
488
- const cardFill = h.style.bg === 'none' ? palette.surface.headerBox : h.style.bg;
489
- const borderColor = palette.header.cardBorder;
490
- const card = tag('rect', {
491
- x: num(cardX),
492
- y: num(cardY),
493
- width: num(cardWidth),
494
- height: num(cardHeight),
495
- rx: 6,
496
- ry: 6,
497
- fill: cardFill,
498
- stroke: borderColor,
499
- 'stroke-width': 1,
500
- filter: `url(#${idPrefix}-shadow-subtle)`,
501
- });
502
- // Title and author baselines come from `@nowline/layout`'s
503
- // `header-card-geometry` module so the renderer paints with the
504
- // exact metrics `sizeBesideHeader` sized the card to.
505
- const titleParts: string[] = [];
506
- h.titleLines.forEach((line, i) => {
507
- titleParts.push(
508
- textTag(
509
- {
510
- x: num(cardX + HEADER_CARD_PADDING_X),
511
- y: num(cardY + HEADER_CARD_PADDING_TOP + i * HEADER_TITLE_LINE_HEIGHT_PX),
512
- 'font-family': fonts[h.style.font],
513
- 'font-size': HEADER_TITLE_FONT_SIZE_PX,
514
- 'font-weight': 600,
515
- fill: h.style.text,
516
- },
517
- line,
518
- ),
519
- );
520
- });
521
- const titleText = titleParts.join('');
522
- const lastTitleY =
523
- cardY +
524
- HEADER_CARD_PADDING_TOP +
525
- Math.max(0, h.titleLines.length - 1) * HEADER_TITLE_LINE_HEIGHT_PX;
526
- const authorColor = palette.header.author;
527
- const authorParts: string[] = [];
528
- h.authorLines.forEach((line, j) => {
529
- authorParts.push(
530
- textTag(
531
- {
532
- x: num(cardX + HEADER_CARD_PADDING_X),
533
- y: num(
534
- lastTitleY +
535
- HEADER_TITLE_TO_AUTHOR_GAP_PX +
536
- j * HEADER_AUTHOR_LINE_HEIGHT_PX,
537
- ),
538
- 'font-family': fonts[h.style.font],
539
- 'font-size': HEADER_AUTHOR_FONT_SIZE_PX,
540
- fill: authorColor,
541
- },
542
- line,
543
- ),
544
- );
545
- });
546
- const authorText = authorParts.join('');
547
- return tag(
548
- 'g',
549
- { 'data-layer': 'header', 'data-id': `${idPrefix}-header` },
550
- card + titleText + authorText,
551
- );
552
- }
553
-
554
- // Renders the chart-body vertical grid lines (major dotted at every
555
- // labeled tick, plus optional faint minor lines at every tick when
556
- // `minorGrid` is set). Emitted as its own layer drawn AFTER the
557
- // swimlane backgrounds so the lines actually span the chart body
558
- // instead of being occluded — without this layer the lines would only
559
- // be visible inside the timeline header strip. Grid lines stay BEHIND
560
- // items, edges, anchor/milestone cuts, and the now-line so item bars
561
- // sit cleanly on top of the ruled-paper backdrop.
562
- function renderGridLines(t: PositionedTimelineScale, swimlaneTopY: number, palette: Theme): string {
563
- const gridColor = palette.timeline.gridLine;
564
- const minorGridColor = palette.timeline.minorGridLine;
565
- // Major lines thread through the FULL timeline strip — they start
566
- // at the top of the top date-label panel (when present) and run
567
- // all the way through the bottom date-label panel (when one is
568
- // mirrored at the chart bottom via `timeline-position:both` or
569
- // `timeline-position:bottom`). This ties date labels at both ends
570
- // to their column boundaries.
571
- //
572
- // Minor lines stay quieter: they start at the TOP OF THE TOPMOST
573
- // SWIMLANE (i.e. below the top date panel AND below the marker
574
- // row, so they don't streak through anchor/milestone diamonds in
575
- // the header) and stop ABOVE the bottom date panel.
576
- //
577
- // Anchor diamonds, milestone markers, and date label text are
578
- // rendered later in the orchestrator so they sit on top of any
579
- // crossing line.
580
- const bottomTickPanelHeight = t.bottomTickPanelHeight ?? 0;
581
- const hasBottomTickPanel = t.bottomTickPanelY !== undefined && bottomTickPanelHeight > 0;
582
- const majorTopY = t.tickPanelY;
583
- const majorBottomY = hasBottomTickPanel
584
- ? t.bottomTickPanelY! + bottomTickPanelHeight
585
- : t.box.y + t.box.height;
586
- // Use the topmost swimlane's top edge directly — `markerRow.height`
587
- // alone misses the small gap (`timelineHeightBudget` slack) between
588
- // the marker row and the swimlane area, which would leave the minor
589
- // lines short and floating in dead space above the swimlane.
590
- const minorTopY = swimlaneTopY;
591
- const minorBottomY = t.box.y + t.box.height;
592
- const parts: string[] = [];
593
- for (const tick of t.ticks) {
594
- if (tick.major) {
595
- // Solid major line at every labeled tick — the dominant
596
- // column boundary, drawn in the stronger gridLine color.
597
- parts.push(
598
- tag('line', {
599
- x1: num(tick.x),
600
- y1: num(majorTopY),
601
- x2: num(tick.x),
602
- y2: num(majorBottomY),
603
- stroke: gridColor,
604
- 'stroke-width': 1,
605
- }),
606
- );
607
- } else if (t.minorGrid) {
608
- // Solid faint minor line at every non-major tick boundary.
609
- // Hierarchy is established by color (lighter than the major)
610
- // rather than by texture. Skip the very last tick since it
611
- // has no following column — a line at the chart's right edge
612
- // just doubles up the chart border.
613
- if (tick.labelX === undefined) continue;
614
- parts.push(
615
- tag('line', {
616
- x1: num(tick.x),
617
- y1: num(minorTopY),
618
- x2: num(tick.x),
619
- y2: num(minorBottomY),
620
- stroke: minorGridColor,
621
- 'stroke-width': 1,
622
- }),
623
- );
624
- }
625
- }
626
- return tag('g', { 'data-layer': 'grid' }, parts.join(''));
627
- }
628
-
629
- function renderTimeline(t: PositionedTimelineScale, palette: Theme, fonts: FontFamilies): string {
630
- const panelFill = palette.timeline.panelFill;
631
- const borderColor = palette.timeline.border;
632
- const labelColor = palette.timeline.labelText;
633
- const parts: string[] = [];
634
- // Header layout from top: now-pill row → tick-label panel → marker row.
635
- // The pill row owns its space (no panel rect); the now-line crosses it
636
- // visually. Marker row is omitted entirely when empty. The top tick
637
- // panel is also omitted when the roadmap requested
638
- // `timeline-position:bottom` (height 0). The optional bottom tick
639
- // panel mirrors the top panel directly above the footnote area.
640
- const tickPanelY = t.tickPanelY;
641
- const tickPanelHeight = t.tickPanelHeight;
642
- const hasTopTickPanel = tickPanelHeight > 0;
643
- const hasMarkerRow = t.markerRow.height > 0;
644
- const markerRowY = tickPanelY + tickPanelHeight;
645
- const markerRowHeight = t.markerRow.height;
646
- const bottomTickPanelY = t.bottomTickPanelY;
647
- const bottomTickPanelHeight = t.bottomTickPanelHeight ?? 0;
648
- const hasBottomTickPanel = bottomTickPanelY !== undefined && bottomTickPanelHeight > 0;
649
-
650
- if (hasTopTickPanel) {
651
- parts.push(
652
- tag('rect', {
653
- x: num(t.box.x),
654
- y: num(tickPanelY),
655
- width: num(t.box.width),
656
- height: num(tickPanelHeight),
657
- rx: 4,
658
- ry: 4,
659
- fill: panelFill,
660
- stroke: borderColor,
661
- 'stroke-width': 1,
662
- }),
663
- );
664
- }
665
- if (hasMarkerRow) {
666
- parts.push(
667
- tag('rect', {
668
- x: num(t.box.x),
669
- y: num(markerRowY),
670
- width: num(t.box.width),
671
- height: num(markerRowHeight),
672
- rx: 4,
673
- ry: 4,
674
- fill: panelFill,
675
- stroke: borderColor,
676
- 'stroke-width': 1,
677
- }),
678
- );
679
- }
680
- if (hasBottomTickPanel) {
681
- parts.push(
682
- tag('rect', {
683
- x: num(t.box.x),
684
- y: num(bottomTickPanelY!),
685
- width: num(t.box.width),
686
- height: num(bottomTickPanelHeight),
687
- rx: 4,
688
- ry: 4,
689
- fill: panelFill,
690
- stroke: borderColor,
691
- 'stroke-width': 1,
692
- }),
693
- );
694
- }
695
- // Header-only labels — the chart-body grid lines themselves are
696
- // emitted by `renderGridLines` after the swimlane backgrounds so
697
- // they actually span the chart body rather than being occluded.
698
- for (const tick of t.ticks) {
699
- if (!tick.major) continue;
700
- if (!tick.label || tick.labelX === undefined) continue;
701
- // Label sits at the COLUMN CENTER (tick.labelX), not at the
702
- // tick boundary. The last tick has no following column → no
703
- // label.
704
- if (hasTopTickPanel) {
705
- parts.push(
706
- textTag(
707
- {
708
- x: num(tick.labelX),
709
- y: num(tickPanelY + TIMELINE_TICK_LABEL_BASELINE_OFFSET_PX),
710
- 'font-family': fonts.sans,
711
- 'font-size': 10,
712
- fill: labelColor,
713
- 'text-anchor': 'middle',
714
- },
715
- tick.label,
716
- ),
717
- );
718
- }
719
- if (hasBottomTickPanel) {
720
- parts.push(
721
- textTag(
722
- {
723
- x: num(tick.labelX),
724
- y: num(bottomTickPanelY! + TIMELINE_TICK_LABEL_BASELINE_OFFSET_PX),
725
- 'font-family': fonts.sans,
726
- 'font-size': 10,
727
- fill: labelColor,
728
- 'text-anchor': 'middle',
729
- },
730
- tick.label,
731
- ),
732
- );
733
- }
734
- }
735
- return tag('g', { 'data-layer': 'timeline' }, parts.join(''));
736
- }
737
-
738
- function renderNowline(n: PositionedNowline | null, palette: Theme, fonts: FontFamilies): string {
739
- if (!n) return '';
740
- const color = palette.nowline.stroke;
741
- const labelTextColor = palette.nowline.labelText;
742
- // Line drops from `topY` (just below the pill / top of date headers)
743
- // through the headers into the chart, ending at `bottomY`.
744
- const line = tag('line', {
745
- x1: num(n.x),
746
- y1: num(n.topY),
747
- x2: num(n.x),
748
- y2: num(n.bottomY),
749
- stroke: color,
750
- 'stroke-width': NOWLINE_STROKE_WIDTH_PX,
751
- });
752
- // Pill — sits above the date headers at `pillTopY`. Three modes
753
- // (decided by layout in `buildNowline`):
754
- // - center → rounded rect centered on the line, label `middle`
755
- // - flag-right → squared LEFT, rounded RIGHT, line at left edge,
756
- // label `start` past the line
757
- // - flag-left → rounded LEFT, squared RIGHT, line at right edge,
758
- // label `end` before the line
759
- // The squared edge IS the line; the rounded edge points into the
760
- // chart, so the pill always hugs the line and never overflows.
761
- const pillBg = renderNowPillBg(n, color);
762
- const label = renderNowPillLabel(n, labelTextColor, fonts);
763
- return tag('g', { 'data-layer': 'nowline' }, line + pillBg + label);
764
- }
765
-
766
- /**
767
- * X coordinate of the pill's squared edge in flag modes. SVG strokes
768
- * are centered on their geometry, so a 2.25 px line at `n.x` actually
769
- * paints from `n.x - 1.125` to `n.x + 1.125`. To make the pill's
770
- * squared edge line up with the OUTER edge of the line stroke (so
771
- * the line and the pill share a single continuous edge instead of
772
- * the line peeking past the pill by half-stroke), we offset by
773
- * `NOWLINE_STROKE_WIDTH_PX / 2` on the side the line is on.
774
- *
775
- * flag-right: line on the LEFT → squared edge at n.x - half-stroke
776
- * flag-left: line on the RIGHT → squared edge at n.x + half-stroke
777
- *
778
- * Center mode doesn't apply — the line passes through the pill's
779
- * vertical center, so a half-stroke offset would make things worse.
780
- */
781
- function squaredEdgeX(n: PositionedNowline): number {
782
- const halfStroke = NOWLINE_STROKE_WIDTH_PX / 2;
783
- if (n.pillMode === 'flag-right') return n.x - halfStroke;
784
- if (n.pillMode === 'flag-left') return n.x + halfStroke;
785
- return n.x;
786
- }
787
-
788
- function renderNowPillBg(n: PositionedNowline, color: string): string {
789
- const top = n.pillTopY;
790
- const bottom = n.pillTopY + NOW_PILL_HEIGHT_PX;
791
- const r = NOW_PILL_CORNER_RADIUS_PX;
792
- // Pill width comes from the layout (`n.pillWidth`) — locale-aware,
793
- // floored at `NOW_PILL_WIDTH_PX` so en-US output stays byte-stable
794
- // and longer locale strings (e.g. fr `'maint.'`) grow the pill
795
- // instead of clipping. See `buildNowline` in `@nowline/layout`.
796
- const width = n.pillWidth;
797
- if (n.pillMode === 'center') {
798
- return tag('rect', {
799
- x: num(n.x - width / 2),
800
- y: num(top),
801
- width: num(width),
802
- height: num(NOW_PILL_HEIGHT_PX),
803
- rx: r,
804
- ry: r,
805
- fill: color,
806
- });
807
- }
808
- const edgeX = squaredEdgeX(n);
809
- if (n.pillMode === 'flag-right') {
810
- // Squared LEFT edge aligns with line's left outer stroke edge,
811
- // rounded corners on the RIGHT.
812
- const right = edgeX + width;
813
- const d = [
814
- `M ${num(edgeX)} ${num(top)}`,
815
- `L ${num(right - r)} ${num(top)}`,
816
- `A ${r} ${r} 0 0 1 ${num(right)} ${num(top + r)}`,
817
- `L ${num(right)} ${num(bottom - r)}`,
818
- `A ${r} ${r} 0 0 1 ${num(right - r)} ${num(bottom)}`,
819
- `L ${num(edgeX)} ${num(bottom)}`,
820
- 'Z',
821
- ].join(' ');
822
- return tag('path', { d, fill: color });
823
- }
824
- // flag-left: squared RIGHT edge aligns with line's right outer
825
- // stroke edge, rounded corners on the LEFT.
826
- const left = edgeX - width;
827
- const d = [
828
- `M ${num(edgeX)} ${num(top)}`,
829
- `L ${num(left + r)} ${num(top)}`,
830
- `A ${r} ${r} 0 0 0 ${num(left)} ${num(top + r)}`,
831
- `L ${num(left)} ${num(bottom - r)}`,
832
- `A ${r} ${r} 0 0 0 ${num(left + r)} ${num(bottom)}`,
833
- `L ${num(edgeX)} ${num(bottom)}`,
834
- 'Z',
835
- ].join(' ');
836
- return tag('path', { d, fill: color });
837
- }
838
-
839
- function renderNowPillLabel(
840
- n: PositionedNowline,
841
- labelTextColor: string,
842
- fonts: FontFamilies,
843
- ): string {
844
- const baselineY = n.pillTopY + NOW_PILL_LABEL_BASELINE_OFFSET_PX;
845
- const edgeX = squaredEdgeX(n);
846
- let labelX: number;
847
- let textAnchor: 'start' | 'middle' | 'end';
848
- if (n.pillMode === 'center') {
849
- labelX = n.x;
850
- textAnchor = 'middle';
851
- } else if (n.pillMode === 'flag-right') {
852
- labelX = edgeX + NOW_PILL_LABEL_INSET_X_PX;
853
- textAnchor = 'start';
854
- } else {
855
- labelX = edgeX - NOW_PILL_LABEL_INSET_X_PX;
856
- textAnchor = 'end';
857
- }
858
- return textTag(
859
- {
860
- x: num(labelX),
861
- y: num(baselineY),
862
- 'font-family': fonts.sans,
863
- 'font-size': NOW_PILL_LABEL_FONT_SIZE_PX,
864
- 'font-weight': 700,
865
- fill: labelTextColor,
866
- 'text-anchor': textAnchor,
867
- },
868
- n.label,
869
- );
870
- }
871
-
872
- function renderItem(
873
- i: PositionedItem,
874
- options: RenderOptions,
875
- idPrefix: string,
876
- palette: Theme,
877
- fonts: FontFamilies,
878
- ): string {
879
- const parts: string[] = [];
880
- const shadow = shadowFilterUrl(idPrefix, i.style.shadow);
881
- parts.push(
882
- rectFrame(i.box.x, i.box.y, i.box.width, i.box.height, i.style, {
883
- filter: shadow ?? null,
884
- }),
885
- );
886
- // Status-dot color — the dot communicates status via hue, but
887
- // the bar bg can range from pale status tints (`#eff6ff`) to
888
- // saturated mid-tones (`#1e88e5` from `bg:blue` labels) to
889
- // dark navies (`#172554` in dark theme), so a single palette
890
- // can't keep contrast across all bars. Two palettes — `onLight`
891
- // (deep tints, for pale bars) and `onDark` (pale tints, for
892
- // saturated/dark bars) — are picked from based on the bar
893
- // bg's relative luminance.
894
- const dotPalette = pickStatusDotPalette(i.style.bg, palette);
895
- const statusColors: Record<string, string> = {
896
- done: dotPalette.done,
897
- 'in-progress': dotPalette.inProgress,
898
- 'at-risk': dotPalette.atRisk,
899
- blocked: dotPalette.blocked,
900
- planned: dotPalette.planned,
901
- neutral: dotPalette.neutral,
902
- };
903
- const dotColor = statusColors[i.status] ?? statusColors.neutral;
904
- // Bottom progress strip along the bottom edge. Height comes from
905
- // `PROGRESS_STRIP_HEIGHT_PX` so layout's chip placement and the
906
- // milestone slack-arrow attach Y stay in sync if it's ever bumped.
907
- if (i.progressFraction > 0) {
908
- const pw = Math.max(0, Math.min(i.box.width, i.box.width * i.progressFraction));
909
- parts.push(
910
- tag('rect', {
911
- x: num(i.box.x),
912
- y: num(i.box.y + i.box.height - PROGRESS_STRIP_HEIGHT_PX),
913
- width: num(pw),
914
- height: PROGRESS_STRIP_HEIGHT_PX,
915
- fill: i.style.fg,
916
- opacity: 0.55,
917
- }),
918
- );
919
- }
920
- // Status dot — upper-right inset inside the bar, OR pushed into
921
- // the spill column when the bar is too narrow to host the dot's
922
- // full inset (`dotSpills`). Layout pre-computes `dotSpillCx` for
923
- // the spilled case so the renderer stays geometry-dumb.
924
- const dotCx =
925
- i.dotSpills && i.dotSpillCx !== null
926
- ? i.dotSpillCx
927
- : i.box.x + i.box.width - ITEM_STATUS_DOT_INSET_RIGHT_PX;
928
- parts.push(
929
- tag('circle', {
930
- cx: num(dotCx),
931
- cy: num(i.box.y + ITEM_STATUS_DOT_INSET_TOP_PX),
932
- r: ITEM_STATUS_DOT_RADIUS_PX,
933
- fill: dotColor,
934
- }),
935
- );
936
- // Inline-date pins (after:DATE / before:DATE). Same z-order family as
937
- // the status dot and footnote indicators — small badge in the top
938
- // decoration row. Color matches the bar's resolved meta (`fg`) so the
939
- // glyph reads against the bar fill the same way the meta text does.
940
- parts.push(renderInlineDatePins(i.inlineDatePins, i.style.fg));
941
- // Title + meta are an atomic caption. When `textSpills` is set the
942
- // layout has already bumped the next item to a fresh row, so we draw
943
- // both lines BESIDE the bar (just past its right edge, stacked) at
944
- // the same vertical positions they would occupy inside. When they
945
- // fit, both go inside at the bar's left padding.
946
- //
947
- // The spilled-decoration cluster reads `[bar] [icon?] [title]
948
- // [footnote?] [dot?]` — the only decoration to the LEFT of the
949
- // title is the link icon (the icon→title affordance must stay
950
- // adjacent). The dot trails the title to mirror its in-bar
951
- // upper-right position; the footnote walks alongside the title
952
- // (between title and dot) just like its in-bar `text-anchor: end`
953
- // placement at the upper-right.
954
- let captionX: number;
955
- if (i.textSpills) {
956
- captionX = i.box.x + i.box.width + ITEM_CAPTION_SPILL_GAP_PX;
957
- if (i.iconSpills) {
958
- captionX += ITEM_LINK_ICON_TILE_SIZE_PX + ITEM_DECORATION_SPILL_GAP_PX;
959
- }
960
- } else {
961
- captionX = i.box.x + ITEM_CAPTION_INSET_X_PX;
962
- }
963
- // When the caption spills outside the bar it renders on the
964
- // chart / group bg instead of the bar fill — `i.style.text` is
965
- // resolved against the bar (e.g. `enterprise-style` propagates
966
- // `text:white` from a label and audit-log's title becomes
967
- // white-on-blue inside, but white-on-peach when spilled onto
968
- // the orange-tinted audit-track group). Use the theme's
969
- // default item text color (always tuned for chart bg) when
970
- // text spills, and the per-bar color when it stays inside.
971
- const captionInsideTextColor = i.style.text;
972
- const captionOutsideTextColor = palette.entities.item.text;
973
- const titleColor = i.textSpills ? captionOutsideTextColor : captionInsideTextColor;
974
- const metaColor = i.textSpills ? captionOutsideTextColor : i.style.fg;
975
- if (i.title) {
976
- parts.push(
977
- textTag(
978
- {
979
- x: num(captionX),
980
- y: num(i.box.y + ITEM_CAPTION_TITLE_BASELINE_OFFSET_PX),
981
- 'font-family': fonts[i.style.font],
982
- 'font-size': ITEM_CAPTION_TITLE_FONT_SIZE_PX,
983
- 'font-weight': 600,
984
- fill: titleColor,
985
- },
986
- i.title,
987
- ),
988
- );
989
- }
990
- // Meta line and capacity suffix render as a unified SVG fragment.
991
- // For pure-text suffixes (multiplier, literal glyph, no glyph) the
992
- // unified path emits a single `<text>` element with `<tspan dx>`
993
- // for the gap so the suffix hugs the metaText regardless of how
994
- // wide it actually rendered. Built-in SVG icon glyphs still emit a
995
- // sibling `<svg>` but at a tighter offset than the legacy two-text
996
- // path. See `renderItemMetaLine` for the full case-by-case.
997
- if (i.metaText || i.capacity) {
998
- parts.push(
999
- renderItemMetaLine({
1000
- metaText: i.metaText,
1001
- capacity: i.capacity,
1002
- x: captionX,
1003
- baselineY: i.box.y + ITEM_CAPTION_META_BASELINE_OFFSET_PX,
1004
- fontSize: ITEM_CAPTION_META_FONT_SIZE_PX,
1005
- fontFamily: fonts[i.style.font],
1006
- color: metaColor,
1007
- }),
1008
- );
1009
- }
1010
- // Footnote superscript indicators. Two render modes:
1011
- // - In-bar (default): glyphs walk LEFT from
1012
- // `bar.right - ITEM_FOOTNOTE_INDICATOR_INSET_RIGHT_PX`,
1013
- // anchored end. They sit on the bar fill, so use the bar's
1014
- // resolved text color for contrast (a hardcoded red was
1015
- // getting lost on saturated mid-tone bars from `bg:blue`
1016
- // labels). The "footnote = red" attention cue lives on the
1017
- // footnote PANEL's red number column at the bottom of the
1018
- // chart where red reads cleanly against white.
1019
- // - Spilled (narrow bars): the glyphs render in the spill
1020
- // column to the right of the bar, walking RIGHT from
1021
- // `footnoteSpillStartX` so they read in the same numerical
1022
- // order as the in-bar case. They sit on the chart bg, so
1023
- // use the chart-tuned default text color (same as spilled
1024
- // captions).
1025
- if (i.footnoteIndicators.length > 0) {
1026
- const footnoteY = i.box.y + ITEM_FOOTNOTE_INDICATOR_BASELINE_OFFSET_PX;
1027
- if (i.footnoteSpills && i.footnoteSpillStartX !== null) {
1028
- let fx = i.footnoteSpillStartX;
1029
- for (let k = 0; k < i.footnoteIndicators.length; k++) {
1030
- const n2 = i.footnoteIndicators[k];
1031
- parts.push(
1032
- textTag(
1033
- {
1034
- x: num(fx),
1035
- y: num(footnoteY),
1036
- 'font-family': fonts.sans,
1037
- 'font-size': 10,
1038
- 'font-weight': 700,
1039
- fill: captionOutsideTextColor,
1040
- },
1041
- String(n2),
1042
- ),
1043
- );
1044
- fx += ITEM_FOOTNOTE_INDICATOR_STEP_PX;
1045
- }
1046
- } else {
1047
- let fx = i.box.x + i.box.width - ITEM_FOOTNOTE_INDICATOR_INSET_RIGHT_PX;
1048
- for (let k = i.footnoteIndicators.length - 1; k >= 0; k--) {
1049
- const n2 = i.footnoteIndicators[k];
1050
- parts.push(
1051
- textTag(
1052
- {
1053
- x: num(fx),
1054
- y: num(footnoteY),
1055
- 'font-family': fonts.sans,
1056
- 'font-size': 10,
1057
- 'font-weight': 700,
1058
- fill: i.style.text,
1059
- 'text-anchor': 'end',
1060
- },
1061
- String(n2),
1062
- ),
1063
- );
1064
- fx -= ITEM_FOOTNOTE_INDICATOR_STEP_PX;
1065
- }
1066
- }
1067
- }
1068
- // Link icon — colored tile + white external-link glyph. Default
1069
- // position is the bar's UPPER-LEFT corner; on a bar too narrow
1070
- // to host both the icon and the status-dot column with a gap
1071
- // between them, the icon spills out to the right of the bar
1072
- // (in front of the spilled title) so the icon→title affordance
1073
- // stays intact. The glyph is the same outbound-arrow ↗ for
1074
- // every link kind (linear / github / jira / generic) — they
1075
- // only differ in tile color. The include FILE-LEVEL region
1076
- // (`include "./other.nowline"`) uses a separate stacked-sheets
1077
- // glyph rendered by `renderIncludeRegion`, distinct from this
1078
- // item-level link icon.
1079
- if (!options.noLinks && i.linkIcon && i.linkIcon !== 'none') {
1080
- const tileColor: Record<string, string> = {
1081
- linear: '#5e6ad2',
1082
- github: '#0f172a',
1083
- jira: '#0052cc',
1084
- generic: palette.item.linkIconFg,
1085
- };
1086
- const tile = tileColor[i.linkIcon] ?? tileColor.generic;
1087
- const tileSize = ITEM_LINK_ICON_TILE_SIZE_PX;
1088
- const tileX =
1089
- i.iconSpills && i.iconSpillX !== null
1090
- ? i.iconSpillX
1091
- : i.box.x + ITEM_LINK_ICON_INSET_PX;
1092
- const tileY = i.box.y + ITEM_LINK_ICON_INSET_PX;
1093
- const tileRect = tag('rect', {
1094
- x: num(tileX),
1095
- y: num(tileY),
1096
- width: tileSize,
1097
- height: tileSize,
1098
- rx: 2,
1099
- ry: 2,
1100
- fill: tile,
1101
- });
1102
- const gx = tileX;
1103
- const gy = tileY;
1104
- const glyph = tag('path', {
1105
- d: `M${num(gx + 4)} ${num(gy + 10)} L${num(gx + 10)} ${num(gy + 4)} M${num(gx + 6)} ${num(gy + 4)} H${num(gx + 10)} V${num(gy + 8)}`,
1106
- stroke: '#ffffff',
1107
- fill: 'none',
1108
- 'stroke-width': 1.1,
1109
- 'stroke-linecap': 'round',
1110
- 'stroke-linejoin': 'round',
1111
- });
1112
- const inner = tileRect + glyph;
1113
- const link = i.linkHref
1114
- ? tag('a', { href: i.linkHref, target: '_blank', rel: 'noopener' }, inner)
1115
- : inner;
1116
- parts.push(link);
1117
- }
1118
- // Overflow tail — red fill + stroke + caption.
1119
- if (i.hasOverflow && i.overflowBox) {
1120
- const tailFill = palette.item.overflowTailFill;
1121
- const tailStroke = palette.item.overflowTailStroke;
1122
- const captionColor = palette.item.overflowCaption;
1123
- parts.push(
1124
- tag('rect', {
1125
- x: num(i.overflowBox.x),
1126
- y: num(i.overflowBox.y),
1127
- width: num(i.overflowBox.width),
1128
- height: num(i.overflowBox.height),
1129
- fill: tailFill,
1130
- stroke: tailStroke,
1131
- 'stroke-width': 1,
1132
- }),
1133
- );
1134
- if (i.overflowAnchorId && i.overflowBox.width > 60) {
1135
- parts.push(
1136
- textTag(
1137
- {
1138
- x: num(i.overflowBox.x + i.overflowBox.width / 2),
1139
- y: num(i.overflowBox.y + i.overflowBox.height / 2 + 3),
1140
- 'font-family': fonts.sans,
1141
- 'font-size': 9,
1142
- 'font-weight': 700,
1143
- fill: captionColor,
1144
- 'text-anchor': 'middle',
1145
- },
1146
- `past ${i.overflowAnchorId}`,
1147
- ),
1148
- );
1149
- }
1150
- }
1151
- // Label chips
1152
- for (const chip of i.labelChips) {
1153
- const rx = Math.min(CORNER_RADIUS_PX[chip.style.cornerRadius] ?? 8, chip.box.height / 2);
1154
- parts.push(
1155
- tag('rect', {
1156
- x: num(chip.box.x),
1157
- y: num(chip.box.y),
1158
- width: num(chip.box.width),
1159
- height: num(chip.box.height),
1160
- rx: num(rx),
1161
- ry: num(rx),
1162
- fill: chip.style.bg === 'none' ? 'transparent' : chip.style.bg,
1163
- stroke: chip.style.fg,
1164
- 'stroke-width': 0.5,
1165
- }),
1166
- );
1167
- parts.push(
1168
- textTag(
1169
- {
1170
- x: num(chip.box.x + chip.box.width / 2),
1171
- y: num(chip.box.y + chip.box.height / 2 + 3),
1172
- ...fontAttrs(chip.style, fonts, TEXT_SIZE_PX.xs),
1173
- 'text-anchor': 'middle',
1174
- },
1175
- chip.text,
1176
- ),
1177
- );
1178
- }
1179
- return tag('g', { 'data-layer': 'item', 'data-id': i.id ?? null }, parts.join(''));
1180
- }
1181
-
1182
- function renderGroup(
1183
- g: PositionedGroup,
1184
- options: RenderOptions,
1185
- idPrefix: string,
1186
- palette: Theme,
1187
- fonts: FontFamilies,
1188
- ): string {
1189
- const parts: string[] = [];
1190
- const hasFill = g.style.bg !== 'none' && g.style.bg !== '#ffffff';
1191
- if (hasFill) {
1192
- // Filled-box style with a chiclet label flush in the upper-left
1193
- // corner. The painted box matches the layout-reported `box` 1:1
1194
- // (no overhang), so parents stack against the right rectangle.
1195
- parts.push(
1196
- tag('rect', {
1197
- x: num(g.box.x),
1198
- y: num(g.box.y),
1199
- width: num(g.box.width),
1200
- height: num(g.box.height),
1201
- rx: 6,
1202
- ry: 6,
1203
- fill: g.style.bg,
1204
- stroke: g.style.fg,
1205
- 'stroke-width': 1,
1206
- 'fill-opacity': 0.18,
1207
- filter: `url(#${idPrefix}-shadow-subtle)`,
1208
- }),
1209
- );
1210
- if (g.title) {
1211
- const tabW =
1212
- g.title.length * GROUP_TITLE_TAB_CHAR_WIDTH_PX + 2 * GROUP_TITLE_TAB_PAD_X_PX;
1213
- const tabX = g.box.x;
1214
- const tabY = g.box.y;
1215
- const tabH = GROUP_TITLE_TAB_HEIGHT_PX;
1216
- // Asymmetric corner shape: TOP-LEFT and BOTTOM-RIGHT are
1217
- // rounded (radius 6, matching the parent group box), while
1218
- // TOP-RIGHT and BOTTOM-LEFT are square. The TL roundness
1219
- // continues the group box's outer corner; the squared
1220
- // BL / TR sides "anchor" the tab into the box's left and
1221
- // top edges so it reads as a corner-mounted label rather
1222
- // than a floating pill.
1223
- const r = 6;
1224
- const tabPath =
1225
- `M${num(tabX + r)} ${num(tabY)}` +
1226
- `H${num(tabX + tabW)}` +
1227
- `V${num(tabY + tabH - r)}` +
1228
- `A${r} ${r} 0 0 1 ${num(tabX + tabW - r)} ${num(tabY + tabH)}` +
1229
- `H${num(tabX)}` +
1230
- `V${num(tabY + r)}` +
1231
- `A${r} ${r} 0 0 1 ${num(tabX + r)} ${num(tabY)}` +
1232
- `Z`;
1233
- parts.push(
1234
- tag('path', {
1235
- d: tabPath,
1236
- fill: g.style.fg,
1237
- }),
1238
- );
1239
- parts.push(
1240
- textTag(
1241
- {
1242
- x: num(tabX + GROUP_TITLE_TAB_PAD_X_PX),
1243
- y: num(tabY + GROUP_TITLE_TAB_LABEL_BASELINE_OFFSET_PX),
1244
- 'font-family': fonts[g.style.font],
1245
- 'font-size': GROUP_TITLE_TAB_LABEL_FONT_SIZE_PX,
1246
- 'font-weight': 600,
1247
- fill: '#ffffff',
1248
- },
1249
- g.title,
1250
- ),
1251
- );
1252
- }
1253
- } else {
1254
- const bracketColor = g.style.fg;
1255
- if (g.style.bracket !== 'none') {
1256
- // Bracket-style groups paint a left-side `[` glyph along
1257
- // `box.x`. When a title is present the layout has reserved
1258
- // `GROUP_BRACKET_LABEL_OVERHANG_PX` of vertical space ABOVE
1259
- // `box.y` (see GroupNode.place); the bracket extends up
1260
- // through that overhang and adds a top foot mirroring the
1261
- // bottom foot so the `[` visually wraps the title text that
1262
- // sits in the reserved region. Title-less bracket groups
1263
- // keep the historical asymmetric shape (vertical bar + a
1264
- // single bottom foot) since there's nothing above to wrap.
1265
- const stub = 4;
1266
- const bottom = g.box.y + g.box.height;
1267
- const dash = g.style.bracket === 'dashed' ? '3 2' : null;
1268
- const bracketPath = g.title
1269
- ? `M${num(g.box.x + stub)} ${num(g.box.y - GROUP_BRACKET_LABEL_OVERHANG_PX)}` +
1270
- ` L${num(g.box.x)} ${num(g.box.y - GROUP_BRACKET_LABEL_OVERHANG_PX)}` +
1271
- ` L${num(g.box.x)} ${num(bottom)}` +
1272
- ` L${num(g.box.x + stub)} ${num(bottom)}`
1273
- : `M${num(g.box.x)} ${num(g.box.y)}` +
1274
- ` L${num(g.box.x)} ${num(bottom)}` +
1275
- ` L${num(g.box.x + stub)} ${num(bottom)}`;
1276
- parts.push(
1277
- tag('path', {
1278
- d: bracketPath,
1279
- fill: 'none',
1280
- stroke: bracketColor,
1281
- 'stroke-width': 1,
1282
- 'stroke-dasharray': dash,
1283
- }),
1284
- );
1285
- }
1286
- if (g.title) {
1287
- parts.push(
1288
- textTag(
1289
- {
1290
- x: num(g.box.x + 6),
1291
- y: num(g.box.y - 2),
1292
- ...fontAttrs(g.style, fonts, TEXT_SIZE_PX.xs),
1293
- 'fill-opacity': 0.7,
1294
- },
1295
- g.title,
1296
- ),
1297
- );
1298
- }
1299
- }
1300
- // Inline-date pins on the group itself (`group ... after:DATE` /
1301
- // `before:DATE`). Painted before the children so children's bars stay
1302
- // visually on top — the glyphs only sit in the empty corners of the
1303
- // bounding box.
1304
- parts.push(renderInlineDatePins(g.inlineDatePins, g.style.fg));
1305
- for (const c of g.children) {
1306
- parts.push(renderTrackChild(c, options, idPrefix, palette, fonts));
1307
- }
1308
- void palette;
1309
- return tag('g', { 'data-layer': 'group', 'data-id': g.id ?? null }, parts.join(''));
1310
- }
1311
-
1312
- function renderParallel(
1313
- p: PositionedParallel,
1314
- options: RenderOptions,
1315
- idPrefix: string,
1316
- palette: Theme,
1317
- fonts: FontFamilies,
1318
- ): string {
1319
- const parts: string[] = [];
1320
- // `bracket: solid|dashed` parallels render explicit [ ] brackets framing
1321
- // the nested tracks with 12 px vertical padding above/below.
1322
- if (p.style.bracket === 'solid' || p.style.bracket === 'dashed') {
1323
- const padding = 12;
1324
- const stub = 4;
1325
- const top = p.box.y - padding;
1326
- const bottom = p.box.y + p.box.height + padding;
1327
- const lx = p.box.x;
1328
- const rx = p.box.x + p.box.width;
1329
- const stroke = palette.parallel.bracketStroke;
1330
- parts.push(
1331
- tag('path', {
1332
- d: `M${num(lx + stub)} ${num(top)} H${num(lx)} V${num(bottom)} H${num(lx + stub)}`,
1333
- fill: 'none',
1334
- stroke,
1335
- 'stroke-width': 1.25,
1336
- 'stroke-dasharray': p.style.bracket === 'dashed' ? '3 3' : null,
1337
- 'stroke-linejoin': 'round',
1338
- }),
1339
- );
1340
- parts.push(
1341
- tag('path', {
1342
- d: `M${num(rx - stub)} ${num(top)} H${num(rx)} V${num(bottom)} H${num(rx - stub)}`,
1343
- fill: 'none',
1344
- stroke,
1345
- 'stroke-width': 1.25,
1346
- 'stroke-dasharray': p.style.bracket === 'dashed' ? '3 3' : null,
1347
- 'stroke-linejoin': 'round',
1348
- }),
1349
- );
1350
- }
1351
- if (p.title) {
1352
- parts.push(
1353
- textTag(
1354
- {
1355
- x: num(p.box.x + 4),
1356
- y: num(p.box.y - 2),
1357
- ...fontAttrs(p.style, fonts, TEXT_SIZE_PX.xs),
1358
- 'fill-opacity': 0.7,
1359
- },
1360
- p.title,
1361
- ),
1362
- );
1363
- }
1364
- // Inline-date pins on the parallel itself (`parallel ... after:DATE` /
1365
- // `before:DATE`). Painted before children so child bars sit on top.
1366
- parts.push(renderInlineDatePins(p.inlineDatePins, p.style.fg));
1367
- for (const c of p.children) {
1368
- parts.push(renderTrackChild(c, options, idPrefix, palette, fonts));
1369
- }
1370
- return tag('g', { 'data-layer': 'parallel', 'data-id': p.id ?? null }, parts.join(''));
1371
- }
1372
-
1373
- function renderTrackChild(
1374
- c: PositionedTrackChild,
1375
- options: RenderOptions,
1376
- idPrefix: string,
1377
- palette: Theme,
1378
- fonts: FontFamilies,
1379
- ): string {
1380
- if (c.kind === 'item') return renderItem(c, options, idPrefix, palette, fonts);
1381
- if (c.kind === 'group') return renderGroup(c, options, idPrefix, palette, fonts);
1382
- return renderParallel(c, options, idPrefix, palette, fonts);
1383
- }
1384
-
1385
- // Renders only the swimlane's background tint rect. Emitted before the
1386
- // chart-body grid lines so those lines visibly span the full chart width.
1387
- // The frame tab (chiclet at top-left) and item content are emitted later,
1388
- // in renderSwimlaneContent, so they appear on top of the grid.
1389
- // Tri-state lane utilization underline. Painted along the bottom edge of
1390
- // the band when the lane has `capacity:` AND at least one item contributing
1391
- // load AND has not opted out of every color band via `utilization-*-at:none`.
1392
- // Geometry per specs/rendering.md § Lane utilization underline:
1393
- // - height: 2px (matches the milestone-line stroke weight)
1394
- // - y: flush with the bottom edge of the band, fully inside it
1395
- // - x: aligned to the segment boundaries the layout already pre-coalesced
1396
- // One <rect> per coalesced segment; classification → palette token mapping
1397
- // is the only renderer-side decision.
1398
- const LANE_UTILIZATION_HEIGHT_PX = 2;
1399
-
1400
- function utilizationColor(classification: 'green' | 'yellow' | 'red', palette: Theme): string {
1401
- switch (classification) {
1402
- case 'green':
1403
- return palette.swimlane.utilizationOk;
1404
- case 'yellow':
1405
- return palette.swimlane.utilizationWarn;
1406
- case 'red':
1407
- return palette.swimlane.utilizationOver;
1408
- }
1409
- }
1410
-
1411
- function renderLaneUtilization(s: PositionedSwimlane, palette: Theme): string {
1412
- if (!s.utilization || s.utilization.segments.length === 0) return '';
1413
- const y = s.box.y + s.box.height - LANE_UTILIZATION_HEIGHT_PX;
1414
- const rects = s.utilization.segments.map((seg) => {
1415
- const width = seg.endX - seg.startX;
1416
- if (width <= 0) return '';
1417
- return tag('rect', {
1418
- x: num(seg.startX),
1419
- y: num(y),
1420
- width: num(width),
1421
- height: LANE_UTILIZATION_HEIGHT_PX,
1422
- fill: utilizationColor(seg.classification, palette),
1423
- 'data-utilization': seg.classification,
1424
- 'data-load': num(seg.load),
1425
- });
1426
- });
1427
- return tag(
1428
- 'g',
1429
- {
1430
- 'data-layer': 'lane-utilization',
1431
- 'data-id': s.id ?? null,
1432
- },
1433
- rects.join(''),
1434
- );
1435
- }
1436
-
1437
- function renderSwimlaneBg(s: PositionedSwimlane, palette: Theme): string {
1438
- const tint = s.bandIndex % 2 === 0 ? palette.swimlane.rowTintEven : palette.swimlane.rowTintOdd;
1439
- const borderColor = palette.swimlane.border;
1440
- return tag(
1441
- 'g',
1442
- { 'data-layer': 'swimlane-bg', 'data-id': s.id ?? null },
1443
- tag('rect', {
1444
- x: num(s.box.x),
1445
- y: num(s.box.y),
1446
- width: num(s.box.width),
1447
- height: num(s.box.height),
1448
- fill: tint,
1449
- stroke: borderColor,
1450
- 'stroke-width': 1,
1451
- }),
1452
- );
1453
- }
1454
-
1455
- function renderSwimlane(
1456
- s: PositionedSwimlane,
1457
- options: RenderOptions,
1458
- idPrefix: string,
1459
- palette: Theme,
1460
- fonts: FontFamilies,
1461
- ): string {
1462
- const tabFill = palette.swimlane.tabFill;
1463
- const tabStroke = palette.swimlane.tabStroke;
1464
- const tabText = palette.swimlane.tabText;
1465
- const ownerText = palette.swimlane.ownerText;
1466
- const footnoteColor = palette.swimlane.footnoteIndicator;
1467
- const parts: string[] = [];
1468
- // Frame-tab chiclet at the top-left of the band — auto-sized to fit
1469
- // title + owner. Geometry comes from the shared `frameTabGeometry`
1470
- // helper that the layout's row-packer also calls, so the chiclet's
1471
- // visible footprint matches the collision box layout reserved for it.
1472
- if (s.title) {
1473
- // Lane capacity badge + footnote indicator sit inside the frame
1474
- // tab after the owner (or after the title if no owner). Compute
1475
- // both widths up-front so `frameTabGeometry` can size the chiclet
1476
- // to fit them, then read the placement positions back out — no
1477
- // second placement pass in the renderer.
1478
- const LANE_BADGE_FONT_SIZE_PX = 10;
1479
- const capacityBadgeBareWidthPx = s.capacity
1480
- ? estimateCapacitySuffixWidth(s.capacity.text, s.capacity.icon, LANE_BADGE_FONT_SIZE_PX)
1481
- : 0;
1482
- // Footnote indicator is a comma-joined number list painted at
1483
- // 10 pt 700-weight; estimate via the shared caption helper.
1484
- const footnoteIndicatorText =
1485
- s.footnoteIndicators.length > 0 ? s.footnoteIndicators.join(',') : '';
1486
- const footnoteIndicatorWidthPx = footnoteIndicatorText
1487
- ? estimateCaptionWidthPx(footnoteIndicatorText, LANE_BADGE_FONT_SIZE_PX)
1488
- : 0;
1489
- const tab = frameTabGeometry(
1490
- s.box.x,
1491
- s.title,
1492
- s.owner,
1493
- capacityBadgeBareWidthPx,
1494
- footnoteIndicatorWidthPx,
1495
- );
1496
- const tabH = FRAME_TAB_HEIGHT_PX;
1497
- const tabY = s.box.y + 10;
1498
- const labelY = tabY + FRAME_TAB_LABEL_BASELINE_OFFSET_PX;
1499
- parts.push(
1500
- tag('rect', {
1501
- x: num(tab.tabX),
1502
- y: num(tabY),
1503
- width: num(tab.tabW),
1504
- height: num(tabH),
1505
- rx: 4,
1506
- ry: 4,
1507
- fill: tabFill,
1508
- stroke: tabStroke,
1509
- 'stroke-width': 1,
1510
- }),
1511
- );
1512
- parts.push(
1513
- textTag(
1514
- {
1515
- x: num(tab.titleX),
1516
- y: num(labelY),
1517
- 'font-family': fonts[s.style.font],
1518
- 'font-size': 12,
1519
- 'font-weight': 600,
1520
- fill: tabText,
1521
- },
1522
- s.title,
1523
- ),
1524
- );
1525
- if (s.owner) {
1526
- parts.push(
1527
- textTag(
1528
- {
1529
- x: num(tab.ownerX),
1530
- y: num(labelY),
1531
- 'font-family': fonts[s.style.font],
1532
- 'font-size': 10,
1533
- fill: ownerText,
1534
- },
1535
- `owner: ${s.owner}`,
1536
- ),
1537
- );
1538
- }
1539
- if (s.capacity) {
1540
- // Re-uses the same `renderCapacitySuffix` helper that paints
1541
- // item-level suffixes (m6) so multiplier / built-in SVG /
1542
- // inline literal / dereferenced-custom-glyph paths stay
1543
- // consistent across both contexts.
1544
- parts.push(
1545
- renderCapacitySuffix(
1546
- s.capacity,
1547
- undefined,
1548
- tab.badgeX,
1549
- labelY,
1550
- LANE_BADGE_FONT_SIZE_PX,
1551
- fonts[s.style.font],
1552
- ownerText,
1553
- ),
1554
- );
1555
- }
1556
- if (footnoteIndicatorText) {
1557
- parts.push(
1558
- textTag(
1559
- {
1560
- x: num(tab.footnoteRightX),
1561
- y: num(tabY + 14),
1562
- 'font-family': fonts.sans,
1563
- 'font-size': LANE_BADGE_FONT_SIZE_PX,
1564
- 'font-weight': 700,
1565
- fill: footnoteColor,
1566
- 'text-anchor': 'end',
1567
- },
1568
- footnoteIndicatorText,
1569
- ),
1570
- );
1571
- }
1572
- }
1573
- for (const c of s.children) {
1574
- parts.push(renderTrackChild(c, options, idPrefix, palette, fonts));
1575
- }
1576
- // m13: tri-state utilization underline along the band's bottom edge.
1577
- // Painted after items so it overlays any item that happens to extend
1578
- // to the band's bottom; under cut-lines / now-line which run as
1579
- // separate top-level passes.
1580
- parts.push(renderLaneUtilization(s, palette));
1581
- return tag('g', { 'data-layer': 'swimlane', 'data-id': s.id ?? null }, parts.join(''));
1582
- }
1583
-
1584
- function renderAnchor(a: PositionedAnchor, palette: Theme, fonts: FontFamilies): string {
1585
- const size = a.radius;
1586
- const cx = a.center.x;
1587
- const cy = a.center.y;
1588
- const fill = palette.anchorDiamond.fill;
1589
- const stroke = palette.anchorDiamond.stroke;
1590
- const diamond = tag('path', {
1591
- d: `M${num(cx)} ${num(cy - size)} L${num(cx + size)} ${num(cy)} L${num(cx)} ${num(cy + size)} L${num(cx - size)} ${num(cy)} Z`,
1592
- fill,
1593
- stroke,
1594
- 'stroke-width': 1.25,
1595
- });
1596
- const labelColor = palette.anchorDiamond.label;
1597
- // For left-flipped labels, anchor the text at its RIGHT edge using
1598
- // `text-anchor: end`. The layout's `labelBox.width` is intentionally
1599
- // pessimistic (0.58 em/char) so positioning by the box's left edge
1600
- // would leave a visible gap between the actual text right edge and
1601
- // the diamond. End-anchoring lets the browser size the glyph run
1602
- // exactly and put the rightmost glyph 6 px from the diamond — same
1603
- // rhythm the right-side labels already get from start-anchoring at
1604
- // `diamondRight + 6`.
1605
- const labelX = a.labelSide === 'left' ? a.labelBox.x + a.labelBox.width : a.labelBox.x;
1606
- const labelAttrs: Record<string, string | number | null | undefined> = {
1607
- x: num(labelX),
1608
- y: num(cy + 4),
1609
- 'font-family': fonts.sans,
1610
- 'font-size': 10,
1611
- fill: labelColor,
1612
- };
1613
- if (a.labelSide === 'left') labelAttrs['text-anchor'] = 'end';
1614
- const label = a.title ? textTag(labelAttrs, a.title) : '';
1615
- return tag('g', { 'data-layer': 'anchor', 'data-id': a.id ?? null }, diamond + label);
1616
- }
1617
-
1618
- function renderAnchorCutLine(a: PositionedAnchor, palette: Theme): string {
1619
- const stroke = palette.anchorDiamond.cutLine;
1620
- return tag('line', {
1621
- x1: num(a.center.x),
1622
- y1: num(a.center.y + a.radius + 1),
1623
- x2: num(a.center.x),
1624
- y2: num(a.cutBottomY),
1625
- stroke,
1626
- 'stroke-width': 1,
1627
- 'stroke-dasharray': '1 3',
1628
- });
1629
- }
1630
-
1631
- function renderMilestone(m: PositionedMilestone, palette: Theme, fonts: FontFamilies): string {
1632
- const cx = m.center.x;
1633
- const cy = m.center.y;
1634
- const r = m.radius;
1635
- const fill = palette.milestoneDiamond.fill;
1636
- const flag = tag('path', {
1637
- d: `M${num(cx)} ${num(cy - r)} L${num(cx + r)} ${num(cy)} L${num(cx)} ${num(cy + r)} L${num(cx - r)} ${num(cy)} Z`,
1638
- fill,
1639
- stroke: fill,
1640
- 'stroke-width': 1,
1641
- });
1642
- const labelColor = palette.milestoneDiamond.label;
1643
- // See renderAnchor — left-flipped labels use `text-anchor: end` so
1644
- // the visual right edge sits at `diamondLeft - 6`, matching the
1645
- // 6 px rhythm of right-side labels.
1646
- const labelX = m.labelSide === 'left' ? m.labelBox.x + m.labelBox.width : m.labelBox.x;
1647
- const labelAttrs: Record<string, string | number | null | undefined> = {
1648
- x: num(labelX),
1649
- y: num(cy + 4),
1650
- 'font-family': fonts.sans,
1651
- 'font-size': 10,
1652
- 'font-weight': 600,
1653
- fill: labelColor,
1654
- };
1655
- if (m.labelSide === 'left') labelAttrs['text-anchor'] = 'end';
1656
- const label = m.title ? textTag(labelAttrs, m.title) : '';
1657
- return tag('g', { 'data-layer': 'milestone', 'data-id': m.id ?? null }, flag + label);
1658
- }
1659
-
1660
- function renderMilestoneCutLine(m: PositionedMilestone, palette: Theme): string {
1661
- const stroke = m.isOverrun
1662
- ? palette.milestoneDiamond.cutLineOverrun
1663
- : palette.milestoneDiamond.cutLineNormal;
1664
- const parts: string[] = [];
1665
- parts.push(
1666
- tag('line', {
1667
- x1: num(m.center.x),
1668
- y1: num(m.center.y + m.radius + 1),
1669
- x2: num(m.center.x),
1670
- y2: num(m.cutBottomY),
1671
- stroke,
1672
- 'stroke-width': 2,
1673
- 'stroke-dasharray': ACCENT_DASH_PATTERN,
1674
- 'stroke-linecap': 'round',
1675
- }),
1676
- );
1677
- if (m.slackArrows && m.slackArrows.length > 0) {
1678
- const slackColor = palette.milestoneDiamond.slack;
1679
- for (const arrow of m.slackArrows) {
1680
- parts.push(
1681
- tag('path', {
1682
- d: `M${num(arrow.x)} ${num(arrow.y)} H${num(m.center.x - 6)}`,
1683
- fill: 'none',
1684
- stroke: slackColor,
1685
- 'stroke-width': 1.1,
1686
- 'stroke-dasharray': '3 3',
1687
- 'stroke-linecap': 'round',
1688
- 'marker-end': 'url(#nl-arrow-dark)',
1689
- }),
1690
- );
1691
- }
1692
- }
1693
- return parts.join('');
1694
- }
1695
-
1696
- function renderEdge(e: PositionedDependencyEdge, palette: Theme): string {
1697
- const color =
1698
- e.kind === 'overflow' ? palette.dependency.overflowStroke : palette.dependency.edgeStroke;
1699
- const points = e.waypoints;
1700
- if (points.length < 2) return '';
1701
- // Under-bar edges paint BEFORE item fills (see `renderRoadmap`)
1702
- // and use a thinner stroke so the bar stays foreground. Normal /
1703
- // overflow edges sit on top of items and use the standard 1.1 px
1704
- // stroke.
1705
- const strokeWidth = e.kind === 'underBar' ? 0.8 : 1.1;
1706
- return tag('path', {
1707
- d: roundedOrthogonalPath(points, EDGE_CORNER_RADIUS),
1708
- fill: 'none',
1709
- stroke: color,
1710
- 'stroke-width': strokeWidth,
1711
- 'stroke-dasharray': e.kind === 'overflow' ? '4 2' : null,
1712
- 'stroke-linejoin': 'round',
1713
- 'marker-end': 'url(#nl-arrow)',
1714
- });
1715
- }
1716
-
1717
- // Build an SVG path for a sequence of orthogonal waypoints, inserting a
1718
- // quarter-arc at every interior bend. Falls back to straight segments when
1719
- // adjacent points aren't axis-aligned (defensive — the layout always emits
1720
- // orthogonal segments).
1721
- function roundedOrthogonalPath(points: Point[], radius: number): string {
1722
- if (points.length < 2) return '';
1723
- const parts: string[] = [`M${num(points[0].x)} ${num(points[0].y)}`];
1724
- for (let i = 1; i < points.length; i++) {
1725
- const prev = points[i - 1];
1726
- const cur = points[i];
1727
- if (i === points.length - 1) {
1728
- parts.push(`L${num(cur.x)} ${num(cur.y)}`);
1729
- continue;
1730
- }
1731
- const next = points[i + 1];
1732
- const dxIn = Math.sign(cur.x - prev.x);
1733
- const dyIn = Math.sign(cur.y - prev.y);
1734
- const dxOut = Math.sign(next.x - cur.x);
1735
- const dyOut = Math.sign(next.y - cur.y);
1736
- const inLen = Math.hypot(cur.x - prev.x, cur.y - prev.y);
1737
- const outLen = Math.hypot(next.x - cur.x, next.y - cur.y);
1738
- const r = Math.min(radius, inLen / 2, outLen / 2);
1739
- if (r <= 0 || (dxIn !== 0 && dxOut !== 0) || (dyIn !== 0 && dyOut !== 0)) {
1740
- parts.push(`L${num(cur.x)} ${num(cur.y)}`);
1741
- continue;
1742
- }
1743
- const beforeBend = { x: cur.x - dxIn * r, y: cur.y - dyIn * r };
1744
- const afterBend = { x: cur.x + dxOut * r, y: cur.y + dyOut * r };
1745
- parts.push(`L${num(beforeBend.x)} ${num(beforeBend.y)}`);
1746
- parts.push(`Q${num(cur.x)} ${num(cur.y)} ${num(afterBend.x)} ${num(afterBend.y)}`);
1747
- }
1748
- return parts.join(' ');
1749
- }
1750
-
1751
- function renderFootnotes(
1752
- f: PositionedFootnoteArea,
1753
- idPrefix: string,
1754
- palette: Theme,
1755
- fonts: FontFamilies,
1756
- ): string {
1757
- if (f.entries.length === 0) return '';
1758
- const panelFill = palette.footnotePanel.fill;
1759
- const borderColor = palette.footnotePanel.border;
1760
- const headerColor = palette.footnotePanel.header;
1761
- const titleColor = palette.footnotePanel.title;
1762
- const descColor = palette.footnotePanel.description;
1763
- const numberColor = palette.footnotePanel.number;
1764
- const parts: string[] = [];
1765
- parts.push(
1766
- tag('rect', {
1767
- x: num(f.box.x),
1768
- y: num(f.box.y),
1769
- width: num(f.box.width),
1770
- height: num(f.box.height),
1771
- rx: 6,
1772
- ry: 6,
1773
- fill: panelFill,
1774
- stroke: borderColor,
1775
- 'stroke-width': 1,
1776
- filter: `url(#${idPrefix}-shadow-subtle)`,
1777
- }),
1778
- );
1779
- parts.push(
1780
- textTag(
1781
- {
1782
- x: num(f.box.x + FOOTNOTE_PANEL_PADDING_PX),
1783
- y: num(f.box.y + FOOTNOTE_HEADER_BASELINE_OFFSET_PX),
1784
- 'font-family': fonts.sans,
1785
- 'font-size': 12,
1786
- 'font-weight': 700,
1787
- fill: headerColor,
1788
- },
1789
- 'Footnotes',
1790
- ),
1791
- );
1792
- // First entry baseline = panel-top + header band + one panel padding
1793
- // (the gap between the header band and the first row).
1794
- const firstEntryBaselineY = f.box.y + FOOTNOTE_HEADER_HEIGHT_PX + FOOTNOTE_PANEL_PADDING_PX;
1795
- const numberX = f.box.x + FOOTNOTE_PANEL_PADDING_PX;
1796
- const titleX = numberX + FOOTNOTE_PANEL_PADDING_PX;
1797
- f.entries.forEach((e, i) => {
1798
- const y = firstEntryBaselineY + i * FOOTNOTE_ROW_HEIGHT;
1799
- parts.push(
1800
- textTag(
1801
- {
1802
- x: num(numberX),
1803
- y: num(y),
1804
- 'font-family': fonts.sans,
1805
- 'font-size': 10,
1806
- 'font-weight': 700,
1807
- fill: numberColor,
1808
- },
1809
- String(e.number),
1810
- ),
1811
- );
1812
- parts.push(
1813
- textTag(
1814
- {
1815
- x: num(titleX),
1816
- y: num(y),
1817
- 'font-family': fonts.sans,
1818
- 'font-size': 11,
1819
- 'font-weight': 600,
1820
- fill: titleColor,
1821
- },
1822
- e.title,
1823
- ),
1824
- );
1825
- if (e.description) {
1826
- parts.push(
1827
- textTag(
1828
- {
1829
- x: num(titleX + Math.max(120, e.title.length * 6)),
1830
- y: num(y),
1831
- 'font-family': fonts.sans,
1832
- 'font-size': 11,
1833
- fill: descColor,
1834
- },
1835
- `— ${e.description}`,
1836
- ),
1837
- );
1838
- }
1839
- });
1840
- return tag('g', { 'data-layer': 'footnotes' }, parts.join(''));
1841
- }
1842
-
1843
- function renderIncludeRegion(
1844
- r: PositionedIncludeRegion,
1845
- options: RenderOptions,
1846
- idPrefix: string,
1847
- palette: Theme,
1848
- fonts: FontFamilies,
1849
- ): string {
1850
- const border = palette.includeRegion.border;
1851
- const fill = palette.includeRegion.fill;
1852
- const tabFill = palette.includeRegion.tabFill;
1853
- const tabStroke = palette.includeRegion.tabStroke;
1854
- const tabText = palette.includeRegion.tabText;
1855
- const badgeFill = palette.includeRegion.badgeFill;
1856
- const badgeStroke = palette.includeRegion.badgeStroke;
1857
- const badgeText = palette.includeRegion.badgeText;
1858
-
1859
- const rx = r.box.x + 8;
1860
- const ry = r.box.y;
1861
- const rw = r.box.width - 16;
1862
- const rh = r.box.height;
1863
-
1864
- const region = tag('rect', {
1865
- x: num(rx),
1866
- y: num(ry),
1867
- width: num(rw),
1868
- height: num(rh),
1869
- rx: 8,
1870
- ry: 8,
1871
- fill,
1872
- stroke: border,
1873
- 'stroke-width': 1,
1874
- 'stroke-dasharray': ACCENT_DASH_PATTERN,
1875
- });
1876
-
1877
- // Chrome geometry — single source of truth shared with the layout
1878
- // (`buildIncludeRegions` calls the same helper to size the dashed
1879
- // bracket so the chrome always fits inside it). All placement Xs
1880
- // come from the helper directly so the renderer stays declarative.
1881
- const tabHeight = FRAME_TAB_HEIGHT_PX;
1882
- const chrome = includeChromeGeometry(r.box.x, r.label, r.sourcePath);
1883
- const tabY = ry - tabHeight / 2;
1884
- const tab = tag('rect', {
1885
- x: num(chrome.tabX),
1886
- y: num(tabY),
1887
- width: num(chrome.tabWidth),
1888
- height: tabHeight,
1889
- rx: 4,
1890
- ry: 4,
1891
- fill: tabFill,
1892
- stroke: tabStroke,
1893
- 'stroke-width': 1,
1894
- });
1895
- const tabLabel = textTag(
1896
- {
1897
- x: num(chrome.tabLabelX),
1898
- y: num(tabY + FRAME_TAB_LABEL_BASELINE_OFFSET_PX),
1899
- 'font-family': fonts.sans,
1900
- 'font-size': 11,
1901
- 'font-weight': 600,
1902
- fill: tabText,
1903
- },
1904
- r.label,
1905
- );
1906
-
1907
- // Content badge to the right of the tab. The glyph here is the
1908
- // stacked-sheets icon, distinct from the item-level link-icon
1909
- // outbound-arrow: an `include` is a content pull (one document
1910
- // brings in another), conceptually different from a `link:` that
1911
- // navigates somewhere.
1912
- const badgeX = chrome.badgeX;
1913
- const badgeSize = chrome.badgeSize;
1914
- const badgeY = ry - badgeSize / 2;
1915
- const badge = tag('rect', {
1916
- x: num(badgeX),
1917
- y: num(badgeY),
1918
- width: badgeSize,
1919
- height: badgeSize,
1920
- rx: 4,
1921
- ry: 4,
1922
- fill: badgeFill,
1923
- stroke: badgeStroke,
1924
- 'stroke-width': 1,
1925
- });
1926
- // Glyph: stacked sheets — back rectangle peeking behind front
1927
- // rectangle. Sized for the 18×18 badge tile.
1928
- const glyph = tag('path', {
1929
- d:
1930
- `M${num(badgeX + 7)} ${num(badgeY + 4)} H${num(badgeX + 14)} V${num(badgeY + 11)}` +
1931
- ` M${num(badgeX + 4)} ${num(badgeY + 7)} H${num(badgeX + 11)} V${num(badgeY + 14)} H${num(badgeX + 4)} Z`,
1932
- stroke: badgeText,
1933
- 'stroke-width': 1.4,
1934
- fill: 'none',
1935
- 'stroke-linecap': 'round',
1936
- 'stroke-linejoin': 'round',
1937
- });
1938
- // Halo behind the source-path text. The text's baseline at `ry + 4`
1939
- // straddles the dashed region border (drawn at y = ry); without a
1940
- // backing rect the dashed stroke cuts through the text body. Matches
1941
- // how the tab and badge already mask the border where they cross it.
1942
- // Fill is `includeRegion.fill` — same cream/tint as the region, near
1943
- // the canvas surface above, so the halo disappears into both.
1944
- const sourceFontSize = 9;
1945
- const sourceTextY = ry + 4;
1946
- const sourceHalo = tag('rect', {
1947
- x: num(chrome.sourceHaloX),
1948
- y: num(sourceTextY - sourceFontSize),
1949
- width: num(chrome.sourceHaloWidth),
1950
- height: sourceFontSize + 6,
1951
- fill,
1952
- });
1953
- const sourceText = textTag(
1954
- {
1955
- x: num(chrome.sourceTextX),
1956
- y: num(sourceTextY),
1957
- 'font-family': fonts.mono,
1958
- 'font-size': sourceFontSize,
1959
- fill: badgeText,
1960
- },
1961
- r.sourcePath,
1962
- );
1963
-
1964
- // Nested swimlanes (laid out by buildIncludeRegions against the parent's timeline).
1965
- const nested = r.nestedSwimlanes
1966
- .map((s) => renderSwimlane(s, options, idPrefix, palette, fonts))
1967
- .join('');
1968
-
1969
- return tag(
1970
- 'g',
1971
- { 'data-layer': 'include' },
1972
- region + nested + tab + tabLabel + badge + glyph + sourceHalo + sourceText,
1973
- );
1974
- }
1975
-
1976
- // Paint the "Powered by nowline" attribution mark inside the
1977
- // layout-supplied `attributionBox`. The whole mark — prefix text,
1978
- // "now", red "l" bar, and "ine" — sits inside one <a href> so the
1979
- // entire string is clickable. Glyph anatomy (positions, widths, scale)
1980
- // lives in `themes/shared.ts` (`ATTRIBUTION_*`); the layout reserves a
1981
- // box of exactly that size at canvas-bottom-right.
1982
- function renderAttributionMark(model: PositionedRoadmap, fonts: FontFamilies): string {
1983
- const muted = model.palette.attribution.mark;
1984
- const accent = model.palette.attribution.link;
1985
- if (model.swimlanes.length === 0) return '';
1986
- const tx = model.header.attributionBox.x;
1987
- const ty = model.header.attributionBox.y;
1988
- // Both texts share the wordmark's baseline (y = wordmark font size)
1989
- // so the smaller "Powered by" sits visually above the wordmark's
1990
- // baseline without bumping the bar's bottom up.
1991
- const baselineY = ATTRIBUTION_WORDMARK_FONT_SIZE;
1992
- const inner =
1993
- textTag(
1994
- {
1995
- x: '0',
1996
- y: baselineY,
1997
- 'font-family': fonts.sans,
1998
- 'font-size': ATTRIBUTION_PREFIX_FONT_SIZE,
1999
- 'font-weight': 400,
2000
- fill: muted,
2001
- },
2002
- ATTRIBUTION_TEXT,
2003
- ) +
2004
- textTag(
2005
- {
2006
- x: ATTRIBUTION_NOW_LOGICAL_X,
2007
- y: baselineY,
2008
- 'font-family': fonts.sans,
2009
- 'font-size': ATTRIBUTION_WORDMARK_FONT_SIZE,
2010
- 'font-weight': 700,
2011
- fill: muted,
2012
- },
2013
- 'now',
2014
- ) +
2015
- tag('rect', {
2016
- x: ATTRIBUTION_BAR_LOGICAL_X,
2017
- y: 12,
2018
- width: ATTRIBUTION_BAR_LOGICAL_WIDTH,
2019
- height: ATTRIBUTION_WORDMARK_FONT_SIZE,
2020
- fill: accent,
2021
- }) +
2022
- textTag(
2023
- {
2024
- x: ATTRIBUTION_INE_LOGICAL_X,
2025
- y: baselineY,
2026
- 'font-family': fonts.sans,
2027
- 'font-size': ATTRIBUTION_WORDMARK_FONT_SIZE,
2028
- 'font-weight': 400,
2029
- fill: muted,
2030
- },
2031
- 'ine',
2032
- );
2033
- const group = tag(
2034
- 'g',
2035
- { transform: `translate(${num(tx)} ${num(ty)}) scale(${num(ATTRIBUTION_SCALE)})` },
2036
- inner,
2037
- );
2038
- return tag(
2039
- 'a',
2040
- {
2041
- href: ATTRIBUTION_LINK,
2042
- target: '_blank',
2043
- rel: 'noopener',
2044
- 'aria-label': 'Powered by nowline',
2045
- },
2046
- tag('g', { 'data-layer': 'attribution' }, group),
2047
- );
2048
- }
2049
-
2050
- async function embedLogo(
2051
- logoRef: string,
2052
- resolver: AssetResolver | undefined,
2053
- idPrefix: string,
2054
- options: RenderOptions,
2055
- x: number,
2056
- y: number,
2057
- size: number,
2058
- ): Promise<string> {
2059
- if (!resolver) return '';
2060
- let asset: AssetBytes;
2061
- try {
2062
- asset = await resolver(logoRef);
2063
- } catch (err) {
2064
- const msg = `logo: failed to load ${logoRef}: ${err instanceof Error ? err.message : String(err)}`;
2065
- if (options.strict) throw err;
2066
- options.warn?.(msg);
2067
- return '';
2068
- }
2069
- const mime = (asset.mime ?? '').toLowerCase();
2070
- if (mime === 'image/svg+xml') {
2071
- const raw = new TextDecoder().decode(asset.bytes);
2072
- const cleaned = sanitizeSvg(raw, { idPrefix: `${idPrefix}-logo`, onWarn: options.warn });
2073
- return tag('g', { transform: `translate(${num(x)} ${num(y)})` }, cleaned);
2074
- }
2075
- if (
2076
- mime === 'image/png' ||
2077
- mime === 'image/jpeg' ||
2078
- mime === 'image/jpg' ||
2079
- mime === 'image/webp'
2080
- ) {
2081
- const b64 = bytesToBase64(asset.bytes);
2082
- return tag('image', {
2083
- href: `data:${mime};base64,${b64}`,
2084
- x: num(x),
2085
- y: num(y),
2086
- width: num(size),
2087
- height: num(size),
2088
- preserveAspectRatio: 'xMidYMid meet',
2089
- });
2090
- }
2091
- const msg = `logo: unsupported mime ${mime} for ${logoRef}`;
2092
- if (options.strict) throw new Error(msg);
2093
- options.warn?.(msg);
2094
- return '';
2095
- }
2096
-
2097
- // Base64 without depending on Node's Buffer (renderer stays browser-safe).
2098
- function bytesToBase64(bytes: Uint8Array): string {
2099
- if (typeof btoa !== 'undefined') {
2100
- let bin = '';
2101
- for (let i = 0; i < bytes.length; i++) bin += String.fromCharCode(bytes[i]);
2102
- return btoa(bin);
2103
- }
2104
- // Node fallback without importing Buffer directly; use lazy dynamic require.
2105
- const g = globalThis as {
2106
- Buffer?: { from: (b: Uint8Array) => { toString: (enc: string) => string } };
2107
- };
2108
- if (g.Buffer) return g.Buffer.from(bytes).toString('base64');
2109
- throw new Error('renderer: no base64 encoder available');
2110
- }
2111
-
2112
89
  export async function renderSvg(
2113
90
  model: PositionedRoadmap,
2114
91
  options: RenderOptions = {},
@@ -2123,17 +100,21 @@ export async function renderSvg(
2123
100
  const fonts: FontFamilies = options.fontFamilies ?? FONT_STACK;
2124
101
  const parts: string[] = [];
2125
102
 
2126
- // <defs> — shadows + arrowhead markers (palette-driven fills baked in).
2127
- const arrowFillNeutral = palette.arrowhead.neutral;
2128
- const arrowFillLight = palette.arrowhead.light;
2129
- const arrowFillDark = palette.arrowhead.dark;
103
+ // <defs> — shadows + the milestone arrow markers (palette-driven fill
104
+ // baked in). Dependency arrows draw their own heads (`renderEdge`), so
105
+ // the milestone slack line's dark marker is the only one. Their ids carry the per-render prefix: several SVGs
106
+ // inlined in one HTML page share an id namespace and `url(#id)` resolves
107
+ // to the first match, so a global id would paint one diagram's
108
+ // arrowheads (and theme) onto another.
2130
109
  const arrowDef = (id: string, fill: string): string =>
2131
110
  `<marker id="${id}" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto"><path d="M 0 0 L 10 5 L 0 10 z" fill="${fill}"/></marker>`;
2132
111
  const defs =
2133
112
  `<defs>${allShadowDefs(idPrefix)}` +
2134
- arrowDef('nl-arrow', arrowFillNeutral) +
2135
- arrowDef('nl-arrow-light', arrowFillLight) +
2136
- arrowDef('nl-arrow-dark', arrowFillDark) +
113
+ arrowDef(`${idPrefix}-arrow-dark`, palette.arrowhead.dark) +
114
+ // Wave hatch patterns, only those a bar or the legend uses.
115
+ usedWaveHatchKinds(model)
116
+ .map((k) => waveHatchPatternDef(idPrefix, k, palette))
117
+ .join('') +
2137
118
  `</defs>`;
2138
119
  parts.push(defs);
2139
120
 
@@ -2154,29 +135,37 @@ export async function renderSvg(
2154
135
  // and minor grid lines never actually rendered in the chart body.
2155
136
  // They now ship as their own layer below.
2156
137
  parts.push(renderTimeline(model.timeline, palette, fonts));
138
+ // Wave strip panel and cells, under the grid like the tick panel.
139
+ parts.push(renderWaveStrip(model, palette));
2157
140
 
2158
141
  // Swimlane backgrounds — emitted as their own pass so the grid
2159
142
  // lines can be drawn on top of them, then the swimlane content
2160
143
  // (frame tab + items) sits on top of the grid.
2161
144
  for (const s of model.swimlanes) parts.push(renderSwimlaneBg(s, palette));
2162
145
 
146
+ // Non-working bands under `show`, over the lane rows and under the
147
+ // wave tints and the grid; nothing under `hide`.
148
+ parts.push(renderNonWorkingBands(model.timeline, model.chartBox.y, palette));
149
+
150
+ // Styled wave column tints, over the lane rows and under the grid.
151
+ if (model.waves) parts.push(renderWaveTints(model.waves));
152
+
2163
153
  // Chart-body grid lines (major dotted at every labeled tick, plus
2164
154
  // optional faint minor lines when minor-grid is set). Drawn after
2165
155
  // swimlane backgrounds so they actually span the chart body, but
2166
156
  // before items and overlays so item bars sit cleanly on top.
2167
157
  parts.push(renderGridLines(model.timeline, model.chartBox.y, palette));
2168
158
 
2169
- // m2g+: under-bar dependency edges go BEFORE swimlane / item
2170
- // content. The channel router falls back to under-bar routing when
2171
- // it can't find a clear vertical gutter between source and target;
2172
- // these edges intentionally cross item bars and need the item fills
2173
- // painted ON TOP so the bars stay the visual foreground. Renderer
2174
- // applies a thinner stroke (see `renderEdge`) to further de-emphasise
2175
- // the arrow body — only the head and stub at the target end stay
2176
- // crisply visible.
2177
- for (const e of model.edges) {
2178
- if (e.kind === 'underBar') parts.push(renderEdge(e, palette));
2179
- }
159
+ // Wave boundaries over the grid and the marker-row panel but under
160
+ // the bars, then the strip labels, diamonds and gap labels on top of
161
+ // them (specs/waves.md §9.9).
162
+ parts.push(renderWaveBoundaries(model.waveBoundaries));
163
+ parts.push(renderWaveLabels(model, palette, fonts));
164
+
165
+ // Dependency arrows go BEFORE swimlane / item content: their legs
166
+ // pass behind the bars they cross (specs/true-width-layout.md §3.4).
167
+ // Each lands in a gap between rows, so its head stays in view.
168
+ for (const e of model.edges) parts.push(renderEdge(e, palette));
2180
169
 
2181
170
  // Swimlane content (frame tabs + items) on top of the grid lines.
2182
171
  for (const s of model.swimlanes)
@@ -2185,18 +174,19 @@ export async function renderSvg(
2185
174
  // Include regions (drawn after own swimlanes so the dashed border + tab
2186
175
  // overlay the chart, with their own nested swimlanes inside).
2187
176
  for (const r of model.includes)
2188
- parts.push(renderIncludeRegion(r, options, idPrefix, palette, fonts));
177
+ parts.push(renderIncludeRegion(r, options, idPrefix, palette, fonts, model));
2189
178
 
2190
- // Normal / overflow dependency edges on top of items but below
2191
- // cut-lines / nowline. Under-bar edges already painted above.
2192
- for (const e of model.edges) {
2193
- if (e.kind !== 'underBar') parts.push(renderEdge(e, palette));
2194
- }
179
+ // Wave crossings over the main lanes' background bars.
180
+ parts.push(renderWaveCrossings(model.waveCrossings));
2195
181
 
2196
182
  // Anchor + milestone cut lines drawn AFTER items so they overlay the
2197
183
  // swimlane fills.
2198
184
  for (const a of model.anchors) parts.push(renderAnchorCutLine(a, palette));
2199
- for (const m of model.milestones) parts.push(renderMilestoneCutLine(m, palette));
185
+ for (const m of model.milestones) parts.push(renderMilestoneCutLine(m, idPrefix, palette));
186
+
187
+ // Titled non-working runs: their marker-row labels, and under `hide`
188
+ // the named cut lines, over the bars like the milestone cut lines.
189
+ parts.push(renderNonWorkingLabels(model.timeline, palette, fonts));
2200
190
 
2201
191
  // Marker-row diamonds + labels.
2202
192
  for (const a of model.anchors) parts.push(renderAnchor(a, palette, fonts));
@@ -2207,19 +197,17 @@ export async function renderSvg(
2207
197
 
2208
198
  // Footnotes + header last (always on top)
2209
199
  parts.push(renderFootnotes(model.footnotes, idPrefix, palette, fonts));
200
+ parts.push(renderWaveLegend(model.waveLegend, idPrefix, palette, fonts));
2210
201
  parts.push(renderHeader(model.header, idPrefix, palette, fonts));
2211
202
  parts.push(renderAttributionMark(model, fonts));
2212
203
 
2213
204
  // Logo (if header carries one)
2214
- if (model.header.logo && options.assetResolver) {
205
+ if (model.header.logo && (options.logo || options.assetResolver)) {
2215
206
  const logoSvg = await embedLogo(
2216
- model.header.logo.assetRef ?? '',
207
+ model.header.logo,
2217
208
  options.assetResolver,
2218
209
  idPrefix,
2219
210
  options,
2220
- model.header.logo.box.x,
2221
- model.header.logo.box.y,
2222
- Math.max(model.header.logo.box.width, model.header.logo.box.height),
2223
211
  );
2224
212
  if (logoSvg) parts.push(logoSvg);
2225
213
  }
@@ -2243,7 +231,3 @@ export const __internal = {
2243
231
  renderHeader,
2244
232
  renderEdge,
2245
233
  };
2246
-
2247
- // These helpers are kept in the exports table so tsc doesn't prune them.
2248
- void escAttr;
2249
- void escText;