@antv/g6 5.0.25 → 5.0.26

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 (165) hide show
  1. package/dist/g6.min.js +2 -2
  2. package/dist/lib/behaviors/auto-adapt-label.d.ts +99 -0
  3. package/dist/lib/behaviors/fix-element-size.d.ts +63 -19
  4. package/dist/lib/behaviors/index.d.ts +2 -0
  5. package/dist/lib/behaviors/optimize-viewport-transform.d.ts +3 -3
  6. package/dist/lib/exports.d.ts +3 -3
  7. package/dist/lib/plugins/edge-bundling/index.d.ts +97 -0
  8. package/dist/lib/plugins/index.d.ts +2 -0
  9. package/dist/lib/runtime/data.d.ts +1 -1
  10. package/dist/lib/runtime/element.d.ts +1 -1
  11. package/dist/lib/runtime/viewport.d.ts +3 -1
  12. package/dist/lib/transforms/map-node-size.d.ts +12 -21
  13. package/dist/lib/transforms/process-parallel-edges.d.ts +4 -0
  14. package/dist/lib/transforms/utils.d.ts +9 -0
  15. package/dist/lib/types/centrality.d.ts +20 -0
  16. package/dist/lib/types/index.d.ts +1 -0
  17. package/dist/lib/utils/animation.d.ts +1 -1
  18. package/dist/lib/utils/bbox.d.ts +9 -0
  19. package/dist/lib/utils/centrality.d.ts +53 -0
  20. package/dist/lib/utils/padding.d.ts +16 -0
  21. package/dist/lib/utils/transform.d.ts +0 -13
  22. package/dist/lib/version.d.ts +1 -1
  23. package/esm/behaviors/auto-adapt-label.d.ts +99 -0
  24. package/esm/behaviors/auto-adapt-label.js +167 -0
  25. package/esm/behaviors/auto-adapt-label.js.map +1 -0
  26. package/esm/behaviors/fix-element-size.d.ts +63 -19
  27. package/esm/behaviors/fix-element-size.js +142 -59
  28. package/esm/behaviors/fix-element-size.js.map +1 -1
  29. package/esm/behaviors/hover-activate.js +1 -2
  30. package/esm/behaviors/hover-activate.js.map +1 -1
  31. package/esm/behaviors/index.d.ts +2 -0
  32. package/esm/behaviors/index.js +1 -0
  33. package/esm/behaviors/index.js.map +1 -1
  34. package/esm/behaviors/optimize-viewport-transform.d.ts +3 -3
  35. package/esm/exports.d.ts +3 -3
  36. package/esm/exports.js +1 -1
  37. package/esm/exports.js.map +1 -1
  38. package/esm/plugins/edge-bundling/index.d.ts +97 -0
  39. package/esm/plugins/edge-bundling/index.js +252 -0
  40. package/esm/plugins/edge-bundling/index.js.map +1 -0
  41. package/esm/plugins/index.d.ts +2 -0
  42. package/esm/plugins/index.js +1 -0
  43. package/esm/plugins/index.js.map +1 -1
  44. package/esm/registry/build-in.js +4 -2
  45. package/esm/registry/build-in.js.map +1 -1
  46. package/esm/runtime/behavior.js +1 -1
  47. package/esm/runtime/behavior.js.map +1 -1
  48. package/esm/runtime/data.d.ts +1 -1
  49. package/esm/runtime/element.d.ts +1 -1
  50. package/esm/runtime/viewport.d.ts +3 -1
  51. package/esm/runtime/viewport.js +13 -4
  52. package/esm/runtime/viewport.js.map +1 -1
  53. package/esm/transforms/collapse-expand-combo.js +0 -1
  54. package/esm/transforms/collapse-expand-combo.js.map +1 -1
  55. package/esm/transforms/map-node-size.d.ts +12 -21
  56. package/esm/transforms/map-node-size.js +34 -178
  57. package/esm/transforms/map-node-size.js.map +1 -1
  58. package/esm/transforms/process-parallel-edges.d.ts +4 -0
  59. package/esm/transforms/process-parallel-edges.js +41 -37
  60. package/esm/transforms/process-parallel-edges.js.map +1 -1
  61. package/esm/transforms/utils.d.ts +9 -0
  62. package/esm/transforms/utils.js +11 -0
  63. package/esm/transforms/utils.js.map +1 -1
  64. package/esm/types/centrality.d.ts +20 -0
  65. package/esm/types/centrality.js +2 -0
  66. package/esm/types/centrality.js.map +1 -0
  67. package/esm/types/index.d.ts +1 -0
  68. package/esm/utils/animation.d.ts +1 -1
  69. package/esm/utils/bbox.d.ts +9 -0
  70. package/esm/utils/bbox.js +15 -0
  71. package/esm/utils/bbox.js.map +1 -1
  72. package/esm/utils/centrality.d.ts +53 -0
  73. package/esm/utils/centrality.js +177 -0
  74. package/esm/utils/centrality.js.map +1 -0
  75. package/esm/utils/padding.d.ts +16 -0
  76. package/esm/utils/padding.js +22 -0
  77. package/esm/utils/padding.js.map +1 -1
  78. package/esm/utils/transform.d.ts +0 -13
  79. package/esm/utils/transform.js +0 -23
  80. package/esm/utils/transform.js.map +1 -1
  81. package/esm/version.d.ts +1 -1
  82. package/esm/version.js +1 -1
  83. package/lib/behaviors/auto-adapt-label.d.ts +99 -0
  84. package/lib/behaviors/auto-adapt-label.js +171 -0
  85. package/lib/behaviors/auto-adapt-label.js.map +1 -0
  86. package/lib/behaviors/fix-element-size.d.ts +63 -19
  87. package/lib/behaviors/fix-element-size.js +141 -58
  88. package/lib/behaviors/fix-element-size.js.map +1 -1
  89. package/lib/behaviors/hover-activate.js +1 -2
  90. package/lib/behaviors/hover-activate.js.map +1 -1
  91. package/lib/behaviors/index.d.ts +2 -0
  92. package/lib/behaviors/index.js +3 -1
  93. package/lib/behaviors/index.js.map +1 -1
  94. package/lib/behaviors/optimize-viewport-transform.d.ts +3 -3
  95. package/lib/exports.d.ts +3 -3
  96. package/lib/exports.js +3 -2
  97. package/lib/exports.js.map +1 -1
  98. package/lib/plugins/edge-bundling/index.d.ts +97 -0
  99. package/lib/plugins/edge-bundling/index.js +256 -0
  100. package/lib/plugins/edge-bundling/index.js.map +1 -0
  101. package/lib/plugins/index.d.ts +2 -0
  102. package/lib/plugins/index.js +3 -1
  103. package/lib/plugins/index.js.map +1 -1
  104. package/lib/registry/build-in.js +2 -0
  105. package/lib/registry/build-in.js.map +1 -1
  106. package/lib/runtime/behavior.js +1 -1
  107. package/lib/runtime/behavior.js.map +1 -1
  108. package/lib/runtime/data.d.ts +1 -1
  109. package/lib/runtime/element.d.ts +1 -1
  110. package/lib/runtime/viewport.d.ts +3 -1
  111. package/lib/runtime/viewport.js +12 -3
  112. package/lib/runtime/viewport.js.map +1 -1
  113. package/lib/transforms/collapse-expand-combo.js +0 -1
  114. package/lib/transforms/collapse-expand-combo.js.map +1 -1
  115. package/lib/transforms/map-node-size.d.ts +12 -21
  116. package/lib/transforms/map-node-size.js +33 -177
  117. package/lib/transforms/map-node-size.js.map +1 -1
  118. package/lib/transforms/process-parallel-edges.d.ts +4 -0
  119. package/lib/transforms/process-parallel-edges.js +41 -37
  120. package/lib/transforms/process-parallel-edges.js.map +1 -1
  121. package/lib/transforms/utils.d.ts +9 -0
  122. package/lib/transforms/utils.js +12 -0
  123. package/lib/transforms/utils.js.map +1 -1
  124. package/lib/types/centrality.d.ts +20 -0
  125. package/lib/types/centrality.js +3 -0
  126. package/lib/types/centrality.js.map +1 -0
  127. package/lib/types/index.d.ts +1 -0
  128. package/lib/utils/animation.d.ts +1 -1
  129. package/lib/utils/bbox.d.ts +9 -0
  130. package/lib/utils/bbox.js +16 -0
  131. package/lib/utils/bbox.js.map +1 -1
  132. package/lib/utils/centrality.d.ts +53 -0
  133. package/lib/utils/centrality.js +187 -0
  134. package/lib/utils/centrality.js.map +1 -0
  135. package/lib/utils/padding.d.ts +16 -0
  136. package/lib/utils/padding.js +24 -0
  137. package/lib/utils/padding.js.map +1 -1
  138. package/lib/utils/transform.d.ts +0 -13
  139. package/lib/utils/transform.js +0 -25
  140. package/lib/utils/transform.js.map +1 -1
  141. package/lib/version.d.ts +1 -1
  142. package/lib/version.js +1 -1
  143. package/package.json +1 -1
  144. package/src/behaviors/auto-adapt-label.ts +255 -0
  145. package/src/behaviors/fix-element-size.ts +213 -83
  146. package/src/behaviors/hover-activate.ts +2 -3
  147. package/src/behaviors/index.ts +2 -0
  148. package/src/behaviors/optimize-viewport-transform.ts +3 -3
  149. package/src/exports.ts +3 -0
  150. package/src/plugins/edge-bundling/index.ts +373 -0
  151. package/src/plugins/index.ts +2 -0
  152. package/src/registry/build-in.ts +4 -0
  153. package/src/runtime/behavior.ts +1 -0
  154. package/src/runtime/viewport.ts +14 -4
  155. package/src/transforms/collapse-expand-combo.ts +0 -1
  156. package/src/transforms/map-node-size.ts +52 -209
  157. package/src/transforms/process-parallel-edges.ts +50 -41
  158. package/src/transforms/utils.ts +12 -0
  159. package/src/types/centrality.ts +8 -0
  160. package/src/types/index.ts +1 -0
  161. package/src/utils/bbox.ts +17 -0
  162. package/src/utils/centrality.ts +209 -0
  163. package/src/utils/padding.ts +24 -0
  164. package/src/utils/transform.ts +0 -32
  165. package/src/version.ts +1 -1
