@metronforge/concept-map 0.1.0 → 0.2.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/README.md +124 -93
- package/css/concept-map.css +31 -21
- package/dist/dom/badgeDom.d.ts +3 -0
- package/dist/dom/badgeDom.d.ts.map +1 -0
- package/dist/dom/badgeDom.js +23 -0
- package/dist/dom/badgeDom.js.map +1 -0
- package/dist/dom/geometry.d.ts.map +1 -1
- package/dist/dom/geometry.js +12 -2
- package/dist/dom/geometry.js.map +1 -1
- package/dist/dom/index.d.ts +6 -0
- package/dist/dom/index.d.ts.map +1 -0
- package/dist/dom/index.js +3 -0
- package/dist/dom/index.js.map +1 -0
- package/dist/dom/measureLabel.d.ts +4 -0
- package/dist/dom/measureLabel.d.ts.map +1 -0
- package/dist/dom/measureLabel.js +29 -0
- package/dist/dom/measureLabel.js.map +1 -0
- package/dist/dom/mount.d.ts +7 -0
- package/dist/dom/mount.d.ts.map +1 -0
- package/dist/dom/mount.js +37 -0
- package/dist/dom/mount.js.map +1 -0
- package/dist/dom/player.d.ts.map +1 -1
- package/dist/dom/player.js +3 -3
- package/dist/dom/player.js.map +1 -1
- package/dist/element/element.d.ts +26 -0
- package/dist/element/element.d.ts.map +1 -0
- package/dist/element/element.js +115 -0
- package/dist/element/element.js.map +1 -0
- package/dist/element/input.d.ts +7 -0
- package/dist/element/input.d.ts.map +1 -0
- package/dist/element/input.js +40 -0
- package/dist/element/input.js.map +1 -0
- package/dist/element/layout.d.ts +4 -0
- package/dist/element/layout.d.ts.map +1 -0
- package/dist/element/layout.js +14 -0
- package/dist/element/layout.js.map +1 -0
- package/dist/element.d.ts +9 -0
- package/dist/element.d.ts.map +1 -0
- package/dist/element.js +5 -0
- package/dist/element.js.map +1 -0
- package/dist/index.d.ts +4 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/layout/badges.d.ts +4 -0
- package/dist/layout/badges.d.ts.map +1 -0
- package/dist/layout/badges.js +45 -0
- package/dist/layout/badges.js.map +1 -0
- package/dist/layout/check.d.ts +5 -0
- package/dist/layout/check.d.ts.map +1 -0
- package/dist/layout/check.js +61 -0
- package/dist/layout/check.js.map +1 -0
- package/dist/layout/dagre.d.ts +4 -0
- package/dist/layout/dagre.d.ts.map +1 -0
- package/dist/layout/dagre.js +62 -0
- package/dist/layout/dagre.js.map +1 -0
- package/dist/layout/elk.d.ts +4 -0
- package/dist/layout/elk.d.ts.map +1 -0
- package/dist/layout/elk.js +98 -0
- package/dist/layout/elk.js.map +1 -0
- package/dist/layout/font-metrics.d.ts +3 -0
- package/dist/layout/font-metrics.d.ts.map +1 -0
- package/dist/layout/font-metrics.js +128 -0
- package/dist/layout/font-metrics.js.map +1 -0
- package/dist/layout/geometry.d.ts +7 -0
- package/dist/layout/geometry.d.ts.map +1 -0
- package/dist/layout/geometry.js +56 -0
- package/dist/layout/geometry.js.map +1 -0
- package/dist/layout/graph.d.ts +6 -0
- package/dist/layout/graph.d.ts.map +1 -0
- package/dist/layout/graph.js +57 -0
- package/dist/layout/graph.js.map +1 -0
- package/dist/layout/index.d.ts +8 -0
- package/dist/layout/index.d.ts.map +1 -0
- package/dist/layout/index.js +21 -0
- package/dist/layout/index.js.map +1 -0
- package/dist/layout/lanes.d.ts +8 -0
- package/dist/layout/lanes.d.ts.map +1 -0
- package/dist/layout/lanes.js +78 -0
- package/dist/layout/lanes.js.map +1 -0
- package/dist/layout/measure.d.ts +4 -0
- package/dist/layout/measure.d.ts.map +1 -0
- package/dist/layout/measure.js +24 -0
- package/dist/layout/measure.js.map +1 -0
- package/dist/layout/resolve.d.ts +4 -0
- package/dist/layout/resolve.d.ts.map +1 -0
- package/dist/layout/resolve.js +114 -0
- package/dist/layout/resolve.js.map +1 -0
- package/dist/layout/self-route.d.ts +6 -0
- package/dist/layout/self-route.d.ts.map +1 -0
- package/dist/layout/self-route.js +110 -0
- package/dist/layout/self-route.js.map +1 -0
- package/dist/layout/types.d.ts +53 -0
- package/dist/layout/types.d.ts.map +1 -0
- package/dist/layout/types.js +2 -0
- package/dist/layout/types.js.map +1 -0
- package/dist/model/badge-placement.d.ts +10 -0
- package/dist/model/badge-placement.d.ts.map +1 -0
- package/dist/model/badge-placement.js +27 -0
- package/dist/model/badge-placement.js.map +1 -0
- package/dist/model/frame.d.ts +1 -1
- package/dist/model/frame.js +1 -1
- package/dist/model/input.d.ts +20 -0
- package/dist/model/input.d.ts.map +1 -0
- package/dist/model/input.js +15 -0
- package/dist/model/input.js.map +1 -0
- package/dist/model/labels.d.ts +1 -0
- package/dist/model/labels.d.ts.map +1 -1
- package/dist/model/labels.js +2 -0
- package/dist/model/labels.js.map +1 -1
- package/dist/render/concepts.d.ts.map +1 -1
- package/dist/render/concepts.js +6 -5
- package/dist/render/concepts.js.map +1 -1
- package/dist/render/data.d.ts +3 -0
- package/dist/render/data.d.ts.map +1 -0
- package/dist/render/data.js +7 -0
- package/dist/render/data.js.map +1 -0
- package/dist/render/figure.d.ts +10 -0
- package/dist/render/figure.d.ts.map +1 -0
- package/dist/render/figure.js +22 -0
- package/dist/render/figure.js.map +1 -0
- package/dist/render/hydration.d.ts +3 -0
- package/dist/render/hydration.d.ts.map +1 -0
- package/dist/render/hydration.js +13 -0
- package/dist/render/hydration.js.map +1 -0
- package/dist/render/panel.d.ts.map +1 -1
- package/dist/render/panel.js +7 -6
- package/dist/render/panel.js.map +1 -1
- package/dist/render/svg.d.ts.map +1 -1
- package/dist/render/svg.js +5 -4
- package/dist/render/svg.js.map +1 -1
- package/dist/schema/content.d.ts +90 -0
- package/dist/schema/content.d.ts.map +1 -0
- package/dist/schema/content.js +60 -0
- package/dist/schema/content.js.map +1 -0
- package/dist/schema/layout.d.ts +10 -0
- package/dist/schema/layout.d.ts.map +1 -0
- package/dist/schema/layout.js +8 -0
- package/dist/schema/layout.js.map +1 -0
- package/dist/schema/level.d.ts +3 -0
- package/dist/schema/level.d.ts.map +1 -0
- package/dist/schema/level.js +7 -0
- package/dist/schema/level.js.map +1 -0
- package/dist/schema/primitives.d.ts +61 -0
- package/dist/schema/primitives.d.ts.map +1 -0
- package/dist/schema/primitives.js +46 -0
- package/dist/schema/primitives.js.map +1 -0
- package/dist/schema/references.d.ts +6 -0
- package/dist/schema/references.d.ts.map +1 -0
- package/dist/schema/references.js +81 -0
- package/dist/schema/references.js.map +1 -0
- package/dist/schema.d.ts +357 -192
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +51 -119
- package/dist/schema.js.map +1 -1
- package/package.json +53 -9
- package/resolved-map.schema.json +184 -212
- package/source-map.schema.json +606 -0
- package/src/dom/badgeDom.ts +32 -0
- package/src/dom/geometry.ts +24 -2
- package/src/dom/index.ts +5 -0
- package/src/dom/measureLabel.ts +28 -0
- package/src/dom/mount.ts +46 -0
- package/src/dom/player.ts +3 -3
- package/src/element/element.ts +128 -0
- package/src/element/input.ts +60 -0
- package/src/element/layout.ts +18 -0
- package/src/element.ts +11 -0
- package/src/index.ts +10 -5
- package/src/layout/FONT-LICENSE.txt +78 -0
- package/src/layout/badges.ts +71 -0
- package/src/layout/check.ts +81 -0
- package/src/layout/dagre.ts +81 -0
- package/src/layout/elk.ts +113 -0
- package/src/layout/font-metrics.ts +127 -0
- package/src/layout/geometry.ts +72 -0
- package/src/layout/graph.ts +88 -0
- package/src/layout/index.ts +29 -0
- package/src/layout/lanes.ts +114 -0
- package/src/layout/measure.ts +25 -0
- package/src/layout/resolve.ts +155 -0
- package/src/layout/self-route.ts +168 -0
- package/src/layout/types.ts +50 -0
- package/src/model/badge-placement.ts +43 -0
- package/src/model/frame.ts +2 -2
- package/src/model/input.ts +26 -0
- package/src/model/labels.ts +3 -0
- package/src/render/concepts.ts +7 -5
- package/src/render/data.ts +10 -0
- package/src/render/figure.ts +35 -0
- package/src/render/hydration.ts +11 -0
- package/src/render/panel.ts +7 -6
- package/src/render/svg.ts +5 -4
- package/src/schema/content.ts +91 -0
- package/src/schema/layout.ts +10 -0
- package/src/schema/level.ts +6 -0
- package/src/schema/primitives.ts +55 -0
- package/src/schema/references.ts +106 -0
- package/src/schema.ts +73 -134
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import ELK from "elkjs/lib/elk.bundled.js";
|
|
2
|
+
import type {
|
|
3
|
+
ElkNode,
|
|
4
|
+
ElkExtendedEdge,
|
|
5
|
+
ELK as ElkApi,
|
|
6
|
+
} from "elkjs/lib/elk-api.js";
|
|
7
|
+
import type {
|
|
8
|
+
LayoutEngine,
|
|
9
|
+
LayoutGraph,
|
|
10
|
+
LayoutNode,
|
|
11
|
+
LayoutResult,
|
|
12
|
+
LayoutRoute,
|
|
13
|
+
LayoutPoint,
|
|
14
|
+
} from "./types.js";
|
|
15
|
+
import { engineNodes, laneBoxes } from "./lanes.js";
|
|
16
|
+
import { routeSelfEdges } from "./self-route.js";
|
|
17
|
+
const elkOptions = {
|
|
18
|
+
"elk.algorithm": "layered",
|
|
19
|
+
"elk.edgeRouting": "ORTHOGONAL",
|
|
20
|
+
"elk.randomSeed": "1",
|
|
21
|
+
"elk.separateConnectedComponents": "false",
|
|
22
|
+
|
|
23
|
+
"elk.layered.spacing.nodeNodeBetweenLayers": "64",
|
|
24
|
+
"elk.spacing.nodeNode": "32",
|
|
25
|
+
};
|
|
26
|
+
// ELK skips empty label text; a placeholder retains geometry for size-only labels.
|
|
27
|
+
function elkGraph(graph: LayoutGraph, nodes: LayoutNode[]): ElkNode {
|
|
28
|
+
return {
|
|
29
|
+
id: "$root",
|
|
30
|
+
layoutOptions: {
|
|
31
|
+
...elkOptions,
|
|
32
|
+
"elk.direction": graph.direction === "right" ? "RIGHT" : "DOWN",
|
|
33
|
+
"elk.partitioning.activate": String(graph.lanes.length > 0),
|
|
34
|
+
},
|
|
35
|
+
children: nodes.map((n) => ({
|
|
36
|
+
id: `n:${n.id}`,
|
|
37
|
+
width: n.width,
|
|
38
|
+
height: n.height,
|
|
39
|
+
layoutOptions: {
|
|
40
|
+
"elk.partitioning.partition": String(
|
|
41
|
+
n.lane === undefined
|
|
42
|
+
? graph.lanes.length
|
|
43
|
+
: graph.lanes.findIndex((l) => l.id === n.lane),
|
|
44
|
+
),
|
|
45
|
+
},
|
|
46
|
+
})),
|
|
47
|
+
edges: graph.edges.map((e) => ({
|
|
48
|
+
id: `e:${e.id}`,
|
|
49
|
+
sources: [`n:${e.from}`],
|
|
50
|
+
targets: [`n:${e.to}`],
|
|
51
|
+
...(e.label
|
|
52
|
+
? {
|
|
53
|
+
labels: [
|
|
54
|
+
{
|
|
55
|
+
id: `$label:${e.id}`,
|
|
56
|
+
text: e.label.text || "label",
|
|
57
|
+
layoutOptions: { "elk.edgeLabels.placement": "CENTER" },
|
|
58
|
+
width: e.label.width,
|
|
59
|
+
height: e.label.height,
|
|
60
|
+
},
|
|
61
|
+
],
|
|
62
|
+
}
|
|
63
|
+
: {}),
|
|
64
|
+
})),
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function route(edge: ElkExtendedEdge): LayoutRoute {
|
|
68
|
+
const section = edge.sections?.[0];
|
|
69
|
+
if (!section || edge.sections!.length !== 1)
|
|
70
|
+
throw new Error(`ELK edge “${edge.id}”: expected one connected route`);
|
|
71
|
+
const points: LayoutPoint[] = [
|
|
72
|
+
section.startPoint,
|
|
73
|
+
...(section.bendPoints ?? []),
|
|
74
|
+
section.endPoint,
|
|
75
|
+
].map((p) => [p.x, p.y]);
|
|
76
|
+
const label = edge.labels?.[0];
|
|
77
|
+
return {
|
|
78
|
+
points,
|
|
79
|
+
...(label
|
|
80
|
+
? {
|
|
81
|
+
label: [
|
|
82
|
+
(label.x ?? NaN) + (label.width ?? 0) / 2,
|
|
83
|
+
(label.y ?? NaN) + (label.height ?? 0) / 2,
|
|
84
|
+
] as LayoutPoint,
|
|
85
|
+
}
|
|
86
|
+
: {}),
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
/** Native ELK layered partitions and orthogonal routing; no default engine chosen. */
|
|
90
|
+
export const elkEngine: LayoutEngine = {
|
|
91
|
+
async layout(graph) {
|
|
92
|
+
const nodes = engineNodes(graph),
|
|
93
|
+
elk = new (ELK as unknown as { new (): ElkApi })();
|
|
94
|
+
// Bundled ELK uses an in-process worker; there is no worker to terminate.
|
|
95
|
+
{
|
|
96
|
+
const output = await elk.layout(elkGraph(graph, nodes));
|
|
97
|
+
const result: LayoutResult = { nodes: {}, edges: {}, lanes: {} };
|
|
98
|
+
for (const n of output.children ?? [])
|
|
99
|
+
result.nodes[n.id.slice(2)] = [
|
|
100
|
+
n.x ?? NaN,
|
|
101
|
+
n.y ?? NaN,
|
|
102
|
+
n.width ?? NaN,
|
|
103
|
+
n.height ?? NaN,
|
|
104
|
+
];
|
|
105
|
+
for (const e of output.edges ?? [])
|
|
106
|
+
result.edges[e.id.slice(2)] = route(e);
|
|
107
|
+
result.lanes = laneBoxes(graph, nodes, result.nodes);
|
|
108
|
+
for (const n of nodes)
|
|
109
|
+
if (n.id.startsWith("$")) delete result.nodes[n.id];
|
|
110
|
+
return routeSelfEdges(graph, result);
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
};
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
// Generated by scripts/font-metrics.py; DejaVu Sans, 1000 units, no kerning.
|
|
2
|
+
// See FONT-LICENSE.txt. Unlisted code points use the one-em fallback.
|
|
3
|
+
export const sansRanges: readonly (readonly [number, readonly number[]])[] = [
|
|
4
|
+
[
|
|
5
|
+
0x20,
|
|
6
|
+
[
|
|
7
|
+
317.875, 400.875, 459.969, 837.891, 636.234, 950.203, 779.781, 274.906,
|
|
8
|
+
390.141, 390.141, 500.0, 837.891, 317.875, 360.844, 317.875, 336.922,
|
|
9
|
+
636.234, 636.234, 636.234, 636.234, 636.234, 636.234, 636.234, 636.234,
|
|
10
|
+
636.234, 636.234, 336.922, 336.922, 837.891, 837.891, 837.891, 530.766,
|
|
11
|
+
1000.0, 684.078, 686.031, 698.25, 770.016, 631.844, 575.203, 774.906,
|
|
12
|
+
751.953, 294.922, 294.922, 655.766, 557.125, 862.797, 748.047, 787.109,
|
|
13
|
+
603.031, 787.109, 694.828, 634.766, 610.844, 731.938, 684.078, 988.766,
|
|
14
|
+
685.062, 610.844, 685.062, 390.141, 336.922, 390.141, 837.891, 500.0,
|
|
15
|
+
500.0, 612.797, 634.766, 549.812, 634.766, 615.234, 352.047, 634.766,
|
|
16
|
+
633.797, 277.828, 277.828, 579.109, 277.828, 974.125, 633.797, 611.812,
|
|
17
|
+
634.766, 634.766, 411.141, 521.0, 392.094, 633.797, 591.797, 817.875,
|
|
18
|
+
591.797, 591.797, 524.906, 636.234, 336.922, 636.234, 837.891,
|
|
19
|
+
],
|
|
20
|
+
],
|
|
21
|
+
[
|
|
22
|
+
0xa0,
|
|
23
|
+
[
|
|
24
|
+
317.875, 400.875, 636.234, 636.234, 636.234, 636.234, 336.922, 500.0,
|
|
25
|
+
500.0, 1000.0, 471.188, 611.812, 837.891, 0.0, 1000.0, 500.0, 500.0,
|
|
26
|
+
837.891, 400.875, 400.875, 500.0, 636.234, 636.234, 317.875, 500.0,
|
|
27
|
+
400.875, 471.188, 611.812, 969.234, 969.234, 969.234, 530.766, 684.078,
|
|
28
|
+
684.078, 684.078, 684.078, 684.078, 684.078, 974.125, 698.25, 631.844,
|
|
29
|
+
631.844, 631.844, 631.844, 294.922, 294.922, 294.922, 294.922, 774.906,
|
|
30
|
+
748.047, 787.109, 787.109, 787.109, 787.109, 787.109, 837.891, 787.109,
|
|
31
|
+
731.938, 731.938, 731.938, 731.938, 610.844, 604.984, 629.891, 612.797,
|
|
32
|
+
612.797, 612.797, 612.797, 612.797, 612.797, 981.938, 549.812, 615.234,
|
|
33
|
+
615.234, 615.234, 615.234, 277.828, 277.828, 277.828, 277.828, 611.812,
|
|
34
|
+
633.797, 611.812, 611.812, 611.812, 611.812, 611.812, 837.891, 611.812,
|
|
35
|
+
633.797, 633.797, 633.797, 633.797, 591.797, 634.766, 591.797, 684.078,
|
|
36
|
+
612.797, 684.078, 612.797, 684.078, 612.797, 698.25, 549.812, 698.25,
|
|
37
|
+
549.812, 698.25, 549.812, 698.25, 549.812, 770.016, 634.766, 774.906,
|
|
38
|
+
634.766, 631.844, 615.234, 631.844, 615.234, 631.844, 615.234, 631.844,
|
|
39
|
+
615.234, 631.844, 615.234, 774.906, 634.766, 774.906, 634.766, 774.906,
|
|
40
|
+
634.766, 774.906, 634.766, 751.953, 633.797, 916.016, 694.828, 294.922,
|
|
41
|
+
277.828, 294.922, 277.828, 294.922, 277.828, 294.922, 277.828, 294.922,
|
|
42
|
+
277.828, 589.844, 555.672, 294.922, 277.828, 655.766, 579.109, 579.109,
|
|
43
|
+
557.125, 277.828, 557.125, 277.828, 557.125, 375.0, 557.125, 341.797,
|
|
44
|
+
562.016, 284.188, 748.047, 633.797, 748.047, 633.797, 748.047, 633.797,
|
|
45
|
+
813.484, 748.047, 633.797, 787.109, 611.812, 787.109, 611.812, 787.109,
|
|
46
|
+
611.812, 1069.828, 1022.953, 694.828, 411.141, 694.828, 411.141, 694.828,
|
|
47
|
+
411.141, 634.766, 521.0, 634.766, 521.0, 634.766, 521.0, 634.766, 521.0,
|
|
48
|
+
610.844, 392.094, 610.844, 392.094, 610.844, 392.094, 731.938, 633.797,
|
|
49
|
+
731.938, 633.797, 731.938, 633.797, 731.938, 633.797, 731.938, 633.797,
|
|
50
|
+
731.938, 633.797, 988.766, 817.875, 610.844, 591.797, 610.844, 685.062,
|
|
51
|
+
524.906, 685.062, 524.906, 685.062, 524.906, 352.047,
|
|
52
|
+
],
|
|
53
|
+
],
|
|
54
|
+
[
|
|
55
|
+
0x370,
|
|
56
|
+
[
|
|
57
|
+
654.297, 567.875, 861.812, 647.469, 278.328, 278.328, 748.047, 649.906,
|
|
58
|
+
600.094, 600.094, 500.0, 549.312, 549.812, 549.312, 336.922, 294.922,
|
|
59
|
+
600.094, 600.094, 600.094, 600.094, 500.0, 500.0, 692.391, 317.875,
|
|
60
|
+
746.094, 871.094, 408.203, 600.094, 812.5, 600.094, 824.703, 825.688,
|
|
61
|
+
338.375, 684.078, 686.031, 557.125, 684.078, 631.844, 685.062, 751.953,
|
|
62
|
+
787.109, 294.922, 655.766, 684.078, 862.797, 748.047, 631.844, 787.109,
|
|
63
|
+
751.953, 603.031, 600.094, 631.844, 610.844, 610.844, 787.109, 685.062,
|
|
64
|
+
787.109, 764.156, 294.922, 610.844, 659.188, 540.531, 633.797, 338.375,
|
|
65
|
+
578.609, 659.188, 638.188, 591.797, 611.812, 540.531, 543.953, 633.797,
|
|
66
|
+
611.812, 338.375, 589.359, 591.797, 636.234, 558.594, 557.625, 611.812,
|
|
67
|
+
602.047, 634.766, 586.922, 633.797, 602.047, 578.609, 659.672, 577.641,
|
|
68
|
+
659.672, 837.406, 338.375, 578.609, 611.812, 578.609, 837.406, 655.766,
|
|
69
|
+
614.266, 619.141, 698.734, 842.281, 698.734, 659.672, 837.406, 663.578,
|
|
70
|
+
787.109, 611.812, 648.438, 586.922, 575.203, 458.5, 659.672, 659.672,
|
|
71
|
+
865.234, 627.438, 933.594, 837.406, 758.297, 659.188, 791.5, 614.75,
|
|
72
|
+
686.531, 606.938, 767.578, 625.0, 699.219, 611.812, 610.844, 536.141,
|
|
73
|
+
663.578, 634.766, 549.812, 277.828, 787.109, 615.234, 615.234, 604.984,
|
|
74
|
+
634.766, 698.25, 862.797, 650.875, 634.766, 703.125, 698.25, 703.125,
|
|
75
|
+
631.844, 631.844, 786.141, 609.859, 698.25, 634.766, 294.922, 294.922,
|
|
76
|
+
294.922, 1093.75, 1044.922, 786.141, 709.969, 748.047, 609.375, 751.953,
|
|
77
|
+
684.078, 686.031, 686.031, 609.859, 781.25, 631.844, 1077.156, 641.109,
|
|
78
|
+
748.047, 748.047, 709.969, 751.953, 862.797, 751.953, 787.109, 751.953,
|
|
79
|
+
603.031, 698.25, 610.844, 609.375, 860.844, 685.062, 776.375, 685.547,
|
|
80
|
+
1069.344, 1093.75, 832.516, 882.328, 686.031, 698.25, 1079.594, 694.828,
|
|
81
|
+
612.797, 616.703, 589.359, 525.391, 691.406, 615.234, 900.875, 531.734,
|
|
82
|
+
649.906, 649.906, 604.0, 639.156, 754.391, 653.812, 611.812, 653.812,
|
|
83
|
+
634.766, 549.812, 582.516, 591.797, 854.984, 591.797, 680.672, 590.828,
|
|
84
|
+
915.047, 941.891, 706.547, 789.547, 589.359, 548.828, 841.797, 601.562,
|
|
85
|
+
615.234, 615.234, 625.0, 525.391, 548.828, 521.0, 277.828, 277.828,
|
|
86
|
+
277.828, 902.344, 898.438, 651.859, 604.0, 649.906, 591.797, 653.812,
|
|
87
|
+
933.594, 837.406, 770.516, 671.875, 942.391, 749.031, 879.391, 783.203,
|
|
88
|
+
1159.672, 1001.469, 787.109, 611.812, 1026.859, 824.219, 636.234, 540.531,
|
|
89
|
+
856.453, 876.469, 787.109, 611.812, 781.25, 665.047, 781.25, 665.047,
|
|
90
|
+
992.188, 904.297, 953.125, 758.297, 1179.688, 1027.828, 933.594, 837.406,
|
|
91
|
+
698.25, 549.812, 502.438, 872.562, 872.562, 872.562, 872.562, 872.562,
|
|
92
|
+
1290.531, 1290.531, 772.469, 676.766, 686.031, 589.359, 603.031, 634.766,
|
|
93
|
+
609.859, 525.391, 674.812, 590.328, 624.031, 529.781, 1077.156, 900.875,
|
|
94
|
+
641.109, 531.734, 709.969, 604.0, 709.969, 604.0, 709.969, 604.0, 856.453,
|
|
95
|
+
831.547, 751.953, 660.641, 1014.156, 876.953, 1081.062, 915.531, 877.938,
|
|
96
|
+
692.875, 698.25, 549.812, 610.844, 582.516, 610.844, 591.797, 610.844,
|
|
97
|
+
591.797, 685.062, 591.797, 934.078, 806.641, 685.547, 590.828, 685.547,
|
|
98
|
+
590.828, 685.547, 633.797, 940.922, 728.031, 940.922, 728.031, 294.922,
|
|
99
|
+
1077.156, 900.875, 655.766, 604.0, 775.875, 670.406, 751.953, 660.641,
|
|
100
|
+
776.375, 680.672, 685.547, 590.828, 887.703, 774.422, 277.828, 684.078,
|
|
101
|
+
612.797, 684.078, 612.797, 974.125, 981.938, 631.844, 615.234, 787.109,
|
|
102
|
+
615.234, 787.109, 615.234, 1077.156, 900.875, 641.109, 531.734, 666.016,
|
|
103
|
+
577.641, 748.047, 649.906, 748.047, 649.906, 787.109, 611.812, 787.109,
|
|
104
|
+
611.812, 787.109, 611.812, 698.25, 548.828, 609.375, 591.797, 609.375,
|
|
105
|
+
591.797, 609.375, 591.797, 685.547, 590.828, 609.859, 525.391, 882.328,
|
|
106
|
+
789.547, 674.812, 590.328, 685.062, 591.797, 685.062, 591.797,
|
|
107
|
+
],
|
|
108
|
+
],
|
|
109
|
+
[
|
|
110
|
+
0x2000,
|
|
111
|
+
[
|
|
112
|
+
500.0, 1000.0, 500.0, 1000.0, 329.594, 250.0, 167.0, 636.234, 317.875,
|
|
113
|
+
199.703, 99.609, 0.0, 0.0, 0.0, 0.0, 0.0, 360.844, 360.844, 636.234,
|
|
114
|
+
500.0, 1000.0, 1000.0, 500.0, 500.0, 317.875, 317.875, 317.875, 317.875,
|
|
115
|
+
518.062, 518.062, 518.062, 518.062, 500.0, 500.0, 589.844, 589.844,
|
|
116
|
+
334.469, 667.484, 1000.0, 317.875, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
|
|
117
|
+
199.703, 1341.797, 1735.359, 227.047, 373.531, 520.016, 227.047, 373.531,
|
|
118
|
+
520.016, 338.875, 399.906, 399.906, 837.891, 485.359, 530.766, 500.0,
|
|
119
|
+
803.719, 803.719, 250.0, 1000.0, 500.0, 167.0, 390.141, 390.141, 921.875,
|
|
120
|
+
732.906, 732.906, 497.078, 636.234, 500.0, 500.0, 500.0, 336.922, 803.719,
|
|
121
|
+
500.0, 449.703, 1000.0, 803.719, 837.891, 585.938, 663.094, 837.891,
|
|
122
|
+
837.891, 317.875, 797.359, 837.891, 317.875, 317.875, 222.172, 0.0, 0.0,
|
|
123
|
+
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
|
|
124
|
+
],
|
|
125
|
+
],
|
|
126
|
+
];
|
|
127
|
+
export const monoAdvance = 0.602;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { LayoutBox, LayoutPoint } from "./types.js";
|
|
2
|
+
export function bounds(boxes: LayoutBox[]): LayoutBox {
|
|
3
|
+
if (!boxes.length) return [0, 0, 60, 36];
|
|
4
|
+
const x = Math.min(...boxes.map((b) => b[0])),
|
|
5
|
+
y = Math.min(...boxes.map((b) => b[1]));
|
|
6
|
+
return [
|
|
7
|
+
x,
|
|
8
|
+
y,
|
|
9
|
+
Math.max(...boxes.map((b) => b[0] + b[2])) - x,
|
|
10
|
+
Math.max(...boxes.map((b) => b[1] + b[3])) - y,
|
|
11
|
+
];
|
|
12
|
+
}
|
|
13
|
+
export function midpoint(points: LayoutPoint[]): LayoutPoint {
|
|
14
|
+
const lengths = points
|
|
15
|
+
.slice(1)
|
|
16
|
+
.map((p, i) => Math.hypot(p[0] - points[i][0], p[1] - points[i][1]));
|
|
17
|
+
let distance = lengths.reduce((a, b) => a + b, 0) / 2;
|
|
18
|
+
for (let i = 0; i < lengths.length; i++) {
|
|
19
|
+
if (distance <= lengths[i] && lengths[i] > 0) {
|
|
20
|
+
const fraction = distance / lengths[i],
|
|
21
|
+
a = points[i],
|
|
22
|
+
b = points[i + 1];
|
|
23
|
+
return [a[0] + (b[0] - a[0]) * fraction, a[1] + (b[1] - a[1]) * fraction];
|
|
24
|
+
}
|
|
25
|
+
distance -= lengths[i];
|
|
26
|
+
}
|
|
27
|
+
return [...points[0]];
|
|
28
|
+
}
|
|
29
|
+
export function crossLaneRoute(
|
|
30
|
+
from: LayoutBox,
|
|
31
|
+
to: LayoutBox,
|
|
32
|
+
right = false,
|
|
33
|
+
): LayoutPoint[] {
|
|
34
|
+
if (right) {
|
|
35
|
+
const swap = ([x, y, w, h]: LayoutBox): LayoutBox => [y, x, h, w];
|
|
36
|
+
return crossLaneRoute(swap(from), swap(to)).map(([x, y]) => [y, x]);
|
|
37
|
+
}
|
|
38
|
+
const downward = from[1] < to[1];
|
|
39
|
+
const a: LayoutPoint = [
|
|
40
|
+
from[0] + from[2] / 2,
|
|
41
|
+
from[1] + (downward ? from[3] : 0),
|
|
42
|
+
];
|
|
43
|
+
const b: LayoutPoint = [to[0] + to[2] / 2, to[1] + (downward ? 0 : to[3])];
|
|
44
|
+
const y = (a[1] + b[1]) / 2;
|
|
45
|
+
return [a, [a[0], y], [b[0], y], b];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Place a label beside the longest segment of a rerouted partition edge. */
|
|
49
|
+
export function besideRoute(
|
|
50
|
+
points: LayoutPoint[],
|
|
51
|
+
width: number,
|
|
52
|
+
height: number,
|
|
53
|
+
): LayoutPoint {
|
|
54
|
+
let a = points[0],
|
|
55
|
+
b = points[1],
|
|
56
|
+
longest = -1;
|
|
57
|
+
for (let i = 1; i < points.length; i++) {
|
|
58
|
+
const length = Math.hypot(
|
|
59
|
+
points[i][0] - points[i - 1][0],
|
|
60
|
+
points[i][1] - points[i - 1][1],
|
|
61
|
+
);
|
|
62
|
+
if (length > longest) {
|
|
63
|
+
a = points[i - 1];
|
|
64
|
+
b = points[i];
|
|
65
|
+
longest = length;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
const nx = longest > 0 ? -(b[1] - a[1]) / longest : 1;
|
|
69
|
+
const ny = longest > 0 ? (b[0] - a[0]) / longest : 0;
|
|
70
|
+
const offset = (Math.abs(nx) * width) / 2 + (Math.abs(ny) * height) / 2 + 12;
|
|
71
|
+
return [(a[0] + b[0]) / 2 + nx * offset, (a[1] + b[1]) / 2 + ny * offset];
|
|
72
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import type { SourceMap } from "../schema.js";
|
|
2
|
+
import type {
|
|
3
|
+
LabelMeasurer,
|
|
4
|
+
LabelSize,
|
|
5
|
+
LabelStyle,
|
|
6
|
+
LayoutGraph,
|
|
7
|
+
LayoutNode,
|
|
8
|
+
} from "./types.js";
|
|
9
|
+
/** Reject unusable host measurements at the same boundary as engine geometry. */
|
|
10
|
+
export function measured(
|
|
11
|
+
measure: LabelMeasurer,
|
|
12
|
+
text: string,
|
|
13
|
+
style: LabelStyle,
|
|
14
|
+
): LabelSize {
|
|
15
|
+
const size = measure(text, style);
|
|
16
|
+
if (
|
|
17
|
+
!Number.isFinite(size.width) ||
|
|
18
|
+
size.width < 0 ||
|
|
19
|
+
!Number.isFinite(size.height) ||
|
|
20
|
+
size.height <= 0
|
|
21
|
+
)
|
|
22
|
+
throw new Error(`Invalid label measurement for “${text}”`);
|
|
23
|
+
return size;
|
|
24
|
+
}
|
|
25
|
+
function nodeSize(
|
|
26
|
+
map: SourceMap,
|
|
27
|
+
id: string,
|
|
28
|
+
measure: LabelMeasurer,
|
|
29
|
+
): LayoutNode {
|
|
30
|
+
const n = map.nodes[id];
|
|
31
|
+
const labels = [
|
|
32
|
+
n.label,
|
|
33
|
+
...map.scenarios.flatMap((s) =>
|
|
34
|
+
s.nodeLabels?.[id] === undefined ? [] : [s.nodeLabels[id]],
|
|
35
|
+
),
|
|
36
|
+
];
|
|
37
|
+
const sizes = labels.map((text) =>
|
|
38
|
+
measured(measure, text, { fontSize: 12.5, mono: !!n.mono }),
|
|
39
|
+
);
|
|
40
|
+
const tag = measured(measure, n.tag ?? "", {
|
|
41
|
+
fontSize: 10.5,
|
|
42
|
+
mono: true,
|
|
43
|
+
letterSpacing: 0.525,
|
|
44
|
+
});
|
|
45
|
+
return {
|
|
46
|
+
id,
|
|
47
|
+
...(n.lane ? { lane: n.lane } : {}),
|
|
48
|
+
width: Math.ceil(
|
|
49
|
+
Math.max(60, ...sizes.map((s) => s.width + 24), tag.width + 24),
|
|
50
|
+
),
|
|
51
|
+
height: Math.ceil(
|
|
52
|
+
Math.max(
|
|
53
|
+
n.tag ? 50 : 36,
|
|
54
|
+
...sizes.map((s) => s.height + (n.tag ? tag.height + 22 : 20)),
|
|
55
|
+
),
|
|
56
|
+
),
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
export function layoutGraph(
|
|
60
|
+
map: SourceMap,
|
|
61
|
+
measure: LabelMeasurer,
|
|
62
|
+
): LayoutGraph {
|
|
63
|
+
return {
|
|
64
|
+
direction: map.direction ?? "down",
|
|
65
|
+
nodes: Object.keys(map.nodes).map((id) => nodeSize(map, id, measure)),
|
|
66
|
+
edges: Object.entries(map.edges).map(([id, e]) => ({
|
|
67
|
+
id,
|
|
68
|
+
from: e.from,
|
|
69
|
+
to: e.to,
|
|
70
|
+
...(e.label === undefined
|
|
71
|
+
? {}
|
|
72
|
+
: {
|
|
73
|
+
label: {
|
|
74
|
+
...measured(measure, e.label, { fontSize: 10.5, mono: true }),
|
|
75
|
+
text: e.label,
|
|
76
|
+
},
|
|
77
|
+
}),
|
|
78
|
+
})),
|
|
79
|
+
lanes: Object.entries(map.lanes).map(([id, l]) => ({
|
|
80
|
+
id,
|
|
81
|
+
label: measured(measure, l.label, {
|
|
82
|
+
fontSize: 10.5,
|
|
83
|
+
mono: true,
|
|
84
|
+
letterSpacing: 0.63,
|
|
85
|
+
}),
|
|
86
|
+
})),
|
|
87
|
+
};
|
|
88
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { ResolvedMap } from "../schema.js";
|
|
2
|
+
import { validateReferences } from "../schema/references.js";
|
|
3
|
+
import { parseMap, checkedResult } from "./check.js";
|
|
4
|
+
import { measureLabel } from "./measure.js";
|
|
5
|
+
import { layoutGraph } from "./graph.js";
|
|
6
|
+
import { resolveGeometry } from "./resolve.js";
|
|
7
|
+
import type { LayoutEngine, LayoutOptions } from "./types.js";
|
|
8
|
+
export type * from "./types.js";
|
|
9
|
+
export { measureLabel } from "./measure.js";
|
|
10
|
+
export { validateReferences } from "../schema/references.js";
|
|
11
|
+
/** Validate first, then measure and lay out; complete hand geometry is retained. */
|
|
12
|
+
export async function layout(
|
|
13
|
+
input: unknown,
|
|
14
|
+
engine: LayoutEngine,
|
|
15
|
+
options: LayoutOptions = {},
|
|
16
|
+
): Promise<ResolvedMap> {
|
|
17
|
+
const map = parseMap(input);
|
|
18
|
+
validateReferences(map);
|
|
19
|
+
if ("viewBox" in map) return map;
|
|
20
|
+
const measure = options.measureLabel ?? measureLabel;
|
|
21
|
+
const graph = layoutGraph(map, measure);
|
|
22
|
+
const result = checkedResult(
|
|
23
|
+
await engine.layout(JSON.parse(JSON.stringify(graph)) as typeof graph),
|
|
24
|
+
graph,
|
|
25
|
+
);
|
|
26
|
+
const resolved = resolveGeometry(map, graph, result, measure);
|
|
27
|
+
validateReferences(resolved);
|
|
28
|
+
return resolved;
|
|
29
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
LayoutGraph,
|
|
3
|
+
LayoutNode,
|
|
4
|
+
LayoutResult,
|
|
5
|
+
LayoutBox,
|
|
6
|
+
} from "./types.js";
|
|
7
|
+
import { bounds, crossLaneRoute, besideRoute } from "./geometry.js";
|
|
8
|
+
/** Empty partitions need an engine vertex to reserve their place. IDs cannot collide. */
|
|
9
|
+
export function engineNodes(graph: LayoutGraph): LayoutNode[] {
|
|
10
|
+
return [
|
|
11
|
+
...graph.nodes,
|
|
12
|
+
...graph.lanes.flatMap((l, i) =>
|
|
13
|
+
graph.direction !== "right" && graph.nodes.some((n) => n.lane === l.id)
|
|
14
|
+
? []
|
|
15
|
+
: [
|
|
16
|
+
{
|
|
17
|
+
id: `$lane${i}`,
|
|
18
|
+
lane: l.id,
|
|
19
|
+
width: Math.max(60, l.label.width + 24),
|
|
20
|
+
height: 36,
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
),
|
|
24
|
+
];
|
|
25
|
+
}
|
|
26
|
+
export function laneBoxes(
|
|
27
|
+
graph: LayoutGraph,
|
|
28
|
+
nodes: LayoutNode[],
|
|
29
|
+
boxes: Record<string, LayoutBox>,
|
|
30
|
+
): Record<string, LayoutBox> {
|
|
31
|
+
if (graph.direction === "right") return rightLaneBoxes(graph, nodes, boxes);
|
|
32
|
+
const width = Math.max(
|
|
33
|
+
60,
|
|
34
|
+
...Object.values(boxes).map((b) => b[0] + b[2] + 12),
|
|
35
|
+
...graph.lanes.map((l) => l.label.width + 32),
|
|
36
|
+
);
|
|
37
|
+
return Object.fromEntries(
|
|
38
|
+
graph.lanes.map((l) => {
|
|
39
|
+
const b = bounds(
|
|
40
|
+
nodes.filter((n) => n.lane === l.id).map((n) => boxes[n.id]),
|
|
41
|
+
);
|
|
42
|
+
return [l.id, [0, b[1] - 24, width, b[3] + 36]];
|
|
43
|
+
}),
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
/** Dagre has no partition constraint: retain intra-lane geometry, stack partitions,
|
|
47
|
+
* then route cross-partition edges between the relocated node boundaries. */
|
|
48
|
+
export function partitionDagre(
|
|
49
|
+
graph: LayoutGraph,
|
|
50
|
+
nodes: LayoutNode[],
|
|
51
|
+
result: LayoutResult,
|
|
52
|
+
): LayoutResult {
|
|
53
|
+
if (!graph.lanes.length) return result;
|
|
54
|
+
const offsets = new Map<string, number>();
|
|
55
|
+
const axis = graph.direction === "right" ? 0 : 1;
|
|
56
|
+
let top = 24;
|
|
57
|
+
for (const lane of [...graph.lanes.map((l) => l.id), undefined]) {
|
|
58
|
+
const group = nodes.filter((n) => n.lane === lane);
|
|
59
|
+
if (!group.length) continue;
|
|
60
|
+
const b = bounds(group.map((n) => result.nodes[n.id]));
|
|
61
|
+
const dy = top - b[axis];
|
|
62
|
+
for (const n of group) {
|
|
63
|
+
result.nodes[n.id][axis] += dy;
|
|
64
|
+
offsets.set(n.id, dy);
|
|
65
|
+
}
|
|
66
|
+
top += b[axis + 2] + 64;
|
|
67
|
+
}
|
|
68
|
+
moveRoutes(graph, result, offsets, axis);
|
|
69
|
+
result.lanes = laneBoxes(graph, nodes, result.nodes);
|
|
70
|
+
for (const n of nodes) if (n.id.startsWith("$")) delete result.nodes[n.id];
|
|
71
|
+
return result;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function rightLaneBoxes(
|
|
75
|
+
graph: LayoutGraph,
|
|
76
|
+
nodes: LayoutNode[],
|
|
77
|
+
boxes: Record<string, LayoutBox>,
|
|
78
|
+
): Record<string, LayoutBox> {
|
|
79
|
+
const all = bounds(Object.values(boxes));
|
|
80
|
+
return Object.fromEntries(
|
|
81
|
+
graph.lanes.map((l) => {
|
|
82
|
+
const b = bounds(
|
|
83
|
+
nodes.filter((n) => n.lane === l.id).map((n) => boxes[n.id]),
|
|
84
|
+
);
|
|
85
|
+
return [l.id, [b[0] - 12, all[1] - 24, b[2] + 24, all[3] + 36]];
|
|
86
|
+
}),
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function moveRoutes(
|
|
91
|
+
graph: LayoutGraph,
|
|
92
|
+
result: LayoutResult,
|
|
93
|
+
offsets: Map<string, number>,
|
|
94
|
+
axis: number,
|
|
95
|
+
): void {
|
|
96
|
+
for (const e of graph.edges) {
|
|
97
|
+
const route = result.edges[e.id],
|
|
98
|
+
dy = offsets.get(e.from)!;
|
|
99
|
+
if (dy === offsets.get(e.to)) {
|
|
100
|
+
route.points.forEach((p) => {
|
|
101
|
+
p[axis] += dy;
|
|
102
|
+
});
|
|
103
|
+
if (route.label) route.label[axis] += dy;
|
|
104
|
+
} else {
|
|
105
|
+
route.points = crossLaneRoute(
|
|
106
|
+
result.nodes[e.from],
|
|
107
|
+
result.nodes[e.to],
|
|
108
|
+
axis === 0,
|
|
109
|
+
);
|
|
110
|
+
if (e.label)
|
|
111
|
+
route.label = besideRoute(route.points, e.label.width, e.label.height);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { sansRanges, monoAdvance } from "./font-metrics.js";
|
|
2
|
+
import type { LabelMeasurer } from "./types.js";
|
|
3
|
+
function sansAdvance(codePoint: number): number {
|
|
4
|
+
for (const [start, widths] of sansRanges) {
|
|
5
|
+
const width = widths[codePoint - start];
|
|
6
|
+
if (width !== undefined) return width / 1000;
|
|
7
|
+
}
|
|
8
|
+
return 1;
|
|
9
|
+
}
|
|
10
|
+
/** Deterministic server fallback. Hosts can inject DOM or their own font metrics. */
|
|
11
|
+
export const measureLabel: LabelMeasurer = (text, style) => {
|
|
12
|
+
const lines = text.split(/\r?\n/);
|
|
13
|
+
const widths = lines.map((line) =>
|
|
14
|
+
[...line].reduce((sum, ch) => {
|
|
15
|
+
const advance = style.mono
|
|
16
|
+
? monoAdvance
|
|
17
|
+
: sansAdvance(ch.codePointAt(0)!);
|
|
18
|
+
return sum + advance * style.fontSize + (style.letterSpacing ?? 0);
|
|
19
|
+
}, 0),
|
|
20
|
+
);
|
|
21
|
+
return {
|
|
22
|
+
width: Math.max(0, ...widths),
|
|
23
|
+
height: Math.max(1, lines.length) * style.fontSize * 1.2,
|
|
24
|
+
};
|
|
25
|
+
};
|