@antv/g6 5.0.0-beta.10 → 5.0.0-beta.12

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 (278) hide show
  1. package/dist/g6.min.js +2 -2
  2. package/esm/api-doc/graph.d.ts +3 -3
  3. package/esm/api-doc/graph.js +3 -3
  4. package/esm/api-doc/graph.js.map +1 -1
  5. package/esm/constant/shape.d.ts +1 -1
  6. package/esm/index.d.ts +12 -62
  7. package/esm/index.js +4 -5
  8. package/esm/index.js.map +1 -1
  9. package/esm/item/node.js +0 -1
  10. package/esm/item/node.js.map +1 -1
  11. package/esm/runtime/controller/item.js +15 -6
  12. package/esm/runtime/controller/item.js.map +1 -1
  13. package/esm/runtime/controller/layout.js +1 -3
  14. package/esm/runtime/controller/layout.js.map +1 -1
  15. package/esm/runtime/graph.d.ts +1 -1
  16. package/esm/runtime/graph.js +11 -5
  17. package/esm/runtime/graph.js.map +1 -1
  18. package/esm/stdlib/behavior/drag-canvas.d.ts +1 -1
  19. package/esm/stdlib/behavior/drag-canvas.js.map +1 -1
  20. package/esm/stdlib/behavior/shortcuts-call.d.ts +2 -2
  21. package/esm/stdlib/behavior/shortcuts-call.js +12 -5
  22. package/esm/stdlib/behavior/shortcuts-call.js.map +1 -1
  23. package/esm/stdlib/behavior/zoom-canvas-3d.js +4 -1
  24. package/esm/stdlib/behavior/zoom-canvas-3d.js.map +1 -1
  25. package/esm/stdlib/index.d.ts +6 -1
  26. package/esm/stdlib/index.js +8 -3
  27. package/esm/stdlib/index.js.map +1 -1
  28. package/esm/stdlib/item/edge/base.js +5 -1
  29. package/esm/stdlib/item/edge/base.js.map +1 -1
  30. package/esm/stdlib/item/edge/cubic-horizontal.js.map +1 -1
  31. package/esm/stdlib/item/edge/cubic-vertical.js.map +1 -1
  32. package/esm/stdlib/item/edge/cubic.js +1 -1
  33. package/esm/stdlib/item/edge/cubic.js.map +1 -1
  34. package/esm/stdlib/item/edge/loop.js +1 -1
  35. package/esm/stdlib/item/edge/loop.js.map +1 -1
  36. package/esm/stdlib/item/node/cube.d.ts +35 -0
  37. package/esm/stdlib/item/node/cube.js +54 -0
  38. package/esm/stdlib/item/node/cube.js.map +1 -0
  39. package/esm/stdlib/item/node/index.d.ts +3 -0
  40. package/esm/stdlib/item/node/index.js +3 -0
  41. package/esm/stdlib/item/node/index.js.map +1 -1
  42. package/esm/stdlib/plugin/edgeFilterLens/index.d.ts +66 -0
  43. package/esm/stdlib/plugin/edgeFilterLens/index.js +309 -0
  44. package/esm/stdlib/plugin/edgeFilterLens/index.js.map +1 -0
  45. package/esm/stdlib/plugin/grid/index.d.ts +1 -1
  46. package/esm/stdlib/plugin/grid/index.js +3 -4
  47. package/esm/stdlib/plugin/grid/index.js.map +1 -1
  48. package/esm/stdlib/plugin/hull/convexHull.d.ts +1 -1
  49. package/esm/stdlib/plugin/hull/hullComponent.js +2 -3
  50. package/esm/stdlib/plugin/hull/hullComponent.js.map +1 -1
  51. package/esm/stdlib/plugin/hull/util.d.ts +2 -2
  52. package/esm/stdlib/plugin/hull/util.js +6 -2
  53. package/esm/stdlib/plugin/hull/util.js.map +1 -1
  54. package/esm/stdlib/plugin/index.d.ts +1 -0
  55. package/esm/stdlib/plugin/index.js +1 -0
  56. package/esm/stdlib/plugin/index.js.map +1 -1
  57. package/esm/stdlib/plugin/legend/index.d.ts +2 -2
  58. package/esm/stdlib/plugin/legend/index.js +3 -3
  59. package/esm/stdlib/plugin/legend/index.js.map +1 -1
  60. package/esm/stdlib/plugin/map/index.d.ts +1 -1
  61. package/esm/stdlib/plugin/map/index.js +4 -4
  62. package/esm/stdlib/plugin/map/index.js.map +1 -1
  63. package/esm/stdlib/plugin/menu/index.d.ts +4 -4
  64. package/esm/stdlib/plugin/menu/index.js +3 -3
  65. package/esm/stdlib/plugin/menu/index.js.map +1 -1
  66. package/esm/stdlib/plugin/minimap/index.d.ts +1 -1
  67. package/esm/stdlib/plugin/minimap/index.js +3 -3
  68. package/esm/stdlib/plugin/minimap/index.js.map +1 -1
  69. package/esm/stdlib/plugin/timebar/index.js +2 -2
  70. package/esm/stdlib/plugin/timebar/index.js.map +1 -1
  71. package/esm/stdlib/plugin/toolbar/index.d.ts +3 -3
  72. package/esm/stdlib/plugin/toolbar/index.js +4 -4
  73. package/esm/stdlib/plugin/toolbar/index.js.map +1 -1
  74. package/esm/stdlib/plugin/tooltip/index.d.ts +4 -4
  75. package/esm/stdlib/plugin/tooltip/index.js +3 -4
  76. package/esm/stdlib/plugin/tooltip/index.js.map +1 -1
  77. package/esm/stdlib/plugin/types.d.ts +1 -0
  78. package/esm/stdlib/plugin/watermaker/index.d.ts +78 -0
  79. package/esm/stdlib/plugin/watermaker/index.js +243 -0
  80. package/esm/stdlib/plugin/watermaker/index.js.map +1 -0
  81. package/esm/types/plugin.d.ts +1 -1
  82. package/esm/util/bbox.js +4 -5
  83. package/esm/util/bbox.js.map +1 -1
  84. package/esm/util/behavior.d.ts +2 -2
  85. package/esm/util/behavior.js +2 -2
  86. package/esm/util/behavior.js.map +1 -1
  87. package/esm/util/data.d.ts +2 -2
  88. package/esm/util/data.js.map +1 -1
  89. package/esm/util/dom.d.ts +15 -0
  90. package/esm/util/dom.js +29 -0
  91. package/esm/util/dom.js.map +1 -0
  92. package/esm/util/extend.d.ts +1 -1
  93. package/esm/util/extend.js +0 -1
  94. package/esm/util/extend.js.map +1 -1
  95. package/esm/util/index.d.ts +7 -52
  96. package/esm/util/index.js +7 -23
  97. package/esm/util/index.js.map +1 -1
  98. package/esm/util/layout.d.ts +1 -1
  99. package/esm/util/layout.js.map +1 -1
  100. package/esm/util/loop.d.ts +1 -1
  101. package/esm/util/math.d.ts +1 -1
  102. package/esm/util/matrix.d.ts +6 -0
  103. package/esm/util/matrix.js +48 -0
  104. package/esm/util/matrix.js.map +1 -0
  105. package/esm/util/path.js +1 -1
  106. package/esm/util/path.js.map +1 -1
  107. package/esm/util/point.d.ts +1 -1
  108. package/esm/util/polyline.d.ts +2 -1
  109. package/esm/util/polyline.js +2 -1
  110. package/esm/util/polyline.js.map +1 -1
  111. package/esm/util/router.d.ts +1 -1
  112. package/esm/util/shape.js.map +1 -1
  113. package/esm/util/shape3d.js +1 -1
  114. package/esm/util/shape3d.js.map +1 -1
  115. package/lib/api-doc/graph.d.ts +3 -3
  116. package/lib/api-doc/graph.js +27 -7
  117. package/lib/api-doc/graph.js.map +1 -1
  118. package/lib/constant/shape.d.ts +1 -1
  119. package/lib/index.d.ts +12 -62
  120. package/lib/index.js +18 -10
  121. package/lib/index.js.map +1 -1
  122. package/lib/item/node.js +0 -1
  123. package/lib/item/node.js.map +1 -1
  124. package/lib/runtime/controller/item.js +15 -6
  125. package/lib/runtime/controller/item.js.map +1 -1
  126. package/lib/runtime/controller/layout.js +1 -3
  127. package/lib/runtime/controller/layout.js.map +1 -1
  128. package/lib/runtime/graph.d.ts +1 -1
  129. package/lib/runtime/graph.js +12 -5
  130. package/lib/runtime/graph.js.map +1 -1
  131. package/lib/stdlib/behavior/drag-canvas.d.ts +1 -1
  132. package/lib/stdlib/behavior/drag-canvas.js.map +1 -1
  133. package/lib/stdlib/behavior/shortcuts-call.d.ts +2 -2
  134. package/lib/stdlib/behavior/shortcuts-call.js +12 -5
  135. package/lib/stdlib/behavior/shortcuts-call.js.map +1 -1
  136. package/lib/stdlib/behavior/zoom-canvas-3d.js +4 -1
  137. package/lib/stdlib/behavior/zoom-canvas-3d.js.map +1 -1
  138. package/lib/stdlib/index.d.ts +6 -1
  139. package/lib/stdlib/index.js +8 -3
  140. package/lib/stdlib/index.js.map +1 -1
  141. package/lib/stdlib/item/edge/base.js +5 -1
  142. package/lib/stdlib/item/edge/base.js.map +1 -1
  143. package/lib/stdlib/item/edge/cubic-horizontal.js.map +1 -1
  144. package/lib/stdlib/item/edge/cubic-vertical.js.map +1 -1
  145. package/lib/stdlib/item/edge/cubic.js +2 -2
  146. package/lib/stdlib/item/edge/cubic.js.map +1 -1
  147. package/lib/stdlib/item/edge/loop.js +3 -3
  148. package/lib/stdlib/item/edge/loop.js.map +1 -1
  149. package/lib/stdlib/item/node/cube.d.ts +35 -0
  150. package/lib/stdlib/item/node/cube.js +58 -0
  151. package/lib/stdlib/item/node/cube.js.map +1 -0
  152. package/lib/stdlib/item/node/index.d.ts +3 -0
  153. package/lib/stdlib/item/node/index.js +3 -0
  154. package/lib/stdlib/item/node/index.js.map +1 -1
  155. package/lib/stdlib/plugin/edgeFilterLens/index.d.ts +66 -0
  156. package/lib/stdlib/plugin/edgeFilterLens/index.js +313 -0
  157. package/lib/stdlib/plugin/edgeFilterLens/index.js.map +1 -0
  158. package/lib/stdlib/plugin/grid/index.d.ts +1 -1
  159. package/lib/stdlib/plugin/grid/index.js +6 -7
  160. package/lib/stdlib/plugin/grid/index.js.map +1 -1
  161. package/lib/stdlib/plugin/hull/convexHull.d.ts +1 -1
  162. package/lib/stdlib/plugin/hull/hullComponent.js +2 -3
  163. package/lib/stdlib/plugin/hull/hullComponent.js.map +1 -1
  164. package/lib/stdlib/plugin/hull/util.d.ts +2 -2
  165. package/lib/stdlib/plugin/hull/util.js +26 -22
  166. package/lib/stdlib/plugin/hull/util.js.map +1 -1
  167. package/lib/stdlib/plugin/index.d.ts +1 -0
  168. package/lib/stdlib/plugin/index.js +1 -0
  169. package/lib/stdlib/plugin/index.js.map +1 -1
  170. package/lib/stdlib/plugin/legend/index.d.ts +2 -2
  171. package/lib/stdlib/plugin/legend/index.js +3 -3
  172. package/lib/stdlib/plugin/legend/index.js.map +1 -1
  173. package/lib/stdlib/plugin/map/index.d.ts +1 -1
  174. package/lib/stdlib/plugin/map/index.js +6 -6
  175. package/lib/stdlib/plugin/map/index.js.map +1 -1
  176. package/lib/stdlib/plugin/menu/index.d.ts +4 -4
  177. package/lib/stdlib/plugin/menu/index.js +6 -6
  178. package/lib/stdlib/plugin/menu/index.js.map +1 -1
  179. package/lib/stdlib/plugin/minimap/index.d.ts +1 -1
  180. package/lib/stdlib/plugin/minimap/index.js +6 -6
  181. package/lib/stdlib/plugin/minimap/index.js.map +1 -1
  182. package/lib/stdlib/plugin/timebar/index.js +2 -2
  183. package/lib/stdlib/plugin/timebar/index.js.map +1 -1
  184. package/lib/stdlib/plugin/toolbar/index.d.ts +3 -3
  185. package/lib/stdlib/plugin/toolbar/index.js +5 -5
  186. package/lib/stdlib/plugin/toolbar/index.js.map +1 -1
  187. package/lib/stdlib/plugin/tooltip/index.d.ts +4 -4
  188. package/lib/stdlib/plugin/tooltip/index.js +10 -11
  189. package/lib/stdlib/plugin/tooltip/index.js.map +1 -1
  190. package/lib/stdlib/plugin/types.d.ts +1 -0
  191. package/lib/stdlib/plugin/watermaker/index.d.ts +78 -0
  192. package/lib/stdlib/plugin/watermaker/index.js +247 -0
  193. package/lib/stdlib/plugin/watermaker/index.js.map +1 -0
  194. package/lib/types/plugin.d.ts +1 -1
  195. package/lib/util/bbox.js +4 -5
  196. package/lib/util/bbox.js.map +1 -1
  197. package/lib/util/behavior.d.ts +2 -2
  198. package/lib/util/behavior.js +2 -2
  199. package/lib/util/behavior.js.map +1 -1
  200. package/lib/util/data.d.ts +2 -2
  201. package/lib/util/data.js.map +1 -1
  202. package/lib/util/dom.d.ts +15 -0
  203. package/lib/util/dom.js +34 -0
  204. package/lib/util/dom.js.map +1 -0
  205. package/lib/util/extend.d.ts +1 -1
  206. package/lib/util/extend.js +0 -1
  207. package/lib/util/extend.js.map +1 -1
  208. package/lib/util/index.d.ts +7 -52
  209. package/lib/util/index.js +23 -23
  210. package/lib/util/index.js.map +1 -1
  211. package/lib/util/layout.d.ts +1 -1
  212. package/lib/util/layout.js.map +1 -1
  213. package/lib/util/loop.d.ts +1 -1
  214. package/lib/util/math.d.ts +1 -1
  215. package/lib/util/matrix.d.ts +6 -0
  216. package/lib/util/matrix.js +52 -0
  217. package/lib/util/matrix.js.map +1 -0
  218. package/lib/util/path.js +2 -2
  219. package/lib/util/path.js.map +1 -1
  220. package/lib/util/point.d.ts +1 -1
  221. package/lib/util/polyline.d.ts +2 -1
  222. package/lib/util/polyline.js +2 -1
  223. package/lib/util/polyline.js.map +1 -1
  224. package/lib/util/router.d.ts +1 -1
  225. package/lib/util/shape.js.map +1 -1
  226. package/lib/util/shape3d.js +1 -1
  227. package/lib/util/shape3d.js.map +1 -1
  228. package/package.json +32 -40
  229. package/src/api-doc/graph.ts +4 -3
  230. package/src/constant/shape.ts +1 -1
  231. package/src/index.ts +5 -6
  232. package/src/item/node.ts +0 -1
  233. package/src/runtime/controller/item.ts +15 -6
  234. package/src/runtime/controller/layout.ts +1 -5
  235. package/src/runtime/graph.ts +12 -6
  236. package/src/stdlib/behavior/drag-canvas.ts +1 -1
  237. package/src/stdlib/behavior/shortcuts-call.ts +13 -4
  238. package/src/stdlib/behavior/zoom-canvas-3d.ts +4 -1
  239. package/src/stdlib/index.ts +10 -1
  240. package/src/stdlib/item/edge/base.ts +5 -2
  241. package/src/stdlib/item/edge/cubic-horizontal.ts +0 -1
  242. package/src/stdlib/item/edge/cubic-vertical.ts +0 -1
  243. package/src/stdlib/item/edge/cubic.ts +1 -1
  244. package/src/stdlib/item/edge/loop.ts +1 -1
  245. package/src/stdlib/item/node/cube.ts +102 -0
  246. package/src/stdlib/item/node/index.ts +3 -0
  247. package/src/stdlib/plugin/edgeFilterLens/index.ts +387 -0
  248. package/src/stdlib/plugin/grid/index.ts +6 -6
  249. package/src/stdlib/plugin/hull/convexHull.ts +1 -1
  250. package/src/stdlib/plugin/hull/hullComponent.ts +2 -3
  251. package/src/stdlib/plugin/hull/util.ts +6 -2
  252. package/src/stdlib/plugin/index.ts +1 -0
  253. package/src/stdlib/plugin/legend/index.ts +6 -6
  254. package/src/stdlib/plugin/map/index.ts +7 -7
  255. package/src/stdlib/plugin/menu/index.ts +13 -13
  256. package/src/stdlib/plugin/minimap/index.ts +6 -6
  257. package/src/stdlib/plugin/timebar/index.ts +4 -4
  258. package/src/stdlib/plugin/toolbar/index.ts +8 -8
  259. package/src/stdlib/plugin/tooltip/index.ts +10 -10
  260. package/src/stdlib/plugin/types.ts +1 -0
  261. package/src/stdlib/plugin/watermaker/index.ts +302 -0
  262. package/src/types/plugin.ts +1 -1
  263. package/src/util/bbox.ts +4 -5
  264. package/src/util/behavior.ts +4 -4
  265. package/src/util/data.ts +2 -3
  266. package/src/util/dom.ts +33 -0
  267. package/src/util/extend.ts +2 -3
  268. package/src/util/index.ts +7 -24
  269. package/src/util/layout.ts +3 -2
  270. package/src/util/loop.ts +1 -1
  271. package/src/util/math.ts +1 -1
  272. package/src/util/matrix.ts +66 -0
  273. package/src/util/path.ts +1 -1
  274. package/src/util/point.ts +1 -1
  275. package/src/util/polyline.ts +2 -1
  276. package/src/util/router.ts +1 -1
  277. package/src/util/shape.ts +0 -1
  278. package/src/util/shape3d.ts +1 -1
