@antv/g6 5.0.17 → 5.0.19

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 (142) 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/drag-element.d.ts +0 -1
  4. package/dist/lib/constants/events/canvas.d.ts +1 -1
  5. package/dist/lib/elements/effect.d.ts +7 -13
  6. package/dist/lib/elements/nodes/html.d.ts +14 -0
  7. package/dist/lib/elements/shapes/base-shape.d.ts +1 -1
  8. package/dist/lib/exports.d.ts +2 -2
  9. package/dist/lib/plugins/edge-filter-lens/index.d.ts +25 -9
  10. package/dist/lib/plugins/fisheye/index.d.ts +167 -0
  11. package/dist/lib/plugins/index.d.ts +2 -0
  12. package/dist/lib/plugins/tooltip.d.ts +1 -0
  13. package/dist/lib/runtime/element.d.ts +3 -1
  14. package/dist/lib/types/element.d.ts +7 -0
  15. package/dist/lib/utils/dom.d.ts +8 -5
  16. package/dist/lib/version.d.ts +1 -1
  17. package/esm/behaviors/click-select.d.ts +0 -1
  18. package/esm/behaviors/click-select.js.map +1 -1
  19. package/esm/behaviors/drag-element.d.ts +0 -1
  20. package/esm/behaviors/drag-element.js +14 -7
  21. package/esm/behaviors/drag-element.js.map +1 -1
  22. package/esm/constants/events/canvas.d.ts +1 -1
  23. package/esm/constants/events/canvas.js +1 -1
  24. package/esm/constants/events/canvas.js.map +1 -1
  25. package/esm/elements/combos/base-combo.js +4 -10
  26. package/esm/elements/combos/base-combo.js.map +1 -1
  27. package/esm/elements/edges/base-edge.js +18 -29
  28. package/esm/elements/edges/base-edge.js.map +1 -1
  29. package/esm/elements/effect.d.ts +7 -13
  30. package/esm/elements/effect.js +20 -33
  31. package/esm/elements/effect.js.map +1 -1
  32. package/esm/elements/nodes/base-node.js +21 -29
  33. package/esm/elements/nodes/base-node.js.map +1 -1
  34. package/esm/elements/nodes/html.d.ts +14 -0
  35. package/esm/elements/nodes/html.js +10 -4
  36. package/esm/elements/nodes/html.js.map +1 -1
  37. package/esm/elements/shapes/base-shape.d.ts +1 -1
  38. package/esm/elements/shapes/base-shape.js +1 -1
  39. package/esm/exports.d.ts +2 -2
  40. package/esm/exports.js +1 -1
  41. package/esm/exports.js.map +1 -1
  42. package/esm/plugins/contextmenu/index.js +1 -1
  43. package/esm/plugins/contextmenu/index.js.map +1 -1
  44. package/esm/plugins/edge-filter-lens/index.d.ts +25 -9
  45. package/esm/plugins/edge-filter-lens/index.js +19 -14
  46. package/esm/plugins/edge-filter-lens/index.js.map +1 -1
  47. package/esm/plugins/fisheye/index.d.ts +167 -0
  48. package/esm/plugins/fisheye/index.js +288 -0
  49. package/esm/plugins/fisheye/index.js.map +1 -0
  50. package/esm/plugins/index.d.ts +2 -0
  51. package/esm/plugins/index.js +1 -0
  52. package/esm/plugins/index.js.map +1 -1
  53. package/esm/plugins/tooltip.d.ts +1 -0
  54. package/esm/plugins/tooltip.js +16 -17
  55. package/esm/plugins/tooltip.js.map +1 -1
  56. package/esm/registry/build-in.js +2 -1
  57. package/esm/registry/build-in.js.map +1 -1
  58. package/esm/runtime/element.d.ts +3 -1
  59. package/esm/runtime/element.js +32 -9
  60. package/esm/runtime/element.js.map +1 -1
  61. package/esm/runtime/graph.js +2 -0
  62. package/esm/runtime/graph.js.map +1 -1
  63. package/esm/types/element.d.ts +7 -0
  64. package/esm/utils/dom.d.ts +8 -5
  65. package/esm/utils/dom.js +24 -15
  66. package/esm/utils/dom.js.map +1 -1
  67. package/esm/version.d.ts +1 -1
  68. package/esm/version.js +1 -1
  69. package/lib/behaviors/click-select.d.ts +0 -1
  70. package/lib/behaviors/click-select.js.map +1 -1
  71. package/lib/behaviors/drag-element.d.ts +0 -1
  72. package/lib/behaviors/drag-element.js +14 -7
  73. package/lib/behaviors/drag-element.js.map +1 -1
  74. package/lib/constants/events/canvas.d.ts +1 -1
  75. package/lib/constants/events/canvas.js +1 -1
  76. package/lib/constants/events/canvas.js.map +1 -1
  77. package/lib/elements/combos/base-combo.js +4 -10
  78. package/lib/elements/combos/base-combo.js.map +1 -1
  79. package/lib/elements/edges/base-edge.js +18 -29
  80. package/lib/elements/edges/base-edge.js.map +1 -1
  81. package/lib/elements/effect.d.ts +7 -13
  82. package/lib/elements/effect.js +20 -33
  83. package/lib/elements/effect.js.map +1 -1
  84. package/lib/elements/nodes/base-node.js +21 -29
  85. package/lib/elements/nodes/base-node.js.map +1 -1
  86. package/lib/elements/nodes/html.d.ts +14 -0
  87. package/lib/elements/nodes/html.js +10 -4
  88. package/lib/elements/nodes/html.js.map +1 -1
  89. package/lib/elements/shapes/base-shape.d.ts +1 -1
  90. package/lib/elements/shapes/base-shape.js +1 -1
  91. package/lib/exports.d.ts +2 -2
  92. package/lib/exports.js +2 -1
  93. package/lib/exports.js.map +1 -1
  94. package/lib/plugins/contextmenu/index.js +1 -1
  95. package/lib/plugins/contextmenu/index.js.map +1 -1
  96. package/lib/plugins/edge-filter-lens/index.d.ts +25 -9
  97. package/lib/plugins/edge-filter-lens/index.js +18 -13
  98. package/lib/plugins/edge-filter-lens/index.js.map +1 -1
  99. package/lib/plugins/fisheye/index.d.ts +167 -0
  100. package/lib/plugins/fisheye/index.js +292 -0
  101. package/lib/plugins/fisheye/index.js.map +1 -0
  102. package/lib/plugins/index.d.ts +2 -0
  103. package/lib/plugins/index.js +3 -1
  104. package/lib/plugins/index.js.map +1 -1
  105. package/lib/plugins/tooltip.d.ts +1 -0
  106. package/lib/plugins/tooltip.js +16 -17
  107. package/lib/plugins/tooltip.js.map +1 -1
  108. package/lib/registry/build-in.js +1 -0
  109. package/lib/registry/build-in.js.map +1 -1
  110. package/lib/runtime/element.d.ts +3 -1
  111. package/lib/runtime/element.js +32 -9
  112. package/lib/runtime/element.js.map +1 -1
  113. package/lib/runtime/graph.js +2 -0
  114. package/lib/runtime/graph.js.map +1 -1
  115. package/lib/types/element.d.ts +7 -0
  116. package/lib/utils/dom.d.ts +8 -5
  117. package/lib/utils/dom.js +24 -15
  118. package/lib/utils/dom.js.map +1 -1
  119. package/lib/version.d.ts +1 -1
  120. package/lib/version.js +1 -1
  121. package/package.json +2 -2
  122. package/src/behaviors/click-select.ts +0 -1
  123. package/src/behaviors/drag-element.ts +17 -7
  124. package/src/constants/events/canvas.ts +1 -1
  125. package/src/elements/combos/base-combo.ts +3 -2
  126. package/src/elements/edges/base-edge.ts +14 -11
  127. package/src/elements/effect.ts +20 -37
  128. package/src/elements/nodes/base-node.ts +21 -16
  129. package/src/elements/nodes/html.ts +28 -4
  130. package/src/elements/shapes/base-shape.ts +1 -1
  131. package/src/exports.ts +2 -0
  132. package/src/plugins/contextmenu/index.ts +1 -1
  133. package/src/plugins/edge-filter-lens/index.ts +36 -23
  134. package/src/plugins/fisheye/index.ts +481 -0
  135. package/src/plugins/index.ts +2 -0
  136. package/src/plugins/tooltip.ts +18 -17
  137. package/src/registry/build-in.ts +2 -0
  138. package/src/runtime/element.ts +32 -10
  139. package/src/runtime/graph.ts +1 -0
  140. package/src/types/element.ts +7 -0
  141. package/src/utils/dom.ts +24 -15
  142. package/src/version.ts +1 -1
