@antv/g6 5.0.16 → 5.0.18

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 (162) hide show
  1. package/dist/g6.min.js +2 -2
  2. package/dist/lib/behaviors/click-select.d.ts +0 -1
  3. package/dist/lib/behaviors/optimize-viewport-transform.d.ts +0 -1
  4. package/dist/lib/constants/events/canvas.d.ts +1 -1
  5. package/dist/lib/constants/registry.d.ts +7 -1
  6. package/dist/lib/elements/edges/polyline.d.ts +1 -0
  7. package/dist/lib/elements/effect.d.ts +19 -2
  8. package/dist/lib/elements/nodes/html.d.ts +14 -0
  9. package/dist/lib/elements/shapes/base-shape.d.ts +51 -2
  10. package/dist/lib/exports.d.ts +4 -2
  11. package/dist/lib/plugins/edge-filter-lens/index.d.ts +141 -0
  12. package/dist/lib/plugins/fisheye/index.d.ts +167 -0
  13. package/dist/lib/plugins/index.d.ts +4 -0
  14. package/dist/lib/plugins/tooltip.d.ts +1 -0
  15. package/dist/lib/registry/types.d.ts +4 -0
  16. package/dist/lib/runtime/element.d.ts +3 -1
  17. package/dist/lib/runtime/plugin.d.ts +1 -1
  18. package/dist/lib/types/element.d.ts +7 -0
  19. package/dist/lib/utils/dom.d.ts +8 -5
  20. package/dist/lib/version.d.ts +1 -1
  21. package/esm/behaviors/click-select.d.ts +0 -1
  22. package/esm/behaviors/click-select.js.map +1 -1
  23. package/esm/behaviors/optimize-viewport-transform.d.ts +0 -1
  24. package/esm/behaviors/optimize-viewport-transform.js +5 -4
  25. package/esm/behaviors/optimize-viewport-transform.js.map +1 -1
  26. package/esm/constants/events/canvas.d.ts +1 -1
  27. package/esm/constants/events/canvas.js +1 -1
  28. package/esm/constants/events/canvas.js.map +1 -1
  29. package/esm/constants/registry.d.ts +7 -1
  30. package/esm/constants/registry.js +6 -0
  31. package/esm/constants/registry.js.map +1 -1
  32. package/esm/elements/edges/polyline.d.ts +1 -0
  33. package/esm/elements/edges/polyline.js +5 -1
  34. package/esm/elements/edges/polyline.js.map +1 -1
  35. package/esm/elements/effect.d.ts +19 -2
  36. package/esm/elements/effect.js +19 -2
  37. package/esm/elements/effect.js.map +1 -1
  38. package/esm/elements/nodes/html.d.ts +14 -0
  39. package/esm/elements/nodes/html.js +10 -4
  40. package/esm/elements/nodes/html.js.map +1 -1
  41. package/esm/elements/shapes/base-shape.d.ts +51 -2
  42. package/esm/elements/shapes/base-shape.js +22 -4
  43. package/esm/elements/shapes/base-shape.js.map +1 -1
  44. package/esm/exports.d.ts +4 -2
  45. package/esm/exports.js +2 -1
  46. package/esm/exports.js.map +1 -1
  47. package/esm/plugins/contextmenu/index.js +1 -1
  48. package/esm/plugins/contextmenu/index.js.map +1 -1
  49. package/esm/plugins/edge-filter-lens/index.d.ts +141 -0
  50. package/esm/plugins/edge-filter-lens/index.js +241 -0
  51. package/esm/plugins/edge-filter-lens/index.js.map +1 -0
  52. package/esm/plugins/fisheye/index.d.ts +167 -0
  53. package/esm/plugins/fisheye/index.js +288 -0
  54. package/esm/plugins/fisheye/index.js.map +1 -0
  55. package/esm/plugins/index.d.ts +4 -0
  56. package/esm/plugins/index.js +2 -0
  57. package/esm/plugins/index.js.map +1 -1
  58. package/esm/plugins/snapline/index.js +2 -2
  59. package/esm/plugins/snapline/index.js.map +1 -1
  60. package/esm/plugins/tooltip.d.ts +1 -0
  61. package/esm/plugins/tooltip.js +16 -17
  62. package/esm/plugins/tooltip.js.map +1 -1
  63. package/esm/registry/build-in.js +20 -1
  64. package/esm/registry/build-in.js.map +1 -1
  65. package/esm/registry/store.js +1 -0
  66. package/esm/registry/store.js.map +1 -1
  67. package/esm/registry/types.d.ts +4 -0
  68. package/esm/runtime/element.d.ts +3 -1
  69. package/esm/runtime/element.js +8 -2
  70. package/esm/runtime/element.js.map +1 -1
  71. package/esm/runtime/plugin.d.ts +1 -1
  72. package/esm/runtime/plugin.js +8 -1
  73. package/esm/runtime/plugin.js.map +1 -1
  74. package/esm/types/element.d.ts +7 -0
  75. package/esm/utils/dom.d.ts +8 -5
  76. package/esm/utils/dom.js +24 -15
  77. package/esm/utils/dom.js.map +1 -1
  78. package/esm/version.d.ts +1 -1
  79. package/esm/version.js +1 -1
  80. package/lib/behaviors/click-select.d.ts +0 -1
  81. package/lib/behaviors/click-select.js.map +1 -1
  82. package/lib/behaviors/optimize-viewport-transform.d.ts +0 -1
  83. package/lib/behaviors/optimize-viewport-transform.js +5 -4
  84. package/lib/behaviors/optimize-viewport-transform.js.map +1 -1
  85. package/lib/constants/events/canvas.d.ts +1 -1
  86. package/lib/constants/events/canvas.js +1 -1
  87. package/lib/constants/events/canvas.js.map +1 -1
  88. package/lib/constants/registry.d.ts +7 -1
  89. package/lib/constants/registry.js +6 -0
  90. package/lib/constants/registry.js.map +1 -1
  91. package/lib/elements/edges/polyline.d.ts +1 -0
  92. package/lib/elements/edges/polyline.js +5 -1
  93. package/lib/elements/edges/polyline.js.map +1 -1
  94. package/lib/elements/effect.d.ts +19 -2
  95. package/lib/elements/effect.js +19 -2
  96. package/lib/elements/effect.js.map +1 -1
  97. package/lib/elements/nodes/html.d.ts +14 -0
  98. package/lib/elements/nodes/html.js +10 -4
  99. package/lib/elements/nodes/html.js.map +1 -1
  100. package/lib/elements/shapes/base-shape.d.ts +51 -2
  101. package/lib/elements/shapes/base-shape.js +22 -4
  102. package/lib/elements/shapes/base-shape.js.map +1 -1
  103. package/lib/exports.d.ts +4 -2
  104. package/lib/exports.js +7 -2
  105. package/lib/exports.js.map +1 -1
  106. package/lib/plugins/contextmenu/index.js +1 -1
  107. package/lib/plugins/contextmenu/index.js.map +1 -1
  108. package/lib/plugins/edge-filter-lens/index.d.ts +141 -0
  109. package/lib/plugins/edge-filter-lens/index.js +245 -0
  110. package/lib/plugins/edge-filter-lens/index.js.map +1 -0
  111. package/lib/plugins/fisheye/index.d.ts +167 -0
  112. package/lib/plugins/fisheye/index.js +292 -0
  113. package/lib/plugins/fisheye/index.js.map +1 -0
  114. package/lib/plugins/index.d.ts +4 -0
  115. package/lib/plugins/index.js +5 -1
  116. package/lib/plugins/index.js.map +1 -1
  117. package/lib/plugins/snapline/index.js +2 -2
  118. package/lib/plugins/snapline/index.js.map +1 -1
  119. package/lib/plugins/tooltip.d.ts +1 -0
  120. package/lib/plugins/tooltip.js +16 -17
  121. package/lib/plugins/tooltip.js.map +1 -1
  122. package/lib/registry/build-in.js +19 -0
  123. package/lib/registry/build-in.js.map +1 -1
  124. package/lib/registry/store.js +1 -0
  125. package/lib/registry/store.js.map +1 -1
  126. package/lib/registry/types.d.ts +4 -0
  127. package/lib/runtime/element.d.ts +3 -1
  128. package/lib/runtime/element.js +8 -2
  129. package/lib/runtime/element.js.map +1 -1
  130. package/lib/runtime/plugin.d.ts +1 -1
  131. package/lib/runtime/plugin.js +8 -1
  132. package/lib/runtime/plugin.js.map +1 -1
  133. package/lib/types/element.d.ts +7 -0
  134. package/lib/utils/dom.d.ts +8 -5
  135. package/lib/utils/dom.js +24 -15
  136. package/lib/utils/dom.js.map +1 -1
  137. package/lib/version.d.ts +1 -1
  138. package/lib/version.js +1 -1
  139. package/package.json +1 -1
  140. package/src/behaviors/click-select.ts +0 -1
  141. package/src/behaviors/optimize-viewport-transform.ts +4 -10
  142. package/src/constants/events/canvas.ts +1 -1
  143. package/src/constants/registry.ts +6 -0
  144. package/src/elements/edges/polyline.ts +7 -1
  145. package/src/elements/effect.ts +19 -2
  146. package/src/elements/nodes/html.ts +28 -4
  147. package/src/elements/shapes/base-shape.ts +75 -5
  148. package/src/exports.ts +8 -0
  149. package/src/plugins/contextmenu/index.ts +1 -1
  150. package/src/plugins/edge-filter-lens/index.ts +404 -0
  151. package/src/plugins/fisheye/index.ts +481 -0
  152. package/src/plugins/index.ts +4 -0
  153. package/src/plugins/snapline/index.ts +2 -2
  154. package/src/plugins/tooltip.ts +18 -17
  155. package/src/registry/build-in.ts +32 -0
  156. package/src/registry/store.ts +1 -0
  157. package/src/registry/types.ts +2 -0
  158. package/src/runtime/element.ts +11 -3
  159. package/src/runtime/plugin.ts +8 -1
  160. package/src/types/element.ts +7 -0
  161. package/src/utils/dom.ts +24 -15
  162. package/src/version.ts +1 -1