@@ -1,9 +1,9 @@
1
1
  import type { DisplayObject } from '@antv/g';
2
- import { isFunction, isNumber } from '@antv/util';
2
+ import { isEmpty, isFunction, isNumber } from '@antv/util';
3
3
  import { GraphEvent } from '../constants';
4
4
  import type { RuntimeContext } from '../runtime/types';
5
- import type { Element, ID, IViewportEvent, State } from '../types';
6
- import { cacheStyle, getCachedStyle, hasCachedStyle } from '../utils/cache';
5
+ import type { ComboData, EdgeData, NodeData } from '../spec';
6
+ import type { Combo, Edge, Element, ID, IViewportEvent, Node, NodeLikeData, State } from '../types';
7
7
  import { idOf } from '../utils/id';
8
8
  import { getDescendantShapes } from '../utils/shape';
9
9
  import type { BaseBehaviorOptions } from './base-behavior';
@@ -11,17 +11,17 @@ import { BaseBehavior } from './base-behavior';
11
11
 
12
12
  export type FixShapeConfig = {
13
13
  /**
14
- * <zh/> 指定要固定大小的元素属性对应的图形。如果不指定,则固定整个元素
14
+ * <zh/> 指定要固定大小的图形,可以是图形的类名字,或者是一个函数,该函数接收构成元素的所有图形并返回目标图形
15
15
  *
16
- * <en/> Specify the shape corresponding to properties to be fixed in size. If not specified, fix the entire element
16
+ * <en/> Specify the shape to be fixed in size. This can be a class name string of the shape, or a function that takes all shapes composing the element and returns the target shape
17
17
  */
18
- shape: (shapes: DisplayObject[]) => DisplayObject;
18
+ shape: string | ((shapes: DisplayObject[]) => DisplayObject);
19
19
  /**
20
- * <zh/> 指定要固定大小的属性
20
+ * <zh/> 指定要固定大小的图形属性字段。如果未指定,则默认固定整个图形的大小
21
21
  *
22
- * <en/> Specify properties to be fixed
22
+ * <en/> Specify the fields of the shape to be fixed in size. If not specified, the entire shape's size will be fixed by default
23
23
  */
24
- fields: string[];
24
+ fields?: string[];
25
25
  };
