@antv/g6 5.0.0-beta.4 → 5.0.0-beta.6

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 (246) hide show
  1. package/dist/g6.min.js +2 -2
  2. package/esm/index.d.ts +15 -1
  3. package/esm/index.js +1 -1
  4. package/esm/item/combo.d.ts +1 -1
  5. package/esm/item/combo.js +16 -9
  6. package/esm/item/combo.js.map +1 -1
  7. package/esm/item/edge.d.ts +2 -1
  8. package/esm/item/edge.js +18 -8
  9. package/esm/item/edge.js.map +1 -1
  10. package/esm/item/item.d.ts +3 -2
  11. package/esm/item/item.js +12 -6
  12. package/esm/item/item.js.map +1 -1
  13. package/esm/item/node.d.ts +2 -1
  14. package/esm/item/node.js +19 -10
  15. package/esm/item/node.js.map +1 -1
  16. package/esm/runtime/controller/item.d.ts +1 -0
  17. package/esm/runtime/controller/item.js +271 -151
  18. package/esm/runtime/controller/item.js.map +1 -1
  19. package/esm/runtime/graph.d.ts +98 -18
  20. package/esm/runtime/graph.js +427 -75
  21. package/esm/runtime/graph.js.map +1 -1
  22. package/esm/stdlib/behavior/activate-relations.js +2 -2
  23. package/esm/stdlib/behavior/activate-relations.js.map +1 -1
  24. package/esm/stdlib/behavior/brush-select.js +1 -2
  25. package/esm/stdlib/behavior/brush-select.js.map +1 -1
  26. package/esm/stdlib/behavior/click-select.js +1 -1
  27. package/esm/stdlib/behavior/click-select.js.map +1 -1
  28. package/esm/stdlib/behavior/create-edge.d.ts +57 -0
  29. package/esm/stdlib/behavior/create-edge.js +206 -0
  30. package/esm/stdlib/behavior/create-edge.js.map +1 -0
  31. package/esm/stdlib/behavior/drag-canvas.d.ts +1 -1
  32. package/esm/stdlib/behavior/drag-canvas.js +51 -28
  33. package/esm/stdlib/behavior/drag-canvas.js.map +1 -1
  34. package/esm/stdlib/behavior/drag-combo.d.ts +2 -2
  35. package/esm/stdlib/behavior/drag-combo.js +43 -32
  36. package/esm/stdlib/behavior/drag-combo.js.map +1 -1
  37. package/esm/stdlib/behavior/drag-node.d.ts +3 -3
  38. package/esm/stdlib/behavior/drag-node.js +76 -63
  39. package/esm/stdlib/behavior/drag-node.js.map +1 -1
  40. package/esm/stdlib/behavior/index.d.ts +2 -0
  41. package/esm/stdlib/behavior/index.js +2 -0
  42. package/esm/stdlib/behavior/index.js.map +1 -1
  43. package/esm/stdlib/behavior/lasso-select.d.ts +1 -1
  44. package/esm/stdlib/behavior/lasso-select.js +1 -2
  45. package/esm/stdlib/behavior/lasso-select.js.map +1 -1
  46. package/esm/stdlib/behavior/scroll-canvas.d.ts +67 -0
  47. package/esm/stdlib/behavior/scroll-canvas.js +266 -0
  48. package/esm/stdlib/behavior/scroll-canvas.js.map +1 -0
  49. package/esm/stdlib/behavior/zoom-canvas.d.ts +1 -1
  50. package/esm/stdlib/behavior/zoom-canvas.js +47 -24
  51. package/esm/stdlib/behavior/zoom-canvas.js.map +1 -1
  52. package/esm/stdlib/index.d.ts +6 -0
  53. package/esm/stdlib/index.js +15 -9
  54. package/esm/stdlib/index.js.map +1 -1
  55. package/esm/stdlib/item/edge/base.d.ts +1 -1
  56. package/esm/stdlib/item/edge/base.js +13 -4
  57. package/esm/stdlib/item/edge/base.js.map +1 -1
  58. package/esm/stdlib/item/node/base.d.ts +1 -1
  59. package/esm/stdlib/item/node/base.js +11 -12
  60. package/esm/stdlib/item/node/base.js.map +1 -1
  61. package/esm/stdlib/item/node/image.d.ts +1 -1
  62. package/esm/stdlib/item/node/image.js +1 -1
  63. package/esm/stdlib/item/node/image.js.map +1 -1
  64. package/esm/stdlib/plugin/history/combo-command.js +2 -2
  65. package/esm/stdlib/plugin/history/combo-command.js.map +1 -1
  66. package/esm/stdlib/plugin/history/index.d.ts +10 -10
  67. package/esm/stdlib/plugin/history/index.js +14 -14
  68. package/esm/stdlib/plugin/history/index.js.map +1 -1
  69. package/esm/stdlib/plugin/history/item-data-command.js +4 -4
  70. package/esm/stdlib/plugin/history/item-data-command.js.map +1 -1
  71. package/esm/stdlib/plugin/history/layer-updated-command.js +2 -2
  72. package/esm/stdlib/plugin/history/layer-updated-command.js.map +1 -1
  73. package/esm/stdlib/plugin/history/state-updated-command.js +1 -1
  74. package/esm/stdlib/plugin/history/state-updated-command.js.map +1 -1
  75. package/esm/stdlib/plugin/history/visibility-updated-command.js +2 -2
  76. package/esm/stdlib/plugin/history/visibility-updated-command.js.map +1 -1
  77. package/esm/stdlib/plugin/hull/hullComponent.d.ts +1 -1
  78. package/esm/stdlib/plugin/hull/hullComponent.js +3 -6
  79. package/esm/stdlib/plugin/hull/hullComponent.js.map +1 -1
  80. package/esm/stdlib/plugin/index.d.ts +1 -0
  81. package/esm/stdlib/plugin/index.js +1 -0
  82. package/esm/stdlib/plugin/index.js.map +1 -1
  83. package/esm/stdlib/plugin/minimap/index.d.ts +5 -1
  84. package/esm/stdlib/plugin/minimap/index.js +109 -8
  85. package/esm/stdlib/plugin/minimap/index.js.map +1 -1
  86. package/esm/stdlib/plugin/snapline/index.d.ts +163 -0
  87. package/esm/stdlib/plugin/snapline/index.js +1052 -0
  88. package/esm/stdlib/plugin/snapline/index.js.map +1 -0
  89. package/esm/stdlib/plugin/types.d.ts +1 -0
  90. package/esm/types/graph.d.ts +45 -19
  91. package/esm/types/hook.d.ts +22 -2
  92. package/esm/types/spec.d.ts +19 -3
  93. package/esm/util/bbox.d.ts +16 -1
  94. package/esm/util/bbox.js +29 -0
  95. package/esm/util/bbox.js.map +1 -1
  96. package/esm/util/item.d.ts +16 -1
  97. package/esm/util/item.js +31 -8
  98. package/esm/util/item.js.map +1 -1
  99. package/esm/util/shape.js +2 -2
  100. package/esm/util/shape.js.map +1 -1
  101. package/esm/util/warn.d.ts +14 -0
  102. package/esm/util/warn.js +4 -0
  103. package/esm/util/warn.js.map +1 -0
  104. package/lib/index.d.ts +15 -1
  105. package/lib/index.js +1 -1
  106. package/lib/item/combo.d.ts +1 -1
  107. package/lib/item/combo.js +16 -9
  108. package/lib/item/combo.js.map +1 -1
  109. package/lib/item/edge.d.ts +2 -1
  110. package/lib/item/edge.js +18 -8
  111. package/lib/item/edge.js.map +1 -1
  112. package/lib/item/item.d.ts +3 -2
  113. package/lib/item/item.js +12 -6
  114. package/lib/item/item.js.map +1 -1
  115. package/lib/item/node.d.ts +2 -1
  116. package/lib/item/node.js +19 -10
  117. package/lib/item/node.js.map +1 -1
  118. package/lib/runtime/controller/item.d.ts +1 -0
  119. package/lib/runtime/controller/item.js +270 -150
  120. package/lib/runtime/controller/item.js.map +1 -1
  121. package/lib/runtime/graph.d.ts +98 -18
  122. package/lib/runtime/graph.js +427 -75
  123. package/lib/runtime/graph.js.map +1 -1
  124. package/lib/stdlib/behavior/activate-relations.js +2 -2
  125. package/lib/stdlib/behavior/activate-relations.js.map +1 -1
  126. package/lib/stdlib/behavior/brush-select.js +1 -2
  127. package/lib/stdlib/behavior/brush-select.js.map +1 -1
  128. package/lib/stdlib/behavior/click-select.js +1 -1
  129. package/lib/stdlib/behavior/click-select.js.map +1 -1
  130. package/lib/stdlib/behavior/create-edge.d.ts +57 -0
  131. package/lib/stdlib/behavior/create-edge.js +210 -0
  132. package/lib/stdlib/behavior/create-edge.js.map +1 -0
  133. package/lib/stdlib/behavior/drag-canvas.d.ts +1 -1
  134. package/lib/stdlib/behavior/drag-canvas.js +51 -28
  135. package/lib/stdlib/behavior/drag-canvas.js.map +1 -1
  136. package/lib/stdlib/behavior/drag-combo.d.ts +2 -2
  137. package/lib/stdlib/behavior/drag-combo.js +43 -32
  138. package/lib/stdlib/behavior/drag-combo.js.map +1 -1
  139. package/lib/stdlib/behavior/drag-node.d.ts +3 -3
  140. package/lib/stdlib/behavior/drag-node.js +76 -63
  141. package/lib/stdlib/behavior/drag-node.js.map +1 -1
  142. package/lib/stdlib/behavior/index.d.ts +2 -0
  143. package/lib/stdlib/behavior/index.js +2 -0
  144. package/lib/stdlib/behavior/index.js.map +1 -1
  145. package/lib/stdlib/behavior/lasso-select.d.ts +1 -1
  146. package/lib/stdlib/behavior/lasso-select.js +1 -2
  147. package/lib/stdlib/behavior/lasso-select.js.map +1 -1
  148. package/lib/stdlib/behavior/scroll-canvas.d.ts +67 -0
  149. package/lib/stdlib/behavior/scroll-canvas.js +270 -0
  150. package/lib/stdlib/behavior/scroll-canvas.js.map +1 -0
  151. package/lib/stdlib/behavior/zoom-canvas.d.ts +1 -1
  152. package/lib/stdlib/behavior/zoom-canvas.js +47 -24
  153. package/lib/stdlib/behavior/zoom-canvas.js.map +1 -1
  154. package/lib/stdlib/index.d.ts +6 -0
  155. package/lib/stdlib/index.js +15 -9
  156. package/lib/stdlib/index.js.map +1 -1
  157. package/lib/stdlib/item/edge/base.d.ts +1 -1
  158. package/lib/stdlib/item/edge/base.js +13 -4
  159. package/lib/stdlib/item/edge/base.js.map +1 -1
  160. package/lib/stdlib/item/node/base.d.ts +1 -1
  161. package/lib/stdlib/item/node/base.js +11 -12
  162. package/lib/stdlib/item/node/base.js.map +1 -1
  163. package/lib/stdlib/item/node/image.d.ts +1 -1
  164. package/lib/stdlib/item/node/image.js +1 -1
  165. package/lib/stdlib/item/node/image.js.map +1 -1
  166. package/lib/stdlib/plugin/history/combo-command.js +2 -2
  167. package/lib/stdlib/plugin/history/combo-command.js.map +1 -1
  168. package/lib/stdlib/plugin/history/index.d.ts +10 -10
  169. package/lib/stdlib/plugin/history/index.js +14 -14
  170. package/lib/stdlib/plugin/history/index.js.map +1 -1
  171. package/lib/stdlib/plugin/history/item-data-command.js +4 -4
  172. package/lib/stdlib/plugin/history/item-data-command.js.map +1 -1
  173. package/lib/stdlib/plugin/history/layer-updated-command.js +2 -2
  174. package/lib/stdlib/plugin/history/layer-updated-command.js.map +1 -1
  175. package/lib/stdlib/plugin/history/state-updated-command.js +1 -1
  176. package/lib/stdlib/plugin/history/state-updated-command.js.map +1 -1
  177. package/lib/stdlib/plugin/history/visibility-updated-command.js +2 -2
  178. package/lib/stdlib/plugin/history/visibility-updated-command.js.map +1 -1
  179. package/lib/stdlib/plugin/hull/hullComponent.d.ts +1 -1
  180. package/lib/stdlib/plugin/hull/hullComponent.js +3 -6
  181. package/lib/stdlib/plugin/hull/hullComponent.js.map +1 -1
  182. package/lib/stdlib/plugin/index.d.ts +1 -0
  183. package/lib/stdlib/plugin/index.js +1 -0
  184. package/lib/stdlib/plugin/index.js.map +1 -1
  185. package/lib/stdlib/plugin/minimap/index.d.ts +5 -1
  186. package/lib/stdlib/plugin/minimap/index.js +109 -8
  187. package/lib/stdlib/plugin/minimap/index.js.map +1 -1
  188. package/lib/stdlib/plugin/snapline/index.d.ts +163 -0
  189. package/lib/stdlib/plugin/snapline/index.js +1056 -0
  190. package/lib/stdlib/plugin/snapline/index.js.map +1 -0
  191. package/lib/stdlib/plugin/types.d.ts +1 -0
  192. package/lib/types/graph.d.ts +45 -19
  193. package/lib/types/hook.d.ts +22 -2
  194. package/lib/types/spec.d.ts +19 -3
  195. package/lib/util/bbox.d.ts +16 -1
  196. package/lib/util/bbox.js +32 -1
  197. package/lib/util/bbox.js.map +1 -1
  198. package/lib/util/item.d.ts +16 -1
  199. package/lib/util/item.js +33 -9
  200. package/lib/util/item.js.map +1 -1
  201. package/lib/util/shape.js +2 -2
  202. package/lib/util/shape.js.map +1 -1
  203. package/lib/util/warn.d.ts +14 -0
  204. package/lib/util/warn.js +8 -0
  205. package/lib/util/warn.js.map +1 -0
  206. package/package.json +2 -2
  207. package/src/index.ts +1 -1
  208. package/src/item/combo.ts +14 -9
  209. package/src/item/edge.ts +17 -8
  210. package/src/item/item.ts +11 -6
  211. package/src/item/node.ts +24 -16
  212. package/src/runtime/controller/item.ts +240 -72
  213. package/src/runtime/graph.ts +536 -80
  214. package/src/stdlib/behavior/activate-relations.ts +2 -2
  215. package/src/stdlib/behavior/brush-select.ts +4 -2
  216. package/src/stdlib/behavior/click-select.ts +1 -1
  217. package/src/stdlib/behavior/create-edge.ts +295 -0
  218. package/src/stdlib/behavior/drag-canvas.ts +67 -29
  219. package/src/stdlib/behavior/drag-combo.ts +10 -10
  220. package/src/stdlib/behavior/drag-node.ts +18 -18
  221. package/src/stdlib/behavior/index.ts +2 -0
  222. package/src/stdlib/behavior/lasso-select.ts +5 -3
  223. package/src/stdlib/behavior/scroll-canvas.ts +348 -0
  224. package/src/stdlib/behavior/zoom-canvas.ts +61 -25
  225. package/src/stdlib/index.ts +16 -7
  226. package/src/stdlib/item/edge/base.ts +13 -5
  227. package/src/stdlib/item/node/base.ts +15 -14
  228. package/src/stdlib/item/node/image.ts +1 -1
  229. package/src/stdlib/plugin/history/combo-command.ts +2 -2
  230. package/src/stdlib/plugin/history/index.ts +14 -14
  231. package/src/stdlib/plugin/history/item-data-command.ts +4 -4
  232. package/src/stdlib/plugin/history/layer-updated-command.ts +2 -2
  233. package/src/stdlib/plugin/history/state-updated-command.ts +1 -1
  234. package/src/stdlib/plugin/history/visibility-updated-command.ts +2 -2
  235. package/src/stdlib/plugin/hull/hullComponent.ts +8 -5
  236. package/src/stdlib/plugin/index.ts +1 -0
  237. package/src/stdlib/plugin/minimap/index.ts +113 -9
  238. package/src/stdlib/plugin/snapline/index.ts +1277 -0
  239. package/src/stdlib/plugin/types.ts +1 -0
  240. package/src/types/graph.ts +53 -22
  241. package/src/types/hook.ts +22 -2
  242. package/src/types/spec.ts +22 -3
  243. package/src/util/bbox.ts +38 -1
  244. package/src/util/item.ts +65 -28
  245. package/src/util/shape.ts +2 -2
  246. package/src/util/warn.ts +20 -0
