@diagrammo/dgmo 0.47.0 → 0.48.1

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 (345) hide show
  1. package/dist/advanced.js +11 -11
  2. package/dist/auto.js +16 -16
  3. package/dist/auto.mjs +41 -12
  4. package/dist/block.js +4 -4
  5. package/dist/{chunk-FNB3PNGF.js → chunk-7DTWEFUE.js} +3 -3
  6. package/dist/{chunk-2DXMZRWJ.js → chunk-B65G5DNL.js} +8 -1
  7. package/dist/{chunk-RZCF2VVM.js → chunk-B7JUCQUA.js} +3 -1
  8. package/dist/{chunk-DU7W62N5.js → chunk-FANX6UJR.js} +3 -3
  9. package/dist/{chunk-6FZYCKXB.js → chunk-HSH73DP6.js} +2 -2
  10. package/dist/{chunk-P4RH4OSP.js → chunk-ILKORZ3H.js} +2 -2
  11. package/dist/{chunk-Y5QGVTVC.js → chunk-JTSMEYIZ.js} +7 -3
  12. package/dist/{chunk-RCERWOJR.js → chunk-ODZVHU3R.js} +1 -2
  13. package/dist/{chunk-DZAQBW35.js → chunk-SGZYXELT.js} +3 -7
  14. package/dist/{chunk-CUVHQHZ7.js → chunk-THXCFRTU.js} +3 -3
  15. package/dist/{chunk-IH6ZMVQ5.js → chunk-UC7TFHUM.js} +29 -11
  16. package/dist/{chunk-EMS2SK26.js → chunk-ZBWMSD5N.js} +3 -1
  17. package/dist/cli.cjs +15 -15
  18. package/dist/{dgmo-router-DZCIDUO5.js → dgmo-router-X35VLZLM.js} +3 -3
  19. package/dist/element.js +16 -16
  20. package/dist/element.mjs +41 -12
  21. package/dist/{flowchart-renderer-ZAEOL4DX.js → flowchart-renderer-SNDSII4D.js} +2 -2
  22. package/dist/index.d.ts +4 -2
  23. package/dist/index.js +4 -4
  24. package/dist/{parser-FUSKFGZN.js → parser-2EWECDSA.js} +2 -2
  25. package/dist/{renderer-UWA5XS74.js → renderer-4JHRUBE6.js} +3 -3
  26. package/dist/{renderer-WZRREQ2P.js → renderer-5MYBMBYO.js} +2 -2
  27. package/dist/{renderer-TOCOVLHS.js → renderer-B2OMQIQG.js} +3 -3
  28. package/dist/{renderer-2XQQQ6QR.js → renderer-N43WR5GV.js} +3 -3
  29. package/dist/{renderer-T7YKC5VP.js → renderer-ZRNG54CW.js} +3 -3
  30. package/dist/{state-renderer-RFYHSP4K.js → state-renderer-B4DQBM6M.js} +2 -2
  31. package/package.json +23 -71
  32. package/dist/advanced.cjs +0 -71648
  33. package/dist/advanced.d.cts +0 -5719
  34. package/dist/auto.cjs +0 -70648
  35. package/dist/auto.d.cts +0 -54
  36. package/dist/block.cjs +0 -70208
  37. package/dist/block.d.cts +0 -115
  38. package/dist/editor.cjs +0 -526
  39. package/dist/editor.d.cts +0 -26
  40. package/dist/element.cjs +0 -70530
  41. package/dist/element.d.cts +0 -62
  42. package/dist/highlight.cjs +0 -852
  43. package/dist/highlight.d.cts +0 -49
  44. package/dist/index.cjs +0 -70491
  45. package/dist/index.d.cts +0 -160
  46. package/dist/pert.cjs +0 -325
  47. package/dist/pert.d.cts +0 -559
  48. package/dist/themes-1-CuKpeH.d.cts +0 -908
  49. package/src/advanced.ts +0 -873
  50. package/src/arc/parser.ts +0 -15
  51. package/src/arc/renderer.ts +0 -633
  52. package/src/auto/index.ts +0 -621
  53. package/src/auto/shared.ts +0 -370
  54. package/src/auto/styles.ts +0 -73
  55. package/src/block/layout.ts +0 -198
  56. package/src/block/parser.ts +0 -427
  57. package/src/block/renderer.ts +0 -484
  58. package/src/block/types.ts +0 -67
  59. package/src/boxes-and-lines/collapse.ts +0 -96
  60. package/src/boxes-and-lines/focus.ts +0 -257
  61. package/src/boxes-and-lines/label-placement.ts +0 -339
  62. package/src/boxes-and-lines/layout-grouped.ts +0 -912
  63. package/src/boxes-and-lines/layout-layered.ts +0 -722
  64. package/src/boxes-and-lines/layout-search.ts +0 -1678
  65. package/src/boxes-and-lines/layout.ts +0 -398
  66. package/src/boxes-and-lines/parser.ts +0 -1181
  67. package/src/boxes-and-lines/renderer.ts +0 -1465
  68. package/src/boxes-and-lines/types.ts +0 -66
  69. package/src/c4/layout.ts +0 -2441
  70. package/src/c4/parser.ts +0 -1158
  71. package/src/c4/renderer.ts +0 -2008
  72. package/src/c4/types.ts +0 -89
  73. package/src/chart-type-registry.ts +0 -529
  74. package/src/chart-types.ts +0 -225
  75. package/src/chart.ts +0 -685
  76. package/src/charts-d3/bar.ts +0 -338
  77. package/src/charts-d3/chord.ts +0 -140
  78. package/src/charts-d3/function.ts +0 -147
  79. package/src/charts-d3/funnel.ts +0 -104
  80. package/src/charts-d3/heatmap.ts +0 -145
  81. package/src/charts-d3/index.ts +0 -337
  82. package/src/charts-d3/interactions.ts +0 -477
  83. package/src/charts-d3/line.ts +0 -344
  84. package/src/charts-d3/mount.ts +0 -151
  85. package/src/charts-d3/pie.ts +0 -117
  86. package/src/charts-d3/polar.ts +0 -89
  87. package/src/charts-d3/radar.ts +0 -0
  88. package/src/charts-d3/sankey.ts +0 -0
  89. package/src/charts-d3/scatter.ts +0 -185
  90. package/src/charts-d3/shared.ts +0 -208
  91. package/src/class/layout.ts +0 -326
  92. package/src/class/parser.ts +0 -635
  93. package/src/class/renderer.ts +0 -793
  94. package/src/class/types.ts +0 -58
  95. package/src/cli-banner.ts +0 -106
  96. package/src/cli.ts +0 -1080
  97. package/src/colors-diagnostics.ts +0 -35
  98. package/src/colors.ts +0 -379
  99. package/src/completion-types.ts +0 -27
  100. package/src/completion.ts +0 -2668
  101. package/src/cycle/layout.ts +0 -1026
  102. package/src/cycle/parser.ts +0 -387
  103. package/src/cycle/renderer.ts +0 -653
  104. package/src/cycle/types.ts +0 -101
  105. package/src/d3.ts +0 -1434
  106. package/src/data-chart-parser.ts +0 -1007
  107. package/src/dgmo-router.ts +0 -296
  108. package/src/diagnostics-registry.ts +0 -108
  109. package/src/diagnostics.ts +0 -0
  110. package/src/dimensions.ts +0 -20
  111. package/src/directives-registry.ts +0 -396
  112. package/src/editor/dgmo.grammar +0 -76
  113. package/src/editor/dgmo.grammar.d.ts +0 -2
  114. package/src/editor/dgmo.grammar.js +0 -18
  115. package/src/editor/dgmo.grammar.terms.d.ts +0 -5
  116. package/src/editor/dgmo.grammar.terms.js +0 -35
  117. package/src/editor/highlight-api.ts +0 -596
  118. package/src/editor/highlight.ts +0 -36
  119. package/src/editor/index.ts +0 -27
  120. package/src/editor/keywords.ts +0 -128
  121. package/src/editor/tokens.ts +0 -30
  122. package/src/element/index.ts +0 -432
  123. package/src/embed/css.ts +0 -312
  124. package/src/embed/escape.ts +0 -15
  125. package/src/embed/index.ts +0 -280
  126. package/src/er/classify.ts +0 -228
  127. package/src/er/layout.ts +0 -530
  128. package/src/er/parser.ts +0 -750
  129. package/src/er/renderer.ts +0 -725
  130. package/src/er/types.ts +0 -52
  131. package/src/error-card.ts +0 -269
  132. package/src/event-line/diagnostics.ts +0 -117
  133. package/src/event-line/parser.ts +0 -643
  134. package/src/event-line/renderer.ts +0 -1742
  135. package/src/event-line/types.ts +0 -74
  136. package/src/fonts.ts +0 -3
  137. package/src/gantt/calculator.ts +0 -979
  138. package/src/gantt/parser.ts +0 -1641
  139. package/src/gantt/renderer.ts +0 -3787
  140. package/src/gantt/resolver.ts +0 -172
  141. package/src/gantt/types.ts +0 -206
  142. package/src/graph/diagnostics.ts +0 -64
  143. package/src/graph/edge-spline.ts +0 -29
  144. package/src/graph/flowchart-parser.ts +0 -759
  145. package/src/graph/flowchart-renderer.ts +0 -817
  146. package/src/graph/layout.ts +0 -472
  147. package/src/graph/notes.ts +0 -21
  148. package/src/graph/state-collapse.ts +0 -78
  149. package/src/graph/state-parser.ts +0 -574
  150. package/src/graph/state-renderer.ts +0 -653
  151. package/src/graph/types.ts +0 -65
  152. package/src/index.ts +0 -261
  153. package/src/infra/compute.ts +0 -1385
  154. package/src/infra/layout.ts +0 -888
  155. package/src/infra/parser.ts +0 -1234
  156. package/src/infra/renderer.ts +0 -2534
  157. package/src/infra/roles.ts +0 -75
  158. package/src/infra/types.ts +0 -216
  159. package/src/infra/validation.ts +0 -201
  160. package/src/journey-map/layout.ts +0 -490
  161. package/src/journey-map/parser.ts +0 -557
  162. package/src/journey-map/renderer.ts +0 -1580
  163. package/src/journey-map/types.ts +0 -47
  164. package/src/kanban/mutations.ts +0 -175
  165. package/src/kanban/parser.ts +0 -509
  166. package/src/kanban/renderer.ts +0 -1449
  167. package/src/kanban/types.ts +0 -39
  168. package/src/label-layout.ts +0 -368
  169. package/src/map/colorize.ts +0 -54
  170. package/src/map/completion.ts +0 -316
  171. package/src/map/context-labels.ts +0 -609
  172. package/src/map/data/PROVENANCE.json +0 -1
  173. package/src/map/data/README.md +0 -40
  174. package/src/map/data/airport-collisions.json +0 -1
  175. package/src/map/data/airports.json +0 -1
  176. package/src/map/data/gazetteer.json +0 -1
  177. package/src/map/data/lakes.json +0 -1
  178. package/src/map/data/mountain-ranges.json +0 -1
  179. package/src/map/data/na-lakes.json +0 -1
  180. package/src/map/data/na-land.json +0 -1
  181. package/src/map/data/region-names.json +0 -1
  182. package/src/map/data/rivers.json +0 -1
  183. package/src/map/data/types.ts +0 -121
  184. package/src/map/data/us-states.json +0 -1
  185. package/src/map/data/water-bodies.json +0 -1
  186. package/src/map/data/world-coarse.json +0 -1
  187. package/src/map/data/world-detail.json +0 -1
  188. package/src/map/diagnostics.ts +0 -134
  189. package/src/map/dimensions.ts +0 -150
  190. package/src/map/geo-query.ts +0 -295
  191. package/src/map/geo.ts +0 -438
  192. package/src/map/invert.ts +0 -111
  193. package/src/map/layout.ts +0 -5069
  194. package/src/map/legend-band.ts +0 -127
  195. package/src/map/load-data.ts +0 -186
  196. package/src/map/parser.ts +0 -783
  197. package/src/map/renderer.ts +0 -1445
  198. package/src/map/resolved-types.ts +0 -160
  199. package/src/map/resolver.ts +0 -1146
  200. package/src/map/types.ts +0 -194
  201. package/src/mindmap/collapse.ts +0 -67
  202. package/src/mindmap/layout.ts +0 -649
  203. package/src/mindmap/parser.ts +0 -430
  204. package/src/mindmap/renderer.ts +0 -637
  205. package/src/mindmap/text-wrap.ts +0 -218
  206. package/src/mindmap/types.ts +0 -56
  207. package/src/org/collapse.ts +0 -151
  208. package/src/org/layout.ts +0 -1262
  209. package/src/org/parser.ts +0 -519
  210. package/src/org/renderer.ts +0 -866
  211. package/src/org/resolver.ts +0 -636
  212. package/src/palettes/atlas.ts +0 -77
  213. package/src/palettes/blueprint.ts +0 -73
  214. package/src/palettes/catppuccin.ts +0 -84
  215. package/src/palettes/color-utils.ts +0 -443
  216. package/src/palettes/index.ts +0 -67
  217. package/src/palettes/nord.ts +0 -67
  218. package/src/palettes/registry.ts +0 -114
  219. package/src/palettes/slate.ts +0 -73
  220. package/src/palettes/tidewater.ts +0 -73
  221. package/src/palettes/tokyo-night.ts +0 -86
  222. package/src/palettes/types.ts +0 -88
  223. package/src/pert/analyzer.ts +0 -1183
  224. package/src/pert/diagnostics.ts +0 -110
  225. package/src/pert/index.ts +0 -43
  226. package/src/pert/internal.ts +0 -252
  227. package/src/pert/layout.ts +0 -971
  228. package/src/pert/monte-carlo.ts +0 -446
  229. package/src/pert/parser.ts +0 -1606
  230. package/src/pert/renderer.ts +0 -4009
  231. package/src/pert/share-normalize.ts +0 -62
  232. package/src/pert/types.ts +0 -604
  233. package/src/pyramid/parser.ts +0 -185
  234. package/src/pyramid/renderer.ts +0 -768
  235. package/src/pyramid/types.ts +0 -28
  236. package/src/quadrant/parser.ts +0 -18
  237. package/src/quadrant/renderer.ts +0 -638
  238. package/src/raci/diagnostics.ts +0 -213
  239. package/src/raci/index.ts +0 -23
  240. package/src/raci/mutations.ts +0 -321
  241. package/src/raci/parser.ts +0 -699
  242. package/src/raci/renderer.ts +0 -1627
  243. package/src/raci/types.ts +0 -82
  244. package/src/raci/variants.ts +0 -320
  245. package/src/render.ts +0 -268
  246. package/src/ring/parser.ts +0 -212
  247. package/src/ring/renderer.ts +0 -490
  248. package/src/ring/types.ts +0 -27
  249. package/src/sequence/collapse.ts +0 -174
  250. package/src/sequence/parser.ts +0 -1596
  251. package/src/sequence/participant-inference.ts +0 -152
  252. package/src/sequence/renderer.ts +0 -3168
  253. package/src/sequence/tag-resolution.ts +0 -164
  254. package/src/sharing.ts +0 -211
  255. package/src/sitemap/collapse.ts +0 -100
  256. package/src/sitemap/layout.ts +0 -925
  257. package/src/sitemap/parser.ts +0 -755
  258. package/src/sitemap/renderer.ts +0 -828
  259. package/src/sitemap/types.ts +0 -42
  260. package/src/slope/parser.ts +0 -18
  261. package/src/slope/renderer.ts +0 -378
  262. package/src/swimlane/diagnostics.ts +0 -94
  263. package/src/swimlane/layout.ts +0 -597
  264. package/src/swimlane/parser.ts +0 -613
  265. package/src/swimlane/renderer.ts +0 -681
  266. package/src/swimlane/types.ts +0 -151
  267. package/src/tech-radar/interactive.ts +0 -1129
  268. package/src/tech-radar/layout.ts +0 -197
  269. package/src/tech-radar/parser.ts +0 -436
  270. package/src/tech-radar/renderer.ts +0 -1239
  271. package/src/tech-radar/shared.ts +0 -151
  272. package/src/tech-radar/types.ts +0 -86
  273. package/src/themes.ts +0 -22
  274. package/src/timeline/parser.ts +0 -472
  275. package/src/timeline/renderer.ts +0 -3024
  276. package/src/timeline/types.ts +0 -33
  277. package/src/timeline/viz-parser.ts +0 -21
  278. package/src/treemap/diagnostics.ts +0 -62
  279. package/src/treemap/layout-radial.ts +0 -233
  280. package/src/treemap/layout.ts +0 -189
  281. package/src/treemap/parser.ts +0 -463
  282. package/src/treemap/renderer-radial.ts +0 -438
  283. package/src/treemap/renderer.ts +0 -572
  284. package/src/treemap/treemap-shared.ts +0 -309
  285. package/src/treemap/types.ts +0 -60
  286. package/src/utils/arrow-markers.ts +0 -51
  287. package/src/utils/arrows-diagnostics.ts +0 -62
  288. package/src/utils/arrows.ts +0 -227
  289. package/src/utils/brand.ts +0 -61
  290. package/src/utils/card.ts +0 -183
  291. package/src/utils/collapse-engine/tree-edges.ts +0 -115
  292. package/src/utils/collapse-engine/tree.ts +0 -117
  293. package/src/utils/d3-helpers.ts +0 -219
  294. package/src/utils/d3-types.ts +0 -9
  295. package/src/utils/description-helpers.ts +0 -38
  296. package/src/utils/duration.ts +0 -312
  297. package/src/utils/export-container.ts +0 -41
  298. package/src/utils/expr-eval.ts +0 -27
  299. package/src/utils/fit-canvas.ts +0 -64
  300. package/src/utils/hover-styles.ts +0 -673
  301. package/src/utils/inline-markdown.ts +0 -96
  302. package/src/utils/legend-constants.ts +0 -48
  303. package/src/utils/legend-d3.ts +0 -618
  304. package/src/utils/legend-integration.ts +0 -107
  305. package/src/utils/legend-layout.ts +0 -776
  306. package/src/utils/legend-svg.ts +0 -214
  307. package/src/utils/legend-types.ts +0 -272
  308. package/src/utils/name-normalize.ts +0 -163
  309. package/src/utils/note-box/constants.ts +0 -25
  310. package/src/utils/note-box/index.ts +0 -11
  311. package/src/utils/note-box/metrics.ts +0 -90
  312. package/src/utils/note-box/svg.ts +0 -331
  313. package/src/utils/notes/bounds.ts +0 -30
  314. package/src/utils/notes/build.ts +0 -131
  315. package/src/utils/notes/index.ts +0 -18
  316. package/src/utils/notes/model.ts +0 -19
  317. package/src/utils/notes/parse.ts +0 -131
  318. package/src/utils/notes/place.ts +0 -177
  319. package/src/utils/notes/resolve.ts +0 -88
  320. package/src/utils/number-format.ts +0 -36
  321. package/src/utils/parsing.ts +0 -953
  322. package/src/utils/reserved-key-registry.ts +0 -239
  323. package/src/utils/safe-href.ts +0 -38
  324. package/src/utils/scaling.ts +0 -97
  325. package/src/utils/svg-embed.ts +0 -251
  326. package/src/utils/tag-groups.ts +0 -607
  327. package/src/utils/text-measure.ts +0 -122
  328. package/src/utils/time-ticks.ts +0 -253
  329. package/src/utils/title-constants.ts +0 -24
  330. package/src/utils/visual-conventions.ts +0 -61
  331. package/src/utils/wrapped-desc.ts +0 -87
  332. package/src/venn/parser.ts +0 -18
  333. package/src/venn/renderer.ts +0 -1047
  334. package/src/version-control/diagnostics.ts +0 -67
  335. package/src/version-control/parser.ts +0 -544
  336. package/src/version-control/renderer.ts +0 -724
  337. package/src/version-control/types.ts +0 -100
  338. package/src/visualizations/parse.ts +0 -1560
  339. package/src/visualizations/types.ts +0 -262
  340. package/src/wireframe/layout.ts +0 -479
  341. package/src/wireframe/parser.ts +0 -1114
  342. package/src/wireframe/renderer.ts +0 -1318
  343. package/src/wireframe/types.ts +0 -110
  344. package/src/wordcloud/parser.ts +0 -18
  345. package/src/wordcloud/renderer.ts +0 -357
