@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,124 @@
|
|
|
1
|
+
import { assertNonNegative, describeValue, isIntegerInRange, runInTimeSlices, runToCompletion, } from "@ac-kit/core";
|
|
2
|
+
import { buildIndexGraph } from "./_index-graph.js";
|
|
3
|
+
import { orderLayerSteps } from "./_layer-order.js";
|
|
4
|
+
import { findReversedLinks } from "./_layered-acyclic.js";
|
|
5
|
+
import { placeLayers } from "./_layered-position.js";
|
|
6
|
+
import { longestPathRanks, networkSimplexRankSteps } from "./_layered-rank.js";
|
|
7
|
+
const DIRECTIONS_ = ["down", "up", "right", "left"];
|
|
8
|
+
const RANKINGS_ = ["networkSimplex", "longestPath"];
|
|
9
|
+
const CYCLE_REMOVALS_ = ["depthFirst", "greedy"];
|
|
10
|
+
function readNumbers_(items, read, isValid, describe) {
|
|
11
|
+
if (read === undefined) {
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
const values = new Float64Array(items.length);
|
|
15
|
+
for (let index = 0; index < items.length; index++) {
|
|
16
|
+
const value = read(items[index], index);
|
|
17
|
+
if (!isValid(value)) {
|
|
18
|
+
throw new RangeError(describe(index, value));
|
|
19
|
+
}
|
|
20
|
+
values[index] = value;
|
|
21
|
+
}
|
|
22
|
+
return values;
|
|
23
|
+
}
|
|
24
|
+
function isFiniteNonNegative_(value) {
|
|
25
|
+
return Number.isFinite(value) && value >= 0;
|
|
26
|
+
}
|
|
27
|
+
function* layeredSteps_(nodes, links, traits, options) {
|
|
28
|
+
const { direction = "down", nodeSeparation = 50, rankSeparation = 50, edgeSeparation = 10, ranking = "networkSimplex", cycleRemoval = "depthFirst", orderingPatience, orderingEffort = "thorough", budget, } = options;
|
|
29
|
+
if (!DIRECTIONS_.includes(direction)) {
|
|
30
|
+
throw new RangeError(`layeredLayout: direction must be "down", "up", "right" or "left", got ${describeValue(direction)}`);
|
|
31
|
+
}
|
|
32
|
+
if (!RANKINGS_.includes(ranking)) {
|
|
33
|
+
throw new RangeError(`layeredLayout: ranking must be "networkSimplex" or "longestPath", got ${describeValue(ranking)}`);
|
|
34
|
+
}
|
|
35
|
+
if (!CYCLE_REMOVALS_.includes(cycleRemoval)) {
|
|
36
|
+
throw new RangeError(`layeredLayout: cycleRemoval must be "depthFirst" or "greedy", got ${describeValue(cycleRemoval)}`);
|
|
37
|
+
}
|
|
38
|
+
assertNonNegative(nodeSeparation, "layeredLayout: nodeSeparation");
|
|
39
|
+
assertNonNegative(rankSeparation, "layeredLayout: rankSeparation");
|
|
40
|
+
assertNonNegative(edgeSeparation, "layeredLayout: edgeSeparation");
|
|
41
|
+
if (orderingPatience !== undefined &&
|
|
42
|
+
!isIntegerInRange(orderingPatience, 0, 2 ** 32)) {
|
|
43
|
+
throw new RangeError(`layeredLayout: orderingPatience must be a non-negative integer, got ${describeValue(orderingPatience)}`);
|
|
44
|
+
}
|
|
45
|
+
if (orderingEffort !== "fast" && orderingEffort !== "thorough") {
|
|
46
|
+
throw new RangeError(`layeredLayout: orderingEffort must be "fast" or "thorough", got ${describeValue(orderingEffort)}`);
|
|
47
|
+
}
|
|
48
|
+
const nodeCount = nodes.length;
|
|
49
|
+
const graph = buildIndexGraph(nodeCount, links, traits, "layeredLayout");
|
|
50
|
+
const widths = readNumbers_(nodes, traits.widthOf, isFiniteNonNegative_, (index, value) => `layeredLayout: width of node ${index} must be finite and ≥ 0, got ${describeValue(value)}`);
|
|
51
|
+
const heights = readNumbers_(nodes, traits.heightOf, isFiniteNonNegative_, (index, value) => `layeredLayout: height of node ${index} must be finite and ≥ 0, got ${describeValue(value)}`);
|
|
52
|
+
const weights = readNumbers_(links, traits.weightOf, isFiniteNonNegative_, (index, value) => `layeredLayout: weight of link ${index} must be finite and ≥ 0, got ${describeValue(value)}`);
|
|
53
|
+
const minLengths = readNumbers_(links, traits.minLengthOf, (value) => isIntegerInRange(value, 1, 2 ** 32), (index, value) => `layeredLayout: minimum length of link ${index} must be a positive integer, got ${describeValue(value)}`);
|
|
54
|
+
yield;
|
|
55
|
+
const reversed = findReversedLinks(graph, cycleRemoval, weights);
|
|
56
|
+
yield;
|
|
57
|
+
const ranks = ranking === "longestPath"
|
|
58
|
+
? longestPathRanks(graph, reversed, minLengths)
|
|
59
|
+
: yield* networkSimplexRankSteps(graph, reversed, weights, minLengths, budget);
|
|
60
|
+
yield;
|
|
61
|
+
const order = yield* orderLayerSteps(graph, ranks, {
|
|
62
|
+
weights,
|
|
63
|
+
patience: orderingPatience,
|
|
64
|
+
effort: orderingEffort,
|
|
65
|
+
budget,
|
|
66
|
+
});
|
|
67
|
+
yield;
|
|
68
|
+
// Ranks run along y for "down" and "up", along x for the other two, so the
|
|
69
|
+
// rank-axis extent of a node is its height, or its width when turned.
|
|
70
|
+
const turned = direction === "right" || direction === "left";
|
|
71
|
+
const empty = new Float64Array(nodeCount);
|
|
72
|
+
const placed = placeLayers(graph, order, reversed, (turned ? heights : widths) ?? empty, (turned ? widths : heights) ?? empty, direction, { nodeSeparation, rankSeparation, edgeSeparation });
|
|
73
|
+
return {
|
|
74
|
+
positions: placed.positions,
|
|
75
|
+
ranks,
|
|
76
|
+
orders: order.orders.slice(0, nodeCount),
|
|
77
|
+
edgePoints: placed.edgePoints,
|
|
78
|
+
edgeStarts: placed.edgeStarts,
|
|
79
|
+
reversed,
|
|
80
|
+
width: placed.width,
|
|
81
|
+
height: placed.height,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Layered drawing of a directed graph (Sugiyama, Tagawa & Toda 1981): cycle
|
|
86
|
+
* removal, ranking, long links split by dummy vertices, crossing reduction by
|
|
87
|
+
* barycentric layer sweeps with exact bilayer crossing counts (Barth, Jünger &
|
|
88
|
+
* Mutzel 2004), coordinates by Brandes & Köpf 2001 (balanced median of four
|
|
89
|
+
* alignments). Disconnected parts share the ranks. Parallel links each get a
|
|
90
|
+
* path. Deterministic.
|
|
91
|
+
*
|
|
92
|
+
* The result is exactly the "down" layout turned: "up" flips the rank axis,
|
|
93
|
+
* "right" and "left" swap the axes (and flip, for "left") with the node sizes
|
|
94
|
+
* swapped, so widths always read along x and heights along y.
|
|
95
|
+
*
|
|
96
|
+
* Complexity: cycle removal O(V + E); ranking O(V + E) longest path, network
|
|
97
|
+
* simplex polynomial and near-linear in practice (cap with `budget`); with D
|
|
98
|
+
* dummy vertices, V′ = V + D and E′ = E + D: ordering O(sweeps · E′ log V′),
|
|
99
|
+
* coordinates O(V′ + E′). D grows with the rank span of the links, bounded by
|
|
100
|
+
* `minLengthOf`.
|
|
101
|
+
*
|
|
102
|
+
* @throws {RangeError} A link index outside `[0, nodes.length)` or not an
|
|
103
|
+
* integer, an invalid size, weight, minimum length or option, naming the
|
|
104
|
+
* row.
|
|
105
|
+
*/
|
|
106
|
+
export function layeredLayout(nodes, links, traits, options = {}) {
|
|
107
|
+
return runToCompletion(layeredSteps_(nodes, links, traits, options));
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* {@link layeredLayout} yielding to the event loop after cycle removal, after
|
|
111
|
+
* every network-simplex round and pivot, after every ordering sweep and
|
|
112
|
+
* transpose pass, and before the coordinates; the result equals the sync
|
|
113
|
+
* form's. Validation errors reject. Aborting rejects with `signal.reason` at
|
|
114
|
+
* the next of those points and discards the work. A single pivot or sweep of a
|
|
115
|
+
* very large graph can still overshoot `sliceMs`.
|
|
116
|
+
*/
|
|
117
|
+
export function layeredLayoutAsync(nodes, links, traits, options = {}) {
|
|
118
|
+
const { signal, sliceMs, ...layoutOptions } = options;
|
|
119
|
+
return runInTimeSlices(layeredSteps_(nodes, links, traits, layoutOptions), {
|
|
120
|
+
signal,
|
|
121
|
+
sliceMs,
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=layered-layout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"layered-layout.js","sourceRoot":"","sources":["../../src/layout/layered-layout.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,iBAAiB,EACjB,aAAa,EACb,gBAAgB,EAChB,eAAe,EACf,eAAe,GACf,MAAM,cAAc,CAAC;AAGtB,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAE1D,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AA+E/E,MAAM,WAAW,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;AACpD,MAAM,SAAS,GAAG,CAAC,gBAAgB,EAAE,aAAa,CAAC,CAAC;AACpD,MAAM,eAAe,GAAG,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;AAEjD,SAAS,YAAY,CACpB,KAAuB,EACvB,IAAgE,EAChE,OAAmC,EACnC,QAAkD;IAElD,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACxB,OAAO,SAAS,CAAC;IAClB,CAAC;IACD,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,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAE,EAAE,KAAK,CAAC,CAAC;QACzC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC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AC,SAAS;QAC3B,KAAK;QACL,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,SAAS,CAAC;QACxC,UAAU,EAAE,MAAM,CAAC,UAAU;QAC7B,UAAU,EAAE,MAAM,CAAC,UAAU;QAC7B,QAAQ;QACR,KAAK,EAAE,MAAM,CAAC,KAAK;QACnB,MAAM,EAAE,MAAM,CAAC,MAAM;KACrB,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,UAAU,aAAa,CAC5B,KAAuB,EACvB,KAAuB,EACvB,MAAmC,EACnC,OAAO,GAAyB,EAAE;IAElC,OAAO,eAAe,CAAC,aAAa,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;AACtE,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,kBAAkB,CACjC,KAAuB,EACvB,KAAuB,EACvB,MAAmC,EACnC,OAAO,GAA8C,EAAE;IAEvD,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,aAAa,EAAE,GAAG,OAAO,CAAC;IACtD,OAAO,eAAe,CAAC,aAAa,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE;QAC1E,MAAM;QACN,OAAO;KACP,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { HierarchyBoxLayout, HierarchyOrder, HierarchyWalkOptions, ValuedHierarchyTraits } from "./types.js";
|
|
2
|
+
export type PartitionLayoutOptions = HierarchyWalkOptions & {
|
|
3
|
+
/** Layout box; default 1 × 1. Breadth (value) along x, depth along y. */
|
|
4
|
+
readonly width?: number;
|
|
5
|
+
readonly height?: number;
|
|
6
|
+
/** Gap removed from each box's right and bottom edges. Default 0. */
|
|
7
|
+
readonly padding?: number;
|
|
8
|
+
/** Round box edges to integers (halves round up). Default false. */
|
|
9
|
+
readonly round?: boolean;
|
|
10
|
+
readonly order?: HierarchyOrder;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Adjacency layout: each row's box spans its value along x and one band of
|
|
14
|
+
* `height / (treeHeight + 1)` along y — what an icicle, a flame graph (flipped
|
|
15
|
+
* by the caller) and a sunburst (x as angle, y as radius) draw. A node's
|
|
16
|
+
* children share its x extent in proportion to their values (the slice-and-dice
|
|
17
|
+
* cut of Shneiderman's tree-maps applied to one band per depth, as in Kruskal &
|
|
18
|
+
* Landis's icicle plots).
|
|
19
|
+
*
|
|
20
|
+
* A zero-value child gets a zero-width box at its position; a box whose padding
|
|
21
|
+
* exceeds its extent collapses to its midpoint. The root box starts at
|
|
22
|
+
* `(padding, padding)`. Values and sizes are meant to lie within [1e−150,
|
|
23
|
+
* 1e150].
|
|
24
|
+
*
|
|
25
|
+
* Complexity: O(n), O(n log n) with `order: "valueDescending"`.
|
|
26
|
+
*
|
|
27
|
+
* @throws {RangeError} A negative or non-finite value, width, height or
|
|
28
|
+
* padding.
|
|
29
|
+
*/
|
|
30
|
+
export declare function partitionLayout<TNode>(root: TNode, traits: ValuedHierarchyTraits<TNode>, options?: PartitionLayoutOptions): HierarchyBoxLayout<TNode>;
|
|
31
|
+
//# sourceMappingURL=partition-layout.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"partition-layout.d.ts","sourceRoot":"","sources":["../../src/layout/partition-layout.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACX,kBAAkB,EAClB,cAAc,EACd,oBAAoB,EACpB,qBAAqB,EACrB,MAAM,YAAY,CAAC;AAEpB,MAAM,MAAM,sBAAsB,GAAG,oBAAoB,GAAG;IAC3D,yEAAyE;IACzE,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,qEAAqE;IACrE,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,oEAAoE;IACpE,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,KAAK,CAAC,EAAE,cAAc,CAAC;CAChC,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,eAAe,CAAC,KAAK,EACpC,IAAI,EAAE,KAAK,EACX,MAAM,EAAE,qBAAqB,CAAC,KAAK,CAAC,EACpC,OAAO,GAAE,sBAA2B,GAClC,kBAAkB,CAAC,KAAK,CAAC,CA0E3B"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { groupIndices } from "@ac-kit/algo";
|
|
2
|
+
import { assertNonNegative } from "@ac-kit/core";
|
|
3
|
+
import { buildValuedHierarchyTable } from "./_hierarchy-table.js";
|
|
4
|
+
import { tileDice } from "./_treemap-tiling.js";
|
|
5
|
+
/**
|
|
6
|
+
* Adjacency layout: each row's box spans its value along x and one band of
|
|
7
|
+
* `height / (treeHeight + 1)` along y — what an icicle, a flame graph (flipped
|
|
8
|
+
* by the caller) and a sunburst (x as angle, y as radius) draw. A node's
|
|
9
|
+
* children share its x extent in proportion to their values (the slice-and-dice
|
|
10
|
+
* cut of Shneiderman's tree-maps applied to one band per depth, as in Kruskal &
|
|
11
|
+
* Landis's icicle plots).
|
|
12
|
+
*
|
|
13
|
+
* A zero-value child gets a zero-width box at its position; a box whose padding
|
|
14
|
+
* exceeds its extent collapses to its midpoint. The root box starts at
|
|
15
|
+
* `(padding, padding)`. Values and sizes are meant to lie within [1e−150,
|
|
16
|
+
* 1e150].
|
|
17
|
+
*
|
|
18
|
+
* Complexity: O(n), O(n log n) with `order: "valueDescending"`.
|
|
19
|
+
*
|
|
20
|
+
* @throws {RangeError} A negative or non-finite value, width, height or
|
|
21
|
+
* padding.
|
|
22
|
+
*/
|
|
23
|
+
export function partitionLayout(root, traits, options = {}) {
|
|
24
|
+
const { width = 1, height = 1, padding = 0, round = false } = options;
|
|
25
|
+
assertNonNegative(width, "partitionLayout: width");
|
|
26
|
+
assertNonNegative(height, "partitionLayout: height");
|
|
27
|
+
assertNonNegative(padding, "partitionLayout: padding");
|
|
28
|
+
const table = buildValuedHierarchyTable(root, traits, { budget: options.budget, order: options.order }, "partitionLayout");
|
|
29
|
+
const { nodes, depths, values } = table;
|
|
30
|
+
const count = nodes.length;
|
|
31
|
+
const boxes = new Float64Array(count * 4);
|
|
32
|
+
let bandCount = 1;
|
|
33
|
+
for (let row = 0; row < count; row++) {
|
|
34
|
+
if (depths[row] + 1 > bandCount) {
|
|
35
|
+
bandCount = depths[row] + 1;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
const children = groupIndices(table.parentIndices, (parent) => parent, count);
|
|
39
|
+
const context = {
|
|
40
|
+
boxes,
|
|
41
|
+
values,
|
|
42
|
+
depths,
|
|
43
|
+
children,
|
|
44
|
+
aspectRatio: 1,
|
|
45
|
+
};
|
|
46
|
+
boxes[0] = padding;
|
|
47
|
+
boxes[1] = padding;
|
|
48
|
+
boxes[2] = width;
|
|
49
|
+
boxes[3] = height / bandCount;
|
|
50
|
+
for (let row = 0; row < count; row++) {
|
|
51
|
+
const offset = row * 4;
|
|
52
|
+
const depth = depths[row];
|
|
53
|
+
if (children.offsets[row + 1] > children.offsets[row]) {
|
|
54
|
+
tileDice(context, row, boxes[offset], (height * (depth + 1)) / bandCount, boxes[offset + 2], (height * (depth + 2)) / bandCount);
|
|
55
|
+
}
|
|
56
|
+
let x0 = boxes[offset];
|
|
57
|
+
let y0 = boxes[offset + 1];
|
|
58
|
+
let x1 = boxes[offset + 2] - padding;
|
|
59
|
+
let y1 = boxes[offset + 3] - padding;
|
|
60
|
+
if (x1 < x0) {
|
|
61
|
+
x0 = x1 = (x0 + x1) / 2;
|
|
62
|
+
}
|
|
63
|
+
if (y1 < y0) {
|
|
64
|
+
y0 = y1 = (y0 + y1) / 2;
|
|
65
|
+
}
|
|
66
|
+
boxes[offset] = x0;
|
|
67
|
+
boxes[offset + 1] = y0;
|
|
68
|
+
boxes[offset + 2] = x1;
|
|
69
|
+
boxes[offset + 3] = y1;
|
|
70
|
+
}
|
|
71
|
+
if (round) {
|
|
72
|
+
for (let index = 0; index < boxes.length; index++) {
|
|
73
|
+
boxes[index] = Math.round(boxes[index]);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return { ...table, boxes };
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=partition-layout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"partition-layout.js","sourceRoot":"","sources":["../../src/layout/partition-layout.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAEjD,OAAO,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AAClE,OAAO,EAAsB,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAmBpE;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,eAAe,CAC9B,IAAW,EACX,MAAoC,EACpC,OAAO,GAA2B,EAAE;IAEpC,MAAM,EAAE,KAAK,GAAG,CAAC,EAAE,MAAM,GAAG,CAAC,EAAE,OAAO,GAAG,CAAC,EAAE,KAAK,GAAG,KAAK,EAAE,GAAG,OAAO,CAAC;IACtE,iBAAiB,CAAC,KAAK,EAAE,wBAAwB,CAAC,CAAC;IACnD,iBAAiB,CAAC,MAAM,EAAE,yBAAyB,CAAC,CAAC;IACrD,iBAAiB,CAAC,OAAO,EAAE,0BAA0B,CAAC,CAAC;IAEvD,MAAM,KAAK,GAAG,yBAAyB,CACtC,IAAI,EACJ,MAAM,EACN,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,EAChD,iBAAiB,CACjB,CAAC;IACF,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,KAAK,CAAC;IACxC,MAAM,KAAK,GAAG,KAA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AE,CAAC;AAC5B,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type PhyllotaxisLayoutOptions = {
|
|
2
|
+
/** Radius scale: node i sits at `spacing · √(0.5 + i)`. Default 10, ≥ 0. */
|
|
3
|
+
readonly spacing?: number;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* Sunflower-seed placement (Vogel, "A better way to construct the sunflower
|
|
7
|
+
* head", Mathematical Biosciences 1979): node i at radius `spacing · √(0.5 +
|
|
8
|
+
* i)` and angle `i` golden angles, so nodes fill a disc about the origin with
|
|
9
|
+
* near-uniform density and never coincide. x, y per node.
|
|
10
|
+
*
|
|
11
|
+
* Complexity: O(n) time and memory.
|
|
12
|
+
*
|
|
13
|
+
* @throws {RangeError} `count` not a non-negative safe integer, or a negative
|
|
14
|
+
* or non-finite spacing.
|
|
15
|
+
*/
|
|
16
|
+
export declare function phyllotaxisLayout(count: number, options?: PhyllotaxisLayoutOptions): Float64Array;
|
|
17
|
+
//# sourceMappingURL=phyllotaxis-layout.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"phyllotaxis-layout.d.ts","sourceRoot":"","sources":["../../src/layout/phyllotaxis-layout.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,wBAAwB,GAAG;IACtC,4EAA4E;IAC5E,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEF;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAChC,KAAK,EAAE,MAAM,EACb,OAAO,GAAE,wBAA6B,GACpC,YAAY,CAgBd"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { 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 { GOLDEN_ANGLE } from "@ac-kit/math-scalar";
|
|
5
|
+
/**
|
|
6
|
+
* Sunflower-seed placement (Vogel, "A better way to construct the sunflower
|
|
7
|
+
* head", Mathematical Biosciences 1979): node i at radius `spacing · √(0.5 +
|
|
8
|
+
* i)` and angle `i` golden angles, so nodes fill a disc about the origin with
|
|
9
|
+
* near-uniform density and never coincide. x, y per node.
|
|
10
|
+
*
|
|
11
|
+
* Complexity: O(n) time and memory.
|
|
12
|
+
*
|
|
13
|
+
* @throws {RangeError} `count` not a non-negative safe integer, or a negative
|
|
14
|
+
* or non-finite spacing.
|
|
15
|
+
*/
|
|
16
|
+
export function phyllotaxisLayout(count, options = {}) {
|
|
17
|
+
const { spacing = 10 } = options;
|
|
18
|
+
assertInteger(count, "phyllotaxisLayout: count", 0);
|
|
19
|
+
assertNonNegative(spacing, "phyllotaxisLayout: spacing");
|
|
20
|
+
const positions = new Float64Array(count * 2);
|
|
21
|
+
const polar = polarCoordsCreate();
|
|
22
|
+
const point = vec2Create();
|
|
23
|
+
for (let index = 0; index < count; index++) {
|
|
24
|
+
polar[0] = spacing * Math.sqrt(0.5 + index);
|
|
25
|
+
polar[1] = index * GOLDEN_ANGLE;
|
|
26
|
+
vec2FromPolar(point, polar);
|
|
27
|
+
positions[index * 2] = point[0];
|
|
28
|
+
positions[index * 2 + 1] = point[1];
|
|
29
|
+
}
|
|
30
|
+
return positions;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=phyllotaxis-layout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"phyllotaxis-layout.js","sourceRoot":"","sources":["../../src/layout/phyllotaxis-layout.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAChE,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACzE,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAOnD;;;;;;;;;;GAUG;AACH,MAAM,UAAU,iBAAiB,CAChC,KAAa,EACb,OAAO,GAA6B,EAAE;IAEtC,MAAM,EAAE,OAAO,GAAG,EAAE,EAAE,GAAG,OAAO,CAAC;IACjC,aAAa,CAAC,KAAK,EAAE,0BAA0B,EAAE,CAAC,CAAC,CAAC;IACpD,iBAAiB,CAAC,OAAO,EAAE,4BAA4B,CAAC,CAAC;IAEzD,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,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC;QAC5C,KAAK,CAAC,CAAC,CAAC,GAAG,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,GAAG,KAAK,CAAC,CAAC;QAC5C,KAAK,CAAC,CAAC,CAAC,GAAG,KAAK,GAAG,YAAY,CAAC;QAChC,aAAa,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;QAC5B,SAAS,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QAChC,SAAS,CAAC,KAAK,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;IACrC,CAAC;IACD,OAAO,SAAS,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import type { Callable, WorkBudget } from "@ac-kit/core";
|
|
2
|
+
import type { AsyncLayoutOptions, NetworkTraits } from "./types.js";
|
|
3
|
+
export type SankeyTraits<TNode, TLink> = NetworkTraits<TNode, TLink> & {
|
|
4
|
+
/**
|
|
5
|
+
* Flow of a link; finite, ≥ 0. Required. Named `linkValueOf`, not `valueOf`,
|
|
6
|
+
* which every object inherits.
|
|
7
|
+
*/
|
|
8
|
+
readonly linkValueOf: Callable<[link: TLink, index: number], number>;
|
|
9
|
+
/**
|
|
10
|
+
* Fixed node value (d3-sankey's `fixedValue`); finite, ≥ 0 and at least max(Σ
|
|
11
|
+
* incoming, Σ outgoing), so the bands fit the node. `undefined`: max(Σ
|
|
12
|
+
* incoming, Σ outgoing). A value short of that flow by at most 1e-9 of it
|
|
13
|
+
* (rounding noise) is raised to the flow; a larger shortfall throws.
|
|
14
|
+
*/
|
|
15
|
+
readonly nodeValueOf?: Callable<[
|
|
16
|
+
node: TNode,
|
|
17
|
+
index: number
|
|
18
|
+
], number | undefined>;
|
|
19
|
+
};
|
|
20
|
+
export type SankeyLayoutOptions = {
|
|
21
|
+
/** The nodes and links fill `[0, width] × [0, height]`; finite, ≥ 0. */
|
|
22
|
+
readonly width: number;
|
|
23
|
+
readonly height: number;
|
|
24
|
+
/** Finite, ≥ 0, at most `width` (the nodes stay inside `[0, width]`). Default 24. */
|
|
25
|
+
readonly nodeWidth?: number;
|
|
26
|
+
/**
|
|
27
|
+
* Gap between nodes of a column, finite ≥ 0; shrunk when a column cannot fit.
|
|
28
|
+
* Default 8.
|
|
29
|
+
*/
|
|
30
|
+
readonly nodePadding?: number;
|
|
31
|
+
/**
|
|
32
|
+
* Column of each node, as d3-sankey's `sankeyJustify` (default: sinks in the
|
|
33
|
+
* last column), `sankeyLeft`, `sankeyRight` and `sankeyCenter`.
|
|
34
|
+
*/
|
|
35
|
+
readonly alignment?: "justify" | "left" | "right" | "center";
|
|
36
|
+
/**
|
|
37
|
+
* Vertical order in a column: `"relaxation"` (default: sorted by position
|
|
38
|
+
* after each relaxation step, as d3-sankey), `"input"` (node order, as
|
|
39
|
+
* `nodeSort(null)`), `"crossings"` (the barycentric sweeps of the layered
|
|
40
|
+
* layout, then kept fixed; the node order of the input is kept when it
|
|
41
|
+
* crosses no more, counting the links as straight lines between node slots).
|
|
42
|
+
*/
|
|
43
|
+
readonly ordering?: "relaxation" | "input" | "crossings";
|
|
44
|
+
/**
|
|
45
|
+
* Effort of the `"crossings"` ordering: `"thorough"` (default) adds sifting
|
|
46
|
+
* after the sweeps, `"fast"` stops after them (see `layeredLayout`'s
|
|
47
|
+
* `orderingEffort`).
|
|
48
|
+
*/
|
|
49
|
+
readonly orderingEffort?: "fast" | "thorough";
|
|
50
|
+
/**
|
|
51
|
+
* Link order at each node: `"breadth"` (default: by the other end's position)
|
|
52
|
+
* or `"input"`. As in d3-sankey, `"breadth"` first orders the incoming bands
|
|
53
|
+
* of each column by the position of their source, and leaves the outgoing
|
|
54
|
+
* bands in input order until a relaxation pass reorders them: with
|
|
55
|
+
* `iterations: 0` they stay in input order.
|
|
56
|
+
*/
|
|
57
|
+
readonly linkOrder?: "breadth" | "input";
|
|
58
|
+
/** Relaxation passes: an integer ≥ 0. Default 6. */
|
|
59
|
+
readonly iterations?: number;
|
|
60
|
+
/**
|
|
61
|
+
* Charged V + E per pass, and as `layeredLayout` charges its ordering for
|
|
62
|
+
* `"crossings"`.
|
|
63
|
+
*/
|
|
64
|
+
readonly budget?: WorkBudget;
|
|
65
|
+
};
|
|
66
|
+
export type SankeyLayout = {
|
|
67
|
+
/** 4 per node (`Box2` order). */
|
|
68
|
+
readonly nodeBoxes: Float64Array;
|
|
69
|
+
readonly nodeValues: Float64Array;
|
|
70
|
+
/** Column per node, 0 leftmost. */
|
|
71
|
+
readonly columns: Uint32Array;
|
|
72
|
+
/** Band thickness per link (value × scale). */
|
|
73
|
+
readonly linkWidths: Float64Array;
|
|
74
|
+
/**
|
|
75
|
+
* 4 per link: x0 (source box maxX), y0 (band centre at the source), x1
|
|
76
|
+
* (target box minX), y1.
|
|
77
|
+
*/
|
|
78
|
+
readonly linkEnds: Float64Array;
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* Flow diagram. Columns follow the longest path from the sources, then
|
|
82
|
+
* `alignment`; node heights are proportional to their value; the link bands are
|
|
83
|
+
* stacked at each node. The vertical positions follow the iterative relaxation
|
|
84
|
+
* that Mike Bostock's d3-sankey 0.12 applies to the layered flow diagrams of
|
|
85
|
+
* Riehmann, Hanfler and Froehlich ("Interactive Sankey Diagrams", IEEE InfoVis
|
|
86
|
+
* 2005), implemented here from that description: `iterations` passes, each
|
|
87
|
+
* moving every node, column by column from the right then from the left, to the
|
|
88
|
+
* position that would level its links (weighted by value × columns spanned,
|
|
89
|
+
* strength 0.99^pass), reordering the bands by the position of their other end,
|
|
90
|
+
* then pushing overlapping nodes apart. Isolated nodes get value 0, and the
|
|
91
|
+
* last column under `"justify"`. Where d3-sankey yields NaN, a single column
|
|
92
|
+
* starts at x = 0 and a column of zero-valued nodes takes no height. Collisions
|
|
93
|
+
* are resolved down to 1e-6 × min(1, height), so two nodes of a column may
|
|
94
|
+
* overlap by that much (d3-sankey's own cutoff for heights ≥ 1).
|
|
95
|
+
*
|
|
96
|
+
* Complexity: O(V + E) columns; each pass O(V log V + E log E + Σ d²) for the
|
|
97
|
+
* node degrees d; `"crossings"` adds the cost of the layered ordering and of
|
|
98
|
+
* comparing it with the input order, O(Σ span · log E) over the links.
|
|
99
|
+
*
|
|
100
|
+
* @throws {RangeError} A cycle or a self-loop (naming a link on it: a circular
|
|
101
|
+
* flow is not supported), a link end that is not a node index, a negative,
|
|
102
|
+
* non-finite or over-1e150 link or node value (so no sum overflows), a node
|
|
103
|
+
* value below its flow, a `nodeWidth` larger than `width`, an option out of
|
|
104
|
+
* range.
|
|
105
|
+
*/
|
|
106
|
+
export declare function sankeyLayout<TNode, TLink>(nodes: readonly TNode[], links: readonly TLink[], traits: SankeyTraits<TNode, TLink>, options: SankeyLayoutOptions): SankeyLayout;
|
|
107
|
+
/**
|
|
108
|
+
* {@link sankeyLayout} in time slices: yields to the event loop every `sliceMs`
|
|
109
|
+
* (after the columns, after each relaxation pass), and rejects with
|
|
110
|
+
* `signal.reason` once aborted. The result equals the sync form's.
|
|
111
|
+
*/
|
|
112
|
+
export declare function sankeyLayoutAsync<TNode, TLink>(nodes: readonly TNode[], links: readonly TLink[], traits: SankeyTraits<TNode, TLink>, options: SankeyLayoutOptions & AsyncLayoutOptions): Promise<SankeyLayout>;
|
|
113
|
+
//# sourceMappingURL=sankey-layout.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sankey-layout.d.ts","sourceRoot":"","sources":["../../src/layout/sankey-layout.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAMzD,OAAO,KAAK,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEpE,MAAM,MAAM,YAAY,CAAC,KAAK,EAAE,KAAK,IAAI,aAAa,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG;IACtE;;;OAGG;IACH,QAAQ,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC;IACrE;;;;;OAKG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,QAAQ,CAC9B;QAAC,IAAI,EAAE,KAAK;QAAE,KAAK,EAAE,MAAM;KAAC,EAC5B,MAAM,GAAG,SAAS,CAClB,CAAC;CACF,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IACjC,wEAAwE;IACxE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,qFAAqF;IACrF,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B;;;OAGG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B;;;OAGG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,SAAS,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,CAAC;IAC7D;;;;;;OAMG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,YAAY,GAAG,OAAO,GAAG,WAAW,CAAC;IAC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