archimaid 0.0.0-stage → 0.1.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/CHANGELOG.md +32 -0
- package/FOUNDATION.md +108 -0
- package/LICENSE +21 -0
- package/README.md +271 -2
- package/dist/archimate/catalogue.d.ts +106 -0
- package/dist/archimate/catalogue.js +219 -0
- package/dist/archimate/catalogue.js.map +1 -0
- package/dist/archimate/diagnostics.d.ts +48 -0
- package/dist/archimate/diagnostics.js +64 -0
- package/dist/archimate/diagnostics.js.map +1 -0
- package/dist/archimate/frontmatter.d.ts +13 -0
- package/dist/archimate/frontmatter.js +62 -0
- package/dist/archimate/frontmatter.js.map +1 -0
- package/dist/archimate/grammar.d.ts +60 -0
- package/dist/archimate/grammar.js +273 -0
- package/dist/archimate/grammar.js.map +1 -0
- package/dist/archimate/lexer.d.ts +91 -0
- package/dist/archimate/lexer.js +215 -0
- package/dist/archimate/lexer.js.map +1 -0
- package/dist/archimate/model.d.ts +46 -0
- package/dist/archimate/model.js +2 -0
- package/dist/archimate/model.js.map +1 -0
- package/dist/archimate/nesting.d.ts +14 -0
- package/dist/archimate/nesting.js +84 -0
- package/dist/archimate/nesting.js.map +1 -0
- package/dist/archimate/parser.d.ts +14 -0
- package/dist/archimate/parser.js +53 -0
- package/dist/archimate/parser.js.map +1 -0
- package/dist/archimate/suggestions.d.ts +1 -0
- package/dist/archimate/suggestions.js +44 -0
- package/dist/archimate/suggestions.js.map +1 -0
- package/dist/archimate/validate.d.ts +4 -0
- package/dist/archimate/validate.js +402 -0
- package/dist/archimate/validate.js.map +1 -0
- package/dist/bundle/archimaid.esm.min.mjs +1 -0
- package/dist/bundle/chunks/archimateDiagram-WUCF6KHR.mjs +132 -0
- package/dist/bundle/chunks/chunk-QBMRZFD3.mjs +1 -0
- package/dist/bundle/chunks/elk.bundled-2VSLVJGB.mjs +26 -0
- package/dist/cli/render.d.ts +10 -0
- package/dist/cli/render.js +102 -0
- package/dist/cli/render.js.map +1 -0
- package/dist/cli/report.d.ts +20 -0
- package/dist/cli/report.js +39 -0
- package/dist/cli/report.js.map +1 -0
- package/dist/cli/sources.d.ts +19 -0
- package/dist/cli/sources.js +86 -0
- package/dist/cli/sources.js.map +1 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +137 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/language.d.ts +5 -0
- package/dist/language.js +3 -0
- package/dist/language.js.map +1 -0
- package/dist/mermaid/archimateDetector.d.ts +12 -0
- package/dist/mermaid/archimateDetector.js +29 -0
- package/dist/mermaid/archimateDetector.js.map +1 -0
- package/dist/mermaid/archimateDiagram.d.ts +9 -0
- package/dist/mermaid/archimateDiagram.js +75 -0
- package/dist/mermaid/archimateDiagram.js.map +1 -0
- package/dist/mermaid/archimateRenderer.d.ts +6 -0
- package/dist/mermaid/archimateRenderer.js +40 -0
- package/dist/mermaid/archimateRenderer.js.map +1 -0
- package/dist/mermaid/architectureLayout.d.ts +50 -0
- package/dist/mermaid/architectureLayout.js +144 -0
- package/dist/mermaid/architectureLayout.js.map +1 -0
- package/dist/mermaid/geometry.d.ts +3 -0
- package/dist/mermaid/geometry.js +20 -0
- package/dist/mermaid/geometry.js.map +1 -0
- package/dist/mermaid/hierarchy.d.ts +1 -0
- package/dist/mermaid/hierarchy.js +8 -0
- package/dist/mermaid/hierarchy.js.map +1 -0
- package/dist/mermaid/invariant.d.ts +1 -0
- package/dist/mermaid/invariant.js +7 -0
- package/dist/mermaid/invariant.js.map +1 -0
- package/dist/mermaid/orthogonalRouter.d.ts +4 -0
- package/dist/mermaid/orthogonalRouter.js +249 -0
- package/dist/mermaid/orthogonalRouter.js.map +1 -0
- package/dist/mermaid/relationshipPlacement.d.ts +3 -0
- package/dist/mermaid/relationshipPlacement.js +350 -0
- package/dist/mermaid/relationshipPlacement.js.map +1 -0
- package/dist/mermaid/render/draw.d.ts +17 -0
- package/dist/mermaid/render/draw.js +275 -0
- package/dist/mermaid/render/draw.js.map +1 -0
- package/dist/mermaid/render/elkRoutes.d.ts +6 -0
- package/dist/mermaid/render/elkRoutes.js +216 -0
- package/dist/mermaid/render/elkRoutes.js.map +1 -0
- package/dist/mermaid/render/graph.d.ts +17 -0
- package/dist/mermaid/render/graph.js +200 -0
- package/dist/mermaid/render/graph.js.map +1 -0
- package/dist/mermaid/render/labels.d.ts +12 -0
- package/dist/mermaid/render/labels.js +148 -0
- package/dist/mermaid/render/labels.js.map +1 -0
- package/dist/mermaid/render/layout.d.ts +12 -0
- package/dist/mermaid/render/layout.js +60 -0
- package/dist/mermaid/render/layout.js.map +1 -0
- package/dist/mermaid/render/measure.d.ts +16 -0
- package/dist/mermaid/render/measure.js +96 -0
- package/dist/mermaid/render/measure.js.map +1 -0
- package/dist/mermaid/render/place.d.ts +20 -0
- package/dist/mermaid/render/place.js +63 -0
- package/dist/mermaid/render/place.js.map +1 -0
- package/dist/mermaid/render/route.d.ts +29 -0
- package/dist/mermaid/render/route.js +113 -0
- package/dist/mermaid/render/route.js.map +1 -0
- package/dist/mermaid/render/shared.d.ts +83 -0
- package/dist/mermaid/render/shared.js +52 -0
- package/dist/mermaid/render/shared.js.map +1 -0
- package/dist/mermaid/render/svg.d.ts +6 -0
- package/dist/mermaid/render/svg.js +33 -0
- package/dist/mermaid/render/svg.js.map +1 -0
- package/dist/mermaid/render/viewport.d.ts +14 -0
- package/dist/mermaid/render/viewport.js +58 -0
- package/dist/mermaid/render/viewport.js.map +1 -0
- package/dist/mermaid/routing/anchors.d.ts +14 -0
- package/dist/mermaid/routing/anchors.js +134 -0
- package/dist/mermaid/routing/anchors.js.map +1 -0
- package/dist/mermaid/routing/bundles.d.ts +14 -0
- package/dist/mermaid/routing/bundles.js +94 -0
- package/dist/mermaid/routing/bundles.js.map +1 -0
- package/dist/mermaid/routing/congestion.d.ts +8 -0
- package/dist/mermaid/routing/congestion.js +70 -0
- package/dist/mermaid/routing/congestion.js.map +1 -0
- package/dist/mermaid/routing/constants.d.ts +13 -0
- package/dist/mermaid/routing/constants.js +17 -0
- package/dist/mermaid/routing/constants.js.map +1 -0
- package/dist/mermaid/routing/primitives.d.ts +33 -0
- package/dist/mermaid/routing/primitives.js +110 -0
- package/dist/mermaid/routing/primitives.js.map +1 -0
- package/dist/mermaid/routing/search.d.ts +4 -0
- package/dist/mermaid/routing/search.js +171 -0
- package/dist/mermaid/routing/search.js.map +1 -0
- package/dist/mermaid/routing/shapes.d.ts +8 -0
- package/dist/mermaid/routing/shapes.js +82 -0
- package/dist/mermaid/routing/shapes.js.map +1 -0
- package/dist/mermaid/routing/types.d.ts +37 -0
- package/dist/mermaid/routing/types.js +14 -0
- package/dist/mermaid/routing/types.js.map +1 -0
- package/dist/mermaid/styles.d.ts +89 -0
- package/dist/mermaid/styles.js +166 -0
- package/dist/mermaid/styles.js.map +1 -0
- package/docs/reference.md +86 -0
- package/examples/cross-layer-relationships.mmd +79 -0
- package/examples/cross-layer-relationships.svg +33 -0
- package/examples/element-preview.svg +1 -0
- package/examples/nested-components.mmd +21 -0
- package/examples/nested-components.svg +4 -0
- package/examples/order-fulfilment.mmd +10 -0
- package/examples/order-management.mmd +15 -0
- package/examples/order-management.svg +2 -0
- package/package.json +91 -4
- package/skills/archimaid/SKILL.md +123 -0
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { getRelationshipNotation, relationshipNames, relationshipTypes, } from '../../archimate/catalogue.js';
|
|
2
|
+
import { ancestors } from '../hierarchy.js';
|
|
3
|
+
import { edgeLabelPadding, elkLayerSpacing, elkNodeSpacing, headerLabelPadding, iconLabelGap, iconRightInset, iconSize, layoutPadding, minimumElementWidth, minimumHeaderHeight, minimumNoteHeight, noteFold, noteInset, noteOverlap, notesBelowHost, plainLabelInset, usesArchitectureLayout, } from './shared.js';
|
|
4
|
+
const layoutDirection = {
|
|
5
|
+
TB: 'DOWN',
|
|
6
|
+
BT: 'UP',
|
|
7
|
+
LR: 'RIGHT',
|
|
8
|
+
RL: 'LEFT',
|
|
9
|
+
};
|
|
10
|
+
function isRelationshipType(type) {
|
|
11
|
+
return relationshipTypes.includes(type);
|
|
12
|
+
}
|
|
13
|
+
const accessModeWords = {
|
|
14
|
+
read: 'read',
|
|
15
|
+
write: 'write',
|
|
16
|
+
readWrite: 'read and write',
|
|
17
|
+
};
|
|
18
|
+
function relationshipDescription(relationship, names) {
|
|
19
|
+
const typeName = isRelationshipType(relationship.type) ? relationshipNames[relationship.type] : relationship.type;
|
|
20
|
+
const mode = relationship.type === 'access' ? relationship.access && accessModeWords[relationship.access] : undefined;
|
|
21
|
+
const qualifier = mode
|
|
22
|
+
? ` (${mode})`
|
|
23
|
+
: relationship.type === 'association' && relationship.directed
|
|
24
|
+
? ' (directed)'
|
|
25
|
+
: '';
|
|
26
|
+
const source = names.get(relationship.source) ?? relationship.source;
|
|
27
|
+
const target = names.get(relationship.target) ?? relationship.target;
|
|
28
|
+
const description = `${source} — ${typeName}${qualifier} → ${target}`;
|
|
29
|
+
return relationship.label ? `${description}: ${relationship.label}` : description;
|
|
30
|
+
}
|
|
31
|
+
function layoutNodes(measured, model) {
|
|
32
|
+
const nodes = new Map();
|
|
33
|
+
const notes = new Map();
|
|
34
|
+
const overlays = new Map();
|
|
35
|
+
const nodeIds = new Map();
|
|
36
|
+
const children = [];
|
|
37
|
+
for (const [index, note] of (model.notes ?? []).entries()) {
|
|
38
|
+
const label = measured.notes[index];
|
|
39
|
+
if (!label)
|
|
40
|
+
throw new Error(`The note "${note.id}" was not measured.`);
|
|
41
|
+
const appearance = {
|
|
42
|
+
note,
|
|
43
|
+
label,
|
|
44
|
+
width: Math.max(minimumElementWidth, label.width + 2 * (noteInset + noteFold)),
|
|
45
|
+
height: Math.max(minimumNoteHeight, label.height + 2 * noteInset),
|
|
46
|
+
};
|
|
47
|
+
if (note.on !== undefined) {
|
|
48
|
+
const attached = overlays.get(note.on);
|
|
49
|
+
if (attached)
|
|
50
|
+
attached.push(appearance);
|
|
51
|
+
else
|
|
52
|
+
overlays.set(note.on, [appearance]);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
const id = `note${index}`;
|
|
56
|
+
nodeIds.set(note.id, id);
|
|
57
|
+
notes.set(id, appearance);
|
|
58
|
+
children.push({ id, width: appearance.width, height: appearance.height });
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
const elkNodes = new Map();
|
|
62
|
+
for (const [index, { element, type, notation, label }] of measured.elements.entries()) {
|
|
63
|
+
const internalId = `n${index}`;
|
|
64
|
+
// Reserve the same space on both sides so centered labels clear the icon.
|
|
65
|
+
const labelInset = notation.icon?.length
|
|
66
|
+
? iconRightInset(notation.outline) + iconSize + iconLabelGap
|
|
67
|
+
: plainLabelInset;
|
|
68
|
+
const attached = overlays.get(element.id) ?? [];
|
|
69
|
+
const notesHeight = attached.length
|
|
70
|
+
? attached.reduce((height, note) => height + note.height, 0) + (attached.length - 1) * noteInset - noteOverlap
|
|
71
|
+
: 0;
|
|
72
|
+
const headerHeight = Math.max(minimumHeaderHeight, label.height + headerLabelPadding);
|
|
73
|
+
const width = Math.max(minimumElementWidth, label.width + 2 * labelInset, ...attached.map(({ width }) => width + 2 * noteInset));
|
|
74
|
+
nodes.set(internalId, { element, type, notation, label, headerHeight, notesHeight });
|
|
75
|
+
nodeIds.set(element.id, internalId);
|
|
76
|
+
elkNodes.set(element.id, { id: internalId, width, height: headerHeight + notesHeight });
|
|
77
|
+
for (const { note } of attached)
|
|
78
|
+
nodeIds.set(note.id, internalId);
|
|
79
|
+
}
|
|
80
|
+
return { nodes, notes, overlays, nodeIds, elkNodes, children };
|
|
81
|
+
}
|
|
82
|
+
// Moves members into their containers and returns the layout ids of the nested members.
|
|
83
|
+
function nestLayoutNodes(model, { nodes, elkNodes, children }) {
|
|
84
|
+
const nested = new Set();
|
|
85
|
+
const notesBelow = notesBelowHost(model);
|
|
86
|
+
for (const { parent, child } of model.nesting ?? []) {
|
|
87
|
+
const container = elkNodes.get(parent);
|
|
88
|
+
const member = elkNodes.get(child);
|
|
89
|
+
const appearance = container && nodes.get(container.id);
|
|
90
|
+
if (!container || !member || !appearance) {
|
|
91
|
+
throw new Error(`Layout nodes for nesting "${child}" in "${parent}" are unavailable.`);
|
|
92
|
+
}
|
|
93
|
+
nested.add(member.id);
|
|
94
|
+
if (!container.children) {
|
|
95
|
+
container.children = [];
|
|
96
|
+
const top = appearance.headerHeight + (notesBelow ? 0 : appearance.notesHeight);
|
|
97
|
+
const bottom = layoutPadding + (notesBelow ? appearance.notesHeight : 0);
|
|
98
|
+
// ELK Layered reads compound minimum sizes in its horizontal coordinate system.
|
|
99
|
+
const vertical = model.direction === 'TB' || model.direction === 'BT';
|
|
100
|
+
const minimumSize = vertical
|
|
101
|
+
? `(${container.height},${container.width})`
|
|
102
|
+
: `(${container.width},${container.height})`;
|
|
103
|
+
container.layoutOptions = {
|
|
104
|
+
'elk.padding': `[top=${top},left=${layoutPadding},bottom=${bottom},right=${layoutPadding}]`,
|
|
105
|
+
'elk.nodeSize.constraints': 'MINIMUM_SIZE',
|
|
106
|
+
'elk.nodeSize.minimum': minimumSize,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
container.children.push(member);
|
|
110
|
+
}
|
|
111
|
+
for (const node of elkNodes.values()) {
|
|
112
|
+
if (!nested.has(node.id))
|
|
113
|
+
children.push(node);
|
|
114
|
+
}
|
|
115
|
+
return nested;
|
|
116
|
+
}
|
|
117
|
+
function layoutEdges(model, measured, nodeIds, parents) {
|
|
118
|
+
const edges = new Map();
|
|
119
|
+
const overlayLaneCounts = new Map();
|
|
120
|
+
const nestingRelationships = new Set(model.nesting?.flatMap(({ relationship }) => relationship ?? []));
|
|
121
|
+
const architecture = usesArchitectureLayout(model);
|
|
122
|
+
const noteHosts = new Map((model.notes ?? []).map((note) => [note.id, note.on]));
|
|
123
|
+
const relationships = [];
|
|
124
|
+
const encloses = (outer, inner) => ancestors(inner ?? '', parents).includes(outer);
|
|
125
|
+
const nestedWithHost = (note, other) => {
|
|
126
|
+
const host = noteHosts.get(note);
|
|
127
|
+
return host !== undefined && (encloses(other, host) || encloses(host, other));
|
|
128
|
+
};
|
|
129
|
+
const endpointNames = new Map([
|
|
130
|
+
...model.elements.map(({ id, name }) => [id, name]),
|
|
131
|
+
...(model.notes ?? []).map(({ id, text }) => [id, text]),
|
|
132
|
+
]);
|
|
133
|
+
for (const [index, relationship] of model.relationships.entries()) {
|
|
134
|
+
if (nestingRelationships.has(relationship.id) && !relationship.label && relationship.access === undefined) {
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
const source = nodeIds.get(relationship.source);
|
|
138
|
+
const target = nodeIds.get(relationship.target);
|
|
139
|
+
const notation = getRelationshipNotation(relationship.type, relationship.access, relationship.directed);
|
|
140
|
+
if (!source || !target || !notation) {
|
|
141
|
+
throw new Error(`SVG notation or endpoints for relationship "${relationship.id}" are unavailable.`);
|
|
142
|
+
}
|
|
143
|
+
const internalId = `e${index}`;
|
|
144
|
+
const label = measured.relationshipLabels.get(relationship.id);
|
|
145
|
+
const appearance = {
|
|
146
|
+
relationship,
|
|
147
|
+
notation,
|
|
148
|
+
label,
|
|
149
|
+
accessibleName: relationshipDescription(relationship, endpointNames),
|
|
150
|
+
};
|
|
151
|
+
// A route between an attached note and a container or member of its host would have to cross the host.
|
|
152
|
+
const enclosed = !architecture &&
|
|
153
|
+
(nestedWithHost(relationship.source, relationship.target) ||
|
|
154
|
+
nestedWithHost(relationship.target, relationship.source));
|
|
155
|
+
if ((source === target && relationship.source !== relationship.target) || enclosed) {
|
|
156
|
+
const host = enclosed
|
|
157
|
+
? nodeIds.get(noteHosts.get(relationship.source) ?? noteHosts.get(relationship.target) ?? '')
|
|
158
|
+
: source;
|
|
159
|
+
if (host === undefined) {
|
|
160
|
+
throw new Error(`The host of the attached note in relationship "${relationship.id}" is unavailable.`);
|
|
161
|
+
}
|
|
162
|
+
const lane = overlayLaneCounts.get(host) ?? 0;
|
|
163
|
+
appearance.overlayLane = lane;
|
|
164
|
+
appearance.overlayKey = host;
|
|
165
|
+
overlayLaneCounts.set(host, lane + 1);
|
|
166
|
+
}
|
|
167
|
+
edges.set(internalId, appearance);
|
|
168
|
+
relationships.push({
|
|
169
|
+
id: internalId,
|
|
170
|
+
sources: [source],
|
|
171
|
+
targets: [target],
|
|
172
|
+
...(label ? { labels: [{ id: `l${index}`, width: label.width + edgeLabelPadding, height: label.height }] } : {}),
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
return { edges, overlayLaneCounts, relationships };
|
|
176
|
+
}
|
|
177
|
+
export function buildLayoutGraph(model, measured, parents) {
|
|
178
|
+
const placed = layoutNodes(measured, model);
|
|
179
|
+
const { nodes, notes, overlays, nodeIds, children } = placed;
|
|
180
|
+
const nested = nestLayoutNodes(model, placed);
|
|
181
|
+
const { edges, overlayLaneCounts, relationships } = layoutEdges(model, measured, nodeIds, parents);
|
|
182
|
+
const input = {
|
|
183
|
+
id: 'archimate',
|
|
184
|
+
layoutOptions: {
|
|
185
|
+
'elk.algorithm': 'layered',
|
|
186
|
+
'elk.direction': layoutDirection[model.direction],
|
|
187
|
+
'elk.edgeRouting': 'ORTHOGONAL',
|
|
188
|
+
'elk.padding': `[top=${layoutPadding},left=${layoutPadding},bottom=${layoutPadding},right=${layoutPadding}]`,
|
|
189
|
+
'elk.spacing.nodeNode': String(elkNodeSpacing),
|
|
190
|
+
'elk.layered.spacing.nodeNodeBetweenLayers': String(elkLayerSpacing),
|
|
191
|
+
'elk.json.shapeCoords': 'ROOT',
|
|
192
|
+
'elk.json.edgeCoords': 'ROOT',
|
|
193
|
+
...(nested.size > 0 ? { 'elk.hierarchyHandling': 'INCLUDE_CHILDREN' } : {}),
|
|
194
|
+
},
|
|
195
|
+
children,
|
|
196
|
+
edges: relationships,
|
|
197
|
+
};
|
|
198
|
+
return { input, nodes, notes, overlays, edges, overlayLaneCounts, nested };
|
|
199
|
+
}
|
|
200
|
+
//# sourceMapp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,eAAe,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAC9C,MAAM,EAAE,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,GAAG,WAAW,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;IACnG,MAAM,KAAK,GAAG;QACZ,EAAE,EAAE,WAAW;QACf,aAAa,EAAE;YACb,eAAe,EAAE,SAAS;YAC1B,eAAe,EAAE,eAAe,CAAC,KAAK,CAAC,SAAS,CAAC;YACjD,iBAAiB,EAAE,YAAY;YAC/B,aAAa,EAAE,QAAQ,aAAa,SAAS,aAAa,WAAW,aAAa,UAAU,aAAa,GAAG;YAC5G,sBAAsB,EAAE,MAAM,CAAC,cAAc,CAAC;YAC9C,2CAA2C,EAAE,MAAM,CAAC,eAAe,CAAC;YACpE,sBAAsB,EAAE,MAAM;YAC9B,qBAAqB,EAAE,MAAM;YAC7B,GAAG,CAAC,MAAM,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAC5E;QACD,QAAQ;QACR,KAAK,EAAE,aAAa;KACrB,CAAC;IACF,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,iBAAiB,EAAE,MAAM,EAAE,CAAC;AAC7E,CAAC","sourcesContent":["import type { ElkExtendedEdge, ElkNode } from 'elkjs/lib/elk.bundled.js';\nimport {\n getRelationshipNotation,\n relationshipNames,\n relationshipTypes,\n type SpecifiedAccessMode,\n type RelationshipType,\n} from '../../archimate/catalogue.js';\nimport type { ArchiMateModel } from '../../archimate/model.js';\nimport { ancestors } from '../hierarchy.js';\nimport type { MeasuredDiagram } from './measure.js';\nimport {\n edgeLabelPadding,\n elkLayerSpacing,\n elkNodeSpacing,\n headerLabelPadding,\n iconLabelGap,\n iconRightInset,\n iconSize,\n layoutPadding,\n minimumElementWidth,\n minimumHeaderHeight,\n minimumNoteHeight,\n noteFold,\n noteInset,\n noteOverlap,\n notesBelowHost,\n plainLabelInset,\n usesArchitectureLayout,\n type EdgeAppearance,\n type MeasuredElkNode,\n type NodeAppearance,\n type NoteAppearance,\n type Relationship,\n} from './shared.js';\n\nconst layoutDirection = {\n TB: 'DOWN',\n BT: 'UP',\n LR: 'RIGHT',\n RL: 'LEFT',\n} satisfies Record<ArchiMateModel['direction'], string>;\n\nfunction isRelationshipType(type: string): type is RelationshipType {\n return (relationshipTypes as readonly string[]).includes(type);\n}\n\nconst accessModeWords = {\n read: 'read',\n write: 'write',\n readWrite: 'read and write',\n} satisfies Record<SpecifiedAccessMode, string>;\n\nfunction relationshipDescription(relationship: Relationship, names: ReadonlyMap<string, string>): string {\n const typeName = isRelationshipType(relationship.type) ? relationshipNames[relationship.type] : relationship.type;\n const mode = relationship.type === 'access' ? relationship.access && accessModeWords[relationship.access] : undefined;\n const qualifier = mode\n ? ` (${mode})`\n : relationship.type === 'association' && relationship.directed\n ? ' (directed)'\n : '';\n const source = names.get(relationship.source) ?? relationship.source;\n const target = names.get(relationship.target) ?? relationship.target;\n const description = `${source} — ${typeName}${qualifier} → ${target}`;\n return relationship.label ? `${description}: ${relationship.label}` : description;\n}\n\nexport interface LayoutGraph {\n readonly input: ElkNode & { children: MeasuredElkNode[]; edges: ElkExtendedEdge[] };\n // Keyed by layout node id.\n readonly nodes: ReadonlyMap<string, NodeAppearance>;\n readonly notes: ReadonlyMap<string, NoteAppearance>;\n // Attached notes, keyed by the id of the element they are attached to.\n readonly overlays: ReadonlyMap<string, readonly NoteAppearance[]>;\n // Keyed by layout edge id.\n readonly edges: ReadonlyMap<string, EdgeAppearance>;\n readonly overlayLaneCounts: ReadonlyMap<string, number>;\n // Layout node ids of elements nested in another element.\n readonly nested: ReadonlySet<string>;\n}\n\ninterface LayoutNodes {\n readonly nodes: Map<string, NodeAppearance>;\n readonly notes: Map<string, NoteAppearance>;\n readonly overlays: Map<string, NoteAppearance[]>;\n // Layout node id by model id; an attached note shares its host's layout node.\n readonly nodeIds: Map<string, string>;\n readonly elkNodes: Map<string, MeasuredElkNode>;\n readonly children: MeasuredElkNode[];\n}\n\nfunction layoutNodes(measured: MeasuredDiagram, model: ArchiMateModel): LayoutNodes {\n const nodes = new Map<string, NodeAppearance>();\n const notes = new Map<string, NoteAppearance>();\n const overlays = new Map<string, NoteAppearance[]>();\n const nodeIds = new Map<string, string>();\n const children: MeasuredElkNode[] = [];\n for (const [index, note] of (model.notes ?? []).entries()) {\n const label = measured.notes[index];\n if (!label) throw new Error(`The note \"${note.id}\" was not measured.`);\n const appearance = {\n note,\n label,\n width: Math.max(minimumElementWidth, label.width + 2 * (noteInset + noteFold)),\n height: Math.max(minimumNoteHeight, label.height + 2 * noteInset),\n };\n if (note.on !== undefined) {\n const attached = overlays.get(note.on);\n if (attached) attached.push(appearance);\n else overlays.set(note.on, [appearance]);\n } else {\n const id = `note${index}`;\n nodeIds.set(note.id, id);\n notes.set(id, appearance);\n children.push({ id, width: appearance.width, height: appearance.height });\n }\n }\n\n const elkNodes = new Map<string, MeasuredElkNode>();\n for (const [index, { element, type, notation, label }] of measured.elements.entries()) {\n const internalId = `n${index}`;\n // Reserve the same space on both sides so centered labels clear the icon.\n const labelInset = notation.icon?.length\n ? iconRightInset(notation.outline) + iconSize + iconLabelGap\n : plainLabelInset;\n const attached = overlays.get(element.id) ?? [];\n const notesHeight = attached.length\n ? attached.reduce((height, note) => height + note.height, 0) + (attached.length - 1) * noteInset - noteOverlap\n : 0;\n const headerHeight = Math.max(minimumHeaderHeight, label.height + headerLabelPadding);\n const width = Math.max(\n minimumElementWidth,\n label.width + 2 * labelInset,\n ...attached.map(({ width }) => width + 2 * noteInset),\n );\n nodes.set(internalId, { element, type, notation, label, headerHeight, notesHeight });\n nodeIds.set(element.id, internalId);\n elkNodes.set(element.id, { id: internalId, width, height: headerHeight + notesHeight });\n for (const { note } of attached) nodeIds.set(note.id, internalId);\n }\n return { nodes, notes, overlays, nodeIds, elkNodes, children };\n}\n\n// Moves members into their containers and returns the layout ids of the nested members.\nfunction nestLayoutNodes(model: ArchiMateModel, { nodes, elkNodes, children }: LayoutNodes): Set<string> {\n const nested = new Set<string>();\n const notesBelow = notesBelowHost(model);\n for (const { parent, child } of model.nesting ?? []) {\n const container = elkNodes.get(parent);\n const member = elkNodes.get(child);\n const appearance = container && nodes.get(container.id);\n if (!container || !member || !appearance) {\n throw new Error(`Layout nodes for nesting \"${child}\" in \"${parent}\" are unavailable.`);\n }\n nested.add(member.id);\n if (!container.children) {\n container.children = [];\n const top = appearance.headerHeight + (notesBelow ? 0 : appearance.notesHeight);\n const bottom = layoutPadding + (notesBelow ? appearance.notesHeight : 0);\n // ELK Layered reads compound minimum sizes in its horizontal coordinate system.\n const vertical = model.direction === 'TB' || model.direction === 'BT';\n const minimumSize = vertical\n ? `(${container.height},${container.width})`\n : `(${container.width},${container.height})`;\n container.layoutOptions = {\n 'elk.padding': `[top=${top},left=${layoutPadding},bottom=${bottom},right=${layoutPadding}]`,\n 'elk.nodeSize.constraints': 'MINIMUM_SIZE',\n 'elk.nodeSize.minimum': minimumSize,\n };\n }\n container.children.push(member);\n }\n for (const node of elkNodes.values()) {\n if (!nested.has(node.id)) children.push(node);\n }\n return nested;\n}\n\ninterface LayoutEdges {\n readonly edges: Map<string, EdgeAppearance>;\n readonly overlayLaneCounts: Map<string, number>;\n readonly relationships: ElkExtendedEdge[];\n}\n\nfunction layoutEdges(\n model: ArchiMateModel,\n measured: MeasuredDiagram,\n nodeIds: ReadonlyMap<string, string>,\n parents: ReadonlyMap<string, string>,\n): LayoutEdges {\n const edges = new Map<string, EdgeAppearance>();\n const overlayLaneCounts = new Map<string, number>();\n const nestingRelationships = new Set(model.nesting?.flatMap(({ relationship }) => relationship ?? []));\n const architecture = usesArchitectureLayout(model);\n const noteHosts = new Map((model.notes ?? []).map((note) => [note.id, note.on]));\n const relationships: ElkExtendedEdge[] = [];\n const encloses = (outer: string, inner: string | undefined): boolean =>\n ancestors(inner ?? '', parents).includes(outer);\n const nestedWithHost = (note: string, other: string): boolean => {\n const host = noteHosts.get(note);\n return host !== undefined && (encloses(other, host) || encloses(host, other));\n };\n const endpointNames = new Map([\n ...model.elements.map(({ id, name }) => [id, name] as const),\n ...(model.notes ?? []).map(({ id, text }) => [id, text] as const),\n ]);\n for (const [index, relationship] of model.relationships.entries()) {\n if (nestingRelationships.has(relationship.id) && !relationship.label && relationship.access === undefined) {\n continue;\n }\n const source = nodeIds.get(relationship.source);\n const target = nodeIds.get(relationship.target);\n const notation = getRelationshipNotation(relationship.type, relationship.access, relationship.directed);\n if (!source || !target || !notation) {\n throw new Error(`SVG notation or endpoints for relationship \"${relationship.id}\" are unavailable.`);\n }\n\n const internalId = `e${index}`;\n const label = measured.relationshipLabels.get(relationship.id);\n const appearance: EdgeAppearance = {\n relationship,\n notation,\n label,\n accessibleName: relationshipDescription(relationship, endpointNames),\n };\n // A route between an attached note and a container or member of its host would have to cross the host.\n const enclosed =\n !architecture &&\n (nestedWithHost(relationship.source, relationship.target) ||\n nestedWithHost(relationship.target, relationship.source));\n if ((source === target && relationship.source !== relationship.target) || enclosed) {\n const host = enclosed\n ? nodeIds.get(noteHosts.get(relationship.source) ?? noteHosts.get(relationship.target) ?? '')\n : source;\n if (host === undefined) {\n throw new Error(`The host of the attached note in relationship \"${relationship.id}\" is unavailable.`);\n }\n const lane = overlayLaneCounts.get(host) ?? 0;\n appearance.overlayLane = lane;\n appearance.overlayKey = host;\n overlayLaneCounts.set(host, lane + 1);\n }\n edges.set(internalId, appearance);\n relationships.push({\n id: internalId,\n sources: [source],\n targets: [target],\n ...(label ? { labels: [{ id: `l${index}`, width: label.width + edgeLabelPadding, height: label.height }] } : {}),\n });\n }\n return { edges, overlayLaneCounts, relationships };\n}\n\nexport function buildLayoutGraph(\n model: ArchiMateModel,\n measured: MeasuredDiagram,\n parents: ReadonlyMap<string, string>,\n): LayoutGraph {\n const placed = layoutNodes(measured, model);\n const { nodes, notes, overlays, nodeIds, children } = placed;\n const nested = nestLayoutNodes(model, placed);\n const { edges, overlayLaneCounts, relationships } = layoutEdges(model, measured, nodeIds, parents);\n const input = {\n id: 'archimate',\n layoutOptions: {\n 'elk.algorithm': 'layered',\n 'elk.direction': layoutDirection[model.direction],\n 'elk.edgeRouting': 'ORTHOGONAL',\n 'elk.padding': `[top=${layoutPadding},left=${layoutPadding},bottom=${layoutPadding},right=${layoutPadding}]`,\n 'elk.spacing.nodeNode': String(elkNodeSpacing),\n 'elk.layered.spacing.nodeNodeBetweenLayers': String(elkLayerSpacing),\n 'elk.json.shapeCoords': 'ROOT',\n 'elk.json.edgeCoords': 'ROOT',\n ...(nested.size > 0 ? { 'elk.hierarchyHandling': 'INCLUDE_CHILDREN' } : {}),\n },\n children,\n edges: relationships,\n };\n return { input, nodes, notes, overlays, edges, overlayLaneCounts, nested };\n}\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ElkPoint } from 'elkjs/lib/elk.bundled.js';
|
|
2
|
+
import type { RouteBundle } from '../orthogonalRouter.js';
|
|
3
|
+
import type { Placement } from './place.js';
|
|
4
|
+
import type { RoutedEdge } from './route.js';
|
|
5
|
+
import { type EdgeAppearance } from './shared.js';
|
|
6
|
+
export interface PlacedEdge {
|
|
7
|
+
readonly appearance: EdgeAppearance;
|
|
8
|
+
readonly points: ElkPoint[];
|
|
9
|
+
readonly labelPosition: ElkPoint | undefined;
|
|
10
|
+
readonly bundle: RouteBundle | undefined;
|
|
11
|
+
}
|
|
12
|
+
export declare function placeLabels(routed: readonly RoutedEdge[], placement: Placement, architecture: boolean): PlacedEdge[];
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { required } from '../invariant.js';
|
|
2
|
+
import { compoundLabelInset, edgeLabelPadding, } from './shared.js';
|
|
3
|
+
// How far along a segment, from its start, other paths run on top of it.
|
|
4
|
+
function coveredFrom(start, end, others) {
|
|
5
|
+
const length = Math.hypot(end.x - start.x, end.y - start.y);
|
|
6
|
+
const vertical = start.x === end.x;
|
|
7
|
+
const direction = vertical ? Math.sign(end.y - start.y) : Math.sign(end.x - start.x);
|
|
8
|
+
let covered = 0;
|
|
9
|
+
for (const path of others) {
|
|
10
|
+
for (let index = 1; index < path.length; index++) {
|
|
11
|
+
const a = path[index - 1];
|
|
12
|
+
const b = path[index];
|
|
13
|
+
if (!a || !b)
|
|
14
|
+
continue;
|
|
15
|
+
const onLine = vertical ? a.x === start.x && b.x === start.x : a.y === start.y && b.y === start.y;
|
|
16
|
+
if (!onLine)
|
|
17
|
+
continue;
|
|
18
|
+
const from = vertical ? start.y : start.x;
|
|
19
|
+
const low = Math.min(vertical ? a.y : a.x, vertical ? b.y : b.x);
|
|
20
|
+
const high = Math.max(vertical ? a.y : a.x, vertical ? b.y : b.x);
|
|
21
|
+
if (from < low || from > high)
|
|
22
|
+
continue;
|
|
23
|
+
covered = Math.max(covered, Math.min(length, direction > 0 ? high - from : from - low));
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return covered;
|
|
27
|
+
}
|
|
28
|
+
// The part of a bundled path that no sibling shares, starting where it leaves the common trunk.
|
|
29
|
+
function unsharedBranch(points, siblings, sharedEnd) {
|
|
30
|
+
const path = sharedEnd === 'start' ? [...points] : points.toReversed();
|
|
31
|
+
const others = sharedEnd === 'start' ? siblings : siblings.map((sibling) => sibling.toReversed());
|
|
32
|
+
for (let index = 1; index < path.length; index++) {
|
|
33
|
+
const start = path[index - 1];
|
|
34
|
+
const end = path[index];
|
|
35
|
+
if (!start || !end)
|
|
36
|
+
continue;
|
|
37
|
+
const length = Math.hypot(end.x - start.x, end.y - start.y);
|
|
38
|
+
const covered = coveredFrom(start, end, others);
|
|
39
|
+
if (covered >= length)
|
|
40
|
+
continue;
|
|
41
|
+
const fraction = covered / length;
|
|
42
|
+
const split = { x: start.x + (end.x - start.x) * fraction, y: start.y + (end.y - start.y) * fraction };
|
|
43
|
+
const branch = [split, ...path.slice(index)];
|
|
44
|
+
return sharedEnd === 'start' ? branch : branch.toReversed();
|
|
45
|
+
}
|
|
46
|
+
return [...points];
|
|
47
|
+
}
|
|
48
|
+
function labelNearRoute(label, points) {
|
|
49
|
+
const centreX = label.x + label.width / 2;
|
|
50
|
+
const centreY = label.y + label.height / 2;
|
|
51
|
+
return points.some((start, index) => {
|
|
52
|
+
const end = points[index + 1];
|
|
53
|
+
if (!end)
|
|
54
|
+
return false;
|
|
55
|
+
const horizontal = Math.abs(start.x - end.x) >= Math.abs(start.y - end.y);
|
|
56
|
+
const along = horizontal ? centreX : centreY;
|
|
57
|
+
const from = horizontal ? start.x : start.y;
|
|
58
|
+
const to = horizontal ? end.x : end.y;
|
|
59
|
+
const across = horizontal
|
|
60
|
+
? Math.abs(centreY - (start.y + end.y) / 2) - label.height / 2
|
|
61
|
+
: Math.abs(centreX - (start.x + end.x) / 2) - label.width / 2;
|
|
62
|
+
return along >= Math.min(from, to) && along <= Math.max(from, to) && across >= 0 && across <= 8;
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
function edgeLabelPosition(points, metrics, obstacles, { hint, hintNearRoute, searchAllSegments }) {
|
|
66
|
+
const width = metrics.width + edgeLabelPadding;
|
|
67
|
+
const { height } = metrics;
|
|
68
|
+
const isClear = ({ x, y }) => !obstacles.some((box) => x < box.x + box.width && x + width > box.x && y < box.y + box.height && y + height > box.y);
|
|
69
|
+
if (hint && isClear(hint) && (!hintNearRoute || labelNearRoute({ ...hint, width, height }, points))) {
|
|
70
|
+
return hint;
|
|
71
|
+
}
|
|
72
|
+
// Labels beside a route leave short paths and their markers visible.
|
|
73
|
+
const segments = [];
|
|
74
|
+
for (let index = 1; index < points.length; index++) {
|
|
75
|
+
const start = points[index - 1];
|
|
76
|
+
const end = points[index];
|
|
77
|
+
if (start && end)
|
|
78
|
+
segments.push({ start, end, length: Math.hypot(end.x - start.x, end.y - start.y) });
|
|
79
|
+
}
|
|
80
|
+
segments.sort((a, b) => b.length - a.length);
|
|
81
|
+
let fallback;
|
|
82
|
+
for (const { start, end } of segments) {
|
|
83
|
+
const horizontal = Math.abs(start.x - end.x) >= Math.abs(start.y - end.y);
|
|
84
|
+
const along = horizontal ? 'x' : 'y';
|
|
85
|
+
const across = horizontal ? 'y' : 'x';
|
|
86
|
+
const alongSize = horizontal ? width : height;
|
|
87
|
+
const acrossSize = horizontal ? height : width;
|
|
88
|
+
const preferred = (start[along] + end[along] - alongSize) / 2;
|
|
89
|
+
const minimum = Math.min(start[along], end[along]) - alongSize / 2;
|
|
90
|
+
const maximum = Math.max(start[along], end[along]) - alongSize / 2;
|
|
91
|
+
const middle = (start[across] + end[across]) / 2;
|
|
92
|
+
const sides = horizontal ? [middle - height - 4, middle + 4] : [middle + 4, middle - width - 4];
|
|
93
|
+
const position = (coordinate, side) => horizontal ? { x: coordinate, y: side } : { x: side, y: coordinate };
|
|
94
|
+
const nearby = [0, -0.5, 0.5].flatMap((shift) => sides.map((side) => position(preferred + shift * alongSize, side)));
|
|
95
|
+
fallback ??= nearby[0];
|
|
96
|
+
const nearbyClear = nearby.find(isClear);
|
|
97
|
+
if (nearbyClear)
|
|
98
|
+
return nearbyClear;
|
|
99
|
+
if (!searchAllSegments)
|
|
100
|
+
break;
|
|
101
|
+
for (const side of sides) {
|
|
102
|
+
const candidates = obstacles
|
|
103
|
+
.flatMap((box) => {
|
|
104
|
+
const acrossEnd = box[across] + (horizontal ? box.height : box.width);
|
|
105
|
+
if (side >= acrossEnd || side + acrossSize <= box[across])
|
|
106
|
+
return [];
|
|
107
|
+
return [box[along] - alongSize - 0.5, box[along] + (horizontal ? box.width : box.height) + 0.5];
|
|
108
|
+
})
|
|
109
|
+
.filter((coordinate) => coordinate >= minimum && coordinate <= maximum)
|
|
110
|
+
.sort((a, b) => Math.abs(a - preferred) - Math.abs(b - preferred));
|
|
111
|
+
const clear = candidates.map((coordinate) => position(coordinate, side)).find(isClear);
|
|
112
|
+
if (clear)
|
|
113
|
+
return clear;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return required(fallback, 'a label position beside the route');
|
|
117
|
+
}
|
|
118
|
+
export function placeLabels(routed, placement, architecture) {
|
|
119
|
+
const labelObstacles = [
|
|
120
|
+
...placement.notes.map(({ box }) => box),
|
|
121
|
+
...placement.elements.map(({ appearance, box, compound }) => compound ? { ...box, height: compoundLabelInset + appearance.label.height } : box),
|
|
122
|
+
];
|
|
123
|
+
return routed.map(({ id, appearance, points, label, bundle }) => {
|
|
124
|
+
const selfLoop = architecture && appearance.relationship.source === appearance.relationship.target;
|
|
125
|
+
const siblings = bundle
|
|
126
|
+
? routed.filter((other) => other.bundle?.id === bundle.id && other.id !== id).map((other) => other.points)
|
|
127
|
+
: [];
|
|
128
|
+
// A loop's label belongs beside its outer segment, away from the element it returns to. A bundled
|
|
129
|
+
// relationship's label belongs on its own branch, where it cannot be mistaken for its siblings'.
|
|
130
|
+
const labelPoints = selfLoop
|
|
131
|
+
? points.slice(1, 3)
|
|
132
|
+
: bundle
|
|
133
|
+
? unsharedBranch(points, siblings, bundle.sharedEnd)
|
|
134
|
+
: points;
|
|
135
|
+
const labelPosition = appearance.label
|
|
136
|
+
? edgeLabelPosition(labelPoints, appearance.label, labelObstacles, label)
|
|
137
|
+
: undefined;
|
|
138
|
+
if (architecture && labelPosition && appearance.label) {
|
|
139
|
+
labelObstacles.push({
|
|
140
|
+
...labelPosition,
|
|
141
|
+
width: appearance.label.width + edgeLabelPadding,
|
|
142
|
+
height: appearance.label.height,
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
return { appearance, points, labelPosition, bundle };
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
//# sourceMappingURL=labels.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"labels.js","sourceRoot":"","sources":["../../../src/mermaid/render/labels.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAI3C,OAAO,EACL,kBAAkB,EAClB,gBA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AAK,CAAC;YACzE,CAAC,CAAC,SAAS,CAAC;QACd,IAAI,YAAY,IAAI,aAAa,IAAI,UAAU,CAAC,KAAK,EAAE,CAAC;YACtD,cAAc,CAAC,IAAI,CAAC;gBAClB,GAAG,aAAa;gBAChB,KAAK,EAAE,UAAU,CAAC,KAAK,CAAC,KAAK,GAAG,gBAAgB;gBAChD,MAAM,EAAE,UAAU,CAAC,KAAK,CAAC,MAAM;aAChC,CAAC,CAAC;QACL,CAAC;QACD,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,CAAC;IACvD,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { ElkPoint } from 'elkjs/lib/elk.bundled.js';\nimport { required } from '../invariant.js';\nimport type { RouteBundle } from '../orthogonalRouter.js';\nimport type { Placement } from './place.js';\nimport type { LabelStrategy, RoutedEdge } from './route.js';\nimport {\n compoundLabelInset,\n edgeLabelPadding,\n type EdgeAppearance,\n type PositionedNode,\n type TextMetrics,\n} from './shared.js';\n\n// How far along a segment, from its start, other paths run on top of it.\nfunction coveredFrom(start: ElkPoint, end: ElkPoint, others: readonly (readonly ElkPoint[])[]): number {\n const length = Math.hypot(end.x - start.x, end.y - start.y);\n const vertical = start.x === end.x;\n const direction = vertical ? Math.sign(end.y - start.y) : Math.sign(end.x - start.x);\n let covered = 0;\n for (const path of others) {\n for (let index = 1; index < path.length; index++) {\n const a = path[index - 1];\n const b = path[index];\n if (!a || !b) continue;\n const onLine = vertical ? a.x === start.x && b.x === start.x : a.y === start.y && b.y === start.y;\n if (!onLine) continue;\n const from = vertical ? start.y : start.x;\n const low = Math.min(vertical ? a.y : a.x, vertical ? b.y : b.x);\n const high = Math.max(vertical ? a.y : a.x, vertical ? b.y : b.x);\n if (from < low || from > high) continue;\n covered = Math.max(covered, Math.min(length, direction > 0 ? high - from : from - low));\n }\n }\n return covered;\n}\n\n// The part of a bundled path that no sibling shares, starting where it leaves the common trunk.\nfunction unsharedBranch(\n points: readonly ElkPoint[],\n siblings: readonly (readonly ElkPoint[])[],\n sharedEnd: 'start' | 'end',\n): ElkPoint[] {\n const path = sharedEnd === 'start' ? [...points] : points.toReversed();\n const others = sharedEnd === 'start' ? siblings : siblings.map((sibling) => sibling.toReversed());\n for (let index = 1; index < path.length; index++) {\n const start = path[index - 1];\n const end = path[index];\n if (!start || !end) continue;\n const length = Math.hypot(end.x - start.x, end.y - start.y);\n const covered = coveredFrom(start, end, others);\n if (covered >= length) continue;\n const fraction = covered / length;\n const split = { x: start.x + (end.x - start.x) * fraction, y: start.y + (end.y - start.y) * fraction };\n const branch = [split, ...path.slice(index)];\n return sharedEnd === 'start' ? branch : branch.toReversed();\n }\n return [...points];\n}\n\nfunction labelNearRoute(label: PositionedNode, points: readonly ElkPoint[]): boolean {\n const centreX = label.x + label.width / 2;\n const centreY = label.y + label.height / 2;\n return points.some((start, index) => {\n const end = points[index + 1];\n if (!end) return false;\n const horizontal = Math.abs(start.x - end.x) >= Math.abs(start.y - end.y);\n const along = horizontal ? centreX : centreY;\n const from = horizontal ? start.x : start.y;\n const to = horizontal ? end.x : end.y;\n const across = horizontal\n ? Math.abs(centreY - (start.y + end.y) / 2) - label.height / 2\n : Math.abs(centreX - (start.x + end.x) / 2) - label.width / 2;\n return along >= Math.min(from, to) && along <= Math.max(from, to) && across >= 0 && across <= 8;\n });\n}\n\nfunction edgeLabelPosition(\n points: readonly ElkPoint[],\n metrics: TextMetrics,\n obstacles: readonly PositionedNode[],\n { hint, hintNearRoute, searchAllSegments }: LabelStrategy,\n): ElkPoint {\n const width = metrics.width + edgeLabelPadding;\n const { height } = metrics;\n const isClear = ({ x, y }: ElkPoint) =>\n !obstacles.some(\n (box) => x < box.x + box.width && x + width > box.x && y < box.y + box.height && y + height > box.y,\n );\n if (hint && isClear(hint) && (!hintNearRoute || labelNearRoute({ ...hint, width, height }, points))) {\n return hint;\n }\n // Labels beside a route leave short paths and their markers visible.\n const segments: { start: ElkPoint; end: ElkPoint; length: number }[] = [];\n for (let index = 1; index < points.length; index++) {\n const start = points[index - 1];\n const end = points[index];\n if (start && end) segments.push({ start, end, length: Math.hypot(end.x - start.x, end.y - start.y) });\n }\n segments.sort((a, b) => b.length - a.length);\n let fallback: ElkPoint | undefined;\n for (const { start, end } of segments) {\n const horizontal = Math.abs(start.x - end.x) >= Math.abs(start.y - end.y);\n const along = horizontal ? 'x' : 'y';\n const across = horizontal ? 'y' : 'x';\n const alongSize = horizontal ? width : height;\n const acrossSize = horizontal ? height : width;\n const preferred = (start[along] + end[along] - alongSize) / 2;\n const minimum = Math.min(start[along], end[along]) - alongSize / 2;\n const maximum = Math.max(start[along], end[along]) - alongSize / 2;\n const middle = (start[across] + end[across]) / 2;\n const sides = horizontal ? [middle - height - 4, middle + 4] : [middle + 4, middle - width - 4];\n const position = (coordinate: number, side: number) =>\n horizontal ? { x: coordinate, y: side } : { x: side, y: coordinate };\n const nearby = [0, -0.5, 0.5].flatMap((shift) =>\n sides.map((side) => position(preferred + shift * alongSize, side)),\n );\n fallback ??= nearby[0];\n const nearbyClear = nearby.find(isClear);\n if (nearbyClear) return nearbyClear;\n if (!searchAllSegments) break;\n\n for (const side of sides) {\n const candidates = obstacles\n .flatMap((box) => {\n const acrossEnd = box[across] + (horizontal ? box.height : box.width);\n if (side >= acrossEnd || side + acrossSize <= box[across]) return [];\n return [box[along] - alongSize - 0.5, box[along] + (horizontal ? box.width : box.height) + 0.5];\n })\n .filter((coordinate) => coordinate >= minimum && coordinate <= maximum)\n .sort((a, b) => Math.abs(a - preferred) - Math.abs(b - preferred));\n const clear = candidates.map((coordinate) => position(coordinate, side)).find(isClear);\n if (clear) return clear;\n }\n }\n return required(fallback, 'a label position beside the route');\n}\n\nexport interface PlacedEdge {\n readonly appearance: EdgeAppearance;\n readonly points: ElkPoint[];\n readonly labelPosition: ElkPoint | undefined;\n readonly bundle: RouteBundle | undefined;\n}\n\nexport function placeLabels(routed: readonly RoutedEdge[], placement: Placement, architecture: boolean): PlacedEdge[] {\n const labelObstacles = [\n ...placement.notes.map(({ box }) => box),\n ...placement.elements.map(({ appearance, box, compound }) =>\n compound ? { ...box, height: compoundLabelInset + appearance.label.height } : box,\n ),\n ];\n return routed.map(({ id, appearance, points, label, bundle }) => {\n const selfLoop = architecture && appearance.relationship.source === appearance.relationship.target;\n const siblings = bundle\n ? routed.filter((other) => other.bundle?.id === bundle.id && other.id !== id).map((other) => other.points)\n : [];\n // A loop's label belongs beside its outer segment, away from the element it returns to. A bundled\n // relationship's label belongs on its own branch, where it cannot be mistaken for its siblings'.\n const labelPoints = selfLoop\n ? points.slice(1, 3)\n : bundle\n ? unsharedBranch(points, siblings, bundle.sharedEnd)\n : points;\n const labelPosition = appearance.label\n ? edgeLabelPosition(labelPoints, appearance.label, labelObstacles, label)\n : undefined;\n if (architecture && labelPosition && appearance.label) {\n labelObstacles.push({\n ...labelPosition,\n width: appearance.label.width + edgeLabelPadding,\n height: appearance.label.height,\n });\n }\n return { appearance, points, labelPosition, bundle };\n });\n}\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ELK, ElkNode } from 'elkjs/lib/elk.bundled.js';
|
|
2
|
+
import type { ArchiMateModel } from '../../archimate/model.js';
|
|
3
|
+
import type { LayoutGraph } from './graph.js';
|
|
4
|
+
type ElkConstructor = new () => ELK;
|
|
5
|
+
export declare function resolveElkConstructor(loaded: unknown): ElkConstructor;
|
|
6
|
+
export interface DiagramLayout {
|
|
7
|
+
readonly root: ElkNode;
|
|
8
|
+
readonly width: number;
|
|
9
|
+
readonly height: number;
|
|
10
|
+
}
|
|
11
|
+
export declare function layoutDiagram(model: ArchiMateModel, { input, nodes, edges }: LayoutGraph, maxRowWidth: number): Promise<DiagramLayout>;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { placeArchitecture } from '../architectureLayout.js';
|
|
2
|
+
import { layoutPadding, usesArchitectureLayout } from './shared.js';
|
|
3
|
+
const architectureRows = ['strategy', 'business', 'application', 'technology', 'implementationAndMigration'];
|
|
4
|
+
function isElkConstructor(value) {
|
|
5
|
+
return typeof value === 'function';
|
|
6
|
+
}
|
|
7
|
+
function property(value, name) {
|
|
8
|
+
return (typeof value === 'object' || typeof value === 'function') && value !== null
|
|
9
|
+
? Reflect.get(value, name)
|
|
10
|
+
: undefined;
|
|
11
|
+
}
|
|
12
|
+
// ELK ships a CommonJS bundle that marks itself as an ES module. Depending on the bundler, the default
|
|
13
|
+
// import is the constructor itself or module.exports with the constructor on its default property.
|
|
14
|
+
export function resolveElkConstructor(loaded) {
|
|
15
|
+
const constructor = [loaded, property(loaded, 'default'), property(property(loaded, 'default'), 'default')].find(isElkConstructor);
|
|
16
|
+
if (!constructor) {
|
|
17
|
+
throw new Error('The elkjs module did not provide its layout constructor.');
|
|
18
|
+
}
|
|
19
|
+
return constructor;
|
|
20
|
+
}
|
|
21
|
+
let elkInstance;
|
|
22
|
+
// Only graph layout needs ELK, so the 1.5 MB bundle loads on first use.
|
|
23
|
+
function loadElk() {
|
|
24
|
+
elkInstance ??= import('elkjs/lib/elk.bundled.js')
|
|
25
|
+
.then((loaded) => new (resolveElkConstructor(loaded))())
|
|
26
|
+
.catch((error) => {
|
|
27
|
+
elkInstance = undefined;
|
|
28
|
+
throw error;
|
|
29
|
+
});
|
|
30
|
+
return elkInstance;
|
|
31
|
+
}
|
|
32
|
+
export async function layoutDiagram(model, { input, nodes, edges }, maxRowWidth) {
|
|
33
|
+
const root = usesArchitectureLayout(model)
|
|
34
|
+
? {
|
|
35
|
+
...input,
|
|
36
|
+
...placeArchitecture(input.children, new Map(Array.from(nodes, ([key, { type, headerHeight, notesHeight }]) => [
|
|
37
|
+
key,
|
|
38
|
+
{
|
|
39
|
+
row: type.category === 'composite' ? null : type.category === 'physical' ? 'technology' : type.category,
|
|
40
|
+
column: type.aspect === 'motivation' ? null : type.aspect,
|
|
41
|
+
headerHeight: headerHeight + notesHeight,
|
|
42
|
+
},
|
|
43
|
+
])), input.edges.flatMap(({ id: edgeId, sources: [source], targets: [target] }) => {
|
|
44
|
+
const type = edges.get(edgeId)?.relationship.type;
|
|
45
|
+
return source && target && type ? [{ source, target, type }] : [];
|
|
46
|
+
}), {
|
|
47
|
+
rowOrder: architectureRows,
|
|
48
|
+
padding: layoutPadding,
|
|
49
|
+
labelHeight: Array.from(edges.values()).reduce((height, edge) => Math.max(height, edge.label?.height ?? 0), 0),
|
|
50
|
+
framework: model.layout === 'framework',
|
|
51
|
+
maxRowWidth,
|
|
52
|
+
}),
|
|
53
|
+
}
|
|
54
|
+
: await (await loadElk()).layout(input);
|
|
55
|
+
if (root.width === undefined || root.height === undefined) {
|
|
56
|
+
throw new Error('ELK did not return the ArchiMate diagram size.');
|
|
57
|
+
}
|
|
58
|
+
return { root, width: root.width, height: root.height };
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=layout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"layout.js","sourceRoot":"","sources":["../../../src/mermaid/render/layout.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAE7D,OAAO,EAAE,aAAa,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAEpE,MAAM,gBAAgB,GAAG,CAAC,UAAU,EAAE,UAAU,EAAE,aAAa,EAAE,YAAY,EAAE,4BAA4B,CAAC,CAAC;AAG7G,SAAS,gBAAgB,CAAC,KAAc;IACtC,OAAO,OAAO,KAAK,KAAK,UAAU,CAAC;AACrC,CAAC;AAED,SAAS,QAAQ,CAAC,KAAc,EAAE,IAAY;IAC5C,OAAO,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,UAAU,CAAC,IAAI,KAAK,KAAK,IAAI;QACjF,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC;QAC1B,CAAC,CAAC,SAAS,CAAC;AAChB,CAAC;AAED,uGAAuG;AACvG,m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AE,CAAC;QAC1D,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;IACpE,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC;AAC1D,CAAC","sourcesContent":["import type { ELK, ElkNode } from 'elkjs/lib/elk.bundled.js';\nimport type { ArchiMateModel } from '../../archimate/model.js';\nimport { placeArchitecture } from '../architectureLayout.js';\nimport type { LayoutGraph } from './graph.js';\nimport { layoutPadding, usesArchitectureLayout } from './shared.js';\n\nconst architectureRows = ['strategy', 'business', 'application', 'technology', 'implementationAndMigration'];\ntype ElkConstructor = new () => ELK;\n\nfunction isElkConstructor(value: unknown): value is ElkConstructor {\n return typeof value === 'function';\n}\n\nfunction property(value: unknown, name: string): unknown {\n return (typeof value === 'object' || typeof value === 'function') && value !== null\n ? Reflect.get(value, name)\n : undefined;\n}\n\n// ELK ships a CommonJS bundle that marks itself as an ES module. Depending on the bundler, the default\n// import is the constructor itself or module.exports with the constructor on its default property.\nexport function resolveElkConstructor(loaded: unknown): ElkConstructor {\n const constructor = [loaded, property(loaded, 'default'), property(property(loaded, 'default'), 'default')].find(\n isElkConstructor,\n );\n if (!constructor) {\n throw new Error('The elkjs module did not provide its layout constructor.');\n }\n return constructor;\n}\n\nlet elkInstance: Promise<ELK> | undefined;\n\n// Only graph layout needs ELK, so the 1.5 MB bundle loads on first use.\nfunction loadElk(): Promise<ELK> {\n elkInstance ??= import('elkjs/lib/elk.bundled.js')\n .then((loaded) => new (resolveElkConstructor(loaded))())\n .catch((error: unknown) => {\n elkInstance = undefined;\n throw error;\n });\n return elkInstance;\n}\n\nexport interface DiagramLayout {\n readonly root: ElkNode;\n readonly width: number;\n readonly height: number;\n}\n\nexport async function layoutDiagram(\n model: ArchiMateModel,\n { input, nodes, edges }: LayoutGraph,\n maxRowWidth: number,\n): Promise<DiagramLayout> {\n const root: ElkNode = usesArchitectureLayout(model)\n ? {\n ...input,\n ...placeArchitecture(\n input.children,\n new Map(\n Array.from(nodes, ([key, { type, headerHeight, notesHeight }]) => [\n key,\n {\n row: type.category === 'composite' ? null : type.category === 'physical' ? 'technology' : type.category,\n column: type.aspect === 'motivation' ? null : type.aspect,\n headerHeight: headerHeight + notesHeight,\n },\n ]),\n ),\n input.edges.flatMap(({ id: edgeId, sources: [source], targets: [target] }) => {\n const type = edges.get(edgeId)?.relationship.type;\n return source && target && type ? [{ source, target, type }] : [];\n }),\n {\n rowOrder: architectureRows,\n padding: layoutPadding,\n labelHeight: Array.from(edges.values()).reduce(\n (height, edge) => Math.max(height, edge.label?.height ?? 0),\n 0,\n ),\n framework: model.layout === 'framework',\n maxRowWidth,\n },\n ),\n }\n : await (await loadElk()).layout(input);\n if (root.width === undefined || root.height === undefined) {\n throw new Error('ELK did not return the ArchiMate diagram size.');\n }\n return { root, width: root.width, height: root.height };\n}\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ArchiMateModel } from '../../archimate/model.js';
|
|
2
|
+
import type { DiagramTypography } from '../styles.js';
|
|
3
|
+
import { type Element, type ElementType, type TextMetrics } from './shared.js';
|
|
4
|
+
export interface MeasuredElement {
|
|
5
|
+
readonly element: Element;
|
|
6
|
+
readonly type: ElementType;
|
|
7
|
+
readonly notation: NonNullable<ElementType['notation']>;
|
|
8
|
+
readonly label: TextMetrics;
|
|
9
|
+
}
|
|
10
|
+
export interface MeasuredDiagram {
|
|
11
|
+
readonly title: TextMetrics | undefined;
|
|
12
|
+
readonly notes: readonly TextMetrics[];
|
|
13
|
+
readonly elements: readonly MeasuredElement[];
|
|
14
|
+
readonly relationshipLabels: ReadonlyMap<string, TextMetrics>;
|
|
15
|
+
}
|
|
16
|
+
export declare function measureDiagram(svg: SVGSVGElement, model: ArchiMateModel, title: string, typography: DiagramTypography): MeasuredDiagram;
|