@zukhruf/diagram 0.3.32 → 0.3.34

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 (122) hide show
  1. package/README.md +98 -52
  2. package/dist/index.d.ts +5 -3
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +1 -0
  5. package/dist/index.js.map +1 -1
  6. package/dist/lib/compiler/diagram-compile.d.ts +3 -4
  7. package/dist/lib/compiler/diagram-compile.d.ts.map +1 -1
  8. package/dist/lib/compiler/diagram-compile.js +85 -370
  9. package/dist/lib/compiler/diagram-compile.js.map +1 -1
  10. package/dist/lib/layouts/graph/attach.d.ts +25 -0
  11. package/dist/lib/layouts/graph/attach.d.ts.map +1 -0
  12. package/dist/lib/layouts/graph/attach.js +272 -0
  13. package/dist/lib/layouts/graph/attach.js.map +1 -0
  14. package/dist/lib/layouts/graph/connections.d.ts +45 -0
  15. package/dist/lib/layouts/graph/connections.d.ts.map +1 -0
  16. package/dist/lib/layouts/graph/connections.js +138 -0
  17. package/dist/lib/layouts/graph/connections.js.map +1 -0
  18. package/dist/lib/layouts/graph/graph-layout-result.d.ts +5 -3
  19. package/dist/lib/layouts/graph/graph-layout-result.d.ts.map +1 -1
  20. package/dist/lib/layouts/graph/graph-layout-result.js.map +1 -1
  21. package/dist/lib/layouts/graph/gutters.js +41 -22
  22. package/dist/lib/layouts/graph/gutters.js.map +1 -1
  23. package/dist/lib/layouts/graph/labels.d.ts +23 -0
  24. package/dist/lib/layouts/graph/labels.d.ts.map +1 -0
  25. package/dist/lib/layouts/graph/labels.js +120 -0
  26. package/dist/lib/layouts/graph/labels.js.map +1 -0
  27. package/dist/lib/layouts/graph/layout.d.ts +1 -1
  28. package/dist/lib/layouts/graph/layout.d.ts.map +1 -1
  29. package/dist/lib/layouts/graph/layout.js +37 -12
  30. package/dist/lib/layouts/graph/layout.js.map +1 -1
  31. package/dist/lib/layouts/graph/measure.d.ts +15 -11
  32. package/dist/lib/layouts/graph/measure.d.ts.map +1 -1
  33. package/dist/lib/layouts/graph/measure.js +82 -38
  34. package/dist/lib/layouts/graph/measure.js.map +1 -1
  35. package/dist/lib/layouts/graph/min-heap.d.ts +8 -0
  36. package/dist/lib/layouts/graph/min-heap.d.ts.map +1 -0
  37. package/dist/lib/layouts/graph/min-heap.js +56 -0
  38. package/dist/lib/layouts/graph/min-heap.js.map +1 -0
  39. package/dist/lib/layouts/graph/node-content.d.ts +2 -3
  40. package/dist/lib/layouts/graph/node-content.d.ts.map +1 -1
  41. package/dist/lib/layouts/graph/node-content.js +67 -47
  42. package/dist/lib/layouts/graph/node-content.js.map +1 -1
  43. package/dist/lib/layouts/graph/path.d.ts +6 -0
  44. package/dist/lib/layouts/graph/path.d.ts.map +1 -0
  45. package/dist/lib/layouts/graph/path.js +53 -0
  46. package/dist/lib/layouts/graph/path.js.map +1 -0
  47. package/dist/lib/layouts/graph/round.d.ts +11 -0
  48. package/dist/lib/layouts/graph/round.d.ts.map +1 -0
  49. package/dist/lib/layouts/graph/round.js +181 -0
  50. package/dist/lib/layouts/graph/round.js.map +1 -0
  51. package/dist/lib/layouts/graph/route-search.d.ts +34 -0
  52. package/dist/lib/layouts/graph/route-search.d.ts.map +1 -0
  53. package/dist/lib/layouts/graph/route-search.js +208 -0
  54. package/dist/lib/layouts/graph/route-search.js.map +1 -0
  55. package/dist/lib/layouts/graph/route.d.ts +20 -0
  56. package/dist/lib/layouts/graph/route.d.ts.map +1 -0
  57. package/dist/lib/layouts/graph/route.js +276 -0
  58. package/dist/lib/layouts/graph/route.js.map +1 -0
  59. package/dist/lib/layouts/graph/sides.d.ts +28 -0
  60. package/dist/lib/layouts/graph/sides.d.ts.map +1 -0
  61. package/dist/lib/layouts/graph/sides.js +98 -0
  62. package/dist/lib/layouts/graph/sides.js.map +1 -0
  63. package/dist/lib/layouts/timeline/timeline-layout.d.ts +2 -1
  64. package/dist/lib/layouts/timeline/timeline-layout.d.ts.map +1 -1
  65. package/dist/lib/layouts/timeline/timeline-layout.js +9 -4
  66. package/dist/lib/layouts/timeline/timeline-layout.js.map +1 -1
  67. package/dist/lib/model/diagram-ir.d.ts +19 -156
  68. package/dist/lib/model/diagram-ir.d.ts.map +1 -1
  69. package/dist/lib/model/diagram-ir.js.map +1 -1
  70. package/dist/lib/model/validate-graph.d.ts +7 -0
  71. package/dist/lib/model/validate-graph.d.ts.map +1 -0
  72. package/dist/lib/model/validate-graph.js +54 -0
  73. package/dist/lib/model/validate-graph.js.map +1 -0
  74. package/dist/lib/react/Diagram.d.ts +3 -9
  75. package/dist/lib/react/Diagram.d.ts.map +1 -1
  76. package/dist/lib/react/Diagram.js +1 -13
  77. package/dist/lib/react/Diagram.js.map +1 -1
  78. package/dist/lib/react/diagram-types.d.ts +17 -46
  79. package/dist/lib/react/diagram-types.d.ts.map +1 -1
  80. package/dist/lib/react/diagram-types.js.map +1 -1
  81. package/dist/lib/renderers/canvas/graph-canvas.d.ts +2 -5
  82. package/dist/lib/renderers/canvas/graph-canvas.d.ts.map +1 -1
  83. package/dist/lib/renderers/canvas/graph-canvas.js +68 -43
  84. package/dist/lib/renderers/canvas/graph-canvas.js.map +1 -1
  85. package/dist/lib/renderers/html/graph-html.d.ts +2 -3
  86. package/dist/lib/renderers/html/graph-html.d.ts.map +1 -1
  87. package/dist/lib/renderers/html/graph-html.js +298 -289
  88. package/dist/lib/renderers/html/graph-html.js.map +1 -1
  89. package/dist/lib/renderers/shared/graph-parts.d.ts +3 -1
  90. package/dist/lib/renderers/shared/graph-parts.d.ts.map +1 -1
  91. package/dist/lib/renderers/shared/graph-parts.js +350 -418
  92. package/dist/lib/renderers/shared/graph-parts.js.map +1 -1
  93. package/dist/lib/renderers/shared/node-parts.d.ts +5 -6
  94. package/dist/lib/renderers/shared/node-parts.d.ts.map +1 -1
  95. package/dist/lib/renderers/shared/node-parts.js +112 -190
  96. package/dist/lib/renderers/shared/node-parts.js.map +1 -1
  97. package/dist/lib/renderers/shared/run-spans.js +2 -2
  98. package/dist/lib/renderers/shared/run-spans.js.map +1 -1
  99. package/dist/lib/renderers/shared/text-runs.d.ts +0 -6
  100. package/dist/lib/renderers/shared/text-runs.d.ts.map +1 -1
  101. package/dist/lib/renderers/shared/text-runs.js +0 -12
  102. package/dist/lib/renderers/shared/text-runs.js.map +1 -1
  103. package/dist/lib/renderers/svg/graph-svg.d.ts +1 -3
  104. package/dist/lib/renderers/svg/graph-svg.d.ts.map +1 -1
  105. package/dist/lib/renderers/svg/graph-svg.js +66 -80
  106. package/dist/lib/renderers/svg/graph-svg.js.map +1 -1
  107. package/dist/lib/renderers/svg/timeline-svg.d.ts.map +1 -1
  108. package/dist/lib/renderers/svg/timeline-svg.js +7 -5
  109. package/dist/lib/renderers/svg/timeline-svg.js.map +1 -1
  110. package/package.json +1 -1
  111. package/dist/lib/layouts/graph/graph-layout.d.ts +0 -154
  112. package/dist/lib/layouts/graph/graph-layout.d.ts.map +0 -1
  113. package/dist/lib/layouts/graph/graph-layout.js +0 -2340
  114. package/dist/lib/layouts/graph/graph-layout.js.map +0 -1
  115. package/dist/lib/layouts/graph/legacy-graph-layout.d.ts +0 -6
  116. package/dist/lib/layouts/graph/legacy-graph-layout.d.ts.map +0 -1
  117. package/dist/lib/layouts/graph/legacy-graph-layout.js +0 -542
  118. package/dist/lib/layouts/graph/legacy-graph-layout.js.map +0 -1
  119. package/dist/lib/layouts/text-metrics.d.ts +0 -7
  120. package/dist/lib/layouts/text-metrics.d.ts.map +0 -1
  121. package/dist/lib/layouts/text-metrics.js +0 -40
  122. package/dist/lib/layouts/text-metrics.js.map +0 -1
