@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,62 @@
|
|
|
1
|
+
import { type IndexGroups } from "@ac-kit/algo";
|
|
2
|
+
export type TilingContext = {
|
|
3
|
+
/** MinX, minY, maxX, maxY per row; the tiling writes its children's. */
|
|
4
|
+
readonly boxes: Float64Array;
|
|
5
|
+
readonly values: Float64Array;
|
|
6
|
+
readonly depths: Uint32Array;
|
|
7
|
+
/** Rows grouped by parent row, in table order. */
|
|
8
|
+
readonly children: IndexGroups;
|
|
9
|
+
/** Squarify's target aspect ratio. */
|
|
10
|
+
readonly aspectRatio: number;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Splits the box `[x0, x1] × [y0, y1]` between the children of `parentRow` (at
|
|
14
|
+
* least one), writing their boxes.
|
|
15
|
+
*/
|
|
16
|
+
export type Tiling = (context: TilingContext, parentRow: number, x0: number, y0: number, x1: number, y1: number) => void;
|
|
17
|
+
/**
|
|
18
|
+
* Slice-and-dice (Shneiderman, "Tree visualization with tree-maps: 2-d
|
|
19
|
+
* space-filling approach", 1992; Johnson & Shneiderman, 1991): children side by
|
|
20
|
+
* side along x.
|
|
21
|
+
*
|
|
22
|
+
* Complexity: O(k) for k children.
|
|
23
|
+
*/
|
|
24
|
+
export declare const tileDice: Tiling;
|
|
25
|
+
/** Slice-and-dice's other cut: children stacked along y. Same complexity. */
|
|
26
|
+
export declare const tileSlice: Tiling;
|
|
27
|
+
/**
|
|
28
|
+
* Slice-and-dice alternating the cut with depth (Shneiderman 1992): an
|
|
29
|
+
* even-depth parent is diced, an odd-depth one sliced.
|
|
30
|
+
*/
|
|
31
|
+
export declare const tileSliceDice: Tiling;
|
|
32
|
+
/**
|
|
33
|
+
* Squarified treemap (Bruls, Huizing & van Wijk, "Squarified Treemaps",
|
|
34
|
+
* Eurographics/IEEE VisSym 2000, the 1999 report): children are laid in rows
|
|
35
|
+
* along the shorter side of the remaining rectangle; a child joins the current
|
|
36
|
+
* row while the row's worst aspect ratio does not get worse. The target ratio
|
|
37
|
+
* `aspectRatio` generalises the paper's square (ratio 1): with the remaining
|
|
38
|
+
* area scaled to the values, a row of sum `s`, smallest `a` and largest `b` has
|
|
39
|
+
* worst ratio `max(b / β, β / a)` where `β = s² · max(h/w, w/h) / (total ·
|
|
40
|
+
* aspectRatio)`, `w × h` being the remaining rectangle. Zero-value children
|
|
41
|
+
* join the next row (they take no space).
|
|
42
|
+
*
|
|
43
|
+
* Complexity: O(k) for k children.
|
|
44
|
+
*/
|
|
45
|
+
export declare const tileSquarify: Tiling;
|
|
46
|
+
/**
|
|
47
|
+
* Binary-tree treemap (the BinaryTree layout of Bederson & Wattenberg, "Treemap
|
|
48
|
+
* Algorithms v1.0", 2001; a balanced-cut description is in Liang et al., 2015,
|
|
49
|
+
* doi 10.1016/j.jvlc.2015.10.009): the children, in order, are cut at the point
|
|
50
|
+
* that balances the two halves' values best, the box is split across its longer
|
|
51
|
+
* side in the same proportion, and each half is split again until one child is
|
|
52
|
+
* left. The cut is found by binary search over prefix sums. Iterative: the
|
|
53
|
+
* recursion of the description runs on an explicit stack.
|
|
54
|
+
*
|
|
55
|
+
* The split uses the parent's value, so a parent's own value, or children whose
|
|
56
|
+
* values sum to zero, still fill the whole box (d3's behaviour).
|
|
57
|
+
*
|
|
58
|
+
* Complexity: O(k log k) for k children (O(k) prefix sums, one binary search
|
|
59
|
+
* per split).
|
|
60
|
+
*/
|
|
61
|
+
export declare const tileBinary: Tiling;
|
|
62
|
+
//# sourceMappingURL=_treemap-tiling.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_treemap-tiling.d.ts","sourceRoot":"","sources":["../../src/layout/_treemap-tiling.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAE9D,MAAM,MAAM,aAAa,GAAG;IAC3B,wEAAwE;IACxE,QAAQ,CAAC,KAAK,EAAE,YAAY,CAAC;IAC7B,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;IAC9B,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;IAC7B,kDAAkD;IAClD,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC;IAC/B,sCAAsC;IACtC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;CAC7B,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,MAAM,GAAG,CACpB,OAAO,EAAE,aAAa,EACtB,SAAS,EAAE,MAAM,EACjB,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,MAAM,KACN,IAAI,CAAC;AA0DV;;;;;;GAMG;AACH,eAAO,MAAM,QAAQ,EAAE,MAYtB,CAAC;AAEF,6EAA6E;AAC7E,eAAO,MAAM,SAAS,EAAE,MAYvB,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,aAAa,EAAE,MAM3B,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,YAAY,EAAE,MAmD1B,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,UAAU,EAAE,MA0DxB,CAAC"}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { binarySearch } from "@ac-kit/algo";
|
|
2
|
+
/**
|
|
3
|
+
* Lays the rows `indices[from … to)`, whose values sum to `total`, side by side
|
|
4
|
+
* along x over the full height (Shneiderman & Johnson, "slice-and-dice", the
|
|
5
|
+
* vertical cut). A zero total gives zero-width boxes at `x0`.
|
|
6
|
+
*/
|
|
7
|
+
function diceRange_(context, from, to, total, x0, y0, x1, y1) {
|
|
8
|
+
const { boxes, values } = context;
|
|
9
|
+
const { indices } = context.children;
|
|
10
|
+
const scale = total === 0 ? 0 : (x1 - x0) / total;
|
|
11
|
+
let x = x0;
|
|
12
|
+
for (let index = from; index < to; index++) {
|
|
13
|
+
const row = indices[index];
|
|
14
|
+
const offset = row * 4;
|
|
15
|
+
boxes[offset] = x;
|
|
16
|
+
boxes[offset + 1] = y0;
|
|
17
|
+
x += values[row] * scale;
|
|
18
|
+
boxes[offset + 2] = x;
|
|
19
|
+
boxes[offset + 3] = y1;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/** {@link diceRange_} along y: the horizontal cut. */
|
|
23
|
+
function sliceRange_(context, from, to, total, x0, y0, x1, y1) {
|
|
24
|
+
const { boxes, values } = context;
|
|
25
|
+
const { indices } = context.children;
|
|
26
|
+
const scale = total === 0 ? 0 : (y1 - y0) / total;
|
|
27
|
+
let y = y0;
|
|
28
|
+
for (let index = from; index < to; index++) {
|
|
29
|
+
const row = indices[index];
|
|
30
|
+
const offset = row * 4;
|
|
31
|
+
boxes[offset] = x0;
|
|
32
|
+
boxes[offset + 1] = y;
|
|
33
|
+
boxes[offset + 2] = x1;
|
|
34
|
+
y += values[row] * scale;
|
|
35
|
+
boxes[offset + 3] = y;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Slice-and-dice (Shneiderman, "Tree visualization with tree-maps: 2-d
|
|
40
|
+
* space-filling approach", 1992; Johnson & Shneiderman, 1991): children side by
|
|
41
|
+
* side along x.
|
|
42
|
+
*
|
|
43
|
+
* Complexity: O(k) for k children.
|
|
44
|
+
*/
|
|
45
|
+
export const tileDice = (context, parentRow, x0, y0, x1, y1) => {
|
|
46
|
+
const { offsets } = context.children;
|
|
47
|
+
diceRange_(context, offsets[parentRow], offsets[parentRow + 1], context.values[parentRow], x0, y0, x1, y1);
|
|
48
|
+
};
|
|
49
|
+
/** Slice-and-dice's other cut: children stacked along y. Same complexity. */
|
|
50
|
+
export const tileSlice = (context, parentRow, x0, y0, x1, y1) => {
|
|
51
|
+
const { offsets } = context.children;
|
|
52
|
+
sliceRange_(context, offsets[parentRow], offsets[parentRow + 1], context.values[parentRow], x0, y0, x1, y1);
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Slice-and-dice alternating the cut with depth (Shneiderman 1992): an
|
|
56
|
+
* even-depth parent is diced, an odd-depth one sliced.
|
|
57
|
+
*/
|
|
58
|
+
export const tileSliceDice = (context, parentRow, ...box) => {
|
|
59
|
+
((context.depths[parentRow] & 1) === 1 ? tileSlice : tileDice)(context, parentRow, ...box);
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Squarified treemap (Bruls, Huizing & van Wijk, "Squarified Treemaps",
|
|
63
|
+
* Eurographics/IEEE VisSym 2000, the 1999 report): children are laid in rows
|
|
64
|
+
* along the shorter side of the remaining rectangle; a child joins the current
|
|
65
|
+
* row while the row's worst aspect ratio does not get worse. The target ratio
|
|
66
|
+
* `aspectRatio` generalises the paper's square (ratio 1): with the remaining
|
|
67
|
+
* area scaled to the values, a row of sum `s`, smallest `a` and largest `b` has
|
|
68
|
+
* worst ratio `max(b / β, β / a)` where `β = s² · max(h/w, w/h) / (total ·
|
|
69
|
+
* aspectRatio)`, `w × h` being the remaining rectangle. Zero-value children
|
|
70
|
+
* join the next row (they take no space).
|
|
71
|
+
*
|
|
72
|
+
* Complexity: O(k) for k children.
|
|
73
|
+
*/
|
|
74
|
+
export const tileSquarify = (context, parentRow, x0, y0, x1, y1) => {
|
|
75
|
+
const { values } = context;
|
|
76
|
+
const { offsets, indices } = context.children;
|
|
77
|
+
const end = offsets[parentRow + 1];
|
|
78
|
+
const ratio = context.aspectRatio;
|
|
79
|
+
let remaining = values[parentRow];
|
|
80
|
+
let from = offsets[parentRow];
|
|
81
|
+
let to = from;
|
|
82
|
+
while (from < end) {
|
|
83
|
+
const width = x1 - x0;
|
|
84
|
+
const height = y1 - y0;
|
|
85
|
+
let sum = 0;
|
|
86
|
+
do {
|
|
87
|
+
sum = values[indices[to++]];
|
|
88
|
+
} while (sum === 0 && to < end);
|
|
89
|
+
let smallest = sum;
|
|
90
|
+
let largest = sum;
|
|
91
|
+
const alpha = Math.max(height / width, width / height) / (remaining * ratio);
|
|
92
|
+
let beta = sum * sum * alpha;
|
|
93
|
+
let worst = Math.max(largest / beta, beta / smallest);
|
|
94
|
+
for (; to < end; to++) {
|
|
95
|
+
const value = values[indices[to]];
|
|
96
|
+
const grown = sum + value;
|
|
97
|
+
const nextSmallest = value < smallest ? value : smallest;
|
|
98
|
+
const nextLargest = value > largest ? value : largest;
|
|
99
|
+
beta = grown * grown * alpha;
|
|
100
|
+
const nextWorst = Math.max(nextLargest / beta, beta / nextSmallest);
|
|
101
|
+
if (nextWorst > worst) {
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
sum = grown;
|
|
105
|
+
smallest = nextSmallest;
|
|
106
|
+
largest = nextLargest;
|
|
107
|
+
worst = nextWorst;
|
|
108
|
+
}
|
|
109
|
+
if (width < height) {
|
|
110
|
+
const cut = remaining === 0 ? y1 : y0 + (height * sum) / remaining;
|
|
111
|
+
diceRange_(context, from, to, sum, x0, y0, x1, cut);
|
|
112
|
+
y0 = cut;
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
const cut = remaining === 0 ? x1 : x0 + (width * sum) / remaining;
|
|
116
|
+
sliceRange_(context, from, to, sum, x0, y0, cut, y1);
|
|
117
|
+
x0 = cut;
|
|
118
|
+
}
|
|
119
|
+
remaining -= sum;
|
|
120
|
+
from = to;
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
/**
|
|
124
|
+
* Binary-tree treemap (the BinaryTree layout of Bederson & Wattenberg, "Treemap
|
|
125
|
+
* Algorithms v1.0", 2001; a balanced-cut description is in Liang et al., 2015,
|
|
126
|
+
* doi 10.1016/j.jvlc.2015.10.009): the children, in order, are cut at the point
|
|
127
|
+
* that balances the two halves' values best, the box is split across its longer
|
|
128
|
+
* side in the same proportion, and each half is split again until one child is
|
|
129
|
+
* left. The cut is found by binary search over prefix sums. Iterative: the
|
|
130
|
+
* recursion of the description runs on an explicit stack.
|
|
131
|
+
*
|
|
132
|
+
* The split uses the parent's value, so a parent's own value, or children whose
|
|
133
|
+
* values sum to zero, still fill the whole box (d3's behaviour).
|
|
134
|
+
*
|
|
135
|
+
* Complexity: O(k log k) for k children (O(k) prefix sums, one binary search
|
|
136
|
+
* per split).
|
|
137
|
+
*/
|
|
138
|
+
export const tileBinary = (context, parentRow, x0, y0, x1, y1) => {
|
|
139
|
+
const { boxes, values } = context;
|
|
140
|
+
const { offsets, indices } = context.children;
|
|
141
|
+
const first = offsets[parentRow];
|
|
142
|
+
const count = offsets[parentRow + 1] - first;
|
|
143
|
+
const sums = new Float64Array(count + 1);
|
|
144
|
+
for (let index = 0; index < count; index++) {
|
|
145
|
+
sums[index + 1] = sums[index] + values[indices[first + index]];
|
|
146
|
+
}
|
|
147
|
+
// Each entry: range start, range end (exclusive), its value, its box.
|
|
148
|
+
const stack = [0, count, values[parentRow], x0, y0, x1, y1];
|
|
149
|
+
while (stack.length > 0) {
|
|
150
|
+
const bottom = stack.pop();
|
|
151
|
+
const right = stack.pop();
|
|
152
|
+
const top = stack.pop();
|
|
153
|
+
const left = stack.pop();
|
|
154
|
+
const value = stack.pop();
|
|
155
|
+
const end = stack.pop();
|
|
156
|
+
const start = stack.pop();
|
|
157
|
+
if (end - start === 1) {
|
|
158
|
+
const offset = indices[first + start] * 4;
|
|
159
|
+
boxes[offset] = left;
|
|
160
|
+
boxes[offset + 1] = top;
|
|
161
|
+
boxes[offset + 2] = right;
|
|
162
|
+
boxes[offset + 3] = bottom;
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
const offset = sums[start];
|
|
166
|
+
const target = value / 2 + offset;
|
|
167
|
+
let low = binarySearch(start + 1, end - 1, (index) => sums[index] < target);
|
|
168
|
+
// The nearer of the two prefix sums around the target, keeping both halves
|
|
169
|
+
// non-empty.
|
|
170
|
+
if (target - sums[low - 1] < sums[low] - target && start + 1 < low) {
|
|
171
|
+
low--;
|
|
172
|
+
}
|
|
173
|
+
const valueLeft = sums[low] - offset;
|
|
174
|
+
const valueRight = value - valueLeft;
|
|
175
|
+
if (right - left > bottom - top) {
|
|
176
|
+
const cut = value === 0 ? right : (left * valueRight + right * valueLeft) / value;
|
|
177
|
+
stack.push(start, low, valueLeft, left, top, cut, bottom);
|
|
178
|
+
stack.push(low, end, valueRight, cut, top, right, bottom);
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
const cut = value === 0 ? bottom : (top * valueRight + bottom * valueLeft) / value;
|
|
182
|
+
stack.push(start, low, valueLeft, left, top, right, cut);
|
|
183
|
+
stack.push(low, end, valueRight, left, cut, right, bottom);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
//# sourceMappingURL=_treemap-tiling.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_treemap-tiling.js","sourceRoot":"","sources":["../../src/layout/_treemap-tiling.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAoB,MAAM,cAAc,CAAC;AA0B9D;;;;GAIG;AACH,SAAS,UAAU,CAClB,OAAsB,EACtB,IAAY,EACZ,EAAU,EACV,KAAa,EACb,EAAU,EACV,EAAU,EACV,EAAU,EACV,EAAU;IAEV,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IAClC,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,QAAQ,CAAC;IACrC,MAAM,KAAK,GAAG,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,KAAK,CAAC;IAClD,IAAI,CAAC,GAAG,EAAE,CAAC;IACX,KAAK,IAAI,KAAK,GAAG,IAAI,EAAE,KAAK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** Default 1, ≥ 0. */
|
|
7
|
+
readonly radius?: number;
|
|
8
|
+
/** Angle of node 0, radians from +x toward +y. Default −π/2 (top, y-down). */
|
|
9
|
+
readonly startAngle?: number;
|
|
10
|
+
/**
|
|
11
|
+
* Total sweep; negative turns the other way. Default 2π (node i at
|
|
12
|
+
* `startAngle + sweep · i / count`).
|
|
13
|
+
*/
|
|
14
|
+
readonly sweep?: number;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Nodes at equal angles on a circle, in index order: x, y per node, y down.
|
|
18
|
+
*
|
|
19
|
+
* Complexity: O(n) time and memory. `startAngle` and `sweep` are meant to lie
|
|
20
|
+
* within [1e−150, 1e150] in magnitude (a sweep near `Number.MAX_VALUE`
|
|
21
|
+
* overflows to NaN).
|
|
22
|
+
*
|
|
23
|
+
* @throws {RangeError} `count` not a non-negative safe integer, a non-finite
|
|
24
|
+
* option, or a negative radius.
|
|
25
|
+
*/
|
|
26
|
+
export declare function circularLayout(count: number, options?: CircularLayoutOptions): Float64Array;
|
|
27
|
+
//# sourceMappingURL=circular-layout.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"circular-layout.d.ts","sourceRoot":"","sources":["../../src/layout/circular-layout.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,qBAAqB,GAAG;IACnC,iBAAiB;IACjB,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,iBAAiB;IACjB,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,sBAAsB;IACtB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,8EAA8E;IAC9E,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B;;;OAGG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAC7B,KAAK,EAAE,MAAM,EACb,OAAO,GAAE,qBAA0B,GACjC,YAAY,CA0Bd"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { assertFinite, assertInteger, assertNonNegative } from "@ac-kit/core";
|
|
2
|
+
import { polarCoordsCreate, vec2FromPolar } from "@ac-kit/math-geometry";
|
|
3
|
+
import { vec2Create } from "@ac-kit/math-linear";
|
|
4
|
+
import { TWO_PI } from "@ac-kit/math-scalar";
|
|
5
|
+
/**
|
|
6
|
+
* Nodes at equal angles on a circle, in index order: x, y per node, y down.
|
|
7
|
+
*
|
|
8
|
+
* Complexity: O(n) time and memory. `startAngle` and `sweep` are meant to lie
|
|
9
|
+
* within [1e−150, 1e150] in magnitude (a sweep near `Number.MAX_VALUE`
|
|
10
|
+
* overflows to NaN).
|
|
11
|
+
*
|
|
12
|
+
* @throws {RangeError} `count` not a non-negative safe integer, a non-finite
|
|
13
|
+
* option, or a negative radius.
|
|
14
|
+
*/
|
|
15
|
+
export function circularLayout(count, options = {}) {
|
|
16
|
+
const { centerX = 0, centerY = 0, radius = 1, startAngle = -Math.PI / 2, sweep = TWO_PI, } = options;
|
|
17
|
+
assertInteger(count, "circularLayout: count", 0);
|
|
18
|
+
assertFinite(centerX, "circularLayout: centerX");
|
|
19
|
+
assertFinite(centerY, "circularLayout: centerY");
|
|
20
|
+
assertNonNegative(radius, "circularLayout: radius");
|
|
21
|
+
assertFinite(startAngle, "circularLayout: startAngle");
|
|
22
|
+
assertFinite(sweep, "circularLayout: sweep");
|
|
23
|
+
const positions = new Float64Array(count * 2);
|
|
24
|
+
const polar = polarCoordsCreate();
|
|
25
|
+
const point = vec2Create();
|
|
26
|
+
polar[0] = radius;
|
|
27
|
+
for (let index = 0; index < count; index++) {
|
|
28
|
+
polar[1] = startAngle + (sweep * index) / count;
|
|
29
|
+
vec2FromPolar(point, polar);
|
|
30
|
+
positions[index * 2] = centerX + point[0];
|
|
31
|
+
positions[index * 2 + 1] = centerY + point[1];
|
|
32
|
+
}
|
|
33
|
+
return positions;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=circular-layout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"circular-layout.js","sourceRoot":"","sources":["../../src/layout/circular-layout.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAC9E,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACzE,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAkB7C;;;;;;;;;GASG;AACH,MAAM,UAAU,cAAc,CAC7B,KAAa,EACb,OAAO,GAA0B,EAAE;IAEnC,MAAM,EACL,OAAO,GAAG,CAAC,EACX,OAAO,GAAG,CAAC,EACX,MAAM,GAAG,CAAC,EACV,UAAU,GAAG,CAAC,IAAI,CAAC,EAAE,GAAG,CAAC,EACzB,KAAK,GAAG,MAAM,GACd,GAAG,OAAO,CAAC;IACZ,aAAa,CAAC,KAAK,EAAE,uBAAuB,EAAE,CAAC,CAAC,CAAC;IACjD,YAAY,CAAC,OAAO,EAAE,yBAAyB,CAAC,CAAC;IACjD,YAAY,CAAC,OAAO,EAAE,yBAAyB,CAAC,CAAC;IACjD,iBAAiB,CAAC,MAAM,EAAE,wBAAwB,CAAC,CAAC;IACpD,YAAY,CAAC,UAAU,EAAE,4BAA4B,CAAC,CAAC;IACvD,YAAY,CAAC,KAAK,EAAE,uBAAuB,CAAC,CAAC;IAE7C,MAAM,SAAS,GAAG,IAAI,YAAY,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;IAC9C,MAAM,KAAK,GAAG,iBAAiB,EAAE,CAAC;IAClC,MAAM,KAAK,GAAG,UAAU,EAAE,CAAC;IAC3B,KAAK,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC;IAClB,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC;QAC5C,KAAK,CAAC,CAAC,CAAC,GAAG,UAAU,GAAG,CAAC,KAAK,GAAG,KAAK,CAAC,GAAG,KAAK,CAAC;QAChD,aAAa,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;QAC5B,SAAS,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,OAAO,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QAC1C,SAAS,CAAC,KAAK,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,OAAO,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;IAC/C,CAAC;IACD,OAAO,SAAS,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import type { Callable, RandomFn } from "@ac-kit/core";
|
|
2
|
+
import type { NetworkTraits } from "./types.js";
|
|
3
|
+
export type ForceTraits<TNode, TLink> = NetworkTraits<TNode, TLink> & {
|
|
4
|
+
/**
|
|
5
|
+
* Many-body strength; negative repels (d3 `forceManyBody`). Default −30;
|
|
6
|
+
* finite.
|
|
7
|
+
*/
|
|
8
|
+
readonly chargeOf?: Callable<[node: TNode, index: number], number>;
|
|
9
|
+
/** Collision radius (d3 `forceCollide`); absent: no collision force. Finite, ≥ 0. */
|
|
10
|
+
readonly radiusOf?: Callable<[node: TNode, index: number], number>;
|
|
11
|
+
/** Rest length (d3 `forceLink`). Default 30; finite, ≥ 0. */
|
|
12
|
+
readonly linkDistanceOf?: Callable<[link: TLink, index: number], number>;
|
|
13
|
+
/**
|
|
14
|
+
* Default 1 / min(degree(source), degree(target)), degrees counting every
|
|
15
|
+
* link end (d3). Finite, ≥ 0.
|
|
16
|
+
*/
|
|
17
|
+
readonly linkStrengthOf?: Callable<[link: TLink, index: number], number>;
|
|
18
|
+
};
|
|
19
|
+
export type ForceOptions = {
|
|
20
|
+
/** Velocity kept per step is 1 − velocityDecay. Default 0.4, in [0, 1]. */
|
|
21
|
+
readonly velocityDecay?: number;
|
|
22
|
+
/**
|
|
23
|
+
* `"barnesHut"`: O(n log n) per step over `Quadtree`; `"exact"`: O(n²).
|
|
24
|
+
* Default "barnesHut".
|
|
25
|
+
*/
|
|
26
|
+
readonly approximation?: "barnesHut" | "exact";
|
|
27
|
+
/**
|
|
28
|
+
* Barnes–Hut opening criterion, as d3-force's: a cell is summarised as one
|
|
29
|
+
* body at its centre of |charge| once width / distance < θ. Default 0.9;
|
|
30
|
+
* finite, > 0. The approximation is d3's and keeps its limits: a cell that
|
|
31
|
+
* holds the node itself is summarised too once θ is large (about > 1), so the
|
|
32
|
+
* node then feels a force from its own charge; with charges of mixed sign the
|
|
33
|
+
* summary uses the signed sum at the |charge|-weighted centre and has no
|
|
34
|
+
* relative error bound. The error is small for same-sign charges and θ ≤ 1.
|
|
35
|
+
* `"exact"` has none of these limits.
|
|
36
|
+
*/
|
|
37
|
+
readonly theta?: number;
|
|
38
|
+
/**
|
|
39
|
+
* Many-body distance clamp. Defaults 1 and Infinity; 0 ≤ min, min ≤ max. In
|
|
40
|
+
* Barnes–Hut mode `distanceMax` is applied per cell, to the distance from the
|
|
41
|
+
* node to the cell's centre (d3-force's behaviour): a cell straddling the
|
|
42
|
+
* cutoff counts whole or not at all. `"exact"` applies it per pair.
|
|
43
|
+
*/
|
|
44
|
+
readonly distanceMin?: number;
|
|
45
|
+
readonly distanceMax?: number;
|
|
46
|
+
/**
|
|
47
|
+
* Centring (d3 `forceCenter`): shifts positions so that their mean moves
|
|
48
|
+
* `centerStrength` of the way to the centre. Defaults 0, 0 and 1; a strength
|
|
49
|
+
* of 0 disables it.
|
|
50
|
+
*/
|
|
51
|
+
readonly centerX?: number;
|
|
52
|
+
readonly centerY?: number;
|
|
53
|
+
readonly centerStrength?: number;
|
|
54
|
+
/**
|
|
55
|
+
* Pull toward the centre on each axis (d3 `forceX`/`forceY`), keeps
|
|
56
|
+
* disconnected parts together. Default 0; finite, ≥ 0.
|
|
57
|
+
*/
|
|
58
|
+
readonly gravity?: number;
|
|
59
|
+
/** Default 1, in [0, 1]. */
|
|
60
|
+
readonly collideStrength?: number;
|
|
61
|
+
/** Default 1; a positive integer. */
|
|
62
|
+
readonly collideIterations?: number;
|
|
63
|
+
/**
|
|
64
|
+
* `"d3"` (default): collision cells are bounded on the predictions made when
|
|
65
|
+
* the pass starts, as d3-force's are, so a node pushed into another's reach
|
|
66
|
+
* earlier in the same pass can miss it until the next pass. `"live"` widens
|
|
67
|
+
* the pruning by how far any prediction has moved, so no pair is missed;
|
|
68
|
+
* results then differ from d3-force's.
|
|
69
|
+
*/
|
|
70
|
+
readonly collideBounds?: "d3" | "live";
|
|
71
|
+
/** Default 1; a positive integer. */
|
|
72
|
+
readonly linkIterations?: number;
|
|
73
|
+
/**
|
|
74
|
+
* Separates coincident nodes with offsets of ±5e-7; a seeded generator
|
|
75
|
+
* (`mulberry32(seed)`) keeps runs reproducible. Called in a fixed order, so
|
|
76
|
+
* the same seed gives the same layout.
|
|
77
|
+
*/
|
|
78
|
+
readonly random: RandomFn;
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* One velocity-Verlet step at cooling `alpha` ∈ [0, 1]: forces in the order
|
|
82
|
+
* link → many-body → collide → gravity → centre, then v ← v·(1 −
|
|
83
|
+
* velocityDecay), x ← x + v; an axis with a finite `fixedPositions` entry is
|
|
84
|
+
* pinned there with zero velocity (d3 `fx`/`fy`; NaN means free). Mutates
|
|
85
|
+
* `positions` and `velocities` (2 per node); both must hold finite numbers. 0 B
|
|
86
|
+
* per call after the first calls. @throws {RangeError} wrong lengths; alpha
|
|
87
|
+
* outside [0, 1]; a `fixedPositions` entry that is ±Infinity; a non-finite
|
|
88
|
+
* position when the many-body or collision force reads it.
|
|
89
|
+
*/
|
|
90
|
+
export type ForceStep = Callable<[
|
|
91
|
+
positions: Float64Array,
|
|
92
|
+
velocities: Float64Array,
|
|
93
|
+
alpha: number,
|
|
94
|
+
fixedPositions?: Float64Array
|
|
95
|
+
]>;
|
|
96
|
+
/**
|
|
97
|
+
* Reads traits once (degrees, biases, strengths, distances, charges, radii into
|
|
98
|
+
* typed arrays) and returns the step for this graph. The simulation's state —
|
|
99
|
+
* positions, velocities, alpha schedule, pins — stays with the caller (an
|
|
100
|
+
* animation loop); the step owns only derived constants and scratch (one
|
|
101
|
+
* `Quadtree` per force, aggregate buffers).
|
|
102
|
+
*
|
|
103
|
+
* Complexity: O(n + m) to create; per step O(n log n + m) Barnes–Hut (O(n²)
|
|
104
|
+
* exact many-body), collision O(n log n) expected, O(n²) when the discs overlap
|
|
105
|
+
* everywhere.
|
|
106
|
+
*
|
|
107
|
+
* @throws {RangeError} A link index outside `[0, nodes.length)` or not an
|
|
108
|
+
* integer, a non-finite or negative trait value naming its row, an option out
|
|
109
|
+
* of range.
|
|
110
|
+
*/
|
|
111
|
+
export declare function createForceStep<TNode, TLink>(nodes: readonly TNode[], links: readonly TLink[], traits: ForceTraits<TNode, TLink>, options: ForceOptions): ForceStep;
|
|
112
|
+
//# sourceMappingURL=create-force-step.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-force-step.d.ts","sourceRoot":"","sources":["../../src/layout/create-force-step.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAWvD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD,MAAM,MAAM,WAAW,CAAC,KAAK,EAAE,KAAK,IAAI,aAAa,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG;IACrE;;;OAGG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC;IACnE,qFAAqF;IACrF,QAAQ,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,MA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AAE,QAAQ,CAAC;CAC1B,CAAC;AAEF;;;;;;;;;GASG;AACH,MAAM,MAAM,SAAS,GAAG,QAAQ,CAC/B;IACC,SAAS,EAAE,YAAY;IACvB,UAAU,EAAE,YAAY;IACxB,KAAK,EAAE,MAAM;IACb,cAAc,CAAC,EAAE,YAAY;CAC7B,CACD,CAAC;AA2BF;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,KAAK,EAC3C,KAAK,EAAE,SAAS,KAAK,EAAE,EACvB,KAAK,EAAE,SAAS,KAAK,EAAE,EACvB,MAAM,EAAE,WAAW,CAAC,KAAK,EAAE,KAAK,CAAC,EACjC,OAAO,EAAE,YAAY,GACnB,SAAS,CAqLX"}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { assertFinite, assertInteger, assertNonNegative, describeValue, } from "@ac-kit/core";
|
|
2
|
+
import { applyCentering, applyGravity, applyLinkForce, CollideForce, integrate, ManyBodyForce, } from "./_force-forces.js";
|
|
3
|
+
import { buildIndexGraph } from "./_index-graph.js";
|
|
4
|
+
function readTrait(items, read, fallback, label, isValid) {
|
|
5
|
+
const values = new Float64Array(items.length);
|
|
6
|
+
for (let index = 0; index < items.length; index++) {
|
|
7
|
+
const value = read === undefined ? fallback(index) : read(items[index], index);
|
|
8
|
+
if (!isValid(value)) {
|
|
9
|
+
throw new RangeError(`createForceStep: ${label} ${index} is invalid, got ${describeValue(value)}`);
|
|
10
|
+
}
|
|
11
|
+
values[index] = value;
|
|
12
|
+
}
|
|
13
|
+
return values;
|
|
14
|
+
}
|
|
15
|
+
function isFiniteNonNegative(value) {
|
|
16
|
+
return Number.isFinite(value) && value >= 0;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Reads traits once (degrees, biases, strengths, distances, charges, radii into
|
|
20
|
+
* typed arrays) and returns the step for this graph. The simulation's state —
|
|
21
|
+
* positions, velocities, alpha schedule, pins — stays with the caller (an
|
|
22
|
+
* animation loop); the step owns only derived constants and scratch (one
|
|
23
|
+
* `Quadtree` per force, aggregate buffers).
|
|
24
|
+
*
|
|
25
|
+
* Complexity: O(n + m) to create; per step O(n log n + m) Barnes–Hut (O(n²)
|
|
26
|
+
* exact many-body), collision O(n log n) expected, O(n²) when the discs overlap
|
|
27
|
+
* everywhere.
|
|
28
|
+
*
|
|
29
|
+
* @throws {RangeError} A link index outside `[0, nodes.length)` or not an
|
|
30
|
+
* integer, a non-finite or negative trait value naming its row, an option out
|
|
31
|
+
* of range.
|
|
32
|
+
*/
|
|
33
|
+
export function createForceStep(nodes, links, traits, options) {
|
|
34
|
+
const { velocityDecay = 0.4, approximation = "barnesHut", theta = 0.9, distanceMin = 1, distanceMax = Infinity, centerX = 0, centerY = 0, centerStrength = 1, gravity = 0, collideStrength = 1, collideIterations = 1, collideBounds = "d3", linkIterations = 1, random, } = options;
|
|
35
|
+
if (typeof random !== "function") {
|
|
36
|
+
throw new TypeError(`createForceStep: random must be a function, got ${describeValue(random)}`);
|
|
37
|
+
}
|
|
38
|
+
if (!(velocityDecay >= 0 && velocityDecay <= 1)) {
|
|
39
|
+
throw new RangeError(`createForceStep: velocityDecay must be in [0, 1], got ${describeValue(velocityDecay)}`);
|
|
40
|
+
}
|
|
41
|
+
if (approximation !== "barnesHut" && approximation !== "exact") {
|
|
42
|
+
throw new RangeError(`createForceStep: approximation must be "barnesHut" or "exact", got ${describeValue(approximation)}`);
|
|
43
|
+
}
|
|
44
|
+
if (!(Number.isFinite(theta) && theta > 0)) {
|
|
45
|
+
throw new RangeError(`createForceStep: theta must be finite and positive, got ${describeValue(theta)}`);
|
|
46
|
+
}
|
|
47
|
+
assertNonNegative(distanceMin, "createForceStep: distanceMin");
|
|
48
|
+
assertNonNegative(distanceMax, "createForceStep: distanceMax", {
|
|
49
|
+
isInfinityAllowed: true,
|
|
50
|
+
});
|
|
51
|
+
if (distanceMax < distanceMin) {
|
|
52
|
+
throw new RangeError(`createForceStep: distanceMax ${distanceMax} is below distanceMin ${distanceMin}`);
|
|
53
|
+
}
|
|
54
|
+
assertFinite(centerX, "createForceStep: centerX");
|
|
55
|
+
assertFinite(centerY, "createForceStep: centerY");
|
|
56
|
+
assertFinite(centerStrength, "createForceStep: centerStrength");
|
|
57
|
+
assertNonNegative(gravity, "createForceStep: gravity");
|
|
58
|
+
if (!(collideStrength >= 0 && collideStrength <= 1)) {
|
|
59
|
+
throw new RangeError(`createForceStep: collideStrength must be in [0, 1], got ${describeValue(collideStrength)}`);
|
|
60
|
+
}
|
|
61
|
+
assertInteger(collideIterations, "createForceStep: collideIterations", 1);
|
|
62
|
+
if (collideBounds !== "d3" && collideBounds !== "live") {
|
|
63
|
+
throw new RangeError(`createForceStep: collideBounds must be "d3" or "live", got ${describeValue(collideBounds)}`);
|
|
64
|
+
}
|
|
65
|
+
assertInteger(linkIterations, "createForceStep: linkIterations", 1);
|
|
66
|
+
const nodeCount = nodes.length;
|
|
67
|
+
const graph = buildIndexGraph(nodeCount, links, traits, "createForceStep");
|
|
68
|
+
const degrees = (node) => graph.outDegrees[node] + graph.inDegrees[node];
|
|
69
|
+
const charges = readTrait(nodes, traits.chargeOf, () => -30, "charge of node", Number.isFinite);
|
|
70
|
+
const radii = traits.radiusOf === undefined
|
|
71
|
+
? undefined
|
|
72
|
+
: readTrait(nodes, traits.radiusOf, () => 0, "radius of node", isFiniteNonNegative);
|
|
73
|
+
const distances = readTrait(links, traits.linkDistanceOf, () => 30, "distance of link", isFiniteNonNegative);
|
|
74
|
+
const strengths = readTrait(links, traits.linkStrengthOf, (link) => 1 /
|
|
75
|
+
Math.min(degrees(graph.sources[link]), degrees(graph.targets[link])), "strength of link", isFiniteNonNegative);
|
|
76
|
+
const biases = new Float64Array(links.length);
|
|
77
|
+
for (let link = 0; link < links.length; link++) {
|
|
78
|
+
const source = degrees(graph.sources[link]);
|
|
79
|
+
biases[link] = source / (source + degrees(graph.targets[link]));
|
|
80
|
+
}
|
|
81
|
+
const linkData = {
|
|
82
|
+
sources: graph.sources,
|
|
83
|
+
targets: graph.targets,
|
|
84
|
+
distances,
|
|
85
|
+
strengths,
|
|
86
|
+
biases,
|
|
87
|
+
iterations: linkIterations,
|
|
88
|
+
};
|
|
89
|
+
const manyBody = new ManyBodyForce(charges, {
|
|
90
|
+
approximation,
|
|
91
|
+
theta,
|
|
92
|
+
distanceMin,
|
|
93
|
+
distanceMax,
|
|
94
|
+
random,
|
|
95
|
+
});
|
|
96
|
+
const collide = radii === undefined
|
|
97
|
+
? undefined
|
|
98
|
+
: new CollideForce(radii, collideStrength, collideIterations, random, collideBounds === "live");
|
|
99
|
+
const keep = 1 - velocityDecay;
|
|
100
|
+
return (positions, velocities, alpha, fixedPositions) => {
|
|
101
|
+
if (positions.length !== nodeCount * 2) {
|
|
102
|
+
throw new RangeError(`createForceStep: positions must hold ${nodeCount * 2} numbers, got ${positions.length}`);
|
|
103
|
+
}
|
|
104
|
+
if (velocities.length !== nodeCount * 2) {
|
|
105
|
+
throw new RangeError(`createForceStep: velocities must hold ${nodeCount * 2} numbers, got ${velocities.length}`);
|
|
106
|
+
}
|
|
107
|
+
if (fixedPositions !== undefined &&
|
|
108
|
+
fixedPositions.length !== nodeCount * 2) {
|
|
109
|
+
throw new RangeError(`createForceStep: fixedPositions must hold ${nodeCount * 2} numbers, got ${fixedPositions.length}`);
|
|
110
|
+
}
|
|
111
|
+
if (fixedPositions !== undefined) {
|
|
112
|
+
for (let index = 0; index < fixedPositions.length; index++) {
|
|
113
|
+
const pin = fixedPositions[index];
|
|
114
|
+
if (!Number.isNaN(pin) && !Number.isFinite(pin)) {
|
|
115
|
+
throw new RangeError(`createForceStep: fixedPositions[${index}] must be finite or NaN, got ${describeValue(pin)}`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
if (!(alpha >= 0 && alpha <= 1)) {
|
|
120
|
+
throw new RangeError(`createForceStep: alpha must be in [0, 1], got ${describeValue(alpha)}`);
|
|
121
|
+
}
|
|
122
|
+
applyLinkForce(positions, velocities, alpha, linkData, random);
|
|
123
|
+
manyBody.apply(positions, velocities, alpha);
|
|
124
|
+
collide?.apply(positions, velocities);
|
|
125
|
+
if (gravity !== 0) {
|
|
126
|
+
applyGravity(positions, velocities, alpha, gravity, centerX, centerY);
|
|
127
|
+
}
|
|
128
|
+
if (centerStrength !== 0) {
|
|
129
|
+
applyCentering(positions, centerStrength, centerX, centerY);
|
|
130
|
+
}
|
|
131
|
+
integrate(positions, velocities, keep, fixedPositions);
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
//# sourceMappingURL=create-force-step.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-force-step.js","sourceRoot":"","sources":["../../src/layout/create-force-step.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,YAAY,EACZ,aAAa,EACb,iBAAiB,EACjB,aAAa,GACb,MAAM,cAAc,CAAC;AAGtB,OAAO,EACN,cAAc,EACd,YAAY,EACZ,cAAc,EACd,YAAY,EACZ,SAAS,EACT,aAAa,GACb,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAqGpD,SAAS,SAAS,CACjB,KAAuB,EACvB,IAAgE,EAChE,QAA2C,EAC3C,KAAa,EACb,OAAmC;IAEnC,MAAM,MAAM,GAAG,IAAI,YAAY,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAC9C,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC;QACnD,MAAM,KAAK,GACV,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAE,EAAE,KAAK,CAAC,CAAC;QACnE,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YACrB,MAAM,IAAI,UAAU,CACnB,oBAAoB,KA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c,CAAC,CAAC;IACxD,CAAC,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { Callable } from "@ac-kit/core";
|
|
2
|
+
import type { HierarchyPointLayout, HierarchyWalkOptions, TreeSizeOptions, TreeTraits } from "./types.js";
|
|
3
|
+
export type DendrogramTraits<TNode> = TreeTraits<TNode> & {
|
|
4
|
+
/**
|
|
5
|
+
* Merge height (0 at leaves). Present: y = height · (1 − h / maxH), so the
|
|
6
|
+
* highest merge sits at the top and leaves at the bottom; inversions (a child
|
|
7
|
+
* higher than its parent) are drawn as given. Absent: every leaf at the same
|
|
8
|
+
* depth and each parent one level above its highest child. Finite, ≥ 0; read
|
|
9
|
+
* once per row, in pre-order.
|
|
10
|
+
*/
|
|
11
|
+
readonly heightOf?: Callable<[node: TNode, index: number], number>;
|
|
12
|
+
};
|
|
13
|
+
export type DendrogramLayoutOptions = HierarchyWalkOptions & TreeSizeOptions;
|
|
14
|
+
/**
|
|
15
|
+
* Leaves evenly spaced in pre-order along x (`separationOf` apart), each parent
|
|
16
|
+
* at the mean x of its children — the layout of a dendrogram or a cluster tree.
|
|
17
|
+
* With `width`/`height` the leaves are inset half a separation from the box
|
|
18
|
+
* edges; with `nodeWidth`/`nodeHeight` the root sits at x = 0 and the highest
|
|
19
|
+
* row at y = 0, `nodeHeight` per unit of height (or per level without
|
|
20
|
+
* `heightOf`). All heights 0 put every row at y = 0.
|
|
21
|
+
*
|
|
22
|
+
* The arrangement is the one scipy's `dendrogram` and d3's `cluster` draw.
|
|
23
|
+
*
|
|
24
|
+
* Complexity: O(n) time and memory, no recursion on depth. Separations and
|
|
25
|
+
* sizes are meant to lie within [1e−150, 1e150]; beyond that sums and quotients
|
|
26
|
+
* can underflow or overflow to NaN or ∞.
|
|
27
|
+
*
|
|
28
|
+
* @throws {RangeError} A size that is not finite and > 0, a height that is not
|
|
29
|
+
* finite and ≥ 0, or a separation that is not finite and > 0.
|
|
30
|
+
*/
|
|
31
|
+
export declare function dendrogramLayout<TNode>(root: TNode, traits: DendrogramTraits<TNode>, options?: DendrogramLayoutOptions): HierarchyPointLayout<TNode>;
|
|
32
|
+
//# sourceMappingURL=dendrogram-layout.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dendrogram-layout.d.ts","sourceRoot":"","sources":["../../src/layout/dendrogram-layout.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAQ7C,OAAO,KAAK,EACX,oBAAoB,EACpB,oBAAoB,EACpB,eAAe,EACf,UAAU,EACV,MAAM,YAAY,CAAC;AAEpB,MAAM,MAAM,gBAAgB,CAAC,KAAK,IAAI,UAAU,CAAC,KAAK,CAAC,GAAG;IACzD;;;;;;OAMG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC;CACnE,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG,oBAAoB,GAAG,eAAe,CAAC;AAE7E;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EACrC,IAAI,EAAE,KAAK,EACX,MAAM,EAAE,gBAAgB,CAAC,KAAK,CAAC,EAC/B,OAAO,GAAE,uBAA4B,GACnC,oBAAoB,CAAC,KAAK,CAAC,CA8F7B"}
|