@@ -0,0 +1,387 @@
1
+ import { DisplayObject } from '@antv/g';
2
+ import { clone } from '@antv/util';
3
+ import { Plugin as Base, IPluginBaseConfig } from '../../../types/plugin';
4
+ import { IGraph } from '../../../types';
5
+ import { IG6GraphEvent } from '../../../types/event';
6
+ import { ShapeStyle } from '../../../types/item';
7
+ import { distance } from '../../../util/point';
8
+
9
+ const DELTA = 0.01;
10
+ interface EdgeFilterLensConfig extends IPluginBaseConfig {
11
+ trigger?: 'mousemove' | 'click' | 'drag';
12
+ r?: number;
13
+ delegateStyle?: ShapeStyle;
14
+ showLabel?: 'node' | 'edge' | 'both' | undefined;
15
+ scaleRBy?: 'wheel' | undefined;
16
+ maxR?: number;
17
+ minR?: number;
18
+ showType?: 'one' | 'both' | 'only-source' | 'only-target'; // 更名,原名与plugin的type冲突
19
+ shouldShow?: (d?: unknown) => boolean;
20
+ }
21
+
22
+ const lensDelegateStyle = {
23
+ stroke: '#000',
24
+ strokeOpacity: 0.8,
25
+ lineWidth: 2,
26
+ fillOpacity: 1,
27
+ fill: '#fff',
28
+ };
29
+
30
+ export class EdgeFilterLens extends Base {
31
+ private showNodeLabel: boolean;
32
+ private showEdgeLabel: boolean;
33
+ private delegate: DisplayObject;
34
+ private cachedTransientNodes: Set<string | number>;
35
+ private cachedTransientEdges: Set<string | number>;
36
+ private dragging: boolean;
37
+ private delegateCenterDiff: { x: number; y: number };
38
+
39
+ constructor(config?: EdgeFilterLensConfig) {
40
+ super(config);
41
+ this.cachedTransientNodes = new Set();
42
+ this.cachedTransientEdges = new Set();
43
+ }
44
+
45
+ public getDefaultCfgs(): EdgeFilterLensConfig {
46
+ return {
47
+ showType: 'both',
48
+ trigger: 'mousemove',
49
+ r: 60,
50
+ delegateStyle: clone(lensDelegateStyle),
51
+ showLabel: 'edge',
52
+ scaleRBy: 'wheel',
53
+ };
54
+ }
55
+
56
+ public getEvents() {
57
+ let events = {
58
+ pointerdown: this.onPointerDown,
59
+ pointerup: this.onPointerUp,
60
+ wheel: this.onWheel,
61
+ } as {
62
+ [key: string]: any;
63
+ };
64
+ switch (this.options.trigger) {
65
+ case 'click':
66
+ events = {
67
+ ...events,
68
+ click: this.filter,
69
+ };
70
+ break;
71
+ case 'drag':
72
+ events = {
73
+ ...events,
74
+ pointermove: this.onPointerMove,
75
+ };
76
+ break;
77
+ default:
78
+ events = {
79
+ ...events,
80
+ pointermove: this.filter,
81
+ };
82
+ break;
83
+ }
84
+ return events;
85
+ }
86
+
87
+ public init(graph: IGraph) {
88
+ super.init(graph);
89
+ const showLabel = this.options.showLabel;
90
+ const showNodeLabel = showLabel === 'node' || showLabel === 'both';
91
+ const showEdgeLabel = showLabel === 'edge' || showLabel === 'both';
92
+ this.showNodeLabel = showNodeLabel;
93
+ this.showEdgeLabel = showEdgeLabel;
94
+ const shouldShow = this.options.shouldShow;
95
+ if (!shouldShow) this.options.shouldShow = () => true;
96
+ }
97
+
98
+ protected onPointerUp(e: IG6GraphEvent) {
99
+ this.dragging = false;
100
+ }
101
+
102
+ protected onPointerMove(e: IG6GraphEvent) {
103
+ if (!this.dragging) return;
104
+ this.moveDelegate(e);
105
+ }
106
+
107
+ protected onPointerDown(e: IG6GraphEvent) {
108
+ const { delegate: lensDelegate } = this;
109
+ let cacheCenter;
110
+ if (!lensDelegate || lensDelegate.destroyed) {
111
+ cacheCenter = { x: e.canvas.x, y: e.canvas.y };
112
+ this.filter(e);
113
+ } else {
114
+ cacheCenter = {
115
+ x: lensDelegate.style.cx,
116
+ y: lensDelegate.style.cy,
117
+ };
118
+ }
119
+ this.delegateCenterDiff = {
120
+ x: e.canvas.x - cacheCenter.x,
121
+ y: e.canvas.y - cacheCenter.y,
122
+ };
123
+ this.dragging = true;
124
+ }
125
+
126
+ // Determine whether it is dragged in the delegate
127
+ protected isInLensDelegate(lensDelegate, pointer): boolean {
128
+ const { cx: lensX, cy: lensY, r: lensR } = lensDelegate.style;
129
+ if (
130
+ pointer.x >= lensX - lensR &&
131
+ pointer.x <= lensX + lensR &&
132
+ pointer.y >= lensY - lensR &&
133
+ pointer.y <= lensY + lensR
134
+ ) {
135
+ return true;
136
+ }
137
+ return false;
138
+ }
139
+
140
+ protected moveDelegate(e) {
141
+ if (
142
+ this.isInLensDelegate(this.delegate, { x: e.canvas.x, y: e.canvas.y })
143
+ ) {
144
+ const center = {
145
+ x: e.canvas.x - this.delegateCenterDiff.x,
146
+ y: e.canvas.y - this.delegateCenterDiff.y,
147
+ };
148
+ this.filter(e, center);
149
+ }
150
+ }
151
+
152
+ protected onWheel(e: IG6GraphEvent) {
153
+ const { delegate: lensDelegate, options } = this;
154
+ const { scaleRBy } = options;
155
+ if (!lensDelegate || lensDelegate.destroyed) return;
156
+ if (scaleRBy !== 'wheel') return;
157
+ if (this.isInLensDelegate(lensDelegate, { x: e.canvas.x, y: e.canvas.y })) {
158
+ if (scaleRBy === 'wheel') {
159
+ this.scaleRByWheel(e);
160
+ }
161
+ }
162
+ }
163
+
164
+ /**
165
+ * Scale the range by wheel
166
+ * @param e mouse wheel event
167
+ */
168
+ protected scaleRByWheel(e: IG6GraphEvent) {
169
+ if (!e || !e.originalEvent) return;
170
+ if (e.preventDefault) e.preventDefault();
171
+ const { graph, options } = this;
172
+ const graphCanvasEl = graph.canvas.context.config.canvas;
173
+ const graphHeight = graphCanvasEl?.height || 500;
174
+ const maxR = options.maxR
175
+ ? Math.min(options.maxR, graphHeight)
176
+ : graphHeight;
177
+ const minR = options.minR
178
+ ? Math.max(options.minR, graphHeight * DELTA)
179
+ : graphHeight * DELTA;
180
+
181
+ const scale = 1 + (e.originalEvent as any).deltaY * -1 * DELTA;
182
+ let r = options.r * scale;
183
+ r = Math.min(r, maxR);
184
+ r = Math.max(r, minR);
185
+ options.r = r;
186
+ this.delegate.style.r = r;
187
+ this.filter(e);
188
+ }
189
+
190
+ /**
191
+ * Response function for mousemove, click, or drag to filter out the edges
192
+ * @param e mouse event
193
+ */
194
+ protected filter(e: IG6GraphEvent, mousePos?) {
195
+ const {
196
+ graph,
197
+ options,
198
+ showNodeLabel,
199
+ showEdgeLabel,
200
+ cachedTransientNodes,
201
+ cachedTransientEdges,
202
+ } = this;
203
+ const r = options.r;
204
+ const showType = options.showType;
205
+ const shouldShow = options.shouldShow;
206
+ const fCenter = mousePos || { x: e.canvas.x, y: e.canvas.y };
207
+ this.updateDelegate(fCenter, r);
208
+
209
+ const nodes = graph.getAllNodesData();
210
+ const hitNodesMap = new Map();
211
+ nodes.forEach((node) => {
212
+ const { data, id } = node;
213
+ if (distance({ x: data.x, y: data.y }, fCenter) < r) {
214
+ hitNodesMap.set(id, node);
215
+ }
216
+ });
217
+
218
+ const edges = graph.getAllEdgesData();
219
+ const hitEdges = [];
220
+ edges.forEach((edge) => {
221
+ const sourceId = edge.source;
222
+ const targetId = edge.target;
223
+ if (shouldShow(edge)) {
224
+ if (showType === 'only-source' || showType === 'one') {
225
+ if (hitNodesMap.get(sourceId) && !hitNodesMap.get(targetId))
226
+ hitEdges.push(edge);
227
+ } else if (showType === 'only-target' || showType === 'one') {
228
+ if (hitNodesMap.get(targetId) && !hitNodesMap.get(sourceId))
229
+ hitEdges.push(edge);
230
+ } else if (
231
+ showType === 'both' &&
232
+ hitNodesMap.get(sourceId) &&
233
+ hitNodesMap.get(targetId)
234
+ ) {
235
+ hitEdges.push(edge);
236
+ }
237
+ }
238
+ });
239
+
240
+ const currentTransientNodes = new Set<string | number>();
241
+ const currentTransientEdges = new Set<string | number>();
242
+
243
+ hitNodesMap.forEach((node) => {
244
+ currentTransientNodes.add(node.id);
245
+
246
+ if (cachedTransientNodes.has(node.id)) {
247
+ cachedTransientNodes.delete(node.id);
248
+ } else {
249
+ graph.drawTransient('node', node.id, {
250
+ shapeIds: showNodeLabel
251
+ ? ['labelShape', 'labelBackgroundShape', 'keyShape']
252
+ : ['keyShape'],
253
+ });
254
+ }
255
+ });
256
+
257
+ cachedTransientNodes.forEach((id) => {
258
+ graph.drawTransient('node', id, { action: 'remove' });
259
+ });
260
+
261
+ if (showEdgeLabel) {
262
+ hitEdges.forEach((edge) => {
263
+ currentTransientEdges.add(edge.id);
264
+
265
+ if (cachedTransientEdges.has(edge.id)) {
266
+ cachedTransientEdges.delete(edge.id);
267
+ } else {
268
+ graph.drawTransient('edge', edge.id, {
269
+ shapeIds: ['labelShape', 'labelBackgroundShape', 'keyShape'],
270
+ drawSource: false,
271
+ drawTarget: false,
272
+ });
273
+ }
274
+ });
275
+
276
+ cachedTransientEdges.forEach((id) => {
277
+ graph.drawTransient('edge', id, { action: 'remove' });
278
+ });
279
+ }
280
+
281
+ this.cachedTransientNodes = currentTransientNodes;
282
+ this.cachedTransientEdges = currentTransientEdges;
283
+ }
284
+
285
+ /**
286
+ * Adjust part of the parameters, including trigger, showType, r, maxR, minR, shouldShow, showLabel, and scaleRBy
287
+ * @param {EdgeFilterLensConfig} cfg
288
+ */
289
+ public updateParams(cfg: EdgeFilterLensConfig) {
290
+ const self = this;
291
+ const { r, trigger, minR, maxR, scaleRBy, showLabel, shouldShow } = cfg;
292
+ if (!isNaN(cfg.r)) {
293
+ self.options.r = r;
294
+ }
295
+ if (!isNaN(maxR)) {
296
+ self.options.maxR = maxR;
297
+ }
298
+ if (!isNaN(minR)) {
299
+ self.options.minR = minR;
300
+ }
301
+ if (trigger === 'mousemove' || trigger === 'click' || trigger === 'drag') {
302
+ self.options.trigger = trigger;
303
+ }
304
+ if (scaleRBy === 'wheel' || scaleRBy === 'unset') {
305
+ self.options.scaleRBy = scaleRBy;
306
+ self.delegate.remove();
307
+ self.delegate.destroy();
308
+ }
309
+ if (showLabel === 'node' || showLabel === 'both') {
310
+ self.showNodeLabel = true;
311
+ }
312
+ if (showLabel === 'edge' || showLabel === 'both') {
313
+ self.showEdgeLabel = true;
314
+ }
315
+ if (shouldShow) {
316
+ self.options.shouldShow = shouldShow;
317
+ }
318
+ }
319
+
320
+ /**
321
+ * Update the delegate shape of the lens
322
+ * @param {Point} mCenter the center of the shape
323
+ * @param {number} r the radius of the shape
324
+ */
325
+ private updateDelegate(mCenter, r) {
326
+ const { graph, options, delegate } = this;
327
+ let lensDelegate = delegate;
328
+ if (!lensDelegate || lensDelegate.destroyed) {
329
+ // 拖动多个
330
+ const attrs = options.delegateStyle || lensDelegateStyle;
331
+
332
+ // model上的x, y是相对于图形中心的,delegateShape是g实例,x,y是绝对坐标
333
+ lensDelegate = graph.drawTransient('circle', 'lens-shape', {
334
+ style: {
335
+ r,
336
+ cx: mCenter.x,
337
+ cy: mCenter.y,
338
+ zIndex: -1,
339
+ ...attrs,
340
+ },
341
+ });
342
+ lensDelegate.toBack();
343
+ } else {
344
+ lensDelegate = graph.drawTransient('circle', 'lens-shape', {
345
+ style: {
346
+ r,
347
+ cx: mCenter.x,
348
+ cy: mCenter.y,
349
+ },
350
+ });
351
+ }
352
+
353
+ this.delegate = lensDelegate;
354
+ }
355
+
356
+ /**
357
+ * Clear the filtering
358
+ */
359
+ public clear() {
360
+ const {
361
+ graph,
362
+ delegate: lensDelegate,
363
+ cachedTransientNodes,
364
+ cachedTransientEdges,
365
+ } = this;
366
+
367
+ if (lensDelegate && !lensDelegate.destroyed) {
368
+ graph.drawTransient('circle', 'lens-shape', { action: 'remove' });
369
+ }
370
+ cachedTransientNodes.forEach((id) => {
371
+ graph.drawTransient('node', id, { action: 'remove' });
372
+ });
373
+ cachedTransientEdges.forEach((id) => {
374
+ graph.drawTransient('edge', id, { action: 'remove' });
375
+ });
376
+
377
+ cachedTransientNodes.clear();
378
+ cachedTransientEdges.clear();
379
+ }
380
+
381
+ /**
382
+ * Destroy the component
383
+ */
384
+ public destroy() {
385
+ this.clear();
386
+ }
387
+ }
@@ -1,7 +1,7 @@
1
1
  // TODO: update type define.