26
26
 
27
27
  /**
@@ -34,32 +34,57 @@ export interface FixElementSizeOptions extends BaseBehaviorOptions {
34
34
  * <zh/> 是否启用固定元素大小交互。默认在缩小画布时启用
35
35
  *
36
36
  * <en/> Whether to enable the fix element size behavior. Enabled by default when zooming out
37
- * @defaultValue `(event) => Boolean(event.data.scale < 1)`
37
+ * @remarks
38
+ * <zh/> 默认在缩小画布时启用,设置 `enable: (event) => event.data.scale < 1`;如果希望在放大画布时启用,设置 `enable: (event) => event.data.scale > 1`;如果希望在放大缩小画布时都启用,设置 `enable: true`
39
+ *
40
+ * <en/> Enabled by default when zooming out, set `enable: (event) => event.data.scale < 1`; If you want to enable it when zooming in, set `enable: (event) => event.data.scale > 1`; If you want to enable it when zooming in and out, set `enable: true`
41
+ * @defaultValue (event) => Boolean(event.data.scale < 1)
38
42
  */
39
43
  enable?: boolean | ((event: IViewportEvent) => boolean);
40
44
  /**
41
45
  * <zh/> 指定要固定大小的元素状态
42
46
  *
43
47
  * <en/> Specify the state of elements to be fixed in size
48
+ * @defaultValue `'selected'`
44
49
  */