@@ -61,8 +61,10 @@ export class LassoSelect extends BrushSelect {
61
61
  const { graph, options } = this;
62
62
  const { brushStyle } = options;
63
63
  return graph.drawTransient('path', LASSO_SHAPE_ID, {
64
- style: brushStyle,
65
- capture: false,
64
+ style: {
65
+ pointerEvents: 'none',
66
+ ...brushStyle,
67
+ },
66
68
  });
67
69
  }
68
70
 
@@ -82,7 +84,7 @@ export class LassoSelect extends BrushSelect {
82
84
 
83
85
  getLassoPath = () => {
84
86
  const points: Point[] = this.points;
85
- const path = [];
87
+ const path: any = [];
86
88
  if (points.length) {
87
89
  points.forEach((point, index) => {
88
90
  if (index === 0) {
@@ -0,0 +1,348 @@
1
+ import { isBoolean, isNumber, isObject } from '@antv/util';
2
+ import { Behavior } from '../../types/behavior';
3
+ import { ID, IG6GraphEvent } from '../../types';
4
+
5
+ interface ScrollCanvasOptions {
6
+ /**
7
+ * The direction of dragging that is allowed. Options: 'x', 'y', 'both'. 'both' by default.
8
+ */
9
+ direction?: string;
10
+ /**
11
+ * Whether enable optimize strategies, which will hide all the shapes excluding node keyShape while scrolling.
12
+ */
13
+ enableOptimize?: boolean;
14
+ /**
15
+ * When the zoom ratio of the graph is smaller than ```optimizeZoom```, all shapes except for node keyShape will always be hidden.
16
+ * This option requires ```enableOptimize=true```;
17
+ */
18
+ optimizeZoom?: number;
19
+ /**
20
+ * Switch to zooming while pressing the key and wheeling. Options: 'shift', 'ctrl', 'alt', 'control', 'meta', using an array of these options allows any of these keys to trigger zooming;
21
+ * Use ```'ctrl'``` by default;
22
+ */
23
+ zoomKey?: string | string[];
24
+ /** Switch to zooming while pressing the key and wheeling. This option allows you to control the zoom ratio for each event.
25
+ * Use ```'0.05'``` by default;
26
+ */
27
+ zoomRatio?: number;
28
+ /**
29
+ * The range of canvas to limit dragging, 0 by default, which means the graph cannot be dragged totally out of the view port range.
30
+ * If scalableRange is number or a string without 'px', means it is a ratio of the graph content.
31
+ * If scalableRange is a string with 'px', it is regarded as pixels.
32
+ * If scalableRange = 0, no constrains;
33
+ * If scalableRange > 0, the graph can be dragged out of the view port range
34
+ * If scalableRange < 0, the range is smaller than the view port.
35
+ * Refer to https://gw.alipayobjects.com/mdn/rms_f8c6a0/afts/img/A*IFfoS67_HssAAAAAAAAAAAAAARQnAQ
36
+ */
37
+ scalableRange?: string | number;
38
+ /**
39
+ * Whether allow trigger this behavior when drag start on nodes / edges / combos.
40
+ */
41
+ allowDragOnItem?:
42
+ | boolean
43
+ | {
44
+ node?: boolean;
45
+ edge?: boolean;
46
+ combo?: boolean;
47
+ };
48
+ }
49
+
50
+ const DEFAULT_OPTIONS: ScrollCanvasOptions = {
51
+ direction: 'both',
52
+ enableOptimize: false,
53
+ zoomKey: 'ctrl',
54
+ scalableRange: 0,
55
+ allowDragOnItem: true,
56
+ zoomRatio: 0.05,
57
+ };
58
+
59
+ export class ScrollCanvas extends Behavior {
60
+ private hiddenEdgeIds: ID[];
61
+ private hiddenNodeIds: ID[];
62
+
63
+ declare options: ScrollCanvasOptions;
64
+ timeout?: number;
65
+ optimized = false;
66
+ constructor(options: Partial<ScrollCanvasOptions>) {
67
+ const finalOptions = Object.assign({}, DEFAULT_OPTIONS, options, {
68
+ zoomKey: initZoomKey(options.zoomKey),
69
+ });
70
+ super(finalOptions);
71
+ }
72
+
73
+ getEvents = () => {
74
+ return {
75
+ wheel: this.onWheel,
76
+ };
77
+ };
78
+
79
+ onWheel(ev: IG6GraphEvent & { deltaX?: number; deltaY?: number }) {
80
+ if (!this.allowDrag(ev)) return;
81
+ const graph = this.graph;
82
+ const { zoomKey, zoomRatio, enableOptimize } = this.options;
83
+ const zoomKeys = Array.isArray(zoomKey) ? [].concat(zoomKey) : [zoomKey];
84
+ if (zoomKeys.includes('control')) zoomKeys.push('ctrl');
85
+ const keyDown = zoomKeys.some((ele) => ev[`${ele}Key`]);
86
+
87
+ const nativeEvent = ev.nativeEvent as
88
+ | (WheelEvent & { wheelDelta: number })
89
+ | undefined;
90
+
91
+ if (keyDown) {
92
+ const canvas = graph.canvas;
93
+ const point = canvas.client2Viewport({ x: ev.client.x, y: ev.client.y });
94
+ let ratio = graph.getZoom();
95
+ if (nativeEvent && nativeEvent.wheelDelta > 0) {
96
+ ratio = ratio + ratio * zoomRatio;
97
+ } else {
98
+ ratio = ratio - ratio * zoomRatio;
99
+ }
100
+ graph.zoomTo(ratio, {
101
+ x: point.x,
102
+ y: point.y,
103
+ });
104
+ } else {
105
+ const diffX = ev.deltaX || ev.movement.x;
106
+ const diffY = ev.deltaY || ev.movement.y;
107
+
108
+ const { dx, dy } = this.formatDisplacement(diffX, diffY);
109
+ graph.translate({ dx: -dx, dy: -dy });
110
+ }
111
+
112
+ if (enableOptimize) {
113
+ const optimized = this.optimized;
114
+
115
+ // hiding
116
+ if (!optimized) {
117
+ this.hideShapes();
118
+ this.optimized = true;
119
+ }
120
+
121
+ // showing after 100ms
122
+ clearTimeout(this.timeout);
123
+ this.timeout = undefined;
124
+ const timeout = window.setTimeout(() => {
125
+ this.showShapes();
126
+ this.optimized = false;
127
+ }, 100);
128
+ this.timeout = timeout;
129
+ }
130
+ }
131
+ private formatDisplacement(dx: number, dy: number) {
132
+ const { graph } = this;
133
+ const { scalableRange, direction } = this.options;
134
+ const [width, height] = graph.getSize();
135
+ const graphBBox = graph.canvas.getRoot().getRenderBounds();
136
+ let rangeNum = Number(scalableRange);
137
+ let isPixel;
138
+ if (typeof scalableRange === 'string') {
139
+ if (scalableRange.includes('px')) {
140
+ isPixel = scalableRange.includes('px');
141
+ rangeNum = Number(scalableRange.replace('px', ''));
142
+ }
143
+ if (scalableRange.includes('%')) {
144
+ rangeNum = Number(scalableRange.replace('%', '')) / 100;
145
+ }
146
+ }
147
+
148
+ let expandWidth = rangeNum;
149
+ let expandHeight = rangeNum;
150
+ // If it is not a string with 'px', regard as ratio
151
+ if (!isPixel) {
152
+ expandWidth = width * rangeNum;
153
+ expandHeight = height * rangeNum;
154
+ }
155
+ const leftTopClient = graph.getViewportByCanvas({
156
+ x: graphBBox.min[0],
157
+ y: graphBBox.min[1],
158
+ });
159
+ const rightBottomClient = graph.getViewportByCanvas({
160
+ x: graphBBox.max[0],
161
+ y: graphBBox.max[1],
162
+ });
163
+ const minX = leftTopClient.x;
164
+ const minY = leftTopClient.y;
165
+ const maxX = rightBottomClient.x;
166
+ const maxY = rightBottomClient.y;
167
+ if (dx > 0) {
168
+ if (maxX < -expandWidth) {
169
+ dx = 0;
170
+ } else if (maxX - dx < -expandWidth) {
171
+ dx = maxX + expandWidth;
172
+ }
173
+ } else if (dx < 0) {
174
+ if (minX > width + expandWidth) {
175
+ dx = 0;
176
+ } else if (minX - dx > width + expandWidth) {
177
+ dx = minX - (width + expandWidth);
178
+ }
179
+ }
180
+
181
+ if (dy > 0) {
182
+ if (maxY < -expandHeight) {
183
+ dy = 0;
184
+ } else if (maxY - dy < -expandHeight) {
185
+ dy = maxY + expandHeight;
186
+ }
187
+ } else if (dy < 0) {
188
+ if (minY > height + expandHeight) {
189
+ dy = 0;
190
+ } else if (minY - dy > height + expandHeight) {
191
+ dy = minY - (height + expandHeight);
192
+ }
193
+ }
194
+
195
+ if (direction === 'x') {
196
+ dy = 0;
197
+ } else if (direction === 'y') {
198
+ dx = 0;
199
+ }
200
+
201
+ return { dx, dy };
202
+ }
203
+
204
+ private allowDrag(evt: IG6GraphEvent) {
205
+ const { itemType } = evt;
206
+ const { allowDragOnItem } = this.options;
207
+ const targetIsCanvas = itemType === 'canvas';
208
+ if (isBoolean(allowDragOnItem) && !allowDragOnItem && !targetIsCanvas)
209
+ return false;
210
+ if (isObject(allowDragOnItem)) {
211
+ const { node, edge, combo } = allowDragOnItem;
212
+ if (!node && itemType === 'node') return false;
213
+ if (!edge && itemType === 'edge') return false;
214
+ if (!combo && itemType === 'combo') return false;
215
+ }
216
+ return true;
217
+ }
218
+
219
+ private hideShapes() {
220
+ const { graph, options } = this;
221
+ const { tileBehavior: graphBehaviorOptimize, tileBehaviorSize = 1000 } =
222
+ graph.getSpecification().optimize || {};
223
+ const { optimizeZoom } = options;
224
+ const optimize = this.options.enableOptimize || graphBehaviorOptimize;
225
+ const shouldOptimzie = isNumber(optimize)
226
+ ? graph.getAllNodesData().length > optimize
227
+ : optimize;
228
+ if (shouldOptimzie) {
229
+ const currentZoom = graph.getZoom();
230
+ const newHiddenEdgeIds = graph
231
+ .getAllEdgesData()
232
+ .map((edge) => edge.id)
233
+ .filter((id) => graph.getItemVisible(id));
234
+ graph.hideItem(newHiddenEdgeIds, true);
235
+
236
+ if (currentZoom < optimizeZoom) {
237
+ this.hiddenEdgeIds.push(...newHiddenEdgeIds);
238
+ } else {
239
+ this.hiddenEdgeIds = newHiddenEdgeIds;
240
+ }
241
+
242
+ const newHiddenNodeIds = graph
243
+ .getAllNodesData()
244
+ .map((node) => node.id)
245
+ .filter((id) => graph.getItemVisible(id));
246
+
247
+ let requestId;
248
+ const sectionNum = Math.ceil(newHiddenNodeIds.length / tileBehaviorSize);
249
+ const sections = Array.from({ length: sectionNum }, (v, i) =>
250
+ newHiddenNodeIds.slice(
251
+ i * tileBehaviorSize,
252
+ i * tileBehaviorSize + tileBehaviorSize,
253
+ ),
254
+ );
255
+ const update = () => {
256
+ if (!sections.length) {
257
+ cancelAnimationFrame(requestId);
258
+ return;
259
+ }
260
+ const section = sections.shift();
261
+ graph.startHistoryBatch();
262
+ graph.hideItem(section, false, true);
263
+ graph.stopHistoryBatch();
264
+ requestId = requestAnimationFrame(update);
265
+ };
266
+ requestId = requestAnimationFrame(update);
267
+
268
+ if (currentZoom < optimizeZoom) {
269
+ this.hiddenNodeIds.push(...newHiddenNodeIds);
270
+ } else {
271
+ this.hiddenNodeIds = newHiddenNodeIds;
272
+ }
273
+ }
274
+ }
275
+ private showShapes() {
276
+ const { graph, hiddenEdgeIds, hiddenNodeIds } = this;
277
+ const currentZoom = graph.getZoom();
278
+ const { optimizeZoom } = this.options;
279
+
280
+ // hide the shapes when the zoom ratio is smaller than optimizeZoom
281
+ // hide the shapes when zoomming
282
+ if (currentZoom < optimizeZoom) {
283
+ return;
284
+ }
285
+
286
+ const { tileBehavior: graphBehaviorOptimize, tileBehaviorSize = 1000 } =
287
+ graph.getSpecification().optimize || {};
288
+ const optimize = this.options.enableOptimize || graphBehaviorOptimize;
289
+ const shouldOptimzie = isNumber(optimize)
290
+ ? graph.getAllNodesData().length > optimize
291
+ : optimize;
292
+ if (!shouldOptimzie) {
293
+ this.hiddenEdgeIds = this.hiddenNodeIds = [];
294
+ return;
295
+ }
296
+
297
+ let requestId;
298
+ const hiddenIds = [...hiddenNodeIds, ...hiddenEdgeIds];
299
+ const sectionNum = Math.ceil(hiddenIds.length / tileBehaviorSize);
300
+ const sections = Array.from({ length: sectionNum }, (v, i) =>
301
+ hiddenIds.slice(
302
+ i * tileBehaviorSize,
303
+ i * tileBehaviorSize + tileBehaviorSize,
304
+ ),
305
+ );
306
+ const update = () => {
307
+ if (!sections.length) {
308
+ cancelAnimationFrame(requestId);
309
+ return;
310
+ }
311
+ graph.executeWithNoStack(() => {
312
+ graph.showItem(sections.shift(), false);
313
+ });
314
+ requestId = requestAnimationFrame(update);
315
+ };
316
+ requestId = requestAnimationFrame(update);
317
+
318
+ this.hiddenEdgeIds = this.hiddenNodeIds = [];
319
+ }
320
+ }
321
+
322
+ const ALLOW_EVENTS = ['shift', 'ctrl', 'alt', 'control', 'meta'];
323
+
324
+ function initZoomKey(zoomKey?: string | string[]) {
325
+ const zoomKeys = zoomKey
326
+ ? Array.isArray(zoomKey)
327
+ ? zoomKey
328
+ : [zoomKey]
329
+ : [];
330
+
331
+ const validZoomKeys = zoomKeys.filter((zoomKey) => {
332
+ const keyIsValid = ALLOW_EVENTS.includes(zoomKey);
333
+ if (!keyIsValid)
334
+ console.warn(
335
+ `Invalid zoomKey: ${zoomKey}, please use a valid zoomKey: ${JSON.stringify(
336
+ ALLOW_EVENTS,
337
+ )}`,
338
+ );
339
+
340
+ return keyIsValid;
341
+ });
342
+
343
+ if (validZoomKeys.length === 0) {
344
+ validZoomKeys.push('ctrl');
345
+ }
346
+
347
+ return validZoomKeys;
348
+ }
@@ -1,4 +1,5 @@
1
- import { ID, IG6GraphEvent } from 'types';
1
+ import { isNumber } from '@antv/util';
2
+ import { ID, IG6GraphEvent } from '../../types';
2
3
  import { Behavior } from '../../types/behavior';
3
4
 
4
5
  const VALID_TRIGGERS = ['wheel', 'upDownKeys'];
@@ -56,7 +57,7 @@ export interface ZoomCanvasOptions {
56
57
  }
57
58
 
58
59
  const DEFAULT_OPTIONS: Required<ZoomCanvasOptions> = {
59
- enableOptimize: false,
60
+ enableOptimize: undefined,
60
61
  triggerOnItems: true,
61
62
  sensitivity: 2,
62
63
  trigger: 'wheel',
@@ -114,43 +115,78 @@ export class ZoomCanvas extends Behavior {
114
115
 
115
116
  private hideShapes() {
116
117
  const { graph } = this;
117
- if (this.options.enableOptimize) {
118
+ const { tileBehavior: graphBehaviorOptimize, tileBehaviorSize = 1000 } =
119
+ graph.getSpecification().optimize || {};
120
+ const optimize = this.options.enableOptimize || graphBehaviorOptimize;
121
+ const shouldOptimzie = isNumber(optimize)
122
+ ? graph.getAllNodesData().length > optimize
123
+ : optimize;
124
+ if (shouldOptimzie) {
118
125
  this.hiddenEdgeIds = graph
119
126
  .getAllEdgesData()
120
127
  .map((edge) => edge.id)
121
128
  .filter((id) => graph.getItemVisible(id) === true);
122
- // TODO
123
- graph.hideItem(this.hiddenEdgeIds, false);
124
129
  this.hiddenNodeIds = graph
125
130
  .getAllNodesData()
126
131
  .map((node) => node.id)
127
132
  .filter((id) => graph.getItemVisible(id) === true);
128
- // draw node's keyShapes on transient, and then hidden the real nodes;
129
- // this.hiddenNodeIds.forEach((id) => {
130
- // graph.drawTransient('node', id, {
131
- // onlyDrawKeyShape: true,
132
- // });
133
- // });
134
- // graph.hideItem(this.hiddenNodeIds, false);
133
+
134
+ let requestId;
135
+ const hiddenIds = [...this.hiddenNodeIds];
136
+ const sectionNum = Math.ceil(hiddenIds.length / tileBehaviorSize);
137
+ const sections = Array.from({ length: sectionNum }, (v, i) =>
138
+ hiddenIds.slice(
139
+ i * tileBehaviorSize,
140
+ i * tileBehaviorSize + tileBehaviorSize,
141
+ ),
142
+ );
143
+ const update = () => {
144
+ if (!sections.length) {
145
+ cancelAnimationFrame(requestId);
146
+ return;
147
+ }
148
+ const section = sections.shift();
149
+ graph.startHistoryBatch();
150
+ graph.hideItem(section, false, true);
151
+ graph.stopHistoryBatch();
152
+ requestId = requestAnimationFrame(update);
153
+ };
154
+ requestId = requestAnimationFrame(update);
135
155
  }
136
156
  }
137
157
 
138
158
  private endZoom() {
139
- const { graph, hiddenEdgeIds, hiddenNodeIds } = this;
140
- const { enableOptimize } = this.options;
159
+ const { graph, hiddenEdgeIds = [], hiddenNodeIds } = this;
160
+ const { tileBehavior: graphBehaviorOptimize, tileBehaviorSize = 1000 } =
161
+ graph.getSpecification().optimize || {};
162
+ const optimize = this.options.enableOptimize || graphBehaviorOptimize;
163
+ const shouldOptimzie = isNumber(optimize)
164
+ ? graph.getAllNodesData().length > optimize
165
+ : optimize;
141
166
  this.zooming = false;
142
- if (enableOptimize) {
143
- // restore hidden items
144
- if (hiddenEdgeIds) {
145
- graph.showItem(hiddenEdgeIds, false);
167
+ if (shouldOptimzie) {
168
+ if (hiddenNodeIds) {
169
+ let requestId;
170
+ const hiddenIds = [...hiddenNodeIds, ...hiddenEdgeIds];
171
+ const sectionNum = Math.ceil(hiddenIds.length / tileBehaviorSize);
172
+ const sections = Array.from({ length: sectionNum }, (v, i) =>
173
+ hiddenIds.slice(
174
+ i * tileBehaviorSize,
175
+ i * tileBehaviorSize + tileBehaviorSize,
176
+ ),
177
+ );
178
+ const update = () => {
179
+ if (!sections.length) {
180
+ cancelAnimationFrame(requestId);
181
+ return;
182
+ }
183
+ graph.executeWithNoStack(() => {
184
+ graph.showItem(sections.shift(), false);
185
+ });
186
+ requestId = requestAnimationFrame(update);
187
+ };
188
+ requestId = requestAnimationFrame(update);
146
189
  }
147
- // TODO
148
- // if (hiddenNodeIds) {
149
- // hiddenNodeIds.forEach((id) => {
150
- // graph.drawTransient('node', id, { action: 'remove' });
151
- // });
152
- // graph.showItem(hiddenNodeIds, false);
153
- // }
154
190
  }
155
191
  this.hiddenEdgeIds = [];
156
192
  this.hiddenNodeIds = [];
@@ -61,7 +61,9 @@ const {
61
61
  DragNode,
62
62
  DragCombo,
63
63
  ClickSelect,
64
+ CreateEdge,
64
65
  ShortcutsCall,
66
+ ScrollCanvas,
65
67
  } = Behaviors;
66
68
  const {
67
69
  History,
@@ -73,6 +75,7 @@ const {
73
75
  Legend,
74
76
  Toolbar,
75
77
  Timebar,
78
+ Snapline,
76
79
  } = Plugins;
77
80
 
78
81
  const {
@@ -120,9 +123,11 @@ const stdLib = {
120
123
  'zoom-canvas': ZoomCanvas,
121
124
  'drag-node': DragNode,
122
125
  'drag-combo': DragCombo,
126
+ 'create-edge': CreateEdge,
123
127
  'collapse-expand-combo': CollapseExpandCombo,
124
128
  'collapse-expand-tree': CollapseExpandTree,
125
129
  'click-select': ClickSelect,
130
+ 'scroll-canvas': ScrollCanvas,
126
131
  },
127
132
  plugins: {
128
133
  history: History,
@@ -134,6 +139,7 @@ const stdLib = {
134
139
  },
135
140
  edges: {
136
141
  'line-edge': LineEdge,
142
+ 'loop-edge': LoopEdge,
137
143
  },
138
144
  combos: {
139
145
  'circle-combo': CircleCombo,
@@ -206,13 +212,13 @@ const Extensions = {
206
212
  ValidateData,
207
213
  TransformV4Data,
208
214
  MapNodeSize,
209
- //themes
215
+ // themes
210
216
  LightTheme,
211
217
  DarkTheme,
212
- //themeSolvers
218
+ // themeSolvers
213
219
  SpecThemeSolver,
214
220
  SubjectThemeSolver,
215
- //layout
221
+ // layout
216
222
  ForceLayout,
217
223
  GridLayout,
218
224
  CircularLayout,
@@ -225,12 +231,12 @@ const Extensions = {
225
231
  ForceAtlas2Layout,
226
232
  DagreLayout,
227
233
  ComboCombinedLayout,
228
- //Hierarchy
234
+ // Hierarchy
229
235
  compactBox,
230
236
  dendrogram,
231
237
  indented,
232
238
  mindmap,
233
- //nodes
239
+ // nodes
234
240
  CircleNode,
235
241
  RectNode,
236
242
  DiamondNode,
@@ -252,7 +258,7 @@ const Extensions = {
252
258
  // combos
253
259
  CircleCombo,
254
260
  RectCombo,
255
- //behaviors
261
+ // behaviors
256
262
  BaseBehavior,
257
263
  ActivateRelations,
258
264
  BrushSelect,
@@ -268,7 +274,9 @@ const Extensions = {
268
274
  CollapseExpandCombo,
269
275
  DragNode,
270
276
  DragCombo,
271
- //plugins
277
+ CreateEdge,
278
+ ShortcutsCall,
279
+ // plugins
272
280
  BasePlugin,
273
281
  History,
274
282
  Toolbar,
@@ -280,6 +288,7 @@ const Extensions = {
280
288
  Legend,
281
289
  Timebar,
282
290
  Hull,
291
+ Snapline,
283
292
  };
284
293
 
285
294
  export default registery;
@@ -550,7 +550,11 @@ export abstract class BaseEdge {
550
550
  * @param shapeMap The shape map that contains all of the elements to show on the edge.
551
551
  * @param zoom The zoom level of the graph.
552
552
  */
553
- public onZoom = (shapeMap: EdgeShapeMap, zoom: number) => {
553
+ public onZoom = (
554
+ shapeMap: EdgeShapeMap,
555
+ zoom: number,
556
+ cacheHiddenShape = {},
557
+ ) => {
554
558
  // balance the size for label, badges
555
559
  this.balanceShapeSize(shapeMap, zoom);
556
560
 
@@ -574,7 +578,10 @@ export abstract class BaseEdge {
574
578
  // zoomLevel changed, from higher to lower, hide something
575
579
  if (firstRender) {
576
580
  for (let i = currentLevel + 1; i <= maxLevel; i++) {
577
- levelShapes[String(i)]?.forEach((id) => shapeMap[id]?.hide());
581
+ levelShapes[String(i)]?.forEach((id) => {
582
+ if (!shapeMap[id] || cacheHiddenShape[id]) return;
583
+ shapeMap[id]?.hide();
584
+ });
578
585
  }
579
586
  } else {
580
587
  for (let i = currentLevel + 1; i <= maxLevel; i++) {
@@ -586,7 +593,8 @@ export abstract class BaseEdge {
586
593
  } else if (currentLevel > previousLevel) {
587
594
  // zoomLevel changed, from lower to higher, show something
588
595
  for (let i = currentLevel; i >= minLevel; i--) {
589
- levelShapes[String(i)]?.forEach((id) =>
596
+ levelShapes[String(i)]?.forEach((id) => {
597
+ if (hiddenShape[id]) return;
590
598
  fadeIn(
591
599
  id,
592
600
  shapeMap[id],
@@ -594,8 +602,8 @@ export abstract class BaseEdge {
594
602
  this.mergedStyles[id.replace('Background', '')],
595
603
  hiddenShape,
596
604
  animateConfig,
597
- ),
598
- );
605
+ );
606
+ });
599
607
  }
600
608
  }
601
609