@ac-kit/math-graph 0.0.0-stage → 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/CHANGELOG.md +183 -0
- package/LICENSE +28 -0
- package/README.md +118 -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 +227 -0
- package/dist/layout/_force-forces.d.ts.map +1 -0
- package/dist/layout/_force-forces.js +1572 -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 +138 -0
- package/dist/layout/_layer-order.d.ts.map +1 -0
- package/dist/layout/_layer-order.js +954 -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 +58 -0
- package/dist/layout/_layered-rank.d.ts.map +1 -0
- package/dist/layout/_layered-rank.js +529 -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 +73 -0
- package/dist/layout/_treemap-tiling.d.ts.map +1 -0
- package/dist/layout/_treemap-tiling.js +247 -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 +127 -0
- package/dist/layout/create-force-step.d.ts.map +1 -0
- package/dist/layout/create-force-step.js +167 -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 +109 -0
- package/dist/layout/layered-layout.d.ts.map +1 -0
- package/dist/layout/layered-layout.js +124 -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 +113 -0
- package/dist/layout/sankey-layout.d.ts.map +1 -0
- package/dist/layout/sankey-layout.js +641 -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 +63 -0
- package/dist/layout/treemap-layout.d.ts.map +1 -0
- package/dist/layout/treemap-layout.js +126 -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 +68 -3
|
@@ -0,0 +1,369 @@
|
|
|
1
|
+
import { groupIndices } from "@ac-kit/algo";
|
|
2
|
+
import { groupByNeighbour } 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;;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,SAAS;QACT,UAAU;QACV,UAAU;QACV,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,aAAa;QAC5C,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,WAAW;KAC7C,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { WorkBudget } from "@ac-kit/core";
|
|
2
|
+
import type { IndexGraph } from "./_index-graph.js";
|
|
3
|
+
/**
|
|
4
|
+
* Ranks every node on the longest path to a sink: rank(v) = L − (length of the
|
|
5
|
+
* longest path from v to a sink), where a link spans at least its minimum
|
|
6
|
+
* length and L is the longest path of the graph. Sinks, and the nodes with no
|
|
7
|
+
* link, sit on the last rank L; the ranks start at 0. The same result as
|
|
8
|
+
* dagre's `longestPath` ranker followed by its normalisation.
|
|
9
|
+
*
|
|
10
|
+
* `reversed` flags the links to read backward (the output of
|
|
11
|
+
* `findReversedLinks`); self-loops are ignored.
|
|
12
|
+
*
|
|
13
|
+
* Complexity: O(V + E) time and memory.
|
|
14
|
+
*
|
|
15
|
+
* @param minLengths Per link, a positive integer (default 1).
|
|
16
|
+
* @throws {RangeError} The graph is still cyclic once `reversed` is applied.
|
|
17
|
+
*/
|
|
18
|
+
export declare function longestPathRanks(graph: IndexGraph, reversed: ArrayLike<number>, minLengths?: ArrayLike<number>): Uint32Array;
|
|
19
|
+
/**
|
|
20
|
+
* Ranks that minimise Σ weight·(rank(head) − rank(tail)) subject to rank(head)
|
|
21
|
+
* − rank(tail) ≥ minLength for every link, by the network simplex method of
|
|
22
|
+
* Gansner, Koutsofios, North & Vo 1993 ("A Technique for Drawing Directed
|
|
23
|
+
* Graphs", §2): a feasible ranking from the longest path, a tight spanning tree
|
|
24
|
+
* (§2.3), then pivots: a tree link with a negative cut value leaves, the
|
|
25
|
+
* non-tree link of least slack across its cut enters, and the subtree below the
|
|
26
|
+
* leaving link shifts until that link is tight. The cut values come from
|
|
27
|
+
* subtree sums of out-weight minus in-weight over a depth-first numbering of
|
|
28
|
+
* the tree, recomputed after each pivot (§2.4 updates them incrementally).
|
|
29
|
+
* Those sums are compensated (TwoSum, with a running error bound), and a cut
|
|
30
|
+
* whose sign lies within its bound is settled by an exact sum over the links
|
|
31
|
+
* that cross it, so no weight, however heavy or inexact, hides an improving
|
|
32
|
+
* pivot. Ties break by link index, so the result is deterministic.
|
|
33
|
+
*
|
|
34
|
+
* Each weakly connected component is solved on its own and normalised to start
|
|
35
|
+
* at rank 0, so components share the ranks. `reversed` flags the links to read
|
|
36
|
+
* backward; self-loops are ignored. The minimum is unique in value, not in
|
|
37
|
+
* ranks.
|
|
38
|
+
*
|
|
39
|
+
* Complexity: a pivot is O(V + E); the number of pivots is not polynomially
|
|
40
|
+
* bounded in theory and near-linear in practice. The feasible tree costs up to
|
|
41
|
+
* O(V · (V + E)). O(V + E) memory.
|
|
42
|
+
*
|
|
43
|
+
* @param weights Per link, finite ≥ 0 (default 1); a zero-weight link only
|
|
44
|
+
* constrains.
|
|
45
|
+
* @param minLengths Per link, a positive integer (default 1).
|
|
46
|
+
* @param budget Charged V + E (of the component) for the tree and per pivot,
|
|
47
|
+
* and E before each exact scan that settles a cut value its compensated sum
|
|
48
|
+
* leaves undecided; whatever it throws propagates.
|
|
49
|
+
* @throws {RangeError} The graph is still cyclic once `reversed` is applied.
|
|
50
|
+
*/
|
|
51
|
+
export declare function networkSimplexRanks(graph: IndexGraph, reversed: ArrayLike<number>, weights?: ArrayLike<number>, minLengths?: ArrayLike<number>, budget?: WorkBudget): Uint32Array;
|
|
52
|
+
/**
|
|
53
|
+
* {@link networkSimplexRanks} as steps: yields right after each budget charge
|
|
54
|
+
* (feasible-tree round, pivot), so a runner can stop or give up the thread
|
|
55
|
+
* between them. Returns the ranks.
|
|
56
|
+
*/
|
|
57
|
+
export declare function networkSimplexRankSteps(graph: IndexGraph, reversed: ArrayLike<number>, weights?: ArrayLike<number>, minLengths?: ArrayLike<number>, budget?: WorkBudget): Generator<void, Uint32Array, undefined>;
|
|
58
|
+
//# sourceMappingURL=_layered-rank.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_layered-rank.d.ts","sourceRoot":"","sources":["../../src/layout/_layered-rank.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAK/C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAIpD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,gBAAgB,CAC/B,KAAK,EAAE,UAAU,EACjB,QAAQ,EAAE,SAAS,CAAC,MAAM,CAAC,EAC3B,UAAU,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,GAC5B,WAAW,CAsEb;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAgB,mBAAmB,CAClC,KAAK,EAAE,UAAU,EACjB,QAAQ,EAAE,SAAS,CAAC,MAAM,CAAC,EAC3B,OAAO,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,EAC3B,UAAU,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,EAC9B,MAAM,CAAC,EAAE,UAAU,GACjB,WAAW,CAIb;AAED;;;;GAIG;AACH,wBAAiB,uBAAuB,CACvC,KAAK,EAAE,UAAU,EACjB,QAAQ,EAAE,SAAS,CAAC,MAAM,CAAC,EAC3B,OAAO,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,EAC3B,UAAU,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,EAC9B,MAAM,CAAC,EAAE,UAAU,GACjB,SAAS,CAAC,IAAI,EAAE,WAAW,EAAE,SAAS,CAAC,CAsFzC"}
|