@@ -335,6 +335,8 @@ export abstract class BaseEdge extends BaseElement<BaseEdgeStyleProps> implement
335
335
 
336
336
  if (enable) {
337
337
  const arrowStyle = this.getArrowStyle(attributes, isStart);
338
+ if (!effect(this, `arrow-${type}`, arrowStyle)) return;
339
+
338
340
  const [marker, markerOffset, arrowOffset] = isStart
339
341
  ? (['markerStart', 'markerStartOffset', 'startArrowOffset'] as const)
340
342
  : (['markerEnd', 'markerEndOffset', 'endArrowOffset'] as const);
@@ -376,35 +378,36 @@ export abstract class BaseEdge extends BaseElement<BaseEdgeStyleProps> implement
376
378
  );
377
379
  }
378
380
 
379
- @effect((self, attributes) => self.getLabelStyle(attributes))
380
381
  protected drawLabelShape(attributes: ParsedBaseEdgeStyleProps, container: Group) {
381
- this.upsert('label', Label, this.getLabelStyle(attributes), container);
382
+ const style = this.getLabelStyle(attributes);
383
+ if (!effect(this, 'label', style)) return;
384
+ this.upsert('label', Label, style, container);
382
385
  }
383
386
 
384
- @effect((self, attributes) => self.getHaloStyle(attributes))
385
387
  protected drawHaloShape(attributes: ParsedBaseEdgeStyleProps, container: Group) {
386
- this.upsert('halo', Path, this.getHaloStyle(attributes), container);
388
+ const style = this.getHaloStyle(attributes);
389
+ if (!effect(this, 'halo', style)) return;
390
+ this.upsert('halo', Path, style, container);
387
391
  }
