@antv/layout 1.2.14-beta.1 → 1.2.14-beta.3

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.
@@ -0,0 +1,35 @@
1
+ import type { ID } from '@antv/graphlib';
2
+ import type { Simulation } from 'd3-force';
3
+ import type { Graph, LayoutMapping, LayoutWithIterations } from '../types';
4
+ import type { D3ForceLayoutOptions, EdgeDatum, NodeDatum } from './types';
5
+ export declare class D3ForceLayout<T extends D3ForceLayoutOptions = D3ForceLayoutOptions> implements LayoutWithIterations<T> {
6
+ id: string;
7
+ simulation: Simulation<NodeDatum, EdgeDatum>;
8
+ protected resolver: (value: LayoutMapping) => void;
9
+ protected config: {
10
+ inputNodeAttrs: string[];
11
+ outputNodeAttrs: string[];
12
+ simulationAttrs: string[];
13
+ };
14
+ protected forceMap: Record<string, Function>;
15
+ options: Partial<T>;
16
+ protected context: {
17
+ assign: boolean;
18
+ options: Partial<T>;
19
+ nodes: NodeDatum[];
20
+ edges: EdgeDatum[];
21
+ graph?: Graph;
22
+ };
23
+ constructor(options?: Partial<T>);
24
+ execute(graph: Graph, options?: T): Promise<LayoutMapping>;
25
+ assign(graph: Graph, options?: T): Promise<void>;
26
+ stop(): void;
27
+ tick(iterations?: number): LayoutMapping;
28
+ restart(): void;
29
+ setFixedPosition(id: ID, position: (number | null)[]): void;
30
+ protected getOptions(options: Partial<T>): T;
31
+ protected genericLayout(assign: boolean, graph: Graph, options?: T): Promise<LayoutMapping>;
32
+ protected getResult(): LayoutMapping;
33
+ protected initSimulation(): Simulation<NodeDatum, EdgeDatum>;
34
+ protected setSimulation(options: T): Simulation<NodeDatum, EdgeDatum>;
35
+ }
@@ -0,0 +1,174 @@
1
+ import { __awaiter } from "tslib";
2
+ import { deepMix, pick } from '@antv/util';
3
+ import { forceCenter, forceCollide, forceLink, forceManyBody, forceRadial, forceSimulation, forceX, forceY, } from 'd3-force';
4
+ export class D3ForceLayout {
5
+ constructor(options) {
6
+ this.id = 'd3-force';
7
+ this.config = {
8
+ inputNodeAttrs: ['x', 'y', 'vx', 'vy', 'fx', 'fy'],
9
+ outputNodeAttrs: ['x', 'y', 'vx', 'vy'],
10
+ simulationAttrs: [
11
+ 'alpha',
12
+ 'alphaMin',
13
+ 'alphaDecay',
14
+ 'alphaTarget',
15
+ 'velocityDecay',
16
+ 'randomSource',
17
+ ],
18
+ };
19
+ this.forceMap = {
20
+ link: forceLink,
21
+ manyBody: forceManyBody,
22
+ center: forceCenter,
23
+ collide: forceCollide,
24
+ radial: forceRadial,
25
+ x: forceX,
26
+ y: forceY,
27
+ };
28
+ // @ts-ignore
29
+ this.options = {
30
+ link: {
31
+ id: (edge) => edge.id,
32
+ },
33
+ manyBody: {},
34
+ center: {
35
+ x: 0,
36
+ y: 0,
37
+ },
38
+ };
39
+ this.context = {
40
+ options: {},
41
+ assign: false,
42
+ nodes: [],
43
+ edges: [],
44
+ };
45
+ deepMix(this.options, options);
46
+ if (this.options.forceSimulation) {
47
+ this.simulation = this.options.forceSimulation;
48
+ }
49
+ }
50
+ execute(graph, options) {
51
+ return __awaiter(this, void 0, void 0, function* () {
52
+ return this.genericLayout(false, graph, options);
53
+ });
54
+ }
55
+ assign(graph, options) {
56
+ return __awaiter(this, void 0, void 0, function* () {
57
+ yield this.genericLayout(true, graph, options);
58
+ });
59
+ }
60
+ stop() {
61
+ this.simulation.stop();
62
+ }
63
+ tick(iterations) {
64
+ this.simulation.tick(iterations);
65
+ return this.getResult();
66
+ }
67
+ restart() {
68
+ this.simulation.restart();
69
+ }
70
+ setFixedPosition(id, position) {
71
+ const node = this.context.nodes.find((n) => n.id === id);
72
+ if (!node)
73
+ return;
74
+ position.forEach((value, index) => {
75
+ if (typeof value === 'number' || value === null) {
76
+ const key = ['fx', 'fy', 'fz'][index];
77
+ node[key] = value;
78
+ }
79
+ });
80
+ }
81
+ getOptions(options) {
82
+ var _a, _b;
83
+ const _ = deepMix({}, this.options, options);
84
+ // process nodeSize
85
+ if (_.collide && ((_a = _.collide) === null || _a === void 0 ? void 0 : _a.radius) === undefined) {
86
+ _.collide = _.collide || {};
87
+ // @ts-ignore
88
+ _.collide.radius = (_b = _.nodeSize) !== null && _b !== void 0 ? _b : 10;
89
+ }
90
+ // process iterations
91
+ if (_.iterations === undefined) {
92
+ if (_.link && _.link.iterations === undefined) {
93
+ _.iterations = _.link.iterations;
94
+ }
95
+ if (_.collide && _.collide.iterations === undefined) {
96
+ _.iterations = _.collide.iterations;
97
+ }
98
+ }
99
+ // assign to context
100
+ this.context.options = _;
101
+ return _;
102
+ }
103
+ genericLayout(assign, graph, options) {
104
+ var _a;
105
+ return __awaiter(this, void 0, void 0, function* () {
106
+ const _options = this.getOptions(options);
107
+ const nodes = graph.getAllNodes().map(({ id, data }) => (Object.assign({ id,
108
+ data }, pick(data, this.config.inputNodeAttrs))));
109
+ const edges = graph.getAllEdges().map((edge) => (Object.assign({}, edge)));
110
+ Object.assign(this.context, { assign, nodes, edges, graph });
111
+ const promise = new Promise((resolver) => {
112
+ this.resolver = resolver;
113
+ });
114
+ const simulation = this.setSimulation(_options);
115
+ simulation.nodes(nodes);
116
+ (_a = simulation.force('link')) === null || _a === void 0 ? void 0 : _a.links(edges);
117
+ return promise;
118
+ });
119
+ }
120
+ getResult() {
121
+ const { assign, nodes, edges, graph } = this.context;
122
+ const nodesResult = nodes.map((node) => ({
123
+ id: node.id,
124
+ data: Object.assign(Object.assign({}, node.data), pick(node, this.config.outputNodeAttrs)),
125
+ }));
126
+ const edgeResult = edges.map(({ id, source, target, data }) => ({
127
+ id,
128
+ source: typeof source === 'object' ? source.id : source,
129
+ target: typeof target === 'object' ? target.id : target,
130
+ data,
131
+ }));
132
+ if (assign) {
133
+ nodesResult.forEach((node) => graph.mergeNodeData(node.id, node.data));
134
+ }
135
+ return { nodes: nodesResult, edges: edgeResult };
136
+ }
137
+ initSimulation() {
138
+ return forceSimulation();
139
+ }
140
+ setSimulation(options) {
141
+ const simulation = this.simulation || this.options.forceSimulation || this.initSimulation();
142
+ if (!this.simulation) {
143
+ this.simulation = simulation
144
+ .on('tick', () => { var _a; return (_a = options.onTick) === null || _a === void 0 ? void 0 : _a.call(options, this.getResult()); })
145
+ .on('end', () => { var _a; return (_a = this.resolver) === null || _a === void 0 ? void 0 : _a.call(this, this.getResult()); });
146
+ }
147
+ apply(simulation, this.config.simulationAttrs.map((name) => [
148
+ name,
149
+ options[name],
150
+ ]));
151
+ Object.entries(this.forceMap).forEach(([name, Ctor]) => {
152
+ const forceName = name;
153
+ if (options[name]) {
154
+ let force = simulation.force(forceName);
155
+ if (!force) {
156
+ force = Ctor();
157
+ simulation.force(forceName, force);
158
+ }
159
+ apply(force, Object.entries(options[forceName]));
160
+ }
161
+ else
162
+ simulation.force(forceName, null);
163
+ });
164
+ return simulation;
165
+ }
166
+ }
167
+ const apply = (target, params) => {
168
+ return params.reduce((acc, [method, param]) => {
169
+ if (!acc[method] || param === undefined)
170
+ return acc;
171
+ return acc[method].call(target, param);
172
+ }, target);
173
+ };
174
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/d3-force/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAE3C,OAAO,EACL,WAAW,EACX,YAAY,EAEZ,SAAS,EACT,aAAa,EACb,WAAW,EACX,eAAe,EACf,MAAM,EACN,MAAM,GACP,MAAM,UAAU,CAAC;AAIlB,MAAM,OAAO,aAAa;IA0DxB,YAAY,OAAoB;QAtDzB,OAAE,GAAG,UAAU,CAAC;QAMb,WAAM,GAAG;YACjB,cAAc,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC;YAClD,eAAe,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,CAAC;YACvC,eAAe,EAAE;gBACf,OAAO;gBACP,UAAU;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AAuB,EAAE,EAAE;IACrD,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE,EAAE;QAC5C,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,KAAK,KAAK,SAAS;YAAE,OAAO,GAAG,CAAC;QACpD,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IACzC,CAAC,EAAE,MAAM,CAAC,CAAC;AACb,CAAC,CAAC"}
@@ -0,0 +1,108 @@
1
+ import type { Simulation, SimulationLinkDatum, SimulationNodeDatum } from 'd3-force';
2
+ import type { EdgeData, LayoutMapping, NodeData } from '../types';
3
+ export interface D3ForceLayoutOptions {
4
+ /**
5
+ * <zh/> 节点尺寸,默认为 10
6
+ *
7
+ * <en/> Node size, default is 10
8
+ */
9
+ nodeSize?: number | ((node: NodeDatum, index: number, nodes: NodeDatum[]) => number);
10
+ /**
11
+ * <zh/> 每次迭代执行回调
12
+ *
13
+ * <en/> Callback executed on each tick
14
+ * @param data - <zh/> 布局结果 | <en/> layout result
15
+ */
16
+ onTick?: (data: LayoutMapping) => void;
17
+ /**
18
+ * <zh/> 迭代次数
19
+ *
20
+ * <en/> Number of iterations
21
+ * @description
22
+ * <zh/> 设置的是力的迭代次数,而不是布局的迭代次数
23
+ *
24
+ * <en/> The number of iterations of the force, not the layout
25
+ */
26
+ iterations?: number;
27
+ forceSimulation?: Simulation<NodeDatum, EdgeDatum>;
28
+ alpha?: number;
29
+ alphaMin?: number;
30
+ alphaDecay?: number;
31
+ alphaTarget?: number;
32
+ velocityDecay?: number;
33
+ randomSource?: () => number;
34
+ /**
35
+ * <zh/> 中心力
36
+ * <en/> Center force
37
+ */
38
+ center?: false | {
39
+ x?: number;
40
+ y?: number;
41
+ strength?: number;
42
+ };
43
+ /**
44
+ * <zh/> 碰撞力
45
+ *
46
+ * <en/> Collision force
47
+ */
48
+ collide?: false | {
49
+ radius?: number | ((node: NodeDatum, index: number, nodes: NodeDatum[]) => number);
50
+ strength?: number;
51
+ iterations?: number;
52
+ };
53
+ /**
54
+ * <zh/> 多体力
55
+ *
56
+ * <en/> Many body force
57
+ */
58
+ manyBody?: false | {
59
+ strength?: number | ((node: NodeDatum, index: number, nodes: NodeDatum[]) => number);
60
+ theta?: number;
61
+ distanceMin?: number;
62
+ distanceMax?: number;
63
+ };
64
+ /**
65
+ * <zh/> 链接力
66
+ *
67
+ * <en/> Link force
68
+ */
69
+ link?: false | {
70
+ id?: (edge: EdgeDatum, index: number, edges: EdgeDatum[]) => string;
71
+ distance?: number | ((edge: EdgeDatum, index: number, edges: EdgeDatum[]) => number);
72
+ strength?: number | ((edge: EdgeDatum, index: number, edges: EdgeDatum[]) => number);
73
+ iterations?: number;
74
+ };
75
+ /**
76
+ * <zh/> 径向力
77
+ *
78
+ * <en/> Radial force
79
+ */
80
+ radial?: false | {
81
+ strength?: number | ((node: NodeDatum, index: number, nodes: NodeDatum[]) => number);
82
+ radius?: number | ((node: NodeDatum, index: number, nodes: NodeDatum[]) => number);
83
+ x?: number;
84
+ y?: number;
85
+ };
86
+ /**
87
+ * <zh/> X 轴力
88
+ *
89
+ * <en/> X axis force
90
+ */
91
+ x?: false | {
92
+ strength?: number | ((node: NodeDatum, index: number, nodes: NodeDatum[]) => number);
93
+ x?: number | ((node: NodeDatum, index: number, nodes: NodeDatum[]) => number);
94
+ };
95
+ /**
96
+ * <zh/> Y 轴力
97
+ *
98
+ * <en/> Y axis force
99
+ */
100
+ y?: false | {
101
+ strength?: number | ((node: NodeDatum, index: number, nodes: NodeDatum[]) => number);
102
+ y?: number | ((node: NodeDatum, index: number, nodes: NodeDatum[]) => number);
103
+ };
104
+ }
105
+ export interface NodeDatum extends NodeData, SimulationNodeDatum {
106
+ }
107
+ export interface EdgeDatum extends EdgeData, SimulationLinkDatum<NodeDatum> {
108
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/d3-force/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,25 @@
1
+ /// <reference path="../../src/d3-force-3d/typing.d.ts" />
2
+ import { forceCenter, forceCollide, forceLink, forceManyBody, forceRadial, forceX, forceY, forceZ } from 'd3-force-3d';
3
+ import { D3ForceLayout } from '../d3-force';
4
+ import type { LayoutWithIterations } from '../types';
5
+ import type { D3Force3DLayoutOptions } from './types';
6
+ export declare class D3Force3DLayout extends D3ForceLayout<D3Force3DLayoutOptions> implements LayoutWithIterations<D3Force3DLayoutOptions> {
7
+ id: string;
8
+ protected config: {
9
+ inputNodeAttrs: string[];
10
+ outputNodeAttrs: string[];
11
+ simulationAttrs: string[];
12
+ };
13
+ protected forceMap: {
14
+ link: typeof forceLink;
15
+ manyBody: typeof forceManyBody;
16
+ center: typeof forceCenter;
17
+ collide: typeof forceCollide;
18
+ radial: typeof forceRadial;
19
+ x: typeof forceX;
20
+ y: typeof forceY;
21
+ z: typeof forceZ;
22
+ };
23
+ options: Partial<D3Force3DLayoutOptions>;
24
+ protected initSimulation(): import("d3-force-3d").ForceSimulation;
25
+ }
@@ -0,0 +1,47 @@
1
+ import { forceCenter, forceCollide, forceLink, forceManyBody, forceRadial, forceSimulation, forceX, forceY, forceZ, } from 'd3-force-3d';
2
+ import { D3ForceLayout } from '../d3-force';
3
+ export class D3Force3DLayout extends D3ForceLayout {
4
+ constructor() {
5
+ super(...arguments);
6
+ this.id = 'd3-force-3d';
7
+ this.config = {
8
+ inputNodeAttrs: ['x', 'y', 'z', 'vx', 'vy', 'vz', 'fx', 'fy', 'fz'],
9
+ outputNodeAttrs: ['x', 'y', 'z', 'vx', 'vy', 'vz'],
10
+ simulationAttrs: [
11
+ 'alpha',
12
+ 'alphaMin',
13
+ 'alphaDecay',
14
+ 'alphaTarget',
15
+ 'velocityDecay',
16
+ 'randomSource',
17
+ 'numDimensions',
18
+ ],
19
+ };
20
+ this.forceMap = {
21
+ link: forceLink,
22
+ manyBody: forceManyBody,
23
+ center: forceCenter,
24
+ collide: forceCollide,
25
+ radial: forceRadial,
26
+ x: forceX,
27
+ y: forceY,
28
+ z: forceZ,
29
+ };
30
+ this.options = {
31
+ numDimensions: 3,
32
+ link: {
33
+ id: (edge) => edge.id,
34
+ },
35
+ manyBody: {},
36
+ center: {
37
+ x: 0,
38
+ y: 0,
39
+ z: 0,
40
+ },
41
+ };
42
+ }
43
+ initSimulation() {
44
+ return forceSimulation();
45
+ }
46
+ }
47
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/d3-force-3d/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,YAAY,EACZ,SAAS,EACT,aAAa,EACb,WAAW,EACX,eAAe,EACf,MAAM,EACN,MAAM,EACN,MAAM,GACP,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAI5C,MAAM,OAAO,eACX,SAAQ,aAAqC;IAD/C;;QAIS,OAAE,GAAG,aAAa,CAAC;QAEhB,WAAM,GAAG;YACjB,cAAc,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC;YACnE,eAAe,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC;YAClD,eAAe,EAAE;gBACf,OAAO;gBACP,UAAU;gBACV,YAAY;gBACZ,aAAa;gBACb,eAAe;gBACf,cAAc;gBACd,eAAe;aAChB;SACF,CAAC;QAEQ,aAAQ,GAAG;YACnB,IAAI,EAAE,SAAS;YACf,QAAQ,EAAE,aAAa;YACvB,MAAM,EAAE,WAAW;YACnB,OAAO,EAAE,YAAY;YACrB,MAAM,EAAE,WAAW;YACnB,CAAC,EAAE,MAAM;YACT,CAAC,EAAE,MAAM;YACT,CAAC,EAAE,MAAM;SACV,CAAC;QAEK,YAAO,GAAoC;YAChD,aAAa,EAAE,CAAC;YAChB,IAAI,EAAE;gBACJ,EAAE,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE;aACtB;YACD,QAAQ,EAAE,EAAE;YACZ,MAAM,EAAE;gBACN,CAAC,EAAE,CAAC;gBACJ,CAAC,EAAE,CAAC;gBACJ,CAAC,EAAE,CAAC;aACL;SACF,CAAC;IAKJ,CAAC;IAHW,cAAc;QACtB,OAAO,eAAe,EAAE,CAAC;IAC3B,CAAC;CACF"}
@@ -0,0 +1,43 @@
1
+ import type { D3ForceLayoutOptions, EdgeDatum, NodeDatum as _NodeDatum } from '../d3-force/types';
2
+ /**
3
+ * @see https://github.com/vasturiano/d3-force-3d
4
+ */
5
+ export interface D3Force3DLayoutOptions extends D3ForceLayoutOptions {
6
+ numDimensions?: number;
7
+ /**
8
+ * <zh/> 中心力
9
+ * <en/> Center force
10
+ */
11
+ center?: false | {
12
+ x?: number;
13
+ y?: number;
14
+ z?: number;
15
+ strength?: number;
16
+ };
17
+ /**
18
+ * <zh/> 径向力
19
+ *
20
+ * <en/> Radial force
21
+ */
22
+ radial?: false | {
23
+ strength?: number | ((node: NodeDatum, index: number, nodes: NodeDatum[]) => number);
24
+ radius?: number | ((node: NodeDatum, index: number, nodes: NodeDatum[]) => number);
25
+ x?: number;
26
+ y?: number;
27
+ z?: number;
28
+ };
29
+ /**
30
+ * <zh/> Z 轴力
31
+ *
32
+ * <en/> Z axis force
33
+ */
34
+ z?: false | {
35
+ strength?: number | ((node: NodeDatum, index: number, nodes: NodeDatum[]) => number);
36
+ z?: number | ((node: NodeDatum, index: number, nodes: NodeDatum[]) => number);
37
+ };
38
+ }
39
+ export interface NodeDatum extends _NodeDatum {
40
+ z: number;
41
+ vz: number;
42
+ }
43
+ export type { EdgeDatum };
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/d3-force-3d/types.ts"],"names":[],"mappings":""}
package/lib/exports.d.ts CHANGED
@@ -3,7 +3,10 @@ export type { DagreAlign, DagreRankdir } from './antv-dagre/types';
3
3
  export * from './circular';
4
4
  export * from './comboCombined';
5
5
  export * from './concentric';
6
- export * from './d3Force';
6
+ export { D3ForceLayout } from './d3-force';
7
+ export { D3Force3DLayout } from './d3-force-3d';
8
+ export type { D3Force3DLayoutOptions } from './d3-force-3d/types';
9
+ export type { D3ForceLayoutOptions } from './d3-force/types';
7
10
  export * from './dagre';
8
11
  export * from './force';
9
12
  export * from './forceAtlas2';
package/lib/exports.js CHANGED
@@ -2,7 +2,8 @@ export * from './antv-dagre';
2
2
  export * from './circular';
3
3
  export * from './comboCombined';
4
4
  export * from './concentric';
5
- export * from './d3Force';
5
+ export { D3ForceLayout } from './d3-force';
6
+ export { D3Force3DLayout } from './d3-force-3d';
6
7
  export * from './dagre';
7
8
  export * from './force';
8
9
  export * from './forceAtlas2';
@@ -1 +1 @@
1
- {"version":3,"file":"exports.js","sourceRoot":"","sources":["../src/exports.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAE7B,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,QAAQ,CAAC;AACvB,cAAc,OAAO,CAAC;AACtB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC"}
1
+ {"version":3,"file":"exports.js","sourceRoot":"","sources":["../src/exports.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAE7B,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAGhD,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,QAAQ,CAAC;AACvB,cAAc,OAAO,CAAC;AACtB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC"}
package/lib/registry.js CHANGED
@@ -2,7 +2,8 @@ import { AntVDagreLayout } from './antv-dagre';
2
2
  import { CircularLayout } from './circular';
3
3
  import { ComboCombinedLayout } from './comboCombined';
4
4
  import { ConcentricLayout } from './concentric';
5
- import { D3ForceLayout } from './d3Force';
5
+ import { D3ForceLayout } from './d3-force';
6
+ import { D3Force3DLayout } from './d3-force-3d';
6
7
  import { DagreLayout } from './dagre';
7
8
  import { ForceLayout } from './force';
8
9
  import { ForceAtlas2Layout } from './forceAtlas2';
@@ -20,6 +21,7 @@ export const registry = {
20
21
  radial: RadialLayout,
21
22
  force: ForceLayout,
22
23
  d3force: D3ForceLayout,
24
+ 'd3-force-3d': D3Force3DLayout,
23
25
  fruchterman: FruchtermanLayout,
24
26
  forceAtlas2: ForceAtlas2Layout,
25
27
  dagre: DagreLayout,
@@ -1 +1 @@
1
- {"version":3,"file":"registry.js","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO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AAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AACtC,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAClC,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAGxC,MAAM,CAAC,MAAM,QAAQ,GAAsD;IACzE,QAAQ,EAAE,cAAc;IACxB,UAAU,EAAE,gBAAgB;IAC5B,GAAG,EAAE,SAAS;IACd,MAAM,EAAE,YAAY;IACpB,IAAI,EAAE,UAAU;IAChB,MAAM,EAAE,YAAY;IACpB,KAAK,EAAE,WAAW;IAClB,OAAO,EAAE,aAAa;IACtB,aAAa,EAAE,eAAe;IAC9B,WAAW,EAAE,iBAAiB;IAC9B,WAAW,EAAE,iBAAiB;IAC9B,KAAK,EAAE,WAAW;IAClB,SAAS,EAAE,eAAe;IAC1B,aAAa,EAAE,mBAAmB;CACnC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antv/layout",
3
- "version": "1.2.14-beta.1",
3
+ "version": "1.2.14-beta.3",
4
4
  "description": "graph layout algorithm",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -33,6 +33,7 @@
33
33
  "@naoak/workerize-transferable": "^0.1.0",
34
34
  "comlink": "^4.4.1",
35
35
  "d3-force": "^3.0.0",
36
+ "d3-force-3d": "^3.0.5",
36
37
  "d3-octree": "^1.0.2",
37
38
  "d3-quadtree": "^3.0.1",
38
39
  "dagre": "^0.8.5",