@antv/g6 5.0.49 → 5.0.51
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/README.md +2 -1
- package/README.zh-CN.md +2 -1
- package/dist/g6.min.js +38 -59
- package/dist/lib/behaviors/brush-select.d.ts +2 -3
- package/dist/lib/behaviors/click-select.d.ts +2 -2
- package/dist/lib/behaviors/drag-element.d.ts +21 -2
- package/dist/lib/behaviors/focus-element.d.ts +18 -0
- package/dist/lib/exports.d.ts +1 -1
- package/dist/lib/layouts/types.d.ts +9 -1
- package/dist/lib/plugins/bubble-sets.d.ts +1 -1
- package/dist/lib/plugins/index.d.ts +2 -0
- package/dist/lib/plugins/legend.d.ts +10 -2
- package/dist/lib/plugins/minimap/index.d.ts +7 -4
- package/dist/lib/plugins/title/index.d.ts +85 -0
- package/dist/lib/runtime/element.d.ts +8 -0
- package/dist/lib/runtime/graph.d.ts +27 -0
- package/dist/lib/runtime/layout.d.ts +2 -1
- package/dist/lib/utils/data.d.ts +9 -0
- package/dist/lib/utils/element.d.ts +1 -1
- package/dist/lib/utils/vector.d.ts +9 -0
- package/dist/lib/version.d.ts +1 -1
- package/esm/behaviors/brush-select.d.ts +2 -3
- package/esm/behaviors/brush-select.js +14 -5
- package/esm/behaviors/brush-select.js.map +1 -1
- package/esm/behaviors/click-select.d.ts +2 -2
- package/esm/behaviors/click-select.js.map +1 -1
- package/esm/behaviors/create-edge.js +5 -1
- package/esm/behaviors/create-edge.js.map +1 -1
- package/esm/behaviors/drag-canvas.js +2 -7
- package/esm/behaviors/drag-canvas.js.map +1 -1
- package/esm/behaviors/drag-element-force.js +1 -1
- package/esm/behaviors/drag-element-force.js.map +1 -1
- package/esm/behaviors/drag-element.d.ts +21 -2
- package/esm/behaviors/drag-element.js +24 -3
- package/esm/behaviors/drag-element.js.map +1 -1
- package/esm/behaviors/focus-element.d.ts +18 -0
- package/esm/behaviors/focus-element.js +18 -1
- package/esm/behaviors/focus-element.js.map +1 -1
- package/esm/behaviors/lasso-select.js +3 -3
- package/esm/behaviors/lasso-select.js.map +1 -1
- package/esm/elements/combos/base-combo.js.map +1 -1
- package/esm/elements/edges/base-edge.js.map +1 -1
- package/esm/elements/nodes/base-node.js.map +1 -1
- package/esm/exports.d.ts +1 -1
- package/esm/exports.js +1 -1
- package/esm/exports.js.map +1 -1
- package/esm/layouts/types.d.ts +9 -1
- package/esm/plugins/bubble-sets.d.ts +1 -1
- package/esm/plugins/bubble-sets.js +30 -7
- package/esm/plugins/bubble-sets.js.map +1 -1
- package/esm/plugins/grid-line.js +1 -1
- package/esm/plugins/grid-line.js.map +1 -1
- package/esm/plugins/index.d.ts +2 -0
- package/esm/plugins/index.js +1 -0
- package/esm/plugins/index.js.map +1 -1
- package/esm/plugins/legend.d.ts +10 -2
- package/esm/plugins/legend.js.map +1 -1
- package/esm/plugins/minimap/index.d.ts +7 -4
- package/esm/plugins/minimap/index.js +41 -52
- package/esm/plugins/minimap/index.js.map +1 -1
- package/esm/plugins/title/index.d.ts +85 -0
- package/esm/plugins/title/index.js +172 -0
- package/esm/plugins/title/index.js.map +1 -0
- package/esm/plugins/tooltip.js +6 -1
- package/esm/plugins/tooltip.js.map +1 -1
- package/esm/registry/build-in.js +5 -4
- package/esm/registry/build-in.js.map +1 -1
- package/esm/runtime/canvas.js.map +1 -1
- package/esm/runtime/element.d.ts +8 -0
- package/esm/runtime/element.js +53 -8
- package/esm/runtime/element.js.map +1 -1
- package/esm/runtime/graph.d.ts +27 -0
- package/esm/runtime/graph.js +35 -2
- package/esm/runtime/graph.js.map +1 -1
- package/esm/runtime/layout.d.ts +2 -1
- package/esm/runtime/layout.js +8 -6
- package/esm/runtime/layout.js.map +1 -1
- package/esm/runtime/viewport.js +3 -0
- package/esm/runtime/viewport.js.map +1 -1
- package/esm/themes/base.js +1 -0
- package/esm/themes/base.js.map +1 -1
- package/esm/transforms/process-parallel-edges.js +16 -3
- package/esm/transforms/process-parallel-edges.js.map +1 -1
- package/esm/utils/data.d.ts +9 -0
- package/esm/utils/data.js +11 -0
- package/esm/utils/data.js.map +1 -1
- package/esm/utils/element.d.ts +1 -1
- package/esm/utils/element.js.map +1 -1
- package/esm/utils/shortcut.js +1 -1
- package/esm/utils/shortcut.js.map +1 -1
- package/esm/utils/vector.d.ts +9 -0
- package/esm/utils/vector.js +17 -0
- package/esm/utils/vector.js.map +1 -1
- package/esm/version.d.ts +1 -1
- package/esm/version.js +1 -1
- package/lib/behaviors/brush-select.d.ts +2 -3
- package/lib/behaviors/brush-select.js +14 -5
- package/lib/behaviors/brush-select.js.map +1 -1
- package/lib/behaviors/click-select.d.ts +2 -2
- package/lib/behaviors/click-select.js.map +1 -1
- package/lib/behaviors/create-edge.js +5 -1
- package/lib/behaviors/create-edge.js.map +1 -1
- package/lib/behaviors/drag-canvas.js +1 -6
- package/lib/behaviors/drag-canvas.js.map +1 -1
- package/lib/behaviors/drag-element-force.js +1 -1
- package/lib/behaviors/drag-element-force.js.map +1 -1
- package/lib/behaviors/drag-element.d.ts +21 -2
- package/lib/behaviors/drag-element.js +23 -2
- package/lib/behaviors/drag-element.js.map +1 -1
- package/lib/behaviors/focus-element.d.ts +18 -0
- package/lib/behaviors/focus-element.js +18 -1
- package/lib/behaviors/focus-element.js.map +1 -1
- package/lib/behaviors/lasso-select.js +3 -3
- package/lib/behaviors/lasso-select.js.map +1 -1
- package/lib/elements/combos/base-combo.js.map +1 -1
- package/lib/elements/edges/base-edge.js.map +1 -1
- package/lib/elements/nodes/base-node.js.map +1 -1
- package/lib/exports.d.ts +1 -1
- package/lib/exports.js +3 -2
- package/lib/exports.js.map +1 -1
- package/lib/layouts/types.d.ts +9 -1
- package/lib/plugins/bubble-sets.d.ts +1 -1
- package/lib/plugins/bubble-sets.js +30 -7
- package/lib/plugins/bubble-sets.js.map +1 -1
- package/lib/plugins/grid-line.js +1 -1
- package/lib/plugins/grid-line.js.map +1 -1
- package/lib/plugins/index.d.ts +2 -0
- package/lib/plugins/index.js +3 -1
- package/lib/plugins/index.js.map +1 -1
- package/lib/plugins/legend.d.ts +10 -2
- package/lib/plugins/legend.js.map +1 -1
- package/lib/plugins/minimap/index.d.ts +7 -4
- package/lib/plugins/minimap/index.js +41 -52
- package/lib/plugins/minimap/index.js.map +1 -1
- package/lib/plugins/title/index.d.ts +85 -0
- package/lib/plugins/title/index.js +176 -0
- package/lib/plugins/title/index.js.map +1 -0
- package/lib/plugins/tooltip.js +6 -1
- package/lib/plugins/tooltip.js.map +1 -1
- package/lib/registry/build-in.js +1 -0
- package/lib/registry/build-in.js.map +1 -1
- package/lib/runtime/canvas.js.map +1 -1
- package/lib/runtime/element.d.ts +8 -0
- package/lib/runtime/element.js +53 -8
- package/lib/runtime/element.js.map +1 -1
- package/lib/runtime/graph.d.ts +27 -0
- package/lib/runtime/graph.js +35 -2
- package/lib/runtime/graph.js.map +1 -1
- package/lib/runtime/layout.d.ts +2 -1
- package/lib/runtime/layout.js +8 -6
- package/lib/runtime/layout.js.map +1 -1
- package/lib/runtime/viewport.js +3 -0
- package/lib/runtime/viewport.js.map +1 -1
- package/lib/themes/base.js +1 -0
- package/lib/themes/base.js.map +1 -1
- package/lib/transforms/process-parallel-edges.js +16 -3
- package/lib/transforms/process-parallel-edges.js.map +1 -1
- package/lib/utils/data.d.ts +9 -0
- package/lib/utils/data.js +13 -0
- package/lib/utils/data.js.map +1 -1
- package/lib/utils/element.d.ts +1 -1
- package/lib/utils/element.js.map +1 -1
- package/lib/utils/shortcut.js +1 -1
- package/lib/utils/shortcut.js.map +1 -1
- package/lib/utils/vector.d.ts +9 -0
- package/lib/utils/vector.js +18 -0
- package/lib/utils/vector.js.map +1 -1
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/package.json +11 -11
- package/src/behaviors/brush-select.ts +17 -7
- package/src/behaviors/click-select.ts +1 -1
- package/src/behaviors/create-edge.ts +5 -3
- package/src/behaviors/drag-canvas.ts +2 -6
- package/src/behaviors/drag-element-force.ts +2 -1
- package/src/behaviors/drag-element.ts +37 -4
- package/src/behaviors/focus-element.ts +28 -1
- package/src/behaviors/lasso-select.ts +3 -3
- package/src/elements/combos/base-combo.ts +2 -1
- package/src/elements/edges/base-edge.ts +2 -1
- package/src/elements/nodes/base-node.ts +2 -1
- package/src/exports.ts +1 -0
- package/src/layouts/types.ts +9 -1
- package/src/plugins/bubble-sets.ts +37 -9
- package/src/plugins/grid-line.ts +1 -1
- package/src/plugins/index.ts +2 -0
- package/src/plugins/legend.ts +1 -1
- package/src/plugins/minimap/index.ts +50 -63
- package/src/plugins/title/index.ts +300 -0
- package/src/plugins/tooltip.ts +8 -2
- package/src/registry/build-in.ts +6 -4
- package/src/runtime/canvas.ts +4 -2
- package/src/runtime/element.ts +54 -9
- package/src/runtime/graph.ts +36 -2
- package/src/runtime/layout.ts +13 -6
- package/src/runtime/viewport.ts +14 -3
- package/src/themes/base.ts +1 -0
- package/src/transforms/process-parallel-edges.ts +17 -3
- package/src/types/edge.ts +1 -3
- package/src/utils/data.ts +12 -0
- package/src/utils/element.ts +5 -5
- package/src/utils/shortcut.ts +1 -1
- package/src/utils/vector.ts +17 -0
- package/src/version.ts +1 -1
- package/src/layouts/hierarchy.d.ts +0 -10
package/src/runtime/element.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { groupBy } from '@antv/util';
|
|
|
6
6
|
import { AnimationType, COMBO_KEY, ChangeType, GraphEvent } from '../constants';
|
|
7
7
|
import { ELEMENT_TYPES } from '../constants/element';
|
|
8
8
|
import { getExtension } from '../registry/get';
|
|
9
|
-
import type { ComboData, EdgeData, GraphData, NodeData } from '../spec';
|
|
9
|
+
import type { ComboData, EdgeData, GraphData, LayoutOptions, NodeData } from '../spec';
|
|
10
10
|
import type { AnimationStage } from '../spec/element/animation';
|
|
11
11
|
import type { DrawData, ProcedureData } from '../transforms/types';
|
|
12
12
|
import type {
|
|
@@ -26,6 +26,7 @@ import type {
|
|
|
26
26
|
import { cacheStyle, hasCachedStyle } from '../utils/cache';
|
|
27
27
|
import { reduceDataChanges } from '../utils/change';
|
|
28
28
|
import { isCollapsed } from '../utils/collapsibility';
|
|
29
|
+
import { isOverridable } from '../utils/data';
|
|
29
30
|
import { markToBeDestroyed, updateStyle } from '../utils/element';
|
|
30
31
|
import type { BaseEvent } from '../utils/event';
|
|
31
32
|
import { AnimateEvent, ElementLifeCycleEvent, GraphLifeCycleEvent, emit } from '../utils/event';
|
|
@@ -77,7 +78,7 @@ export class ElementController {
|
|
|
77
78
|
|
|
78
79
|
public getElementType(elementType: ElementType, datum: ElementDatum) {
|
|
79
80
|
const { options, graph } = this.context;
|
|
80
|
-
const userDefinedType = options[elementType]?.type || datum.type;
|
|
81
|
+
const userDefinedType = isOverridable(datum) ? options[elementType]?.type || datum.type : datum.type;
|
|
81
82
|
|
|
82
83
|
if (!userDefinedType) {
|
|
83
84
|
if (elementType === 'edge') return 'line';
|
|
@@ -255,7 +256,9 @@ export class ElementController {
|
|
|
255
256
|
const themeStateStyle = this.getThemeStateStyle(elementType, this.getElementState(id));
|
|
256
257
|
const stateStyle = this.getStateStyle(id);
|
|
257
258
|
|
|
258
|
-
const style =
|
|
259
|
+
const style = isOverridable(datum)
|
|
260
|
+
? Object.assign({}, themeStyle, paletteStyle, dataStyle, defaultStyle, themeStateStyle, stateStyle)
|
|
261
|
+
: Object.assign({}, dataStyle);
|
|
259
262
|
|
|
260
263
|
if (elementType === 'combo') {
|
|
261
264
|
const childrenData = this.context.model.getChildrenData(id);
|
|
@@ -380,6 +383,23 @@ export class ElementController {
|
|
|
380
383
|
ComboRemoved = [],
|
|
381
384
|
} = groupBy(tasks, (change) => change.type) as unknown as Record<`${ChangeType}`, DataChange[]>;
|
|
382
385
|
|
|
386
|
+
const moveToAddedIfUnrendered = (updated: DataChange[], added: DataChange[]) => {
|
|
387
|
+
const keptUpdates: DataChange[] = [];
|
|
388
|
+
updated.forEach((change) => {
|
|
389
|
+
const id = idOf(change.value);
|
|
390
|
+
if (!this.getElement(id)) {
|
|
391
|
+
added.push(change);
|
|
392
|
+
} else {
|
|
393
|
+
keptUpdates.push(change);
|
|
394
|
+
}
|
|
395
|
+
});
|
|
396
|
+
return keptUpdates;
|
|
397
|
+
};
|
|
398
|
+
|
|
399
|
+
const finalNodeUpdated = moveToAddedIfUnrendered(NodeUpdated, NodeAdded);
|
|
400
|
+
const finalEdgeUpdated = moveToAddedIfUnrendered(EdgeUpdated, EdgeAdded);
|
|
401
|
+
const finalComboUpdated = moveToAddedIfUnrendered(ComboUpdated, ComboAdded);
|
|
402
|
+
|
|
383
403
|
const dataOf = <T extends DataChange['value']>(data: DataChange[]) =>
|
|
384
404
|
new Map(
|
|
385
405
|
data.map((datum) => {
|
|
@@ -395,9 +415,9 @@ export class ElementController {
|
|
|
395
415
|
combos: dataOf<ComboData>(ComboAdded),
|
|
396
416
|
},
|
|
397
417
|
update: {
|
|
398
|
-
nodes: dataOf<NodeData>(
|
|
399
|
-
edges: dataOf<EdgeData>(
|
|
400
|
-
combos: dataOf<ComboData>(
|
|
418
|
+
nodes: dataOf<NodeData>(finalNodeUpdated),
|
|
419
|
+
edges: dataOf<EdgeData>(finalEdgeUpdated),
|
|
420
|
+
combos: dataOf<ComboData>(finalComboUpdated),
|
|
401
421
|
},
|
|
402
422
|
remove: {
|
|
403
423
|
nodes: dataOf<NodeData>(NodeRemoved),
|
|
@@ -655,6 +675,29 @@ export class ElementController {
|
|
|
655
675
|
}
|
|
656
676
|
}
|
|
657
677
|
|
|
678
|
+
/**
|
|
679
|
+
* <zh/> 同步布局结果
|
|
680
|
+
*
|
|
681
|
+
* <en/> Sync layout result
|
|
682
|
+
* @param id - <zh/> 元素 ID | <en/> element ID
|
|
683
|
+
* @param align - <zh/> 是否对齐 | <en/> whether to align
|
|
684
|
+
*/
|
|
685
|
+
private async syncLayoutResult(id: ID, align?: boolean) {
|
|
686
|
+
const { layout, model } = this.context;
|
|
687
|
+
if (!layout) return;
|
|
688
|
+
|
|
689
|
+
const layoutOptions = this.context.options.layout;
|
|
690
|
+
const forcePreLayout = (opts: LayoutOptions): LayoutOptions => {
|
|
691
|
+
if (Array.isArray(opts)) {
|
|
692
|
+
return opts.map((o) => ({ ...o, preLayout: true }));
|
|
693
|
+
}
|
|
694
|
+
return { ...opts, preLayout: true };
|
|
695
|
+
};
|
|
696
|
+
const layoutResult = await layout.simulate(layoutOptions ? forcePreLayout(layoutOptions) : undefined);
|
|
697
|
+
if (align) this.alignLayoutResultToElement(layoutResult, id);
|
|
698
|
+
model.updateData(layoutResult);
|
|
699
|
+
}
|
|
700
|
+
|
|
658
701
|
/**
|
|
659
702
|
* <zh/> 收起节点
|
|
660
703
|
*
|
|
@@ -663,8 +706,8 @@ export class ElementController {
|
|
|
663
706
|
* @param options - <zh/> 选项 | <en/> options
|
|
664
707
|
*/
|
|
665
708
|
public async collapseNode(id: ID, options: CollapseExpandNodeOptions): Promise<void> {
|
|
666
|
-
const { animation } = options;
|
|
667
|
-
|
|
709
|
+
const { animation, align } = options;
|
|
710
|
+
await this.syncLayoutResult(id, align);
|
|
668
711
|
|
|
669
712
|
// 重新计算数据 / Recalculate data
|
|
670
713
|
const data = this.computeChangesAndDrawData({ stage: 'collapse', animation });
|
|
@@ -704,10 +747,12 @@ export class ElementController {
|
|
|
704
747
|
* @param animation - <zh/> 是否使用动画,默认为 true | <en/> Whether to use animation, default is true
|
|
705
748
|
*/
|
|
706
749
|
public async expandNode(id: ID, options: CollapseExpandNodeOptions): Promise<void> {
|
|
707
|
-
const { model
|
|
750
|
+
const { model } = this.context;
|
|
708
751
|
const { animation, align } = options;
|
|
709
752
|
const position = positionOf(model.getNodeData([id])[0]);
|
|
710
753
|
|
|
754
|
+
await this.syncLayoutResult(id, align);
|
|
755
|
+
|
|
711
756
|
// 重新计算数据 / Recalculate data
|
|
712
757
|
const data = this.computeChangesAndDrawData({ stage: 'expand', animation });
|
|
713
758
|
this.createElements(data!.drawData.add, { animation: false, stage: 'expand', target: id });
|
package/src/runtime/graph.ts
CHANGED
|
@@ -504,6 +504,40 @@ export class Graph extends EventEmitter {
|
|
|
504
504
|
public getData(): Required<GraphData> {
|
|
505
505
|
return this.context.model.getData();
|
|
506
506
|
}
|
|
507
|
+
/**
|
|
508
|
+
* <zh/> 判断图中是否存在指定节点
|
|
509
|
+
* <en/> Determine whether a specified node exists in the graph
|
|
510
|
+
* @param {ID} id
|
|
511
|
+
* @returns {boolean}
|
|
512
|
+
* @remarks <zh/> 判断图中是否存在指定节点,避免在不存在的节点上进行操作
|
|
513
|
+
* <en/> Determine whether a specified node exists in the graph and avoid operating on non-existent nodes
|
|
514
|
+
*/
|
|
515
|
+
public hasNode(id: ID): boolean {
|
|
516
|
+
return this.context.model.hasNode(id);
|
|
517
|
+
}
|
|
518
|
+
/**
|
|
519
|
+
* <zh/> 判断图中是否存在指定边
|
|
520
|
+
* <en/> Determine whether a specified edge exists in the graph
|
|
521
|
+
* @param {ID} id
|
|
522
|
+
* @returns {boolean}
|
|
523
|
+
* @remarks <zh/> 判断图中是否存在指定边,避免在不存在的边上进行操作
|
|
524
|
+
* <en/> Determine whether a specified edge exists in the graph and avoid operating on non-existent edges
|
|
525
|
+
*/
|
|
526
|
+
public hasEdge(id: ID): boolean {
|
|
527
|
+
return this.context.model.hasEdge(id);
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
/**
|
|
531
|
+
* <zh/> 判断图中是否存在指定组合
|
|
532
|
+
* <en/> Determine whether a specified combo exists in the graph
|
|
533
|
+
* @param {ID} id
|
|
534
|
+
* @returns {boolean}
|
|
535
|
+
* @remarks <zh/> 判断图中是否存在指定组合,避免在不存在的组合上进行操作
|
|
536
|
+
* <en/> Determine whether a specified combo exists in the graph and avoid operating on non-existent combos
|
|
537
|
+
*/
|
|
538
|
+
public hasCombo(id: ID): boolean {
|
|
539
|
+
return this.context.model.hasCombo(id);
|
|
540
|
+
}
|
|
507
541
|
|
|
508
542
|
/**
|
|
509
543
|
* <zh/> 获取单个元素数据
|
|
@@ -1839,7 +1873,7 @@ export class Graph extends EventEmitter {
|
|
|
1839
1873
|
if (isCollapsed(model.getNodeLikeData([id])[0])) return;
|
|
1840
1874
|
if (this.isCollapsingExpanding) return;
|
|
1841
1875
|
|
|
1842
|
-
if (typeof options === 'boolean') options = { animation: options, align:
|
|
1876
|
+
if (typeof options === 'boolean') options = { animation: options, align: false };
|
|
1843
1877
|
|
|
1844
1878
|
const elementType = model.getElementType(id);
|
|
1845
1879
|
|
|
@@ -1877,7 +1911,7 @@ export class Graph extends EventEmitter {
|
|
|
1877
1911
|
if (!isCollapsed(model.getNodeLikeData([id])[0])) return;
|
|
1878
1912
|
if (this.isCollapsingExpanding) return;
|
|
1879
1913
|
|
|
1880
|
-
if (typeof options === 'boolean') options = { animation: options, align:
|
|
1914
|
+
if (typeof options === 'boolean') options = { animation: options, align: false };
|
|
1881
1915
|
|
|
1882
1916
|
const elementType = model.getElementType(id);
|
|
1883
1917
|
|
package/src/runtime/layout.ts
CHANGED
|
@@ -127,11 +127,12 @@ export class LayoutController {
|
|
|
127
127
|
* <zh/> 模拟布局
|
|
128
128
|
*
|
|
129
129
|
* <en/> Simulate layout
|
|
130
|
+
* @param options - <zh/> 布局配置项 | <en/> Layout options
|
|
130
131
|
* @returns <zh/> 模拟布局结果 | <en/> Simulated layout result
|
|
131
132
|
*/
|
|
132
|
-
public async simulate(): Promise<GraphData> {
|
|
133
|
-
if (!
|
|
134
|
-
const pipeline = Array.isArray(
|
|
133
|
+
public async simulate(options: LayoutOptions | undefined = this.options): Promise<GraphData> {
|
|
134
|
+
if (!options) return {};
|
|
135
|
+
const pipeline = Array.isArray(options) ? options : [options];
|
|
135
136
|
|
|
136
137
|
let simulation: GraphData = {};
|
|
137
138
|
|
|
@@ -296,7 +297,12 @@ export class LayoutController {
|
|
|
296
297
|
}
|
|
297
298
|
|
|
298
299
|
public getLayoutData(options: STDLayoutOptions): GraphData {
|
|
299
|
-
const {
|
|
300
|
+
const {
|
|
301
|
+
nodeFilter = () => true,
|
|
302
|
+
comboFilter = () => true,
|
|
303
|
+
preLayout = false,
|
|
304
|
+
isLayoutInvisibleNodes = false,
|
|
305
|
+
} = options;
|
|
300
306
|
const { nodes, edges, combos } = this.context.model.getData();
|
|
301
307
|
|
|
302
308
|
const { element, model } = this.context;
|
|
@@ -320,9 +326,10 @@ export class LayoutController {
|
|
|
320
326
|
};
|
|
321
327
|
|
|
322
328
|
const nodesToLayout = nodes.filter(filterFn);
|
|
329
|
+
const combosToLayout = combos.filter(comboFilter);
|
|
323
330
|
|
|
324
331
|
const nodeLikeIdsMap = new Map<ID, NodeData>(nodesToLayout.map((node) => [idOf(node), node]));
|
|
325
|
-
|
|
332
|
+
combosToLayout.forEach((combo) => nodeLikeIdsMap.set(idOf(combo), combo));
|
|
326
333
|
|
|
327
334
|
const edgesToLayout = edges.filter(({ source, target }) => {
|
|
328
335
|
return nodeLikeIdsMap.has(source) && nodeLikeIdsMap.has(target);
|
|
@@ -331,7 +338,7 @@ export class LayoutController {
|
|
|
331
338
|
return {
|
|
332
339
|
nodes: nodesToLayout,
|
|
333
340
|
edges: edgesToLayout,
|
|
334
|
-
combos,
|
|
341
|
+
combos: combosToLayout,
|
|
335
342
|
};
|
|
336
343
|
}
|
|
337
344
|
|
package/src/runtime/viewport.ts
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
import { AABB, ICamera } from '@antv/g';
|
|
2
2
|
import { clamp, isNumber, pick } from '@antv/util';
|
|
3
3
|
import { AnimationType, GraphEvent } from '../constants';
|
|
4
|
-
import type {
|
|
4
|
+
import type {
|
|
5
|
+
FitViewOptions,
|
|
6
|
+
ID,
|
|
7
|
+
Point,
|
|
8
|
+
TransformOptions,
|
|
9
|
+
Vector2,
|
|
10
|
+
Vector3,
|
|
11
|
+
ViewportAnimationEffectTiming,
|
|
12
|
+
} from '../types';
|
|
5
13
|
import type { Element } from '../types/element';
|
|
6
14
|
import { getAnimationOptions } from '../utils/animation';
|
|
7
15
|
import { getBBoxSize, getCombinedBBox, getExpandedBBox, isBBoxInside, isPointInBBox } from '../utils/bbox';
|
|
@@ -131,8 +139,8 @@ export class ViewportController {
|
|
|
131
139
|
|
|
132
140
|
return mode === 'relative'
|
|
133
141
|
? {
|
|
134
|
-
position: add(position, delta),
|
|
135
|
-
focalPoint: add(focalPoint, delta),
|
|
142
|
+
position: add(position as Vector3, delta),
|
|
143
|
+
focalPoint: add(focalPoint as Vector3, delta),
|
|
136
144
|
}
|
|
137
145
|
: {
|
|
138
146
|
position: add([cx, cy, position[2]], delta),
|
|
@@ -225,6 +233,9 @@ export class ViewportController {
|
|
|
225
233
|
const scale = direction === 'x' ? scaleX : direction === 'y' ? scaleY : Math.min(scaleX, scaleY);
|
|
226
234
|
|
|
227
235
|
const _animation = this.getAnimation(animation);
|
|
236
|
+
if (!Number.isFinite(scale)) {
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
228
239
|
await this.transform(
|
|
229
240
|
{
|
|
230
241
|
mode: 'relative',
|
package/src/themes/base.ts
CHANGED
|
@@ -121,9 +121,23 @@ export class ProcessParallelEdges extends BaseTransform<ProcessParallelEdgesOpti
|
|
|
121
121
|
combosToUpdate.forEach(addRelatedEdges);
|
|
122
122
|
|
|
123
123
|
const pushParallelEdges = (edge: EdgeData) => {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
124
|
+
// 获取已被标记删除的边ID集合
|
|
125
|
+
// Get the set of edge IDs that have been marked for removal
|
|
126
|
+
const removedEdgeIds = new Set(input.remove.edges.keys());
|
|
127
|
+
|
|
128
|
+
// 过滤掉已删除的边,避免重定向后重新添加(修复combo收起时内部边变成loop边的问题)
|
|
129
|
+
// Filter out removed edges to prevent them from being re-added after redirection (fixes the issue where internal edges become loop edges when combo collapses)
|
|
130
|
+
const validEdgeData = model
|
|
131
|
+
.getEdgeData()
|
|
132
|
+
.filter((edge) => !removedEdgeIds.has(idOf(edge)))
|
|
133
|
+
.map((edge) => getEdgeEndsContext(model, edge));
|
|
134
|
+
|
|
135
|
+
// 查找平行边并添加到处理列表,确保只处理有效的边
|
|
136
|
+
// Find parallel edges and add them to the processing list, ensuring only valid edges are processed
|
|
137
|
+
getParallelEdges(edge, validEdgeData, true).forEach((e) => {
|
|
138
|
+
const id = idOf(e);
|
|
139
|
+
if (!edges.has(id)) edges.set(id, e);
|
|
140
|
+
});
|
|
127
141
|
};
|
|
128
142
|
|
|
129
143
|
if (edgesToRemove.size) edgesToRemove.forEach(pushParallelEdges);
|
package/src/types/edge.ts
CHANGED
|
@@ -102,9 +102,7 @@ export interface EdgeBadgeStyleProps extends BadgeStyleProps {
|
|
|
102
102
|
* <en/> Edge arrow style properties
|
|
103
103
|
*/
|
|
104
104
|
export interface EdgeArrowStyleProps
|
|
105
|
-
extends PathStyleProps,
|
|
106
|
-
Omit<ImageStyleProps, 'width' | 'height'>,
|
|
107
|
-
Record<string, unknown> {
|
|
105
|
+
extends PathStyleProps, Omit<ImageStyleProps, 'width' | 'height'>, Record<string, unknown> {
|
|
108
106
|
/**
|
|
109
107
|
* <zh/> 箭头大小
|
|
110
108
|
*
|
package/src/utils/data.ts
CHANGED
|
@@ -111,3 +111,15 @@ export function isElementDataEqual(original: Partial<ElementDatum> = {}, modifie
|
|
|
111
111
|
|
|
112
112
|
return true;
|
|
113
113
|
}
|
|
114
|
+
|
|
115
|
+
export const OVERRIDE_KEY = '__internal_override__';
|
|
116
|
+
/**
|
|
117
|
+
* <zh/> 判断元素数据是否允许被覆盖
|
|
118
|
+
*
|
|
119
|
+
* <en/> Determine whether the element data can be overridden
|
|
120
|
+
* @param datum - <zh/> 元素数据 | <en/> element data
|
|
121
|
+
* @returns <zh/> 是否允许被覆盖 | <en/> is overridable
|
|
122
|
+
*/
|
|
123
|
+
export function isOverridable(datum: ElementDatum): boolean {
|
|
124
|
+
return datum[OVERRIDE_KEY] !== false;
|
|
125
|
+
}
|
package/src/utils/element.ts
CHANGED
|
@@ -148,7 +148,7 @@ export function isSimplePort(portStyle: NodePortStyleProps): boolean {
|
|
|
148
148
|
* @returns <zh/> 连接桩的位置 | <en/> Port Position
|
|
149
149
|
*/
|
|
150
150
|
export function getPortPosition(port: Port): Point {
|
|
151
|
-
return isPoint(port) ? port : port.getPosition();
|
|
151
|
+
return isPoint(port) ? port : (port.getPosition() as Point);
|
|
152
152
|
}
|
|
153
153
|
|
|
154
154
|
/**
|
|
@@ -246,7 +246,7 @@ export function getPortConnectionPoint(port: Port, opposite: Node | Port): Point
|
|
|
246
246
|
if (isPoint(port)) return port;
|
|
247
247
|
|
|
248
248
|
// 1. linkToCenter 为 true,则返回连接桩的中心 | If linkToCenter is true, return the center of the port
|
|
249
|
-
if (port.attributes.linkToCenter) return port.getPosition();
|
|
249
|
+
if (port.attributes.linkToCenter) return port.getPosition() as Point;
|
|
250
250
|
|
|
251
251
|
// 2. 推导对端的具体点:如果是连接桩或节点,则返回它的中心;如果是具体点,则直接返回
|
|
252
252
|
// 2. Get a specific opposite point: if it is a port or a node, return its center; if it is a specific point, return directly
|
|
@@ -257,7 +257,7 @@ export function getPortConnectionPoint(port: Port, opposite: Node | Port): Point
|
|
|
257
257
|
: opposite.getPosition();
|
|
258
258
|
|
|
259
259
|
// 3. 返回连接桩边界上的交点 | Return the intersection point on the port boundary
|
|
260
|
-
return getEllipseIntersectPoint(oppositePosition, port.getBounds());
|
|
260
|
+
return getEllipseIntersectPoint(oppositePosition as Point, port.getBounds());
|
|
261
261
|
}
|
|
262
262
|
|
|
263
263
|
/**
|
|
@@ -275,7 +275,7 @@ export function getNodeConnectionPoint(nodeLike: Node | Combo, opposite: Node |
|
|
|
275
275
|
? opposite
|
|
276
276
|
: isNode(opposite)
|
|
277
277
|
? opposite.getCenter()
|
|
278
|
-
: opposite.getPosition();
|
|
278
|
+
: (opposite.getPosition() as Point);
|
|
279
279
|
return nodeLike.getIntersectPoint(oppositePosition) || nodeLike.getCenter();
|
|
280
280
|
}
|
|
281
281
|
|
|
@@ -544,6 +544,6 @@ export function markToBeDestroyed(element: DisplayObject) {
|
|
|
544
544
|
* @param element - <zh/> 图形 | <en/> element
|
|
545
545
|
* @returns <zh/> 是否即将销毁 | <en/> whether the element is to be destroyed
|
|
546
546
|
*/
|
|
547
|
-
export function isToBeDestroyed(element: DisplayObject) {
|
|
547
|
+
export function isToBeDestroyed(element: DisplayObject | unknown) {
|
|
548
548
|
return get(element, '__to_be_destroyed__', false);
|
|
549
549
|
}
|
package/src/utils/shortcut.ts
CHANGED
|
@@ -130,6 +130,6 @@ export class Shortcut {
|
|
|
130
130
|
this.emitter.off(CommonEvent.WHEEL, this.onWheel);
|
|
131
131
|
this.emitter.off(CommonEvent.DRAG, this.onDrag);
|
|
132
132
|
this.pinchHandler?.off('pinchmove', this.boundHandlePinch);
|
|
133
|
-
globalThis.removeEventListener?.('
|
|
133
|
+
globalThis.removeEventListener?.('focus', this.onFocus);
|
|
134
134
|
}
|
|
135
135
|
}
|
package/src/utils/vector.ts
CHANGED
|
@@ -219,3 +219,20 @@ export function rad(a: Vector2 | Vector3): number {
|
|
|
219
219
|
if (!x && !y) return 0;
|
|
220
220
|
return Math.atan2(y, x);
|
|
221
221
|
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* <zh/> 旋转向量(角度制)
|
|
225
|
+
*
|
|
226
|
+
* <en/> Rotational vector (Angle system)
|
|
227
|
+
* @param a - <zh/> 向量 | <en/> The vector
|
|
228
|
+
* @param angle - <zh/> 旋转角度 | <en/> The rotation angle
|
|
229
|
+
* @returns <zh/> 向量 | <en/> The vector
|
|
230
|
+
*/
|
|
231
|
+
export function rotate(a: Vector2, angle: number): Vector2 {
|
|
232
|
+
const [dx, dy] = a;
|
|
233
|
+
if (angle % 360 === 0) return [dx, dy];
|
|
234
|
+
const rad = (angle * Math.PI) / 180;
|
|
235
|
+
const cos = Math.cos(rad);
|
|
236
|
+
const sin = Math.sin(rad);
|
|
237
|
+
return [dx * cos - dy * sin, dx * sin + dy * cos];
|
|
238
|
+
}
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '5.0.
|
|
1
|
+
export const version = '5.0.51';
|