@ac-kit/math-graph 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 +91 -0
- package/LICENSE +28 -0
- package/README.md +92 -2
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/layout/_force-forces.d.ts +103 -0
- package/dist/layout/_force-forces.d.ts.map +1 -0
- package/dist/layout/_force-forces.js +490 -0
- package/dist/layout/_force-forces.js.map +1 -0
- package/dist/layout/_hierarchy-table.d.ts +34 -0
- package/dist/layout/_hierarchy-table.d.ts.map +1 -0
- package/dist/layout/_hierarchy-table.js +131 -0
- package/dist/layout/_hierarchy-table.js.map +1 -0
- package/dist/layout/_index-graph.d.ts +32 -0
- package/dist/layout/_index-graph.d.ts.map +1 -0
- package/dist/layout/_index-graph.js +51 -0
- package/dist/layout/_index-graph.js.map +1 -0
- package/dist/layout/_layer-order.d.ts +96 -0
- package/dist/layout/_layer-order.d.ts.map +1 -0
- package/dist/layout/_layer-order.js +462 -0
- package/dist/layout/_layer-order.js.map +1 -0
- package/dist/layout/_layered-acyclic.d.ts +28 -0
- package/dist/layout/_layered-acyclic.d.ts.map +1 -0
- package/dist/layout/_layered-acyclic.js +179 -0
- package/dist/layout/_layered-acyclic.js.map +1 -0
- package/dist/layout/_layered-position.d.ts +56 -0
- package/dist/layout/_layered-position.d.ts.map +1 -0
- package/dist/layout/_layered-position.js +369 -0
- package/dist/layout/_layered-position.js.map +1 -0
- package/dist/layout/_layered-rank.d.ts +54 -0
- package/dist/layout/_layered-rank.d.ts.map +1 -0
- package/dist/layout/_layered-rank.js +436 -0
- package/dist/layout/_layered-rank.js.map +1 -0
- package/dist/layout/_tree-common.d.ts +38 -0
- package/dist/layout/_tree-common.d.ts.map +1 -0
- package/dist/layout/_tree-common.js +73 -0
- package/dist/layout/_tree-common.js.map +1 -0
- package/dist/layout/_treemap-tiling.d.ts +62 -0
- package/dist/layout/_treemap-tiling.d.ts.map +1 -0
- package/dist/layout/_treemap-tiling.js +187 -0
- package/dist/layout/_treemap-tiling.js.map +1 -0
- package/dist/layout/circular-layout.d.ts +27 -0
- package/dist/layout/circular-layout.d.ts.map +1 -0
- package/dist/layout/circular-layout.js +35 -0
- package/dist/layout/circular-layout.js.map +1 -0
- package/dist/layout/create-force-step.d.ts +112 -0
- package/dist/layout/create-force-step.d.ts.map +1 -0
- package/dist/layout/create-force-step.js +134 -0
- package/dist/layout/create-force-step.js.map +1 -0
- package/dist/layout/dendrogram-layout.d.ts +32 -0
- package/dist/layout/dendrogram-layout.d.ts.map +1 -0
- package/dist/layout/dendrogram-layout.js +110 -0
- package/dist/layout/dendrogram-layout.js.map +1 -0
- package/dist/layout/force-directed-layout.d.ts +42 -0
- package/dist/layout/force-directed-layout.d.ts.map +1 -0
- package/dist/layout/force-directed-layout.js +112 -0
- package/dist/layout/force-directed-layout.js.map +1 -0
- package/dist/layout/layered-layout.d.ts +96 -0
- package/dist/layout/layered-layout.d.ts.map +1 -0
- package/dist/layout/layered-layout.js +120 -0
- package/dist/layout/layered-layout.js.map +1 -0
- package/dist/layout/partition-layout.d.ts +31 -0
- package/dist/layout/partition-layout.d.ts.map +1 -0
- package/dist/layout/partition-layout.js +78 -0
- package/dist/layout/partition-layout.js.map +1 -0
- package/dist/layout/phyllotaxis-layout.d.ts +17 -0
- package/dist/layout/phyllotaxis-layout.d.ts.map +1 -0
- package/dist/layout/phyllotaxis-layout.js +32 -0
- package/dist/layout/phyllotaxis-layout.js.map +1 -0
- package/dist/layout/sankey-layout.d.ts +104 -0
- package/dist/layout/sankey-layout.d.ts.map +1 -0
- package/dist/layout/sankey-layout.js +636 -0
- package/dist/layout/sankey-layout.js.map +1 -0
- package/dist/layout/tidy-tree-layout.d.ts +25 -0
- package/dist/layout/tidy-tree-layout.d.ts.map +1 -0
- package/dist/layout/tidy-tree-layout.js +197 -0
- package/dist/layout/tidy-tree-layout.js.map +1 -0
- package/dist/layout/treemap-layout.d.ts +54 -0
- package/dist/layout/treemap-layout.d.ts.map +1 -0
- package/dist/layout/treemap-layout.js +121 -0
- package/dist/layout/treemap-layout.js.map +1 -0
- package/dist/layout/types.d.ts +90 -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/package.json +66 -3
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { BinaryHeap } from "@ac-kit/data";
|
|
2
|
+
/**
|
|
3
|
+
* Picks the links to reverse so that the rest of the graph is acyclic. Returns
|
|
4
|
+
* one byte per link: 1 where the link is reversed. Self-loops are never
|
|
5
|
+
* reversed (ranking ignores them).
|
|
6
|
+
*
|
|
7
|
+
* - `"depthFirst"`: a depth-first search from the nodes in index order, out links
|
|
8
|
+
* in input order; a link that closes onto a node still on the search stack is
|
|
9
|
+
* reversed (Gansner, Koutsofios, North & Vo 1993, §2.1). The weights are not
|
|
10
|
+
* read.
|
|
11
|
+
* - `"greedy"`: the Eades, Lin & Smyth 1993 heuristic ("A fast and effective
|
|
12
|
+
* heuristic for the feedback arc set problem"): sinks go to the back of a
|
|
13
|
+
* node sequence, sources to the front, otherwise the node with the largest
|
|
14
|
+
* `out-weight − in-weight` goes to the front; links running backward in the
|
|
15
|
+
* sequence are reversed. Ties break by node index.
|
|
16
|
+
*
|
|
17
|
+
* Reversing never changes the set of nodes, so the result is acyclic for both
|
|
18
|
+
* methods.
|
|
19
|
+
*
|
|
20
|
+
* Complexity: depth-first O(V + E) time; greedy O((V + E) log V) time. O(V + E)
|
|
21
|
+
* memory.
|
|
22
|
+
*
|
|
23
|
+
* @param weights Per link, finite ≥ 0 (default 1); read by `"greedy"` only.
|
|
24
|
+
*/
|
|
25
|
+
export function findReversedLinks(graph, method, weights) {
|
|
26
|
+
return method === "greedy"
|
|
27
|
+
? greedyReversedLinks_(graph, weights)
|
|
28
|
+
: depthFirstReversedLinks_(graph);
|
|
29
|
+
}
|
|
30
|
+
function depthFirstReversedLinks_(graph) {
|
|
31
|
+
const { nodeCount, targets, outOffsets, outLinks } = graph;
|
|
32
|
+
const reversed = new Uint8Array(graph.linkCount);
|
|
33
|
+
// 0 unvisited, 1 on the search stack, 2 finished.
|
|
34
|
+
const state = new Uint8Array(nodeCount);
|
|
35
|
+
const cursors = new Uint32Array(nodeCount);
|
|
36
|
+
const stack = new Uint32Array(nodeCount);
|
|
37
|
+
for (let root = 0; root < nodeCount; root++) {
|
|
38
|
+
if (state[root] !== 0) {
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
let depth = 0;
|
|
42
|
+
stack[depth++] = root;
|
|
43
|
+
state[root] = 1;
|
|
44
|
+
cursors[root] = outOffsets[root];
|
|
45
|
+
while (depth > 0) {
|
|
46
|
+
const node = stack[depth - 1];
|
|
47
|
+
if (cursors[node] === outOffsets[node + 1]) {
|
|
48
|
+
state[node] = 2;
|
|
49
|
+
depth--;
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
const link = outLinks[cursors[node]++];
|
|
53
|
+
const target = targets[link];
|
|
54
|
+
if (target === node) {
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
if (state[target] === 1) {
|
|
58
|
+
reversed[link] = 1;
|
|
59
|
+
}
|
|
60
|
+
else if (state[target] === 0) {
|
|
61
|
+
state[target] = 1;
|
|
62
|
+
cursors[target] = outOffsets[target];
|
|
63
|
+
stack[depth++] = target;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return reversed;
|
|
68
|
+
}
|
|
69
|
+
function greedyReversedLinks_(graph, weights) {
|
|
70
|
+
const { nodeCount, linkCount, sources, targets, outOffsets, outLinks, inOffsets, inLinks, } = graph;
|
|
71
|
+
const weightOf = (link) => weights?.[link] ?? 1;
|
|
72
|
+
const outCounts = new Uint32Array(nodeCount);
|
|
73
|
+
const inCounts = new Uint32Array(nodeCount);
|
|
74
|
+
// Remaining out-weight minus remaining in-weight.
|
|
75
|
+
const balances = new Float64Array(nodeCount);
|
|
76
|
+
for (let link = 0; link < linkCount; link++) {
|
|
77
|
+
const source = sources[link];
|
|
78
|
+
const target = targets[link];
|
|
79
|
+
if (source !== target) {
|
|
80
|
+
outCounts[source]++;
|
|
81
|
+
inCounts[target]++;
|
|
82
|
+
balances[source] += weightOf(link);
|
|
83
|
+
balances[target] -= weightOf(link);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
const removed = new Uint8Array(nodeCount);
|
|
87
|
+
// Bumped on each balance change, to ignore outdated heap entries.
|
|
88
|
+
const stamps = new Uint32Array(nodeCount);
|
|
89
|
+
const heap = new BinaryHeap((a, b) => a.balance > b.balance || (a.balance === b.balance && a.node < b.node));
|
|
90
|
+
const sinks = [];
|
|
91
|
+
const sourceNodes = [];
|
|
92
|
+
for (let node = 0; node < nodeCount; node++) {
|
|
93
|
+
if (outCounts[node] === 0) {
|
|
94
|
+
sinks.push(node);
|
|
95
|
+
}
|
|
96
|
+
else if (inCounts[node] === 0) {
|
|
97
|
+
sourceNodes.push(node);
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
heap.insert({ node, balance: balances[node], stamp: 0 });
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
const position = new Uint32Array(nodeCount);
|
|
104
|
+
let front = 0;
|
|
105
|
+
let back = nodeCount;
|
|
106
|
+
const touch = (node) => {
|
|
107
|
+
stamps[node]++;
|
|
108
|
+
if (outCounts[node] === 0) {
|
|
109
|
+
sinks.push(node);
|
|
110
|
+
}
|
|
111
|
+
else if (inCounts[node] === 0) {
|
|
112
|
+
sourceNodes.push(node);
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
heap.insert({
|
|
116
|
+
node,
|
|
117
|
+
balance: balances[node],
|
|
118
|
+
stamp: stamps[node],
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
const removeNode = (node) => {
|
|
123
|
+
removed[node] = 1;
|
|
124
|
+
for (let at = outOffsets[node]; at < outOffsets[node + 1]; at++) {
|
|
125
|
+
const link = outLinks[at];
|
|
126
|
+
const target = targets[link];
|
|
127
|
+
if (target !== node && removed[target] === 0) {
|
|
128
|
+
inCounts[target]--;
|
|
129
|
+
balances[target] += weightOf(link);
|
|
130
|
+
touch(target);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
for (let at = inOffsets[node]; at < inOffsets[node + 1]; at++) {
|
|
134
|
+
const link = inLinks[at];
|
|
135
|
+
const source = sources[link];
|
|
136
|
+
if (source !== node && removed[source] === 0) {
|
|
137
|
+
outCounts[source]--;
|
|
138
|
+
balances[source] -= weightOf(link);
|
|
139
|
+
touch(source);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
for (let left = nodeCount; left > 0;) {
|
|
144
|
+
let node;
|
|
145
|
+
let atBack = false;
|
|
146
|
+
if (sinks.length > 0) {
|
|
147
|
+
node = sinks.pop();
|
|
148
|
+
atBack = true;
|
|
149
|
+
}
|
|
150
|
+
else if (sourceNodes.length > 0) {
|
|
151
|
+
node = sourceNodes.pop();
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
const entry = heap.extract();
|
|
155
|
+
if (entry === undefined) {
|
|
156
|
+
break;
|
|
157
|
+
}
|
|
158
|
+
if (removed[entry.node] === 0 && entry.stamp === stamps[entry.node]) {
|
|
159
|
+
node = entry.node;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
if (node === undefined || removed[node] === 1) {
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
position[node] = atBack ? --back : front++;
|
|
166
|
+
removeNode(node);
|
|
167
|
+
left--;
|
|
168
|
+
}
|
|
169
|
+
const reversed = new Uint8Array(linkCount);
|
|
170
|
+
for (let link = 0; link < linkCount; link++) {
|
|
171
|
+
const source = sources[link];
|
|
172
|
+
const target = targets[link];
|
|
173
|
+
if (source !== target && position[target] < position[source]) {
|
|
174
|
+
reversed[link] = 1;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return reversed;
|
|
178
|
+
}
|
|
179
|
+
//# sourceMappingURL=_layered-acyclic.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_layered-acyclic.js","sourceRoot":"","sources":["../../src/layout/_layered-acyclic.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAO1C;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,UAAU,iBAAiB,CAChC,KAAiB,EACjB,MAA0B,EAC1B,OAA2B;IAE3B,OAAO,MAAM,KAAK,QAAQ;QACzB,CAAC,CAAC,oBAAoB,CAAC,KAAK,EAAE,OAAO,CAAC;QACtC,CAAC,CAAC,wBAAwB,CAAC,KAAK,CAAC,CAAC;AACpC,CAAC;AAED,SAAS,wBAAwB,CAAC,KAAiB;IAClD,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC;IAC3D,MAAM,QAAQ,GAAG,IAAI,UAAU,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;IACjD,kDAAkD;IAClD,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,SAAS,CAAC,CAAC;IACxC,MAAM,OAAO,GAAG,IAAI,WAAW,CAAC,SAAS,CAAC,CAAC;IAC3C,MAAM,KAAK,GAAG,IAAI,WAAW,CAAC,SAAS,CAAC,CAAC;IAEzC,KAAK,IAAI,IAAI,GAAG,CAAC,EAAE,IAAI,GAAG,SAAS,EAAE,IAAI,EAAE,EAAE,CAAC;QAC7C,IAAI,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;YACvB,SAAS;QACV,CAAC;QAED,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,KAAK,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC;QACtB,KAAK,CAAC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,CAAC;IACF,CAAC;IACD,OAAO,QAAQ,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { IndexGraph } from "./_index-graph.js";
|
|
2
|
+
import type { LayerOrder } from "./_layer-order.js";
|
|
3
|
+
/** Rank direction of the drawing. */
|
|
4
|
+
export type LayeredDirection = "down" | "up" | "right" | "left";
|
|
5
|
+
export type LayeredSeparations = {
|
|
6
|
+
/** Gap between two input nodes of a layer. */
|
|
7
|
+
readonly nodeSeparation: number;
|
|
8
|
+
/** Gap between a dummy vertex (a bend of a long link) and its neighbour. */
|
|
9
|
+
readonly edgeSeparation: number;
|
|
10
|
+
/** Gap between two layers, beyond the node sizes. */
|
|
11
|
+
readonly rankSeparation: number;
|
|
12
|
+
};
|
|
13
|
+
export type PlacedLayers = {
|
|
14
|
+
/** Node centres, 2 per node, in the final direction. */
|
|
15
|
+
readonly positions: Float64Array;
|
|
16
|
+
/** Polyline vertices, 2 each. */
|
|
17
|
+
readonly edgePoints: Float64Array;
|
|
18
|
+
/** `linkCount + 1` offsets, in vertices. */
|
|
19
|
+
readonly edgeStarts: Uint32Array;
|
|
20
|
+
readonly width: number;
|
|
21
|
+
readonly height: number;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Horizontal coordinates (the breadth axis) of every vertex of a layered graph,
|
|
25
|
+
* Brandes & Köpf 2001, "Fast and Simple Horizontal Coordinate Assignment": type
|
|
26
|
+
* 1 conflicts are marked, four layouts are built (alignment towards the layer
|
|
27
|
+
* above or below, leaning left or right), aligned to the one of least width,
|
|
28
|
+
* and each vertex takes the mean of its two median coordinates. Vertices of one
|
|
29
|
+
* rank keep their order and are `nodeSeparation` (between input nodes) or
|
|
30
|
+
* `edgeSeparation` (around dummies) apart, half of it on each side, beyond
|
|
31
|
+
* their half sizes. Straight where the paper guarantees it: the segments
|
|
32
|
+
* between dummy vertices.
|
|
33
|
+
*
|
|
34
|
+
* Complexity: O(V′ + E′) time and memory.
|
|
35
|
+
*
|
|
36
|
+
* @param sizes Per vertex, the extent along the breadth axis (0 for dummies).
|
|
37
|
+
*/
|
|
38
|
+
export declare function assignBreadths(order: LayerOrder, nodeCount: number, sizes: Float64Array, separations: Pick<LayeredSeparations, "nodeSeparation" | "edgeSeparation">): Float64Array;
|
|
39
|
+
/**
|
|
40
|
+
* Centre of every layer along the rank axis: layers are as thick as their
|
|
41
|
+
* thickest node, `rankSeparation` apart.
|
|
42
|
+
*/
|
|
43
|
+
export declare function assignDepths(layerSizes: Float64Array, rankSeparation: number): Float64Array;
|
|
44
|
+
/**
|
|
45
|
+
* Coordinates of a layered drawing in the requested direction: breadth by
|
|
46
|
+
* Brandes–Köpf, layer depths, link polylines clipped to the node boxes, then
|
|
47
|
+
* the axis transform of "down" (`up` flips the rank axis, `right` and `left`
|
|
48
|
+
* swap the axes, `left` flipping too), origin at the corner of the box holding
|
|
49
|
+
* every node and bend. Self-loops get no polyline; a reversed link's polyline
|
|
50
|
+
* still runs from its source to its target.
|
|
51
|
+
*
|
|
52
|
+
* @param breadthSizes Per node, the extent along the breadth axis.
|
|
53
|
+
* @param depthSizes Per node, the extent along the rank axis.
|
|
54
|
+
*/
|
|
55
|
+
export declare function placeLayers(graph: IndexGraph, order: LayerOrder, reversed: ArrayLike<number>, breadthSizes: ArrayLike<number>, depthSizes: ArrayLike<number>, direction: LayeredDirection, separations: LayeredSeparations): PlacedLayers;
|
|
56
|
+
//# sourceMappingURL=_layered-position.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_layered-position.d.ts","sourceRoot":"","sources":["../../src/layout/_layered-position.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAEpD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAEpD,qCAAqC;AACrC,MAAM,MAAM,gBAAgB,GAAG,MAAM,GAAG,IAAI,GAAG,OAAO,GAAG,MAAM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bour } from "./_layer-order.js";
|
|
3
|
+
/**
|
|
4
|
+
* Marks the type 1 conflicts of Brandes & Köpf 2001 (Algorithm 1): a segment
|
|
5
|
+
* between two layers that crosses an inner segment (one joining two dummy
|
|
6
|
+
* vertices). Inner segments are never marked, so long links stay straight. O(V′ +
|
|
7
|
+
* E′).
|
|
8
|
+
*/
|
|
9
|
+
function markConflicts_(order, nodeCount, above) {
|
|
10
|
+
const { layerCount, layerStarts, layerVertices, orders, segmentSources } = order;
|
|
11
|
+
const conflicts = new Uint8Array(order.segmentCount);
|
|
12
|
+
for (let layer = 1; layer < layerCount; layer++) {
|
|
13
|
+
const upperSize = layerStarts[layer] - layerStarts[layer - 1];
|
|
14
|
+
const lowerStart = layerStarts[layer];
|
|
15
|
+
const lowerSize = layerStarts[layer + 1] - lowerStart;
|
|
16
|
+
let firstUpper = 0;
|
|
17
|
+
let scanned = 0;
|
|
18
|
+
for (let last = 0; last < lowerSize; last++) {
|
|
19
|
+
const vertex = layerVertices[lowerStart + last];
|
|
20
|
+
let innerUpper = -1;
|
|
21
|
+
if (vertex >= nodeCount) {
|
|
22
|
+
// A dummy has exactly one segment from above.
|
|
23
|
+
const upper = segmentSources[above.indices[above.offsets[vertex]]];
|
|
24
|
+
if (upper >= nodeCount) {
|
|
25
|
+
innerUpper = orders[upper];
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
if (last === lowerSize - 1 || innerUpper >= 0) {
|
|
29
|
+
const lastUpper = innerUpper >= 0 ? innerUpper : upperSize - 1;
|
|
30
|
+
for (; scanned <= last; scanned++) {
|
|
31
|
+
const scannedVertex = layerVertices[lowerStart + scanned];
|
|
32
|
+
for (let slot = above.offsets[scannedVertex]; slot < above.offsets[scannedVertex + 1]; slot++) {
|
|
33
|
+
const segment = above.indices[slot];
|
|
34
|
+
const upper = orders[segmentSources[segment]];
|
|
35
|
+
if (upper < firstUpper || upper > lastUpper) {
|
|
36
|
+
conflicts[segment] = 1;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
firstUpper = lastUpper;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return conflicts;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* One of the four layouts of Brandes & Köpf: vertical alignment (Algorithm 2)
|
|
48
|
+
* towards the median neighbours of the layer above (`downward`) or below, then
|
|
49
|
+
* horizontal compaction. `mirrored` runs the same on the layers read right to
|
|
50
|
+
* left; the coordinates are negated back.
|
|
51
|
+
*
|
|
52
|
+
* Compaction differs from the paper's sink and shift recursion, whose class
|
|
53
|
+
* shifts can leave blocks overlapping (Brandes, Walter & Zink 2020, erratum):
|
|
54
|
+
* every aligned block is placed at the least coordinate that keeps the gap to
|
|
55
|
+
* the block before it in each layer, a longest path over the block graph, which
|
|
56
|
+
* is acyclic for non-crossing alignments.
|
|
57
|
+
*/
|
|
58
|
+
function alignedLayout_(context, downward, mirrored) {
|
|
59
|
+
const { order, nodeCount, sizes, align, root, conflicts } = context;
|
|
60
|
+
const { layerCount, layerStarts, layerVertices, orders, vertexCount } = order;
|
|
61
|
+
const { segmentSources, segmentTargets } = order;
|
|
62
|
+
const neighbours = downward ? context.above : context.below;
|
|
63
|
+
const neighbourOf = downward ? segmentSources : segmentTargets;
|
|
64
|
+
for (let vertex = 0; vertex < vertexCount; vertex++) {
|
|
65
|
+
align[vertex] = vertex;
|
|
66
|
+
root[vertex] = vertex;
|
|
67
|
+
}
|
|
68
|
+
const layerSizeOf = (layer) => layerStarts[layer + 1] - layerStarts[layer];
|
|
69
|
+
const positionOf = (vertex) => mirrored
|
|
70
|
+
? layerSizeOf(order.layerOf[vertex]) - 1 - orders[vertex]
|
|
71
|
+
: orders[vertex];
|
|
72
|
+
const vertexAt = (layer, position) => layerVertices[layerStarts[layer] +
|
|
73
|
+
(mirrored ? layerSizeOf(layer) - 1 - position : position)];
|
|
74
|
+
for (let step = 1; step < layerCount; step++) {
|
|
75
|
+
const layer = downward ? step : layerCount - 1 - step;
|
|
76
|
+
const size = layerSizeOf(layer);
|
|
77
|
+
let previous = -1;
|
|
78
|
+
for (let position = 0; position < size; position++) {
|
|
79
|
+
const vertex = vertexAt(layer, position);
|
|
80
|
+
const first = neighbours.offsets[vertex];
|
|
81
|
+
const degree = neighbours.offsets[vertex + 1] - first;
|
|
82
|
+
if (degree === 0) {
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
const lowMedian = (degree - 1) >> 1;
|
|
86
|
+
const highMedian = degree >> 1;
|
|
87
|
+
for (let median = lowMedian; median <= highMedian; median++) {
|
|
88
|
+
if (align[vertex] !== vertex) {
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
const slot = mirrored ? first + degree - 1 - median : first + median;
|
|
92
|
+
const segment = neighbours.indices[slot];
|
|
93
|
+
const neighbour = neighbourOf[segment];
|
|
94
|
+
const neighbourPosition = positionOf(neighbour);
|
|
95
|
+
if (conflicts[segment] === 0 && previous < neighbourPosition) {
|
|
96
|
+
align[neighbour] = vertex;
|
|
97
|
+
root[vertex] = root[neighbour];
|
|
98
|
+
align[vertex] = root[vertex];
|
|
99
|
+
previous = neighbourPosition;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
// Block graph: an edge from the block of a vertex to the block of its
|
|
105
|
+
// successor in the layer, weighted by the least gap between their centres.
|
|
106
|
+
const edgeFrom = new Uint32Array(vertexCount);
|
|
107
|
+
const edgeTo = new Uint32Array(vertexCount);
|
|
108
|
+
const edgeGap = new Float64Array(vertexCount);
|
|
109
|
+
let edgeCount = 0;
|
|
110
|
+
for (let layer = 0; layer < layerCount; layer++) {
|
|
111
|
+
const size = layerSizeOf(layer);
|
|
112
|
+
for (let position = 1; position < size; position++) {
|
|
113
|
+
const left = vertexAt(layer, position - 1);
|
|
114
|
+
const right = vertexAt(layer, position);
|
|
115
|
+
edgeFrom[edgeCount] = root[left];
|
|
116
|
+
edgeTo[edgeCount] = root[right];
|
|
117
|
+
edgeGap[edgeCount] =
|
|
118
|
+
(sizes[left] + sizes[right]) / 2 +
|
|
119
|
+
((left < nodeCount ? context.nodeSeparation : context.edgeSeparation) +
|
|
120
|
+
(right < nodeCount
|
|
121
|
+
? context.nodeSeparation
|
|
122
|
+
: context.edgeSeparation)) /
|
|
123
|
+
2;
|
|
124
|
+
edgeCount++;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
const successors = groupIndices(edgeFrom.subarray(0, edgeCount), (from) => from, vertexCount);
|
|
128
|
+
const waiting = new Uint32Array(vertexCount);
|
|
129
|
+
for (let edge = 0; edge < edgeCount; edge++) {
|
|
130
|
+
waiting[edgeTo[edge]]++;
|
|
131
|
+
}
|
|
132
|
+
const coordinates = new Float64Array(vertexCount);
|
|
133
|
+
const queue = new Uint32Array(vertexCount);
|
|
134
|
+
let queued = 0;
|
|
135
|
+
let blockCount = 0;
|
|
136
|
+
for (let vertex = 0; vertex < vertexCount; vertex++) {
|
|
137
|
+
if (root[vertex] === vertex) {
|
|
138
|
+
blockCount++;
|
|
139
|
+
if (waiting[vertex] === 0) {
|
|
140
|
+
queue[queued++] = vertex;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
for (let head = 0; head < queued; head++) {
|
|
145
|
+
const block = queue[head];
|
|
146
|
+
for (let slot = successors.offsets[block]; slot < successors.offsets[block + 1]; slot++) {
|
|
147
|
+
const edge = successors.indices[slot];
|
|
148
|
+
const next = edgeTo[edge];
|
|
149
|
+
coordinates[next] = Math.max(coordinates[next], coordinates[block] + edgeGap[edge]);
|
|
150
|
+
if (--waiting[next] === 0) {
|
|
151
|
+
queue[queued++] = next;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
if (queued !== blockCount) {
|
|
156
|
+
throw new Error("layeredLayout: the block graph of an alignment is cyclic");
|
|
157
|
+
}
|
|
158
|
+
const result = new Float64Array(vertexCount);
|
|
159
|
+
for (let vertex = 0; vertex < vertexCount; vertex++) {
|
|
160
|
+
const value = coordinates[root[vertex]];
|
|
161
|
+
result[vertex] = mirrored ? -value : value;
|
|
162
|
+
}
|
|
163
|
+
return result;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Horizontal coordinates (the breadth axis) of every vertex of a layered graph,
|
|
167
|
+
* Brandes & Köpf 2001, "Fast and Simple Horizontal Coordinate Assignment": type
|
|
168
|
+
* 1 conflicts are marked, four layouts are built (alignment towards the layer
|
|
169
|
+
* above or below, leaning left or right), aligned to the one of least width,
|
|
170
|
+
* and each vertex takes the mean of its two median coordinates. Vertices of one
|
|
171
|
+
* rank keep their order and are `nodeSeparation` (between input nodes) or
|
|
172
|
+
* `edgeSeparation` (around dummies) apart, half of it on each side, beyond
|
|
173
|
+
* their half sizes. Straight where the paper guarantees it: the segments
|
|
174
|
+
* between dummy vertices.
|
|
175
|
+
*
|
|
176
|
+
* Complexity: O(V′ + E′) time and memory.
|
|
177
|
+
*
|
|
178
|
+
* @param sizes Per vertex, the extent along the breadth axis (0 for dummies).
|
|
179
|
+
*/
|
|
180
|
+
export function assignBreadths(order, nodeCount, sizes, separations) {
|
|
181
|
+
const { vertexCount, layerCount, layerStarts } = order;
|
|
182
|
+
if (vertexCount === 0) {
|
|
183
|
+
return new Float64Array(0);
|
|
184
|
+
}
|
|
185
|
+
let widestLayer = 1;
|
|
186
|
+
for (let layer = 0; layer < layerCount; layer++) {
|
|
187
|
+
widestLayer = Math.max(widestLayer, layerStarts[layer + 1] - layerStarts[layer]);
|
|
188
|
+
}
|
|
189
|
+
const above = groupByNeighbour(order.vertexCount, order.segmentTargets, order.segmentSources, order.orders, widestLayer);
|
|
190
|
+
const below = groupByNeighbour(order.vertexCount, order.segmentSources, order.segmentTargets, order.orders, widestLayer);
|
|
191
|
+
const context = {
|
|
192
|
+
order,
|
|
193
|
+
nodeCount,
|
|
194
|
+
sizes,
|
|
195
|
+
nodeSeparation: separations.nodeSeparation,
|
|
196
|
+
edgeSeparation: separations.edgeSeparation,
|
|
197
|
+
above,
|
|
198
|
+
below,
|
|
199
|
+
conflicts: markConflicts_(order, nodeCount, above),
|
|
200
|
+
align: new Uint32Array(vertexCount),
|
|
201
|
+
root: new Uint32Array(vertexCount),
|
|
202
|
+
};
|
|
203
|
+
// Up-left, up-right, down-left, down-right.
|
|
204
|
+
const layouts = [
|
|
205
|
+
alignedLayout_(context, false, false),
|
|
206
|
+
alignedLayout_(context, false, true),
|
|
207
|
+
alignedLayout_(context, true, false),
|
|
208
|
+
alignedLayout_(context, true, true),
|
|
209
|
+
];
|
|
210
|
+
const lows = new Float64Array(4);
|
|
211
|
+
const highs = new Float64Array(4);
|
|
212
|
+
let narrowest = 0;
|
|
213
|
+
for (let index = 0; index < 4; index++) {
|
|
214
|
+
let low = Number.POSITIVE_INFINITY;
|
|
215
|
+
let high = Number.NEGATIVE_INFINITY;
|
|
216
|
+
const layout = layouts[index];
|
|
217
|
+
for (let vertex = 0; vertex < vertexCount; vertex++) {
|
|
218
|
+
low = Math.min(low, layout[vertex] - sizes[vertex] / 2);
|
|
219
|
+
high = Math.max(high, layout[vertex] + sizes[vertex] / 2);
|
|
220
|
+
}
|
|
221
|
+
lows[index] = low;
|
|
222
|
+
highs[index] = high;
|
|
223
|
+
if (high - low < highs[narrowest] - lows[narrowest]) {
|
|
224
|
+
narrowest = index;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
for (let index = 0; index < 4; index++) {
|
|
228
|
+
// The left-leaning layouts share the narrowest one's left edge, the
|
|
229
|
+
// right-leaning ones its right edge.
|
|
230
|
+
const shift = index % 2 === 0
|
|
231
|
+
? lows[narrowest] - lows[index]
|
|
232
|
+
: highs[narrowest] - highs[index];
|
|
233
|
+
const layout = layouts[index];
|
|
234
|
+
for (let vertex = 0; vertex < vertexCount; vertex++) {
|
|
235
|
+
layout[vertex] += shift;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
const breadths = new Float64Array(vertexCount);
|
|
239
|
+
for (let vertex = 0; vertex < vertexCount; vertex++) {
|
|
240
|
+
const first = layouts[0][vertex];
|
|
241
|
+
const second = layouts[1][vertex];
|
|
242
|
+
const third = layouts[2][vertex];
|
|
243
|
+
const fourth = layouts[3][vertex];
|
|
244
|
+
const lowest = Math.min(first, second, third, fourth);
|
|
245
|
+
const highest = Math.max(first, second, third, fourth);
|
|
246
|
+
// The two middle values of four: their sum less the extremes.
|
|
247
|
+
breadths[vertex] = (first + second + third + fourth - lowest - highest) / 2;
|
|
248
|
+
}
|
|
249
|
+
return breadths;
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Centre of every layer along the rank axis: layers are as thick as their
|
|
253
|
+
* thickest node, `rankSeparation` apart.
|
|
254
|
+
*/
|
|
255
|
+
export function assignDepths(layerSizes, rankSeparation) {
|
|
256
|
+
const centres = new Float64Array(layerSizes.length);
|
|
257
|
+
let edge = 0;
|
|
258
|
+
for (let layer = 0; layer < layerSizes.length; layer++) {
|
|
259
|
+
const size = layerSizes[layer];
|
|
260
|
+
centres[layer] = edge + size / 2;
|
|
261
|
+
edge += size + rankSeparation;
|
|
262
|
+
}
|
|
263
|
+
return centres;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Where the ray from the centre of a box of `breadth × depth` towards a point
|
|
267
|
+
* (`deltaBreadth`, `deltaDepth` away from the centre) leaves the box, as a
|
|
268
|
+
* fraction of that vector.
|
|
269
|
+
*/
|
|
270
|
+
function exitFraction_(breadth, depth, deltaBreadth, deltaDepth) {
|
|
271
|
+
const alongBreadth = deltaBreadth === 0 ? Infinity : breadth / 2 / Math.abs(deltaBreadth);
|
|
272
|
+
const alongDepth = deltaDepth === 0 ? Infinity : depth / 2 / Math.abs(deltaDepth);
|
|
273
|
+
const fraction = Math.min(alongBreadth, alongDepth);
|
|
274
|
+
return Number.isFinite(fraction) ? Math.min(fraction, 1) : 0;
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Coordinates of a layered drawing in the requested direction: breadth by
|
|
278
|
+
* Brandes–Köpf, layer depths, link polylines clipped to the node boxes, then
|
|
279
|
+
* the axis transform of "down" (`up` flips the rank axis, `right` and `left`
|
|
280
|
+
* swap the axes, `left` flipping too), origin at the corner of the box holding
|
|
281
|
+
* every node and bend. Self-loops get no polyline; a reversed link's polyline
|
|
282
|
+
* still runs from its source to its target.
|
|
283
|
+
*
|
|
284
|
+
* @param breadthSizes Per node, the extent along the breadth axis.
|
|
285
|
+
* @param depthSizes Per node, the extent along the rank axis.
|
|
286
|
+
*/
|
|
287
|
+
export function placeLayers(graph, order, reversed, breadthSizes, depthSizes, direction, separations) {
|
|
288
|
+
const { nodeCount, linkCount, sources, targets } = graph;
|
|
289
|
+
const { vertexCount, layerCount, layerOf, chainStarts } = order;
|
|
290
|
+
const sizes = new Float64Array(vertexCount);
|
|
291
|
+
const layerSizes = new Float64Array(layerCount);
|
|
292
|
+
for (let node = 0; node < nodeCount; node++) {
|
|
293
|
+
sizes[node] = breadthSizes[node];
|
|
294
|
+
const layer = layerOf[node];
|
|
295
|
+
layerSizes[layer] = Math.max(layerSizes[layer], depthSizes[node]);
|
|
296
|
+
}
|
|
297
|
+
const breadths = assignBreadths(order, nodeCount, sizes, separations);
|
|
298
|
+
const depths = assignDepths(layerSizes, separations.rankSeparation);
|
|
299
|
+
let lowest = Number.POSITIVE_INFINITY;
|
|
300
|
+
let highest = Number.NEGATIVE_INFINITY;
|
|
301
|
+
for (let vertex = 0; vertex < vertexCount; vertex++) {
|
|
302
|
+
lowest = Math.min(lowest, breadths[vertex] - sizes[vertex] / 2);
|
|
303
|
+
highest = Math.max(highest, breadths[vertex] + sizes[vertex] / 2);
|
|
304
|
+
}
|
|
305
|
+
let breadthExtent = 0;
|
|
306
|
+
let depthExtent = 0;
|
|
307
|
+
if (vertexCount > 0) {
|
|
308
|
+
for (let vertex = 0; vertex < vertexCount; vertex++) {
|
|
309
|
+
breadths[vertex] -= lowest;
|
|
310
|
+
}
|
|
311
|
+
breadthExtent = highest - lowest;
|
|
312
|
+
depthExtent = depths[layerCount - 1] + layerSizes[layerCount - 1] / 2;
|
|
313
|
+
}
|
|
314
|
+
const swapped = direction === "right" || direction === "left";
|
|
315
|
+
const flipped = direction === "up" || direction === "left";
|
|
316
|
+
const writePoint = (target, offset, breadth, depth) => {
|
|
317
|
+
const along = flipped ? depthExtent - depth : depth;
|
|
318
|
+
target[offset] = swapped ? along : breadth;
|
|
319
|
+
target[offset + 1] = swapped ? breadth : along;
|
|
320
|
+
};
|
|
321
|
+
const positions = new Float64Array(2 * nodeCount);
|
|
322
|
+
for (let node = 0; node < nodeCount; node++) {
|
|
323
|
+
writePoint(positions, 2 * node, breadths[node], depths[layerOf[node]]);
|
|
324
|
+
}
|
|
325
|
+
const edgeStarts = new Uint32Array(linkCount + 1);
|
|
326
|
+
for (let link = 0; link < linkCount; link++) {
|
|
327
|
+
const hasPath = sources[link] !== targets[link];
|
|
328
|
+
edgeStarts[link + 1] =
|
|
329
|
+
edgeStarts[link] +
|
|
330
|
+
(hasPath ? 2 + chainStarts[link + 1] - chainStarts[link] : 0);
|
|
331
|
+
}
|
|
332
|
+
const edgePoints = new Float64Array(2 * edgeStarts[linkCount]);
|
|
333
|
+
for (let link = 0; link < linkCount; link++) {
|
|
334
|
+
const source = sources[link];
|
|
335
|
+
const target = targets[link];
|
|
336
|
+
if (source === target) {
|
|
337
|
+
continue;
|
|
338
|
+
}
|
|
339
|
+
const bendCount = chainStarts[link + 1] - chainStarts[link];
|
|
340
|
+
const bendAt = (index) => nodeCount +
|
|
341
|
+
chainStarts[link] +
|
|
342
|
+
(reversed[link] === 1 ? bendCount - 1 - index : index);
|
|
343
|
+
const firstOther = bendCount > 0 ? bendAt(0) : target;
|
|
344
|
+
const lastOther = bendCount > 0 ? bendAt(bendCount - 1) : source;
|
|
345
|
+
let offset = 2 * edgeStarts[link];
|
|
346
|
+
const border = (node, other) => {
|
|
347
|
+
const deltaBreadth = breadths[other] - breadths[node];
|
|
348
|
+
const deltaDepth = depths[layerOf[other]] - depths[layerOf[node]];
|
|
349
|
+
const fraction = exitFraction_(sizes[node], depthSizes[node], deltaBreadth, deltaDepth);
|
|
350
|
+
writePoint(edgePoints, offset, breadths[node] + fraction * deltaBreadth, depths[layerOf[node]] + fraction * deltaDepth);
|
|
351
|
+
offset += 2;
|
|
352
|
+
};
|
|
353
|
+
border(source, firstOther);
|
|
354
|
+
for (let index = 0; index < bendCount; index++) {
|
|
355
|
+
const bend = bendAt(index);
|
|
356
|
+
writePoint(edgePoints, offset, breadths[bend], depths[layerOf[bend]]);
|
|
357
|
+
offset += 2;
|
|
358
|
+
}
|
|
359
|
+
border(target, lastOther);
|
|
360
|
+
}
|
|
361
|
+
return {
|
|
362
|
+
positions,
|
|
363
|
+
edgePoints,
|
|
364
|
+
edgeStarts,
|
|
365
|
+
width: swapped ? depthExtent : breadthExtent,
|
|
366
|
+
height: swapped ? breadthExtent : depthExtent,
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
//# sourceMappingURL=_layered-position.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_layered-position.js","sourceRoot":"","sources":["../../src/layout/_layered-position.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAI5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AA0CrD;;;;;GAKG;AACH,SAAS,cAAc,CACtB,KAAiB,EACjB,SAAiB,EACjB,KAAkB;IAElB,MAAM,EAAE,UAAU,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,EAAE,cAAc,EAAE,GACvE,KAAK,CAAC;IACP,MAAM,SAAS,GAAG,IAAI,UAAU,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;IACrD,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,UAAU,EAAE,KAAK,EAAE,EAAE,CAAC;QACjD,MAAM,SAAS,GAAG,WAAW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