@@ -1,6 +1,9 @@
1
+ import { validateGraph } from "../../model/validate-graph.js";
1
2
  import { gridAreas } from "./areas.js";
2
3
  import { gridGutters } from "./gutters.js";
3
- import { measureGroupTitle, measureNode } from "./measure.js";
4
+ import { measureGroupTitle, measureNode, placeGroupPorts } from "./measure.js";
5
+ import { roundLayout } from "./round.js";
6
+ import { routeGraph } from "./route.js";
4
7
  import { LAYOUT_TOKENS } from "./tokens.js";
5
8
  import { sizeTracks } from "./tracks.js";
6
9
 
@@ -8,11 +11,12 @@ import { sizeTracks } from "./tracks.js";
8
11
  * Lays out a graph on a content-sized grid: it measures every node, sizes
9
12
  * each row and column to the content in it, and reserves the chrome of the
10
13
  * groups in the gutters between them. It throws when the grid cannot be
11
- * drawn without overlap.
14
+ * drawn without overlap, or when an id or an edge end is wrong.
12
15
  */
13
16
  export function layoutGraph(ir) {
14
- const measured = new Map(ir.nodes.map(node => [node.id, measureNode(node, LAYOUT_TOKENS)]));
15
- const titles = new Map(ir.groups.map(group => [group.id, measureGroupTitle(group, LAYOUT_TOKENS)]));
17
+ validateGraph(ir);
18
+ const measured = new Map(ir.nodes.map(node => [node.id, measureNode(node)]));
19
+ const titles = new Map(ir.groups.map(group => [group.id, measureGroupTitle(group)]));
16
20
  const areas = gridAreas(ir);
17
21
  const gutters = gridGutters(areas, new Map([...titles].map(([id, title]) => [id, title.height])), ir.edges);
18
22
  const items = axis => ir.nodes.map(node => {
@@ -45,13 +49,18 @@ export function layoutGraph(ir) {
45
49
  };
46
50
  });
47
51
  const groups = areas.groups.map(groupArea => placeGroup(groupArea, titles.get(groupArea.group.id), lines, gutters));
48
- return {
52
+ const widestGutter = Math.max(...[...gutters.row, ...gutters.col].map(gutter => gutter.size));
53
+ const {
54
+ edges,
55
+ leaders
56
+ } = routeGraph(ir, nodes, groups, areas, 2 * widestGutter);
57
+ return roundLayout({
49
58
  nodes,
50
59
  groups,
51
- edges: [],
52
- leaders: [],
53
- viewBox: viewBoxOf(nodes, groups)
54
- };
60
+ edges,
61
+ leaders,
62
+ viewBox: viewBoxOf(nodes, groups, edges, leaders)
63
+ });
55
64
  }
56
65
  function areaBox(area, lines) {
57
66
  const x = lines.col.trackStart(area.col);
@@ -108,7 +117,8 @@ function placeGroup({
108
117
  depth,
109
118
  rect,
110
119
  ...title.place(rect),
111
- dividers: group.dividers ? dividers(rect, area, title, group.labelSide, lines, gutters) : []
120
+ dividers: group.dividers ? dividers(rect, area, title, group.labelSide, lines, gutters) : [],
121
+ ports: placeGroupPorts(group.ports ?? [], rect)
112
122
  };
113
123
  }
114
124
 
@@ -141,8 +151,23 @@ function dividers(rect, area, title, labelSide, lines, gutters) {
141
151
  }];
142
152
  })];
143
153
  }
