@antv/g6 5.0.0-beta.20 → 5.0.0-beta.21

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 (184) hide show
  1. package/dist/g6.min.js +2 -2
  2. package/esm/index.d.ts +16 -9
  3. package/esm/index.js +1 -1
  4. package/esm/runtime/controller/data.d.ts +27 -10
  5. package/esm/runtime/controller/data.js +240 -216
  6. package/esm/runtime/controller/data.js.map +1 -1
  7. package/esm/stdlib/behavior/activate-relations.d.ts +1 -1
  8. package/esm/stdlib/behavior/brush-select.d.ts +2 -2
  9. package/esm/stdlib/behavior/click-select.d.ts +1 -1
  10. package/esm/stdlib/behavior/collapse-expand-combo.d.ts +1 -1
  11. package/esm/stdlib/behavior/collapse-expand-tree.d.ts +1 -1
  12. package/esm/stdlib/behavior/drag-canvas.js +1 -1
  13. package/esm/stdlib/behavior/drag-combo.d.ts +1 -1
  14. package/esm/stdlib/behavior/drag-node.d.ts +1 -1
  15. package/esm/stdlib/behavior/shortcuts-call.d.ts +1 -1
  16. package/esm/stdlib/behavior/zoom-canvas.js +1 -1
  17. package/esm/stdlib/data/index.d.ts +1 -0
  18. package/esm/stdlib/data/index.js +1 -0
  19. package/esm/stdlib/data/index.js.map +1 -1
  20. package/esm/stdlib/data/mapNodeSize.d.ts +3 -4
  21. package/esm/stdlib/data/mapNodeSize.js +10 -0
  22. package/esm/stdlib/data/mapNodeSize.js.map +1 -1
  23. package/esm/stdlib/data/processParallelEdges.d.ts +21 -0
  24. package/esm/stdlib/data/processParallelEdges.js +127 -0
  25. package/esm/stdlib/data/processParallelEdges.js.map +1 -0
  26. package/esm/stdlib/data/transformV4Data.d.ts +2 -3
  27. package/esm/stdlib/data/transformV4Data.js +8 -0
  28. package/esm/stdlib/data/transformV4Data.js.map +1 -1
  29. package/esm/stdlib/data/validateData.d.ts +3 -4
  30. package/esm/stdlib/data/validateData.js +9 -1
  31. package/esm/stdlib/data/validateData.js.map +1 -1
  32. package/esm/stdlib/index.d.ts +15 -8
  33. package/esm/stdlib/index.js +2 -1
  34. package/esm/stdlib/index.js.map +1 -1
  35. package/esm/stdlib/item/node/donut.d.ts +3 -3
  36. package/esm/stdlib/plugin/hull/hullComponent.d.ts +1 -1
  37. package/esm/stdlib/plugin/legend/index.d.ts +1 -1
  38. package/esm/stdlib/plugin/snapline/index.d.ts +2 -2
  39. package/esm/stdlib/plugin/snapline/index.js +239 -239
  40. package/esm/stdlib/plugin/snapline/index.js.map +1 -1
  41. package/esm/stdlib/plugin/timebar/index.d.ts +4 -4
  42. package/esm/stdlib/plugin/timebar/index.js +4 -4
  43. package/esm/stdlib/plugin/timebar/index.js.map +1 -1
  44. package/esm/stdlib/plugin/tooltip/index.d.ts +1 -1
  45. package/esm/stdlib/plugin/watermaker/index.d.ts +1 -1
  46. package/esm/types/animate.d.ts +2 -2
  47. package/esm/types/behavior.d.ts +1 -1
  48. package/esm/types/combo.d.ts +7 -7
  49. package/esm/types/common.d.ts +5 -5
  50. package/esm/types/data.d.ts +11 -6
  51. package/esm/types/edge.d.ts +9 -9
  52. package/esm/types/event.d.ts +1 -1
  53. package/esm/types/history.d.ts +2 -2
  54. package/esm/types/hook.d.ts +1 -1
  55. package/esm/types/item.d.ts +13 -13
  56. package/esm/types/item.js.map +1 -1
  57. package/esm/types/layout.d.ts +6 -6
  58. package/esm/types/loop.d.ts +2 -2
  59. package/esm/types/node.d.ts +7 -7
  60. package/esm/types/render.d.ts +1 -1
  61. package/esm/types/spec.d.ts +4 -3
  62. package/esm/types/stdlib.d.ts +1 -1
  63. package/esm/types/theme.d.ts +8 -8
  64. package/esm/types/view.d.ts +2 -2
  65. package/esm/util/array.d.ts +1 -0
  66. package/esm/util/array.js +3 -0
  67. package/esm/util/array.js.map +1 -1
  68. package/esm/util/data.d.ts +3 -0
  69. package/esm/util/data.js +15 -0
  70. package/esm/util/data.js.map +1 -1
  71. package/esm/util/event.d.ts +2 -2
  72. package/esm/util/layout.d.ts +1 -1
  73. package/esm/util/loop.d.ts +1 -0
  74. package/esm/util/loop.js +10 -0
  75. package/esm/util/loop.js.map +1 -1
  76. package/esm/util/shape.d.ts +2 -1
  77. package/esm/util/shape.js +2 -1
  78. package/esm/util/shape.js.map +1 -1
  79. package/esm/util/shape3d.d.ts +1 -1
  80. package/esm/util/warn.d.ts +1 -1
  81. package/lib/index.d.ts +16 -9
  82. package/lib/index.js +1 -1
  83. package/lib/runtime/controller/data.d.ts +27 -10
  84. package/lib/runtime/controller/data.js +238 -214
  85. package/lib/runtime/controller/data.js.map +1 -1
  86. package/lib/stdlib/behavior/activate-relations.d.ts +1 -1
  87. package/lib/stdlib/behavior/brush-select.d.ts +2 -2
  88. package/lib/stdlib/behavior/click-select.d.ts +1 -1
  89. package/lib/stdlib/behavior/collapse-expand-combo.d.ts +1 -1
  90. package/lib/stdlib/behavior/collapse-expand-tree.d.ts +1 -1
  91. package/lib/stdlib/behavior/drag-canvas.js +1 -1
  92. package/lib/stdlib/behavior/drag-combo.d.ts +1 -1
  93. package/lib/stdlib/behavior/drag-node.d.ts +1 -1
  94. package/lib/stdlib/behavior/shortcuts-call.d.ts +1 -1
  95. package/lib/stdlib/behavior/zoom-canvas.js +1 -1
  96. package/lib/stdlib/data/index.d.ts +1 -0
  97. package/lib/stdlib/data/index.js +1 -0
  98. package/lib/stdlib/data/index.js.map +1 -1
  99. package/lib/stdlib/data/mapNodeSize.d.ts +3 -4
  100. package/lib/stdlib/data/mapNodeSize.js +11 -1
  101. package/lib/stdlib/data/mapNodeSize.js.map +1 -1
  102. package/lib/stdlib/data/processParallelEdges.d.ts +21 -0
  103. package/lib/stdlib/data/processParallelEdges.js +131 -0
  104. package/lib/stdlib/data/processParallelEdges.js.map +1 -0
  105. package/lib/stdlib/data/transformV4Data.d.ts +2 -3
  106. package/lib/stdlib/data/transformV4Data.js +9 -1
  107. package/lib/stdlib/data/transformV4Data.js.map +1 -1
  108. package/lib/stdlib/data/validateData.d.ts +3 -4
  109. package/lib/stdlib/data/validateData.js +10 -2
  110. package/lib/stdlib/data/validateData.js.map +1 -1
  111. package/lib/stdlib/index.d.ts +15 -8
  112. package/lib/stdlib/index.js +2 -1
  113. package/lib/stdlib/index.js.map +1 -1
  114. package/lib/stdlib/item/node/donut.d.ts +3 -3
  115. package/lib/stdlib/plugin/hull/hullComponent.d.ts +1 -1
  116. package/lib/stdlib/plugin/legend/index.d.ts +1 -1
  117. package/lib/stdlib/plugin/snapline/index.d.ts +2 -2
  118. package/lib/stdlib/plugin/snapline/index.js +239 -239
  119. package/lib/stdlib/plugin/snapline/index.js.map +1 -1
  120. package/lib/stdlib/plugin/timebar/index.d.ts +4 -4
  121. package/lib/stdlib/plugin/timebar/index.js +4 -4
  122. package/lib/stdlib/plugin/timebar/index.js.map +1 -1
  123. package/lib/stdlib/plugin/tooltip/index.d.ts +1 -1
  124. package/lib/stdlib/plugin/watermaker/index.d.ts +1 -1
  125. package/lib/types/animate.d.ts +2 -2
  126. package/lib/types/behavior.d.ts +1 -1
  127. package/lib/types/combo.d.ts +7 -7
  128. package/lib/types/common.d.ts +5 -5
  129. package/lib/types/data.d.ts +11 -6
  130. package/lib/types/edge.d.ts +9 -9
  131. package/lib/types/event.d.ts +1 -1
  132. package/lib/types/event.js +2 -2
  133. package/lib/types/event.js.map +1 -1
  134. package/lib/types/history.d.ts +2 -2
  135. package/lib/types/history.js +1 -1
  136. package/lib/types/history.js.map +1 -1
  137. package/lib/types/hook.d.ts +1 -1
  138. package/lib/types/item.d.ts +13 -13
  139. package/lib/types/item.js +1 -1
  140. package/lib/types/item.js.map +1 -1
  141. package/lib/types/layout.d.ts +6 -6
  142. package/lib/types/loop.d.ts +2 -2
  143. package/lib/types/loop.js +1 -1
  144. package/lib/types/loop.js.map +1 -1
  145. package/lib/types/node.d.ts +7 -7
  146. package/lib/types/render.d.ts +1 -1
  147. package/lib/types/spec.d.ts +4 -3
  148. package/lib/types/stdlib.d.ts +1 -1
  149. package/lib/types/theme.d.ts +8 -8
  150. package/lib/types/view.d.ts +2 -2
  151. package/lib/util/array.d.ts +1 -0
  152. package/lib/util/array.js +5 -1
  153. package/lib/util/array.js.map +1 -1
  154. package/lib/util/data.d.ts +3 -0
  155. package/lib/util/data.js +16 -1
  156. package/lib/util/data.js.map +1 -1
  157. package/lib/util/event.d.ts +2 -2
  158. package/lib/util/layout.d.ts +1 -1
  159. package/lib/util/loop.d.ts +1 -0
  160. package/lib/util/loop.js +11 -1
  161. package/lib/util/loop.js.map +1 -1
  162. package/lib/util/shape.d.ts +2 -1
  163. package/lib/util/shape.js +1 -0
  164. package/lib/util/shape.js.map +1 -1
  165. package/lib/util/shape3d.d.ts +1 -1
  166. package/lib/util/warn.d.ts +1 -1
  167. package/package.json +3 -3
  168. package/src/index.ts +1 -1
  169. package/src/runtime/controller/data.ts +309 -229
  170. package/src/stdlib/behavior/drag-canvas.ts +1 -1
  171. package/src/stdlib/behavior/zoom-canvas.ts +1 -1
  172. package/src/stdlib/data/index.ts +1 -0
  173. package/src/stdlib/data/mapNodeSize.ts +20 -1
  174. package/src/stdlib/data/processParallelEdges.ts +203 -0
  175. package/src/stdlib/data/transformV4Data.ts +14 -1
  176. package/src/stdlib/data/validateData.ts +16 -2
  177. package/src/stdlib/index.ts +3 -1
  178. package/src/types/data.ts +6 -0
  179. package/src/types/item.ts +2 -1
  180. package/src/types/spec.ts +1 -0
  181. package/src/util/array.ts +12 -0
  182. package/src/util/data.ts +24 -1
  183. package/src/util/loop.ts +11 -0
  184. package/src/util/shape.ts +1 -0