package/src/exports.ts CHANGED
@@ -28,6 +28,7 @@ export {
28
28
  } from './constants';
29
29
  export { BaseCombo, CircleCombo, RectCombo } from './elements/combos';
30
30
  export { BaseEdge, Cubic, CubicHorizontal, CubicVertical, Line, Polyline, Quadratic } from './elements/edges';
31
+ export { effect } from './elements/effect';
31
32
  export {
32
33
  BaseNode,
33
34
  Circle,
@@ -67,12 +68,15 @@ export {
67
68
  BubbleSets,
68
69
  CameraSetting,
69
70
  Contextmenu,
71
+ EdgeFilterLens,
72
+ Fisheye,
70
73
  Fullscreen,
71
74
  GridLine,
72
75
  History,
73
76
  Hull,
74
77
  Legend,
75
78
  Minimap,
79
+ Snapline,
76
80
  Timebar,
77
81
  Toolbar,
78
82
  Tooltip,
@@ -158,6 +162,7 @@ export type {
158
162
  LabelStyleProps,
159
163
  PolygonStyleProps,
160
164
  } from './elements/shapes';
165
+ export type { UpsertHooks } from './elements/shapes/base-shape';
161
166
  export type { ContourLabelStyleProps, ContourStyleProps } from './elements/shapes/contour';
162
167
  export type { BaseLayoutOptions, WebWorkerLayoutOptions } from './layouts/types';
163
168
  export type { CategoricalPalette } from './palettes/types';
@@ -166,12 +171,15 @@ export type {
166
171
  BubbleSetsOptions,
167
172
  CameraSettingOptions,
168
173
  ContextmenuOptions,
174
+ EdgeFilterLensOptions,
175
+ FisheyeOptions,
169
176
  FullscreenOptions,
170
177
  GridLineOptions,
171
178
  HistoryOptions,
172
179
  HullOptions,
173
180
  LegendOptions,
174
181
  MinimapOptions,
182
+ SnaplineOptions,
175
183
  TimebarOptions,
176
184
  ToolbarOptions,
177
185
  TooltipOptions,
@@ -100,7 +100,7 @@ export class Contextmenu extends BasePlugin<ContextmenuOptions> {
100
100
  }
101
101
 
102
102
  private initElement() {
103
- this.$element = createPluginContainer('contextmenu', false);
103
+ this.$element = createPluginContainer('contextmenu', false, { zIndex: '99' });
104
104
  const { className } = this.options;
105
105
  if (className) this.$element.classList.add(className);
106
106
 
@@ -0,0 +1,404 @@
1
+ import type { BaseStyleProps } from '@antv/g';
2
+ import { CommonEvent } from '../../constants';
3
+ import { Circle } from '../../elements';
4
+ import type { RuntimeContext } from '../../runtime/types';
5
+ import type { EdgeData, GraphData, NodeData } from '../../spec';
6
+ import type { EdgeStyle } from '../../spec/element/edge';
7
+ import type { NodeStyle } from '../../spec/element/node';
8
+ import type {
9
+ Element,
10
+ ElementDatum,
11
+ ElementType,
12
+ ID,
13
+ IDragEvent,
14
+ IPointerEvent,
15
+ Point,
16
+ PointObject,
17
+ } from '../../types';
18
+ import { idOf } from '../../utils/id';
19
+ import { parsePoint, toPointObject } from '../../utils/point';
20
+ import { positionOf } from '../../utils/position';
21
+ import { distance } from '../../utils/vector';
22
+ import type { BasePluginOptions } from '../base-plugin';
23
+ import { BasePlugin } from '../base-plugin';
24
+
25
+ /**
26
+ * <zh/> 边过滤镜插件配置项
27
+ *
28
+ * <en/> Edge filter lens plugin options
29
+ */
30
+ export interface EdgeFilterLensOptions extends BasePluginOptions {
31
+ /**
32
+ * <zh/> 移动透镜的方式
33
+ * - `'pointermove'`:始终跟随鼠标移动
34
+ * - `'click'`:鼠标点击时透镜移动
35
+ * - `'drag'`:拖拽透镜
36
+ *
37
+ * <en/> The way to move the lens
38
+ * - `'pointermove'`: always follow the mouse movement
39
+ * - `'click'`: move the lens when the mouse clicks
40
+ * - `'drag'`: drag the lens
41
+ * @defaultValue 'pointermove'
42
+ */
43
+ trigger?: 'pointermove' | 'click' | 'drag';
44
+ /**
45
+ * <zh/> 透镜的半径
46
+ *
47
+ * <en/> The radius of the lens
48
+ * @defaultValue 60
49
+ */
50
+ r?: number;
51
+ /**
52
+ * <zh/> 透镜的最大半径。只有在 `scaleRBy` 为 `wheel` 时生效
53
+ *
54
+ * <en/> The maximum radius of the lens. Only valid when `scaleRBy` is `wheel`
55
+ * @defaultValue canvas 宽高最小值的一半
56
+ */
57
+ maxR?: number;
58
+ /**
59
+ * <zh/> 透镜的最小半径。只有在 `scaleRBy` 为 `wheel` 时生效
60
+ *
61
+ * <en/> The minimum radius of the lens. Only valid when `scaleRBy` is `wheel`
62
+ * @defaultValue 0
63
+ */
64
+ minR?: number;
65
+ /**
66
+ * <zh/> 缩放透镜半径的方式
67
+ * - `'wheel'`:通过滚轮缩放透镜的半径
68
+ *
69
+ * <en/> The way to scale the radius of the lens
70
+ * - `'wheel'`: scale the radius of the lens by the wheel
71
+ * @defaultValue `'wheel'`
72
+ */
73
+ scaleRBy?: 'wheel';
74
+ /**
75
+ * <zh/> 边显示的条件
76
+ * - `'both'`:只有起始节点和目标节点都在透镜中时,边才会显示
77
+ * - `'source'`:只有起始节点在透镜中时,边才会显示
78
+ * - `'target'`:只有目标节点在透镜中时,边才会显示
79
+ * - `'either'`:只要起始节点或目标节点有一个在透镜中时,边就会显示
80
+ *
81
+ * <en/> The condition for displaying the edge
82
+ * - `'both'`: The edge is displayed only when both the source node and the target node are in the lens
83
+ * - `'source'`: The edge is displayed only when the source node is in the lens
84
+ * - `'target'`: The edge is displayed only when the target node is in the lens
85
+ * - `'either'`: The edge is displayed when either the source node or the target node is in the lens
86
+ * @defaultValue 'both'
87
+ */
88
+ nodeType?: 'both' | 'source' | 'target' | 'either';
89
+ /**
90
+ * <zh/> 过滤出始终不在透镜中显示的元素
91
+ *
92
+ * <en/> Filter elements that are never displayed in the lens
93
+ * @param id - <zh/> 元素的 id | <en/> The id of the element
94
+ * @param elementType - <zh/> 元素的类型 | <en/> The type of the element
95
+ * @returns <zh/> 是否显示 | <en/> Whether to display
96
+ */
97
+ filter?: (id: ID, elementType: ElementType) => boolean;
98
+ /**
99
+ * <zh/> 透镜的样式
100
+ *
101
+ * <en/> The style of the lens
102
+ */
103
+ style?: BaseStyleProps;
104
+ /**
105
+ * <zh/> 在透镜中节点的样式
106
+ *
107
+ * <en/> The style of the nodes displayed in the lens
108
+ */
109
+ nodeStyle?: NodeStyle | ((datum: NodeData) => NodeStyle);
110
+ /**
111
+ * <zh/> 在透镜中边的样式
112
+ *
113
+ * <en/> The style of the edges displayed in the lens
114
+ */
115
+ edgeStyle?: EdgeStyle | ((datum: EdgeData) => EdgeStyle);
116
+ /**
117
+ * <zh/> 是否阻止默认事件
118
+ *
119
+ * <en/> Whether to prevent the default event
120
+ * @defaultValue true
121
+ */
122
+ preventDefault?: boolean;
123
+ }
124
+
125
+ const defaultLensStyle: BaseStyleProps = {
126
+ fill: '#fff',
127
+ fillOpacity: 1,
128
+ lineWidth: 1,
129
+ stroke: '#000',
130
+ strokeOpacity: 0.8,
131
+ };
132
+
133
+ const DELTA = 0.05;
134
+
135
+ /**
136
+ * <zh/> 边过滤镜插件
137
+ *
138
+ * <en/> Edge filter lens plugin
139
+ * @remarks
140
+ * <zh/> 边过滤镜可以将关注的边保留在过滤镜范围内,其他边将在该范围内不显示。
141
+ *
142
+ * <en/> EdgeFilterLens can keep the focused edges within the lens range, while other edges will not be displayed within that range.
143
+ */
144
+ export class EdgeFilterLens extends BasePlugin<EdgeFilterLensOptions> {
145
+ static defaultOptions: Partial<EdgeFilterLensOptions> = {
146
+ trigger: 'pointermove',
147
+ r: 60,
148
+ nodeType: 'both',
149
+ filter: () => true,
150
+ style: { lineWidth: 2 },
151
+ nodeStyle: { label: false },
152
+ edgeStyle: { label: true },
153
+ scaleRBy: 'wheel',
154
+ preventDefault: true,
155
+ };
156
+
157
+ constructor(context: RuntimeContext, options: EdgeFilterLensOptions) {
158
+ super(context, Object.assign({}, EdgeFilterLens.defaultOptions, options));
159
+ this.bindEvents();
160
+ }
161
+
162
+ private lens!: Circle;
163
+
164
+ private shapes = new Map<ID, Element>();
165
+
166
+ private r = this.options.r;
167
+
168
+ private get canvas() {
169
+ return this.context.canvas.getLayer('transient');
170
+ }
171
+
172
+ private get isLensOn() {
173
+ return this.lens && !this.lens.destroyed;
174
+ }
175
+
176
+ protected onEdgeFilter = (event: IPointerEvent) => {
177
+ if (this.options.trigger === 'drag' && this.isLensOn) return;
178
+
179
+ const origin = parsePoint(event.canvas as PointObject);
180
+ this.renderLens(origin);
181
+ this.renderFocusElements();
182
+ };
183
+
184
+ private renderLens = (origin: Point) => {
185
+ const style = Object.assign({}, defaultLensStyle, this.options.style);
186
+
187
+ if (!this.isLensOn) {
188
+ this.lens = new Circle({ style });
189
+ this.canvas.appendChild(this.lens);
190
+ }
191
+
192
+ Object.assign(style, toPointObject(origin), { size: this.r * 2 });
193
+
194
+ this.lens.update(style);
195
+ };
196
+
197
+ private getFilterData = (): Required<GraphData> => {
198
+ const { filter } = this.options;
199
+ const { model } = this.context;
200
+ const data = model.getData();
201
+
202
+ if (!filter) return data;
203
+
204
+ const { nodes, edges, combos } = data;
205
+
206
+ return {
207
+ nodes: nodes.filter((node) => filter(idOf(node), 'node')),
208
+ edges: edges.filter((edge) => filter(idOf(edge), 'edge')),
209
+ combos: combos.filter((combo) => filter(idOf(combo), 'combo')),
210
+ };
211
+ };
212
+
213
+ private getFocusElements = (origin: Point) => {
214
+ const { nodes, edges } = this.getFilterData();
215
+
216
+ const focusNodes = nodes.filter((datum) => distance(positionOf(datum), origin) < this.r);
217
+ const focusNodeIds = focusNodes.map((node) => idOf(node));
218
+
219
+ const focusEdges = edges.filter((datum) => {
220
+ const { source, target } = datum;
221
+ const isSourceFocus = focusNodeIds.includes(source);
222
+ const isTargetFocus = focusNodeIds.includes(target);
223
+
224
+ switch (this.options.nodeType) {
225
+ case 'both':
226
+ return isSourceFocus && isTargetFocus;
227
+ case 'either':
228
+ return isSourceFocus !== isTargetFocus;
229
+ case 'source':
230
+ return isSourceFocus && !isTargetFocus;
231
+ case 'target':
232
+ return !isSourceFocus && isTargetFocus;
233
+ default:
234
+ return false;
235
+ }
236
+ });
237
+
238
+ return { nodes: focusNodes, edges: focusEdges };
239
+ };
240
+
241
+ private renderFocusElements = () => {
242
+ const { element, graph } = this.context;
243
+ if (!this.isLensOn) return;
244
+
245
+ const origin = this.lens.getCenter();
246
+ const { nodes, edges } = this.getFocusElements(origin);
247
+
248
+ const ids = new Set<ID>();
249
+
250
+ const iterate = (datum: ElementDatum) => {
251
+ const id = idOf(datum);
252
+ ids.add(id);
253
+
254
+ const shape = element!.getElement(id);
255
+ if (!shape) return;
256
+
257
+ const cloneShape = this.shapes.get(id) || shape.cloneNode();
258
+
259
+ cloneShape.setPosition(shape.getPosition());
260
+ cloneShape.id = shape.id;
261
+
262
+ if (!this.shapes.has(id)) {
263
+ this.canvas.appendChild(cloneShape);
264
+ this.shapes.set(id, cloneShape);
265
+ } else {
266
+ Object.entries(shape.attributes).forEach(([key, value]) => {
267
+ if (cloneShape.style[key] !== value) cloneShape.style[key] = value;
268
+ });
269
+ }
270
+
271
+ const elementType = graph.getElementType(id) as Exclude<ElementType, 'combo'>;
272
+ const style = this.getElementStyle(elementType, datum);
273
+
274
+ // @ts-ignore
275
+ cloneShape.update(style);
276
+ };
277
+
278
+ nodes.forEach(iterate);
279
+ edges.forEach(iterate);
280
+
281
+ this.shapes.forEach((shape, id) => {
282
+ if (!ids.has(id)) {
283
+ shape.destroy();
284
+ this.shapes.delete(id);
285
+ }
286
+ });
287
+ };
288
+
289
+ private getElementStyle(elementType: ElementType, datum: ElementDatum) {
290
+ const styler = elementType === 'node' ? this.options.nodeStyle : this.options.edgeStyle;
291
+ if (typeof styler === 'function') return styler(datum as any);
292
+ return styler;
293
+ }
294
+
295
+ private scaleRByWheel = (event: WheelEvent) => {
296
+ if (this.options.preventDefault) event.preventDefault();
297
+ const { clientX, clientY, deltaX, deltaY } = event;
298
+ const { graph, canvas } = this.context;
299
+ const scaleOrigin = graph.getCanvasByClient([clientX, clientY]);
300
+ const origin = this.lens?.getCenter();
301
+
302
+ if (!this.isLensOn || distance(scaleOrigin, origin) > this.r) {
303
+ return;
304
+ }
305
+
306
+ const { maxR, minR } = this.options;
307
+ const ratio = deltaX + deltaY > 0 ? 1 / (1 - DELTA) : 1 - DELTA;
308
+ const canvasR = Math.min(...canvas.getSize()) / 2;
309
+ this.r = Math.max(minR || 0, Math.min(maxR || canvasR, this.r * ratio));
310
+
311
+ this.renderLens(origin);
312
+ this.renderFocusElements();
313
+ };
314
+
315
+ get graphDom() {
316
+ return this.context.graph.getCanvas().getContextService().getDomElement();
317
+ }
318
+
319
+ private isLensDragging = false;
320
+
321
+ private onDragStart = (event: IDragEvent) => {
322
+ const dragOrigin = parsePoint(event.canvas as PointObject);
323
+ const origin = this.lens?.getCenter();
324
+
325
+ if (!this.isLensOn || distance(dragOrigin, origin) > this.r) return;
326
+
327
+ this.isLensDragging = true;
328
+ };
329
+
330
+ private onDrag = (event: IDragEvent) => {
331
+ if (!this.isLensDragging) return;
332
+
333
+ const dragOrigin = parsePoint(event.canvas as PointObject);
334
+ this.renderLens(dragOrigin);
335
+ this.renderFocusElements();
336
+ };
337
+
338
+ private onDragEnd = () => {
339
+ this.isLensDragging = false;
340
+ };
341
+
342
+ private bindEvents() {
343
+ const { graph } = this.context;
344
+ const { trigger, scaleRBy } = this.options;
345
+
346
+ const canvas = graph.getCanvas().getLayer();
347
+
348
+ if (['click', 'drag'].includes(trigger)) {
349
+ canvas.addEventListener(CommonEvent.CLICK, this.onEdgeFilter);
350
+ }
351
+
352
+ if (trigger === 'pointermove') {
353
+ canvas.addEventListener(CommonEvent.POINTER_MOVE, this.onEdgeFilter);
354
+ } else if (trigger === 'drag') {
355
+ canvas.addEventListener(CommonEvent.DRAG_START, this.onDragStart);
356
+ canvas.addEventListener(CommonEvent.DRAG, this.onDrag);
357
+ canvas.addEventListener(CommonEvent.DRAG_END, this.onDragEnd);
358
+ }
359
+
360
+ if (scaleRBy === 'wheel') {
361
+ this.graphDom?.addEventListener(CommonEvent.WHEEL, this.scaleRByWheel, { passive: false });
362
+ }
363
+ }
364
+
365
+ private unbindEvents() {
366
+ const { graph } = this.context;
367
+ const { trigger, scaleRBy } = this.options;
368
+ const canvas = graph.getCanvas().getLayer();
369
+
370
+ if (['click', 'drag'].includes(trigger)) {
371
+ canvas.removeEventListener(CommonEvent.CLICK, this.onEdgeFilter);
372
+ }
373
+
374
+ if (trigger === 'pointermove') {
375
+ canvas.removeEventListener(CommonEvent.POINTER_MOVE, this.onEdgeFilter);
376
+ } else if (trigger === 'drag') {
377
+ canvas.removeEventListener(CommonEvent.DRAG_START, this.onDragStart);
378
+ canvas.removeEventListener(CommonEvent.DRAG, this.onDrag);
379
+ canvas.removeEventListener(CommonEvent.DRAG_END, this.onDragEnd);
380
+ }
381
+
382
+ if (scaleRBy === 'wheel') {
383
+ this.graphDom?.removeEventListener(CommonEvent.WHEEL, this.scaleRByWheel);
384
+ }
385
+ }
386
+
387
+ public update(options: Partial<EdgeFilterLensOptions>) {
388
+ this.unbindEvents();
389
+ super.update(options);
390
+ this.bindEvents();
391
+ }
392
+
393
+ public destroy() {
394
+ this.unbindEvents();
395
+ if (this.isLensOn) {
396
+ this.lens.destroy();
397
+ }
398
+ this.shapes.forEach((shape, id) => {
399
+ shape.destroy();
400
+ this.shapes.delete(id);
401
+ });
402
+ super.destroy();
403
+ }
404
+ }