388
392
 
389
- @effect((self, attributes) => self.getBadgeStyle(attributes))
390
393
  protected drawBadgeShape(attributes: ParsedBaseEdgeStyleProps, container: Group) {
391
- this.upsert('badge', Badge, this.getBadgeStyle(attributes), container);
394
+ const style = this.getBadgeStyle(attributes);
395
+ if (!effect(this, 'badge', style)) return;
396
+ this.upsert('badge', Badge, style, container);
392
397
  }
393
398
 
394
- @effect((self, attributes) => self.getArrowStyle(attributes, 'start'))
395
399
  protected drawSourceArrow(attributes: ParsedBaseEdgeStyleProps) {
396
400
  this.drawArrow(attributes, 'start');
397
401
  }
398
402
 
399
- @effect((self, attributes) => self.getArrowStyle(attributes, 'end'))
400
403
  protected drawTargetArrow(attributes: ParsedBaseEdgeStyleProps) {
401
404
  this.drawArrow(attributes, 'end');
402
405
  }
403
406
 
404
- @effect((self, attributes) => self.getKeyStyle(attributes))
405
407
  protected drawKeyShape(attributes: ParsedBaseEdgeStyleProps, container: Group): Path | undefined {
406
- const key = this.upsert('key', Path, this.getKeyStyle(attributes), container);
407
- return key;
408
+ const style = this.getKeyStyle(attributes);
409
+ if (!effect(this, 'key', style)) return;
410
+ return this.upsert('key', Path, style, container);
408
411
  }