@@ -1,1580 +0,0 @@
1
- import { tagAttrKey } from '../utils/tag-groups';
2
- import * as d3 from 'd3-selection';
3
- import * as d3Shape from 'd3-shape';
4
- import type { PaletteColors } from '../palettes';
5
- import { contrastText, mix, shapeFill } from '../palettes/color-utils';
6
- import { FONT_FAMILY } from '../fonts';
7
- import { parseJourneyMap } from './parser';
8
- import {
9
- layoutJourneyMap,
10
- scoreToColor,
11
- scoreToCurveY,
12
- TAG_STRIP_HEIGHT,
13
- type CurvePoint,
14
- type StepLayout,
15
- } from './layout';
16
- import type {
17
- ParsedJourneyMap,
18
- JourneyMapAnnotation,
19
- JourneyMapStep,
20
- } from './types';
21
- import { renderInlineText } from '../utils/inline-markdown';
22
- import { wrapNoteBody, NOTE_BULLET_INDENT } from '../utils/note-box';
23
- import { renderIntegratedLegend } from '../utils/legend-integration';
24
- import { resolveActiveTagGroup } from '../utils/tag-groups';
25
- import { ScaleContext } from '../utils/scaling';
26
- import {
27
- measureText,
28
- wrapTextToWidth,
29
- truncateText as truncateToWidth,
30
- } from '../utils/text-measure';
31
-
32
- // ============================================================
33
- // Interactive Options
34
- // ============================================================
35
-
36
- export interface JourneyMapInteractiveOptions {
37
- onNavigateToLine?: (line: number) => void;
38
- exportDims?: { width: number; height: number };
39
- activeTagGroup?: string | null;
40
- onActiveTagGroupChange?: (group: string | null) => void;
41
- /** Current editor cursor line — highlights the matching face + card, dims the rest */
42
- currentLine?: number | null;
43
- /** Set of collapsed phase names */
44
- collapsedPhases?: Set<string>;
45
- /** Called when a phase is toggled */
46
- onPhaseToggle?: (phaseName: string) => void;
47
- exportMode?: boolean;
48
- }
49
-
50
- // ============================================================
51
- // Constants
52
- // ============================================================
53
-
54
- // Match kanban styling constants
55
- const DIAGRAM_PADDING = 20;
56
- const PADDING = DIAGRAM_PADDING;
57
- import { CARD_RADIUS } from '../utils/visual-conventions'; // shared (Story 111.1)
58
- const CARD_PADDING_X = 10;
59
- const CARD_PADDING_Y = 6;
60
- const CARD_HEADER_HEIGHT = 24;
61
- const CARD_STROKE_WIDTH = 1.5;
62
- const CARD_META_LINE_HEIGHT = 14;
63
- const CARD_GAP_INTERNAL = 8;
64
- const COLUMN_RADIUS = 8;
65
- const COLUMN_HEADER_HEIGHT = 36;
66
- const COLUMN_PADDING = 12;
67
- const FONT_SIZE_TITLE = 18;
68
- const FONT_SIZE_PHASE = 13;
69
- const FONT_SIZE_STEP = 12;
70
- const FONT_SIZE_META = 10;
71
- const GRID_LINE_OPACITY = 0.15;
72
- const CURVE_STROKE_WIDTH = 2.5;
73
- const FACE_RADIUS = 14;
74
- // Distance from curveAreaBottom down to the filled band's bottom edge/border.
75
- // The score-1 face sits ~10px above curveAreaBottom; its emotion caption hangs
76
- // FACE_RADIUS + 5 + label-height (~29px) below the face center, so the band
77
- // must drop far enough that the caption clears the bottom border.
78
- const CURVE_AREA_BOTTOM_GAP = 28;
79
- // Faces grow on hover/active; the thought bubble + connector must clear the
80
- // enlarged outer edge (radius + ring halo), not the base radius.
81
- const FACE_HOVER_SCALE = 1.5;
82
- const FACE_HOVER_R = (FACE_RADIUS + 1) * FACE_HOVER_SCALE;
83
- const DIM_HOVER = 0.25;
84
- const TITLE_LINE_HEIGHT = 16;
85
-
86
- // ============================================================
87
- // Renderer
88
- // ============================================================
89
-
90
- export function renderJourneyMap(
91
- container: HTMLElement,
92
- parsed: ParsedJourneyMap,
93
- palette: PaletteColors,
94
- isDark: boolean,
95
- options?: JourneyMapInteractiveOptions
96
- ): void {
97
- const exportDims = options?.exportDims;
98
- const onNavigateToLine = options?.onNavigateToLine;
99
- const activeTagGroup = options?.activeTagGroup ?? null;
100
- const onActiveTagGroupChange = options?.onActiveTagGroupChange;
101
- const collapsedPhases = options?.collapsedPhases ?? new Set<string>();
102
- const onPhaseToggle = options?.onPhaseToggle;
103
- const solid = parsed.options['solid-fill'] === 'on';
104
-
105
- const layout = layoutJourneyMap(parsed, palette, {
106
- collapsedPhases,
107
- ...(exportDims !== undefined && { exportDims }),
108
- isDark,
109
- });
110
-
111
- container.innerHTML = '';
112
-
113
- const containerW = exportDims?.width ?? container.clientWidth;
114
- const containerH = exportDims?.height ?? container.clientHeight;
115
- const useContainerFit = !exportDims && containerW > 0 && containerH > 0;
116
-
117
- const sctx = exportDims
118
- ? ScaleContext.identity()
119
- : ScaleContext.from(containerW, layout.totalWidth);
120
-
121
- const svg = d3
122
- .select(container)
123
- .append('svg')
124
- .attr('xmlns', 'http://www.w3.org/2000/svg')
125
- .attr(
126
- 'width',
127
- useContainerFit ? containerW : (exportDims?.width ?? layout.totalWidth)
128
- )
129
- .attr(
130
- 'height',
131
- useContainerFit ? containerH : (exportDims?.height ?? layout.totalHeight)
132
- )
133
- .attr('viewBox', `0 0 ${layout.totalWidth} ${layout.totalHeight}`)
134
- .attr('preserveAspectRatio', 'xMidYMin meet')
135
- .attr('font-family', FONT_FAMILY);
136
-
137
- if (sctx.isBelowFloor) {
138
- svg.attr('width', '100%');
139
- }
140
-
141
- // Background
142
- svg
143
- .append('rect')
144
- .attr('width', layout.totalWidth)
145
- .attr('height', layout.totalHeight)
146
- .attr('fill', palette.bg);
147
-
148
- // Defs for gradients
149
- const defs = svg.append('defs');
150
-
151
- // Curve area gradient (green top, red bottom)
152
- const curveGradient = defs
153
- .append('linearGradient')
154
- .attr('id', 'journey-curve-gradient')
155
- .attr('x1', '0')
156
- .attr('y1', '0')
157
- .attr('x2', '0')
158
- .attr('y2', '1');
159
- curveGradient
160
- .append('stop')
161
- .attr('offset', '0%')
162
- .attr('stop-color', palette.colors.green)
163
- .attr('stop-opacity', 0.3);
164
- curveGradient
165
- .append('stop')
166
- .attr('offset', '100%')
167
- .attr('stop-color', palette.colors.red)
168
- .attr('stop-opacity', 0.3);
169
-
170
- // ── Title ────────────────────────────────────────────────
171
- const showTitle = !!parsed.title && parsed.options['no-title'] !== 'on';
172
- if (showTitle) {
173
- const titleG = svg.append('g').attr('class', 'chart-title');
174
- if (parsed.titleLineNumber) {
175
- titleG.attr('data-line-number', parsed.titleLineNumber);
176
- }
177
- titleG
178
- .append('text')
179
- .attr('x', PADDING)
180
- .attr('y', PADDING + FONT_SIZE_TITLE)
181
- .attr('font-size', FONT_SIZE_TITLE)
182
- .attr('font-weight', 'bold')
183
- .attr('fill', palette.text)
184
- .text(parsed.title!);
185
-
186
- if (onNavigateToLine && parsed.titleLineNumber) {
187
- titleG.style('cursor', 'pointer').on('click', () => {
188
- onNavigateToLine(parsed.titleLineNumber!);
189
- });
190
- }
191
- }
192
-
193
- // ── Persona ──────────────────────────────────────────────
194
- if (parsed.persona) {
195
- const personaColor = parsed.persona.color ?? palette.textMuted;
196
- const personaG = svg
197
- .append('g')
198
- .attr('class', 'journey-persona')
199
- .attr('data-line-number', parsed.persona.lineNumber);
200
-
201
- // Panel dimensions
202
- const titleRowH = CARD_HEADER_HEIGHT;
203
- const silhouetteZone = 60; // right-side space reserved for silhouette
204
- const panelWidth = 280;
205
- const textAreaWidth = panelWidth - silhouetteZone - CARD_PADDING_X;
206
- const descLineH = 14;
207
-
208
- // Wrap description text into lines — bullet-aware (`- `/`* ` → hanging
209
- // "•") + inline markdown, matching how note boxes render rich bodies.
210
- const descLines = parsed.persona.description
211
- ? wrapNoteBody(parsed.persona.description, textAreaWidth, FONT_SIZE_META)
212
- : [];
213
- const descRowH =
214
- descLines.length > 0 ? descLines.length * descLineH + 8 : 0;
215
- const panelHeight = titleRowH + descRowH;
216
- const panelX = layout.totalWidth - PADDING - panelWidth;
217
- const panelY = PADDING;
218
- const textX = panelX + CARD_PADDING_X;
219
-
220
- // Clip path so silhouette stays inside the card
221
- const clipId = 'persona-clip';
222
- defs
223
- .append('clipPath')
224
- .attr('id', clipId)
225
- .append('rect')
226
- .attr('x', panelX)
227
- .attr('y', panelY)
228
- .attr('width', panelWidth)
229
- .attr('height', panelHeight)
230
- .attr('rx', CARD_RADIUS);
231
-
232
- // Card — canonical 25% tint via shapeFill() (or full intent when solid-fill is on)
233
- const personaFill = shapeFill(palette, personaColor, isDark, { solid });
234
- // Text drawn on top of the card must contrast against the fill, not against bg/surface.
235
- const onPersonaText = contrastText(
236
- personaFill,
237
- palette.textOnFillLight,
238
- palette.textOnFillDark
239
- );
240
-
241
- personaG
242
- .append('rect')
243
- .attr('x', panelX)
244
- .attr('y', panelY)
245
- .attr('width', panelWidth)
246
- .attr('height', panelHeight)
247
- .attr('rx', CARD_RADIUS)
248
- .attr('fill', personaFill);
249
-
250
- // Divider line (drawn BEFORE silhouette so it doesn't cut through)
251
- if (descLines.length > 0) {
252
- personaG
253
- .append('line')
254
- .attr('x1', panelX + 1)
255
- .attr('x2', panelX + panelWidth - silhouetteZone)
256
- .attr('y1', panelY + titleRowH)
257
- .attr('y2', panelY + titleRowH)
258
- .attr('stroke', solid ? onPersonaText : personaColor)
259
- .attr('stroke-opacity', 0.3)
260
- .attr('stroke-width', 1);
261
- }
262
-
263
- // Silhouette (clipped inside card, more right padding, taller)
264
- const silX = panelX + panelWidth - 32;
265
- const silY = panelY + panelHeight / 2 - 6;
266
- const silClip = personaG.append('g').attr('clip-path', `url(#${clipId})`);
267
- renderPersonaSilhouette(silClip, silX, silY, personaColor, palette, 1.2);
268
-
269
- // Card border (drawn on top so outline is clean all around)
270
- personaG
271
- .append('rect')
272
- .attr('x', panelX)
273
- .attr('y', panelY)
274
- .attr('width', panelWidth)
275
- .attr('height', panelHeight)
276
- .attr('rx', CARD_RADIUS)
277
- .attr('fill', 'none')
278
- .attr('stroke', personaColor)
279
- .attr('stroke-width', CARD_STROKE_WIDTH);
280
-
281
- // Name (left-aligned in title row, matches kanban card title)
282
- personaG
283
- .append('text')
284
- .attr('x', textX)
285
- .attr('y', panelY + CARD_PADDING_Y + FONT_SIZE_STEP)
286
- .attr('font-size', FONT_SIZE_STEP)
287
- .attr('font-weight', '500')
288
- .attr('fill', onPersonaText)
289
- .text(parsed.persona.name);
290
-
291
- // Description — wrapped lines below divider, with inline markdown.
292
- // Bullet first-lines get a "•" glyph at the left edge with the body
293
- // hanging-indented; continuation lines align under the body.
294
- for (let li = 0; li < descLines.length; li++) {
295
- // In-bounds by loop guard.
296
- const line = descLines[li]!;
297
- const indent = line.kind === 'plain' ? 0 : NOTE_BULLET_INDENT;
298
- const lineY = panelY + titleRowH + descLineH * (li + 1);
299
- if (line.kind === 'bullet-first') {
300
- personaG
301
- .append('text')
302
- .attr('x', textX)
303
- .attr('y', lineY)
304
- .attr('font-size', FONT_SIZE_META)
305
- .attr('fill', onPersonaText)
306
- .text('•');
307
- }
308
- const lineEl = personaG
309
- .append('text')
310
- .attr('x', textX + indent)
311
- .attr('y', lineY)
312
- .attr('font-size', FONT_SIZE_META)
313
- .attr('fill', onPersonaText);
314
- renderInlineText(lineEl, line.text, palette, FONT_SIZE_META);
315
- }
316
-
317
- if (onNavigateToLine) {
318
- personaG.style('cursor', 'pointer').on('click', () => {
319
- onNavigateToLine(parsed.persona!.lineNumber);
320
- });
321
- }
322
- }
323
-
324
- // ── Score group + active group (shared by legend and card coloring) ──
325
- const scoreGroup = {
326
- name: 'Score',
327
- entries: [1, 2, 3, 4, 5].map((s) => ({
328
- value: String(s),
329
- color: scoreToColor(s, palette),
330
- lineNumber: 0,
331
- })),
332
- lineNumber: 0,
333
- };
334
- const allLegendGroups = [...parsed.tagGroups, scoreGroup];
335
- const effectiveActiveGroup =
336
- activeTagGroup ??
337
- resolveActiveTagGroup(allLegendGroups, parsed.options['active-tag']);
338
-
339
- // ── Legend ──────────────────────────────────────────────
340
- if (parsed.options['no-legend'] !== 'on') {
341
- const legendX = PADDING;
342
- const legendY = PADDING + (showTitle ? FONT_SIZE_TITLE + 8 : 0);
343
- const legendG = svg
344
- .append('g')
345
- .attr('class', 'journey-legend')
346
- .attr('transform', `translate(${legendX},${legendY})`);
347
-
348
- const legendCallbacks: import('../utils/legend-types').LegendCallbacks = {
349
- ...(onActiveTagGroupChange
350
- ? {
351
- onGroupToggle: (groupName: string) => {
352
- const isDeactivating =
353
- effectiveActiveGroup?.toLowerCase() === groupName.toLowerCase();
354
- onActiveTagGroupChange(isDeactivating ? null : groupName);
355
- },
356
- }
357
- : {}),
358
- ...(!exportDims
359
- ? {
360
- onEntryHover: (groupName: string, entryValue: string | null) => {
361
- if (!entryValue) {
362
- // Hover out — restore all
363
- svg.selectAll('.journey-step').style('opacity', null);
364
- svg.selectAll('.journey-face').style('opacity', null);
365
- svg.selectAll('.journey-face-icon').attr('transform', null);
366
- svg.selectAll('.journey-thought').style('opacity', null);
367
- return;
368
- }
369
-
370
- const isScore = groupName === 'Score';
371
- const attrName = isScore
372
- ? 'data-score'
373
- : `data-tag-${tagAttrKey(groupName)}`;
374
-
375
- const matches = (el: Element) =>
376
- el.getAttribute(attrName) === entryValue;
377
-
378
- svg
379
- .selectAll<SVGGElement, unknown>('.journey-step')
380
- .each(function () {
381
- const hit = matches(this);
382
- d3.select(this).style(
383
- 'opacity',
384
- hit ? '1' : String(DIM_HOVER)
385
- );
386
- });
387
-
388
- svg
389
- .selectAll<SVGGElement, unknown>('.journey-face')
390
- .each(function () {
391
- const hit = matches(this);
392
- const sel = d3.select(this);
393
- sel.style('opacity', hit ? '1' : String(DIM_HOVER));
394
- const icon = sel.select('.journey-face-icon');
395
- if (hit) {
396
- const fcx = parseFloat(sel.attr('data-cx') ?? '0');
397
- const fcy = parseFloat(sel.attr('data-cy') ?? '0');
398
- icon.attr(
399
- 'transform',
400
- `translate(${fcx},${fcy}) scale(1.3) translate(${-fcx},${-fcy})`
401
- );
402
- } else {
403
- icon.attr('transform', null);
404
- }
405
- });
406
-
407
- // Dim thought bubbles that aren't associated with matching faces
408
- svg
409
- .selectAll<SVGGElement, unknown>('.journey-thought')
410
- .style('opacity', String(DIM_HOVER));
411
- },
412
- }
413
- : {}),
414
- };
415
-
416
- renderIntegratedLegend(legendG, {
417
- groups: parsed.tagGroups,
418
- activeGroup: effectiveActiveGroup,
419
- mode: options?.exportMode ? 'export' : 'preview',
420
- position: { placement: 'top-center', titleRelation: 'inline-with-title' },
421
- titleWidth: 0,
422
- callbacks: legendCallbacks,
423
- palette,
424
- isDark,
425
- // Reduce available width if persona card exists to avoid collision
426
- width: parsed.persona
427
- ? layout.totalWidth - legendX - PADDING - 280 - PADDING
428
- : layout.totalWidth - legendX - PADDING,
429
- });
430
- }
431
-
432
- // ── Curve Area ───────────────────────────────────────────
433
- const curveG = svg.append('g').attr('class', 'journey-curve-area');
434
-
435
- // Grid lines at score levels 1-5
436
- for (let score = 1; score <= 5; score++) {
437
- const y = scoreToCurveY(score, layout.curveAreaBottom);
438
-
439
- curveG
440
- .append('line')
441
- .attr('x1', PADDING)
442
- .attr('x2', layout.totalWidth - PADDING)
443
- .attr('y1', y)
444
- .attr('y2', y)
445
- .attr('stroke', palette.textMuted)
446
- .attr('stroke-opacity', GRID_LINE_OPACITY)
447
- .attr('stroke-dasharray', '4,4');
448
- }
449
-
450
- // Emotion curve (area fill + line)
451
- if (layout.curvePoints.length >= 2) {
452
- // Extend curve to edges with flat continuations
453
- // In-bounds by length >= 2 check above.
454
- const first = layout.curvePoints[0]!;
455
- const last = layout.curvePoints[layout.curvePoints.length - 1]!;
456
- const extendedPoints: CurvePoint[] = [
457
- {
458
- x: PADDING,
459
- y: first.y,
460
- score: first.score,
461
- stepIndex: first.stepIndex,
462
- },
463
- ...layout.curvePoints,
464
- {
465
- x: layout.totalWidth - PADDING,
466
- y: last.y,
467
- score: last.score,
468
- stepIndex: last.stepIndex,
469
- },
470
- ];
471
-
472
- // Bottom of the filled band. Sits clear of the lowest face's emotion
473
- // caption (score-1 face + FACE_RADIUS + EMOTION_LABEL gap) so the caption
474
- // doesn't collide with the bottom border.
475
- const areaBottomY = layout.curveAreaBottom + CURVE_AREA_BOTTOM_GAP;
476
-
477
- const areaGen = d3Shape
478
- .area<CurvePoint>()
479
- .x((d) => d.x)
480
- .y0(areaBottomY)
481
- .y1((d) => d.y)
482
- .curve(d3Shape.curveMonotoneX);
483
-
484
- curveG
485
- .append('path')
486
- .attr('d', areaGen(extendedPoints) ?? '')
487
- .attr('fill', 'url(#journey-curve-gradient)')
488
- .attr('stroke', 'none');
489
-
490
- // Frame the filled area on three sides (left, bottom, right) — the curve
491
- // line itself forms the top edge. Polishes the plot into a contained box.
492
- const leftX = PADDING;
493
- const rightX = layout.totalWidth - PADDING;
494
- curveG
495
- .append('path')
496
- .attr(
497
- 'd',
498
- `M${leftX},${first.y} L${leftX},${areaBottomY} ` +
499
- `L${rightX},${areaBottomY} L${rightX},${last.y}`
500
- )
501
- .attr('fill', 'none')
502
- .attr('stroke', palette.primary)
503
- .attr('stroke-width', CURVE_STROKE_WIDTH)
504
- .attr('stroke-linecap', 'round')
505
- .attr('stroke-linejoin', 'round');
506
-
507
- // Curve line on top
508
- const lineGen = d3Shape
509
- .line<CurvePoint>()
510
- .x((d) => d.x)
511
- .y((d) => d.y)
512
- .curve(d3Shape.curveMonotoneX);
513
-
514
- curveG
515
- .append('path')
516
- .attr('d', lineGen(extendedPoints) ?? '')
517
- .attr('fill', 'none')
518
- .attr('stroke', palette.primary)
519
- .attr('stroke-width', CURVE_STROKE_WIDTH)
520
- .attr('stroke-linecap', 'round');
521
-
522
- // Curve face icons (clickable → navigate to step line)
523
- const allSteps =
524
- parsed.phases.length > 0
525
- ? parsed.phases.flatMap((p) => p.steps)
526
- : parsed.steps;
527
-
528
- for (const pt of layout.curvePoints) {
529
- const step = allSteps[pt.stepIndex];
530
- const faceG = renderScoreFace(
531
- curveG,
532
- pt.x,
533
- pt.y,
534
- pt.score,
535
- palette,
536
- isDark
537
- );
538
- addEmotionLabel(faceG, pt, palette);
539
- if (step) {
540
- faceG.attr('data-line-number', step.lineNumber);
541
- faceG.attr('data-score', pt.score);
542
- for (const [key, value] of Object.entries(step.tags)) {
543
- faceG.attr(`data-tag-${key.toLowerCase()}`, value);
544
- }
545
- // Store thought text for hover-to-reveal
546
- const thoughts = step.annotations.filter((a) => a.type === 'thought');
547
- if (thoughts.length > 0) {
548
- faceG.attr(
549
- 'data-thought',
550
- thoughts.map((t) => t.text).join(' \u2022 ')
551
- );
552
- }
553
- if (onNavigateToLine) {
554
- faceG.style('cursor', 'pointer').on('click', () => {
555
- onNavigateToLine(step.lineNumber);
556
- });
557
- }
558
- }
559
- }
560
- } else if (layout.curvePoints.length === 1) {
561
- // Single point — face only, no curve
562
- // In-bounds by length === 1 check above.
563
- const pt = layout.curvePoints[0]!;
564
- const allSteps =
565
- parsed.phases.length > 0
566
- ? parsed.phases.flatMap((p) => p.steps)
567
- : parsed.steps;
568
- const step = allSteps[pt.stepIndex];
569
- const faceG = renderScoreFace(
570
- curveG,
571
- pt.x,
572
- pt.y,
573
- pt.score,
574
- palette,
575
- isDark
576
- );
577
- addEmotionLabel(faceG, pt, palette);
578
- if (step) {
579
- faceG.attr('data-line-number', step.lineNumber);
580
- faceG.attr('data-score', pt.score);
581
- for (const [key, value] of Object.entries(step.tags)) {
582
- faceG.attr(`data-tag-${key.toLowerCase()}`, value);
583
- }
584
- const thoughts = step.annotations.filter((a) => a.type === 'thought');
585
- if (thoughts.length > 0) {
586
- faceG.attr(
587
- 'data-thought',
588
- thoughts.map((t) => t.text).join(' \u2022 ')
589
- );
590
- }
591
- if (onNavigateToLine) {
592
- faceG.style('cursor', 'pointer').on('click', () => {
593
- onNavigateToLine(step.lineNumber);
594
- });
595
- }
596
- }
597
- }
598
-
599
- // ── Phases + Cards ───────────────────────────────────────
600
- const phasesG = svg.append('g').attr('class', 'journey-phases');
601
-
602
- if (layout.phases.length > 0) {
603
- for (const pl of layout.phases) {
604
- const isCollapsed = collapsedPhases.has(pl.phase.name);
605
- const phaseG = phasesG
606
- .append('g')
607
- .attr('class', 'journey-phase')
608
- .attr('data-line-number', pl.phase.lineNumber);
609
-
610
- // Column background (no stroke — matches kanban)
611
- const colBg = isDark
612
- ? mix(palette.surface, palette.bg, 50)
613
- : mix(palette.surface, palette.bg, 30);
614
- phaseG
615
- .append('rect')
616
- .attr('x', pl.x)
617
- .attr('y', pl.y)
618
- .attr('width', pl.width)
619
- .attr('height', pl.height)
620
- .attr('rx', COLUMN_RADIUS)
621
- .attr('fill', colBg);
622
-
623
- // Column header (no stroke — matches kanban)
624
- phaseG
625
- .append('rect')
626
- .attr('x', pl.x)
627
- .attr('y', pl.y)
628
- .attr('width', pl.width)
629
- .attr('height', COLUMN_HEADER_HEIGHT)
630
- .attr('rx', COLUMN_RADIUS)
631
- .attr('fill', pl.headerColor);
632
-
633
- // Clip bottom corners of header
634
- phaseG
635
- .append('rect')
636
- .attr('x', pl.x)
637
- .attr('y', pl.y + COLUMN_HEADER_HEIGHT - COLUMN_RADIUS)
638
- .attr('width', pl.width)
639
- .attr('height', COLUMN_RADIUS)
640
- .attr('fill', pl.headerColor);
641
-
642
- // Column header text — must contrast against pl.headerColor, not bg.
643
- // (palette.text is dark in light themes, illegible on a saturated header.)
644
- const onHeaderText = contrastText(
645
- pl.headerColor,
646
- palette.textOnFillLight,
647
- palette.textOnFillDark
648
- );
649
- phaseG
650
- .append('text')
651
- .attr('x', pl.x + COLUMN_PADDING)
652
- .attr('y', pl.y + COLUMN_HEADER_HEIGHT / 2 + FONT_SIZE_PHASE / 2 - 2)
653
- .attr('font-size', FONT_SIZE_PHASE)
654
- .attr('font-weight', 'bold')
655
- .attr('fill', onHeaderText)
656
- .text(
657
- isCollapsed
658
- ? truncateText(
659
- pl.phase.name,
660
- pl.width - COLUMN_PADDING * 2,
661
- FONT_SIZE_PHASE
662
- )
663
- : pl.phase.name
664
- );
665
-
666
- // Click header to toggle collapse
667
- if (onPhaseToggle) {
668
- phaseG.style('cursor', 'pointer').on('click', (event: MouseEvent) => {
669
- const target = event.target as Element;
670
- if (
671
- !target.closest('.journey-step') &&
672
- !target.closest('.journey-face')
673
- ) {
674
- onPhaseToggle(pl.phase.name);
675
- }
676
- });
677
- } else if (onNavigateToLine) {
678
- phaseG.style('cursor', 'pointer').on('click', (event: MouseEvent) => {
679
- const target = event.target as Element;
680
- if (!target.closest('.journey-step')) {
681
- onNavigateToLine(pl.phase.lineNumber);
682
- }
683
- });
684
- }
685
-
686
- if (isCollapsed) {
687
- // Collapsed: mini card rows with colored border matching active tag
688
- const COLLAPSED_CARD_H = 26;
689
- const COLLAPSED_GAP = 6;
690
- const COLLAPSED_FACE_R = 7;
691
- const listX = pl.x + COLUMN_PADDING;
692
- const cardW = pl.width - COLUMN_PADDING * 2;
693
- let itemY = pl.y + COLUMN_HEADER_HEIGHT + CARD_GAP_INTERNAL + 4;
694
-
695
- for (const step of pl.phase.steps) {
696
- const itemG = phaseG
697
- .append('g')
698
- .attr('class', 'journey-step')
699
- .attr('data-line-number', step.lineNumber);
700
-
701
- // Data attributes for legend hover highlighting
702
- if (step.score !== undefined) {
703
- itemG.attr('data-score', step.score);
704
- }
705
- for (const [key, value] of Object.entries(step.tags)) {
706
- itemG.attr(`data-tag-${key.toLowerCase()}`, value);
707
- }
708
-
709
- // Resolve card color from active tag group
710
- const stepColor = resolveStepColor(
711
- step,
712
- step.score !== undefined
713
- ? scoreToColor(step.score, palette)
714
- : palette.surface,
715
- effectiveActiveGroup,
716
- parsed.tagGroups,
717
- palette
718
- );
719
- // Canonical 25% tint via shapeFill() (or full intent when solid-fill is on)
720
- const rowFill = shapeFill(
721
- palette,
722
- stepColor ?? palette.primary,
723
- isDark,
724
- { solid }
725
- );
726
- const rowStroke = stepColor ?? palette.textMuted;
727
-
728
- // Card background
729
- itemG
730
- .append('rect')
731
- .attr('x', listX)
732
- .attr('y', itemY)
733
- .attr('width', cardW)
734
- .attr('height', COLLAPSED_CARD_H)
735
- .attr('rx', CARD_RADIUS)
736
- .attr('fill', rowFill)
737
- .attr('stroke', rowStroke)
738
- .attr('stroke-width', CARD_STROKE_WIDTH);
739
-
740
- // Face icon (small, left side)
741
- const faceCx = listX + CARD_PADDING_X + COLLAPSED_FACE_R;
742
- const faceCy = itemY + COLLAPSED_CARD_H / 2;
743
- if (step.score !== undefined) {
744
- const faceG = renderScoreFace(
745
- itemG,
746
- faceCx,
747
- faceCy,
748
- step.score,
749
- palette,
750
- isDark,
751
- COLLAPSED_FACE_R
752
- );
753
- faceG.attr('data-line-number', step.lineNumber);
754
- faceG.attr('data-score', step.score);
755
- for (const [key, value] of Object.entries(step.tags)) {
756
- faceG.attr(`data-tag-${key.toLowerCase()}`, value);
757
- }
758
- }
759
-
760
- // Step title
761
- const textX = listX + CARD_PADDING_X + COLLAPSED_FACE_R * 2 + 6;
762
- const maxTextW =
763
- cardW - CARD_PADDING_X * 2 - COLLAPSED_FACE_R * 2 - 6;
764
- itemG
765
- .append('text')
766
- .attr('x', textX)
767
- .attr('y', itemY + COLLAPSED_CARD_H / 2 + FONT_SIZE_META / 2 - 1)
768
- .attr('font-size', FONT_SIZE_META)
769
- .attr('fill', palette.text)
770
- .text(truncateText(step.title, maxTextW, FONT_SIZE_META));
771
-
772
- if (onNavigateToLine) {
773
- itemG.style('cursor', 'pointer').on('click', (event: Event) => {
774
- event.stopPropagation();
775
- onNavigateToLine(step.lineNumber);
776
- });
777
- }
778
-
779
- itemY += COLLAPSED_CARD_H + COLLAPSED_GAP;
780
- }
781
- } else {
782
- // Expanded: render step cards
783
- for (const sl of pl.stepLayouts) {
784
- renderStepCard(
785
- phaseG,
786
- sl,
787
- palette,
788
- isDark,
789
- effectiveActiveGroup,
790
- parsed.tagGroups,
791
- onNavigateToLine,
792
- solid
793
- );
794
- }
795
- }
796
- }
797
- } else {
798
- // Flat mode
799
- for (const sl of layout.flatStepLayouts) {
800
- renderStepCard(
801
- phasesG,
802
- sl,
803
- palette,
804
- isDark,
805
- effectiveActiveGroup,
806
- parsed.tagGroups,
807
- onNavigateToLine,
808
- solid
809
- );
810
- }
811
- }
812
-
813
- // Top-level overlay group for hover elements (renders above everything)
814
- const overlayG = svg.append('g').attr('class', 'journey-overlay');
815
-
816
- // ── Hover + click-to-lock dimming ─────────────────────
817
- if (!exportDims) {
818
- const DIM_OPACITY = 0.35;
819
- let lockedLine: number | null = null;
820
-
821
- // Helper: dim everything except elements matching a line number
822
- const applyDimming = (activeLine: number) => {
823
- svg.selectAll('.journey-step').each(function () {
824
- const el = d3.select(this);
825
- const ln = parseInt(el.attr('data-line-number') ?? '0', 10);
826
- el.style('opacity', ln === activeLine ? '1' : String(DIM_OPACITY));
827
- });
828
- svg.selectAll('.journey-face').each(function () {
829
- const el = d3.select(this);
830
- const ln = parseInt(el.attr('data-line-number') ?? '0', 10);
831
- const isActive = ln === activeLine;
832
- el.style('opacity', isActive ? '1' : String(DIM_OPACITY));
833
- const icon = el.select('.journey-face-icon');
834
- if (isActive) {
835
- const fcx = parseFloat(el.attr('data-cx') ?? '0');
836
- const fcy = parseFloat(el.attr('data-cy') ?? '0');
837
- icon.attr(
838
- 'transform',
839
- `translate(${fcx},${fcy}) scale(${FACE_HOVER_SCALE}) translate(${-fcx},${-fcy})`
840
- );
841
- } else {
842
- icon.attr('transform', null);
843
- }
844
- });
845
- // Dim phases slightly (but not as much)
846
- svg.selectAll('.journey-phase').each(function () {
847
- const el = d3.select(this);
848
- const hasActive = el.select(
849
- `.journey-step[data-line-number="${activeLine}"]`
850
- );
851
- if (!hasActive.node()) {
852
- el.style('opacity', String(DIM_OPACITY + 0.3));
853
- }
854
- });
855
- };
856
-
857
- const clearDimming = () => {
858
- svg.selectAll('.journey-step').style('opacity', null);
859
- svg.selectAll('.journey-face').style('opacity', null);
860
- svg.selectAll('.journey-face-icon').attr('transform', null);
861
- svg.selectAll('.journey-phase').style('opacity', null);
862
- overlayG.selectAll('.journey-thought-hover').remove();
863
- };
864
-
865
- // Show thought bubble for a face in the overlay layer
866
- const THOUGHT_FONT = 11;
867
- const THOUGHT_PAD_X = 10;
868
- const THOUGHT_PAD_Y = 6;
869
- const THOUGHT_MAX_W = 200;
870
- const THOUGHT_LINE_H = 14;
871
- const THOUGHT_GAP = 10;
872
-
873
- const showThoughtBubble = (
874
- faceEl: d3.Selection<SVGGElement, unknown, null, undefined>
875
- ) => {
876
- overlayG.selectAll('.journey-thought-hover').remove();
877
-
878
- const thoughtText = faceEl.attr('data-thought');
879
- if (!thoughtText || !layout.hasThoughts) return;
880
-
881
- const fcx = parseFloat(faceEl.attr('data-cx') ?? '0');
882
- const fcy = parseFloat(faceEl.attr('data-cy') ?? '0');
883
- const score = parseInt(faceEl.attr('data-score') ?? '3', 10);
884
-
885
- const lines = wrapText(thoughtText, THOUGHT_MAX_W, THOUGHT_FONT);
886
- const textW = Math.min(
887
- THOUGHT_MAX_W,
888
- Math.max(...lines.map((l) => measureText(l, THOUGHT_FONT)))
889
- );
890
- const bw = textW + THOUGHT_PAD_X * 2;
891
- const bh = lines.length * THOUGHT_LINE_H + THOUGHT_PAD_Y * 2;
892
-
893
- // Position above the face, overlaying the curve area (clamp to stay in
894
- // view). The layout reserves top headroom so the bubble clears the title
895
- // and persona band even above the highest face — no flip needed.
896
- const bx = Math.max(
897
- PADDING,
898
- Math.min(fcx - bw / 2, layout.totalWidth - PADDING - bw)
899
- );
900
- const by = Math.max(PADDING, fcy - FACE_HOVER_R - THOUGHT_GAP - bh);
901
-
902
- const scoreColor = scoreToColor(score, palette);
903
- const tintedBg = mix(scoreColor, palette.surface, 20);
904
-
905
- const g = overlayG.append('g').attr('class', 'journey-thought-hover');
906
-
907
- g.append('rect')
908
- .attr('x', bx)
909
- .attr('y', by)
910
- .attr('width', bw)
911
- .attr('height', bh)
912
- .attr('rx', CARD_RADIUS)
913
- .attr('fill', tintedBg)
914
- .attr('stroke', scoreColor)
915
- .attr('stroke-width', CARD_STROKE_WIDTH);
916
-
917
- // Connector line from bubble bottom to face top
918
- g.append('line')
919
- .attr('x1', fcx)
920
- .attr('y1', by + bh)
921
- .attr('x2', fcx)
922
- .attr('y2', fcy - FACE_HOVER_R - 1)
923
- .attr('stroke', scoreColor)
924
- .attr('stroke-width', CARD_STROKE_WIDTH);
925
-
926
- const centerX = bx + bw / 2;
927
- for (let i = 0; i < lines.length; i++) {
928
- g.append('text')
929
- .attr('x', centerX)
930
- .attr('y', by + THOUGHT_PAD_Y + (i + 1) * THOUGHT_LINE_H - 2)
931
- .attr('text-anchor', 'middle')
932
- .attr('font-size', THOUGHT_FONT)
933
- .attr('font-style', 'italic')
934
- .attr('fill', palette.textMuted)
935
- // In-bounds by loop guard.
936
- .text(lines[i]!);
937
- }
938
- };
939
-
940
- // Click background to unlock
941
- svg.on('click', (event: MouseEvent) => {
942
- const target = event.target as Element;
943
- if (
944
- !target.closest('.journey-face') &&
945
- !target.closest('.journey-step') &&
946
- !target.closest('.journey-phase')
947
- ) {
948
- lockedLine = null;
949
- clearDimming();
950
- }
951
- });
952
-
953
- // Find the curve face for a line number and show its thought bubble
954
- const showThoughtForLine = (ln: number) => {
955
- svg
956
- .selectAll<SVGGElement, unknown>('.journey-curve-area .journey-face')
957
- .each(function () {
958
- const face = d3.select<SVGGElement, unknown>(this);
959
- if (parseInt(face.attr('data-line-number') ?? '0', 10) === ln) {
960
- showThoughtBubble(face);
961
- }
962
- });
963
- };
964
-
965
- // Hover + click on faces
966
- svg.selectAll<SVGGElement, unknown>('.journey-face').each(function () {
967
- const el = d3.select<SVGGElement, unknown>(this);
968
- el.on('mouseenter', () => {
969
- if (lockedLine !== null) return;
970
- const ln = parseInt(el.attr('data-line-number') ?? '0', 10);
971
- if (ln) {
972
- applyDimming(ln);
973
- showThoughtForLine(ln);
974
- }
975
- })
976
- .on('mouseleave', () => {
977
- if (lockedLine !== null) return;
978
- clearDimming();
979
- })
980
- .on('click', (event: MouseEvent) => {
981
- event.stopPropagation();
982
- const ln = parseInt(el.attr('data-line-number') ?? '0', 10);
983
- if (lockedLine === ln) {
984
- lockedLine = null;
985
- clearDimming();
986
- } else {
987
- lockedLine = ln;
988
- applyDimming(ln);
989
- showThoughtForLine(ln);
990
- if (onNavigateToLine && ln) onNavigateToLine(ln);
991
- }
992
- });
993
- });
994
-
995
- // Hover + click on step cards
996
- svg.selectAll('.journey-step').each(function () {
997
- const el = d3.select(this);
998
- el.on('mouseenter', () => {
999
- if (lockedLine !== null) return;
1000
- const ln = parseInt(el.attr('data-line-number') ?? '0', 10);
1001
- if (ln) {
1002
- applyDimming(ln);
1003
- showThoughtForLine(ln);
1004
- }
1005
- })
1006
- .on('mouseleave', () => {
1007
- if (lockedLine !== null) return;
1008
- clearDimming();
1009
- })
1010
- .on('click', (event: MouseEvent) => {
1011
- event.stopPropagation();
1012
- const ln = parseInt(el.attr('data-line-number') ?? '0', 10);
1013
- if (lockedLine === ln) {
1014
- lockedLine = null;
1015
- clearDimming();
1016
- } else {
1017
- lockedLine = ln;
1018
- applyDimming(ln);
1019
- showThoughtForLine(ln);
1020
- if (onNavigateToLine && ln) onNavigateToLine(ln);
1021
- }
1022
- });
1023
- });
1024
- }
1025
- }
1026
-
1027
- // ============================================================
1028
- // Step Card Renderer
1029
- // ============================================================
1030
-
1031
- function resolveStepColor(
1032
- step: JourneyMapStep,
1033
- scoreColor: string,
1034
- activeGroup: string | null,
1035
- tagGroups: readonly import('../utils/tag-groups').TagGroup[],
1036
- _palette: PaletteColors
1037
- ): string | undefined {
1038
- if (!activeGroup) return undefined;
1039
-
1040
- // "Score" is a synthetic group — use the score-to-color mapping
1041
- if (activeGroup.toLowerCase() === 'score') {
1042
- return step.score !== undefined ? scoreColor : undefined;
1043
- }
1044
-
1045
- // Tag group — find the matching group and look up the step's tag value
1046
- const group = tagGroups.find(
1047
- (g) => g.name.toLowerCase() === activeGroup.toLowerCase()
1048
- );
1049
- if (!group) return undefined;
1050
-
1051
- const tagValue = step.tags[tagAttrKey(group.name)];
1052
- if (!tagValue) return undefined;
1053
-
1054
- const entry = group.entries.find(
1055
- (e) => e.value.toLowerCase() === tagValue.toLowerCase()
1056
- );
1057
- return entry?.color;
1058
- }
1059
-
1060
- function renderStepCard(
1061
- parent: d3.Selection<SVGGElement, unknown, null, undefined>,
1062
- sl: StepLayout,
1063
- palette: PaletteColors,
1064
- isDark: boolean,
1065
- activeGroup: string | null,
1066
- tagGroups: readonly import('../utils/tag-groups').TagGroup[],
1067
- onNavigateToLine?: (line: number) => void,
1068
- solid?: boolean
1069
- ): void {
1070
- const stepG = parent
1071
- .append('g')
1072
- .attr('class', 'journey-step')
1073
- .attr('data-line-number', sl.step.lineNumber);
1074
-
1075
- // Data attributes for legend hover highlighting
1076
- if (sl.step.score !== undefined) {
1077
- stepG.attr('data-score', sl.step.score);
1078
- }
1079
- for (const [key, value] of Object.entries(sl.step.tags)) {
1080
- stepG.attr(`data-tag-${key.toLowerCase()}`, value);
1081
- }
1082
-
1083
- const cx = sl.x;
1084
- const cy = sl.y;
1085
-
1086
- // Card colors — driven by active legend group (matches kanban pattern)
1087
- const resolvedColor = resolveStepColor(
1088
- sl.step,
1089
- sl.color,
1090
- activeGroup,
1091
- tagGroups,
1092
- palette
1093
- );
1094
- // Canonical 25% tint via shapeFill() (or full intent when solid-fill is on)
1095
- const cardFill = shapeFill(
1096
- palette,
1097
- resolvedColor ?? palette.primary,
1098
- isDark,
1099
- { ...(solid !== undefined && { solid }) }
1100
- );
1101
- const cardStroke = resolvedColor ?? palette.textMuted;
1102
- // Text drawn on top of the card must contrast against the fill,
1103
- // not against bg/surface (otherwise textMuted is illegible on solid fills).
1104
- const onCardText = contrastText(
1105
- cardFill,
1106
- palette.textOnFillLight,
1107
- palette.textOnFillDark
1108
- );
1109
-
1110
- // Card background
1111
- stepG
1112
- .append('rect')
1113
- .attr('x', cx)
1114
- .attr('y', cy)
1115
- .attr('width', sl.width)
1116
- .attr('height', sl.height)
1117
- .attr('rx', CARD_RADIUS)
1118
- .attr('fill', cardFill)
1119
- .attr('stroke', cardStroke)
1120
- .attr('stroke-width', CARD_STROKE_WIDTH);
1121
-
1122
- // Title (wrapped)
1123
- const titleMaxW = sl.width - CARD_PADDING_X * 2;
1124
- const titleLines = wrapTextToWidth(sl.step.title, FONT_SIZE_STEP, titleMaxW);
1125
-
1126
- for (let i = 0; i < titleLines.length; i++) {
1127
- stepG
1128
- .append('text')
1129
- .attr('x', cx + CARD_PADDING_X)
1130
- .attr('y', cy + CARD_PADDING_Y + FONT_SIZE_STEP + i * TITLE_LINE_HEIGHT)
1131
- .attr('font-size', FONT_SIZE_STEP)
1132
- .attr('font-weight', '500')
1133
- .attr('fill', onCardText)
1134
- // In-bounds by loop guard.
1135
- .text(titleLines[i]!);
1136
- }
1137
-
1138
- const titleBlockH =
1139
- CARD_PADDING_Y + titleLines.length * TITLE_LINE_HEIGHT + CARD_PADDING_Y;
1140
- const cardAnnotations = sl.step.annotations;
1141
-
1142
- // Separator line between title and content (matches kanban)
1143
- const hasContent = sl.step.description || cardAnnotations.length > 0;
1144
-
1145
- if (hasContent) {
1146
- stepG
1147
- .append('line')
1148
- .attr('x1', cx)
1149
- .attr('y1', cy + titleBlockH)
1150
- .attr('x2', cx + sl.width)
1151
- .attr('y2', cy + titleBlockH)
1152
- // Solid mode: cardStroke matches the fill, so the divider is invisible.
1153
- // Use the contrast text color at low opacity instead.
1154
- .attr('stroke', solid ? onCardText : cardStroke)
1155
- .attr('stroke-opacity', 0.3)
1156
- .attr('stroke-width', 1);
1157
- }
1158
-
1159
- let metaY = cy + titleBlockH + CARD_META_LINE_HEIGHT;
1160
-
1161
- // Description (wrapped text, matches kanban metadata style)
1162
- if (sl.step.description) {
1163
- const descLines = wrapText(
1164
- sl.step.description,
1165
- sl.width - CARD_PADDING_X * 2,
1166
- FONT_SIZE_META
1167
- );
1168
- for (const line of descLines) {
1169
- stepG
1170
- .append('text')
1171
- .attr('x', cx + CARD_PADDING_X)
1172
- .attr('y', metaY)
1173
- .attr('font-size', FONT_SIZE_META)
1174
- .attr('fill', onCardText)
1175
- .text(line);
1176
- metaY += CARD_META_LINE_HEIGHT;
1177
- }
1178
- }
1179
-
1180
- // Annotations (icon bullet + indented text)
1181
- const ANNO_ICON_SIZE = 10;
1182
- const ANNO_ICON_GAP = 4;
1183
- const annoIconIndent = ANNO_ICON_SIZE + ANNO_ICON_GAP;
1184
- const annoTextW = sl.width - CARD_PADDING_X * 2 - annoIconIndent;
1185
- for (const anno of cardAnnotations) {
1186
- const annoColor = annotationColor(anno.type, palette);
1187
- const iconPaths = annotationIconPaths(anno.type);
1188
- const annoLines = wrapText(anno.text, annoTextW, FONT_SIZE_META);
1189
- // Icon color: semantic in tint mode (red pain / green opportunity reads
1190
- // fine on a 25% tinted card). In solid mode the semantic color often
1191
- // matches the card fill (red icon on red card → invisible), so fall back
1192
- // to the contrast color — the icon SHAPE still differentiates the type.
1193
- const iconColor = solid ? onCardText : annoColor;
1194
- // Icon as bullet, aligned to first line
1195
- renderAnnotationIcon(
1196
- stepG,
1197
- cx + CARD_PADDING_X,
1198
- metaY - ANNO_ICON_SIZE + 1,
1199
- ANNO_ICON_SIZE,
1200
- iconPaths,
1201
- iconColor
1202
- );
1203
- // All text lines indented past the icon. Text uses the same
1204
- // contrast color as the rest of the card body — the icon already
1205
- // signals the annotation type. Without this, "thought" lines
1206
- // (palette.textMuted) and "pain"/"opportunity" lines (red/green)
1207
- // are illegible on solid fills.
1208
- for (let li = 0; li < annoLines.length; li++) {
1209
- stepG
1210
- .append('text')
1211
- .attr('x', cx + CARD_PADDING_X + annoIconIndent)
1212
- .attr('y', metaY)
1213
- .attr('font-size', FONT_SIZE_META)
1214
- .attr('fill', onCardText)
1215
- // In-bounds by loop guard.
1216
- .text(annoLines[li]!);
1217
- metaY += CARD_META_LINE_HEIGHT;
1218
- }
1219
- }
1220
-
1221
- // Tag strip — colored bar above the card
1222
- for (const [key, value] of Object.entries(sl.step.tags)) {
1223
- const group = tagGroups.find(
1224
- (g) => g.name.toLowerCase() === key.toLowerCase()
1225
- );
1226
- const entry = group?.entries.find(
1227
- (e) => e.value.toLowerCase() === value.toLowerCase()
1228
- );
1229
- const stripColor = entry?.color ?? palette.textMuted;
1230
- const TAG_GAP = 6;
1231
- const stripY = cy - TAG_STRIP_HEIGHT - TAG_GAP;
1232
- // Canonical 25% tint via shapeFill() (or full intent when solid-fill is on)
1233
- const stripFill = shapeFill(palette, stripColor, isDark, {
1234
- ...(solid !== undefined && { solid }),
1235
- });
1236
-
1237
- stepG
1238
- .append('rect')
1239
- .attr('x', cx)
1240
- .attr('y', stripY)
1241
- .attr('width', sl.width)
1242
- .attr('height', TAG_STRIP_HEIGHT)
1243
- .attr('rx', CARD_RADIUS)
1244
- .attr('fill', stripFill)
1245
- .attr('stroke', stripColor)
1246
- .attr('stroke-width', CARD_STROKE_WIDTH);
1247
-
1248
- // Tag strip text — contrast against the strip fill, not against bg.
1249
- const stripTextColor = contrastText(
1250
- stripFill,
1251
- palette.textOnFillLight,
1252
- palette.textOnFillDark
1253
- );
1254
- stepG
1255
- .append('text')
1256
- .attr('x', cx + sl.width / 2)
1257
- .attr('y', stripY + TAG_STRIP_HEIGHT / 2 + FONT_SIZE_META / 2 - 1)
1258
- .attr('text-anchor', 'middle')
1259
- .attr('font-size', FONT_SIZE_META)
1260
- .attr('fill', stripTextColor)
1261
- .text(value);
1262
- }
1263
-
1264
- if (onNavigateToLine) {
1265
- stepG.style('cursor', 'pointer').on('click', (event: MouseEvent) => {
1266
- event.stopPropagation();
1267
- onNavigateToLine(sl.step.lineNumber);
1268
- });
1269
- }
1270
- }
1271
-
1272
- // ============================================================
1273
- // Helpers
1274
- // ============================================================
1275
-
1276
- // ============================================================
1277
- // Persona Silhouette
1278
- // ============================================================
1279
-
1280
- function renderPersonaSilhouette(
1281
- parent: d3.Selection<SVGGElement, unknown, null, undefined>,
1282
- cx: number,
1283
- cy: number,
1284
- color: string,
1285
- palette: PaletteColors,
1286
- scale = 1
1287
- ): void {
1288
- // Solid color border, muted fill that stands out slightly from card bg
1289
- const fill = mix(color, palette.bg, 70);
1290
- const stroke = color;
1291
- const s = scale;
1292
-
1293
- // Torso + neck (drawn first so head overlaps the junction cleanly)
1294
- parent
1295
- .append('path')
1296
- .attr(
1297
- 'd',
1298
- `M ${cx - 5 * s} ${cy + 6 * s}` +
1299
- ` L ${cx - 5 * s} ${cy + 11 * s}` +
1300
- ` L ${cx - 8 * s} ${cy + 11 * s}` +
1301
- ` Q ${cx - 20 * s} ${cy + 12 * s}, ${cx - 20 * s} ${cy + 22 * s}` +
1302
- ` L ${cx - 20 * s} ${cy + 36 * s}` +
1303
- ` L ${cx + 20 * s} ${cy + 36 * s}` +
1304
- ` L ${cx + 20 * s} ${cy + 22 * s}` +
1305
- ` Q ${cx + 20 * s} ${cy + 12 * s}, ${cx + 8 * s} ${cy + 11 * s}` +
1306
- ` L ${cx + 5 * s} ${cy + 11 * s}` +
1307
- ` L ${cx + 5 * s} ${cy + 6 * s}` +
1308
- ` Z`
1309
- )
1310
- .attr('fill', fill)
1311
- .attr('stroke', stroke)
1312
- .attr('stroke-width', 1.2);
1313
-
1314
- // Head — oval (drawn on top, covers neck junction)
1315
- parent
1316
- .append('path')
1317
- .attr(
1318
- 'd',
1319
- `M ${cx} ${cy - 12 * s}` +
1320
- ` C ${cx + 10 * s} ${cy - 12 * s}, ${cx + 9 * s} ${cy + 2 * s}, ${cx + 6 * s} ${cy + 6 * s}` +
1321
- ` Q ${cx} ${cy + 9 * s}, ${cx - 6 * s} ${cy + 6 * s}` +
1322
- ` C ${cx - 9 * s} ${cy + 2 * s}, ${cx - 10 * s} ${cy - 12 * s}, ${cx} ${cy - 12 * s}` +
1323
- ` Z`
1324
- )
1325
- .attr('fill', fill)
1326
- .attr('stroke', stroke)
1327
- .attr('stroke-width', 1.2);
1328
- }
1329
-
1330
- // ============================================================
1331
- // Score Face Icon (SVG smiley)
1332
- // ============================================================
1333
-
1334
- function renderScoreFace(
1335
- parent: d3.Selection<SVGGElement, unknown, null, undefined>,
1336
- cx: number,
1337
- cy: number,
1338
- score: number,
1339
- palette: PaletteColors,
1340
- isDark: boolean,
1341
- radius?: number
1342
- ): d3.Selection<SVGGElement, unknown, null, undefined> {
1343
- const r = radius ?? FACE_RADIUS;
1344
- const color = scoreToColor(score, palette);
1345
- const g = parent
1346
- .append('g')
1347
- .attr('class', 'journey-face')
1348
- .attr('data-cx', cx)
1349
- .attr('data-cy', cy);
1350
-
1351
- // Inner group holding only the face visuals. Hover/focus scaling is applied
1352
- // to THIS group, not the outer `g`, so the emotion caption (appended into the
1353
- // outer group later) never grows or shifts down into the bottom border.
1354
- const iconG = g.append('g').attr('class', 'journey-face-icon');
1355
-
1356
- // Face: a solid colored ring over the canonical tinted fill (the same
1357
- // shapeFill() tint used for unsolid shapes elsewhere), with the eyes and
1358
- // mouth drawn in the full score color.
1359
- const faceFill = shapeFill(palette, color, isDark);
1360
-
1361
- // Thin bg halo so the colored ring reads crisply where it crosses the line.
1362
- iconG
1363
- .append('circle')
1364
- .attr('cx', cx)
1365
- .attr('cy', cy)
1366
- .attr('r', r + 1)
1367
- .attr('fill', palette.bg);
1368
-
1369
- iconG
1370
- .append('circle')
1371
- .attr('cx', cx)
1372
- .attr('cy', cy)
1373
- .attr('r', r)
1374
- .attr('fill', faceFill)
1375
- .attr('stroke', color)
1376
- .attr('stroke-width', 2);
1377
-
1378
- // Eyes & mouth share the solid score color.
1379
- const eyeColor = color;
1380
- const eyeY = cy - r * 0.15;
1381
- const eyeSpacing = r * 0.32;
1382
- const eyeR = r * 0.12;
1383
- iconG
1384
- .append('circle')
1385
- .attr('cx', cx - eyeSpacing)
1386
- .attr('cy', eyeY)
1387
- .attr('r', eyeR)
1388
- .attr('fill', eyeColor);
1389
- iconG
1390
- .append('circle')
1391
- .attr('cx', cx + eyeSpacing)
1392
- .attr('cy', eyeY)
1393
- .attr('r', eyeR)
1394
- .attr('fill', eyeColor);
1395
-
1396
- // Mouth — arc curvature based on score
1397
- // score 5: big smile, score 3: straight, score 1: deep frown
1398
- const mouthW = r * 0.46;
1399
- // Curve amount: positive = smile, negative = frown
1400
- const curve = ((score - 3) / 2) * r * 0.42;
1401
- // Pin the mouth's visual apex (its mid-point) to a fixed Y and let the
1402
- // curvature swing symmetrically about it. Anchoring the corners instead made
1403
- // the frown's arch ride up into the eyes and read as a cramped grimace.
1404
- const apexY = cy + r * 0.32;
1405
- const mouthY = apexY - curve / 2;
1406
-
1407
- iconG
1408
- .append('path')
1409
- .attr(
1410
- 'd',
1411
- `M ${cx - mouthW} ${mouthY} Q ${cx} ${mouthY + curve} ${cx + mouthW} ${mouthY}`
1412
- )
1413
- .attr('fill', 'none')
1414
- .attr('stroke', eyeColor)
1415
- .attr('stroke-width', 1.2)
1416
- .attr('stroke-linecap', 'round');
1417
-
1418
- return g;
1419
- }
1420
-
1421
- // Max width an emotion caption may occupy. Curve faces sit at card centers
1422
- // (columns are ~190px wide and never overlap), so clamping each caption below
1423
- // the column width guarantees adjacent captions can never collide horizontally,
1424
- // however tight the journey gets.
1425
- const EMOTION_LABEL_MAX_WIDTH = 180;
1426
- const EMOTION_LABEL_FONT_SIZE = FONT_SIZE_META;
1427
-
1428
- /**
1429
- * Caption a curve face with its emotion word. Appended INTO the face group so
1430
- * it dims / navigates with the face. Always placed BELOW the face: the curve
1431
- * band reserves a gap beneath the lowest face before the cards, and — crucially
1432
- * — the hover thought-bubble always pops ABOVE the face, so a below-caption is
1433
- * never occluded on hover (above-captions were). Below also keeps every caption
1434
- * clear of the persona box / title at the top of the band.
1435
- */
1436
- function addEmotionLabel(
1437
- faceG: d3.Selection<SVGGElement, unknown, null, undefined>,
1438
- pt: CurvePoint,
1439
- palette: PaletteColors
1440
- ): void {
1441
- if (!pt.emotionLabel) return;
1442
- const text = truncateText(
1443
- pt.emotionLabel,
1444
- EMOTION_LABEL_MAX_WIDTH,
1445
- EMOTION_LABEL_FONT_SIZE
1446
- );
1447
- const y = pt.y + FACE_RADIUS + 5 + EMOTION_LABEL_FONT_SIZE;
1448
-
1449
- faceG
1450
- .append('text')
1451
- .attr('class', 'journey-emotion-label')
1452
- .attr('x', pt.x)
1453
- .attr('y', y)
1454
- .attr('text-anchor', 'middle')
1455
- .attr('font-family', FONT_FAMILY)
1456
- .attr('font-size', EMOTION_LABEL_FONT_SIZE)
1457
- .attr('font-weight', 500)
1458
- .attr('fill', palette.text)
1459
- .attr('stroke', palette.bg)
1460
- .attr('stroke-width', 3)
1461
- .attr('stroke-linejoin', 'round')
1462
- .attr('stroke-opacity', 0.8)
1463
- .attr('paint-order', 'stroke')
1464
- .attr('pointer-events', 'none')
1465
- .text(text);
1466
- }
1467
-
1468
- function wrapText(text: string, maxWidth: number, fontSize: number): string[] {
1469
- return wrapTextToWidth(text, fontSize, maxWidth);
1470
- }
1471
-
1472
- function truncateText(
1473
- text: string,
1474
- maxWidth: number,
1475
- fontSize: number
1476
- ): string {
1477
- return truncateToWidth(text, fontSize, maxWidth);
1478
- }
1479
-
1480
- function annotationColor(
1481
- type: JourneyMapAnnotation['type'],
1482
- palette: PaletteColors
1483
- ): string {
1484
- switch (type) {
1485
- case 'pain':
1486
- return palette.colors.red;
1487
- case 'opportunity':
1488
- return palette.colors.green;
1489
- case 'thought':
1490
- return palette.textMuted;
1491
- }
1492
- }
1493
-
1494
- // Lucide icon paths (24×24 viewBox, ISC license)
1495
- const ICON_THUMBS_DOWN: string[] = [
1496
- 'M9 18.12 10 14H4.17a2 2 0 0 1-1.92-2.56l2.33-8A2 2 0 0 1 6.5 2H20a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2h-2.76a2 2 0 0 0-1.79 1.11L12 22a3.13 3.13 0 0 1-3-3.88Z',
1497
- 'M17 14V2',
1498
- ];
1499
- const ICON_THUMBS_UP: string[] = [
1500
- 'M15 5.88 14 10h5.83a2 2 0 0 1 1.92 2.56l-2.33 8A2 2 0 0 1 17.5 22H4a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2h2.76a2 2 0 0 0 1.79-1.11L12 2a3.13 3.13 0 0 1 3 3.88Z',
1501
- 'M7 10v12',
1502
- ];
1503
- const ICON_THOUGHT: string[] = [
1504
- 'M15 14c.2-1 .7-1.7 1.5-2.5 1-.9 1.5-2.2 1.5-3.5A6 6 0 0 0 6 8c0 1 .2 2.2 1.5 3.5.7.7 1.3 1.5 1.5 2.5',
1505
- 'M9 18h6',
1506
- 'M10 22h4',
1507
- ];
1508
-
1509
- function annotationIconPaths(type: JourneyMapAnnotation['type']): string[] {
1510
- switch (type) {
1511
- case 'pain':
1512
- return ICON_THUMBS_DOWN;
1513
- case 'opportunity':
1514
- return ICON_THUMBS_UP;
1515
- case 'thought':
1516
- return ICON_THOUGHT;
1517
- }
1518
- }
1519
-
1520
- /** Render a lucide-style icon (24×24 viewBox) scaled to fit `size` px. */
1521
- function renderAnnotationIcon(
1522
- parent: d3.Selection<SVGGElement, unknown, null, undefined>,
1523
- x: number,
1524
- y: number,
1525
- size: number,
1526
- paths: string[],
1527
- color: string
1528
- ): void {
1529
- const g = parent.append('g').attr('transform', `translate(${x}, ${y})`);
1530
- const scale = size / 24;
1531
- const inner = g.append('g').attr('transform', `scale(${scale})`);
1532
- for (const d of paths) {
1533
- inner
1534
- .append('path')
1535
- .attr('d', d)
1536
- .attr('fill', 'none')
1537
- .attr('stroke', color)
1538
- .attr('stroke-width', 2)
1539
- .attr('stroke-linecap', 'round')
1540
- .attr('stroke-linejoin', 'round');
1541
- }
1542
- }
1543
-
1544
- // ============================================================
1545
- // Export Renderer
1546
- // ============================================================
1547
-
1548
- export function renderJourneyMapForExport(
1549
- content: string,
1550
- theme: 'light' | 'dark' | 'transparent',
1551
- palette: PaletteColors
1552
- ): string {
1553
- const parsed = parseJourneyMap(content, palette);
1554
- if (
1555
- parsed.error ||
1556
- (parsed.phases.length === 0 && parsed.steps.length === 0)
1557
- ) {
1558
- return '';
1559
- }
1560
-
1561
- const isDark = theme === 'dark';
1562
- const layout = layoutJourneyMap(parsed, palette, { isDark });
1563
-
1564
- const container = document.createElement('div');
1565
- renderJourneyMap(container, parsed, palette, isDark, {
1566
- exportDims: { width: layout.totalWidth, height: layout.totalHeight },
1567
- exportMode: true,
1568
- });
1569
-
1570
- const svgEl = container.querySelector('svg');
1571
- if (!svgEl) return '';
1572
-
1573
- // Handle transparent background
1574
- if (theme === 'transparent') {
1575
- const bgRect = svgEl.querySelector('rect:first-child');
1576
- if (bgRect) bgRect.remove();
1577
- }
1578
-
1579
- return svgEl.outerHTML;
1580
- }