@antv/g6 5.0.28 → 5.0.30
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/g6.min.js +29 -29
- package/dist/lib/elements/combos/base-combo.d.ts +0 -2
- package/dist/lib/exports.d.ts +2 -1
- package/dist/lib/layouts/fishbone.d.ts +72 -0
- package/dist/lib/layouts/index.d.ts +2 -0
- package/dist/lib/runtime/data.d.ts +28 -0
- package/dist/lib/runtime/element.d.ts +0 -9
- package/dist/lib/utils/z-index.d.ts +8 -0
- package/dist/lib/version.d.ts +1 -1
- package/esm/elements/combos/base-combo.d.ts +0 -2
- package/esm/elements/combos/base-combo.js +1 -7
- package/esm/elements/combos/base-combo.js.map +1 -1
- package/esm/exports.d.ts +2 -1
- package/esm/exports.js +1 -1
- package/esm/exports.js.map +1 -1
- package/esm/layouts/fishbone.d.ts +72 -0
- package/esm/layouts/fishbone.js +209 -0
- package/esm/layouts/fishbone.js.map +1 -0
- package/esm/layouts/index.d.ts +2 -0
- package/esm/layouts/index.js +1 -0
- package/esm/layouts/index.js.map +1 -1
- package/esm/plugins/background/index.js +1 -0
- package/esm/plugins/background/index.js.map +1 -1
- package/esm/plugins/edge-filter-lens/index.js +1 -0
- package/esm/plugins/edge-filter-lens/index.js.map +1 -1
- package/esm/preset.js +2 -0
- package/esm/preset.js.map +1 -1
- package/esm/registry/build-in.js +3 -2
- package/esm/registry/build-in.js.map +1 -1
- package/esm/runtime/canvas.js +4 -1
- package/esm/runtime/canvas.js.map +1 -1
- package/esm/runtime/data.d.ts +28 -0
- package/esm/runtime/data.js +131 -16
- package/esm/runtime/data.js.map +1 -1
- package/esm/runtime/element.d.ts +0 -9
- package/esm/runtime/element.js +7 -48
- package/esm/runtime/element.js.map +1 -1
- package/esm/runtime/graph.js +8 -9
- package/esm/runtime/graph.js.map +1 -1
- package/esm/utils/z-index.d.ts +8 -0
- package/esm/utils/z-index.js +11 -0
- package/esm/utils/z-index.js.map +1 -0
- package/esm/version.d.ts +1 -1
- package/esm/version.js +1 -1
- package/lib/elements/combos/base-combo.d.ts +0 -2
- package/lib/elements/combos/base-combo.js +1 -7
- package/lib/elements/combos/base-combo.js.map +1 -1
- package/lib/exports.d.ts +2 -1
- package/lib/exports.js +3 -2
- package/lib/exports.js.map +1 -1
- package/lib/layouts/fishbone.d.ts +72 -0
- package/lib/layouts/fishbone.js +213 -0
- package/lib/layouts/fishbone.js.map +1 -0
- package/lib/layouts/index.d.ts +2 -0
- package/lib/layouts/index.js +3 -1
- package/lib/layouts/index.js.map +1 -1
- package/lib/plugins/background/index.js +1 -0
- package/lib/plugins/background/index.js.map +1 -1
- package/lib/plugins/edge-filter-lens/index.js +1 -0
- package/lib/plugins/edge-filter-lens/index.js.map +1 -1
- package/lib/preset.js +2 -0
- package/lib/preset.js.map +1 -1
- package/lib/registry/build-in.js +2 -1
- package/lib/registry/build-in.js.map +1 -1
- package/lib/runtime/canvas.js +4 -1
- package/lib/runtime/canvas.js.map +1 -1
- package/lib/runtime/data.d.ts +28 -0
- package/lib/runtime/data.js +130 -15
- package/lib/runtime/data.js.map +1 -1
- package/lib/runtime/element.d.ts +0 -9
- package/lib/runtime/element.js +7 -48
- package/lib/runtime/element.js.map +1 -1
- package/lib/runtime/graph.js +8 -9
- package/lib/runtime/graph.js.map +1 -1
- package/lib/utils/z-index.d.ts +8 -0
- package/lib/utils/z-index.js +14 -0
- package/lib/utils/z-index.js.map +1 -0
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/package.json +6 -6
- package/src/elements/combos/base-combo.ts +1 -8
- package/src/exports.ts +2 -0
- package/src/layouts/fishbone.ts +295 -0
- package/src/layouts/index.ts +2 -0
- package/src/plugins/background/index.ts +1 -0
- package/src/plugins/edge-filter-lens/index.ts +1 -0
- package/src/preset.ts +3 -0
- package/src/registry/build-in.ts +3 -1
- package/src/runtime/canvas.ts +5 -1
- package/src/runtime/data.ts +145 -16
- package/src/runtime/element.ts +5 -55
- package/src/runtime/graph.ts +8 -8
- package/src/utils/z-index.ts +11 -0
- package/src/version.ts +1 -1
package/src/runtime/canvas.ts
CHANGED
|
@@ -391,11 +391,15 @@ function configCanvasDom(layers: Record<CanvasLayer, GCanvas>) {
|
|
|
391
391
|
// 浏览器环境下,设置画布样式
|
|
392
392
|
// Set canvas style in browser environment
|
|
393
393
|
if (domElement?.style) {
|
|
394
|
-
domElement.style.
|
|
394
|
+
domElement.style.gridArea = '1 / 1 / 2 / 2';
|
|
395
395
|
domElement.style.outline = 'none';
|
|
396
396
|
domElement.tabIndex = 1;
|
|
397
397
|
|
|
398
398
|
if (layer !== 'main') domElement.style.pointerEvents = 'none';
|
|
399
399
|
}
|
|
400
|
+
|
|
401
|
+
if (domElement?.parentElement) {
|
|
402
|
+
domElement.parentElement.style.display = 'grid';
|
|
403
|
+
}
|
|
400
404
|
});
|
|
401
405
|
}
|
package/src/runtime/data.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Graph as GraphLib } from '@antv/graphlib';
|
|
2
|
-
import {
|
|
2
|
+
import { isNumber, isUndefined, uniq } from '@antv/util';
|
|
3
3
|
import { COMBO_KEY, ChangeType, TREE_KEY } from '../constants';
|
|
4
4
|
import type { ComboData, EdgeData, GraphData, NodeData } from '../spec';
|
|
5
5
|
import type {
|
|
@@ -20,6 +20,7 @@ import type {
|
|
|
20
20
|
} from '../types';
|
|
21
21
|
import type { EdgeDirection } from '../types/edge';
|
|
22
22
|
import type { ElementType } from '../types/element';
|
|
23
|
+
import { isCollapsed } from '../utils/collapsibility';
|
|
23
24
|
import { cloneElementData, isElementDataEqual, mergeElementsData } from '../utils/data';
|
|
24
25
|
import { arrayDiff } from '../utils/diff';
|
|
25
26
|
import { toG6Data, toGraphlibData } from '../utils/graphlib';
|
|
@@ -104,6 +105,10 @@ export class DataController {
|
|
|
104
105
|
this.batchCount--;
|
|
105
106
|
}
|
|
106
107
|
|
|
108
|
+
protected isBatching() {
|
|
109
|
+
return this.batchCount > 0;
|
|
110
|
+
}
|
|
111
|
+
|
|
107
112
|
/**
|
|
108
113
|
* <zh/> 执行操作而不会留下记录
|
|
109
114
|
*
|
|
@@ -301,23 +306,28 @@ export class DataController {
|
|
|
301
306
|
const comboDiff = arrayDiff(originalCombos, modifiedCombos, (combo) => idOf(combo), isElementDataEqual);
|
|
302
307
|
|
|
303
308
|
this.batch(() => {
|
|
304
|
-
|
|
309
|
+
const dataToAdd = {
|
|
305
310
|
nodes: nodeDiff.enter,
|
|
306
311
|
edges: edgeDiff.enter,
|
|
307
312
|
combos: comboDiff.enter,
|
|
308
|
-
}
|
|
313
|
+
};
|
|
314
|
+
this.addData(dataToAdd);
|
|
315
|
+
this.computeZIndex(dataToAdd, 'add', true);
|
|
309
316
|
|
|
310
|
-
|
|
317
|
+
const dataToUpdate = {
|
|
311
318
|
nodes: nodeDiff.update,
|
|
312
319
|
edges: edgeDiff.update,
|
|
313
320
|
combos: comboDiff.update,
|
|
314
|
-
}
|
|
321
|
+
};
|
|
322
|
+
this.updateData(dataToUpdate);
|
|
323
|
+
this.computeZIndex(dataToUpdate, 'update', true);
|
|
315
324
|
|
|
316
|
-
|
|
325
|
+
const dataToRemove = {
|
|
317
326
|
nodes: nodeDiff.exit.map(idOf),
|
|
318
327
|
edges: edgeDiff.exit.map(idOf),
|
|
319
328
|
combos: comboDiff.exit.map(idOf),
|
|
320
|
-
}
|
|
329
|
+
};
|
|
330
|
+
this.removeData(dataToRemove);
|
|
321
331
|
});
|
|
322
332
|
}
|
|
323
333
|
|
|
@@ -329,6 +339,7 @@ export class DataController {
|
|
|
329
339
|
this.addNodeData(nodes);
|
|
330
340
|
this.addEdgeData(edges);
|
|
331
341
|
});
|
|
342
|
+
this.computeZIndex(data, 'add');
|
|
332
343
|
}
|
|
333
344
|
|
|
334
345
|
public addNodeData(nodes: NodeData[] = []) {
|
|
@@ -340,6 +351,8 @@ export class DataController {
|
|
|
340
351
|
}),
|
|
341
352
|
);
|
|
342
353
|
this.updateNodeLikeHierarchy(nodes);
|
|
354
|
+
|
|
355
|
+
this.computeZIndex({ nodes }, 'add');
|
|
343
356
|
}
|
|
344
357
|
|
|
345
358
|
public addEdgeData(edges: EdgeData[] = []) {
|
|
@@ -350,6 +363,8 @@ export class DataController {
|
|
|
350
363
|
return toGraphlibData(edge);
|
|
351
364
|
}),
|
|
352
365
|
);
|
|
366
|
+
|
|
367
|
+
this.computeZIndex({ edges }, 'add');
|
|
353
368
|
}
|
|
354
369
|
|
|
355
370
|
public addComboData(combos: ComboData[] = []) {
|
|
@@ -369,6 +384,8 @@ export class DataController {
|
|
|
369
384
|
);
|
|
370
385
|
|
|
371
386
|
this.updateNodeLikeHierarchy(combos);
|
|
387
|
+
|
|
388
|
+
this.computeZIndex({ combos }, 'add');
|
|
372
389
|
}
|
|
373
390
|
|
|
374
391
|
public addChildrenData(parentId: ID, childrenData: NodeData[]) {
|
|
@@ -379,6 +396,120 @@ export class DataController {
|
|
|
379
396
|
this.addEdgeData(childrenId.map((childId) => ({ source: parentId, target: childId })));
|
|
380
397
|
}
|
|
381
398
|
|
|
399
|
+
/**
|
|
400
|
+
* <zh/> 计算 zIndex
|
|
401
|
+
*
|
|
402
|
+
* <en/> Calculate zIndex
|
|
403
|
+
* @param data - <zh/> 新增的数据 | <en/> newly added data
|
|
404
|
+
* @param type - <zh/> 操作类型 | <en/> operation type
|
|
405
|
+
* @param force - <zh/> 忽略批处理 | <en/> ignore batch processing
|
|
406
|
+
* @remarks
|
|
407
|
+
* <zh/> 调用该函数的情况:
|
|
408
|
+
* - 新增元素
|
|
409
|
+
* - 更新节点/组合的 combo
|
|
410
|
+
* - 更新节点的 children
|
|
411
|
+
*
|
|
412
|
+
* <en/> The situation of calling this function:
|
|
413
|
+
* - Add element
|
|
414
|
+
* - Update the combo of the node/combo
|
|
415
|
+
* - Update the children of the node
|
|
416
|
+
*/
|
|
417
|
+
protected computeZIndex(data: PartialGraphData, type: 'add' | 'update', force = false) {
|
|
418
|
+
if (!force && this.isBatching()) return;
|
|
419
|
+
this.batch(() => {
|
|
420
|
+
const { nodes = [], edges = [], combos = [] } = data;
|
|
421
|
+
|
|
422
|
+
combos.forEach((combo) => {
|
|
423
|
+
const id = idOf(combo);
|
|
424
|
+
if (type === 'add' && isNumber(combo.style?.zIndex)) return;
|
|
425
|
+
if (type === 'update' && !('combo' in combo)) return;
|
|
426
|
+
|
|
427
|
+
const parent = this.getParentData(id, COMBO_KEY);
|
|
428
|
+
const zIndex = parent ? (parent.style?.zIndex ?? 0) + 1 : 0;
|
|
429
|
+
|
|
430
|
+
this.preventUpdateNodeLikeHierarchy(() => {
|
|
431
|
+
this.updateComboData([{ id, style: { zIndex } }]);
|
|
432
|
+
});
|
|
433
|
+
});
|
|
434
|
+
|
|
435
|
+
nodes.forEach((node) => {
|
|
436
|
+
const id = idOf(node);
|
|
437
|
+
if (type === 'add' && isNumber(node.style?.zIndex)) return;
|
|
438
|
+
if (type === 'update' && !('combo' in node) && !('children' in node)) return;
|
|
439
|
+
|
|
440
|
+
let zIndex = 0;
|
|
441
|
+
|
|
442
|
+
const comboParent = this.getParentData(id, COMBO_KEY);
|
|
443
|
+
if (comboParent) {
|
|
444
|
+
zIndex = (comboParent.style?.zIndex || 0) + 1;
|
|
445
|
+
} else {
|
|
446
|
+
const nodeParent = this.getParentData(id, TREE_KEY);
|
|
447
|
+
if (nodeParent) zIndex = nodeParent?.style?.zIndex || 0;
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
this.preventUpdateNodeLikeHierarchy(() => {
|
|
451
|
+
this.updateNodeData([{ id, style: { zIndex } }]);
|
|
452
|
+
});
|
|
453
|
+
});
|
|
454
|
+
|
|
455
|
+
edges.forEach((edge) => {
|
|
456
|
+
if (isNumber(edge.style?.zIndex)) return;
|
|
457
|
+
|
|
458
|
+
let { id, source, target } = edge;
|
|
459
|
+
if (!id) id = idOf(edge);
|
|
460
|
+
else {
|
|
461
|
+
const datum = this.getEdgeDatum(id);
|
|
462
|
+
source = datum.source;
|
|
463
|
+
target = datum.target;
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
if (!source || !target) return;
|
|
467
|
+
|
|
468
|
+
const sourceZIndex = this.getNodeLikeDatum(source)?.style?.zIndex || 0;
|
|
469
|
+
const targetZIndex = this.getNodeLikeDatum(target)?.style?.zIndex || 0;
|
|
470
|
+
|
|
471
|
+
this.updateEdgeData([{ id: idOf(edge), style: { zIndex: Math.max(sourceZIndex, targetZIndex) - 1 } }]);
|
|
472
|
+
});
|
|
473
|
+
});
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
/**
|
|
477
|
+
* <zh/> 计算元素置顶后的 zIndex
|
|
478
|
+
*
|
|
479
|
+
* <en/> Calculate the zIndex after the element is placed on top
|
|
480
|
+
* @param id - <zh/> 元素 ID | <en/> ID of the element
|
|
481
|
+
* @returns <zh/> zIndex | <en/> zIndex
|
|
482
|
+
*/
|
|
483
|
+
public getFrontZIndex(id: ID) {
|
|
484
|
+
const elementType = this.getElementType(id);
|
|
485
|
+
const elementData = this.getElementDataById(id);
|
|
486
|
+
const data = this.getData();
|
|
487
|
+
|
|
488
|
+
// 排除当前元素 / Exclude the current element
|
|
489
|
+
Object.assign(data, {
|
|
490
|
+
[`${elementType}s`]: data[`${elementType}s`].filter((element) => idOf(element) !== id),
|
|
491
|
+
});
|
|
492
|
+
|
|
493
|
+
if (elementType === 'combo') {
|
|
494
|
+
// 如果 combo 展开,则排除 combo 的子节点/combo 及内部边
|
|
495
|
+
// If the combo is expanded, exclude the child nodes/combos of the combo and the internal edges
|
|
496
|
+
if (!isCollapsed(elementData as ComboData)) {
|
|
497
|
+
const ancestorIds = new Set(this.getAncestorsData(id, COMBO_KEY).map(idOf));
|
|
498
|
+
data.nodes = data.nodes.filter((element) => !ancestorIds.has(idOf(element)));
|
|
499
|
+
data.combos = data.combos.filter((element) => !ancestorIds.has(idOf(element)));
|
|
500
|
+
data.edges = data.edges.filter(({ source, target }) => !ancestorIds.has(source) && !ancestorIds.has(target));
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
return Math.max(
|
|
505
|
+
elementData.style?.zIndex || 0,
|
|
506
|
+
0,
|
|
507
|
+
...Object.values(data)
|
|
508
|
+
.flat()
|
|
509
|
+
.map((datum) => (datum?.style?.zIndex || 0) + 1),
|
|
510
|
+
);
|
|
511
|
+
}
|
|
512
|
+
|
|
382
513
|
protected updateNodeLikeHierarchy(data: NodeLikeData[]) {
|
|
383
514
|
if (!this.enableUpdateNodeLikeHierarchy) return;
|
|
384
515
|
const { model } = this;
|
|
@@ -427,6 +558,7 @@ export class DataController {
|
|
|
427
558
|
this.updateComboData(combos);
|
|
428
559
|
this.updateEdgeData(edges);
|
|
429
560
|
});
|
|
561
|
+
this.computeZIndex(data, 'update');
|
|
430
562
|
}
|
|
431
563
|
|
|
432
564
|
public updateNodeData(nodes: PartialNodeLikeData<NodeData>[] = []) {
|
|
@@ -447,6 +579,8 @@ export class DataController {
|
|
|
447
579
|
|
|
448
580
|
this.updateNodeLikeHierarchy(modifiedNodes);
|
|
449
581
|
});
|
|
582
|
+
|
|
583
|
+
this.computeZIndex({ nodes }, 'update');
|
|
450
584
|
}
|
|
451
585
|
|
|
452
586
|
/**
|
|
@@ -496,6 +630,8 @@ export class DataController {
|
|
|
496
630
|
model.mergeEdgeData(id, updatedData);
|
|
497
631
|
});
|
|
498
632
|
});
|
|
633
|
+
|
|
634
|
+
this.computeZIndex({ edges }, 'update');
|
|
499
635
|
}
|
|
500
636
|
|
|
501
637
|
public updateComboData(combos: PartialNodeLikeData<ComboData>[] = []) {
|
|
@@ -516,6 +652,8 @@ export class DataController {
|
|
|
516
652
|
|
|
517
653
|
this.updateNodeLikeHierarchy(modifiedCombos);
|
|
518
654
|
});
|
|
655
|
+
|
|
656
|
+
this.computeZIndex({ combos }, 'update');
|
|
519
657
|
}
|
|
520
658
|
|
|
521
659
|
/**
|
|
@@ -532,15 +670,6 @@ export class DataController {
|
|
|
532
670
|
const elementData = this.getNodeLikeDatum(id);
|
|
533
671
|
const originalParentId = parentIdOf(elementData);
|
|
534
672
|
|
|
535
|
-
if (parent) {
|
|
536
|
-
const parentData = this.getNodeLikeDatum(parent);
|
|
537
|
-
if (parentData.style?.zIndex !== undefined) {
|
|
538
|
-
const zIndex = get(parentData, ['style', 'zIndex'], 0) + (this.isCombo(parent) ? 1 : 0);
|
|
539
|
-
set(elementData, ['style', 'zIndex'], zIndex);
|
|
540
|
-
}
|
|
541
|
-
}
|
|
542
|
-
// Sync data
|
|
543
|
-
|
|
544
673
|
if (originalParentId !== parent && hierarchyKey === COMBO_KEY) {
|
|
545
674
|
const modifiedDatum = { id, combo: parent };
|
|
546
675
|
if (this.isCombo(id)) this.syncComboDatum(modifiedDatum);
|
package/src/runtime/element.ts
CHANGED
|
@@ -228,12 +228,6 @@ export class ElementController {
|
|
|
228
228
|
return this.elementMap[id] as T;
|
|
229
229
|
}
|
|
230
230
|
|
|
231
|
-
public getElementZIndex(id: ID): number {
|
|
232
|
-
const element = this.getElement(id);
|
|
233
|
-
if (!element) return 0;
|
|
234
|
-
return element.style.zIndex ?? 0;
|
|
235
|
-
}
|
|
236
|
-
|
|
237
231
|
public getNodes() {
|
|
238
232
|
return this.context.model.getNodeData().map(({ id }) => this.elementMap[id]) as Node[];
|
|
239
233
|
}
|
|
@@ -393,11 +387,11 @@ export class ElementController {
|
|
|
393
387
|
|
|
394
388
|
this.emit(new ElementLifeCycleEvent(GraphEvent.BEFORE_ELEMENT_CREATE, elementType, datum), context);
|
|
395
389
|
|
|
396
|
-
if (context.stage === 'expand') {
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
}
|
|
390
|
+
// if (context.stage === 'expand') {
|
|
391
|
+
// // 如果是展开的元素,需要将其 zIndex 提升至目标元素的上层
|
|
392
|
+
// const targetZIndex = this.getElementZIndex(context.target!);
|
|
393
|
+
// if (!style.zIndex || style.zIndex < targetZIndex) style.zIndex = targetZIndex + (style.zIndex ?? 0);
|
|
394
|
+
// }
|
|
401
395
|
const element = this.container.appendChild(
|
|
402
396
|
new Ctor({
|
|
403
397
|
id,
|
|
@@ -794,50 +788,6 @@ export class ElementController {
|
|
|
794
788
|
)?.finished;
|
|
795
789
|
}
|
|
796
790
|
|
|
797
|
-
/**
|
|
798
|
-
* <zh/> 计算元素置顶后的 zIndex
|
|
799
|
-
*
|
|
800
|
-
* <en/> Calculate the zIndex after the element is placed on top
|
|
801
|
-
* @param id - <zh/> 元素 ID | <en/> ID of the element
|
|
802
|
-
* @returns <zh/> zIndex | <en/> zIndex
|
|
803
|
-
*/
|
|
804
|
-
public getFrontZIndex(id: ID) {
|
|
805
|
-
const { model } = this.context;
|
|
806
|
-
|
|
807
|
-
const elementType = model.getElementType(id);
|
|
808
|
-
const elementData = model.getElementDataById(id);
|
|
809
|
-
const data = model.getData();
|
|
810
|
-
|
|
811
|
-
// 排除当前元素 / Exclude the current element
|
|
812
|
-
Object.assign(data, {
|
|
813
|
-
[`${elementType}s`]: data[`${elementType}s`].filter((element) => idOf(element) !== id),
|
|
814
|
-
});
|
|
815
|
-
|
|
816
|
-
if (elementType === 'combo') {
|
|
817
|
-
// 如果 combo 展开,则排除 combo 的子节点/combo 及内部边
|
|
818
|
-
// If the combo is expanded, exclude the child nodes/combos of the combo and the internal edges
|
|
819
|
-
if (!isCollapsed(elementData as ComboData)) {
|
|
820
|
-
const ancestors = model.getAncestorsData(id, COMBO_KEY).map(idOf);
|
|
821
|
-
data.nodes = data.nodes.filter((element) => !ancestors.includes(idOf(element)));
|
|
822
|
-
data.combos = data.combos.filter((element) => !ancestors.includes(idOf(element)));
|
|
823
|
-
data.edges = data.edges.filter(
|
|
824
|
-
({ source, target }) => ancestors.includes(source) && ancestors.includes(target),
|
|
825
|
-
);
|
|
826
|
-
}
|
|
827
|
-
}
|
|
828
|
-
return (
|
|
829
|
-
Math.max(
|
|
830
|
-
0,
|
|
831
|
-
...Object.values(data)
|
|
832
|
-
.flat()
|
|
833
|
-
.map((datum) => {
|
|
834
|
-
const id = idOf(datum);
|
|
835
|
-
return this.getElementZIndex(id);
|
|
836
|
-
}),
|
|
837
|
-
) + 1
|
|
838
|
-
);
|
|
839
|
-
}
|
|
840
|
-
|
|
841
791
|
public destroy() {
|
|
842
792
|
this.container.destroy();
|
|
843
793
|
this.elementMap = {};
|
package/src/runtime/graph.ts
CHANGED
|
@@ -46,6 +46,7 @@ import { GraphLifeCycleEvent, emit } from '../utils/event';
|
|
|
46
46
|
import { idOf } from '../utils/id';
|
|
47
47
|
import { format } from '../utils/print';
|
|
48
48
|
import { subtract } from '../utils/vector';
|
|
49
|
+
import { getZIndexOf } from '../utils/z-index';
|
|
49
50
|
import { Animation } from './animation';
|
|
50
51
|
import { BatchController } from './batch';
|
|
51
52
|
import { BehaviorController } from './behavior';
|
|
@@ -1674,21 +1675,21 @@ export class Graph extends EventEmitter {
|
|
|
1674
1675
|
*/
|
|
1675
1676
|
public async frontElement(id: ID | ID[]): Promise<void> {
|
|
1676
1677
|
const ids = Array.isArray(id) ? id : [id];
|
|
1677
|
-
const { model
|
|
1678
|
+
const { model } = this.context;
|
|
1678
1679
|
const zIndexes: Record<ID, number> = {};
|
|
1679
1680
|
|
|
1680
1681
|
ids.map((_id) => {
|
|
1681
|
-
const zIndex =
|
|
1682
|
+
const zIndex = model.getFrontZIndex(_id);
|
|
1682
1683
|
const elementType = model.getElementType(_id);
|
|
1683
1684
|
if (elementType === 'combo') {
|
|
1684
1685
|
const ancestor = model.getAncestorsData(_id, COMBO_KEY).at(-1) || this.getComboData(_id);
|
|
1685
|
-
const
|
|
1686
|
-
const delta = zIndex -
|
|
1687
|
-
|
|
1686
|
+
const descendants = [ancestor, ...model.getDescendantsData(idOf(ancestor))];
|
|
1687
|
+
const delta = zIndex - getZIndexOf(ancestor);
|
|
1688
|
+
descendants.forEach((combo) => {
|
|
1688
1689
|
zIndexes[idOf(combo)] = this.getElementZIndex(idOf(combo)) + delta;
|
|
1689
1690
|
});
|
|
1690
1691
|
|
|
1691
|
-
const { internal } = getSubgraphRelatedEdges(
|
|
1692
|
+
const { internal } = getSubgraphRelatedEdges(descendants.map(idOf), (id) => model.getRelatedEdgesData(id));
|
|
1692
1693
|
internal.forEach((edge) => {
|
|
1693
1694
|
const edgeId = idOf(edge);
|
|
1694
1695
|
zIndexes[edgeId] = this.getElementZIndex(edgeId) + delta;
|
|
@@ -1708,8 +1709,7 @@ export class Graph extends EventEmitter {
|
|
|
1708
1709
|
* @apiCategory element
|
|
1709
1710
|
*/
|
|
1710
1711
|
public getElementZIndex(id: ID): number {
|
|
1711
|
-
|
|
1712
|
-
return model.getElementDataById(id)?.style?.zIndex ?? element!.getElementZIndex(id);
|
|
1712
|
+
return getZIndexOf(this.context.model.getElementDataById(id));
|
|
1713
1713
|
}
|
|
1714
1714
|
|
|
1715
1715
|
/**
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ElementDatum } from '../types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* <zh/> 获取元素的 zIndex
|
|
5
|
+
* <en/> Get the zIndex of the element
|
|
6
|
+
* @param datum - <zh/> 元素数据 | <en/> element data
|
|
7
|
+
* @returns - <zh/> zIndex | <en/> zIndex
|
|
8
|
+
*/
|
|
9
|
+
export function getZIndexOf(datum: ElementDatum): number {
|
|
10
|
+
return datum?.style?.zIndex || 0;
|
|
11
|
+
}
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '5.0.
|
|
1
|
+
export const version = '5.0.30';
|