@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.
Files changed (232) hide show
  1. package/dist/85db61ddc757dae66e04.worker.js +2 -0
  2. package/dist/85db61ddc757dae66e04.worker.js.map +1 -0
  3. package/dist/index.min.js +1 -1
  4. package/dist/index.min.js.map +1 -1
  5. package/lib/{dagre → antv-dagre}/acyclic.d.ts +1 -1
  6. package/lib/antv-dagre/acyclic.js +61 -0
  7. package/lib/antv-dagre/acyclic.js.map +1 -0
  8. package/lib/{dagre → antv-dagre}/add-border-segments.js +12 -12
  9. package/lib/antv-dagre/add-border-segments.js.map +1 -0
  10. package/lib/{dagre → antv-dagre}/coordinate-system.d.ts +2 -1
  11. package/lib/antv-dagre/coordinate-system.js +65 -0
  12. package/lib/antv-dagre/coordinate-system.js.map +1 -0
  13. package/lib/{dagre → antv-dagre}/data/list.d.ts +1 -1
  14. package/lib/{dagre → antv-dagre}/data/list.js +20 -22
  15. package/lib/antv-dagre/data/list.js.map +1 -0
  16. package/lib/{dagre → antv-dagre}/greedy-fas.d.ts +2 -2
  17. package/lib/antv-dagre/greedy-fas.js +136 -0
  18. package/lib/antv-dagre/greedy-fas.js.map +1 -0
  19. package/lib/{dagre → antv-dagre}/layout.d.ts +2 -1
  20. package/lib/{dagre → antv-dagre}/layout.js +125 -127
  21. package/lib/antv-dagre/layout.js.map +1 -0
  22. package/lib/{dagre → antv-dagre}/nesting-graph.js +36 -37
  23. package/lib/antv-dagre/nesting-graph.js.map +1 -0
  24. package/lib/{dagre → antv-dagre}/normalize.d.ts +2 -2
  25. package/lib/{dagre → antv-dagre}/normalize.js +24 -24
  26. package/lib/antv-dagre/normalize.js.map +1 -0
  27. package/lib/{dagre → antv-dagre}/order/add-subgraph-constraints.js +9 -9
  28. package/lib/antv-dagre/order/add-subgraph-constraints.js.map +1 -0
  29. package/lib/{dagre → antv-dagre}/order/barycenter.d.ts +2 -2
  30. package/lib/{dagre → antv-dagre}/order/barycenter.js +8 -8
  31. package/lib/antv-dagre/order/barycenter.js.map +1 -0
  32. package/lib/{dagre → antv-dagre}/order/build-layer-graph.js +18 -22
  33. package/lib/antv-dagre/order/build-layer-graph.js.map +1 -0
  34. package/lib/antv-dagre/order/cross-count.d.ts +3 -0
  35. package/lib/{dagre → antv-dagre}/order/cross-count.js +17 -17
  36. package/lib/antv-dagre/order/cross-count.js.map +1 -0
  37. package/lib/{dagre → antv-dagre}/order/index.d.ts +1 -1
  38. package/lib/{dagre → antv-dagre}/order/index.js +35 -35
  39. package/lib/antv-dagre/order/index.js.map +1 -0
  40. package/lib/{dagre → antv-dagre}/order/init-data-order.js +8 -9
  41. package/lib/antv-dagre/order/init-data-order.js.map +1 -0
  42. package/lib/antv-dagre/order/init-order.js +47 -0
  43. package/lib/antv-dagre/order/init-order.js.map +1 -0
  44. package/lib/{dagre → antv-dagre}/order/resolve-conflicts.d.ts +3 -3
  45. package/lib/{dagre → antv-dagre}/order/resolve-conflicts.js +32 -35
  46. package/lib/antv-dagre/order/resolve-conflicts.js.map +1 -0
  47. package/lib/{dagre → antv-dagre}/order/sort-subgraph.js +20 -20
  48. package/lib/antv-dagre/order/sort-subgraph.js.map +1 -0
  49. package/lib/{dagre → antv-dagre}/order/sort.d.ts +2 -2
  50. package/lib/{dagre → antv-dagre}/order/sort.js +19 -19
  51. package/lib/antv-dagre/order/sort.js.map +1 -0
  52. package/lib/{dagre → antv-dagre}/parent-dummy-chains.js +28 -28
  53. package/lib/antv-dagre/parent-dummy-chains.js.map +1 -0
  54. package/lib/{dagre → antv-dagre}/position/bk.d.ts +5 -4
  55. package/lib/{dagre → antv-dagre}/position/bk.js +140 -143
  56. package/lib/antv-dagre/position/bk.js.map +1 -0
  57. package/lib/{dagre → antv-dagre}/position/index.d.ts +2 -1
  58. package/lib/antv-dagre/position/index.js +51 -0
  59. package/lib/antv-dagre/position/index.js.map +1 -0
  60. package/lib/{dagre → antv-dagre}/rank/feasible-tree.d.ts +2 -2
  61. package/lib/{dagre → antv-dagre}/rank/feasible-tree.js +32 -32
  62. package/lib/antv-dagre/rank/feasible-tree.js.map +1 -0
  63. package/lib/antv-dagre/rank/index.d.ts +2 -0
  64. package/lib/{dagre → antv-dagre}/rank/index.js +10 -10
  65. package/lib/antv-dagre/rank/index.js.map +1 -0
  66. package/lib/{dagre → antv-dagre}/rank/network-simplex.d.ts +2 -2
  67. package/lib/{dagre → antv-dagre}/rank/network-simplex.js +70 -71
  68. package/lib/antv-dagre/rank/network-simplex.js.map +1 -0
  69. package/lib/{dagre → antv-dagre}/rank/util.d.ts +2 -2
  70. package/lib/{dagre → antv-dagre}/rank/util.js +31 -31
  71. package/lib/antv-dagre/rank/util.js.map +1 -0
  72. package/lib/antv-dagre/types.d.ts +2 -0
  73. package/lib/antv-dagre/types.js +2 -0
  74. package/lib/antv-dagre/types.js.map +1 -0
  75. package/lib/{dagre → antv-dagre}/util.d.ts +1 -1
  76. package/lib/{dagre → antv-dagre}/util.js +90 -98
  77. package/lib/antv-dagre/util.js.map +1 -0
  78. package/lib/antv-dagre.d.ts +50 -0
  79. package/lib/antv-dagre.js +538 -0
  80. package/lib/antv-dagre.js.map +1 -0
  81. package/lib/bundle-entry.d.ts +2 -18
  82. package/lib/bundle-entry.js +2 -18
  83. package/lib/bundle-entry.js.map +1 -1
  84. package/lib/bundle-supervisor.d.ts +4 -22
  85. package/lib/bundle-supervisor.js +54 -53
  86. package/lib/bundle-supervisor.js.map +1 -1
  87. package/lib/bundle-worker.d.ts +1 -1
  88. package/lib/bundle-worker.js +31 -33
  89. package/lib/bundle-worker.js.map +1 -1
  90. package/lib/circular.d.ts +1 -1
  91. package/lib/circular.js +124 -140
  92. package/lib/circular.js.map +1 -1
  93. package/lib/comboCombined.d.ts +1 -1
  94. package/lib/comboCombined.js +254 -284
  95. package/lib/comboCombined.js.map +1 -1
  96. package/lib/concentric.d.ts +1 -1
  97. package/lib/concentric.js +166 -176
  98. package/lib/concentric.js.map +1 -1
  99. package/lib/d3Force/forceInBox.js +75 -77
  100. package/lib/d3Force/forceInBox.js.map +1 -1
  101. package/lib/d3Force/index.d.ts +2 -2
  102. package/lib/d3Force/index.js +196 -222
  103. package/lib/d3Force/index.js.map +1 -1
  104. package/lib/dagre.d.ts +13 -24
  105. package/lib/dagre.js +57 -542
  106. package/lib/dagre.js.map +1 -1
  107. package/lib/exports.d.ts +17 -0
  108. package/lib/exports.js +17 -0
  109. package/lib/exports.js.map +1 -0
  110. package/lib/force/forceNBody.js +42 -45
  111. package/lib/force/forceNBody.js.map +1 -1
  112. package/lib/force/index.d.ts +1 -1
  113. package/lib/force/index.js +282 -309
  114. package/lib/force/index.js.map +1 -1
  115. package/lib/force/types.d.ts +5 -5
  116. package/lib/forceAtlas2/body.d.ts +1 -1
  117. package/lib/forceAtlas2/body.js +29 -31
  118. package/lib/forceAtlas2/body.js.map +1 -1
  119. package/lib/forceAtlas2/index.d.ts +1 -1
  120. package/lib/forceAtlas2/index.js +206 -218
  121. package/lib/forceAtlas2/index.js.map +1 -1
  122. package/lib/forceAtlas2/quad.d.ts +2 -2
  123. package/lib/forceAtlas2/quad.js +40 -42
  124. package/lib/forceAtlas2/quad.js.map +1 -1
  125. package/lib/forceAtlas2/quadTree.js +16 -17
  126. package/lib/forceAtlas2/quadTree.js.map +1 -1
  127. package/lib/fruchterman.d.ts +1 -1
  128. package/lib/fruchterman.js +185 -205
  129. package/lib/fruchterman.js.map +1 -1
  130. package/lib/grid.d.ts +1 -1
  131. package/lib/grid.js +197 -207
  132. package/lib/grid.js.map +1 -1
  133. package/lib/index.d.ts +1 -15
  134. package/lib/index.js +1 -15
  135. package/lib/index.js.map +1 -1
  136. package/lib/mds.d.ts +1 -1
  137. package/lib/mds.js +68 -78
  138. package/lib/mds.js.map +1 -1
  139. package/lib/radial/index.d.ts +1 -1
  140. package/lib/radial/index.js +177 -184
  141. package/lib/radial/index.js.map +1 -1
  142. package/lib/radial/mds.d.ts +1 -1
  143. package/lib/radial/mds.js +15 -13
  144. package/lib/radial/mds.js.map +1 -1
  145. package/lib/radial/radial-nonoverlap-force.d.ts +2 -2
  146. package/lib/radial/radial-nonoverlap-force.js +36 -37
  147. package/lib/radial/radial-nonoverlap-force.js.map +1 -1
  148. package/lib/random.d.ts +1 -1
  149. package/lib/random.js +53 -66
  150. package/lib/random.js.map +1 -1
  151. package/lib/registry.d.ts +2 -2
  152. package/lib/registry.js +3 -1
  153. package/lib/registry.js.map +1 -1
  154. package/lib/supervisor.d.ts +2 -3
  155. package/lib/supervisor.js +57 -56
  156. package/lib/supervisor.js.map +1 -1
  157. package/lib/types.d.ts +20 -75
  158. package/lib/types.js.map +1 -1
  159. package/lib/util/array.js +1 -1
  160. package/lib/util/array.js.map +1 -1
  161. package/lib/util/common.d.ts +1 -1
  162. package/lib/util/common.js +7 -8
  163. package/lib/util/common.js.map +1 -1
  164. package/lib/util/function.js +23 -25
  165. package/lib/util/function.js.map +1 -1
  166. package/lib/util/index.d.ts +0 -2
  167. package/lib/util/index.js +0 -2
  168. package/lib/util/index.js.map +1 -1
  169. package/lib/util/math.d.ts +1 -26
  170. package/lib/util/math.js +41 -149
  171. package/lib/util/math.js.map +1 -1
  172. package/lib/util/object.d.ts +1 -1
  173. package/lib/util/object.js +13 -13
  174. package/lib/util/object.js.map +1 -1
  175. package/lib/util/size.d.ts +3 -0
  176. package/lib/util/size.js +12 -0
  177. package/lib/util/size.js.map +1 -0
  178. package/lib/worker.js +30 -31
  179. package/lib/worker.js.map +1 -1
  180. package/package.json +9 -5
  181. package/dist/aa1bb0ccc06b11cf79c1.worker.js +0 -2
  182. package/dist/aa1bb0ccc06b11cf79c1.worker.js.map +0 -1
  183. package/lib/dagre/acyclic.js +0 -62
  184. package/lib/dagre/acyclic.js.map +0 -1
  185. package/lib/dagre/add-border-segments.js.map +0 -1
  186. package/lib/dagre/coordinate-system.js +0 -65
  187. package/lib/dagre/coordinate-system.js.map +0 -1
  188. package/lib/dagre/data/list.js.map +0 -1
  189. package/lib/dagre/greedy-fas.js +0 -147
  190. package/lib/dagre/greedy-fas.js.map +0 -1
  191. package/lib/dagre/layout.js.map +0 -1
  192. package/lib/dagre/nesting-graph.js.map +0 -1
  193. package/lib/dagre/normalize.js.map +0 -1
  194. package/lib/dagre/order/add-subgraph-constraints.js.map +0 -1
  195. package/lib/dagre/order/barycenter.js.map +0 -1
  196. package/lib/dagre/order/build-layer-graph.js.map +0 -1
  197. package/lib/dagre/order/cross-count.d.ts +0 -3
  198. package/lib/dagre/order/cross-count.js.map +0 -1
  199. package/lib/dagre/order/index.js.map +0 -1
  200. package/lib/dagre/order/init-data-order.js.map +0 -1
  201. package/lib/dagre/order/init-order.js +0 -50
  202. package/lib/dagre/order/init-order.js.map +0 -1
  203. package/lib/dagre/order/resolve-conflicts.js.map +0 -1
  204. package/lib/dagre/order/sort-subgraph.js.map +0 -1
  205. package/lib/dagre/order/sort.js.map +0 -1
  206. package/lib/dagre/parent-dummy-chains.js.map +0 -1
  207. package/lib/dagre/position/bk.js.map +0 -1
  208. package/lib/dagre/position/index.js +0 -54
  209. package/lib/dagre/position/index.js.map +0 -1
  210. package/lib/dagre/rank/feasible-tree.js.map +0 -1
  211. package/lib/dagre/rank/index.d.ts +0 -2
  212. package/lib/dagre/rank/index.js.map +0 -1
  213. package/lib/dagre/rank/network-simplex.js.map +0 -1
  214. package/lib/dagre/rank/util.js.map +0 -1
  215. package/lib/dagre/util.js.map +0 -1
  216. package/lib/util/gpu.d.ts +0 -45
  217. package/lib/util/gpu.js +0 -214
  218. package/lib/util/gpu.js.map +0 -1
  219. package/lib/util/number.d.ts +0 -1
  220. package/lib/util/number.js +0 -5
  221. package/lib/util/number.js.map +0 -1
  222. package/lib/util/string.d.ts +0 -1
  223. package/lib/util/string.js +0 -15
  224. package/lib/util/string.js.map +0 -1
  225. /package/lib/{dagre → antv-dagre}/add-border-segments.d.ts +0 -0
  226. /package/lib/{dagre → antv-dagre}/nesting-graph.d.ts +0 -0
  227. /package/lib/{dagre → antv-dagre}/order/add-subgraph-constraints.d.ts +0 -0
  228. /package/lib/{dagre → antv-dagre}/order/build-layer-graph.d.ts +0 -0
  229. /package/lib/{dagre → antv-dagre}/order/init-data-order.d.ts +0 -0
  230. /package/lib/{dagre → antv-dagre}/order/init-order.d.ts +0 -0
  231. /package/lib/{dagre → antv-dagre}/order/sort-subgraph.d.ts +0 -0
  232. /package/lib/{dagre → antv-dagre}/parent-dummy-chains.d.ts +0 -0