45
50
  state?: State;
51
+ /**
52
+ * <zh/> 节点过滤器,用于过滤哪些节点在缩放过程中保持固定大小
53
+ *
54
+ * <en/> Node filter for filtering which nodes remain fixed in size during zooming
55
+ * @defaultValue () => true
56
+ */
57
+ nodeFilter?: (datum: NodeData) => boolean;
58
+ /**
59
+ * <zh/> 边过滤器,用于过滤哪些边在缩放过程中保持固定大小
60
+ *
61
+ * <en/> Edge filter for filtering which edges remain fixed in size during zooming
62
+ * @defaultValue () => true
63
+ */
64
+ edgeFilter?: (datum: EdgeData) => boolean;
65
+ /**
66
+ * <zh/> Combo 过滤器,用于过滤哪些 Combo 在缩放过程中保持固定大小
67
+ *
68
+ * <en/> Combo filter for filtering which combos remain fixed in size during zooming
69
+ * @defaultValue () => true
70
+ */
71
+ comboFilter?: (datum: ComboData) => boolean;
46
72
  /**
47
73
  * <zh/> 节点配置项,用于定义哪些属性在视觉上保持固定大小。若未指定(即为 undefined),则整个节点将被固定
48
74
  *
49
75
  * <en/> Node configuration for defining which node attributes should remain fixed in size visually. If not specified (i.e., undefined), the entire node will be fixed in size.
50
76
  * @example
51
- * <zh/> 例如,在缩放过程中固定节点的 lineWidth 属性,可以配置如下:
77
+ * <zh/> 如果在缩放过程中希望固定节点主图形的 lineWidth,可以这样配置:
78
+ *
79
+ * <en/> If you want to fix the lineWidth of the key shape of the node during zooming, you can configure it like this:
80
+ * ```ts
81
+ * { node: [{ shape: 'key', fields: ['lineWidth'] }] }
82
+ *```
83
+ * <zh/> 如果在缩放过程中想保持元素标签大小不变,可以这样配置:
52
84
  *
53
- * <en/> For example, to fix `lineWidth` attribute of a node during zooming, you can configure it as follows:
85
+ * <en/> If you want to keep the label size of the element unchanged during zooming, you can configure it like this:
54
86
  * ```ts
55
- * {
56
- * node: [
57
- * {
58
- * shape: (shapes: DisplayObject[]) => shapes.find((shape) => shape.className === 'key'),
59
- * fields: ['lineWidth'],
60
- * },
61
- * ],
62
- * }
87
+ * { shape: 'label' }
63
88
  * ```
64
89
  */
65
90
  node?: FixShapeConfig | FixShapeConfig[];
