@antv/g6 5.0.0-beta.13 → 5.0.0-beta.15

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