144
- function viewBoxOf(nodes, groups) {
145
- const boxes = [...nodes.map(nodeLayout => nodeLayout.visual), ...groups.map(groupLayout => groupLayout.rect)];
154
+ function viewBoxOf(nodes, groups, edges, leaders) {
155
+ const pointBox = ({
156
+ x,
157
+ y
158
+ }) => ({
159
+ x,
160
+ y,
161
+ w: 0,
162
+ h: 0
163
+ });
164
+ const boxes = [...nodes.map(nodeLayout => nodeLayout.visual), ...groups.map(groupLayout => groupLayout.rect), ...edges.flatMap(({
165
+ points,
166
+ label,
167
+ badge
168
+ }) => [...points.map(pointBox), ...(label ? [label.box] : []), ...(badge ? [badge.box] : [])]), ...leaders.flatMap(({
169
+ points
170
+ }) => points.map(pointBox))];
146
171
  const pad = LAYOUT_TOKENS.CONTENT_PAD;
147
172
  if (boxes.length === 0) return {
148
173
  x: -pad,
@@ -1 +1 @@
1
- {"version":3,"file":"layout.js","names":["gridAreas","gridGutters","measureGroupTitle","measureNode","LAYOUT_TOKENS","sizeTracks","layoutGraph","ir","measured","Map","nodes","map","node","id","titles","groups","group","areas","gutters","title","height","edges","items","axis","area","get","frame","overhang","start","row","span","rowSpan","size","h","top","bottom","col","colSpan","w","left","right","line","count","gutter","lines","rows","cols","measuredNode","areaBox","place","nodeFrame","groupArea","placeGroup","leaders","viewBox","viewBoxOf","x","trackStart","y","trackEnd","stretch","visualW","visualH","depth","border","boundary","side","gutterStart","rect","dividers","labelSide","centre","titleAtBottom","inner","Array","from","length","_","index","boxes","nodeLayout","visual","groupLayout","pad","CONTENT_PAD","Math","min","box","max"],"sources":["../../../../src/lib/layouts/graph/layout.ts"],"sourcesContent":["import type { Box, DiagramGraphIR, Point } from '../../model/diagram-ir.ts';\nimport { type CellArea, type GroupArea, gridAreas } from './areas.ts';\nimport type {\n GraphLayout,\n GroupLayout,\n NodeLayout,\n} from './graph-layout-result.ts';\nimport { type Axis, type GridGutters, gridGutters } from './gutters.ts';\nimport {\n type MeasuredGroupTitle,\n type MeasuredNode,\n measureGroupTitle,\n measureNode,\n} from './measure.ts';\nimport { LAYOUT_TOKENS } from './tokens.ts';\nimport { type TrackLine, sizeTracks } from './tracks.ts';\n\n/**\n * Lays out a graph on a content-sized grid: it measures every node, sizes\n * each row and column to the content in it, and reserves the chrome of the\n * groups in the gutters between them. It throws when the grid cannot be\n * drawn without overlap.\n */\nexport function layoutGraph(ir: DiagramGraphIR): GraphLayout {\n const measured = new Map(\n ir.nodes.map(\n (node) => [node.id, measureNode(node, LAYOUT_TOKENS)] as const,\n ),\n );\n const titles = new Map(\n ir.groups.map(\n (group) => [group.id, measureGroupTitle(group, LAYOUT_TOKENS)] as const,\n ),\n );\n const areas = gridAreas(ir);\n const gutters = gridGutters(\n areas,\n new Map([...titles].map(([id, title]) => [id, title.height])),\n ir.edges,\n );\n\n const items = (axis: Axis) =>\n ir.nodes.map((node) => {\n const area = areas.nodes.get(node.id)!;\n const { frame, overhang } = measured.get(node.id)!;\n return axis === 'row'\n ? {\n start: area.row,\n span: area.rowSpan,\n size: frame.h + overhang.top + overhang.bottom,\n }\n : {\n start: area.col,\n span: area.colSpan,\n size: frame.w + overhang.left + overhang.right,\n };\n });\n const line = (axis: Axis, count: number) =>\n sizeTracks(\n count,\n items(axis),\n gutters[axis].map((gutter) => gutter.size),\n );\n const lines: Record<Axis, TrackLine> = {\n row: line('row', areas.rows),\n col: line('col', areas.cols),\n };\n\n const nodes: NodeLayout[] = ir.nodes.map((node) => {\n const measuredNode = measured.get(node.id)!;\n const area = areaBox(areas.nodes.get(node.id)!, lines);\n return { node, ...measuredNode.place(nodeFrame(measuredNode, area)) };\n });\n const groups = areas.groups.map((groupArea) =>\n placeGroup(groupArea, titles.get(groupArea.group.id)!, lines, gutters),\n );\n\n return {\n nodes,\n groups,\n edges: [],\n leaders: [],\n viewBox: viewBoxOf(nodes, groups),\n };\n}\n\nfunction areaBox(area: CellArea, lines: Record<Axis, TrackLine>): Box {\n const x = lines.col.trackStart(area.col);\n const y = lines.row.trackStart(area.row);\n return {\n x,\n y,\n w: lines.col.trackEnd(area.col + area.colSpan - 1) - x,\n h: lines.row.trackEnd(area.row + area.rowSpan - 1) - y,\n };\n}\n\n/** A stretching node fills its area; any other node keeps its measured frame, centred in the area. */\nfunction nodeFrame(measured: MeasuredNode, area: Box): Box {\n const { frame, overhang, stretch } = measured;\n if (stretch) {\n return {\n x: area.x + overhang.left,\n y: area.y + overhang.top,\n w: area.w - overhang.left - overhang.right,\n h: area.h - overhang.top - overhang.bottom,\n };\n }\n const visualW = frame.w + overhang.left + overhang.right;\n const visualH = frame.h + overhang.top + overhang.bottom;\n return {\n x: area.x + (area.w - visualW) / 2 + overhang.left,\n y: area.y + (area.h - visualH) / 2 + overhang.top,\n ...frame,\n };\n}\n\n/** Each side of a group lies on the outer edge of its chrome slot in the gutter where the group opens or closes. */\nfunction placeGroup(\n { group, depth, area }: GroupArea,\n title: MeasuredGroupTitle,\n lines: Record<Axis, TrackLine>,\n gutters: GridGutters,\n): GroupLayout {\n const border = (axis: Axis, boundary: number, side: 'opening' | 'closing') =>\n lines[axis].gutterStart(boundary) +\n gutters[axis][boundary]![side].get(depth)!;\n const x = border('col', area.col, 'opening');\n const y = border('row', area.row, 'opening');\n const rect = {\n x,\n y,\n w: border('col', area.col + area.colSpan, 'closing') - x,\n h: border('row', area.row + area.rowSpan, 'closing') - y,\n };\n return {\n group,\n depth,\n rect,\n ...title.place(rect),\n dividers: group.dividers\n ? dividers(rect, area, title, group.labelSide, lines, gutters)\n : [],\n };\n}\n\n/** A line through the middle of every gutter inside the group, clear of its title. */\nfunction dividers(\n rect: Box,\n area: CellArea,\n title: MeasuredGroupTitle,\n labelSide: 'top' | 'bottom' | undefined,\n lines: Record<Axis, TrackLine>,\n gutters: GridGutters,\n): [Point, Point][] {\n const centre = (axis: Axis, boundary: number) =>\n lines[axis].gutterStart(boundary) + gutters[axis][boundary]!.size / 2;\n const titleAtBottom = labelSide === 'bottom';\n const top = rect.y + (titleAtBottom ? 0 : title.height);\n const bottom = rect.y + rect.h - (titleAtBottom ? title.height : 0);\n const inner = (start: number, span: number) =>\n Array.from({ length: span - 1 }, (_, index) => start + index + 1);\n return [\n ...inner(area.col, area.colSpan).map((boundary): [Point, Point] => {\n const x = centre('col', boundary);\n return [\n { x, y: top },\n { x, y: bottom },\n ];\n }),\n ...inner(area.row, area.rowSpan).map((boundary): [Point, Point] => {\n const y = centre('row', boundary);\n return [\n { x: rect.x, y },\n { x: rect.x + rect.w, y },\n ];\n }),\n ];\n}\n\nfunction viewBoxOf(nodes: NodeLayout[], groups: GroupLayout[]): Box {\n const boxes = [\n ...nodes.map((nodeLayout) => nodeLayout.visual),\n ...groups.map((groupLayout) => groupLayout.rect),\n ];\n const pad = LAYOUT_TOKENS.CONTENT_PAD;\n if (boxes.length === 0) return { x: -pad, y: -pad, w: 2 * pad, h: 2 * pad };\n const left = Math.min(...boxes.map((box) => box.x));\n const top = Math.min(...boxes.map((box) => box.y));\n const right = Math.max(...boxes.map((box) => box.x + box.w));\n const bottom = Math.max(...boxes.map((box) => box.y + box.h));\n return {\n x: left - pad,\n y: top - pad,\n w: right - left + 2 * pad,\n h: bottom - top + 2 * pad,\n };\n}\n"],"mappings":"AACA,SAAwCA,SAAS,QAAQ,YAAY;AAMrE,SAAsCC,WAAW,QAAQ,cAAc;AACvE,SAGEC,iBAAiB,EACjBC,WAAW,QACN,cAAc;AACrB,SAASC,aAAa,QAAQ,aAAa;AAC3C,SAAyBC,UAAU,QAAQ,aAAa;;AAExD;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,WAAWA,CAACC,EAAkB,EAAe;EAC3D,MAAMC,QAAQ,GAAG,IAAIC,GAAG,CACtBF,EAAE,CAACG,KAAK,CAACC,GAAG,CACTC,I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4E,GAAG,IAAKA,GAAG,CAAC7B,CAAC,CAAC,CAAC;EAClD,MAAMlB,KAAK,GAAG6C,IAAI,CAACG,GAAG,CAAC,GAAGT,KAAK,CAACpE,GAAG,CAAE4E,GAAG,IAAKA,GAAG,CAAC/B,CAAC,GAAG+B,GAAG,CAACjD,CAAC,CAAC,CAAC;EAC5D,MAAMH,MAAM,GAAGkD,IAAI,CAACG,GAAG,CAAC,GAAGT,KAAK,CAACpE,GAAG,CAAE4E,GAAG,IAAKA,GAAG,CAAC7B,CAAC,GAAG6B,GAAG,CAACtD,CAAC,CAAC,CAAC;EAC7D,OAAO;IACLuB,CAAC,EAAEjB,IAAI,GAAG4C,GAAG;IACbzB,CAAC,EAAExB,GAAG,GAAGiD,GAAG;IACZ7C,CAAC,EAAEE,KAAK,GAAGD,IAAI,GAAG,CAAC,GAAG4C,GAAG;IACzBlD,CAAC,EAAEE,MAAM,GAAGD,GAAG,GAAG,CAAC,GAAGiD;EACxB,CAAC;AACH","ignoreList":[]}
1
+ {"version":3,"file":"layout.js","names":["validateGraph","gridAreas","gridGutters","measureGroupTitle","measureNode","placeGroupPorts","roundLayout","routeGraph","LAYOUT_TOKENS","sizeTracks","layoutGraph","ir","measured","Map","nodes","map","node","id","titles","groups","group","areas","gutters","title","height","edges","items","axis","area","get","frame","overhang","start","row","span","rowSpan","size","h","top","bottom","col","colSpan","w","left","right","line","count","gutter","lines","rows","cols","measuredNode","areaBox","place","nodeFrame","groupArea","placeGroup","widestGutter","Math","max","leaders","viewBox","viewBoxOf","x","trackStart","y","trackEnd","stretch","visualW","visualH","depth","border","boundary","side","gutterStart","rect","dividers","labelSide","ports","centre","titleAtBottom","inner","Array","from","length","_","index","pointBox","boxes","nodeLayout","visual","groupLayout","flatMap","points","label","badge","box","pad","CONTENT_PAD","min"],"sources":["../../../../src/lib/layouts/graph/layout.ts"],"sourcesContent":["import type { Box, DiagramGraphIR, Point } from '../../model/diagram-ir.ts';\nimport { validateGraph } from '../../model/validate-graph.ts';\nimport { type CellArea, type GroupArea, gridAreas } from './areas.ts';\nimport type {\n GraphLayout,\n GroupLayout,\n NodeLayout,\n} from './graph-layout-result.ts';\nimport { type Axis, type GridGutters, gridGutters } from './gutters.ts';\nimport {\n type MeasuredGroupTitle,\n type MeasuredNode,\n measureGroupTitle,\n measureNode,\n placeGroupPorts,\n} from './measure.ts';\nimport { roundLayout } from './round.ts';\nimport { type RoutedGraph, routeGraph } from './route.ts';\nimport { LAYOUT_TOKENS } from './tokens.ts';\nimport { type TrackLine, sizeTracks } from './tracks.ts';\n\n/**\n * Lays out a graph on a content-sized grid: it measures every node, sizes\n * each row and column to the content in it, and reserves the chrome of the\n * groups in the gutters between them. It throws when the grid cannot be\n * drawn without overlap, or when an id or an edge end is wrong.\n */\nexport function layoutGraph(ir: DiagramGraphIR): GraphLayout {\n validateGraph(ir);\n const measured = new Map(\n ir.nodes.map((node) => [node.id, measureNode(node)] as const),\n );\n const titles = new Map(\n ir.groups.map((group) => [group.id, measureGroupTitle(group)] as const),\n );\n const areas = gridAreas(ir);\n const gutters = gridGutters(\n areas,\n new Map([...titles].map(([id, title]) => [id, title.height])),\n ir.edges,\n );\n\n const items = (axis: Axis) =>\n ir.nodes.map((node) => {\n const area = areas.nodes.get(node.id)!;\n const { frame, overhang } = measured.get(node.id)!;\n return axis === 'row'\n ? {\n start: area.row,\n span: area.rowSpan,\n size: frame.h + overhang.top + overhang.bottom,\n }\n : {\n start: area.col,\n span: area.colSpan,\n size: frame.w + overhang.left + overhang.right,\n };\n });\n const line = (axis: Axis, count: number) =>\n sizeTracks(\n count,\n items(axis),\n gutters[axis].map((gutter) => gutter.size),\n );\n const lines: Record<Axis, TrackLine> = {\n row: line('row', areas.rows),\n col: line('col', areas.cols),\n };\n\n const nodes: NodeLayout[] = ir.nodes.map((node) => {\n const measuredNode = measured.get(node.id)!;\n const area = areaBox(areas.nodes.get(node.id)!, lines);\n return { node, ...measuredNode.place(nodeFrame(measuredNode, area)) };\n });\n const groups = areas.groups.map((groupArea) =>\n placeGroup(groupArea, titles.get(groupArea.group.id)!, lines, gutters),\n );\n\n const widestGutter = Math.max(\n ...[...gutters.row, ...gutters.col].map((gutter) => gutter.size),\n );\n const { edges, leaders } = routeGraph(\n ir,\n nodes,\n groups,\n areas,\n 2 * widestGutter,\n );\n\n return roundLayout({\n nodes,\n groups,\n edges,\n leaders,\n viewBox: viewBoxOf(nodes, groups, edges, leaders),\n });\n}\n\nfunction areaBox(area: CellArea, lines: Record<Axis, TrackLine>): Box {\n const x = lines.col.trackStart(area.col);\n const y = lines.row.trackStart(area.row);\n return {\n x,\n y,\n w: lines.col.trackEnd(area.col + area.colSpan - 1) - x,\n h: lines.row.trackEnd(area.row + area.rowSpan - 1) - y,\n };\n}\n\n/** A stretching node fills its area; any other node keeps its measured frame, centred in the area. */\nfunction nodeFrame(measured: MeasuredNode, area: Box): Box {\n const { frame, overhang, stretch } = measured;\n if (stretch) {\n return {\n x: area.x + overhang.left,\n y: area.y + overhang.top,\n w: area.w - overhang.left - overhang.right,\n h: area.h - overhang.top - overhang.bottom,\n };\n }\n const visualW = frame.w + overhang.left + overhang.right;\n const visualH = frame.h + overhang.top + overhang.bottom;\n return {\n x: area.x + (area.w - visualW) / 2 + overhang.left,\n y: area.y + (area.h - visualH) / 2 + overhang.top,\n ...frame,\n };\n}\n\n/** Each side of a group lies on the outer edge of its chrome slot in the gutter where the group opens or closes. */\nfunction placeGroup(\n { group, depth, area }: GroupArea,\n title: MeasuredGroupTitle,\n lines: Record<Axis, TrackLine>,\n gutters: GridGutters,\n): GroupLayout {\n const border = (axis: Axis, boundary: number, side: 'opening' | 'closing') =>\n lines[axis].gutterStart(boundary) +\n gutters[axis][boundary]![side].get(depth)!;\n const x = border('col', area.col, 'opening');\n const y = border('row', area.row, 'opening');\n const rect = {\n x,\n y,\n w: border('col', area.col + area.colSpan, 'closing') - x,\n h: border('row', area.row + area.rowSpan, 'closing') - y,\n };\n return {\n group,\n depth,\n rect,\n ...title.place(rect),\n dividers: group.dividers\n ? dividers(rect, area, title, group.labelSide, lines, gutters)\n : [],\n ports: placeGroupPorts(group.ports ?? [], rect),\n };\n}\n\n/** A line through the middle of every gutter inside the group, clear of its title. */\nfunction dividers(\n rect: Box,\n area: CellArea,\n title: MeasuredGroupTitle,\n labelSide: 'top' | 'bottom' | undefined,\n lines: Record<Axis, TrackLine>,\n gutters: GridGutters,\n): [Point, Point][] {\n const centre = (axis: Axis, boundary: number) =>\n lines[axis].gutterStart(boundary) + gutters[axis][boundary]!.size / 2;\n const titleAtBottom = labelSide === 'bottom';\n const top = rect.y + (titleAtBottom ? 0 : title.height);\n const bottom = rect.y + rect.h - (titleAtBottom ? title.height : 0);\n const inner = (start: number, span: number) =>\n Array.from({ length: span - 1 }, (_, index) => start + index + 1);\n return [\n ...inner(area.col, area.colSpan).map((boundary): [Point, Point] => {\n const x = centre('col', boundary);\n return [\n { x, y: top },\n { x, y: bottom },\n ];\n }),\n ...inner(area.row, area.rowSpan).map((boundary): [Point, Point] => {\n const y = centre('row', boundary);\n return [\n { x: rect.x, y },\n { x: rect.x + rect.w, y },\n ];\n }),\n ];\n}\n\nfunction viewBoxOf(\n nodes: NodeLayout[],\n groups: GroupLayout[],\n edges: RoutedGraph['edges'],\n leaders: RoutedGraph['leaders'],\n): Box {\n const pointBox = ({ x, y }: Point): Box => ({ x, y, w: 0, h: 0 });\n const boxes = [\n ...nodes.map((nodeLayout) => nodeLayout.visual),\n ...groups.map((groupLayout) => groupLayout.rect),\n ...edges.flatMap(({ points, label, badge }) => [\n ...points.map(pointBox),\n ...(label ? [label.box] : []),\n ...(badge ? [badge.box] : []),\n ]),\n ...leaders.flatMap(({ points }) => points.map(pointBox)),\n ];\n const pad = LAYOUT_TOKENS.CONTENT_PAD;\n if (boxes.length === 0) return { x: -pad, y: -pad, w: 2 * pad, h: 2 * pad };\n const left = Math.min(...boxes.map((box) => box.x));\n const top = Math.min(...boxes.map((box) => box.y));\n const right = Math.max(...boxes.map((box) => box.x + box.w));\n const bottom = Math.max(...boxes.map((box) => box.y + box.h));\n return {\n x: left - pad,\n y: top - pad,\n w: right - left + 2 * pad,\n h: bottom - top + 2 * pad,\n };\n}\n"],"mappings":"AACA,SAASA,aAAa,QAAQ,+BAA+B;AAC7D,SAAwCC,SAAS,QAAQ,YAAY;AAMrE,SAAsCC,WAAW,QAAQ,cAAc;AACvE,SAGEC,iBAAiB,EACjBC,WAAW,EACXC,eAAe,QACV,cAAc;AACrB,SAASC,WAAW,QAAQ,YAAY;AACxC,SAA2BC,UAAU,QAAQ,YAAY;AACzD,SAASC,aAAa,QAAQ,aAAa;AAC3C,SAAyBC,UAAU,QAAQ,aAAa;;AAExD;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,WAAWA,CAACC,EAAkB,EAAe;EAC3DX,aAAa,CAACW,EAAE,CAAC;EACjB,MAAMC,QAAQ,GAAG,IAAIC,GAAG,CACtBF,EAAE,CAACG,KAAK,CAACC,GAAG,CAAEC,IAAI,IAAK,CAACA,IAAI,CAACC,EAAE,EAAEb,WAAW,CAACY,IAAI,CAAC,CAAU,CAC9D,CAAC;EACD,MAAME,MAAM,GAAG,IAAIL,GAAG,CACpBF,EAAE,CAACQ,MAAM,CAACJ,GAAG,CAAEK,KAAK,IAAK,CAACA,KAAK,CAACH,EAAE,EAAEd,iBAAiB,CAACiB,KAAK,CAAC,CAAU,CACxE,CAAC;EACD,MAAMC,KAAK,GAAGpB,SAAS,CAACU,EAAE,CAAC;EAC3B,MAAMW,OAAO,GAAGpB,WAAW,CACzBmB,KAAK,EACL,IAAIR,GAAG,CAAC,CAAC,GAAGK,MAAM,CAAC,CAACH,GAAG,CAAC,CAAC,CAACE,EAAE,EAAEM,KAAK,CAAC,KAAK,CAACN,EAAE,EAAEM,KAAK,CAACC,MAAM,CAAC,CAAC,CAAC,EAC7Db,EAAE,CAACc,KACL,CAAC;EAED,MAAMC,KAAK,GAAIC,IAAU,IACvBhB,EAAE,CAACG,KAAK,CAACC,GAAG,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ACrC,IAAIV,KAAK,CAACJ,MAAM,KAAK,CAAC,EAAE,OAAO;IAAErB,CAAC,EAAE,CAACkC,GAAG;IAAEhC,CAAC,EAAE,CAACgC,GAAG;IAAEvD,CAAC,EAAE,CAAC,GAAGuD,GAAG;IAAE5D,CAAC,EAAE,CAAC,GAAG4D;EAAI,CAAC;EAC3E,MAAMtD,IAAI,GAAGe,IAAI,CAACyC,GAAG,CAAC,GAAGX,KAAK,CAACzE,GAAG,CAAEiF,GAAG,IAAKA,GAAG,CAACjC,CAAC,CAAC,CAAC;EACnD,MAAMzB,GAAG,GAAGoB,IAAI,CAACyC,GAAG,CAAC,GAAGX,KAAK,CAACzE,GAAG,CAAEiF,GAAG,IAAKA,GAAG,CAAC/B,CAAC,CAAC,CAAC;EAClD,MAAMrB,KAAK,GAAGc,IAAI,CAACC,GAAG,CAAC,GAAG6B,KAAK,CAACzE,GAAG,CAAEiF,GAAG,IAAKA,GAAG,CAACjC,CAAC,GAAGiC,GAAG,CAACtD,CAAC,CAAC,CAAC;EAC5D,MAAMH,MAAM,GAAGmB,IAAI,CAACC,GAAG,CAAC,GAAG6B,KAAK,CAACzE,GAAG,CAAEiF,GAAG,IAAKA,GAAG,CAAC/B,CAAC,GAAG+B,GAAG,CAAC3D,CAAC,CAAC,CAAC;EAC7D,OAAO;IACL0B,CAAC,EAAEpB,IAAI,GAAGsD,GAAG;IACbhC,CAAC,EAAE3B,GAAG,GAAG2D,GAAG;IACZvD,CAAC,EAAEE,KAAK,GAAGD,IAAI,GAAG,CAAC,GAAGsD,GAAG;IACzB5D,CAAC,EAAEE,MAAM,GAAGD,GAAG,GAAG,CAAC,GAAG2D;EACxB,CAAC;AACH","ignoreList":[]}
@@ -1,6 +1,5 @@
1
- import type { Box, DiagramEdge, DiagramGroup, DiagramNode, DiagramSide } from '../../model/diagram-ir.ts';
2
- import type { NodeLayout, TextRun } from './graph-layout-result.ts';
3
- import type { LayoutTokens } from './tokens.ts';
1
+ import type { Box, DiagramEdge, DiagramGroup, DiagramNode, DiagramNodePort, DiagramSide } from '../../model/diagram-ir.ts';
2
+ import type { GroupLayout, NodeLayout, TextRun } from './graph-layout-result.ts';
4
3
  type Sides = Record<DiagramSide, number>;
5
4
  export type MeasuredNode = {
6
5
  /** The smallest frame that holds the node's content. */
@@ -15,22 +14,21 @@ export type MeasuredNode = {
15
14
  /** Positions everything the node draws, given its final frame (at least `frame`). */
16
15
  place(box: Box): Omit<NodeLayout, 'node'>;
17
16
  };
18
- export declare function measureNode(node: DiagramNode, tokens: LayoutTokens): MeasuredNode;
17
+ export declare function measureNode(node: DiagramNode): MeasuredNode;
18
+ /** A group's ports sit evenly along their side of its rect, like a node's ports along its frame. */
19
+ export declare function placeGroupPorts(ports: DiagramNodePort[], rect: Box): NodeLayout['ports'];
19
20
  export type MeasuredGroupTitle = {
20
21
  /** The height the title reserves on its side, BAND_PAD above and below included; 0 without a label. */
21
22
  height: number;
22
- place(rect: Box): {
23
- band?: Box;
24
- label: TextRun[];
25
- };
23
+ place(rect: Box): Pick<GroupLayout, 'band' | 'separator' | 'label'>;
26
24
  };
27
- export declare function measureGroupTitle(group: DiagramGroup, tokens: LayoutTokens): MeasuredGroupTitle;
25
+ export declare function measureGroupTitle(group: DiagramGroup): MeasuredGroupTitle;
28
26
  export type MeasuredEdgeLabel = {
29
27
  w: number;
30
28
  h: number;
31
29
  place(box: Box): TextRun[];
32
30
  };
33
- export declare function measureEdgeLabel(edge: DiagramEdge, tokens: LayoutTokens): MeasuredEdgeLabel;
31
+ export declare function measureEdgeLabel(edge: DiagramEdge): MeasuredEdgeLabel;
34
32
  export type MeasuredEdgeBadge = {
35
33
  w: number;
36
34
  h: number;
@@ -39,6 +37,12 @@ export type MeasuredEdgeBadge = {
39
37
  text: TextRun[];
40
38
  };
41
39
  };
42
- export declare function measureEdgeBadge(edge: DiagramEdge, tokens: LayoutTokens): MeasuredEdgeBadge;
40
+ export declare function measureEdgeBadge(edge: DiagramEdge): MeasuredEdgeBadge;
41
+ export type MeasuredEdgeTags = {
42
+ label?: MeasuredEdgeLabel;
43
+ badge?: MeasuredEdgeBadge;
44
+ };
45
+ /** What an edge carries along its route: a label beside it and a badge on it, each only when the edge has one. */
46
+ export declare function measureEdgeTags(edge: DiagramEdge): MeasuredEdgeTags;
43
47
  export {};
44
48
  //# sourceMappingURL=measure.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"measure.d.ts","sourceRoot":"","sources":["../../../../src/lib/layouts/graph/measure.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,GAAG,EACH,WAAW,EACX,YAAY,EACZ,WAAW,EAEX,WAAW,EACZ,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAGpE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD,KAAK,KAAK,GAAG,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;AAEzC,MAAM,MAAM,YAAY,GAAG;IACzB,wDAAwD;IACxD,KAAK,EAAE;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAChC,0EAA0E;IAC1E,QAAQ,EAAE,KAAK,CAAC;IAChB,qDAAqD;IACrD,OAAO,EAAE,OAAO,CAAC;IACjB,qFAAqF;IACrF,KAAK,CAAC,GAAG,EAAE,GAAG,GAAG,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;CAC3C,CAAC;AAWF,wBAAgB,WAAW,CACzB,IAAI,EAAE,WAAW,EACjB,MAAM,EAAE,YAAY,GACnB,YAAY,CAiDd;AA6MD,MAAM,MAAM,kBAAkB,GAAG;IAC/B,uGAAuG;IACvG,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,IAAI,EAAE,GAAG,GAAG;QAAE,IAAI,CAAC,EAAE,GAAG,CAAC;QAAC,KAAK,EAAE,OAAO,EAAE,CAAA;KAAE,C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B,CAAC;CAC3B,CAAC;AAEF,kHAAkH;AAClH,wBAAgB,eAAe,CAAC,IAAI,EAAE,WAAW,GAAG,gBAAgB,CAOnE"}
@@ -1,5 +1,6 @@
1
1
  import { nodeContent } from "./node-content.js";
2
2
  import { labelLines, textBlock } from "./text-block.js";
3
+ import { LAYOUT_TOKENS } from "./tokens.js";
3
4
  /** The distance from a port's point to its label: the port marker's radius plus a gap. */
4
5
  const PORT_LABEL_OFFSET = 8;
5
6
  const EDGE_LABEL_FRAME_PAD = 4;
@@ -10,11 +11,11 @@ const BADGE_PAD = {
10
11
  };
11
12
  const BADGE_MIN_CONTENT = 24;
12
13
  const SIDES = ['top', 'right', 'bottom', 'left'];
13
- export function measureNode(node, tokens) {
14
+ export function measureNode(node) {
14
15
  const kind = node.kind ?? 'node';
15
16
  if (node.hidden && kind === 'node') return hiddenNode();
16
- const content = nodeContent(node, tokens);
17
- const ports = portGeometry(node.ports ?? [], tokens);
17
+ const content = nodeContent(node);
18
+ const ports = portGeometry(node.ports ?? []);
18
19
  const w = Math.max(content.w + 2 * content.pad.x + ports.inset.left + ports.inset.right, ports.minLength.top, ports.minLength.bottom);
19
20
  const h = Math.max(content.h + 2 * content.pad.y + ports.inset.top + ports.inset.bottom, ports.minLength.left, ports.minLength.right);
20
21
  const place = box => {
@@ -24,13 +25,13 @@ export function measureNode(node, tokens) {
24
25
  left: content.pad.x,
25
26
  right: content.pad.x
26
27
  });
27
- const frames = stackFrames(node, box, tokens);
28
- const caption = placeCaption(node, union([box, ...frames]), tokens);
28
+ const frames = stackFrames(node, box);
29
+ const caption = placeCaption(node, union([box, ...frames]));
29
30
  return {
30
31
  box,
31
32
  visual: union([box, ...frames, ...(caption ? [caption.box] : [])]),
32
33
  frames,
33
- radius: frameRadius(node, box, tokens),
34
+ radius: frameRadius(node, box),
34
35
  ...content.place(inner),
35
36
  ...(caption ? {
36
37
  caption
@@ -39,25 +40,43 @@ export function measureNode(node, tokens) {
39
40
  };
40
41
  };
41
42
  const {
42
- visual
43
+ visual,
44
+ frames
43
45
  } = place({
44
46
  x: 0,
45
47
  y: 0,
46
48
  w,
47
49
  h
48
50
  });
51
+ const outside = outer => ({
52
+ top: 0 - outer.y,
53
+ left: 0 - outer.x,
54
+ bottom: outer.y + outer.h - h,
55
+ right: outer.x + outer.w - w
56
+ });
57
+ const stack = outside(union([{
58
+ x: 0,
59
+ y: 0,
60
+ w,
61
+ h
62
+ }, ...frames]));
63
+ const all = outside(visual);
64
+ // A caption reserves its room on both sides of the frame, so the frames of a row (or column) stay on one centre line whichever side their captions hang.
65
+ const caption = (a, b) => Math.max(all[a] - stack[a], all[b] - stack[b]);
66
+ const vertical = caption('top', 'bottom');
67
+ const horizontal = caption('left', 'right');
49
68
  return {
50
69
  frame: {
51
70
  w,
52
71
  h
53
72
  },
54
73
  overhang: {
55
- top: 0 - visual.y,
56
- left: 0 - visual.x,
57
- bottom: visual.y + visual.h - h,
58
- right: visual.x + visual.w - w
74
+ top: stack.top + vertical,
75
+ bottom: stack.bottom + vertical,
76
+ left: stack.left + horizontal,
77
+ right: stack.right + horizontal
59
78
  },
60
- stretch: kind === 'node' && (node.stretch ?? true),
79
+ stretch: kind === 'node',
61
80
  place
62
81
  };
63
82
  }
@@ -85,7 +104,7 @@ function hiddenNode() {
85
104
  })
86
105
  };
87
106
  }
88
- function frameRadius(node, box, tokens) {
107
+ function frameRadius(node, box) {
89
108
  switch (node.kind) {
90
109
  case 'connector':
91
110
  return box.h / 2;
@@ -97,7 +116,7 @@ function frameRadius(node, box, tokens) {
97
116
  return 0;
98
117
  default:
99
118
  if (node.frame === 'none') return 0;
100
- return node.frame === 'flat' ? tokens.FLAT_RADIUS : tokens.RADIUS;
119
+ return node.frame === 'flat' ? LAYOUT_TOKENS.FLAT_RADIUS : LAYOUT_TOKENS.RADIUS;
101
120
  }
102
121
  }
103
122
 
@@ -106,8 +125,8 @@ function frameRadius(node, box, tokens) {
106
125
  * side's labels push the content inward, and a side with k ports is long
107
126
  * enough for k + 1 port spacings.
108
127
  */
109
- function portGeometry(ports, tokens) {
110
- const font = tokens.fonts.portLabel;
128
+ function portGeometry(ports) {
129
+ const font = LAYOUT_TOKENS.fonts.portLabel;
111
130
  const bySide = new Map(SIDES.map(side => [side, ports.filter(port => port.side === side).map(port => ({
112
131
  port,
113
132
  label: port.label ? textBlock(labelLines(port.label, port.accent ? 'accent' : undefined), font) : undefined
@@ -126,7 +145,7 @@ function portGeometry(ports, tokens) {
126
145
  const count = bySide.get(side).length;
127
146
  if (count === 0) return 0;
128
147
  const labelLength = side === 'top' || side === 'bottom' ? widest(side) : tallest(side);
129
- const pitch = Math.max(tokens.PORT_SPACING, labelLength + tokens.LABEL_GAP);
148
+ const pitch = Math.max(LAYOUT_TOKENS.PORT_SPACING, labelLength + LAYOUT_TOKENS.LABEL_GAP);
130
149
  return (count + 1) * pitch;
131
150
  };
132
151
  return {
@@ -154,6 +173,11 @@ function portGeometry(ports, tokens) {
154
173
  };
155
174
  }
156
175
 
176
+ /** A group's ports sit evenly along their side of its rect, like a node's ports along its frame. */
177
+ export function placeGroupPorts(ports, rect) {
178
+ return portGeometry(ports).place(rect);
179
+ }
180
+
157
181
  /** The point `fraction` of the way along `side` of `box`. */
158
182
  function portPoint(box, side, fraction) {
159
183
  switch (side) {
@@ -193,13 +217,13 @@ function placePortLabel(label, point, side) {
193
217
  }
194
218
 
195
219
  /** The back frames of a stack, farthest first, each one STACK_STEP further in the stack direction. */
196
- function stackFrames(node, box, tokens) {
220
+ function stackFrames(node, box) {
197
221
  const count = Math.max(1, Math.floor(node.stack ?? 1));
198
222
  const kind = node.kind ?? 'node';
199
223
  if (count === 1 || kind !== 'node' || node.frame === 'none') return [];
200
224
  const direction = node.stackDirection ?? 'up-left';
201
- const dx = (direction.endsWith('left') ? -1 : 1) * tokens.STACK_STEP.x;
202
- const dy = (direction.startsWith('up') ? -1 : 1) * tokens.STACK_STEP.y;
225
+ const dx = (direction.endsWith('left') ? -1 : 1) * LAYOUT_TOKENS.STACK_STEP.x;
226
+ const dy = (direction.startsWith('up') ? -1 : 1) * LAYOUT_TOKENS.STACK_STEP.y;
203
227
  return Array.from({
204
228
  length: count - 1
205
229
  }, (_, index) => {
@@ -213,8 +237,8 @@ function stackFrames(node, box, tokens) {
213
237
  }
214
238
 
215
239
  /** The caption sits beside `box`, the frame together with its stacked back frames. */
216
- function placeCaption(node, box, tokens) {
217
- const font = tokens.fonts.caption;
240
+ function placeCaption(node, box) {
241
+ const font = LAYOUT_TOKENS.fonts.caption;
218
242
  const lines = textBlock(labelLines([node.caption ?? []].flat().map(line => line.trim()), node.captionColor), font);
219
243
  if (lines.h === 0) return undefined;
220
244
  const framed = node.captionFrame ?? false;
@@ -227,7 +251,7 @@ function placeCaption(node, box, tokens) {
227
251
  };
228
252
  const w = lines.w + 2 * pad.x;
229
253
  const h = lines.h + 2 * pad.y;
230
- const gap = tokens.CAPTION_GAP;
254
+ const gap = LAYOUT_TOKENS.CAPTION_GAP;
231
255
  const side = node.captionSide ?? 'bottom';
232
256
  const centreX = box.x + (box.w - w) / 2;
233
257
  const centreY = box.y + (box.h - h) / 2;
@@ -272,9 +296,9 @@ function placeCaption(node, box, tokens) {
272
296
  text
273
297
  };
274
298
  }
275
- export function measureGroupTitle(group, tokens) {
276
- const lines = textBlock(labelLines(group.label), tokens.fonts.groupLabel);
277
- const height = lines.h > 0 ? lines.h + 2 * tokens.BAND_PAD : 0;
299
+ export function measureGroupTitle(group) {
300
+ const lines = textBlock(labelLines(group.label), LAYOUT_TOKENS.fonts.groupLabel);
301
+ const height = lines.h > 0 ? lines.h + 2 * LAYOUT_TOKENS.BAND_PAD : 0;
278
302
  return {
279
303
  height,
280
304
  place(rect) {
@@ -282,32 +306,41 @@ export function measureGroupTitle(group, tokens) {
282
306
  label: []
283
307
  };
284
308
  const y = group.labelSide === 'bottom' ? rect.y + rect.h - height : rect.y;
285
- const top = y + tokens.BAND_PAD;
309
+ const top = y + LAYOUT_TOKENS.BAND_PAD;
286
310
  const align = group.labelAlign ?? 'center';
287
311
  let label;
288
312
  if (align === 'start') {
289
- label = lines.place(rect.x + tokens.PAD_X, top, 'start');
313
+ label = lines.place(rect.x + LAYOUT_TOKENS.PAD_X, top, 'start');
290
314
  } else if (align === 'end') {
291
- label = lines.place(rect.x + rect.w - tokens.PAD_X, top, 'end');
315
+ label = lines.place(rect.x + rect.w - LAYOUT_TOKENS.PAD_X, top, 'end');
292
316
  } else {
293
317
  label = lines.place(rect.x + rect.w / 2, top, 'middle');
294
318
  }
295
- return group.titleBand ? {
319
+ if (!group.titleBand) return {
320
+ label
321
+ };
322
+ const edge = group.labelSide === 'bottom' ? y : y + height;
323
+ return {
296
324
  band: {
297
325
  x: rect.x,
298
326
  y,
299
327
  w: rect.w,
300
328
  h: height
301
329
  },
302
- label
303
- } : {
330
+ separator: [{
331
+ x: rect.x,
332
+ y: edge
333
+ }, {
334
+ x: rect.x + rect.w,
335
+ y: edge
336
+ }],
304
337
  label
305
338
  };
306
339
  }
307
340
  };
308
341
  }
309
- export function measureEdgeLabel(edge, tokens) {
310
- const lines = textBlock(labelLines(edge.label), tokens.fonts.edgeLabel);
342
+ export function measureEdgeLabel(edge) {
343
+ const lines = textBlock(labelLines(edge.label), LAYOUT_TOKENS.fonts.edgeLabel);
311
344
  const pad = edge.labelFrame ? EDGE_LABEL_FRAME_PAD : 0;
312
345
  return {
313
346
  w: lines.w + 2 * pad,
@@ -315,10 +348,10 @@ export function measureEdgeLabel(edge, tokens) {
315
348
  place: box => lines.place(box.x + box.w / 2, box.y + pad, 'middle')
316
349
  };
317
350
  }
318
- export function measureEdgeBadge(edge, tokens) {
319
- const lines = textBlock(labelLines(edge.badgeLabel), tokens.fonts.badge);
320
- const icon = edge.badgeIcon ? tokens.BADGE_ICON : 0;
321
- const gap = icon > 0 && lines.w > 0 ? tokens.BLOCK_GAP : 0;
351
+ export function measureEdgeBadge(edge) {
352
+ const lines = textBlock(labelLines(edge.badgeLabel), LAYOUT_TOKENS.fonts.badge);
353
+ const icon = edge.badgeIcon ? LAYOUT_TOKENS.BADGE_ICON : 0;
354
+ const gap = icon > 0 && lines.w > 0 ? LAYOUT_TOKENS.BLOCK_GAP : 0;
322
355
  const rowW = icon + gap + lines.w;
323
356
  return {
324
357
  w: Math.max(BADGE_MIN_CONTENT, rowW) + 2 * BADGE_PAD.x,
@@ -341,6 +374,17 @@ export function measureEdgeBadge(edge, tokens) {
341
374
  }
342
375
  };
343
376
  }
377
+ /** What an edge carries along its route: a label beside it and a badge on it, each only when the edge has one. */
378
+ export function measureEdgeTags(edge) {
379
+ return {
380
+ ...(edge.label?.length ? {
381
+ label: measureEdgeLabel(edge)
382
+ } : {}),
383
+ ...(edge.badgeIcon || edge.badgeLabel?.length ? {
384
+ badge: measureEdgeBadge(edge)
385
+ } : {})
386
+ };
387
+ }
344
388
  function sidesOf(value) {
345
389
  return {
346
390
  top: value('top'),