@@ -67,6 +92,7 @@ export interface FixElementSizeOptions extends BaseBehaviorOptions {
67
92
  * <zh/> 边配置项,用于定义哪些属性在视觉上保持固定大小。默认固定 lineWidth、labelFontSize 属性
68
93
  *
69
94
  * <en/> Edge configuration for defining which edge attributes should remain fixed in size visually. By default, the lineWidth and labelFontSize attributes are fixed
95
+ * @defaultValue [{ shape: 'key', fields: ['lineWidth'] }, { shape: 'halo', fields: ['lineWidth'] }, { shape: 'label' }]
70
96
  */
71
97
  edge?: FixShapeConfig | FixShapeConfig[];
72
98
  /**
@@ -75,6 +101,13 @@ export interface FixElementSizeOptions extends BaseBehaviorOptions {
75
101
  * <en/> Combo configuration for defining which combo attributes should remain fixed in size visually. By default, the entire combo will be fixed
76
102
  */
77
103
  combo?: FixShapeConfig | FixShapeConfig[];
104
+ /**
105
+ * <zh/> 元素重绘时是否还原样式
106
+ *
107
+ * <en/> Whether to reset styles when elements are redrawn
108
+ * @defaultValue false
109
+ */
110
+ reset?: boolean;
78
111
  }
79
112
 
80
113
  /**
@@ -82,98 +115,195 @@ export interface FixElementSizeOptions extends BaseBehaviorOptions {
82
115
  *
83
116
  * <en/> Fix element size while zooming
84
117
  */