@@ -4,245 +4,6 @@ exports.Snapline = void 0;
4
4
  const util_1 = require("@antv/util");
5
5
  const plugin_1 = require("../../../types/plugin");
6
6
  class Snapline extends plugin_1.Plugin {
7
- constructor(options) {
8
- super(options);
9
- //#region state: historyPoints
10
- this.historyPoints = [
11
- undefined,
12
- undefined,
13
- ];
14
- /**
15
- * when start drag, offset of cursor and node center (event.canvas - draggingnode.BBox)
16
- */
17
- this.initialOffset = [undefined, undefined];
18
- /**
19
- * Cache the nodes' positions to be throttly updated.
20
- */
21
- this.updateCache = new Map();
22
- /**
23
- * Gets the current cursor node and center offset and then with initialOffset difference
24
- */
25
- this.getCurOffsetCompareToInitialOffset = (e) => {
26
- if (this.initialOffset[0] === undefined ||
27
- this.initialOffset[1] === undefined) {
28
- return [undefined, undefined];
29
- }
30
- const curOffset = [
31
- e.canvas.x - this.draggingBBox.center[0],
32
- e.canvas.y - this.draggingBBox.center[1],
33
- ];
34
- return [
35
- curOffset[0] - this.initialOffset[0],
36
- curOffset[1] - this.initialOffset[1],
37
- ];
38
- };
39
- this.dragging = false;
40
- this.draggingBBox = undefined;
41
- // Gets the offset between the cursor and draggingItem
42
- this.getPointerOffsetWithItem = (pointer) => {
43
- return {
44
- x: Math.abs(pointer.x - this.draggingBBox.center[0]),
45
- y: Math.abs(pointer.x - this.draggingBBox.center[1]),
46
- };
47
- };
48
- //#region state: tolerance
49
- this.tolerance = 4;
50
- this.toleranceFactor = 2;
51
- //#endregion
52
- // All the lines in the vertical direction
53
- this.vContrastPoints = [];
54
- this.hContrastPoints = [];
55
- /**
56
- * alignLinesForChoose container
57
- */
58
- this.alignLinesForChoose = { v: [], h: [] };
59
- /**
60
- * v and h direction adsorption state
61
- */
62
- this.isAdsorbed = [false, false]; // whether the adsorption state
63
- this.dragEvent = undefined; // drag event
64
- // use dragItemId and dragItemType to avoid object changing when dragging
65
- this.dragItemId = undefined;
66
- this.dragItemType = undefined;
67
- /**
68
- * Historical adsorption region: v and h directions
69
- * x0 ~ x1: Represents the starting and ending line in the v direction
70
- * y0 ~ y1: Represents the starting and ending line in the h direction
71
- *
72
- * When the cursor moves out of this region && non-adsorbed state => set to undefined
73
- */
74
- this.historyAbsorbArea = [undefined, undefined];
75
- /**
76
- * Unable to adsorb: countdown
77
- */
78
- this.canAdsorbCount = 0;
79
- /**
80
- * Countdown method: Countdown
81
- */
82
- this.canAdsorbCountDown = () => {
83
- if (this.canAdsorbCount > 0) {
84
- const intervalID = setInterval(() => {
85
- this.canAdsorbCount--;
86
- if (this.canAdsorbCount <= 0) {
87
- clearTimeout(intervalID);
88
- }
89
- }, 100);
90
- }
91
- };
92
- this.onDrag = (0, util_1.throttle)(((event) => {
93
- var _a, _b, _c, _d, _e, _f, _g, _h;
94
- this.dragEvent = event;
95
- this.initAlignLinesForChoose();
96
- // control layer: Check to delete existing line & drawed line & adsorption
97
- // set historyPoints
98
- this.historyPoints[0] = this.historyPoints[1];
99
- this.historyPoints[1] = { x: event.canvas.x, y: event.canvas.y };
100
- let vlp = undefined;
101
- let vline = undefined;
102
- let hlp = undefined;
103
- let hline = undefined;
104
- // v direction: whether keep adsorption
105
- const checkVShouldHoldAbsorb = (vlp, vline) => {
106
- // v direction: continue to adsorb
107
- const vShouldAbsorb = Math.abs(this.getCurOffsetCompareToInitialOffset(event)[0]) <=
108
- this.tolerance * this.toleranceFactor;
109
- if (vShouldAbsorb) {
110
- if (vlp === 'left') {
111
- this.doUpdatePosition({
112
- x: vline[0].x + this.draggingBBox.halfExtents[0],
113
- });
114
- }
115
- else if (vlp === 'vcenter') {
116
- this.doUpdatePosition({
117
- x: vline[0].x,
118
- });
119
- }
120
- else if (vlp === 'right') {
121
- this.doUpdatePosition({
122
- fx: vline[0].x - this.draggingBBox.halfExtents[0],
123
- });
124
- }
125
- // updarte align line when absorb
126
- this.updateAlignLineWhenAbsorb([true, false]);
127
- }
128
- else {
129
- // cancel absorb
130
- // 1.update positon
131
- this.doUpdatePosition({ fx: undefined });
132
- // 2.remove align line && update state
133
- this.removeAlignLine([true, undefined]);
134
- // count down to be adsorbable
135
- this.canAdsorbCount = 10; // 1s
136
- this.canAdsorbCountDown();
137
- }
138
- };
139
- // h direction: whether keep adsorption
140
- const checkHShouldHoldAbsorb = (hlp, hline) => {
141
- // h direction: continue to adsorb
142
- const hShouldAbsorb = Math.abs(this.getCurOffsetCompareToInitialOffset(event)[1]) <=
143
- this.tolerance * this.toleranceFactor;
144
- if (hShouldAbsorb) {
145
- if (hlp === 'top') {
146
- this.doUpdatePosition({
147
- fy: hline[0].y + this.draggingBBox.halfExtents[1],
148
- });
149
- }
150
- else if (hlp === 'hcenter') {
151
- this.doUpdatePosition({
152
- fy: hline[0].y,
153
- });
154
- }
155
- else if (hlp === 'bottom') {
156
- this.doUpdatePosition({
157
- fy: hline[0].y - this.draggingBBox.halfExtents[1],
158
- });
159
- }
160
- // update align line
161
- this.updateAlignLineWhenAbsorb([false, true]);
162
- }
163
- else {
164
- // 1.update position
165
- this.doUpdatePosition({ fy: undefined });
166
- // 2.remove align line && update state
167
- this.removeAlignLine([undefined, true]);
168
- // count down to be adsorbable
169
- this.canAdsorbCount = 10; // 1s
170
- this.canAdsorbCountDown();
171
- }
172
- };
173
- // v direction: whether adsorbed
174
- const checkVShouldAbsorb = () => {
175
- const ret = this.canDrawLine();
176
- // If in recent from adsorption area, can't immediately draw lines (must be removed from the area to reline this area)
177
- if (ret) {
178
- // draw align lines
179
- this.drawAlignLines({ vdl: ret.vdl, hdl: undefined });
180
- // absorb dragging box
181
- this.absorb({ vdl: ret.vdl, hdl: undefined });
182
- }
183
- };
184
- // h direction: whether adsorbed
185
- const checkHShouldAbsorb = () => {
186
- const ret = this.canDrawLine();
187
- // If in recent from adsorption area, can't immediately draw lines (must be removed from the area to reline this area)
188
- if (ret) {
189
- // draw align lines
190
- this.drawAlignLines({ vdl: undefined, hdl: ret.hdl });
191
- // absorb dragging box
192
- this.absorb({ vdl: undefined, hdl: ret.hdl });
193
- }
194
- };
195
- // 1、the current state of the two directions are adsorption
196
- if (this.isAdsorbed[0] && this.isAdsorbed[1]) {
197
- vlp = (_a = this.drawedLines[0].dl) === null || _a === void 0 ? void 0 : _a.lp;
198
- vline = (_b = this.drawedLines[0].dl) === null || _b === void 0 ? void 0 : _b.line;
199
- hlp = (_c = this.drawedLines[1].dl) === null || _c === void 0 ? void 0 : _c.lp;
200
- hline = (_d = this.drawedLines[1].dl) === null || _d === void 0 ? void 0 : _d.line;
201
- checkVShouldHoldAbsorb(vlp, vline);
202
- checkHShouldHoldAbsorb(hlp, hline);
203
- }
204
- else if (this.isAdsorbed[0] && !this.isAdsorbed[1]) {
205
- // 2、currently, only the v direction is adsorbed
206
- vlp = (_e = this.drawedLines[0].dl) === null || _e === void 0 ? void 0 : _e.lp;
207
- vline = (_f = this.drawedLines[0].dl) === null || _f === void 0 ? void 0 : _f.line;
208
- checkVShouldHoldAbsorb(vlp, vline);
209
- checkHShouldAbsorb();
210
- }
211
- else if (!this.isAdsorbed[0] && this.isAdsorbed[1]) {
212
- // 3、currently, only the h direction is adsorbed
213
- hlp = (_g = this.drawedLines[1].dl) === null || _g === void 0 ? void 0 : _g.lp;
214
- hline = (_h = this.drawedLines[1].dl) === null || _h === void 0 ? void 0 : _h.line;
215
- checkHShouldHoldAbsorb(vlp, vline);
216
- checkVShouldAbsorb();
217
- }
218
- else if (!this.isAdsorbed[0] && !this.isAdsorbed[1]) {
219
- // 4、currently, v and h directions are not adsorbed
220
- const ret = this.canDrawLine();
221
- // If you have recently detached from the attachment area, you cannot draw the line immediately (you need to remove the detached area to redraw the area)
222
- if (ret) {
223
- // draw align lines
224
- this.drawAlignLines(ret);
225
- // absorb dragging box
226
- this.absorb(ret);
227
- }
228
- }
229
- }).bind(this), 16, {
230
- leading: false,
231
- trailing: true,
232
- });
233
- //#region draw/remove lines
234
- // first:v direction; second:h direction;
235
- // ddo: drawed DisplayObject, dl: DrawLine
236
- this.drawedLines = [undefined, undefined];
237
- this.throttleUpdate = (0, util_1.throttle)(() => {
238
- this.graph.updateNodePosition(Array.from(this.updateCache.values()), false, true);
239
- this.updateCache.clear();
240
- }, 16, {
241
- leading: true,
242
- trailing: true,
243
- });
244
- this.init(options.graph);
245
- }
246
7
  setTolerance(tolerance) {
247
8
  this.tolerance = tolerance;
248
9
  }
@@ -729,6 +490,245 @@ class Snapline extends plugin_1.Plugin {
729
490
  h: hMaxDL ? hMaxDL.dl : undefined,
730
491
  };
731
492
  }
