@antv/layout 1.2.13 → 1.2.14-beta.1
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/dist/85db61ddc757dae66e04.worker.js +2 -0
- package/dist/85db61ddc757dae66e04.worker.js.map +1 -0
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/lib/{dagre → antv-dagre}/acyclic.d.ts +1 -1
- package/lib/antv-dagre/acyclic.js +61 -0
- package/lib/antv-dagre/acyclic.js.map +1 -0
- package/lib/{dagre → antv-dagre}/add-border-segments.js +12 -12
- package/lib/antv-dagre/add-border-segments.js.map +1 -0
- package/lib/{dagre → antv-dagre}/coordinate-system.d.ts +2 -1
- package/lib/antv-dagre/coordinate-system.js +65 -0
- package/lib/antv-dagre/coordinate-system.js.map +1 -0
- package/lib/{dagre → antv-dagre}/data/list.d.ts +1 -1
- package/lib/{dagre → antv-dagre}/data/list.js +20 -22
- package/lib/antv-dagre/data/list.js.map +1 -0
- package/lib/{dagre → antv-dagre}/greedy-fas.d.ts +2 -2
- package/lib/antv-dagre/greedy-fas.js +136 -0
- package/lib/antv-dagre/greedy-fas.js.map +1 -0
- package/lib/{dagre → antv-dagre}/layout.d.ts +2 -1
- package/lib/{dagre → antv-dagre}/layout.js +125 -127
- package/lib/antv-dagre/layout.js.map +1 -0
- package/lib/{dagre → antv-dagre}/nesting-graph.js +36 -37
- package/lib/antv-dagre/nesting-graph.js.map +1 -0
- package/lib/{dagre → antv-dagre}/normalize.d.ts +2 -2
- package/lib/{dagre → antv-dagre}/normalize.js +24 -24
- package/lib/antv-dagre/normalize.js.map +1 -0
- package/lib/{dagre → antv-dagre}/order/add-subgraph-constraints.js +9 -9
- package/lib/antv-dagre/order/add-subgraph-constraints.js.map +1 -0
- package/lib/{dagre → antv-dagre}/order/barycenter.d.ts +2 -2
- package/lib/{dagre → antv-dagre}/order/barycenter.js +8 -8
- package/lib/antv-dagre/order/barycenter.js.map +1 -0
- package/lib/{dagre → antv-dagre}/order/build-layer-graph.js +18 -22
- package/lib/antv-dagre/order/build-layer-graph.js.map +1 -0
- package/lib/antv-dagre/order/cross-count.d.ts +3 -0
- package/lib/{dagre → antv-dagre}/order/cross-count.js +17 -17
- package/lib/antv-dagre/order/cross-count.js.map +1 -0
- package/lib/{dagre → antv-dagre}/order/index.d.ts +1 -1
- package/lib/{dagre → antv-dagre}/order/index.js +35 -35
- package/lib/antv-dagre/order/index.js.map +1 -0
- package/lib/{dagre → antv-dagre}/order/init-data-order.js +8 -9
- package/lib/antv-dagre/order/init-data-order.js.map +1 -0
- package/lib/antv-dagre/order/init-order.js +47 -0
- package/lib/antv-dagre/order/init-order.js.map +1 -0
- package/lib/{dagre → antv-dagre}/order/resolve-conflicts.d.ts +3 -3
- package/lib/{dagre → antv-dagre}/order/resolve-conflicts.js +32 -35
- package/lib/antv-dagre/order/resolve-conflicts.js.map +1 -0
- package/lib/{dagre → antv-dagre}/order/sort-subgraph.js +20 -20
- package/lib/antv-dagre/order/sort-subgraph.js.map +1 -0
- package/lib/{dagre → antv-dagre}/order/sort.d.ts +2 -2
- package/lib/{dagre → antv-dagre}/order/sort.js +19 -19
- package/lib/antv-dagre/order/sort.js.map +1 -0
- package/lib/{dagre → antv-dagre}/parent-dummy-chains.js +28 -28
- package/lib/antv-dagre/parent-dummy-chains.js.map +1 -0
- package/lib/{dagre → antv-dagre}/position/bk.d.ts +5 -4
- package/lib/{dagre → antv-dagre}/position/bk.js +140 -143
- package/lib/antv-dagre/position/bk.js.map +1 -0
- package/lib/{dagre → antv-dagre}/position/index.d.ts +2 -1
- package/lib/antv-dagre/position/index.js +51 -0
- package/lib/antv-dagre/position/index.js.map +1 -0
- package/lib/{dagre → antv-dagre}/rank/feasible-tree.d.ts +2 -2
- package/lib/{dagre → antv-dagre}/rank/feasible-tree.js +32 -32
- package/lib/antv-dagre/rank/feasible-tree.js.map +1 -0
- package/lib/antv-dagre/rank/index.d.ts +2 -0
- package/lib/{dagre → antv-dagre}/rank/index.js +10 -10
- package/lib/antv-dagre/rank/index.js.map +1 -0
- package/lib/{dagre → antv-dagre}/rank/network-simplex.d.ts +2 -2
- package/lib/{dagre → antv-dagre}/rank/network-simplex.js +70 -71
- package/lib/antv-dagre/rank/network-simplex.js.map +1 -0
- package/lib/{dagre → antv-dagre}/rank/util.d.ts +2 -2
- package/lib/{dagre → antv-dagre}/rank/util.js +31 -31
- package/lib/antv-dagre/rank/util.js.map +1 -0
- package/lib/antv-dagre/types.d.ts +2 -0
- package/lib/antv-dagre/types.js +2 -0
- package/lib/antv-dagre/types.js.map +1 -0
- package/lib/{dagre → antv-dagre}/util.d.ts +1 -1
- package/lib/{dagre → antv-dagre}/util.js +90 -98
- package/lib/antv-dagre/util.js.map +1 -0
- package/lib/antv-dagre.d.ts +50 -0
- package/lib/antv-dagre.js +538 -0
- package/lib/antv-dagre.js.map +1 -0
- package/lib/bundle-entry.d.ts +2 -18
- package/lib/bundle-entry.js +2 -18
- package/lib/bundle-entry.js.map +1 -1
- package/lib/bundle-supervisor.d.ts +4 -22
- package/lib/bundle-supervisor.js +54 -53
- package/lib/bundle-supervisor.js.map +1 -1
- package/lib/bundle-worker.d.ts +1 -1
- package/lib/bundle-worker.js +31 -33
- package/lib/bundle-worker.js.map +1 -1
- package/lib/circular.d.ts +1 -1
- package/lib/circular.js +124 -140
- package/lib/circular.js.map +1 -1
- package/lib/comboCombined.d.ts +1 -1
- package/lib/comboCombined.js +254 -284
- package/lib/comboCombined.js.map +1 -1
- package/lib/concentric.d.ts +1 -1
- package/lib/concentric.js +166 -176
- package/lib/concentric.js.map +1 -1
- package/lib/d3Force/forceInBox.js +75 -77
- package/lib/d3Force/forceInBox.js.map +1 -1
- package/lib/d3Force/index.d.ts +2 -2
- package/lib/d3Force/index.js +196 -222
- package/lib/d3Force/index.js.map +1 -1
- package/lib/dagre.d.ts +13 -24
- package/lib/dagre.js +57 -542
- package/lib/dagre.js.map +1 -1
- package/lib/exports.d.ts +17 -0
- package/lib/exports.js +17 -0
- package/lib/exports.js.map +1 -0
- package/lib/force/forceNBody.js +42 -45
- package/lib/force/forceNBody.js.map +1 -1
- package/lib/force/index.d.ts +1 -1
- package/lib/force/index.js +282 -309
- package/lib/force/index.js.map +1 -1
- package/lib/force/types.d.ts +5 -5
- package/lib/forceAtlas2/body.d.ts +1 -1
- package/lib/forceAtlas2/body.js +29 -31
- package/lib/forceAtlas2/body.js.map +1 -1
- package/lib/forceAtlas2/index.d.ts +1 -1
- package/lib/forceAtlas2/index.js +206 -218
- package/lib/forceAtlas2/index.js.map +1 -1
- package/lib/forceAtlas2/quad.d.ts +2 -2
- package/lib/forceAtlas2/quad.js +40 -42
- package/lib/forceAtlas2/quad.js.map +1 -1
- package/lib/forceAtlas2/quadTree.js +16 -17
- package/lib/forceAtlas2/quadTree.js.map +1 -1
- package/lib/fruchterman.d.ts +1 -1
- package/lib/fruchterman.js +185 -205
- package/lib/fruchterman.js.map +1 -1
- package/lib/grid.d.ts +1 -1
- package/lib/grid.js +197 -207
- package/lib/grid.js.map +1 -1
- package/lib/index.d.ts +1 -15
- package/lib/index.js +1 -15
- package/lib/index.js.map +1 -1
- package/lib/mds.d.ts +1 -1
- package/lib/mds.js +68 -78
- package/lib/mds.js.map +1 -1
- package/lib/radial/index.d.ts +1 -1
- package/lib/radial/index.js +177 -184
- package/lib/radial/index.js.map +1 -1
- package/lib/radial/mds.d.ts +1 -1
- package/lib/radial/mds.js +15 -13
- package/lib/radial/mds.js.map +1 -1
- package/lib/radial/radial-nonoverlap-force.d.ts +2 -2
- package/lib/radial/radial-nonoverlap-force.js +36 -37
- package/lib/radial/radial-nonoverlap-force.js.map +1 -1
- package/lib/random.d.ts +1 -1
- package/lib/random.js +53 -66
- package/lib/random.js.map +1 -1
- package/lib/registry.d.ts +2 -2
- package/lib/registry.js +3 -1
- package/lib/registry.js.map +1 -1
- package/lib/supervisor.d.ts +2 -3
- package/lib/supervisor.js +57 -56
- package/lib/supervisor.js.map +1 -1
- package/lib/types.d.ts +20 -75
- package/lib/types.js.map +1 -1
- package/lib/util/array.js +1 -1
- package/lib/util/array.js.map +1 -1
- package/lib/util/common.d.ts +1 -1
- package/lib/util/common.js +7 -8
- package/lib/util/common.js.map +1 -1
- package/lib/util/function.js +23 -25
- package/lib/util/function.js.map +1 -1
- package/lib/util/index.d.ts +0 -2
- package/lib/util/index.js +0 -2
- package/lib/util/index.js.map +1 -1
- package/lib/util/math.d.ts +1 -26
- package/lib/util/math.js +41 -149
- package/lib/util/math.js.map +1 -1
- package/lib/util/object.d.ts +1 -1
- package/lib/util/object.js +13 -13
- package/lib/util/object.js.map +1 -1
- package/lib/util/size.d.ts +3 -0
- package/lib/util/size.js +12 -0
- package/lib/util/size.js.map +1 -0
- package/lib/worker.js +30 -31
- package/lib/worker.js.map +1 -1
- package/package.json +9 -5
- package/dist/aa1bb0ccc06b11cf79c1.worker.js +0 -2
- package/dist/aa1bb0ccc06b11cf79c1.worker.js.map +0 -1
- package/lib/dagre/acyclic.js +0 -62
- package/lib/dagre/acyclic.js.map +0 -1
- package/lib/dagre/add-border-segments.js.map +0 -1
- package/lib/dagre/coordinate-system.js +0 -65
- package/lib/dagre/coordinate-system.js.map +0 -1
- package/lib/dagre/data/list.js.map +0 -1
- package/lib/dagre/greedy-fas.js +0 -147
- package/lib/dagre/greedy-fas.js.map +0 -1
- package/lib/dagre/layout.js.map +0 -1
- package/lib/dagre/nesting-graph.js.map +0 -1
- package/lib/dagre/normalize.js.map +0 -1
- package/lib/dagre/order/add-subgraph-constraints.js.map +0 -1
- package/lib/dagre/order/barycenter.js.map +0 -1
- package/lib/dagre/order/build-layer-graph.js.map +0 -1
- package/lib/dagre/order/cross-count.d.ts +0 -3
- package/lib/dagre/order/cross-count.js.map +0 -1
- package/lib/dagre/order/index.js.map +0 -1
- package/lib/dagre/order/init-data-order.js.map +0 -1
- package/lib/dagre/order/init-order.js +0 -50
- package/lib/dagre/order/init-order.js.map +0 -1
- package/lib/dagre/order/resolve-conflicts.js.map +0 -1
- package/lib/dagre/order/sort-subgraph.js.map +0 -1
- package/lib/dagre/order/sort.js.map +0 -1
- package/lib/dagre/parent-dummy-chains.js.map +0 -1
- package/lib/dagre/position/bk.js.map +0 -1
- package/lib/dagre/position/index.js +0 -54
- package/lib/dagre/position/index.js.map +0 -1
- package/lib/dagre/rank/feasible-tree.js.map +0 -1
- package/lib/dagre/rank/index.d.ts +0 -2
- package/lib/dagre/rank/index.js.map +0 -1
- package/lib/dagre/rank/network-simplex.js.map +0 -1
- package/lib/dagre/rank/util.js.map +0 -1
- package/lib/dagre/util.js.map +0 -1
- package/lib/util/gpu.d.ts +0 -45
- package/lib/util/gpu.js +0 -214
- package/lib/util/gpu.js.map +0 -1
- package/lib/util/number.d.ts +0 -1
- package/lib/util/number.js +0 -5
- package/lib/util/number.js.map +0 -1
- package/lib/util/string.d.ts +0 -1
- package/lib/util/string.js +0 -15
- package/lib/util/string.js.map +0 -1
- /package/lib/{dagre → antv-dagre}/add-border-segments.d.ts +0 -0
- /package/lib/{dagre → antv-dagre}/nesting-graph.d.ts +0 -0
- /package/lib/{dagre → antv-dagre}/order/add-subgraph-constraints.d.ts +0 -0
- /package/lib/{dagre → antv-dagre}/order/build-layer-graph.d.ts +0 -0
- /package/lib/{dagre → antv-dagre}/order/init-data-order.d.ts +0 -0
- /package/lib/{dagre → antv-dagre}/order/init-order.d.ts +0 -0
- /package/lib/{dagre → antv-dagre}/order/sort-subgraph.d.ts +0 -0
- /package/lib/{dagre → antv-dagre}/parent-dummy-chains.d.ts +0 -0
package/lib/bundle-supervisor.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { __awaiter,
|
|
2
|
-
|
|
3
|
-
import EventEmitter from "@antv/event-emitter";
|
|
1
|
+
import { __awaiter, __rest } from "tslib";
|
|
2
|
+
import EventEmitter from '@antv/event-emitter';
|
|
4
3
|
// @ts-ignore
|
|
5
4
|
// Inline the worker as a Blob. @see https://github.com/developit/workerize-loader#inline
|
|
6
|
-
import worker from
|
|
5
|
+
import worker from 'workerize-loader?inline!./bundle-worker';
|
|
7
6
|
/**
|
|
8
7
|
* @example
|
|
9
8
|
* const graph = new Graph();
|
|
@@ -14,17 +13,15 @@ import worker from "workerize-loader?inline!./bundle-worker";
|
|
|
14
13
|
* supervisor.stop();
|
|
15
14
|
* supervisor.kill();
|
|
16
15
|
*/
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
_this.spawnWorker();
|
|
25
|
-
return _this;
|
|
16
|
+
export class Supervisor extends EventEmitter {
|
|
17
|
+
constructor(graph, layout, options) {
|
|
18
|
+
super();
|
|
19
|
+
this.graph = graph;
|
|
20
|
+
this.layout = layout;
|
|
21
|
+
this.options = options;
|
|
22
|
+
this.spawnWorker();
|
|
26
23
|
}
|
|
27
|
-
|
|
24
|
+
spawnWorker() {
|
|
28
25
|
if (this.worker) {
|
|
29
26
|
this.worker.terminate();
|
|
30
27
|
}
|
|
@@ -40,55 +37,59 @@ var Supervisor = /** @class */ (function (_super) {
|
|
|
40
37
|
this.running = false;
|
|
41
38
|
this.execute();
|
|
42
39
|
}
|
|
43
|
-
}
|
|
44
|
-
|
|
40
|
+
}
|
|
41
|
+
execute() {
|
|
45
42
|
var _a;
|
|
46
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
43
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
44
|
+
if (this.running)
|
|
45
|
+
return this;
|
|
46
|
+
this.running = true;
|
|
47
|
+
// Payload should include nodes & edges(if needed).
|
|
48
|
+
const _b = this.layout.options, { onTick } = _b, rest = __rest(_b, ["onTick"]);
|
|
49
|
+
const payload = {
|
|
50
|
+
layout: {
|
|
51
|
+
id: this.layout.id,
|
|
52
|
+
options: rest,
|
|
53
|
+
iterations: (_a = this.options) === null || _a === void 0 ? void 0 : _a.iterations,
|
|
54
|
+
},
|
|
55
|
+
nodes: this.graph.getAllNodes(),
|
|
56
|
+
edges: this.graph.getAllEdges(),
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* TODO: Convert graph object to linear memory(e.g. csr, adjacency matrix), then transfer the ownership to worker.
|
|
60
|
+
* @example
|
|
61
|
+
* const arraybufferWithNodesEdges = graphToByteArrays(this.graph); // Float32Array
|
|
62
|
+
*/
|
|
63
|
+
const arraybufferWithNodesEdges = new Float32Array([0]);
|
|
64
|
+
// TODO: Support transferables.
|
|
65
|
+
// @see https://www.npmjs.com/package/@naoak/workerize-transferable
|
|
66
|
+
// setupTransferableMethodsOnMain(this.worker, {
|
|
67
|
+
// calculateLayout: {
|
|
68
|
+
// // pick a transferable object from the method parameters
|
|
69
|
+
// pickTransferablesFromParams: (params) => [params[1].buffer],
|
|
70
|
+
// },
|
|
71
|
+
// });
|
|
72
|
+
const [positions] = yield this.worker.calculateLayout(payload, [
|
|
73
|
+
arraybufferWithNodesEdges,
|
|
74
|
+
]);
|
|
75
|
+
return positions;
|
|
73
76
|
});
|
|
74
|
-
}
|
|
75
|
-
|
|
77
|
+
}
|
|
78
|
+
stop() {
|
|
76
79
|
this.running = false;
|
|
77
80
|
// trigger `layout.stop()` if needed
|
|
78
81
|
this.worker.stopLayout();
|
|
79
82
|
return this;
|
|
80
|
-
}
|
|
81
|
-
|
|
83
|
+
}
|
|
84
|
+
kill() {
|
|
82
85
|
if (this.worker) {
|
|
83
86
|
this.worker.terminate();
|
|
84
87
|
}
|
|
85
88
|
// TODO: unbind listeners on graph.
|
|
86
89
|
// TODO: release attached memory
|
|
87
|
-
}
|
|
88
|
-
|
|
90
|
+
}
|
|
91
|
+
isRunning() {
|
|
89
92
|
return this.running;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
}(EventEmitter));
|
|
93
|
-
export { Supervisor };
|
|
93
|
+
}
|
|
94
|
+
}
|
|
94
95
|
//# sourceMappingURL=bundle-supervisor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bundle-supervisor.js","sourceRoot":"","sources":["../src/bundle-supervisor.ts"],"names":[],"mappings":";AAAA,
|
|
1
|
+
{"version":3,"file":"bundle-supervisor.js","sourceRoot":"","sources":["../src/bundle-supervisor.ts"],"names":[],"mappings":";AAAA,OAAO,YAAY,MAAM,qBAAqB,CAAC;AAG/C,aAAa;AACb,yFAAyF;AACzF,OAAO,MAAM,MAAM,yCAAyC,CAAC;AAG7D;;;;;;;;;GASG;AACH,MAAM,OAAO,UAAW,SAAQ,YAAY;IAW1C,YACU,KAAsB,EACtB,MAAmB,EACnB,OAAoC;QAE5C,KAAK,EAAE,CAAC;QAJA,UAAK,GAAL,KAAK,CAAiB;QACtB,WAAM,GAAN,MAAM,CAAa;QACnB,YAAO,GAAP,OAAO,CAA6B;QAI5C,IAAI,CAAC,WAAW,EAAE,CAAC;IACrB,CAAC;IAED,WAAW;QACT,IAAI,IAAI,CAAC,MAAM,EAAE;YACf,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC;SACzB;QAED;;WAEG;QACH,yDAAyD;QACzD,qEAAqE;QAErE,4CAA4C;QAC5C,qDAAqD;QACrD,IAAI,CAAC,MAAM,GAAG,MAAM,EAAE,CAAC;QAEvB,IAAI,IAAI,CAAC,OAAO,EAAE;YAChB,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;YACrB,IAAI,CAAC,OAAO,EAAE,CAAC;SAChB;IACH,CAAC;IAEK,OAAO;;;YACX,IAAI,IAAI,CAAC,OAAO;gBAAE,OAAO,IAAI,CAAC;YAE9B,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;YAEpB,mDAAmD;YACnD,MAAM,KAAsB,IAAI,CAAC,MAAM,CAAC,OAAO,EAAzC,EAAE,MAAM,OAAiC,EAA5B,IAAI,cAAjB,UAAmB,CAAsB,CAAC;YAChD,MAAM,OAAO,GAAG;gBACd,MAAM,EAAE;oBACN,EAAE,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE;oBAClB,OAAO,EAAE,IAAI;oBACb,UAAU,EAAE,MAAA,IAAI,CAAC,OAAO,0CAAE,UAAU;iBACrC;gBACD,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE;gBAC/B,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE;aAChC,CAAC;YAEF;;;;eAIG;YACH,MAAM,yBAAyB,GAAG,IAAI,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YAExD,+BAA+B;YAC/B,mEAAmE;YACnE,gDAAgD;YAChD,uBAAuB;YACvB,+DAA+D;YAC/D,mEAAmE;YACnE,OAAO;YACP,MAAM;YAEN,MAAM,CAAC,SAAS,CAAC,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,OAAO,EAAE;gBAC7D,yBAAyB;aAC1B,CAAC,CAAC;YAEH,OAAO,SAAS,CAAC;;KAClB;IAED,IAAI;QACF,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;QAErB,oCAAoC;QACpC,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;QAEzB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI;QACF,IAAI,IAAI,CAAC,MAAM,EAAE;YACf,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC;SACzB;QAED,mCAAmC;QAEnC,gCAAgC;IAClC,CAAC;IAED,SAAS;QACP,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;CACF"}
|
package/lib/bundle-worker.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { Payload } from
|
|
1
|
+
import type { Payload } from './supervisor';
|
|
2
2
|
export declare function stopLayout(): void;
|
|
3
3
|
export declare function calculateLayout(payload: Payload, transferables: Float32Array[]): Promise<(import("./types").LayoutMapping | Float32Array[])[]>;
|
package/lib/bundle-worker.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { __awaiter
|
|
2
|
-
import { Graph } from
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
2
|
+
import { Graph } from '@antv/graphlib';
|
|
3
3
|
// import { setupTransferableMethodsOnWorker } from "@naoak/workerize-transferable";
|
|
4
|
-
import { registry } from
|
|
5
|
-
import { isLayoutWithIterations } from
|
|
4
|
+
import { registry } from './registry';
|
|
5
|
+
import { isLayoutWithIterations } from './types';
|
|
6
6
|
// @see https://www.npmjs.com/package/@naoak/workerize-transferable
|
|
7
7
|
// setupTransferableMethodsOnWorker({
|
|
8
8
|
// // The name of function which use some transferables.
|
|
@@ -13,41 +13,39 @@ import { isLayoutWithIterations } from "./types";
|
|
|
13
13
|
// pickTransferablesFromResult: (result) => [result[1].buffer],
|
|
14
14
|
// },
|
|
15
15
|
// });
|
|
16
|
-
|
|
16
|
+
let currentLayout;
|
|
17
17
|
export function stopLayout() {
|
|
18
|
-
|
|
19
|
-
if ((_a = currentLayout) === null || _a === void 0 ? void 0 : _a.stop) {
|
|
18
|
+
if (currentLayout === null || currentLayout === void 0 ? void 0 : currentLayout.stop) {
|
|
20
19
|
currentLayout.stop();
|
|
21
20
|
}
|
|
22
21
|
}
|
|
23
22
|
export function calculateLayout(payload, transferables) {
|
|
24
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
});
|
|
34
|
-
layoutCtor = registry[id];
|
|
35
|
-
if (layoutCtor) {
|
|
36
|
-
currentLayout = new layoutCtor(options);
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
throw new Error("Unknown layout id: " + id);
|
|
40
|
-
}
|
|
41
|
-
return [4 /*yield*/, currentLayout.execute(graph)];
|
|
42
|
-
case 1:
|
|
43
|
-
positions = _b.sent();
|
|
44
|
-
if (isLayoutWithIterations(currentLayout)) {
|
|
45
|
-
currentLayout.stop();
|
|
46
|
-
positions = currentLayout.tick(iterations);
|
|
47
|
-
}
|
|
48
|
-
return [2 /*return*/, [positions, transferables]];
|
|
49
|
-
}
|
|
23
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
const { layout: { id, options, iterations }, nodes, edges, } = payload;
|
|
25
|
+
// Sync graph on the worker side.
|
|
26
|
+
// TODO: Use transferable objects like ArrayBuffer for nodes & edges,
|
|
27
|
+
// in which case we don't need the whole graph.
|
|
28
|
+
// @see https://github.com/graphology/graphology/blob/master/src/layout-noverlap/webworker.tpl.js#L32
|
|
29
|
+
const graph = new Graph({
|
|
30
|
+
nodes,
|
|
31
|
+
edges,
|
|
50
32
|
});
|
|
33
|
+
/**
|
|
34
|
+
* Create layout instance on the worker side.
|
|
35
|
+
*/
|
|
36
|
+
const layoutCtor = registry[id];
|
|
37
|
+
if (layoutCtor) {
|
|
38
|
+
currentLayout = new layoutCtor(options);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
throw new Error(`Unknown layout id: ${id}`);
|
|
42
|
+
}
|
|
43
|
+
let positions = yield currentLayout.execute(graph);
|
|
44
|
+
if (isLayoutWithIterations(currentLayout)) {
|
|
45
|
+
currentLayout.stop();
|
|
46
|
+
positions = currentLayout.tick(iterations);
|
|
47
|
+
}
|
|
48
|
+
return [positions, transferables];
|
|
51
49
|
});
|
|
52
50
|
}
|
|
53
51
|
//# sourceMappingURL=bundle-worker.js.map
|
package/lib/bundle-worker.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bundle-worker.js","sourceRoot":"","sources":["../src/bundle-worker.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACvC,oFAAoF;AACpF,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,OAAO,
|
|
1
|
+
{"version":3,"file":"bundle-worker.js","sourceRoot":"","sources":["../src/bundle-worker.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACvC,oFAAoF;AACpF,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,OAAO,EAAE,sBAAsB,EAAgC,MAAM,SAAS,CAAC;AAE/E,mEAAmE;AACnE,qCAAqC;AACrC,0DAA0D;AAC1D,uBAAuB;AACvB,6CAA6C;AAC7C,2BAA2B;AAC3B,yFAAyF;AACzF,mEAAmE;AACnE,OAAO;AACP,MAAM;AAEN,IAAI,aAA0B,CAAC;AAE/B,MAAM,UAAU,UAAU;IACxB,IAAK,aAA2C,aAA3C,aAAa,uBAAb,aAAa,CAAgC,IAAI,EAAE;QACrD,aAA2C,CAAC,IAAI,EAAE,CAAC;KACrD;AACH,CAAC;AAED,MAAM,UAAgB,eAAe,CACnC,OAAgB,EAChB,aAA6B;;QAE7B,MAAM,EACJ,MAAM,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,EACnC,KAAK,EACL,KAAK,GACN,GAAG,OAAO,CAAC;QAEZ,iCAAiC;QACjC,qEAAqE;QACrE,+CAA+C;QAC/C,qGAAqG;QACrG,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC;YACtB,KAAK;YACL,KAAK;SACN,CAAC,CAAC;QAEH;;WAEG;QAEH,MAAM,UAAU,GAAG,QAAQ,CAAC,EAAE,CAAC,CAAC;QAChC,IAAI,UAAU,EAAE;YACd,aAAa,GAAG,IAAI,UAAU,CAAC,OAAO,CAAC,CAAC;SACzC;aAAM;YACL,MAAM,IAAI,KAAK,CAAC,sBAAsB,EAAE,EAAE,CAAC,CAAC;SAC7C;QAED,IAAI,SAAS,GAAG,MAAM,aAAa,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QACnD,IAAI,sBAAsB,CAAC,aAAa,CAAC,EAAE;YACzC,aAAa,CAAC,IAAI,EAAE,CAAC;YACrB,SAAS,GAAG,aAAa,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;SAC5C;QACD,OAAO,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC;IACpC,CAAC;CAAA"}
|
package/lib/circular.d.ts
CHANGED
package/lib/circular.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
2
|
+
import { cloneFormatData, formatNumberFn, formatSizeFn } from './util';
|
|
3
3
|
import { handleSingleNodeGraph } from './util/common';
|
|
4
|
-
|
|
4
|
+
const DEFAULTS_LAYOUT_OPTIONS = {
|
|
5
5
|
radius: null,
|
|
6
6
|
startRadius: null,
|
|
7
7
|
endRadius: null,
|
|
@@ -27,138 +27,125 @@ var DEFAULTS_LAYOUT_OPTIONS = {
|
|
|
27
27
|
* // If you want to assign the positions directly to the nodes, use assign method.
|
|
28
28
|
* await layout.assign(graph, { radius: 20 });
|
|
29
29
|
*/
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
if (options === void 0) { options = {}; }
|
|
30
|
+
export class CircularLayout {
|
|
31
|
+
constructor(options = {}) {
|
|
33
32
|
this.options = options;
|
|
34
33
|
this.id = 'circular';
|
|
35
|
-
this.options =
|
|
34
|
+
this.options = Object.assign(Object.assign({}, DEFAULTS_LAYOUT_OPTIONS), options);
|
|
36
35
|
}
|
|
37
36
|
/**
|
|
38
37
|
* Return the positions of nodes and edges(if needed).
|
|
39
38
|
*/
|
|
40
|
-
|
|
41
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
42
|
-
return
|
|
43
|
-
return [2 /*return*/, this.genericCircularLayout(false, graph, options)];
|
|
44
|
-
});
|
|
39
|
+
execute(graph, options) {
|
|
40
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
return this.genericCircularLayout(false, graph, options);
|
|
45
42
|
});
|
|
46
|
-
}
|
|
43
|
+
}
|
|
47
44
|
/**
|
|
48
45
|
* To directly assign the positions to the nodes.
|
|
49
46
|
*/
|
|
50
|
-
|
|
51
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
52
|
-
|
|
53
|
-
switch (_a.label) {
|
|
54
|
-
case 0: return [4 /*yield*/, this.genericCircularLayout(true, graph, options)];
|
|
55
|
-
case 1:
|
|
56
|
-
_a.sent();
|
|
57
|
-
return [2 /*return*/];
|
|
58
|
-
}
|
|
59
|
-
});
|
|
47
|
+
assign(graph, options) {
|
|
48
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
yield this.genericCircularLayout(true, graph, options);
|
|
60
50
|
});
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
51
|
+
}
|
|
52
|
+
genericCircularLayout(assign, graph, options) {
|
|
53
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
+
const mergedOptions = Object.assign(Object.assign({}, this.options), options);
|
|
55
|
+
const { width, height, center, divisions, startAngle = 0, endAngle = 2 * Math.PI, angleRatio, ordering, clockwise, nodeSpacing: paramNodeSpacing, nodeSize: paramNodeSize, } = mergedOptions;
|
|
56
|
+
const nodes = graph.getAllNodes();
|
|
57
|
+
const edges = graph.getAllEdges();
|
|
58
|
+
// Calculate center according to `window` if not provided.
|
|
59
|
+
const [calculatedWidth, calculatedHeight, calculatedCenter] = calculateCenter(width, height, center);
|
|
60
|
+
const n = nodes === null || nodes === void 0 ? void 0 : nodes.length;
|
|
61
|
+
if (!n || n === 1) {
|
|
62
|
+
return handleSingleNodeGraph(graph, assign, calculatedCenter);
|
|
63
|
+
}
|
|
64
|
+
const angleStep = (endAngle - startAngle) / n;
|
|
65
|
+
let { radius, startRadius, endRadius } = mergedOptions;
|
|
66
|
+
if (paramNodeSpacing) {
|
|
67
|
+
const nodeSpacing = formatNumberFn(10, paramNodeSpacing);
|
|
68
|
+
const nodeSize = formatSizeFn(10, paramNodeSize);
|
|
69
|
+
let maxNodeSize = -Infinity;
|
|
70
|
+
nodes.forEach((node) => {
|
|
71
|
+
const nSize = nodeSize(node);
|
|
72
|
+
if (maxNodeSize < nSize)
|
|
73
|
+
maxNodeSize = nSize;
|
|
74
|
+
});
|
|
75
|
+
let perimeter = 0;
|
|
76
|
+
nodes.forEach((node, i) => {
|
|
77
|
+
if (i === 0)
|
|
78
|
+
perimeter += maxNodeSize || 10;
|
|
79
|
+
else
|
|
80
|
+
perimeter += (nodeSpacing(node) || 0) + (maxNodeSize || 10);
|
|
81
|
+
});
|
|
82
|
+
radius = perimeter / (2 * Math.PI);
|
|
83
|
+
}
|
|
84
|
+
else if (!radius && !startRadius && !endRadius) {
|
|
85
|
+
radius = Math.min(calculatedHeight, calculatedWidth) / 2;
|
|
86
|
+
}
|
|
87
|
+
else if (!startRadius && endRadius) {
|
|
88
|
+
startRadius = endRadius;
|
|
89
|
+
}
|
|
90
|
+
else if (startRadius && !endRadius) {
|
|
91
|
+
endRadius = startRadius;
|
|
92
|
+
}
|
|
93
|
+
const astep = angleStep * angleRatio;
|
|
94
|
+
// calculated nodes as temporary result
|
|
95
|
+
let layoutNodes = [];
|
|
96
|
+
if (ordering === 'topology') {
|
|
97
|
+
// layout according to the topology
|
|
98
|
+
layoutNodes = topologyOrdering(graph, nodes);
|
|
99
|
+
}
|
|
100
|
+
else if (ordering === 'topology-directed') {
|
|
101
|
+
// layout according to the topology
|
|
102
|
+
layoutNodes = topologyOrdering(graph, nodes, true);
|
|
103
|
+
}
|
|
104
|
+
else if (ordering === 'degree') {
|
|
105
|
+
// layout according to the descent order of degrees
|
|
106
|
+
layoutNodes = degreeOrdering(graph, nodes);
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
// layout according to the original order in the data.nodes
|
|
110
|
+
layoutNodes = nodes.map((node) => cloneFormatData(node));
|
|
111
|
+
}
|
|
112
|
+
const divN = Math.ceil(n / divisions); // node number in each division
|
|
113
|
+
for (let i = 0; i < n; ++i) {
|
|
114
|
+
let r = radius;
|
|
115
|
+
if (!r && startRadius !== null && endRadius !== null) {
|
|
116
|
+
r = startRadius + (i * (endRadius - startRadius)) / (n - 1);
|
|
117
117
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
layoutNodes = nodes.map(function (node) { return cloneFormatData(node); });
|
|
118
|
+
if (!r) {
|
|
119
|
+
r = 10 + (i * 100) / (n - 1);
|
|
121
120
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
}
|
|
131
|
-
angle = startAngle +
|
|
132
|
-
(i % divN) * astep +
|
|
133
|
-
((2 * Math.PI) / divisions) * Math.floor(i / divN);
|
|
134
|
-
if (!clockwise) {
|
|
135
|
-
angle =
|
|
136
|
-
endAngle -
|
|
137
|
-
(i % divN) * astep -
|
|
138
|
-
((2 * Math.PI) / divisions) * Math.floor(i / divN);
|
|
139
|
-
}
|
|
140
|
-
layoutNodes[i].data.x = calculatedCenter[0] + Math.cos(angle) * r;
|
|
141
|
-
layoutNodes[i].data.y = calculatedCenter[1] + Math.sin(angle) * r;
|
|
121
|
+
let angle = startAngle +
|
|
122
|
+
(i % divN) * astep +
|
|
123
|
+
((2 * Math.PI) / divisions) * Math.floor(i / divN);
|
|
124
|
+
if (!clockwise) {
|
|
125
|
+
angle =
|
|
126
|
+
endAngle -
|
|
127
|
+
(i % divN) * astep -
|
|
128
|
+
((2 * Math.PI) / divisions) * Math.floor(i / divN);
|
|
142
129
|
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
130
|
+
layoutNodes[i].data.x = calculatedCenter[0] + Math.cos(angle) * r;
|
|
131
|
+
layoutNodes[i].data.y = calculatedCenter[1] + Math.sin(angle) * r;
|
|
132
|
+
}
|
|
133
|
+
if (assign) {
|
|
134
|
+
layoutNodes.forEach((node) => {
|
|
135
|
+
graph.mergeNodeData(node.id, {
|
|
136
|
+
x: node.data.x,
|
|
137
|
+
y: node.data.y,
|
|
149
138
|
});
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
const result = {
|
|
142
|
+
nodes: layoutNodes,
|
|
143
|
+
edges,
|
|
144
|
+
};
|
|
145
|
+
return result;
|
|
157
146
|
});
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
}());
|
|
161
|
-
export { CircularLayout };
|
|
147
|
+
}
|
|
148
|
+
}
|
|
162
149
|
/**
|
|
163
150
|
* order the nodes acoording to the graph topology
|
|
164
151
|
* @param graph
|
|
@@ -166,15 +153,14 @@ export { CircularLayout };
|
|
|
166
153
|
* @param directed
|
|
167
154
|
* @returns
|
|
168
155
|
*/
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
var n = nodes.length;
|
|
156
|
+
const topologyOrdering = (graph, nodes, directed = false) => {
|
|
157
|
+
const orderedCNodes = [cloneFormatData(nodes[0])];
|
|
158
|
+
const pickFlags = {};
|
|
159
|
+
const n = nodes.length;
|
|
174
160
|
pickFlags[nodes[0].id] = true;
|
|
175
161
|
// write children into cnodes
|
|
176
|
-
|
|
177
|
-
nodes.forEach(
|
|
162
|
+
let k = 0;
|
|
163
|
+
nodes.forEach((node, i) => {
|
|
178
164
|
if (i !== 0) {
|
|
179
165
|
if ((i === n - 1 ||
|
|
180
166
|
graph.getDegree(node.id, 'both') !==
|
|
@@ -186,12 +172,12 @@ var topologyOrdering = function (graph, nodes, directed) {
|
|
|
186
172
|
k++;
|
|
187
173
|
}
|
|
188
174
|
else {
|
|
189
|
-
|
|
175
|
+
const children = directed
|
|
190
176
|
? graph.getSuccessors(orderedCNodes[k].id)
|
|
191
177
|
: graph.getNeighbors(orderedCNodes[k].id);
|
|
192
|
-
|
|
193
|
-
for (
|
|
194
|
-
|
|
178
|
+
let foundChild = false;
|
|
179
|
+
for (let j = 0; j < children.length; j++) {
|
|
180
|
+
const child = children[j];
|
|
195
181
|
if (graph.getDegree(child.id) === graph.getDegree(node.id) &&
|
|
196
182
|
!pickFlags[child.id]) {
|
|
197
183
|
orderedCNodes.push(cloneFormatData(child));
|
|
@@ -200,7 +186,7 @@ var topologyOrdering = function (graph, nodes, directed) {
|
|
|
200
186
|
break;
|
|
201
187
|
}
|
|
202
188
|
}
|
|
203
|
-
|
|
189
|
+
let ii = 0;
|
|
204
190
|
while (!foundChild) {
|
|
205
191
|
if (!pickFlags[nodes[ii].id]) {
|
|
206
192
|
orderedCNodes.push(cloneFormatData(nodes[ii]));
|
|
@@ -224,13 +210,11 @@ var topologyOrdering = function (graph, nodes, directed) {
|
|
|
224
210
|
* @returns
|
|
225
211
|
*/
|
|
226
212
|
function degreeOrdering(graph, nodes) {
|
|
227
|
-
|
|
228
|
-
nodes.forEach(
|
|
213
|
+
const orderedNodes = [];
|
|
214
|
+
nodes.forEach((node, i) => {
|
|
229
215
|
orderedNodes.push(cloneFormatData(node));
|
|
230
216
|
});
|
|
231
|
-
orderedNodes.sort(
|
|
232
|
-
return graph.getDegree(nodeA.id, 'both') - graph.getDegree(nodeB.id, 'both');
|
|
233
|
-
});
|
|
217
|
+
orderedNodes.sort((nodeA, nodeB) => graph.getDegree(nodeA.id, 'both') - graph.getDegree(nodeB.id, 'both'));
|
|
234
218
|
return orderedNodes;
|
|
235
219
|
}
|
|
236
220
|
/**
|
|
@@ -240,10 +224,10 @@ function degreeOrdering(graph, nodes) {
|
|
|
240
224
|
* @param center
|
|
241
225
|
* @returns
|
|
242
226
|
*/
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
227
|
+
const calculateCenter = (width, height, center) => {
|
|
228
|
+
let calculatedWidth = width;
|
|
229
|
+
let calculatedHeight = height;
|
|
230
|
+
let calculatedCenter = center;
|
|
247
231
|
if (!calculatedWidth && typeof window !== 'undefined') {
|
|
248
232
|
calculatedWidth = window.innerWidth;
|
|
249
233
|
}
|