85
- export class FixElementSize extends BaseBehavior {
118
+ export class FixElementSize extends BaseBehavior<FixElementSizeOptions> {
86
119
  static defaultOptions: Partial<FixElementSizeOptions> = {
87
- enable: (event) => event.data.scale! < 1,
88
- state: 'selected',
89
- edge: [
90
- {
91
- shape: (shapes: DisplayObject[]) => shapes.find((shape) => shape.className === 'key')!,
92
- fields: ['lineWidth'],
93
- },
94
- {
95
- shape: (shapes: DisplayObject[]) =>
96
- shapes.find((shape) => shape.parentElement?.className === 'label' && shape.className === 'text')!,
97
- fields: ['fontSize', 'lineHeight'],
98
- },
99
- ],
120
+ enable: (event: IViewportEvent) => event.data.scale! < 1,
121
+ nodeFilter: () => true,
122
+ edgeFilter: () => true,
123
+ comboFilter: () => true,
124
+ edge: [{ shape: 'key', fields: ['lineWidth'] }, { shape: 'halo', fields: ['lineWidth'] }, { shape: 'label' }],
125
+ reset: false,
100
126
  };
101
127
 
102
- private elementCache: Map<ID, Element> = new Map();
103
-
104
128
  constructor(context: RuntimeContext, options: FixElementSizeOptions) {
105
129
  super(context, Object.assign({}, FixElementSize.defaultOptions, options));
106
130
  this.bindEvents();
107
131
  }
108
132
 
109
- private isZoomEvent = (event: IViewportEvent) => 'scale' in event.data;
133
+ private isZoomEvent = (event: IViewportEvent) => Boolean(event.data && 'scale' in event.data);
134
+
135
+ private relatedEdgeToUpdate: Set<ID> = new Set();
136
+
137
+ private zoom = this.context.graph.getZoom();
110
138
 
111
139
  private fixElementSize = async (event: IViewportEvent) => {
112
- if (!this.isZoomEvent(event) || !this.validate(event)) return;
113
-
114
- const { graph, element } = this.context;
115
- const { state } = this.options;
116
- const elementData = state
117
- ? [
118
- ...graph.getElementDataByState('node', state),
119
- ...graph.getElementDataByState('edge', state),
120
- ...graph.getElementDataByState('combo', state),
121
- ]
122
- : Object.values(graph.getData()).flat();
123
-
124
- if (!elementData.length) return;
125
-
126
- const currentScale = event.data.scale || graph.getZoom();
127
- elementData.forEach((elementData) => {
128
- const id = idOf(elementData);
129
- const el = element?.getElement(id) as Element;
130
- const type = graph.getElementType(id);
131
-
132
- const config = this.options[type];
133
-
134
- if (!config) {
135
- this.elementCache.set(id, el);
136
- if (type === 'edge') {
137
- el.style.transformOrigin = 'center';
138
- }
139
- // FIXME: 修改 Path 的 localScale 属性时遇到问题,导致边会偏移错位
140
- el.setLocalScale(1 / currentScale);
140
+ if (!this.validate(event)) return;
141
+
142
+ const { graph } = this.context;
143
+ const { state, nodeFilter, edgeFilter, comboFilter } = this.options;
144
+
145
+ const nodeData = (state ? graph.getElementDataByState('node', state) : graph.getNodeData()).filter(nodeFilter);
146
+ const edgeData = (state ? graph.getElementDataByState('edge', state) : graph.getEdgeData()).filter(edgeFilter);
147
+ const comboData = (state ? graph.getElementDataByState('combo', state) : graph.getComboData()).filter(comboFilter);
148
+
149
+ // 设置阈值防止过大或过小时抖动 | Set the threshold to prevent jitter when too large or too small
150
+ const currentScale = this.isZoomEvent(event)
151
+ ? (this.zoom = Math.max(0.01, Math.min(event.data.scale!, 10)))
152
+ : this.zoom;
153
+
154
+ const nodeLikeData = [...nodeData, ...comboData];
155
+ if (nodeLikeData.length > 0) {
156
+ nodeLikeData.forEach((datum) => this.fixNodeLike(datum, currentScale));
157
+ }
158
+
159
+ this.updateRelatedEdges();
160
+
161
+ if (edgeData.length > 0) {
162
+ edgeData.forEach((datum) => this.fixEdge(datum, currentScale));
163
+ }
164
+ };
165
+
166
+ private cachedStyles: Map<ID, { shape: DisplayObject; [field: string]: any }[]> = new Map();
167
+
168
+ private getOriginalFieldValue = (id: ID, shape: DisplayObject, field: string) => {
169
+ const shapesStyle = this.cachedStyles.get(id) || [];
170
+ const shapeStyle = shapesStyle.find((style) => style.shape === shape)?.style || {};
171
+ if (!(field in shapeStyle)) {
172
+ shapeStyle[field] = shape.attributes[field];
173
+ this.cachedStyles.set(id, [
174
+ ...shapesStyle.filter((style) => style.shape !== shape),
175
+ { shape, style: shapeStyle },
176
+ ]);
177
+ }
178
+ return shapeStyle[field];
179
+ };
180
+
181
+ private scaleEntireElement = (id: ID, el: DisplayObject, currentScale: number) => {
182
+ el.setLocalScale(1 / currentScale);
183
+ const shapesStyle = this.cachedStyles.get(id) || [];
184
+ shapesStyle.push({ shape: el });
185
+ this.cachedStyles.set(id, shapesStyle);
186
+ };
187
+
188
+ private scaleSpecificShapes = (el: Element, currentScale: number, config: FixShapeConfig | FixShapeConfig[]) => {
189
+ const descendantShapes = getDescendantShapes(el);
190
+ const configs = Array.isArray(config) ? config : [config];
191
+
192
+ configs.forEach((config: FixShapeConfig) => {
193
+ const { shape: shapeFilter, fields } = config;
194
+ const shape = typeof shapeFilter === 'function' ? shapeFilter(descendantShapes) : el.getShape(shapeFilter);
195
+
196
+ if (!shape) return;
197
+ if (!fields) {
198
+ this.scaleEntireElement(el.id, shape, currentScale);
141
199
  return;
142
200
  }
143
201
 
144
- const descendantShapes = getDescendantShapes(el);
145
- const configs = Array.isArray(config) ? config : [config];
146
- configs.forEach((config: FixShapeConfig) => {
147
- const { shape: shapeFilter, fields } = config;
148
- const shape = shapeFilter(descendantShapes);
149
-
150
- fields.forEach((field) => {
151
- if (!hasCachedStyle(shape, field)) cacheStyle(shape, field);
152
- const oriFieldValue = getCachedStyle(shape, field);
153
- if (!isNumber(oriFieldValue)) return;
154
- shape.style[field] = oriFieldValue / currentScale;
155
- });
202
+ fields.forEach((field) => {
203
+ const oriFieldValue = this.getOriginalFieldValue(el.id, shape, field);
204
+ if (!isNumber(oriFieldValue)) return;
205
+ shape.style[field] = oriFieldValue / currentScale;
156
206
  });
157
207
  });
158
208
  };
159
209
 
210
+ private skipIfExceedViewport = (el: Element) => {
211
+ const { viewport } = this.context;
212
+ return !viewport?.isInViewport(el.getRenderBounds(), false, 30);
213
+ };
214
+
215
+ private fixNodeLike = (datum: NodeLikeData, currentScale: number) => {
216
+ const id = idOf(datum);
217
+ const { element, model } = this.context;
218
+ const el = element!.getElement(id) as Node | Combo;
219
+
220
+ if (this.skipIfExceedViewport(el)) return;
221
+
222
+ const edges = model.getRelatedEdgesData(id);
223
+ edges.forEach((edge) => this.relatedEdgeToUpdate.add(idOf(edge)));
224
+
225
+ const config = this.options[(el as any).type];
226
+ if (!config) {
227
+ this.scaleEntireElement(id, el, currentScale);
228
+ return;
229
+ }
230
+ this.scaleSpecificShapes(el, currentScale, config);
231
+ };
232
+
233
+ private fixEdge = (datum: EdgeData, currentScale: number) => {
234
+ const id = idOf(datum);
235
+ const el = this.context.element!.getElement(id) as Edge;
236
+
237
+ if (this.skipIfExceedViewport(el)) return;
238
+
239
+ const config = this.options.edge;
240
+ if (!config) {
241
+ el.style.transformOrigin = 'center';
242
+ this.scaleEntireElement(id, el, currentScale);
243
+ return;
244
+ }
245
+ this.scaleSpecificShapes(el, currentScale, config);
246
+ };
247
+
248
+ private updateRelatedEdges = () => {
249
+ const { element } = this.context;
250
+ if (this.relatedEdgeToUpdate.size > 0) {
251
+ this.relatedEdgeToUpdate.forEach((id) => {
252
+ const edge = element!.getElement(id) as Edge;
253
+ edge?.update({});
254
+ });
255
+ }
256
+ this.relatedEdgeToUpdate.clear();
257
+ };
258
+
259
+ private restoreCachedStyles() {
260
+ if (this.cachedStyles.size > 0) {
261
+ this.cachedStyles.forEach((shapesStyle) => {
262
+ shapesStyle.forEach(({ shape, style }) => {
263
+ if (isEmpty(style)) {
264
+ shape.setLocalScale(1);
265
+ } else {
266
+ if (this.options.state) return;
267
+ Object.entries(style).forEach(([field, value]) => (shape.style[field] = value));
268
+ }
269
+ });
270
+ });
271
+ const { graph, element } = this.context;
272
+ const nodeIds = Object.keys(Object.fromEntries(this.cachedStyles)).filter(
273
+ (id) => id && graph.getElementType(id) === 'node',
274
+ );
275
+ if (nodeIds.length > 0) {
276
+ const edgeIds = new Set<ID>();
277
+ nodeIds.forEach((id) => {
278
+ graph.getRelatedEdgesData(id).forEach((edge) => edgeIds.add(idOf(edge)));
279
+ });
280
+ edgeIds.forEach((id) => {
281
+ const edge = element?.getElement(id) as Edge;
282
+ edge?.update({});
283
+ });
284
+ }
285
+ }
286
+ // this.cachedStyles.clear();
287
+ }
288
+
160
289
  private resetTransform = async () => {
161
- if (this.elementCache) {
162
- this.elementCache.forEach((el) => el.setLocalScale(1));
163
- this.elementCache.clear();
290
+ if (this.options.reset) {
291
+ this.restoreCachedStyles();
292
+ } else {
293
+ this.fixElementSize({ data: { scale: this.zoom } } as IViewportEvent);
164
294
  }
165
295
  };
166
296
 
167
297
  private bindEvents() {
168
298
  const { graph } = this.context;
299
+ graph.on(GraphEvent.AFTER_DRAW, this.resetTransform);
169
300
  graph.on(GraphEvent.AFTER_TRANSFORM, this.fixElementSize);
170
- graph.on(GraphEvent.BEFORE_DRAW, this.resetTransform);
171
301
  }
172
302
 
173
303
  private unbindEvents() {
174
304
  const { graph } = this.context;
305
+ graph.off(GraphEvent.AFTER_DRAW, this.resetTransform);
175
306
  graph.off(GraphEvent.AFTER_TRANSFORM, this.fixElementSize);
176
- graph.off(GraphEvent.BEFORE_DRAW, this.resetTransform);
177
307
  }
178
308
 
179
309
  private validate(event: IViewportEvent) {
@@ -2,7 +2,7 @@ import { isFunction } from '@antv/util';
2
2
  import { CommonEvent } from '../constants';
3
3
  import { ELEMENT_TYPES } from '../constants/element';
4
4
  import type { RuntimeContext } from '../runtime/types';
5
- import type { EdgeDirection, Element, ID, IDragEvent, IPointerEvent, State } from '../types';
5
+ import type { EdgeDirection, Element, ElementType, ID, IDragEvent, IPointerEvent, State } from '../types';
6
6
  import { isToBeDestroyed } from '../utils/element';
7
7
  import { idsOf } from '../utils/id';
8
8
  import { getElementNthDegreeIds } from '../utils/relation';
@@ -138,12 +138,11 @@ export class HoverActivate extends BaseBehavior<HoverActivateOptions> {
138
138
  const { graph } = this.context;
139
139
  const { degree, direction } = this.options;
140
140
  const elementId = event.target.id;
141
- const elementType = graph.getElementType(elementId);
142
141
 
143
142
  return degree
144
143
  ? getElementNthDegreeIds(
145
144
  graph,
146
- elementType,
145
+ event.targetType as ElementType,
147
146
  elementId,
148
147
  typeof degree === 'function' ? degree(event) : degree,
149
148
  direction,
@@ -1,3 +1,4 @@
1
+ export { AutoAdaptLabel } from './auto-adapt-label';
1
2
  export { BaseBehavior } from './base-behavior';
2
3
  export { BrushSelect } from './brush-select';
3
4
  export { ClickSelect } from './click-select';
@@ -14,6 +15,7 @@ export { OptimizeViewportTransform } from './optimize-viewport-transform';
14
15
  export { ScrollCanvas } from './scroll-canvas';
15
16
  export { ZoomCanvas } from './zoom-canvas';
16
17
 
18
+ export type { AutoAdaptLabelOptions } from './auto-adapt-label';
17
19
  export type { BaseBehaviorOptions } from './base-behavior';
18
20
  export type { BrushSelectOptions } from './brush-select';
19
21
  export type { ClickSelectOptions } from './click-select';
@@ -21,10 +21,10 @@ export interface OptimizeViewportTransformOptions extends BaseBehaviorOptions {
21
21
  */
22
22
  enable?: boolean | ((event: IViewportEvent) => boolean);
23
23
  /**
24
- * <zh/> 始终保留的图形类名。操作画布过程中会隐藏元素reservedShapes(除了指定类名的图形),以提高性能
24
+ * <zh/> 在画布操作过程中,元素会被隐藏以提高性能。通过设置 `shapes` 配置项,可以保留指定类名的子图形不被隐藏,从而保留整个元素的部分可见性
25
25
  *
26
- * <en/> Persistently reserved shape classnames. Elements are hidden during canvas manipulation (except for shapes with specified classnames) to enhance performance.
27
- * @defaultValue `{ node: ['key'] }`
26
+ * <en/> During canvas operations, elements are hidden to improve performance. By configuring the `shapes` option, specific sub-elements with designated class names can be retained, thereby maintaining partial visibility of the entire element.
27
+ * @defaultValue { node: ['key'] }
28
28
  */
29
29
  shapes?: {
30
30
  node?: string[];
package/src/exports.ts CHANGED
@@ -78,6 +78,7 @@ export {
78
78
  BubbleSets,
79
79
  CameraSetting,
80
80
  Contextmenu,
81
+ EdgeBundling,
81
82
  EdgeFilterLens,
82
83
  Fisheye,
83
84
  Fullscreen,
@@ -184,6 +185,7 @@ export type {
184
185
  BubbleSetsOptions,
185
186
  CameraSettingOptions,
186
187
  ContextmenuOptions,
188
+ EdgeBundlingOptions,
187
189
  EdgeFilterLensOptions,
188
190
  FisheyeOptions,
189
191
  FullscreenOptions,
@@ -260,6 +262,7 @@ export type {
260
262
  LoopStyleProps,
261
263
  Node,
262
264
  NodeBadgeStyleProps,
265
+ NodeCentralityOptions,
263
266
  NodeLabelStyleProps,
264
267
  NodeLikeData,
265
268
  NodePortStyleProps,