493
+ constructor(options) {
494
+ super(options);
495
+ //#region state: historyPoints
496
+ this.historyPoints = [
497
+ undefined,
498
+ undefined,
499
+ ];
500
+ /**
501
+ * when start drag, offset of cursor and node center (event.canvas - draggingnode.BBox)
502
+ */
503
+ this.initialOffset = [undefined, undefined];
504
+ /**
505
+ * Cache the nodes' positions to be throttly updated.
506
+ */
507
+ this.updateCache = new Map();
508
+ /**
509
+ * Gets the current cursor node and center offset and then with initialOffset difference
510
+ */
511
+ this.getCurOffsetCompareToInitialOffset = (e) => {
512
+ if (this.initialOffset[0] === undefined ||
513
+ this.initialOffset[1] === undefined) {
514
+ return [undefined, undefined];
515
+ }
516
+ const curOffset = [
517
+ e.canvas.x - this.draggingBBox.center[0],
518
+ e.canvas.y - this.draggingBBox.center[1],
519
+ ];
520
+ return [
521
+ curOffset[0] - this.initialOffset[0],
522
+ curOffset[1] - this.initialOffset[1],
523
+ ];
524
+ };
525
+ this.dragging = false;
526
+ this.draggingBBox = undefined;
527
+ // Gets the offset between the cursor and draggingItem
528
+ this.getPointerOffsetWithItem = (pointer) => {
529
+ return {
530
+ x: Math.abs(pointer.x - this.draggingBBox.center[0]),
531
+ y: Math.abs(pointer.x - this.draggingBBox.center[1]),
532
+ };
533
+ };
534
+ //#region state: tolerance
535
+ this.tolerance = 4;
536
+ this.toleranceFactor = 2;
537
+ //#endregion
538
+ // All the lines in the vertical direction
539
+ this.vContrastPoints = [];
540
+ this.hContrastPoints = [];
541
+ /**
542
+ * alignLinesForChoose container
543
+ */
544
+ this.alignLinesForChoose = { v: [], h: [] };
545
+ /**
546
+ * v and h direction adsorption state
547
+ */
548
+ this.isAdsorbed = [false, false]; // whether the adsorption state
549
+ this.dragEvent = undefined; // drag event
550
+ // use dragItemId and dragItemType to avoid object changing when dragging
551
+ this.dragItemId = undefined;
552
+ this.dragItemType = undefined;
553
+ /**
554
+ * Historical adsorption region: v and h directions
555
+ * x0 ~ x1: Represents the starting and ending line in the v direction
556
+ * y0 ~ y1: Represents the starting and ending line in the h direction
557
+ *
558
+ * When the cursor moves out of this region && non-adsorbed state => set to undefined
559
+ */
560
+ this.historyAbsorbArea = [undefined, undefined];
561
+ /**
562
+ * Unable to adsorb: countdown
563
+ */
564
+ this.canAdsorbCount = 0;
565
+ /**
566
+ * Countdown method: Countdown
567
+ */
568
+ this.canAdsorbCountDown = () => {
569
+ if (this.canAdsorbCount > 0) {
570
+ const intervalID = setInterval(() => {
571
+ this.canAdsorbCount--;
572
+ if (this.canAdsorbCount <= 0) {
573
+ clearTimeout(intervalID);
574
+ }
575
+ }, 100);
576
+ }
577
+ };
578
+ this.onDrag = (0, util_1.throttle)(((event) => {
579
+ var _a, _b, _c, _d, _e, _f, _g, _h;
580
+ this.dragEvent = event;
581
+ this.initAlignLinesForChoose();
582
+ // control layer: Check to delete existing line & drawed line & adsorption
583
+ // set historyPoints
584
+ this.historyPoints[0] = this.historyPoints[1];
585
+ this.historyPoints[1] = { x: event.canvas.x, y: event.canvas.y };
586
+ let vlp = undefined;
587
+ let vline = undefined;
588
+ let hlp = undefined;
589
+ let hline = undefined;
590
+ // v direction: whether keep adsorption
591
+ const checkVShouldHoldAbsorb = (vlp, vline) => {
592
+ // v direction: continue to adsorb
593
+ const vShouldAbsorb = Math.abs(this.getCurOffsetCompareToInitialOffset(event)[0]) <=
594
+ this.tolerance * this.toleranceFactor;
595
+ if (vShouldAbsorb) {
596
+ if (vlp === 'left') {
597
+ this.doUpdatePosition({
598
+ x: vline[0].x + this.draggingBBox.halfExtents[0],
599
+ });
600
+ }
601
+ else if (vlp === 'vcenter') {
602
+ this.doUpdatePosition({
603
+ x: vline[0].x,
604
+ });
605
+ }
606
+ else if (vlp === 'right') {
607
+ this.doUpdatePosition({
608
+ fx: vline[0].x - this.draggingBBox.halfExtents[0],
609
+ });
610
+ }
611
+ // updarte align line when absorb
612
+ this.updateAlignLineWhenAbsorb([true, false]);
613
+ }
614
+ else {
615
+ // cancel absorb
616
+ // 1.update positon
617
+ this.doUpdatePosition({ fx: undefined });
618
+ // 2.remove align line && update state
619
+ this.removeAlignLine([true, undefined]);
620
+ // count down to be adsorbable
621
+ this.canAdsorbCount = 10; // 1s
622
+ this.canAdsorbCountDown();
623
+ }
624
+ };
625
+ // h direction: whether keep adsorption
626
+ const checkHShouldHoldAbsorb = (hlp, hline) => {
627
+ // h direction: continue to adsorb
628
+ const hShouldAbsorb = Math.abs(this.getCurOffsetCompareToInitialOffset(event)[1]) <=
629
+ this.tolerance * this.toleranceFactor;
630
+ if (hShouldAbsorb) {
631
+ if (hlp === 'top') {
632
+ this.doUpdatePosition({
633
+ fy: hline[0].y + this.draggingBBox.halfExtents[1],
634
+ });
635
+ }
636
+ else if (hlp === 'hcenter') {
637
+ this.doUpdatePosition({
638
+ fy: hline[0].y,
639
+ });
640
+ }
641
+ else if (hlp === 'bottom') {
642
+ this.doUpdatePosition({
643
+ fy: hline[0].y - this.draggingBBox.halfExtents[1],
644
+ });
645
+ }
646
+ // update align line
647
+ this.updateAlignLineWhenAbsorb([false, true]);
648
+ }
649
+ else {
650
+ // 1.update position
651
+ this.doUpdatePosition({ fy: undefined });
652
+ // 2.remove align line && update state
653
+ this.removeAlignLine([undefined, true]);
654
+ // count down to be adsorbable
655
+ this.canAdsorbCount = 10; // 1s
656
+ this.canAdsorbCountDown();
657
+ }
658
+ };
659
+ // v direction: whether adsorbed
660
+ const checkVShouldAbsorb = () => {
661
+ const ret = this.canDrawLine();
662
+ // If in recent from adsorption area, can't immediately draw lines (must be removed from the area to reline this area)
663
+ if (ret) {
664
+ // draw align lines
665
+ this.drawAlignLines({ vdl: ret.vdl, hdl: undefined });
666
+ // absorb dragging box
667
+ this.absorb({ vdl: ret.vdl, hdl: undefined });
668
+ }
669
+ };
670
+ // h direction: whether adsorbed
671
+ const checkHShouldAbsorb = () => {
672
+ const ret = this.canDrawLine();
673
+ // If in recent from adsorption area, can't immediately draw lines (must be removed from the area to reline this area)
674
+ if (ret) {
675
+ // draw align lines
676
+ this.drawAlignLines({ vdl: undefined, hdl: ret.hdl });
677
+ // absorb dragging box
678
+ this.absorb({ vdl: undefined, hdl: ret.hdl });
679
+ }
680
+ };
681
+ // 1、the current state of the two directions are adsorption
682
+ if (this.isAdsorbed[0] && this.isAdsorbed[1]) {
683
+ vlp = (_a = this.drawedLines[0].dl) === null || _a === void 0 ? void 0 : _a.lp;
684
+ vline = (_b = this.drawedLines[0].dl) === null || _b === void 0 ? void 0 : _b.line;
685
+ hlp = (_c = this.drawedLines[1].dl) === null || _c === void 0 ? void 0 : _c.lp;
686
+ hline = (_d = this.drawedLines[1].dl) === null || _d === void 0 ? void 0 : _d.line;
687
+ checkVShouldHoldAbsorb(vlp, vline);
688
+ checkHShouldHoldAbsorb(hlp, hline);
689
+ }
690
+ else if (this.isAdsorbed[0] && !this.isAdsorbed[1]) {
691
+ // 2、currently, only the v direction is adsorbed
692
+ vlp = (_e = this.drawedLines[0].dl) === null || _e === void 0 ? void 0 : _e.lp;
693
+ vline = (_f = this.drawedLines[0].dl) === null || _f === void 0 ? void 0 : _f.line;
694
+ checkVShouldHoldAbsorb(vlp, vline);
695
+ checkHShouldAbsorb();
696
+ }
697
+ else if (!this.isAdsorbed[0] && this.isAdsorbed[1]) {
698
+ // 3、currently, only the h direction is adsorbed
699
+ hlp = (_g = this.drawedLines[1].dl) === null || _g === void 0 ? void 0 : _g.lp;
700
+ hline = (_h = this.drawedLines[1].dl) === null || _h === void 0 ? void 0 : _h.line;
701
+ checkHShouldHoldAbsorb(vlp, vline);
702
+ checkVShouldAbsorb();
703
+ }
704
+ else if (!this.isAdsorbed[0] && !this.isAdsorbed[1]) {
705
+ // 4、currently, v and h directions are not adsorbed
706
+ const ret = this.canDrawLine();
707
+ // If you have recently detached from the attachment area, you cannot draw the line immediately (you need to remove the detached area to redraw the area)
708
+ if (ret) {
709
+ // draw align lines
710
+ this.drawAlignLines(ret);
711
+ // absorb dragging box
712
+ this.absorb(ret);
713
+ }
714
+ }
715
+ }).bind(this), 16, {
716
+ leading: false,
717
+ trailing: true,
718
+ });
719
+ //#region draw/remove lines
720
+ // first:v direction; second:h direction;
721
+ // ddo: drawed DisplayObject, dl: DrawLine
722
+ this.drawedLines = [undefined, undefined];
723
+ this.throttleUpdate = (0, util_1.throttle)(() => {
724
+ this.graph.updateNodePosition(Array.from(this.updateCache.values()), false, true);
725
+ this.updateCache.clear();
726
+ }, 16, {
727
+ leading: true,
728
+ trailing: true,
729
+ });
730
+ this.init(options.graph);
731
+ }
732
732
  getEvents() {
733
733
  return {
734
734
  pointerdown: this.onPointerDown,