@antv/layout 0.3.0 → 0.3.2
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/layout.min.js +1 -1
- package/dist/layout.min.js.map +1 -1
- package/es/layout/force2/index.js +6 -1
- package/es/layout/force2/index.js.map +1 -1
- package/es/util/gpu.js +0 -1
- package/es/util/gpu.js.map +1 -1
- package/es/util/math.js +12 -12
- package/es/util/math.js.map +1 -1
- package/es/util/object.js +1 -1
- package/es/util/object.js.map +1 -1
- package/lib/layout/force2/index.js +6 -1
- package/lib/layout/force2/index.js.map +1 -1
- package/lib/util/gpu.js +0 -1
- package/lib/util/gpu.js.map +1 -1
- package/lib/util/math.js +12 -12
- package/lib/util/math.js.map +1 -1
- package/lib/util/object.js +1 -1
- package/lib/util/object.js.map +1 -1
- package/package.json +2 -2
- package/src/layout/force2/index.ts +18 -15
- package/src/util/gpu.ts +0 -1
- package/src/util/math.ts +11 -13
- package/src/util/object.ts +1 -1
|
@@ -126,7 +126,7 @@ export class Force2Layout extends Base {
|
|
|
126
126
|
public distanceThresholdMode: 'mean' | 'max' | 'min' = 'mean';
|
|
127
127
|
|
|
128
128
|
/** 每次迭代结束的回调函数 */
|
|
129
|
-
public tick: (() => void) | null = () => {};
|
|
129
|
+
public tick: (() => void) | null = () => { };
|
|
130
130
|
|
|
131
131
|
/** 是否允许每次迭代结束调用回调函数 */
|
|
132
132
|
public enableTick: boolean;
|
|
@@ -158,7 +158,7 @@ export class Force2Layout extends Base {
|
|
|
158
158
|
|
|
159
159
|
/** 迭代中的标识 */
|
|
160
160
|
private timeInterval: number;
|
|
161
|
-
|
|
161
|
+
|
|
162
162
|
/** 与 minMovement 进行对比的判断停止迭代节点移动距离 */
|
|
163
163
|
private judgingDistance: number;
|
|
164
164
|
|
|
@@ -178,7 +178,8 @@ export class Force2Layout extends Base {
|
|
|
178
178
|
};
|
|
179
179
|
},
|
|
180
180
|
};
|
|
181
|
-
|
|
181
|
+
const { getMass } = options;
|
|
182
|
+
this.propsGetMass = getMass;
|
|
182
183
|
this.updateCfg(options);
|
|
183
184
|
}
|
|
184
185
|
|
|
@@ -193,7 +194,7 @@ export class Force2Layout extends Base {
|
|
|
193
194
|
// 如果传入了需要叶子节点聚类
|
|
194
195
|
if (leafCluster) {
|
|
195
196
|
sameTypeLeafMap = this.getSameTypeLeafMap() || {};
|
|
196
|
-
const relativeNodesType = Array.from(new Set(nodes?.map(node => node[nodeClusterBy])))|| [];
|
|
197
|
+
const relativeNodesType = Array.from(new Set(nodes?.map(node => node[nodeClusterBy]))) || [];
|
|
197
198
|
centripetalOptions = {
|
|
198
199
|
single: 100,
|
|
199
200
|
leaf: (node, nodes, edges) => {
|
|
@@ -298,7 +299,7 @@ export class Force2Layout extends Base {
|
|
|
298
299
|
const self = this;
|
|
299
300
|
self.stop();
|
|
300
301
|
const { nodes, edges, defSpringLen } = self;
|
|
301
|
-
|
|
302
|
+
|
|
302
303
|
self.judgingDistance = 0;
|
|
303
304
|
|
|
304
305
|
if (!nodes || nodes.length === 0) {
|
|
@@ -324,7 +325,9 @@ export class Force2Layout extends Base {
|
|
|
324
325
|
return;
|
|
325
326
|
}
|
|
326
327
|
self.degreesMap = getDegreeMap(nodes, edges);
|
|
327
|
-
if (
|
|
328
|
+
if (self.propsGetMass) {
|
|
329
|
+
self.getMass = self.propsGetMass;
|
|
330
|
+
} else {
|
|
328
331
|
self.getMass = (d) => {
|
|
329
332
|
let massWeight = 1;
|
|
330
333
|
if (isNumber(d.mass)) massWeight = d.mass;
|
|
@@ -352,7 +355,7 @@ export class Force2Layout extends Base {
|
|
|
352
355
|
if (d.size) {
|
|
353
356
|
if (isArray(d.size)) {
|
|
354
357
|
return Math.max(d.size[0], d.size[1]) + nodeSpacingFunc(d);
|
|
355
|
-
}
|
|
358
|
+
} if (isObject(d.size)) {
|
|
356
359
|
return Math.max(d.size.width, d.size.height) + nodeSpacingFunc(d);
|
|
357
360
|
}
|
|
358
361
|
return (d.size as number) + nodeSpacingFunc(d);
|
|
@@ -418,7 +421,7 @@ export class Force2Layout extends Base {
|
|
|
418
421
|
source: sourceNode,
|
|
419
422
|
target: targetNode
|
|
420
423
|
},
|
|
421
|
-
sourceNode,
|
|
424
|
+
sourceNode,
|
|
422
425
|
targetNode
|
|
423
426
|
) : self.linkDistance(edge, sourceNode, targetNode) || 1 + ((nodeSize(sourceNode) + nodeSize(sourceNode)) || 0) / 2
|
|
424
427
|
})
|
|
@@ -427,7 +430,7 @@ export class Force2Layout extends Base {
|
|
|
427
430
|
|
|
428
431
|
this.getCentripetalOptions();
|
|
429
432
|
|
|
430
|
-
self.onLayoutEnd = self.onLayoutEnd || (() => {});
|
|
433
|
+
self.onLayoutEnd = self.onLayoutEnd || (() => { });
|
|
431
434
|
|
|
432
435
|
self.run();
|
|
433
436
|
}
|
|
@@ -448,7 +451,7 @@ export class Force2Layout extends Base {
|
|
|
448
451
|
const silence = !animate;
|
|
449
452
|
if (workerEnabled || silence) {
|
|
450
453
|
let usedIter = 0;
|
|
451
|
-
for (let i = 0; (self.judgingDistance > minMovement || i < 1) &&
|
|
454
|
+
for (let i = 0; (self.judgingDistance > minMovement || i < 1) && i < maxIter; i++) {
|
|
452
455
|
usedIter = i;
|
|
453
456
|
self.runOneStep(i, velArray);
|
|
454
457
|
}
|
|
@@ -498,7 +501,7 @@ export class Force2Layout extends Base {
|
|
|
498
501
|
const vx = accArray[2 * i];
|
|
499
502
|
const vy = accArray[2 * i + 1];
|
|
500
503
|
const speed2 = vx * vx + vy * vy;
|
|
501
|
-
const { mass = 1} = nodeMap[node.id].data.layout.force;
|
|
504
|
+
const { mass = 1 } = nodeMap[node.id].data.layout.force;
|
|
502
505
|
energy += mass * speed2 * 0.5; // p = 1/2*(mv^2)
|
|
503
506
|
});
|
|
504
507
|
|
|
@@ -586,7 +589,7 @@ export class Force2Layout extends Base {
|
|
|
586
589
|
|
|
587
590
|
if (centripetalOptions) {
|
|
588
591
|
const { leaf, single, others, center: centriCenter } = centripetalOptions;
|
|
589
|
-
const { x: centriX, y: centriY, centerStrength } = centriCenter?.(node, nodes, edges, width, height) || { x: 0, y: 0, centerStrength: 0};
|
|
592
|
+
const { x: centriX, y: centriY, centerStrength } = centriCenter?.(node, nodes, edges, width, height) || { x: 0, y: 0, centerStrength: 0 };
|
|
590
593
|
if (!isNumber(centriX) || !isNumber(centriY)) continue;
|
|
591
594
|
const vx = (node.x - centriX) / mass;
|
|
592
595
|
const vy = (node.y - centriY) / mass;
|
|
@@ -603,7 +606,7 @@ export class Force2Layout extends Base {
|
|
|
603
606
|
accArray[idx + 1] -= singleStrength * vy;
|
|
604
607
|
continue;
|
|
605
608
|
}
|
|
606
|
-
|
|
609
|
+
|
|
607
610
|
// 没有出度或没有入度,都认为是叶子节点
|
|
608
611
|
if (inDegree === 0 || outDegree === 0) {
|
|
609
612
|
const leafStrength = leaf(node, nodes, edges);
|
|
@@ -677,7 +680,7 @@ export class Force2Layout extends Base {
|
|
|
677
680
|
node.x = node.fx;
|
|
678
681
|
node.y = node.fy;
|
|
679
682
|
mappedNode.x = node.x;
|
|
680
|
-
mappedNode.y = node.y;
|
|
683
|
+
mappedNode.y = node.y;
|
|
681
684
|
return;
|
|
682
685
|
}
|
|
683
686
|
const distX = velArray[2 * i] * stepInterval;
|
|
@@ -685,7 +688,7 @@ export class Force2Layout extends Base {
|
|
|
685
688
|
node.x += distX;
|
|
686
689
|
node.y += distY;
|
|
687
690
|
mappedNode.x = node.x;
|
|
688
|
-
mappedNode.y = node.y;
|
|
691
|
+
mappedNode.y = node.y;
|
|
689
692
|
|
|
690
693
|
const distanceMagnitude = Math.sqrt(distX * distX + distY * distY);
|
|
691
694
|
switch (distanceThresholdMode) {
|
package/src/util/gpu.ts
CHANGED
|
@@ -63,7 +63,6 @@ export const buildTextureData = (nodes: OutNode[], edges: Edge[]): {
|
|
|
63
63
|
const offset: number = dataArray.length;
|
|
64
64
|
const dests = nodeDict[i];
|
|
65
65
|
const len = dests.length;
|
|
66
|
-
console.log('dests', dests, len)
|
|
67
66
|
dataArray[i * 4 + 2] = offset;
|
|
68
67
|
dataArray[i * 4 + 3] = len;
|
|
69
68
|
maxEdgePerVetex = Math.max(maxEdgePerVetex, len);
|
package/src/util/math.ts
CHANGED
|
@@ -111,19 +111,17 @@ export const getAdjMatrix = (data: Model, directed: boolean): Matrix[] => {
|
|
|
111
111
|
});
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
}
|
|
126
|
-
|
|
114
|
+
edges?.forEach((e) => {
|
|
115
|
+
const source = getEdgeTerminal(e, 'source');
|
|
116
|
+
const target = getEdgeTerminal(e, 'target');
|
|
117
|
+
const sIndex = nodeMap[source as string];
|
|
118
|
+
const tIndex = nodeMap[target as string];
|
|
119
|
+
if (sIndex === undefined || tIndex === undefined) return;
|
|
120
|
+
matrix[sIndex][tIndex] = 1;
|
|
121
|
+
if (!directed) {
|
|
122
|
+
matrix[tIndex][sIndex] = 1;
|
|
123
|
+
}
|
|
124
|
+
});
|
|
127
125
|
return matrix;
|
|
128
126
|
};
|
|
129
127
|
|
package/src/util/object.ts
CHANGED
|
@@ -15,7 +15,7 @@ export const clone = <T>(target: T): T => {
|
|
|
15
15
|
});
|
|
16
16
|
return cp.map((n: any) => clone<any>(n)) as any;
|
|
17
17
|
}
|
|
18
|
-
if (typeof target === 'object' && target
|
|
18
|
+
if (typeof target === 'object' && Object.keys(target).length) {
|
|
19
19
|
const cp = { ...(target as { [key: string]: any }) } as {
|
|
20
20
|
[key: string]: any
|
|
21
21
|
};
|