409
412
 
410
413
  public render(attributes = this.parsedAttributes, container: Group = this): void {
@@ -1,44 +1,27 @@
1
1
  import type { Element } from '../types';
2
- import { getCachedStyle, setCacheStyle } from '../utils/cache';
2
+
3
+ const EFFECT_WEAKMAP = new WeakMap<Element, Record<string, any>>();
3
4
 
4
5
  /**
5
- * <zh/> 基于样式属性是否变化控制函数是否执行
6
- *
7
- * <en/> Control whether the function is executed based on whether the style attribute changes
8
- * @param styler - <zh/> 获取样式属性函数 | <en/> Get style attribute function
9
- * @returns <zh/> 装饰器 | <en/> Decorator
10
- * @remarks
11
- * <zh/> 仅指定 getStyle 的情况下,会分别使用当前的 attributes 和 新的 attributes 调用函数,若两者相同,则不执行函数。
6
+ * <zh/> 判定给定样式是否与上一次的样式相同
12
7
  *
13
- * 如果指定了 shapeKey, 则会直接获取该图形的 attributes 作为原始样式属性,通常在 getStyle 函数中获取了包围盒时使用。
14
- *
15
- * <en/> Only when getStyle is specified, the function will be called with the current attributes and the new attributes respectively. If they are the same, the function will not be executed.
16
- *
17
- * If shapeKey is specified, the attributes of the shape will be directly obtained as the original style attributes, which is usually used when the bounding box of the element is used in the getStyle function.
8
+ * <en/> Determine whether the given style are the same as the previous ones
9
+ * @param target - <zh/> 目标元素 | <en/> Target element
10
+ * @param key - <zh/> 缓存 key | <en/> Cache key
11
+ * @param style - <zh/> 样式属性 | <en/> Style attribute
12
+ * @returns <zh/> 是否执行函数 | <en/> Whether to execute the function
18
13
  */
19
- export function effect(styler: (self: any, attributes: Record<string, unknown>) => Record<string, unknown>) {
20
- return function (target: Element, propertyKey: string, descriptor: PropertyDescriptor) {
21
- const fn = descriptor.value;
22
-
23
- descriptor.value = function (this: Element, attr: Record<string, unknown>, ...rest: unknown[]) {
24
- // 初始化后需要执行首次调用 / First call after initialization
25
- const initKey = `${propertyKey}_invoke`;
26
- if (!getCachedStyle(this, initKey)) {
27
- setCacheStyle(this, initKey, true);
28
- return fn.call(this, attr, ...rest);
29
- }
30
-
31
- const styleKey = `${propertyKey}_style`;
32
- const original = getCachedStyle(this, styleKey);
33
- const modified = styler(this, attr);
34
- setCacheStyle(this, styleKey, modified);
35
-
36
- if (isStyleEqual(original, modified)) return null;
37
-
38
- return fn.call(this, attr, ...rest);
39
- };
40
- return descriptor;
41
- };
14
+ export function effect<T extends false | Record<string, any>>(target: Element, key: string, style: T): boolean {
15
+ if (!EFFECT_WEAKMAP.has(target)) EFFECT_WEAKMAP.set(target, {});
16
+ const cache = EFFECT_WEAKMAP.get(target)!;
17
+ if (!cache[key]) {
18
+ cache[key] = style;
19
+ return true;
20
+ }
21
+ const original = cache[key];
22
+ if (isStyleEqual(original, style)) return false;
23
+ cache[key] = style;
24
+ return true;
42
25
  }
43
26
 
44
27
  /**
@@ -54,7 +37,7 @@ export function effect(styler: (self: any, attributes: Record<string, unknown>)
54
37
  *
55
38
  * <en/> Perform a second-level shallow comparison to compare complex shape attributes such as badges and ports
56
39
  */
57
- const isStyleEqual = (a: Record<string, unknown>, b: Record<string, unknown>, depth = 2): boolean => {
40
+ const isStyleEqual = (a: false | Record<string, unknown>, b: false | Record<string, unknown>, depth = 2): boolean => {
58
41
  if (typeof a !== 'object' || typeof b !== 'object') return a === b;
59
42
 
60
43
  const keys1 = Object.keys(a);
@@ -361,49 +361,54 @@ export abstract class BaseNode<S extends BaseNodeStyleProps = BaseNodeStyleProps
361
361
  return getRectIntersectPoint(point, keyShapeBounds);
362
362
  }
363
363
 
364
- @effect((self, attributes) => self.getHaloStyle(attributes))
365
364
  protected drawHaloShape(attributes: Required<S>, container: Group): void {
365
+ const style = this.getHaloStyle(attributes);
366
+ if (!effect(this, 'halo', style)) return;
367
+
366
368
  const keyShape = this.getShape('key');
367
- this.upsert(
368
- 'halo',
369
- keyShape.constructor as new (...args: unknown[]) => DisplayObject,
370
- this.getHaloStyle(attributes),
371
- container,
372
- );
369
+ this.upsert('halo', keyShape.constructor as new (...args: unknown[]) => DisplayObject, style, container);
373
370
  }
374
371
 
375
- @effect((self, attributes) => self.getIconStyle(attributes))
376
372
  protected drawIconShape(attributes: Required<S>, container: Group): void {
377
- this.upsert('icon', Icon, this.getIconStyle(attributes), container);
373
+ const style = this.getIconStyle(attributes);
374
+ if (!effect(this, 'icon', style)) return;
375
+
376
+ this.upsert('icon', Icon, style, container);
378
377
  connectImage(this);
379
378
  }
380
379
 
381
- @effect((self, attributes) => self.getBadgesStyle(attributes))
382
380
  protected drawBadgeShapes(attributes: Required<S>, container: Group): void {
383
381
  const badgesStyle = this.getBadgesStyle(attributes);
384
382
  Object.keys(badgesStyle).forEach((key) => {
385
- this.upsert(`badge-${key}`, Badge, badgesStyle[key], container);
383
+ const style = badgesStyle[key];
384
+ if (!effect(this, `badge-${key}`, style)) return;
385
+
386
+ this.upsert(`badge-${key}`, Badge, style, container);
386
387
  });
387
388
  }
388
389
 
389
- @effect((self, attributes) => self.getPortsStyle(attributes))
390
390
  protected drawPortShapes(attributes: Required<S>, container: Group): void {
391
391
  const portsStyle = this.getPortsStyle(attributes);
392
392
 
393
393
  Object.keys(portsStyle).forEach((key) => {
394
- this.upsert(`port-${key}`, GCircle, portsStyle[key] as CircleStyleProps, container);
394
+ const style = portsStyle[key] as CircleStyleProps;
395
+ const shapeKey = `port-${key}`;
396
+ if (!effect(this, shapeKey, style)) return;
397
+
398
+ this.upsert(shapeKey, GCircle, style, container);
395
399
  });
396
400
  }
397
401
 
398
- @effect((self, attributes) => self.getLabelStyle(attributes))
399
402
  protected drawLabelShape(attributes: Required<S>, container: Group): void {
400
- this.upsert('label', Label, this.getLabelStyle(attributes), container);
403
+ const style = this.getLabelStyle(attributes);
404
+ if (!effect(this, 'label', style)) return;
405
+
406
+ this.upsert('label', Label, style, container);
401
407
  }
402
408
 
403
409
  protected abstract drawKeyShape(attributes: Required<S>, container: Group): DisplayObject | undefined;
404
410
 
405
411
  // 用于装饰抽象方法 / Used to decorate abstract methods
406
- @effect((self, attributes) => self.getKeyStyle(attributes))
407
412
  private _drawKeyShape(attributes: Required<S>, container: Group) {
408
413
  return this.drawKeyShape(attributes, container);
409
414
  }
@@ -9,6 +9,7 @@ import {
9
9
  IEventTarget,
10
10
  Rect,
11
11
  } from '@antv/g';
12
+ import { Renderer } from '@antv/g-canvas';
12
13
  import { isNil, isUndefined, pick } from '@antv/util';
13
14
  import { CommonEvent } from '../../constants';
14
15
  import type { BaseNodeStyleProps } from './base-node';
@@ -26,6 +27,20 @@ export interface HTMLStyleProps extends BaseNodeStyleProps {
26
27
  * <en/> HTML content, can be a string or `HTMLElement`
27
28
  */
28
29
  innerHTML: string | HTMLElement;
30
+ /**
31
+ * <zh/> 横行偏移量。HTML 容器默认以左上角为原点,通过 dx 来进行横向偏移
32
+ *
33
+ * <en/> Horizontal offset. The HTML container defaults to the upper left corner as the origin, and the horizontal offset is performed through dx
34
+ * @defaultValue 0
35
+ */
36
+ dx?: number;
37
+ /**
38
+ * <zh/> 纵向偏移量。HTML 容器默认以左上角为原点,通过 dy 来进行纵向偏移
39
+ *
40
+ * <en/> Vertical offset. The HTML container defaults to the upper left corner as the origin, and the vertical offset is performed through dy
41
+ * @defaultValue 0
42
+ */
43
+ dy?: number;
29
44
  }
30
45
 
31
46
  /**
@@ -69,19 +84,28 @@ export class HTML extends BaseNode<HTMLStyleProps> {
69
84
  }
70
85
 
71
86
  protected getKeyStyle(attributes: Required<HTMLStyleProps>): GHTMLStyleProps {
72
- const style = pick(attributes, ['innerHTML', 'pointerEvents', 'cursor']) as unknown as HTMLStyleProps;
87
+ const {
88
+ dx = 0,
89
+ dy = 0,
90
+ ...style
91
+ } = pick(attributes, ['dx', 'dy', 'innerHTML', 'pointerEvents', 'cursor']) as unknown as HTMLStyleProps;
73
92
  const [width, height] = this.getSize(attributes);
74
- return { ...style, width, height };
93
+ return { x: dx, y: dy, ...style, width, height };
75
94
  }
76
95
 
77
96
  protected drawKeyShape(attributes: Required<HTMLStyleProps>, container: Group) {
78
97
  const style = this.getKeyStyle(attributes);
79
- const { width = 0, height = 0 } = style;
80
- const bounds = this.upsert('key-container', Rect, { width, height, opacity: 0 }, container)!;
98
+ const { x, y, width = 0, height = 0 } = style;
99
+ const bounds = this.upsert('key-container', Rect, { x, y, width, height, opacity: 0 }, container)!;
81
100
  return this.upsert('key', GHTML, style, bounds);
82
101
  }
83
102
 
84
103
  public connectedCallback() {
104
+ // only enable in canvas renderer
105
+ const renderer = this.context.canvas.getRenderer('main');
106
+ const isCanvasRenderer = renderer instanceof Renderer;
107
+ if (!isCanvasRenderer) return;
108
+
85
109
  const element = this.getDomElement();
86
110
  this.events.forEach((eventName) => {
87
111
  // @ts-expect-error assert event is PointerEvent
@@ -47,7 +47,7 @@ export abstract class BaseShape<StyleProps extends BaseShapeStyleProps> extends
47
47
  * <en> create, update or remove shape
48
48
  * @param className - <zh> 图形名称 | <en> shape name
49
49
  * @param Ctor - <zh> 图形类型 | <en> shape type
50
- * @param style - <zh> 图形样式 | <en> shape style
50
+ * @param style - <zh> 图形样式。若要删除图形,传入 false | <en> shape style. Pass false to remove the shape
51
51
  * @param container - <zh> 容器 | <en> container
52
52
  * @param hooks - <zh> 钩子函数 | <en> hooks
53
53
  * @returns <zh> 图形实例 | <en> shape instance
package/src/exports.ts CHANGED
@@ -68,6 +68,7 @@ export {
68
68
  CameraSetting,
69
69
  Contextmenu,
70
70
  EdgeFilterLens,
71
+ Fisheye,
71
72
  Fullscreen,
72
73
  GridLine,
73
74
  History,
@@ -170,6 +171,7 @@ export type {
170
171
  CameraSettingOptions,
171
172
  ContextmenuOptions,
172
173
  EdgeFilterLensOptions,
174
+ FisheyeOptions,
173
175
  FullscreenOptions,
174
176
  GridLineOptions,
175
177
  HistoryOptions,
@@ -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
 
@@ -16,12 +16,17 @@ import type {
16
16
  PointObject,
17
17
  } from '../../types';
18
18
  import { idOf } from '../../utils/id';
19
- import { parsePoint } from '../../utils/point';
19
+ import { parsePoint, toPointObject } from '../../utils/point';
20
20
  import { positionOf } from '../../utils/position';
21
21
  import { distance } from '../../utils/vector';
22
22
  import type { BasePluginOptions } from '../base-plugin';
23
23
  import { BasePlugin } from '../base-plugin';
24
24
 
25
+ /**
26
+ * <zh/> 边过滤镜插件配置项
27
+ *
28
+ * <en/> Edge filter lens plugin options
29
+ */
25
30
  export interface EdgeFilterLensOptions extends BasePluginOptions {
26
31
  /**
27
32
  * <zh/> 移动透镜的方式
@@ -44,26 +49,28 @@ export interface EdgeFilterLensOptions extends BasePluginOptions {
44
49
  */
45
50
  r?: number;
46
51
  /**
47
- * <zh/> 透镜的最大半径。只有在开启 `scaleRByWheel` 时生效
52
+ * <zh/> 透镜的最大半径。只有在 `scaleRBy` 为 `wheel` 时生效
48
53
  *
49
- * <en/> The maximum radius of the lens. Only valid when `scaleRByWheel` is enabled
54
+ * <en/> The maximum radius of the lens. Only valid when `scaleRBy` is `wheel`
50
55
  * @defaultValue canvas 宽高最小值的一半
51
56
  */
52
57
  maxR?: number;
53
58
  /**
54
- * <zh/> 透镜的最小半径。只有在开启 `scaleRByWheel` 时生效
59
+ * <zh/> 透镜的最小半径。只有在 `scaleRBy` 为 `wheel` 时生效
55
60
  *
56
- * <en/> The minimum radius of the lens. Only valid when `scaleRByWheel` is enabled
61
+ * <en/> The minimum radius of the lens. Only valid when `scaleRBy` is `wheel`
57
62
  * @defaultValue 0
58
63
  */
59
64
  minR?: number;
60
65
  /**
61
- * <zh/> 是否通过滚轮缩放透镜的半径
66
+ * <zh/> 缩放透镜半径的方式
67
+ * - `'wheel'`:通过滚轮缩放透镜的半径
62
68
  *
63
- * <en/> Whether to scale the radius of the lens by wheel
64
- * @defaultValue true
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'`
65
72
  */
66
- scaleRByWheel?: boolean;
73
+ scaleRBy?: 'wheel';
67
74
  /**
68
75
  * <zh/> 边显示的条件
69
76
  * - `'both'`:只有起始节点和目标节点都在透镜中时,边才会显示
@@ -71,7 +78,7 @@ export interface EdgeFilterLensOptions extends BasePluginOptions {
71
78
  * - `'target'`:只有目标节点在透镜中时,边才会显示
72
79
  * - `'either'`:只要起始节点或目标节点有一个在透镜中时,边就会显示
73
80
  *
74
- * <zh/> The condition for displaying the edge
81
+ * <en/> The condition for displaying the edge
75
82
  * - `'both'`: The edge is displayed only when both the source node and the target node are in the lens
76
83
  * - `'source'`: The edge is displayed only when the source node is in the lens
77
84
  * - `'target'`: The edge is displayed only when the target node is in the lens
@@ -125,6 +132,15 @@ const defaultLensStyle: BaseStyleProps = {
125
132
 
126
133
  const DELTA = 0.05;
127
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
+ */
128
144
  export class EdgeFilterLens extends BasePlugin<EdgeFilterLensOptions> {
129
145
  static defaultOptions: Partial<EdgeFilterLensOptions> = {
130
146
  trigger: 'pointermove',
@@ -134,7 +150,7 @@ export class EdgeFilterLens extends BasePlugin<EdgeFilterLensOptions> {
134
150
  style: { lineWidth: 2 },
135
151
  nodeStyle: { label: false },
136
152
  edgeStyle: { label: true },
137
- scaleRByWheel: true,
153
+ scaleRBy: 'wheel',
138
154
  preventDefault: true,
139
155
  };
140
156
 
@@ -166,17 +182,16 @@ export class EdgeFilterLens extends BasePlugin<EdgeFilterLensOptions> {
166
182
  };
167
183
 
168
184
  private renderLens = (origin: Point) => {
169
- const [x, y] = origin;
170
- const positionStyle = { size: this.r * 2, x, y };
185
+ const style = Object.assign({}, defaultLensStyle, this.options.style);
171
186
 
172
187
  if (!this.isLensOn) {
173
- const style = Object.assign({}, defaultLensStyle, this.options.style, positionStyle);
174
188
  this.lens = new Circle({ style });
175
- } else {
176
- this.lens.update(positionStyle);
189
+ this.canvas.appendChild(this.lens);
177
190
  }
178
191
 
179
- this.canvas.appendChild(this.lens);
192
+ Object.assign(style, toPointObject(origin), { size: this.r * 2 });
193
+
194
+ this.lens.update(style);
180
195
  };
181
196
 
182
197
  private getFilterData = (): Required<GraphData> => {
@@ -232,8 +247,6 @@ export class EdgeFilterLens extends BasePlugin<EdgeFilterLensOptions> {
232
247
 
233
248
  const ids = new Set<ID>();
234
249
 
235
- const { nodeStyle, edgeStyle } = this.options;
236
-
237
250
  const iterate = (datum: ElementDatum) => {
238
251
  const id = idOf(datum);
239
252
  ids.add(id);
@@ -328,7 +341,7 @@ export class EdgeFilterLens extends BasePlugin<EdgeFilterLensOptions> {
328
341
 
329
342
  private bindEvents() {
330
343
  const { graph } = this.context;
331
- const { trigger, scaleRByWheel } = this.options;
344
+ const { trigger, scaleRBy } = this.options;
332
345
 
333
346
  const canvas = graph.getCanvas().getLayer();
334
347
 
@@ -344,14 +357,14 @@ export class EdgeFilterLens extends BasePlugin<EdgeFilterLensOptions> {
344
357
  canvas.addEventListener(CommonEvent.DRAG_END, this.onDragEnd);
345
358
  }
346
359
 
347
- if (scaleRByWheel) {
360
+ if (scaleRBy === 'wheel') {
348
361
  this.graphDom?.addEventListener(CommonEvent.WHEEL, this.scaleRByWheel, { passive: false });
349
362
  }
350
363
  }
351
364
 
352
365
  private unbindEvents() {
353
366
  const { graph } = this.context;
354
- const { trigger, scaleRByWheel } = this.options;
367
+ const { trigger, scaleRBy } = this.options;
355
368
  const canvas = graph.getCanvas().getLayer();
356
369
 
357
370
  if (['click', 'drag'].includes(trigger)) {
@@ -366,7 +379,7 @@ export class EdgeFilterLens extends BasePlugin<EdgeFilterLensOptions> {
366
379
  canvas.removeEventListener(CommonEvent.DRAG_END, this.onDragEnd);
367
380
  }
368
381
 
369
- if (scaleRByWheel) {
382
+ if (scaleRBy === 'wheel') {
370
383
  this.graphDom?.removeEventListener(CommonEvent.WHEEL, this.scaleRByWheel);
371
384
  }
372
385
  }