@antv/g6 5.0.0-beta.14 → 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.
- package/dist/g6.min.js +1 -6
- package/esm/api-doc/types.d.ts +1 -0
- package/esm/api-doc/types.js +1 -2
- package/esm/api-doc/types.js.map +1 -1
- package/esm/index.d.ts +1 -1
- package/esm/index.js +1 -1
- package/esm/item/combo.js +2 -5
- package/esm/item/combo.js.map +1 -1
- package/esm/item/node.js +0 -1
- package/esm/item/node.js.map +1 -1
- package/esm/runtime/controller/item.js +2 -1
- package/esm/runtime/controller/item.js.map +1 -1
- package/esm/runtime/graph.js +2 -2
- package/esm/runtime/graph.js.map +1 -1
- package/esm/stdlib/behavior/activate-relations.d.ts +1 -1
- package/esm/stdlib/behavior/brush-select.d.ts +9 -3
- package/esm/stdlib/behavior/brush-select.js +9 -10
- package/esm/stdlib/behavior/brush-select.js.map +1 -1
- package/esm/stdlib/behavior/click-select.d.ts +1 -1
- package/esm/stdlib/behavior/collapse-expand-combo.d.ts +1 -1
- package/esm/stdlib/behavior/collapse-expand-tree.d.ts +1 -1
- package/esm/stdlib/behavior/drag-canvas.js +8 -1
- package/esm/stdlib/behavior/drag-canvas.js.map +1 -1
- package/esm/stdlib/behavior/drag-combo.d.ts +1 -1
- package/esm/stdlib/behavior/drag-node.d.ts +1 -1
- package/esm/stdlib/behavior/drag-node.js +3 -0
- package/esm/stdlib/behavior/drag-node.js.map +1 -1
- package/esm/stdlib/behavior/lasso-select.js +2 -2
- package/esm/stdlib/behavior/lasso-select.js.map +1 -1
- package/esm/stdlib/behavior/shortcuts-call.d.ts +1 -1
- package/esm/stdlib/behavior/zoom-canvas.js +10 -7
- package/esm/stdlib/behavior/zoom-canvas.js.map +1 -1
- package/esm/stdlib/item/edge/base.d.ts +2 -4
- package/esm/stdlib/item/edge/base.js +11 -18
- package/esm/stdlib/item/edge/base.js.map +1 -1
- package/esm/stdlib/item/node/base.d.ts +1 -5
- package/esm/stdlib/item/node/base.js +7 -32
- package/esm/stdlib/item/node/base.js.map +1 -1
- package/esm/stdlib/item/node/donut.d.ts +3 -3
- package/esm/stdlib/plugin/hull/hullComponent.d.ts +1 -1
- package/esm/stdlib/plugin/legend/index.d.ts +1 -1
- package/esm/stdlib/plugin/snapline/index.d.ts +2 -2
- package/esm/stdlib/plugin/snapline/index.js +239 -239
- package/esm/stdlib/plugin/snapline/index.js.map +1 -1
- package/esm/stdlib/plugin/timebar/index.d.ts +4 -4
- package/esm/stdlib/plugin/timebar/index.js +4 -4
- package/esm/stdlib/plugin/timebar/index.js.map +1 -1
- package/esm/stdlib/plugin/tooltip/index.d.ts +1 -1
- package/esm/stdlib/plugin/watermaker/index.d.ts +1 -1
- package/esm/types/animate.d.ts +2 -2
- package/esm/types/behavior.d.ts +1 -1
- package/esm/types/combo.d.ts +7 -7
- package/esm/types/common.d.ts +5 -5
- package/esm/types/data.d.ts +6 -6
- package/esm/types/edge.d.ts +9 -9
- package/esm/types/event.d.ts +1 -1
- package/esm/types/history.d.ts +2 -2
- package/esm/types/hook.d.ts +1 -1
- package/esm/types/item.d.ts +13 -13
- package/esm/types/layout.d.ts +6 -6
- package/esm/types/loop.d.ts +2 -2
- package/esm/types/node.d.ts +7 -7
- package/esm/types/render.d.ts +1 -1
- package/esm/types/spec.d.ts +3 -3
- package/esm/types/stdlib.d.ts +1 -1
- package/esm/types/theme.d.ts +8 -8
- package/esm/types/view.d.ts +2 -2
- package/esm/util/event.d.ts +2 -2
- package/esm/util/layout.d.ts +1 -1
- package/esm/util/loop.js +4 -0
- package/esm/util/loop.js.map +1 -1
- package/esm/util/shape.d.ts +0 -1
- package/esm/util/shape.js +0 -6
- package/esm/util/shape.js.map +1 -1
- package/esm/util/shape3d.js +1 -6
- package/esm/util/shape3d.js.map +1 -1
- package/esm/util/warn.d.ts +1 -1
- package/lib/api-doc/types.d.ts +1 -0
- package/lib/api-doc/types.js +2 -2
- package/lib/api-doc/types.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/item/combo.js +2 -5
- package/lib/item/combo.js.map +1 -1
- package/lib/item/node.js +0 -1
- package/lib/item/node.js.map +1 -1
- package/lib/runtime/controller/item.js +2 -1
- package/lib/runtime/controller/item.js.map +1 -1
- package/lib/runtime/graph.js +2 -2
- package/lib/runtime/graph.js.map +1 -1
- package/lib/stdlib/behavior/activate-relations.d.ts +1 -1
- package/lib/stdlib/behavior/brush-select.d.ts +9 -3
- package/lib/stdlib/behavior/brush-select.js +12 -10
- package/lib/stdlib/behavior/brush-select.js.map +1 -1
- package/lib/stdlib/behavior/click-select.d.ts +1 -1
- package/lib/stdlib/behavior/collapse-expand-combo.d.ts +1 -1
- package/lib/stdlib/behavior/collapse-expand-tree.d.ts +1 -1
- package/lib/stdlib/behavior/drag-canvas.js +8 -1
- package/lib/stdlib/behavior/drag-canvas.js.map +1 -1
- package/lib/stdlib/behavior/drag-combo.d.ts +1 -1
- package/lib/stdlib/behavior/drag-node.d.ts +1 -1
- package/lib/stdlib/behavior/drag-node.js +3 -0
- package/lib/stdlib/behavior/drag-node.js.map +1 -1
- package/lib/stdlib/behavior/lasso-select.js +5 -2
- package/lib/stdlib/behavior/lasso-select.js.map +1 -1
- package/lib/stdlib/behavior/shortcuts-call.d.ts +1 -1
- package/lib/stdlib/behavior/zoom-canvas.js +10 -7
- package/lib/stdlib/behavior/zoom-canvas.js.map +1 -1
- package/lib/stdlib/item/edge/base.d.ts +2 -4
- package/lib/stdlib/item/edge/base.js +9 -16
- package/lib/stdlib/item/edge/base.js.map +1 -1
- package/lib/stdlib/item/node/base.d.ts +1 -5
- package/lib/stdlib/item/node/base.js +6 -31
- package/lib/stdlib/item/node/base.js.map +1 -1
- package/lib/stdlib/item/node/donut.d.ts +3 -3
- package/lib/stdlib/plugin/hull/hullComponent.d.ts +1 -1
- package/lib/stdlib/plugin/legend/index.d.ts +1 -1
- package/lib/stdlib/plugin/snapline/index.d.ts +2 -2
- package/lib/stdlib/plugin/snapline/index.js +239 -239
- package/lib/stdlib/plugin/snapline/index.js.map +1 -1
- package/lib/stdlib/plugin/timebar/index.d.ts +4 -4
- package/lib/stdlib/plugin/timebar/index.js +4 -4
- package/lib/stdlib/plugin/timebar/index.js.map +1 -1
- package/lib/stdlib/plugin/tooltip/index.d.ts +1 -1
- package/lib/stdlib/plugin/watermaker/index.d.ts +1 -1
- package/lib/types/animate.d.ts +2 -2
- package/lib/types/behavior.d.ts +1 -1
- package/lib/types/combo.d.ts +7 -7
- package/lib/types/common.d.ts +5 -5
- package/lib/types/data.d.ts +6 -6
- package/lib/types/edge.d.ts +9 -9
- package/lib/types/event.d.ts +1 -1
- package/lib/types/event.js +2 -2
- package/lib/types/event.js.map +1 -1
- package/lib/types/history.d.ts +2 -2
- package/lib/types/history.js +1 -1
- package/lib/types/history.js.map +1 -1
- package/lib/types/hook.d.ts +1 -1
- package/lib/types/item.d.ts +13 -13
- package/lib/types/item.js +1 -1
- package/lib/types/item.js.map +1 -1
- package/lib/types/layout.d.ts +6 -6
- package/lib/types/loop.d.ts +2 -2
- package/lib/types/loop.js +1 -1
- package/lib/types/loop.js.map +1 -1
- package/lib/types/node.d.ts +7 -7
- package/lib/types/render.d.ts +1 -1
- package/lib/types/spec.d.ts +3 -3
- package/lib/types/stdlib.d.ts +1 -1
- package/lib/types/theme.d.ts +8 -8
- package/lib/types/view.d.ts +2 -2
- package/lib/util/event.d.ts +2 -2
- package/lib/util/layout.d.ts +1 -1
- package/lib/util/loop.js +4 -0
- package/lib/util/loop.js.map +1 -1
- package/lib/util/shape.d.ts +0 -1
- package/lib/util/shape.js +1 -7
- package/lib/util/shape.js.map +1 -1
- package/lib/util/shape3d.js +0 -5
- package/lib/util/shape3d.js.map +1 -1
- package/lib/util/warn.d.ts +1 -1
- package/package.json +32 -32
- package/src/api-doc/types.ts +1 -0
- package/src/index.ts +1 -1
- package/src/item/combo.ts +2 -6
- package/src/item/node.ts +0 -1
- package/src/runtime/controller/item.ts +1 -1
- package/src/runtime/graph.ts +2 -2
- package/src/stdlib/behavior/brush-select.ts +10 -11
- package/src/stdlib/behavior/drag-canvas.ts +11 -0
- package/src/stdlib/behavior/drag-node.ts +8 -0
- package/src/stdlib/behavior/lasso-select.ts +2 -2
- package/src/stdlib/behavior/zoom-canvas.ts +13 -14
- package/src/stdlib/item/edge/base.ts +11 -27
- package/src/stdlib/item/node/base.ts +10 -36
- package/src/util/loop.ts +4 -0
- package/src/util/shape.ts +0 -7
- package/src/util/shape3d.ts +1 -10
|
@@ -4,6 +4,245 @@ 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
|
+
}
|
|
7
246
|
setTolerance(tolerance) {
|
|
8
247
|
this.tolerance = tolerance;
|
|
9
248
|
}
|
|
@@ -490,245 +729,6 @@ class Snapline extends plugin_1.Plugin {
|
|
|
490
729
|
h: hMaxDL ? hMaxDL.dl : undefined,
|
|
491
730
|
};
|
|
492
731
|
}
|
|
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,
|