@@ -1,12 +1,12 @@
1
- import { __assign, __awaiter, __generator, __read, __spreadArray } from "tslib";
2
- import { isFunction, isNumber, isObject } from '@antv/util';
1
+ import { __awaiter } from "tslib";
3
2
  import { Graph as GraphCore } from '@antv/graphlib';
4
- import { isArray, getLayoutBBox, graphTreeDfs } from './util';
5
- import { handleSingleNodeGraph } from './util/common';
6
- import { MDSLayout } from './mds';
7
- import { ForceLayout } from './force';
3
+ import { isFunction, isNumber, isObject } from '@antv/util';
8
4
  import { ConcentricLayout } from './concentric';
9
- var FORCE_LAYOUT_TYPE_MAP = {
5
+ import { ForceLayout } from './force';
6
+ import { MDSLayout } from './mds';
7
+ import { getLayoutBBox, graphTreeDfs, isArray } from './util';
8
+ import { handleSingleNodeGraph } from './util/common';
9
+ const FORCE_LAYOUT_TYPE_MAP = {
10
10
  gForce: true,
11
11
  force2: true,
12
12
  d3force: true,
@@ -15,7 +15,7 @@ var FORCE_LAYOUT_TYPE_MAP = {
15
15
  force: true,
16
16
  'graphin-force': true,
17
17
  };
18
- var DEFAULTS_LAYOUT_OPTIONS = {
18
+ const DEFAULTS_LAYOUT_OPTIONS = {
19
19
  center: [0, 0],
20
20
  comboPadding: 10,
21
21
  treeKey: 'combo',
@@ -35,232 +35,213 @@ var DEFAULTS_LAYOUT_OPTIONS = {
35
35
  * // If you want to assign the positions directly to the nodes, use assign method.
36
36
  * await layout.assign(graph, { radius: 20 });
37
37
  */
38
- var ComboCombinedLayout = /** @class */ (function () {
39
- function ComboCombinedLayout(options) {
40
- if (options === void 0) { options = {}; }
38
+ export class ComboCombinedLayout {
39
+ constructor(options = {}) {
41
40
  this.options = options;
42
41
  this.id = 'comboCombined';
43
- this.options = __assign(__assign({}, DEFAULTS_LAYOUT_OPTIONS), options);
42
+ this.options = Object.assign(Object.assign({}, DEFAULTS_LAYOUT_OPTIONS), options);
44
43
  }
45
44
  /**
46
45
  * Return the positions of nodes and edges(if needed).
47
46
  */
48
- ComboCombinedLayout.prototype.execute = function (graph, options) {
49
- return __awaiter(this, void 0, void 0, function () {
50
- return __generator(this, function (_a) {
51
- return [2 /*return*/, this.genericComboCombinedLayout(false, graph, options)];
52
- });
47
+ execute(graph, options) {
48
+ return __awaiter(this, void 0, void 0, function* () {
49
+ return this.genericComboCombinedLayout(false, graph, options);
53
50
  });
54
- };
51
+ }
55
52
  /**
56
53
  * To directly assign the positions to the nodes.
57
54
  */
58
- ComboCombinedLayout.prototype.assign = function (graph, options) {
59
- return __awaiter(this, void 0, void 0, function () {
60
- return __generator(this, function (_a) {
61
- switch (_a.label) {
62
- case 0: return [4 /*yield*/, this.genericComboCombinedLayout(true, graph, options)];
63
- case 1:
64
- _a.sent();
65
- return [2 /*return*/];
55
+ assign(graph, options) {
56
+ return __awaiter(this, void 0, void 0, function* () {
57
+ yield this.genericComboCombinedLayout(true, graph, options);
58
+ });
59
+ }
60
+ genericComboCombinedLayout(assign, graph, options) {
61
+ return __awaiter(this, void 0, void 0, function* () {
62
+ const mergedOptions = this.initVals(Object.assign(Object.assign({}, this.options), options));
63
+ const { center, treeKey, outerLayout: propsOuterLayout } = mergedOptions;
64
+ const nodes = graph
65
+ .getAllNodes()
66
+ .filter((node) => !node.data._isCombo);
67
+ const combos = graph
68
+ .getAllNodes()
69
+ .filter((node) => node.data._isCombo);
70
+ const edges = graph.getAllEdges();
71
+ const n = nodes === null || nodes === void 0 ? void 0 : nodes.length;
72
+ if (!n || n === 1) {
73
+ return handleSingleNodeGraph(graph, assign, center);
74
+ }
75
+ // output nodes
76
+ const layoutNodes = [];
77
+ const nodeMap = new Map();
78
+ nodes.forEach((node) => {
79
+ nodeMap.set(node.id, node);
80
+ });
81
+ const comboMap = new Map();
82
+ combos.forEach((combo) => {
83
+ comboMap.set(combo.id, combo);
84
+ });
85
+ // each one in comboNodes is a combo contains the size and child nodes
86
+ // comboNodes ncludes the node who has no parent combo
87
+ const comboNodes = new Map();
88
+ // the inner layouts, the result positions are stored in comboNodes and their child nodes
89
+ const innerGraphLayoutPromises = this.getInnerGraphs(graph, treeKey, nodeMap, comboMap, edges, mergedOptions, comboNodes);
90
+ yield Promise.all(innerGraphLayoutPromises);
91
+ const outerNodeIds = new Map();
92
+ const outerLayoutNodes = [];
93
+ const nodeAncestorIdMap = new Map();
94
+ let allHaveNoPosition = true;
95
+ graph.getRoots(treeKey).forEach((root) => {
96
+ const combo = comboNodes.get(root.id);
97
+ const cacheCombo = comboMap.get(root.id) || nodeMap.get(root.id);
98
+ const comboLayoutNode = {
99
+ id: root.id,
100
+ data: Object.assign(Object.assign({}, root.data), { x: combo.data.x || cacheCombo.data.x, y: combo.data.y || cacheCombo.data.y, fx: combo.data.fx || cacheCombo.data.fx, fy: combo.data.fy || cacheCombo.data.fy, mass: combo.data.mass || cacheCombo.data.mass, size: combo.data.size }),
101
+ };
102
+ outerLayoutNodes.push(comboLayoutNode);
103
+ outerNodeIds.set(root.id, true);
104
+ if (!isNaN(comboLayoutNode.data.x) &&
105
+ comboLayoutNode.data.x !== 0 &&
106
+ !isNaN(comboLayoutNode.data.y) &&
107
+ comboLayoutNode.data.y !== 0) {
108
+ allHaveNoPosition = false;
66
109
  }
110
+ else {
111
+ comboLayoutNode.data.x = Math.random() * 100;
112
+ comboLayoutNode.data.y = Math.random() * 100;
113
+ }
114
+ graphTreeDfs(graph, [root], (child) => {
115
+ if (child.id !== root.id)
116
+ nodeAncestorIdMap.set(child.id, root.id);
117
+ }, 'TB', treeKey);
67
118
  });
68
- });
69
- };
70
- ComboCombinedLayout.prototype.genericComboCombinedLayout = function (assign, graph, options) {
71
- return __awaiter(this, void 0, void 0, function () {
72
- var mergedOptions, center, treeKey, propsOuterLayout, nodes, combos, edges, n, layoutNodes, nodeMap, comboMap, comboNodes, innerGraphLayoutPromises, outerNodeIds, outerLayoutNodes, nodeAncestorIdMap, allHaveNoPosition, outerLayoutEdges, outerPositions, outerLayoutGraph, outerLayout, outerLayoutPreset, result;
73
- return __generator(this, function (_a) {
74
- switch (_a.label) {
75
- case 0:
76
- mergedOptions = this.initVals(__assign(__assign({}, this.options), options));
77
- center = mergedOptions.center, treeKey = mergedOptions.treeKey, propsOuterLayout = mergedOptions.outerLayout;
78
- nodes = graph
79
- .getAllNodes()
80
- .filter(function (node) { return !node.data._isCombo; });
81
- combos = graph
82
- .getAllNodes()
83
- .filter(function (node) { return node.data._isCombo; });
84
- edges = graph.getAllEdges();
85
- n = nodes === null || nodes === void 0 ? void 0 : nodes.length;
86
- if (!n || n === 1) {
87
- return [2 /*return*/, handleSingleNodeGraph(graph, assign, center)];
88
- }
89
- layoutNodes = [];
90
- nodeMap = new Map();
91
- nodes.forEach(function (node) {
92
- nodeMap.set(node.id, node);
93
- });
94
- comboMap = new Map();
95
- combos.forEach(function (combo) {
96
- comboMap.set(combo.id, combo);
97
- });
98
- comboNodes = new Map();
99
- innerGraphLayoutPromises = this.getInnerGraphs(graph, treeKey, nodeMap, comboMap, edges, mergedOptions, comboNodes);
100
- return [4 /*yield*/, Promise.all(innerGraphLayoutPromises)];
101
- case 1:
102
- _a.sent();
103
- outerNodeIds = new Map();
104
- outerLayoutNodes = [];
105
- nodeAncestorIdMap = new Map();
106
- allHaveNoPosition = true;
107
- graph.getRoots(treeKey).forEach(function (root) {
108
- var combo = comboNodes.get(root.id);
109
- var cacheCombo = comboMap.get(root.id) || nodeMap.get(root.id);
110
- var comboLayoutNode = {
111
- id: root.id,
112
- data: __assign(__assign({}, root.data), { x: combo.data.x || cacheCombo.data.x, y: combo.data.y || cacheCombo.data.y, fx: combo.data.fx || cacheCombo.data.fx, fy: combo.data.fy || cacheCombo.data.fy, mass: combo.data.mass || cacheCombo.data.mass, size: combo.data.size }),
113
- };
114
- outerLayoutNodes.push(comboLayoutNode);
115
- outerNodeIds.set(root.id, true);
116
- if (!isNaN(comboLayoutNode.data.x) &&
117
- comboLayoutNode.data.x !== 0 &&
118
- !isNaN(comboLayoutNode.data.y) &&
119
- comboLayoutNode.data.y !== 0) {
120
- allHaveNoPosition = false;
121
- }
122
- else {
123
- comboLayoutNode.data.x = Math.random() * 100;
124
- comboLayoutNode.data.y = Math.random() * 100;
125
- }
126
- graphTreeDfs(graph, [root], function (child) {
127
- if (child.id !== root.id)
128
- nodeAncestorIdMap.set(child.id, root.id);
129
- }, 'TB', treeKey);
130
- });
131
- outerLayoutEdges = [];
132
- edges.forEach(function (edge) {
133
- var sourceAncestorId = nodeAncestorIdMap.get(edge.source) || edge.source;
134
- var targetAncestorId = nodeAncestorIdMap.get(edge.target) || edge.target;
135
- // create an edge for outer layout if both source and target's ancestor combo is in outer layout nodes
136
- if (sourceAncestorId !== targetAncestorId &&
137
- outerNodeIds.has(sourceAncestorId) &&
138
- outerNodeIds.has(targetAncestorId)) {
139
- outerLayoutEdges.push({
140
- id: edge.id,
141
- source: sourceAncestorId,
142
- target: targetAncestorId,
143
- data: {},
144
- });
145
- }
146
- });
147
- if (!(outerLayoutNodes === null || outerLayoutNodes === void 0 ? void 0 : outerLayoutNodes.length)) return [3 /*break*/, 7];
148
- if (!(outerLayoutNodes.length === 1)) return [3 /*break*/, 2];
149
- outerLayoutNodes[0].data.x = center[0];
150
- outerLayoutNodes[0].data.y = center[1];
151
- return [3 /*break*/, 6];
152
- case 2:
153
- outerLayoutGraph = new GraphCore({
154
- nodes: outerLayoutNodes,
155
- edges: outerLayoutEdges,
156
- });
157
- outerLayout = propsOuterLayout || new ForceLayout();
158
- if (!(allHaveNoPosition && FORCE_LAYOUT_TYPE_MAP[outerLayout.id])) return [3 /*break*/, 4];
159
- outerLayoutPreset = outerLayoutNodes.length < 100
119
+ const outerLayoutEdges = [];
120
+ edges.forEach((edge) => {
121
+ const sourceAncestorId = nodeAncestorIdMap.get(edge.source) || edge.source;
122
+ const targetAncestorId = nodeAncestorIdMap.get(edge.target) || edge.target;
123
+ // create an edge for outer layout if both source and target's ancestor combo is in outer layout nodes
124
+ if (sourceAncestorId !== targetAncestorId &&
125
+ outerNodeIds.has(sourceAncestorId) &&
126
+ outerNodeIds.has(targetAncestorId)) {
127
+ outerLayoutEdges.push({
128
+ id: edge.id,
129
+ source: sourceAncestorId,
130
+ target: targetAncestorId,
131
+ data: {},
132
+ });
133
+ }
134
+ });
135
+ // 若有需要最外层的 combo 或节点,则对最外层执行力导向
136
+ let outerPositions;
137
+ if (outerLayoutNodes === null || outerLayoutNodes === void 0 ? void 0 : outerLayoutNodes.length) {
138
+ if (outerLayoutNodes.length === 1) {
139
+ outerLayoutNodes[0].data.x = center[0];
140
+ outerLayoutNodes[0].data.y = center[1];
141
+ }
142
+ else {
143
+ const outerLayoutGraph = new GraphCore({
144
+ nodes: outerLayoutNodes,
145
+ edges: outerLayoutEdges,
146
+ });
147
+ const outerLayout = propsOuterLayout || new ForceLayout();
148
+ // preset the nodes if the outerLayout is a force family layout
149
+ if (allHaveNoPosition && FORCE_LAYOUT_TYPE_MAP[outerLayout.id]) {
150
+ const outerLayoutPreset = outerLayoutNodes.length < 100
160
151
  ? new MDSLayout()
161
152
  : new ConcentricLayout();
162
- return [4 /*yield*/, outerLayoutPreset.assign(outerLayoutGraph)];
163
- case 3:
164
- _a.sent();
165
- _a.label = 4;
166
- case 4: return [4 /*yield*/, outerLayout.execute(outerLayoutGraph, __assign({ center: center, kg: 5, preventOverlap: true, animate: false }, (outerLayout.id === 'force'
167
- ? {
168
- gravity: 1,
169
- factor: 4,
170
- linkDistance: function (edge, source, target) {
171
- var sourceSize = Math.max.apply(Math, __spreadArray([], __read(source.data.size))) || 32;
172
- var targetSize = Math.max.apply(Math, __spreadArray([], __read(target.data.size))) || 32;
173
- return sourceSize / 2 + targetSize / 2 + 200;
174
- },
175
- }
176
- : {})))];
177
- case 5:
178
- outerPositions = _a.sent();
179
- _a.label = 6;
180
- case 6:
181
- // move the combos and their child nodes
182
- comboNodes.forEach(function (comboNode) {
183
- var _a;
184
- var outerPosition = outerPositions.nodes.find(function (pos) { return pos.id === comboNode.id; });
185
- if (outerPosition) {
186
- // if it is one of the outer layout nodes, update the positions
187
- var _b = outerPosition.data, x_1 = _b.x, y_1 = _b.y;
188
- comboNode.data.visited = true;
189
- comboNode.data.x = x_1;
190
- comboNode.data.y = y_1;
191
- layoutNodes.push({
192
- id: comboNode.id,
193
- data: { x: x_1, y: y_1 },
194
- });
195
- }
196
- // move the child nodes
197
- var _c = comboNode.data, x = _c.x, y = _c.y;
198
- (_a = comboNode.data.nodes) === null || _a === void 0 ? void 0 : _a.forEach(function (node) {
199
- layoutNodes.push({
200
- id: node.id,
201
- data: { x: node.data.x + x, y: node.data.y + y },
202
- });
203
- });
153
+ yield outerLayoutPreset.assign(outerLayoutGraph);
154
+ }
155
+ outerPositions = yield outerLayout.execute(outerLayoutGraph, Object.assign({ center, kg: 5, preventOverlap: true, animate: false }, (outerLayout.id === 'force'
156
+ ? {
157
+ gravity: 1,
158
+ factor: 4,
159
+ linkDistance: (edge, source, target) => {
160
+ const sourceSize = Math.max(...source.data.size) || 32;
161
+ const targetSize = Math.max(...target.data.size) || 32;
162
+ return sourceSize / 2 + targetSize / 2 + 200;
163
+ },
164
+ }
165
+ : {})));
166
+ }
167
+ // move the combos and their child nodes
168
+ comboNodes.forEach((comboNode) => {
169
+ var _a;
170
+ const outerPosition = outerPositions.nodes.find((pos) => pos.id === comboNode.id);
171
+ if (outerPosition) {
172
+ // if it is one of the outer layout nodes, update the positions
173
+ const { x, y } = outerPosition.data;
174
+ comboNode.data.visited = true;
175
+ comboNode.data.x = x;
176
+ comboNode.data.y = y;
177
+ layoutNodes.push({
178
+ id: comboNode.id,
179
+ data: { x, y },
204
180
  });
205
- // move the nodes from top to bottom
206
- comboNodes.forEach(function (_a) {
207
- var _b;
208
- var data = _a.data;
209
- var x = data.x, y = data.y, visited = data.visited, nodes = data.nodes;
210
- (_b = nodes) === null || _b === void 0 ? void 0 : _b.forEach(function (node) {
211
- if (!visited) {
212
- var layoutNode = layoutNodes.find(function (n) { return n.id === node.id; });
213
- layoutNode.data.x += x || 0;
214
- layoutNode.data.y += y || 0;
215
- }
216
- });
181
+ }
182
+ // move the child nodes
183
+ const { x, y } = comboNode.data;
184
+ (_a = comboNode.data.nodes) === null || _a === void 0 ? void 0 : _a.forEach((node) => {
185
+ layoutNodes.push({
186
+ id: node.id,
187
+ data: { x: node.data.x + x, y: node.data.y + y },
217
188
  });
218
- _a.label = 7;
219
- case 7:
220
- if (assign) {
221
- layoutNodes.forEach(function (node) {
222
- graph.mergeNodeData(node.id, {
223
- x: node.data.x,
224
- y: node.data.y,
225
- });
226
- });
189
+ });
190
+ });
191
+ // move the nodes from top to bottom
192
+ comboNodes.forEach(({ data }) => {
193
+ const { x, y, visited, nodes } = data;
194
+ nodes === null || nodes === void 0 ? void 0 : nodes.forEach((node) => {
195
+ if (!visited) {
196
+ const layoutNode = layoutNodes.find((n) => n.id === node.id);
197
+ layoutNode.data.x += x || 0;
198
+ layoutNode.data.y += y || 0;
227
199
  }
228
- result = {
229
- nodes: layoutNodes,
230
- edges: edges,
231
- };
232
- return [2 /*return*/, result];
233
- }
234
- });
200
+ });
201
+ });
202
+ }
203
+ if (assign) {
204
+ layoutNodes.forEach((node) => {
205
+ graph.mergeNodeData(node.id, {
206
+ x: node.data.x,
207
+ y: node.data.y,
208
+ });
209
+ });
210
+ }
211
+ const result = {
212
+ nodes: layoutNodes,
213
+ edges,
214
+ };
215
+ return result;
235
216
  });
236
- };
237
- ComboCombinedLayout.prototype.initVals = function (options) {
238
- var formattedOptions = __assign({}, options);
239
- var nodeSize = options.nodeSize, spacing = options.spacing, comboPadding = options.comboPadding;
240
- var nodeSizeFunc;
241
- var spacingFunc;
217
+ }
218
+ initVals(options) {
219
+ const formattedOptions = Object.assign({}, options);
220
+ const { nodeSize, spacing, comboPadding } = options;
221
+ let nodeSizeFunc;
222
+ let spacingFunc;
242
223
  // nodeSpacing to function
243
224
  if (isNumber(spacing)) {
244
- spacingFunc = function () { return spacing; };
225
+ spacingFunc = () => spacing;
245
226
  }
246
227
  else if (isFunction(spacing)) {
247
228
  spacingFunc = spacing;
248
229
  }
249
230
  else {
250
- spacingFunc = function () { return 0; };
231
+ spacingFunc = () => 0;
251
232
  }
252
233
  formattedOptions.spacing = spacingFunc;
253
234
  // nodeSize to function
254
235
  if (!nodeSize) {
255
- nodeSizeFunc = function (d) {
256
- var spacing = spacingFunc(d);
236
+ nodeSizeFunc = (d) => {
237
+ const spacing = spacingFunc(d);
257
238
  if (d.size) {
258
239
  if (isArray(d.size)) {
259
- var res = d.size[0] > d.size[1] ? d.size[0] : d.size[1];
240
+ const res = d.size[0] > d.size[1] ? d.size[0] : d.size[1];
260
241
  return (res + spacing) / 2;
261
242
  }
262
243
  if (isObject(d.size)) {
263
- var res = d.size.width > d.size.height ? d.size.width : d.size.height;
244
+ const res = d.size.width > d.size.height ? d.size.width : d.size.height;
264
245
  return (res + spacing) / 2;
265
246
  }
266
247
  return (d.size + spacing) / 2;
@@ -269,66 +250,65 @@ var ComboCombinedLayout = /** @class */ (function () {
269
250
  };
270
251
  }
271
252
  else if (isFunction(nodeSize)) {
272
- nodeSizeFunc = function (d) {
273
- var size = nodeSize(d);
274
- var spacing = spacingFunc(d);
253
+ nodeSizeFunc = (d) => {
254
+ const size = nodeSize(d);
255
+ const spacing = spacingFunc(d);
275
256
  if (isArray(d.size)) {
276
- var res = d.size[0] > d.size[1] ? d.size[0] : d.size[1];
257
+ const res = d.size[0] > d.size[1] ? d.size[0] : d.size[1];
277
258
  return (res + spacing) / 2;
278
259
  }
279
260
  return ((size || 32) + spacing) / 2;
280
261
  };
281
262
  }
282
263
  else if (isArray(nodeSize)) {
283
- var larger = nodeSize[0] > nodeSize[1] ? nodeSize[0] : nodeSize[1];
284
- var radius_1 = larger / 2;
285
- nodeSizeFunc = function (d) { return radius_1 + spacingFunc(d) / 2; };
264
+ const larger = nodeSize[0] > nodeSize[1] ? nodeSize[0] : nodeSize[1];
265
+ const radius = larger / 2;
266
+ nodeSizeFunc = (d) => radius + spacingFunc(d) / 2;
286
267
  }
287
268
  else {
288
269
  // number type
289
- var radius_2 = nodeSize / 2;
290
- nodeSizeFunc = function (d) { return radius_2 + spacingFunc(d) / 2; };
270
+ const radius = nodeSize / 2;
271
+ nodeSizeFunc = (d) => radius + spacingFunc(d) / 2;
291
272
  }
292
273
  formattedOptions.nodeSize = nodeSizeFunc;
293
274
  // comboPadding to function
294
- var comboPaddingFunc;
275
+ let comboPaddingFunc;
295
276
  if (isNumber(comboPadding)) {
296
- comboPaddingFunc = function () { return comboPadding; };
277
+ comboPaddingFunc = () => comboPadding;
297
278
  }
298
279
  else if (isArray(comboPadding)) {
299
- comboPaddingFunc = function () { return Math.max.apply(null, comboPadding); };
280
+ comboPaddingFunc = () => Math.max.apply(null, comboPadding);
300
281
  }
301
282
  else if (isFunction(comboPadding)) {
302
283
  comboPaddingFunc = comboPadding;
303
284
  }
304
285
  else {
305
286
  // null type
306
- comboPaddingFunc = function () { return 0; };
287
+ comboPaddingFunc = () => 0;
307
288
  }
308
289
  formattedOptions.comboPadding = comboPaddingFunc;
309
290
  return formattedOptions;
310
- };
311
- ComboCombinedLayout.prototype.getInnerGraphs = function (graph, treeKey, nodeMap, comboMap, edges, options, comboNodes) {
312
- var _this = this;
313
- var nodeSize = options.nodeSize, comboPadding = options.comboPadding, spacing = options.spacing, innerLayout = options.innerLayout;
314
- var innerGraphLayout = innerLayout || new ConcentricLayout({});
315
- var innerLayoutOptions = {
291
+ }
292
+ getInnerGraphs(graph, treeKey, nodeMap, comboMap, edges, options, comboNodes) {
293
+ const { nodeSize, comboPadding, spacing, innerLayout } = options;
294
+ const innerGraphLayout = innerLayout || new ConcentricLayout({});
295
+ const innerLayoutOptions = {
316
296
  center: [0, 0],
317
297
  preventOverlap: true,
318
298
  nodeSpacing: spacing,
319
299
  };
320
- var innerLayoutPromises = [];
321
- var getSize = function (node) {
300
+ const innerLayoutPromises = [];
301
+ const getSize = (node) => {
322
302
  // @ts-ignore
323
- var padding = (comboPadding === null || comboPadding === void 0 ? void 0 : comboPadding(node)) || 10;
303
+ let padding = (comboPadding === null || comboPadding === void 0 ? void 0 : comboPadding(node)) || 10;
324
304
  if (isArray(padding))
325
- padding = Math.max.apply(Math, __spreadArray([], __read(padding)));
305
+ padding = Math.max(...padding);
326
306
  return {
327
307
  size: padding ? [padding * 2, padding * 2] : [30, 30],
328
- padding: padding,
308
+ padding,
329
309
  };
330
310
  };
331
- graph.getRoots(treeKey).forEach(function (root) {
311
+ graph.getRoots(treeKey).forEach((root) => {
332
312
  // @ts-ignore
333
313
  comboNodes.set(root.id, {
334
314
  id: root.id,
@@ -337,105 +317,95 @@ var ComboCombinedLayout = /** @class */ (function () {
337
317
  size: getSize(root).size,
338
318
  },
339
319
  });
340
- var start = Promise.resolve();
320
+ let start = Promise.resolve();
341
321
  // Regard the child nodes in one combo as a graph, and layout them from bottom to top
342
- graphTreeDfs(graph, [root], function (treeNode) {
322
+ graphTreeDfs(graph, [root], (treeNode) => {
343
323
  var _a;
344
324
  if (!treeNode.data._isCombo)
345
325
  return;
346
- var _b = getSize(treeNode), nsize = _b.size, padding = _b.padding;
326
+ const { size: nsize, padding } = getSize(treeNode);
347
327
  if (!((_a = graph.getChildren(treeNode.id, treeKey)) === null || _a === void 0 ? void 0 : _a.length)) {
348
328
  // empty combo
349
329
  comboNodes.set(treeNode.id, {
350
330
  id: treeNode.id,
351
- data: __assign(__assign({}, treeNode.data), { size: nsize }),
331
+ data: Object.assign(Object.assign({}, treeNode.data), { size: nsize }),
352
332
  });
353
333
  }
354
334
  else {
355
335
  // combo not empty
356
- var comboNode = comboNodes.get(treeNode.id);
336
+ const comboNode = comboNodes.get(treeNode.id);
357
337
  comboNodes.set(treeNode.id, {
358
338
  id: treeNode.id,
359
- data: __assign({ nodes: [] }, comboNode === null || comboNode === void 0 ? void 0 : comboNode.data),
339
+ data: Object.assign({ nodes: [] }, comboNode === null || comboNode === void 0 ? void 0 : comboNode.data),
360
340
  });
361
- var innerLayoutNodeIds_1 = new Map();
362
- var innerLayoutNodes_1 = graph
341
+ const innerLayoutNodeIds = new Map();
342
+ const innerLayoutNodes = graph
363
343
  .getChildren(treeNode.id, treeKey)
364
- .map(function (child) {
344
+ .map((child) => {
365
345
  if (child.data._isCombo) {
366
- if (!comboNodes.has(child.id))
346
+ if (!comboNodes.has(child.id)) {
367
347
  comboNodes.set(child.id, {
368
348
  id: child.id,
369
- data: __assign({}, child.data),
349
+ data: Object.assign({}, child.data),
370
350
  });
371
- innerLayoutNodeIds_1.set(child.id, true);
351
+ }
352
+ innerLayoutNodeIds.set(child.id, true);
372
353
  return comboNodes.get(child.id);
373
354
  }
374
- var oriNode = nodeMap.get(child.id) || comboMap.get(child.id);
375
- innerLayoutNodeIds_1.set(child.id, true);
355
+ const oriNode = nodeMap.get(child.id) || comboMap.get(child.id);
356
+ innerLayoutNodeIds.set(child.id, true);
376
357
  return {
377
358
  id: child.id,
378
- data: __assign(__assign({}, oriNode.data), child.data),
359
+ data: Object.assign(Object.assign({}, oriNode.data), child.data),
379
360
  };
380
361
  });
381
- var innerGraphData_1 = {
382
- nodes: innerLayoutNodes_1,
383
- edges: edges.filter(function (edge) {
384
- return innerLayoutNodeIds_1.has(edge.source) &&
385
- innerLayoutNodeIds_1.has(edge.target);
386
- }),
362
+ const innerGraphData = {
363
+ nodes: innerLayoutNodes,
364
+ edges: edges.filter((edge) => innerLayoutNodeIds.has(edge.source) &&
365
+ innerLayoutNodeIds.has(edge.target)),
387
366
  };
388
- var minNodeSize_1 = Infinity;
389
- innerLayoutNodes_1.forEach(function (node) {
390
- var _a, _b;
391
- var size = node.data.size;
367
+ let minNodeSize = Infinity;
368
+ innerLayoutNodes.forEach((node) => {
369
+ var _a;
370
+ let { size } = node.data;
392
371
  if (!size) {
393
372
  size = ((_a = comboNodes.get(node.id)) === null || _a === void 0 ? void 0 : _a.data.size) ||
394
- ((_b = nodeSize) === null || _b === void 0 ? void 0 : _b(node)) || [30, 30];
373
+ (nodeSize === null || nodeSize === void 0 ? void 0 : nodeSize(node)) || [30, 30];
395
374
  }
396
375
  if (isNumber(size))
397
376
  size = [size, size];
398
- var _c = __read(size, 2), size0 = _c[0], size1 = _c[1];
399
- if (minNodeSize_1 > size0)
400
- minNodeSize_1 = size0;
401
- if (minNodeSize_1 > size1)
402
- minNodeSize_1 = size1;
377
+ const [size0, size1] = size;
378
+ if (minNodeSize > size0)
379
+ minNodeSize = size0;
380
+ if (minNodeSize > size1)
381
+ minNodeSize = size1;
403
382
  node.data.size = size;
404
383
  });
405
384
  // innerGraphLayout.assign(innerGraphCore, innerLayoutOptions);
406
- start = start.then(function () { return __awaiter(_this, void 0, void 0, function () {
407
- var innerGraphCore, innerLayout, _a, minX, minY, maxX, maxY, center, size;
408
- return __generator(this, function (_b) {
409
- switch (_b.label) {
410
- case 0:
411
- innerGraphCore = new GraphCore(innerGraphData_1);
412
- return [4 /*yield*/, innerGraphLayout.assign(innerGraphCore, innerLayoutOptions)];
413
- case 1:
414
- innerLayout = _b.sent();
415
- _a = getLayoutBBox(innerLayoutNodes_1), minX = _a.minX, minY = _a.minY, maxX = _a.maxX, maxY = _a.maxY;
416
- center = { x: (maxX + minX) / 2, y: (maxY + minY) / 2 };
417
- innerGraphData_1.nodes.forEach(function (node) {
418
- node.data.x -= center.x;
419
- node.data.y -= center.y;
420
- });
421
- size = [
422
- Math.max(maxX - minX, minNodeSize_1) + padding * 2,
423
- Math.max(maxY - minY, minNodeSize_1) + padding * 2,
424
- ];
425
- comboNodes.get(treeNode.id).data.size = size;
426
- comboNodes.get(treeNode.id).data.nodes = innerLayoutNodes_1;
427
- return [2 /*return*/, innerLayout];
428
- }
385
+ start = start.then(() => __awaiter(this, void 0, void 0, function* () {
386
+ const innerGraphCore = new GraphCore(innerGraphData);
387
+ const innerLayout = yield innerGraphLayout.assign(innerGraphCore, innerLayoutOptions);
388
+ const { minX, minY, maxX, maxY } = getLayoutBBox(innerLayoutNodes);
389
+ // move the innerGraph to [0, 0], for later controled by parent layout
390
+ const center = { x: (maxX + minX) / 2, y: (maxY + minY) / 2 };
391
+ innerGraphData.nodes.forEach((node) => {
392
+ node.data.x -= center.x;
393
+ node.data.y -= center.y;
429
394
  });
430
- }); });
395
+ const size = [
396
+ Math.max(maxX - minX, minNodeSize) + padding * 2,
397
+ Math.max(maxY - minY, minNodeSize) + padding * 2,
398
+ ];
399
+ comboNodes.get(treeNode.id).data.size = size;
400
+ comboNodes.get(treeNode.id).data.nodes = innerLayoutNodes;
401
+ return innerLayout;
402
+ }));
431
403
  }
432
404
  return true;
433
405
  }, 'BT', treeKey);
434
406
  innerLayoutPromises.push(start);
435
407
  });
436
408
  return innerLayoutPromises;
437
- };
438
- return ComboCombinedLayout;
439
- }());
440
- export { ComboCombinedLayout };
409
+ }
410
+ }
441
411
  //# sourceMappingURL=comboCombined.js.map