2
- import { createDom, modifyCSS } from '@antv/dom-util';
3
2
  import { Canvas } from '@antv/g';
4
3
  import { uniqueId } from '@antv/util';
4
+ import { createDOM, modifyCSS } from '../../../util/dom';
5
5
  import { IGraph } from '../../../types';
6
6
  import { Plugin as Base, IPluginBaseConfig } from '../../../types/plugin';
7
7
 
@@ -28,7 +28,7 @@ interface ViewPortEventParam {
28
28
  export class Grid extends Base {
29
29
  private canvas: Canvas;
30
30
  private viewport: HTMLElement | undefined;
31
- private container: HTMLDivElement;
31
+ private container: HTMLElement;
32
32
  constructor(options?: GridConfig) {
33
33
  super(options);
34
34
  }
@@ -49,11 +49,11 @@ export class Grid extends Base {
49
49
  const [width, height] = graph.getSize();
50
50
  const img = this.options.img || GRID_PNG;
51
51
 
52
- const container: HTMLDivElement = createDom(
52
+ const container: HTMLElement = createDOM(
53
53
  `<div class='g6-grid-container' style="position: absolute; left:0;top:0;right:0;bottom:0;overflow: hidden;"></div>`,
54
54
  );
55
55
 
56
- const gridContainer: HTMLDivElement = createDom(
56
+ const gridContainer: HTMLElement = createDOM(
57
57
  `<div
58
58
  class='g6-grid'
59
59
  style='position:absolute;
@@ -96,7 +96,7 @@ export class Grid extends Base {
96
96
  * @param param
97
97
  */
98
98
  protected updateGrid(param: ViewPortEventParam) {
99
- const gridContainer: HTMLDivElement = this.container;
99
+ const gridContainer: HTMLElement = this.container;
100
100
  let { matrix } = param;
101
101
  if (!matrix) matrix = [1, 0, 0, 0, 1, 0, 0, 0, 1];
102
102
 
@@ -110,7 +110,7 @@ export class Grid extends Base {
110
110
  });
111
111
  }
112
112
 
113
- public getContainer(): HTMLDivElement {
113
+ public getContainer(): HTMLElement {
114
114
  return this.container;
115
115
  }
116
116
 
@@ -1,4 +1,4 @@
1
- import { ComboModel, NodeModel } from 'types';
1
+ import { ComboModel, NodeModel } from '../../../types';
2
2
  import { Point } from '../../../types/common';
3
3
 
4
4
  /**
@@ -1,4 +1,3 @@
1
- import { parsePathString } from '@antv/path-util';
2
1
  import { DisplayObject } from '@antv/g';
3
2
  import { isArray } from '@antv/util';
4
3
  import { ComboModel, ID, IGraph, NodeModel } from '../../../types';
@@ -141,7 +140,7 @@ export default class Hull {
141
140
  contour.map((p) => [p.x, p.y]),
142
141
  this.padding,
143
142
  );
144
- path = parsePathString(hull);
143
+ path = hull;
145
144
  break;
146
145
  case 'smooth-convex':
147
146
  contour = genConvexHull(members);
@@ -150,7 +149,7 @@ export default class Hull {
150
149
  contour.map((p) => [p.x, p.y]),
151
150
  this.padding,
152
151
  );
153
- path = parsePathString(hull);
152
+ path = hull;
154
153
  } else if (contour.length > 2) {
155
154
  hull = paddedHull(
156
155
  contour.map((p) => [p.x, p.y]),
@@ -1,4 +1,4 @@
1
- import { vec2 } from '@antv/matrix-util';
1
+ import { vec2 } from 'gl-matrix';
2
2
  import { ID, IGraph } from 'types';
3
3
  import { AABB } from '@antv/g';
4
4
  import { Bounds, Point } from '../../../types/common';
@@ -56,7 +56,11 @@ export function roundedHull(polyPoints: vec2[], padding: number) {
56
56
  const p1 = [points[0][0], points[0][1] - padding];
57
57
  const p2 = [points[0][0], points[0][1] + padding];
58
58
 
59
- return `M ${p1} A ${padding},${padding},0,0,0,${p2} A ${padding},${padding},0,0,0,${p1}`;
59
+ return [
60
+ ['M', p1],
61
+ ['A', padding, padding, 0, 0, 0, p2],
62
+ ['A', padding, padding, 0, 0, 0, p1],
63
+ ];
60
64
  };
61
65
 
62
66
  // The rounded hull path around two points
@@ -8,3 +8,4 @@ export * from './toolbar';
8
8
  export * from './tooltip';
9
9
  export * from './timebar';
10
10
  export * from './snapline';
11
+ export * from './edgeFilterLens';
@@ -1,13 +1,13 @@
1
1
  import { Category } from '@antv/gui';
2
2
  import { Canvas, DisplayObject, Circle, Line } from '@antv/g';
3
3
  import { isFunction, isString, upperFirst, uniqueId } from '@antv/util';
4
- import { createDom } from '@antv/dom-util';
5
4
  import { ID } from '@antv/graphlib';
6
5
  import { IGraph } from '../../../types';
7
6
  import { RendererName } from '../../../types/render';
8
7
  import { Plugin as Base, IPluginBaseConfig } from '../../../types/plugin';
9
8
  import { createCanvas } from '../../../util/canvas';
10
9
  import { ShapeTagMap, formatPadding } from '../../../util/shape';
10
+ import { createDOM } from '../../../util/dom';
11
11
 
12
12
  const LEGEND_CATEGORY_ITEM_MARKER = '.legend-category-item-marker';
13
13
 
@@ -51,7 +51,7 @@ export interface LegendConfig extends IPluginBaseConfig {
51
51
  /**
52
52
  * Container for the legend, using graph's container by default
53
53
  */
54
- container?: HTMLDivElement | string;
54
+ container?: HTMLElement | string;
55
55
  /**
56
56
  * Renderer for the legend canvas, 'canvas' by default
57
57
  */
@@ -102,7 +102,7 @@ export class Legend extends Base {
102
102
  */
103
103
  private edgeLegend: Category;
104
104
 
105
- private wrapper: HTMLDivElement;
105
+ private wrapper: HTMLElement;
106
106
  private canvas: Canvas;
107
107
 
108
108
  private size: ('fit-content' | number)[];
@@ -303,7 +303,7 @@ export class Legend extends Base {
303
303
 
304
304
  /**
305
305
  * Creates a wrapper div element for the graph and appends it to the container.
306
- * @returns {HTMLDivElement} - The created wrapper div element.
306
+ * @returns {HTMLElement} - The created wrapper div element.
307
307
  */
308
308
  private createWrapper() {
309
309
  const { options, graph, size } = this;
@@ -322,9 +322,9 @@ export class Legend extends Base {
322
322
  size[0] === 'fit-content' ? 0 : size[0],
323
323
  size[1] === 'fit-content' ? 0 : size[1],
324
324
  ];
325
- const wrapper = (HTMLDivElement = createDom(
325
+ const wrapper = createDOM(
326
326
  `<div class='${className}' style='width: ${wrapperSize[0]}px; height: ${wrapperSize[1]}px; overflow: hidden;'></div>`,
327
- ));
327
+ );
328
328
  $container.appendChild(wrapper);
329
329
  return wrapper;
330
330
  }
@@ -1,6 +1,5 @@
1
1
  // TODO: update type define.
2
2
  // @ts-nocheck
3
- import { createDom, modifyCSS } from '@antv/dom-util';
4
3
  import { Canvas, DisplayObject, Group, Rect } from '@antv/g';
5
4
  import { debounce, each, isNil, isString, uniqueId } from '@antv/util';
6
5
  import { IGraph } from '../../../types';
@@ -8,6 +7,7 @@ import { IG6GraphEvent } from '../../../types/event';
8
7
  import { ShapeStyle } from '../../../types/item';
9
8
  import { Plugin as Base, IPluginBaseConfig } from '../../../types/plugin';
10
9
  import { createCanvas } from '../../../util/canvas';
10
+ import { createDOM, modifyCSS } from '../../../util/dom';
11
11
 
12
12
  const DEFAULT_MODE = 'default';
13
13
  const KEYSHAPE_MODE = 'keyShape';
@@ -32,7 +32,7 @@ export interface MiniMapConfig extends IPluginBaseConfig {
32
32
  /** Whether to hide edges on minimap to enhance performance */
33
33
  hideEdge?: boolean;
34
34
  /** Container for minimap */
35
- container?: HTMLDivElement | null;
35
+ container?: HTMLElement | null;
36
36
  }
37
37
 
38
38
  export class Minimap extends Base {
@@ -47,7 +47,7 @@ export class Minimap extends Base {
47
47
  graphItem: DisplayObject;
48
48
  }
49
49
  > = new Map();
50
- private container: HTMLDivElement;
50
+ private container: HTMLElement;
51
51
  /** Ratio of (minimap graph size / main graph size). */
52
52
  private ratio: number;
53
53
  /** Distance from top of minimap graph to the top of minimap container. */
@@ -111,7 +111,7 @@ export class Minimap extends Base {
111
111
  const containerDOM = canvas.context.config.container as HTMLElement;
112
112
  const isFireFox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
113
113
  const isSafari = navigator.userAgent.toLowerCase().indexOf('safari') > -1;
114
- const viewport = createDom(`
114
+ const viewport = createDOM(`
115
115
  <div
116
116
  class=${viewportClassName}
117
117
  style='position:absolute;
@@ -631,12 +631,12 @@ export class Minimap extends Base {
631
631
  const { graph, options } = this;
632
632
  const { size, className } = options;
633
633
  let parentNode = options.container;
634
- const container: HTMLDivElement = createDom(
634
+ const container: HTMLElement = createDOM(
635
635
  `<div class='${className}' style='width: ${size[0]}px; height: ${size[1]}px; overflow: hidden;'></div>`,
636
636
  );
637
637
 
638
638
  if (isString(parentNode)) {
639
- parentNode = document.getElementById(parentNode) as HTMLDivElement;
639
+ parentNode = document.getElementById(parentNode) as HTMLElement;
640
640
  }
641
641
 
642
642
  if (parentNode) {
@@ -653,7 +653,7 @@ export class Minimap extends Base {
653
653
  }
654
654
  this.container = container;
655
655
 
656
- const containerDOM = createDom(
656
+ const containerDOM = createDOM(
657
657
  '<div class="g6-minimap-container" style="position: relative;"></div>',
658
658
  );
659
659
  container.appendChild(containerDOM);