@md2nativedocx/core 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/diagrams/architecture-diagram/icons.d.ts +24 -0
- package/dist/diagrams/architecture-diagram/icons.js +148 -0
- package/dist/diagrams/architecture-diagram/icons.js.map +1 -0
- package/dist/diagrams/architecture-diagram/layout.d.ts +71 -0
- package/dist/diagrams/architecture-diagram/layout.js +388 -0
- package/dist/diagrams/architecture-diagram/layout.js.map +1 -0
- package/dist/diagrams/architecture-diagram/parser.d.ts +14 -19
- package/dist/diagrams/architecture-diagram/parser.js +316 -113
- package/dist/diagrams/architecture-diagram/parser.js.map +1 -1
- package/dist/diagrams/architecture-diagram/translator.d.ts +26 -36
- package/dist/diagrams/architecture-diagram/translator.js +234 -147
- package/dist/diagrams/architecture-diagram/translator.js.map +1 -1
- package/dist/diagrams/architecture-diagram/types.d.ts +26 -16
- package/dist/diagrams/architecture-diagram/types.js +4 -14
- package/dist/diagrams/architecture-diagram/types.js.map +1 -1
- package/dist/diagrams/c4/parser.d.ts +11 -19
- package/dist/diagrams/c4/parser.js +242 -90
- package/dist/diagrams/c4/parser.js.map +1 -1
- package/dist/diagrams/c4/translator.d.ts +23 -43
- package/dist/diagrams/c4/translator.js +333 -204
- package/dist/diagrams/c4/translator.js.map +1 -1
- package/dist/diagrams/c4/types.d.ts +78 -45
- package/dist/diagrams/c4/types.js +17 -38
- package/dist/diagrams/c4/types.js.map +1 -1
- package/dist/diagrams/class-diagram/parser.d.ts +10 -11
- package/dist/diagrams/class-diagram/parser.js +316 -74
- package/dist/diagrams/class-diagram/parser.js.map +1 -1
- package/dist/diagrams/class-diagram/translator.d.ts +5 -0
- package/dist/diagrams/class-diagram/translator.js +292 -24
- package/dist/diagrams/class-diagram/translator.js.map +1 -1
- package/dist/diagrams/class-diagram/types.d.ts +61 -4
- package/dist/diagrams/er-diagram/parser.d.ts +22 -19
- package/dist/diagrams/er-diagram/parser.js +412 -89
- package/dist/diagrams/er-diagram/parser.js.map +1 -1
- package/dist/diagrams/er-diagram/translator.d.ts +8 -0
- package/dist/diagrams/er-diagram/translator.js +170 -38
- package/dist/diagrams/er-diagram/translator.js.map +1 -1
- package/dist/diagrams/er-diagram/types.d.ts +32 -5
- package/dist/diagrams/er-diagram/types.js +2 -5
- package/dist/diagrams/er-diagram/types.js.map +1 -1
- package/dist/diagrams/gantt/date-utils.d.ts +55 -33
- package/dist/diagrams/gantt/date-utils.js +147 -58
- package/dist/diagrams/gantt/date-utils.js.map +1 -1
- package/dist/diagrams/gantt/parser.d.ts +31 -22
- package/dist/diagrams/gantt/parser.js +259 -141
- package/dist/diagrams/gantt/parser.js.map +1 -1
- package/dist/diagrams/gantt/time-axis.d.ts +44 -0
- package/dist/diagrams/gantt/time-axis.js +158 -0
- package/dist/diagrams/gantt/time-axis.js.map +1 -0
- package/dist/diagrams/gantt/translator.d.ts +8 -5
- package/dist/diagrams/gantt/translator.js +67 -56
- package/dist/diagrams/gantt/translator.js.map +1 -1
- package/dist/diagrams/gantt/types.d.ts +25 -4
- package/dist/diagrams/gantt/types.js +4 -3
- package/dist/diagrams/gantt/types.js.map +1 -1
- package/dist/diagrams/mindmap/parser.d.ts +18 -14
- package/dist/diagrams/mindmap/parser.js +169 -69
- package/dist/diagrams/mindmap/parser.js.map +1 -1
- package/dist/diagrams/mindmap/translator.js +88 -35
- package/dist/diagrams/mindmap/translator.js.map +1 -1
- package/dist/diagrams/mindmap/types.d.ts +18 -0
- package/dist/diagrams/plantuml/class-parser.d.ts +2 -1
- package/dist/diagrams/plantuml/class-parser.js +19 -11
- package/dist/diagrams/plantuml/class-parser.js.map +1 -1
- package/dist/diagrams/plantuml/sequence-parser.d.ts +3 -2
- package/dist/diagrams/plantuml/sequence-parser.js +28 -12
- package/dist/diagrams/plantuml/sequence-parser.js.map +1 -1
- package/dist/diagrams/plantuml/state-parser.d.ts +5 -3
- package/dist/diagrams/plantuml/state-parser.js +141 -19
- package/dist/diagrams/plantuml/state-parser.js.map +1 -1
- package/dist/diagrams/requirement-diagram/parser.d.ts +26 -19
- package/dist/diagrams/requirement-diagram/parser.js +249 -70
- package/dist/diagrams/requirement-diagram/parser.js.map +1 -1
- package/dist/diagrams/requirement-diagram/translator.d.ts +16 -11
- package/dist/diagrams/requirement-diagram/translator.js +170 -50
- package/dist/diagrams/requirement-diagram/translator.js.map +1 -1
- package/dist/diagrams/requirement-diagram/types.d.ts +30 -9
- package/dist/diagrams/requirement-diagram/types.js +7 -5
- package/dist/diagrams/requirement-diagram/types.js.map +1 -1
- package/dist/diagrams/sequence/parser.d.ts +8 -7
- package/dist/diagrams/sequence/parser.js +100 -31
- package/dist/diagrams/sequence/parser.js.map +1 -1
- package/dist/diagrams/sequence/participant-glyph.d.ts +38 -0
- package/dist/diagrams/sequence/participant-glyph.js +97 -0
- package/dist/diagrams/sequence/participant-glyph.js.map +1 -0
- package/dist/diagrams/sequence/participant-kind.d.ts +7 -0
- package/dist/diagrams/sequence/participant-kind.js +19 -0
- package/dist/diagrams/sequence/participant-kind.js.map +1 -0
- package/dist/diagrams/sequence/translator.d.ts +7 -3
- package/dist/diagrams/sequence/translator.js +134 -25
- package/dist/diagrams/sequence/translator.js.map +1 -1
- package/dist/diagrams/sequence/types.d.ts +24 -1
- package/dist/diagrams/state-diagram/parser.d.ts +24 -24
- package/dist/diagrams/state-diagram/parser.js +259 -73
- package/dist/diagrams/state-diagram/parser.js.map +1 -1
- package/dist/diagrams/state-diagram/translator.d.ts +13 -1
- package/dist/diagrams/state-diagram/translator.js +554 -72
- package/dist/diagrams/state-diagram/translator.js.map +1 -1
- package/dist/diagrams/state-diagram/types.d.ts +57 -11
- package/dist/diagrams/state-diagram/types.js +5 -7
- package/dist/diagrams/state-diagram/types.js.map +1 -1
- package/dist/diagrams/tree-view/implicit-root.d.ts +11 -0
- package/dist/diagrams/tree-view/implicit-root.js +14 -0
- package/dist/diagrams/tree-view/implicit-root.js.map +1 -0
- package/dist/diagrams/tree-view/parser.d.ts +23 -8
- package/dist/diagrams/tree-view/parser.js +242 -98
- package/dist/diagrams/tree-view/parser.js.map +1 -1
- package/dist/diagrams/tree-view/translator.d.ts +6 -5
- package/dist/diagrams/tree-view/translator.js +40 -23
- package/dist/diagrams/tree-view/translator.js.map +1 -1
- package/dist/diagrams/tree-view/types.d.ts +22 -6
- package/dist/diagrams/tree-view/types.js +2 -2
- package/dist/diagrams/treemap/parser.d.ts +2 -2
- package/dist/diagrams/treemap/parser.js +5 -12
- package/dist/diagrams/treemap/parser.js.map +1 -1
- package/dist/diagrams/zenuml/parser.d.ts +2 -2
- package/dist/diagrams/zenuml/parser.js +14 -7
- package/dist/diagrams/zenuml/parser.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/layout/collapse-subgraphs.d.ts +18 -0
- package/dist/layout/collapse-subgraphs.js +80 -0
- package/dist/layout/collapse-subgraphs.js.map +1 -0
- package/dist/layout/layout.d.ts +9 -0
- package/dist/layout/layout.js +77 -17
- package/dist/layout/layout.js.map +1 -1
- package/dist/parser/css-named-colors.d.ts +7 -0
- package/dist/parser/css-named-colors.js +157 -0
- package/dist/parser/css-named-colors.js.map +1 -0
- package/dist/parser/css-style.d.ts +39 -0
- package/dist/parser/css-style.js +88 -0
- package/dist/parser/css-style.js.map +1 -0
- package/dist/parser/entities.d.ts +5 -0
- package/dist/parser/entities.js +52 -0
- package/dist/parser/entities.js.map +1 -0
- package/dist/parser/frontmatter.d.ts +4 -2
- package/dist/parser/frontmatter.js +7 -5
- package/dist/parser/frontmatter.js.map +1 -1
- package/dist/parser/label.d.ts +37 -0
- package/dist/parser/label.js +73 -0
- package/dist/parser/label.js.map +1 -0
- package/dist/parser/parser.d.ts +2 -1
- package/dist/parser/parser.js +295 -329
- package/dist/parser/parser.js.map +1 -1
- package/dist/render-diagram-odf.d.ts +2 -1
- package/dist/render-diagram-odf.js +20 -5
- package/dist/render-diagram-odf.js.map +1 -1
- package/dist/render-diagram.d.ts +11 -3
- package/dist/render-diagram.js +44 -21
- package/dist/render-diagram.js.map +1 -1
- package/dist/smartart/chain.js +1 -1
- package/dist/smartart/chain.js.map +1 -1
- package/dist/smartart/cycle.js +1 -1
- package/dist/smartart/cycle.js.map +1 -1
- package/dist/smartart/drawing.js +2 -10
- package/dist/smartart/drawing.js.map +1 -1
- package/dist/smartart/embed.d.ts +4 -3
- package/dist/smartart/embed.js +5 -4
- package/dist/smartart/embed.js.map +1 -1
- package/dist/smartart/from-graph.d.ts +13 -3
- package/dist/smartart/from-graph.js +39 -7
- package/dist/smartart/from-graph.js.map +1 -1
- package/dist/smartart/from-tree.d.ts +9 -5
- package/dist/smartart/from-tree.js +23 -11
- package/dist/smartart/from-tree.js.map +1 -1
- package/dist/smartart/text.d.ts +18 -4
- package/dist/smartart/text.js +32 -8
- package/dist/smartart/text.js.map +1 -1
- package/dist/smartart/tree-deep.js +1 -1
- package/dist/smartart/tree-deep.js.map +1 -1
- package/dist/smartart/tree.js +2 -2
- package/dist/smartart/tree.js.map +1 -1
- package/dist/translator/boxes.d.ts +1 -1
- package/dist/translator/canvas.d.ts +9 -1
- package/dist/translator/canvas.js +19 -16
- package/dist/translator/canvas.js.map +1 -1
- package/dist/translator/custom-geometry.d.ts +28 -0
- package/dist/translator/custom-geometry.js +59 -0
- package/dist/translator/custom-geometry.js.map +1 -0
- package/dist/translator/elbow-connector.d.ts +52 -0
- package/dist/translator/elbow-connector.js +110 -0
- package/dist/translator/elbow-connector.js.map +1 -0
- package/dist/translator/graph-shapes.d.ts +17 -4
- package/dist/translator/graph-shapes.js +25 -6
- package/dist/translator/graph-shapes.js.map +1 -1
- package/dist/translator/label-runs.d.ts +14 -0
- package/dist/translator/label-runs.js +36 -0
- package/dist/translator/label-runs.js.map +1 -0
- package/dist/translator/odf-translator.js +20 -22
- package/dist/translator/odf-translator.js.map +1 -1
- package/dist/translator/ooxml-translator.d.ts +17 -11
- package/dist/translator/ooxml-translator.js +73 -139
- package/dist/translator/ooxml-translator.js.map +1 -1
- package/dist/translator/text-color.d.ts +9 -0
- package/dist/translator/text-color.js +17 -0
- package/dist/translator/text-color.js.map +1 -0
- package/dist/types.d.ts +20 -3
- package/package.json +1 -1
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The icons Mermaid 12.3 builds into `architecture-beta` (`cloud`, `database`, `disk`, `internet`,
|
|
3
|
+
* `server`, plus `blank` and the `?` it shows for an icon it does not have), drawn as DrawingML paths:
|
|
4
|
+
* white strokes on a blue square, as Mermaid shows them. The drawings are this project's own, in the
|
|
5
|
+
* same spirit as Mermaid's (a rack, a cylinder, a hard disk, a globe, a cloud); none of its path data is
|
|
6
|
+
* reused.
|
|
7
|
+
*
|
|
8
|
+
* Each glyph is authored in an 80-unit square (Mermaid's icon size) and placed by a {@link Pen} into the
|
|
9
|
+
* coordinates of the shape that carries it, so an icon and its label stay one shape in Word.
|
|
10
|
+
*/
|
|
11
|
+
/** Mermaid's icon background. */
|
|
12
|
+
export declare const ICON_FILL = "087EBF";
|
|
13
|
+
export declare const ICON_STROKE = "FFFFFF";
|
|
14
|
+
/** Icon names Mermaid draws without any icon pack. */
|
|
15
|
+
export declare const BUILT_IN_ICONS: ReadonlySet<string>;
|
|
16
|
+
/**
|
|
17
|
+
* The paths of icon `name` in a square of `size` px at (`x`, `y`) of a shape: the blue square (filled, no
|
|
18
|
+
* outline) and the white glyph (outlined, unfilled). An icon Mermaid does not build in gets its `?`.
|
|
19
|
+
*/
|
|
20
|
+
export declare function iconPaths(name: string, x: number, y: number, size: number): Array<['norm', string, {
|
|
21
|
+
stroke: false;
|
|
22
|
+
}] | ['none', string]>;
|
|
23
|
+
/** The outline Mermaid draws for a service without an icon: rounded top corners, flat bottom. */
|
|
24
|
+
export declare function bareServicePath(x: number, y: number, size: number): string;
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The icons Mermaid 12.3 builds into `architecture-beta` (`cloud`, `database`, `disk`, `internet`,
|
|
3
|
+
* `server`, plus `blank` and the `?` it shows for an icon it does not have), drawn as DrawingML paths:
|
|
4
|
+
* white strokes on a blue square, as Mermaid shows them. The drawings are this project's own, in the
|
|
5
|
+
* same spirit as Mermaid's (a rack, a cylinder, a hard disk, a globe, a cloud); none of its path data is
|
|
6
|
+
* reused.
|
|
7
|
+
*
|
|
8
|
+
* Each glyph is authored in an 80-unit square (Mermaid's icon size) and placed by a {@link Pen} into the
|
|
9
|
+
* coordinates of the shape that carries it, so an icon and its label stay one shape in Word.
|
|
10
|
+
*/
|
|
11
|
+
import { pathUnits } from '../../translator/custom-geometry.js';
|
|
12
|
+
/** Mermaid's icon background. */
|
|
13
|
+
export const ICON_FILL = '087EBF';
|
|
14
|
+
export const ICON_STROKE = 'FFFFFF';
|
|
15
|
+
/** Icon names Mermaid draws without any icon pack. */
|
|
16
|
+
export const BUILT_IN_ICONS = new Set(['cloud', 'database', 'disk', 'internet', 'server', 'blank']);
|
|
17
|
+
const DEG = 60000;
|
|
18
|
+
/** Writes path operations for a glyph authored in an 80-unit square, placed at (`ox`, `oy`) and `size` px wide. */
|
|
19
|
+
class Pen {
|
|
20
|
+
ox;
|
|
21
|
+
oy;
|
|
22
|
+
ops = [];
|
|
23
|
+
k;
|
|
24
|
+
constructor(ox, oy, size) {
|
|
25
|
+
this.ox = ox;
|
|
26
|
+
this.oy = oy;
|
|
27
|
+
this.k = size / 80;
|
|
28
|
+
}
|
|
29
|
+
pt(x, y) {
|
|
30
|
+
return `<a:pt x="${pathUnits(this.ox + x * this.k)}" y="${pathUnits(this.oy + y * this.k)}"/>`;
|
|
31
|
+
}
|
|
32
|
+
move(x, y) {
|
|
33
|
+
this.ops.push(`<a:moveTo>${this.pt(x, y)}</a:moveTo>`);
|
|
34
|
+
return this;
|
|
35
|
+
}
|
|
36
|
+
line(x, y) {
|
|
37
|
+
this.ops.push(`<a:lnTo>${this.pt(x, y)}</a:lnTo>`);
|
|
38
|
+
return this;
|
|
39
|
+
}
|
|
40
|
+
/** An arc of the ellipse (`rx`, `ry`) the current point lies on at `start` degrees, turning `sweep` degrees (clockwise on screen when positive). */
|
|
41
|
+
arc(rx, ry, start, sweep) {
|
|
42
|
+
this.ops.push(`<a:arcTo wR="${pathUnits(rx * this.k)}" hR="${pathUnits(ry * this.k)}" stAng="${Math.round(start * DEG)}" swAng="${Math.round(sweep * DEG)}"/>`);
|
|
43
|
+
return this;
|
|
44
|
+
}
|
|
45
|
+
/** From the current point, which lies on the circle centred at (`cx`, `cy`), round to the `end` angle (degrees, clockwise). */
|
|
46
|
+
arcAround(cx, cy, fromX, fromY, end) {
|
|
47
|
+
const r = Math.hypot(fromX - cx, fromY - cy);
|
|
48
|
+
const start = (Math.atan2(fromY - cy, fromX - cx) * 180) / Math.PI;
|
|
49
|
+
let sweep = end - start;
|
|
50
|
+
while (sweep <= 0)
|
|
51
|
+
sweep += 360;
|
|
52
|
+
while (sweep > 360)
|
|
53
|
+
sweep -= 360;
|
|
54
|
+
return this.arc(r, r, start, sweep);
|
|
55
|
+
}
|
|
56
|
+
close() {
|
|
57
|
+
this.ops.push('<a:close/>');
|
|
58
|
+
return this;
|
|
59
|
+
}
|
|
60
|
+
circle(cx, cy, r) {
|
|
61
|
+
return this.move(cx - r, cy).arc(r, r, 180, 360).close();
|
|
62
|
+
}
|
|
63
|
+
ellipse(cx, cy, rx, ry) {
|
|
64
|
+
return this.move(cx - rx, cy).arc(rx, ry, 180, 360).close();
|
|
65
|
+
}
|
|
66
|
+
segment(x1, y1, x2, y2) {
|
|
67
|
+
return this.move(x1, y1).line(x2, y2);
|
|
68
|
+
}
|
|
69
|
+
/** A rectangle with corners of radius `r`. */
|
|
70
|
+
box(x, y, w, h, r) {
|
|
71
|
+
if (r <= 0)
|
|
72
|
+
return this.move(x, y).line(x + w, y).line(x + w, y + h).line(x, y + h).close();
|
|
73
|
+
return this.move(x + r, y)
|
|
74
|
+
.line(x + w - r, y)
|
|
75
|
+
.arc(r, r, 270, 90)
|
|
76
|
+
.line(x + w, y + h - r)
|
|
77
|
+
.arc(r, r, 0, 90)
|
|
78
|
+
.line(x + r, y + h)
|
|
79
|
+
.arc(r, r, 90, 90)
|
|
80
|
+
.line(x, y + r)
|
|
81
|
+
.arc(r, r, 180, 90)
|
|
82
|
+
.close();
|
|
83
|
+
}
|
|
84
|
+
toString() {
|
|
85
|
+
return this.ops.join('');
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
function server(p) {
|
|
89
|
+
p.box(18, 18, 44, 44, 2).segment(18, 32.5, 62, 32.5).segment(18, 47.5, 62, 47.5);
|
|
90
|
+
for (const y of [25.25, 40, 54.75]) {
|
|
91
|
+
p.segment(44, y, 56, y);
|
|
92
|
+
for (const x of [23, 28, 33])
|
|
93
|
+
p.circle(x, y, 0.8);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
function database(p) {
|
|
97
|
+
p.ellipse(40, 23, 20, 7).segment(20, 23, 20, 57).segment(60, 23, 60, 57);
|
|
98
|
+
for (const y of [35, 46, 57])
|
|
99
|
+
p.move(20, y).arc(20, 7, 180, -180);
|
|
100
|
+
}
|
|
101
|
+
function disk(p) {
|
|
102
|
+
p.box(21, 15, 38, 50, 1.5).circle(40, 34, 13).circle(40, 34, 3.5).segment(37, 45, 30, 57);
|
|
103
|
+
for (const [x, y] of [[25, 19], [55, 19], [25, 61], [55, 61]])
|
|
104
|
+
p.circle(x, y, 1);
|
|
105
|
+
}
|
|
106
|
+
function internet(p) {
|
|
107
|
+
p.circle(40, 40, 22).segment(40, 18, 40, 62).segment(18, 40, 62, 40).ellipse(40, 40, 10, 22);
|
|
108
|
+
p.segment(21, 29, 59, 29).segment(21, 51, 59, 51);
|
|
109
|
+
}
|
|
110
|
+
function cloud(p) {
|
|
111
|
+
// Three bumps on a flat base, each arc starting where the previous one ended.
|
|
112
|
+
const bump = (cx, cy, from, end) => {
|
|
113
|
+
p.arcAround(cx, cy, from[0], from[1], end);
|
|
114
|
+
const r = Math.hypot(from[0] - cx, from[1] - cy);
|
|
115
|
+
return [cx + r * Math.cos((end * Math.PI) / 180), cy + r * Math.sin((end * Math.PI) / 180)];
|
|
116
|
+
};
|
|
117
|
+
let at = [27, 54];
|
|
118
|
+
p.move(...at);
|
|
119
|
+
at = bump(27, 46, at, 300);
|
|
120
|
+
at = bump(42, 40, at, 350);
|
|
121
|
+
bump(54, 46, at, 90);
|
|
122
|
+
p.line(27, 54).close();
|
|
123
|
+
}
|
|
124
|
+
function unknown(p) {
|
|
125
|
+
p.move(31, 30).arc(9, 9, 180, 270).line(40, 47).circle(40, 56, 1.6);
|
|
126
|
+
}
|
|
127
|
+
const GLYPHS = { server, database, disk, internet, cloud, blank: () => undefined };
|
|
128
|
+
/**
|
|
129
|
+
* The paths of icon `name` in a square of `size` px at (`x`, `y`) of a shape: the blue square (filled, no
|
|
130
|
+
* outline) and the white glyph (outlined, unfilled). An icon Mermaid does not build in gets its `?`.
|
|
131
|
+
*/
|
|
132
|
+
export function iconPaths(name, x, y, size) {
|
|
133
|
+
const square = new Pen(x, y, size).box(0, 0, 80, 80, 0).toString();
|
|
134
|
+
const pen = new Pen(x, y, size);
|
|
135
|
+
(GLYPHS[name] ?? unknown)(pen);
|
|
136
|
+
const glyph = pen.toString();
|
|
137
|
+
return glyph ? [['norm', square, { stroke: false }], ['none', glyph]] : [['norm', square, { stroke: false }]];
|
|
138
|
+
}
|
|
139
|
+
/** The outline Mermaid draws for a service without an icon: rounded top corners, flat bottom. */
|
|
140
|
+
export function bareServicePath(x, y, size) {
|
|
141
|
+
const r = (5 * size) / 80;
|
|
142
|
+
const u = pathUnits;
|
|
143
|
+
return (`<a:moveTo><a:pt x="${u(x)}" y="${u(y + size)}"/></a:moveTo>` +
|
|
144
|
+
`<a:lnTo><a:pt x="${u(x)}" y="${u(y + r)}"/></a:lnTo><a:arcTo wR="${u(r)}" hR="${u(r)}" stAng="${180 * DEG}" swAng="${90 * DEG}"/>` +
|
|
145
|
+
`<a:lnTo><a:pt x="${u(x + size - r)}" y="${u(y)}"/></a:lnTo><a:arcTo wR="${u(r)}" hR="${u(r)}" stAng="${270 * DEG}" swAng="${90 * DEG}"/>` +
|
|
146
|
+
`<a:lnTo><a:pt x="${u(x + size)}" y="${u(y + size)}"/></a:lnTo><a:close/>`);
|
|
147
|
+
}
|
|
148
|
+
//# sourceMappingURL=icons.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"icons.js","sourceRoot":"","sources":["../../../src/diagrams/architecture-diagram/icons.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,qCAAqC,CAAC;AAEhE,iCAAiC;AACjC,MAAM,CAAC,MAAM,SAAS,GAAG,QAAQ,CAAC;AAClC,MAAM,CAAC,MAAM,WAAW,GAAG,QAAQ,CAAC;AAEpC,sDAAsD;AACtD,MAAM,CAAC,MAAM,cAAc,GAAwB,IAAI,GAAG,CAAC,CAAC,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC;AAEzH,MAAM,GAAG,GAAG,KAAK,CAAC;AAElB,mHAAmH;AACnH,MAAM,GAAG;IAKY;IACA;IALF,GAAG,GAAa,EAAE,CAAC;IACnB,CAAC,CAAS;IAE3B,YACmB,EAAU,EACV,EAAU,EAC3B,IAAY;QAFK,OAAE,GAAF,EAAE,CAAQ;QACV,OAAE,GAAF,EAAE,CAAQ;QAG3B,IAAI,CAAC,CAAC,GAAG,IAAI,GAAG,EAAE,CAAC;IACrB,CAAC;IAEO,EAAE,CAAC,CAAS,EAAE,CAAS;QAC7B,OAAO,YAAY,SAAS,CAAC,IAAI,CAAC,EAAE,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,QAAQ,SAAS,CAAC,IAAI,CAAC,EAAE,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC;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,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;AAChH,CAAC;AAED,iGAAiG;AACjG,MAAM,UAAU,eAAe,CAAC,CAAS,EAAE,CAAS,EAAE,IAAY;IAChE,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IAC1B,MAAM,CAAC,GAAG,SAAS,CAAC;IACpB,OAAO,CACL,sBAAsB,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,gBAAgB;QAC7D,oBAAoB,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,4BAA4B,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,YAAY,GAAG,GAAG,GAAG,YAAY,EAAE,GAAG,GAAG,KAAK;QACnI,oBAAoB,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,4BAA4B,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,YAAY,GAAG,GAAG,GAAG,YAAY,EAAE,GAAG,GAAG,KAAK;QAC1I,oBAAoB,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,wBAAwB,CAC3E,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Layout of an `architecture-beta` diagram, on the model Mermaid 12.3 uses (its renderer read against the
|
|
3
|
+
* official examples; the code here is this project's own). Mermaid does not rank the graph: it reads a
|
|
4
|
+
* grid out of the ports. `db:L -- R:server` puts `server` to the left of `db`, in the same row;
|
|
5
|
+
* `disk:T -- B:server` puts `server` above `disk`, in the same column. Mermaid hands that grid to a force
|
|
6
|
+
* layout (fcose) as alignment and placement constraints; here the constraints are solved directly.
|
|
7
|
+
*
|
|
8
|
+
* **Constraints, per axis.** An edge whose two ports face each other (`R`–`L`, `T`–`B`) puts its ends in
|
|
9
|
+
* the same row (or column) and orders them along it. An edge that turns (`R`–`T`…) orders its ends on both
|
|
10
|
+
* axes: `a:R -- T:b` puts `b` to the right of `a` (it leaves `a` rightwards) and below it (it enters `b`
|
|
11
|
+
* from above). Mermaid gives such an edge no constraint at all, which leaves `b` wherever the forces drop
|
|
12
|
+
* it; the reading here is the one its ports describe. `align row a b c` puts its members in one row, left
|
|
13
|
+
* to right; `align column` in one column, top to bottom. As in Mermaid, an `align` overrides what the
|
|
14
|
+
* edges said about the nodes it names: their edge alignments are dropped, the order of consecutive
|
|
15
|
+
* members comes from the `align`.
|
|
16
|
+
*
|
|
17
|
+
* **Solving.** Equalities merge nodes into rows and columns; orders between them form a graph whose
|
|
18
|
+
* longest paths give each row and column its index. A constraint that contradicts the others (a cycle)
|
|
19
|
+
* is dropped with a warning: Mermaid stops on it. A node no order reaches on an axis takes the mean of
|
|
20
|
+
* its neighbours' positions there (how Mermaid's forces centre `mcp` beside the column it is linked to).
|
|
21
|
+
* Two nodes that end up in the same cell are moved apart, across the way the moved one's edges come in:
|
|
22
|
+
* a node reached from the side goes under the other (two services linked to the same side of a third end
|
|
23
|
+
* up in a column), one reached from above or below goes beside it, so no line runs behind an icon it
|
|
24
|
+
* does not belong to. Separate parts of the diagram
|
|
25
|
+
* (nothing links them, no group holds both) are laid out on their own and placed side by side.
|
|
26
|
+
*
|
|
27
|
+
* **Sizes.** Rows and columns are `iconSize + gap` apart; where frames end or start between two of them,
|
|
28
|
+
* the distance grows to fit each frame's padding plus a clearance, as Mermaid's frames push their
|
|
29
|
+
* neighbours away. A group's frame encloses its members (their labels included) and its nested groups,
|
|
30
|
+
* with `padding` all around, the title in the top padding.
|
|
31
|
+
*/
|
|
32
|
+
import { type GraphLimits } from '../../layout/graph-limits.js';
|
|
33
|
+
import type { ArchitectureDiagram, ArchitectureNode } from './types.js';
|
|
34
|
+
/** Sizes the layout works with, in px. */
|
|
35
|
+
export interface ArchitectureMetrics {
|
|
36
|
+
iconSize: number;
|
|
37
|
+
/** Space between two icons in the same frame, along a row or a column. */
|
|
38
|
+
gap: number;
|
|
39
|
+
/** A frame's margin around what it holds. */
|
|
40
|
+
padding: number;
|
|
41
|
+
/** Space between a frame and what lies outside it. */
|
|
42
|
+
clearance: number;
|
|
43
|
+
/** Height of the label under a service (0 for none). */
|
|
44
|
+
labelHeight(node: ArchitectureNode): number;
|
|
45
|
+
/** Width of the label under a service (0 for none). */
|
|
46
|
+
labelWidth(node: ArchitectureNode): number;
|
|
47
|
+
/** Width a group's frame needs for its icon and title. */
|
|
48
|
+
headerWidth(group: ArchitectureNode): number;
|
|
49
|
+
}
|
|
50
|
+
export interface Box {
|
|
51
|
+
x: number;
|
|
52
|
+
y: number;
|
|
53
|
+
w: number;
|
|
54
|
+
h: number;
|
|
55
|
+
}
|
|
56
|
+
/** A service or junction, by the centre of its icon. */
|
|
57
|
+
export interface PlacedNode {
|
|
58
|
+
node: ArchitectureNode;
|
|
59
|
+
cx: number;
|
|
60
|
+
cy: number;
|
|
61
|
+
}
|
|
62
|
+
export interface ArchitectureLayout {
|
|
63
|
+
nodes: Map<string, PlacedNode>;
|
|
64
|
+
/** Group frames by id, outermost first. */
|
|
65
|
+
frames: Map<string, Box>;
|
|
66
|
+
width: number;
|
|
67
|
+
height: number;
|
|
68
|
+
warnings: string[];
|
|
69
|
+
}
|
|
70
|
+
/** Lay out a parsed diagram. @throws {DiagramTooLargeError} past the node or edge limit. */
|
|
71
|
+
export declare function layoutArchitecture(chart: ArchitectureDiagram, m: ArchitectureMetrics, limits?: GraphLimits): ArchitectureLayout;
|
|
@@ -0,0 +1,388 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Layout of an `architecture-beta` diagram, on the model Mermaid 12.3 uses (its renderer read against the
|
|
3
|
+
* official examples; the code here is this project's own). Mermaid does not rank the graph: it reads a
|
|
4
|
+
* grid out of the ports. `db:L -- R:server` puts `server` to the left of `db`, in the same row;
|
|
5
|
+
* `disk:T -- B:server` puts `server` above `disk`, in the same column. Mermaid hands that grid to a force
|
|
6
|
+
* layout (fcose) as alignment and placement constraints; here the constraints are solved directly.
|
|
7
|
+
*
|
|
8
|
+
* **Constraints, per axis.** An edge whose two ports face each other (`R`–`L`, `T`–`B`) puts its ends in
|
|
9
|
+
* the same row (or column) and orders them along it. An edge that turns (`R`–`T`…) orders its ends on both
|
|
10
|
+
* axes: `a:R -- T:b` puts `b` to the right of `a` (it leaves `a` rightwards) and below it (it enters `b`
|
|
11
|
+
* from above). Mermaid gives such an edge no constraint at all, which leaves `b` wherever the forces drop
|
|
12
|
+
* it; the reading here is the one its ports describe. `align row a b c` puts its members in one row, left
|
|
13
|
+
* to right; `align column` in one column, top to bottom. As in Mermaid, an `align` overrides what the
|
|
14
|
+
* edges said about the nodes it names: their edge alignments are dropped, the order of consecutive
|
|
15
|
+
* members comes from the `align`.
|
|
16
|
+
*
|
|
17
|
+
* **Solving.** Equalities merge nodes into rows and columns; orders between them form a graph whose
|
|
18
|
+
* longest paths give each row and column its index. A constraint that contradicts the others (a cycle)
|
|
19
|
+
* is dropped with a warning: Mermaid stops on it. A node no order reaches on an axis takes the mean of
|
|
20
|
+
* its neighbours' positions there (how Mermaid's forces centre `mcp` beside the column it is linked to).
|
|
21
|
+
* Two nodes that end up in the same cell are moved apart, across the way the moved one's edges come in:
|
|
22
|
+
* a node reached from the side goes under the other (two services linked to the same side of a third end
|
|
23
|
+
* up in a column), one reached from above or below goes beside it, so no line runs behind an icon it
|
|
24
|
+
* does not belong to. Separate parts of the diagram
|
|
25
|
+
* (nothing links them, no group holds both) are laid out on their own and placed side by side.
|
|
26
|
+
*
|
|
27
|
+
* **Sizes.** Rows and columns are `iconSize + gap` apart; where frames end or start between two of them,
|
|
28
|
+
* the distance grows to fit each frame's padding plus a clearance, as Mermaid's frames push their
|
|
29
|
+
* neighbours away. A group's frame encloses its members (their labels included) and its nested groups,
|
|
30
|
+
* with `padding` all around, the title in the top padding.
|
|
31
|
+
*/
|
|
32
|
+
import { DiagramTooLargeError, DEFAULT_MAX_EDGES, DEFAULT_MAX_NODES } from '../../layout/graph-limits.js';
|
|
33
|
+
/** Unit step of a side, y pointing down. */
|
|
34
|
+
const STEP = {
|
|
35
|
+
L: { x: -1, y: 0 },
|
|
36
|
+
R: { x: 1, y: 0 },
|
|
37
|
+
T: { x: 0, y: -1 },
|
|
38
|
+
B: { x: 0, y: 1 },
|
|
39
|
+
};
|
|
40
|
+
const axisOf = (side) => (side === 'L' || side === 'R' ? 'x' : 'y');
|
|
41
|
+
/** Disjoint sets over node ids. */
|
|
42
|
+
class UnionFind {
|
|
43
|
+
parent = new Map();
|
|
44
|
+
find(id) {
|
|
45
|
+
let root = id;
|
|
46
|
+
while (this.parent.has(root) && this.parent.get(root) !== root)
|
|
47
|
+
root = this.parent.get(root);
|
|
48
|
+
let cursor = id;
|
|
49
|
+
while (cursor !== root) {
|
|
50
|
+
const next = this.parent.get(cursor) ?? root;
|
|
51
|
+
this.parent.set(cursor, root);
|
|
52
|
+
cursor = next;
|
|
53
|
+
}
|
|
54
|
+
return root;
|
|
55
|
+
}
|
|
56
|
+
union(a, b) {
|
|
57
|
+
const ra = this.find(a);
|
|
58
|
+
const rb = this.find(b);
|
|
59
|
+
if (ra !== rb)
|
|
60
|
+
this.parent.set(rb, ra);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/** Positions on one axis, in steps (fractional for a node centred between others). */
|
|
64
|
+
function solveAxis(ids, constraints, neighbours, warnings) {
|
|
65
|
+
const uf = new UnionFind();
|
|
66
|
+
for (const [a, b] of constraints.equal)
|
|
67
|
+
uf.union(a, b);
|
|
68
|
+
const classes = [...new Set(ids.map((id) => uf.find(id)))];
|
|
69
|
+
const succ = new Map(classes.map((c) => [c, new Set()]));
|
|
70
|
+
const pred = new Map(classes.map((c) => [c, new Set()]));
|
|
71
|
+
const reaches = (from, to) => {
|
|
72
|
+
const stack = [from];
|
|
73
|
+
const seen = new Set();
|
|
74
|
+
while (stack.length > 0) {
|
|
75
|
+
const c = stack.pop();
|
|
76
|
+
if (c === to)
|
|
77
|
+
return true;
|
|
78
|
+
if (seen.has(c))
|
|
79
|
+
continue;
|
|
80
|
+
seen.add(c);
|
|
81
|
+
for (const n of succ.get(c))
|
|
82
|
+
stack.push(n);
|
|
83
|
+
}
|
|
84
|
+
return false;
|
|
85
|
+
};
|
|
86
|
+
for (const o of constraints.order) {
|
|
87
|
+
const a = uf.find(o.before);
|
|
88
|
+
const b = uf.find(o.after);
|
|
89
|
+
if (succ.get(a).has(b))
|
|
90
|
+
continue;
|
|
91
|
+
if (a === b || reaches(b, a)) {
|
|
92
|
+
warnings.push(`Placement of ${o.why} contradicts the other edges and align lines; not applied.`);
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
succ.get(a).add(b);
|
|
96
|
+
pred.get(b).add(a);
|
|
97
|
+
}
|
|
98
|
+
// Longest path from the sources, in topological order.
|
|
99
|
+
const level = new Map();
|
|
100
|
+
const indegree = new Map(classes.map((c) => [c, pred.get(c).size]));
|
|
101
|
+
const queue = classes.filter((c) => indegree.get(c) === 0);
|
|
102
|
+
const topo = [];
|
|
103
|
+
while (queue.length > 0) {
|
|
104
|
+
const c = queue.shift();
|
|
105
|
+
topo.push(c);
|
|
106
|
+
const l = Math.max(0, ...[...pred.get(c)].map((p) => level.get(p) + 1));
|
|
107
|
+
level.set(c, l);
|
|
108
|
+
for (const n of succ.get(c)) {
|
|
109
|
+
indegree.set(n, indegree.get(n) - 1);
|
|
110
|
+
if (indegree.get(n) === 0)
|
|
111
|
+
queue.push(n);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
// A source sits right before its nearest successor, not at the far end of the axis.
|
|
115
|
+
for (const c of [...topo].reverse()) {
|
|
116
|
+
if (pred.get(c).size === 0 && succ.get(c).size > 0)
|
|
117
|
+
level.set(c, Math.min(...[...succ.get(c)].map((n) => level.get(n))) - 1);
|
|
118
|
+
}
|
|
119
|
+
// Classes no order reaches: the mean of their neighbours, refined a few times; 0 when nothing anchors them.
|
|
120
|
+
const free = classes.filter((c) => pred.get(c).size === 0 && succ.get(c).size === 0);
|
|
121
|
+
const members = new Map();
|
|
122
|
+
for (const id of ids)
|
|
123
|
+
members.set(uf.find(id), [...(members.get(uf.find(id)) ?? []), id]);
|
|
124
|
+
for (const c of free)
|
|
125
|
+
level.delete(c);
|
|
126
|
+
for (let pass = 0; pass < 8; pass++) {
|
|
127
|
+
for (const c of free) {
|
|
128
|
+
const around = members
|
|
129
|
+
.get(c)
|
|
130
|
+
.flatMap((id) => neighbours.get(id) ?? [])
|
|
131
|
+
.map((id) => uf.find(id))
|
|
132
|
+
.filter((n) => n !== c && level.has(n));
|
|
133
|
+
if (around.length > 0)
|
|
134
|
+
level.set(c, around.reduce((sum, n) => sum + level.get(n), 0) / around.length);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
for (const c of free)
|
|
138
|
+
if (!level.has(c))
|
|
139
|
+
level.set(c, 0);
|
|
140
|
+
// Start at 0.
|
|
141
|
+
const min = Math.min(...[...level.values()]);
|
|
142
|
+
const out = new Map();
|
|
143
|
+
for (const id of ids)
|
|
144
|
+
out.set(id, level.get(uf.find(id)) - min);
|
|
145
|
+
return out;
|
|
146
|
+
}
|
|
147
|
+
/** The constraints the edges and `align` lines put on the nodes of one part of the diagram. */
|
|
148
|
+
function constraintsOf(chart, ids) {
|
|
149
|
+
const out = { x: { equal: [], order: [] }, y: { equal: [], order: [] } };
|
|
150
|
+
const alignments = (chart.alignments ?? []).filter((a) => a.members.every((m) => ids.has(m)));
|
|
151
|
+
const aligned = new Set(alignments.flatMap((a) => a.members));
|
|
152
|
+
const declaredPairs = new Set();
|
|
153
|
+
for (const a of alignments) {
|
|
154
|
+
const along = a.direction === 'row' ? 'x' : 'y';
|
|
155
|
+
const across = along === 'x' ? 'y' : 'x';
|
|
156
|
+
a.members.forEach((m, i) => {
|
|
157
|
+
const next = a.members[i + 1];
|
|
158
|
+
if (next === undefined)
|
|
159
|
+
return;
|
|
160
|
+
declaredPairs.add(`${m}|${next}`).add(`${next}|${m}`);
|
|
161
|
+
out[across].equal.push([m, next]);
|
|
162
|
+
out[along].order.push({ before: m, after: next, why: `align ${a.direction} ${m} ${next}` });
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
const push = (axis, from, to, sign, why) => {
|
|
166
|
+
if (sign > 0)
|
|
167
|
+
out[axis].order.push({ before: from, after: to, why });
|
|
168
|
+
else if (sign < 0)
|
|
169
|
+
out[axis].order.push({ before: to, after: from, why });
|
|
170
|
+
};
|
|
171
|
+
for (const e of chart.edges) {
|
|
172
|
+
if (e.from === e.to || !ids.has(e.from) || !ids.has(e.to))
|
|
173
|
+
continue;
|
|
174
|
+
const why = `${e.from}:${e.fromSide} -- ${e.toSide}:${e.to}`;
|
|
175
|
+
const declared = declaredPairs.has(`${e.from}|${e.to}`);
|
|
176
|
+
const fromAxis = axisOf(e.fromSide);
|
|
177
|
+
const toAxis = axisOf(e.toSide);
|
|
178
|
+
if (fromAxis === toAxis) {
|
|
179
|
+
// Ports facing each other; `R -- R` and the like say nothing (Mermaid ignores them too).
|
|
180
|
+
if (e.fromSide === e.toSide)
|
|
181
|
+
continue;
|
|
182
|
+
const across = fromAxis === 'x' ? 'y' : 'x';
|
|
183
|
+
if (!aligned.has(e.from) && !aligned.has(e.to))
|
|
184
|
+
out[across].equal.push([e.from, e.to]);
|
|
185
|
+
if (!declared)
|
|
186
|
+
push(fromAxis, e.from, e.to, STEP[e.fromSide][fromAxis], why);
|
|
187
|
+
}
|
|
188
|
+
else if (!declared) {
|
|
189
|
+
// A turn: away from `from` along its port, and towards `to`'s port on the other axis.
|
|
190
|
+
push(fromAxis, e.from, e.to, STEP[e.fromSide][fromAxis], why);
|
|
191
|
+
push(toAxis, e.from, e.to, -STEP[e.toSide][toAxis], why);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
return out;
|
|
195
|
+
}
|
|
196
|
+
/** Steps on both axes for one part of the diagram; two nodes never share a cell. */
|
|
197
|
+
function solveGrid(chart, ids, neighbours, warnings) {
|
|
198
|
+
const base = constraintsOf(chart, new Set(ids));
|
|
199
|
+
// How many of each node's edge ends are on a left/right side (`x`) or a top/bottom side (`y`).
|
|
200
|
+
const portCount = new Map();
|
|
201
|
+
for (const e of chart.edges) {
|
|
202
|
+
for (const [id, side] of [[e.from, e.fromSide], [e.to, e.toSide]]) {
|
|
203
|
+
const count = portCount.get(id) ?? { x: 0, y: 0 };
|
|
204
|
+
count[axisOf(side)]++;
|
|
205
|
+
portCount.set(id, count);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
// Nodes taken out of their row (`y`) or column (`x`) to resolve a collision, and the extra orders that do it.
|
|
209
|
+
const detached = { x: new Set(), y: new Set() };
|
|
210
|
+
const extra = { x: [], y: [] };
|
|
211
|
+
let grid = new Map();
|
|
212
|
+
const maxPasses = 2 * ids.length + 2;
|
|
213
|
+
for (let pass = 0; pass < maxPasses; pass++) {
|
|
214
|
+
const solved = {};
|
|
215
|
+
const sameLine = {};
|
|
216
|
+
for (const axis of ['x', 'y']) {
|
|
217
|
+
const equal = base[axis].equal.filter(([a, b]) => !detached[axis].has(a) && !detached[axis].has(b));
|
|
218
|
+
// A contradiction is reported once, on the first pass.
|
|
219
|
+
solved[axis] = solveAxis(ids, { equal, order: [...base[axis].order, ...extra[axis]] }, neighbours, pass === 0 ? warnings : []);
|
|
220
|
+
sameLine[axis] = new UnionFind();
|
|
221
|
+
for (const [a, b] of equal)
|
|
222
|
+
sameLine[axis].union(a, b);
|
|
223
|
+
}
|
|
224
|
+
grid = new Map(ids.map((id) => [id, { x: solved.x.get(id), y: solved.y.get(id) }]));
|
|
225
|
+
const cells = new Map();
|
|
226
|
+
for (const id of ids) {
|
|
227
|
+
const p = grid.get(id);
|
|
228
|
+
const key = `${p.x.toFixed(3)},${p.y.toFixed(3)}`;
|
|
229
|
+
cells.set(key, [...(cells.get(key) ?? []), id]);
|
|
230
|
+
}
|
|
231
|
+
const crowded = [...cells.values()].filter((list) => list.length > 1);
|
|
232
|
+
if (crowded.length === 0)
|
|
233
|
+
return grid;
|
|
234
|
+
for (const list of crowded) {
|
|
235
|
+
const [first, ...others] = list;
|
|
236
|
+
let previous = first;
|
|
237
|
+
for (const id of others) {
|
|
238
|
+
const why = `${id} (moved off ${previous}, they landed on the same spot)`;
|
|
239
|
+
// Move it across the way its edges come in: a node reached from the side goes under the other one,
|
|
240
|
+
// so its horizontal edges do not run behind it; one reached from above or below goes beside it.
|
|
241
|
+
const axis = (portCount.get(id)?.x ?? 0) > (portCount.get(id)?.y ?? 0) ? 'y' : 'x';
|
|
242
|
+
if (sameLine[axis].find(id) === sameLine[axis].find(previous))
|
|
243
|
+
detached[axis].add(id);
|
|
244
|
+
extra[axis].push({ before: previous, after: id, why });
|
|
245
|
+
previous = id;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
warnings.push('Some services could not be given a place of their own and overlap.');
|
|
250
|
+
return grid;
|
|
251
|
+
}
|
|
252
|
+
/** Ids of the services and junctions in each separate part: linked by an edge, an `align` or a common group. */
|
|
253
|
+
function parts(chart, ids, groupOf) {
|
|
254
|
+
const uf = new UnionFind();
|
|
255
|
+
for (const e of chart.edges)
|
|
256
|
+
uf.union(e.from, e.to);
|
|
257
|
+
for (const a of chart.alignments ?? [])
|
|
258
|
+
for (const m of a.members.slice(1))
|
|
259
|
+
uf.union(a.members[0], m);
|
|
260
|
+
// Every node joins its outermost group.
|
|
261
|
+
for (const id of ids) {
|
|
262
|
+
let top = groupOf(id);
|
|
263
|
+
if (top === undefined)
|
|
264
|
+
continue;
|
|
265
|
+
const seen = new Set();
|
|
266
|
+
for (let g = top; g !== undefined && !seen.has(g); g = groupOf(g)) {
|
|
267
|
+
seen.add(g);
|
|
268
|
+
top = g;
|
|
269
|
+
}
|
|
270
|
+
uf.union(id, `group:${top}`);
|
|
271
|
+
}
|
|
272
|
+
const byRoot = new Map();
|
|
273
|
+
for (const id of ids)
|
|
274
|
+
byRoot.set(uf.find(id), [...(byRoot.get(uf.find(id)) ?? []), id]);
|
|
275
|
+
return [...byRoot.values()];
|
|
276
|
+
}
|
|
277
|
+
/** Lay out a parsed diagram. @throws {DiagramTooLargeError} past the node or edge limit. */
|
|
278
|
+
export function layoutArchitecture(chart, m, limits = {}) {
|
|
279
|
+
const maxNodes = limits.maxNodes ?? DEFAULT_MAX_NODES;
|
|
280
|
+
const maxEdges = limits.maxEdges ?? DEFAULT_MAX_EDGES;
|
|
281
|
+
if (chart.nodes.length > maxNodes)
|
|
282
|
+
throw new DiagramTooLargeError('nodes', chart.nodes.length, maxNodes);
|
|
283
|
+
if (chart.edges.length > maxEdges)
|
|
284
|
+
throw new DiagramTooLargeError('edges', chart.edges.length, maxEdges);
|
|
285
|
+
const warnings = [];
|
|
286
|
+
const byId = new Map(chart.nodes.map((n) => [n.id, n]));
|
|
287
|
+
const groups = chart.nodes.filter((n) => n.kind === 'group');
|
|
288
|
+
const placeable = chart.nodes.filter((n) => n.kind !== 'group');
|
|
289
|
+
// A parent that is not a group (or a loop of groups) is left out; the parser already said so.
|
|
290
|
+
const groupOf = (id) => {
|
|
291
|
+
const parent = byId.get(id)?.parent;
|
|
292
|
+
return parent !== undefined && byId.get(parent)?.kind === 'group' ? parent : undefined;
|
|
293
|
+
};
|
|
294
|
+
const ancestors = (id) => {
|
|
295
|
+
const out = [];
|
|
296
|
+
for (let g = groupOf(id); g !== undefined && !out.includes(g); g = groupOf(g))
|
|
297
|
+
out.push(g);
|
|
298
|
+
return out;
|
|
299
|
+
};
|
|
300
|
+
const neighbours = new Map();
|
|
301
|
+
for (const e of chart.edges) {
|
|
302
|
+
neighbours.set(e.from, [...(neighbours.get(e.from) ?? []), e.to]);
|
|
303
|
+
neighbours.set(e.to, [...(neighbours.get(e.to) ?? []), e.from]);
|
|
304
|
+
}
|
|
305
|
+
const nodes = new Map();
|
|
306
|
+
const frames = new Map();
|
|
307
|
+
const labelBelow = (n) => (n.kind === 'service' ? m.labelHeight(n) : 0);
|
|
308
|
+
/** A node's box: its icon and the label under it. */
|
|
309
|
+
const nodeBox = (p) => {
|
|
310
|
+
const lw = Math.max(m.iconSize, p.node.kind === 'service' ? m.labelWidth(p.node) : 0);
|
|
311
|
+
return { x: p.cx - lw / 2, y: p.cy - m.iconSize / 2, w: lw, h: m.iconSize + labelBelow(p.node) };
|
|
312
|
+
};
|
|
313
|
+
let cursorX = 0;
|
|
314
|
+
for (const ids of parts(chart, placeable.map((n) => n.id), groupOf)) {
|
|
315
|
+
const grid = solveGrid(chart, ids, neighbours, warnings);
|
|
316
|
+
const partGroups = groups.filter((g) => ids.some((id) => ancestors(id).includes(g.id)));
|
|
317
|
+
// Distance between consecutive grid lines, widened where frames end or start between them.
|
|
318
|
+
const coords = (axis) => {
|
|
319
|
+
const values = ids.map((id) => grid.get(id)[axis]);
|
|
320
|
+
const lo = Math.floor(Math.min(...values));
|
|
321
|
+
const hi = Math.ceil(Math.max(...values));
|
|
322
|
+
const spans = partGroups.map((g) => {
|
|
323
|
+
const inside = ids.filter((id) => ancestors(id).includes(g.id)).map((id) => grid.get(id)[axis]);
|
|
324
|
+
return { min: Math.min(...inside), max: Math.max(...inside) };
|
|
325
|
+
});
|
|
326
|
+
const pos = new Map([[lo, 0]]);
|
|
327
|
+
for (let k = lo; k < hi; k++) {
|
|
328
|
+
const borders = spans.filter((s) => (s.max >= k && s.max < k + 1) || (s.min > k && s.min <= k + 1)).length;
|
|
329
|
+
const row = ids.filter((id) => grid.get(id)[axis] >= k && grid.get(id)[axis] < k + 1);
|
|
330
|
+
const next = ids.filter((id) => grid.get(id)[axis] > k && grid.get(id)[axis] <= k + 1);
|
|
331
|
+
let step;
|
|
332
|
+
if (axis === 'x') {
|
|
333
|
+
const half = (list) => Math.max(m.iconSize, ...list.map((id) => m.labelWidth(byId.get(id)))) / 2;
|
|
334
|
+
step = Math.max(m.iconSize + Math.max(m.gap, borders * m.padding + (borders > 0 ? m.clearance : 0)), half(row) + half(next) + m.gap / 3);
|
|
335
|
+
}
|
|
336
|
+
else {
|
|
337
|
+
const label = Math.max(0, ...row.map((id) => labelBelow(byId.get(id))));
|
|
338
|
+
step = m.iconSize + Math.max(m.gap, label + (borders > 0 ? borders * m.padding + m.clearance : m.gap / 3));
|
|
339
|
+
}
|
|
340
|
+
pos.set(k + 1, pos.get(k) + step);
|
|
341
|
+
}
|
|
342
|
+
return pos;
|
|
343
|
+
};
|
|
344
|
+
const px = coords('x');
|
|
345
|
+
const py = coords('y');
|
|
346
|
+
const at = (pos, v) => {
|
|
347
|
+
const k = Math.floor(v);
|
|
348
|
+
const base = pos.get(k);
|
|
349
|
+
return v === k ? base : base + (v - k) * (pos.get(k + 1) - base);
|
|
350
|
+
};
|
|
351
|
+
const placed = ids.map((id) => ({ node: byId.get(id), cx: at(px, grid.get(id).x), cy: at(py, grid.get(id).y) }));
|
|
352
|
+
// Frames, innermost first: members' boxes and nested frames, plus the padding and room for the header.
|
|
353
|
+
const partFrames = new Map();
|
|
354
|
+
const depth = (g) => ancestors(g).length;
|
|
355
|
+
for (const g of [...partGroups].sort((a, b) => depth(b.id) - depth(a.id))) {
|
|
356
|
+
const boxes = [
|
|
357
|
+
...placed.filter((p) => groupOf(p.node.id) === g.id).map(nodeBox),
|
|
358
|
+
...partGroups.filter((c) => groupOf(c.id) === g.id).map((c) => partFrames.get(c.id)),
|
|
359
|
+
].filter((b) => b !== undefined);
|
|
360
|
+
if (boxes.length === 0)
|
|
361
|
+
continue;
|
|
362
|
+
const x = Math.min(...boxes.map((b) => b.x)) - m.padding;
|
|
363
|
+
const y = Math.min(...boxes.map((b) => b.y)) - m.padding;
|
|
364
|
+
const right = Math.max(...boxes.map((b) => b.x + b.w)) + m.padding;
|
|
365
|
+
const bottom = Math.max(...boxes.map((b) => b.y + b.h)) + m.padding;
|
|
366
|
+
partFrames.set(g.id, { x, y, w: Math.max(right - x, m.headerWidth(g)), h: bottom - y });
|
|
367
|
+
}
|
|
368
|
+
// Place this part to the right of the previous one, tops aligned.
|
|
369
|
+
const extent = [...placed.map(nodeBox), ...partFrames.values()];
|
|
370
|
+
const left = Math.min(...extent.map((b) => b.x));
|
|
371
|
+
const top = Math.min(...extent.map((b) => b.y));
|
|
372
|
+
const right = Math.max(...extent.map((b) => b.x + b.w));
|
|
373
|
+
const dx = cursorX - left;
|
|
374
|
+
const dy = -top;
|
|
375
|
+
for (const p of placed)
|
|
376
|
+
nodes.set(p.node.id, { ...p, cx: p.cx + dx, cy: p.cy + dy });
|
|
377
|
+
for (const [id, b] of partFrames)
|
|
378
|
+
frames.set(id, { ...b, x: b.x + dx, y: b.y + dy });
|
|
379
|
+
cursorX += right - left + m.gap;
|
|
380
|
+
}
|
|
381
|
+
// Outermost first, so an inner frame is drawn over its parent.
|
|
382
|
+
const ordered = new Map([...frames].sort(([a], [b]) => ancestors(a).length - ancestors(b).length));
|
|
383
|
+
const all = [...[...nodes.values()].map(nodeBox), ...ordered.values()];
|
|
384
|
+
const width = all.length > 0 ? Math.max(...all.map((b) => b.x + b.w)) : 0;
|
|
385
|
+
const height = all.length > 0 ? Math.max(...all.map((b) => b.y + b.h)) : 0;
|
|
386
|
+
return { nodes, frames: ordered, width, height, warnings };
|
|
387
|
+
}
|
|
388
|
+
//# sourceMappingURL=layout.js.map
|