@neo4j-nvl/interaction-handlers 2.0.0 → 2.1.0
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/CHANGELOG.md +25 -1
- package/README.md +8 -0
- package/lib/constants.d.ts +1 -1
- package/lib/constants.js +4 -2
- package/lib/index.d.ts +10 -20
- package/lib/index.js +10 -10
- package/lib/interaction-handlers/base.d.ts +67 -67
- package/lib/interaction-handlers/base.js +98 -104
- package/lib/interaction-handlers/box-select-interaction.d.ts +44 -44
- package/lib/interaction-handlers/box-select-interaction.js +133 -127
- package/lib/interaction-handlers/click-interaction.d.ts +111 -111
- package/lib/interaction-handlers/click-interaction.js +116 -131
- package/lib/interaction-handlers/drag-node-interaction.d.ts +40 -40
- package/lib/interaction-handlers/drag-node-interaction.js +102 -111
- package/lib/interaction-handlers/draw-interaction.d.ts +37 -37
- package/lib/interaction-handlers/draw-interaction.js +245 -278
- package/lib/interaction-handlers/hover-interaction.d.ts +34 -30
- package/lib/interaction-handlers/hover-interaction.js +83 -89
- package/lib/interaction-handlers/keyboard-interaction.d.ts +149 -97
- package/lib/interaction-handlers/keyboard-interaction.js +255 -201
- package/lib/interaction-handlers/lasso-interaction.d.ts +45 -45
- package/lib/interaction-handlers/lasso-interaction.js +174 -196
- package/lib/interaction-handlers/pan-interaction.d.ts +62 -61
- package/lib/interaction-handlers/pan-interaction.js +111 -100
- package/lib/interaction-handlers/utils.d.ts +2 -2
- package/lib/interaction-handlers/utils.js +39 -38
- package/lib/interaction-handlers/zoom-interaction.d.ts +52 -48
- package/lib/interaction-handlers/zoom-interaction.js +73 -71
- package/lib/overlay-renderer/overlay-renderer.d.ts +13 -13
- package/lib/overlay-renderer/overlay-renderer.js +96 -111
- package/package.json +19 -6
- package/lib/__tests__/box-select-interaction.test.d.ts +0 -1
- package/lib/__tests__/box-select-interaction.test.js +0 -149
- package/lib/__tests__/click-interaction.test.d.ts +0 -1
- package/lib/__tests__/click-interaction.test.js +0 -505
- package/lib/__tests__/drag-node-interaction.test.d.ts +0 -1
- package/lib/__tests__/drag-node-interaction.test.js +0 -247
- package/lib/__tests__/hover-interaction.test.d.ts +0 -1
- package/lib/__tests__/hover-interaction.test.js +0 -374
- package/lib/__tests__/keyboard-interaction.test.d.ts +0 -1
- package/lib/__tests__/keyboard-interaction.test.js +0 -322
- package/lib/__tests__/lasso-interaction.test.d.ts +0 -1
- package/lib/__tests__/lasso-interaction.test.js +0 -219
- package/lib/__tests__/pan-interaction.test.d.ts +0 -1
- package/lib/__tests__/pan-interaction.test.js +0 -223
- package/lib/__tests__/utils.test.d.ts +0 -1
- package/lib/__tests__/utils.test.js +0 -19
- package/lib/__tests__/zoom-interaction.test.d.ts +0 -1
- package/lib/__tests__/zoom-interaction.test.js +0 -185
|
@@ -1,247 +0,0 @@
|
|
|
1
|
-
import NVL from '@neo4j-nvl/base';
|
|
2
|
-
import '@testing-library/jest-dom';
|
|
3
|
-
import { DragNodeInteraction } from '../interaction-handlers/drag-node-interaction';
|
|
4
|
-
jest.mock('@neo4j-nvl/layout-workers');
|
|
5
|
-
describe('DragNodeInteraction', () => {
|
|
6
|
-
let dragNodeInteraction;
|
|
7
|
-
let myNVL;
|
|
8
|
-
const dragStartCallbackMock = jest.fn();
|
|
9
|
-
const dragCallbackMock = jest.fn();
|
|
10
|
-
const dragEndCallbackMock = jest.fn();
|
|
11
|
-
const NodeRadius = 30;
|
|
12
|
-
const nodes = [
|
|
13
|
-
{ id: '0', x: 10, y: 10, size: NodeRadius },
|
|
14
|
-
{ id: '1', x: 200, y: 200 }
|
|
15
|
-
];
|
|
16
|
-
const relationships = [{ id: '10', from: '0', to: '1' }];
|
|
17
|
-
beforeEach(() => {
|
|
18
|
-
myNVL = new NVL(document.createElement('div'), nodes, relationships, {
|
|
19
|
-
disableWebGL: true,
|
|
20
|
-
initialZoom: 1,
|
|
21
|
-
layout: 'free'
|
|
22
|
-
});
|
|
23
|
-
dragNodeInteraction = new DragNodeInteraction(myNVL);
|
|
24
|
-
});
|
|
25
|
-
afterEach(() => {
|
|
26
|
-
dragNodeInteraction.destroy();
|
|
27
|
-
myNVL.destroy();
|
|
28
|
-
dragStartCallbackMock.mockReset();
|
|
29
|
-
dragCallbackMock.mockReset();
|
|
30
|
-
dragEndCallbackMock.mockReset();
|
|
31
|
-
});
|
|
32
|
-
test('performing a simple drag operation should invoke all expected callbacks', () => {
|
|
33
|
-
dragNodeInteraction.updateCallback('onDragStart', dragStartCallbackMock);
|
|
34
|
-
dragNodeInteraction.updateCallback('onDrag', dragCallbackMock);
|
|
35
|
-
dragNodeInteraction.updateCallback('onDragEnd', dragEndCallbackMock);
|
|
36
|
-
expect(myNVL.getSelectedNodes()).toHaveLength(0);
|
|
37
|
-
const mouseDownEvent = new MouseEvent('mousedown', {
|
|
38
|
-
clientX: 10,
|
|
39
|
-
clientY: 10
|
|
40
|
-
});
|
|
41
|
-
const mouseMoveEvent = new MouseEvent('mousemove', {
|
|
42
|
-
buttons: 1,
|
|
43
|
-
clientX: 20,
|
|
44
|
-
clientY: 20
|
|
45
|
-
});
|
|
46
|
-
const mouseUpEvent = new MouseEvent('mouseup', {
|
|
47
|
-
clientX: 20,
|
|
48
|
-
clientY: 20
|
|
49
|
-
});
|
|
50
|
-
const container = myNVL.getContainer();
|
|
51
|
-
container.dispatchEvent(mouseDownEvent);
|
|
52
|
-
container.dispatchEvent(mouseMoveEvent);
|
|
53
|
-
document.body.dispatchEvent(mouseUpEvent);
|
|
54
|
-
return new Promise((resolve) => {
|
|
55
|
-
expect(dragStartCallbackMock).toHaveBeenCalledTimes(1);
|
|
56
|
-
expect(dragStartCallbackMock).toHaveBeenCalledWith([nodes[0]], mouseMoveEvent);
|
|
57
|
-
expect(dragCallbackMock).toHaveBeenCalledTimes(1);
|
|
58
|
-
expect(dragCallbackMock).toHaveBeenCalledWith([nodes[0]], mouseMoveEvent);
|
|
59
|
-
expect(dragEndCallbackMock).toHaveBeenCalledTimes(1);
|
|
60
|
-
expect(dragEndCallbackMock).toHaveBeenCalledWith([nodes[0]], mouseUpEvent);
|
|
61
|
-
resolve();
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
test('performing dragging on selection of nodes should invoke all expected callbacks', () => {
|
|
65
|
-
dragNodeInteraction.updateCallback('onDragStart', dragStartCallbackMock);
|
|
66
|
-
dragNodeInteraction.updateCallback('onDrag', dragCallbackMock);
|
|
67
|
-
dragNodeInteraction.updateCallback('onDragEnd', dragEndCallbackMock);
|
|
68
|
-
myNVL.updateElementsInGraph([
|
|
69
|
-
{ id: '0', selected: true },
|
|
70
|
-
{ id: '1', selected: true }
|
|
71
|
-
], []);
|
|
72
|
-
expect(myNVL.getSelectedNodes()).toHaveLength(2);
|
|
73
|
-
const mouseDownEvent = new MouseEvent('mousedown', {
|
|
74
|
-
clientX: 10,
|
|
75
|
-
clientY: 10
|
|
76
|
-
});
|
|
77
|
-
const mouseMoveEvent = new MouseEvent('mousemove', {
|
|
78
|
-
buttons: 1,
|
|
79
|
-
clientX: 20,
|
|
80
|
-
clientY: 20
|
|
81
|
-
});
|
|
82
|
-
const mouseUpEvent = new MouseEvent('mouseup', {
|
|
83
|
-
clientX: 20,
|
|
84
|
-
clientY: 20
|
|
85
|
-
});
|
|
86
|
-
const container = myNVL.getContainer();
|
|
87
|
-
container.dispatchEvent(mouseDownEvent);
|
|
88
|
-
container.dispatchEvent(mouseMoveEvent);
|
|
89
|
-
document.body.dispatchEvent(mouseUpEvent);
|
|
90
|
-
const expectedSelectedNodes = nodes.map((node) => ({ ...node, selected: true }));
|
|
91
|
-
return new Promise((resolve) => {
|
|
92
|
-
expect(dragStartCallbackMock).toHaveBeenCalledTimes(1);
|
|
93
|
-
expect(dragStartCallbackMock).toHaveBeenCalledWith(expectedSelectedNodes, mouseMoveEvent);
|
|
94
|
-
expect(dragCallbackMock).toHaveBeenCalledTimes(1);
|
|
95
|
-
expect(dragCallbackMock).toHaveBeenCalledWith(expectedSelectedNodes, mouseMoveEvent);
|
|
96
|
-
expect(dragEndCallbackMock).toHaveBeenCalledTimes(1);
|
|
97
|
-
expect(dragEndCallbackMock).toHaveBeenCalledWith(expectedSelectedNodes, mouseUpEvent);
|
|
98
|
-
resolve();
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
test('dragging should not be invoked when the mouse is not on a node', () => {
|
|
102
|
-
dragNodeInteraction.updateCallback('onDragStart', dragStartCallbackMock);
|
|
103
|
-
dragNodeInteraction.updateCallback('onDrag', dragCallbackMock);
|
|
104
|
-
dragNodeInteraction.updateCallback('onDragEnd', dragEndCallbackMock);
|
|
105
|
-
const mouseDownEvent = new MouseEvent('mousedown', {
|
|
106
|
-
clientX: 100,
|
|
107
|
-
clientY: 100
|
|
108
|
-
});
|
|
109
|
-
const mouseMoveEvent = new MouseEvent('mousemove', {
|
|
110
|
-
buttons: 1,
|
|
111
|
-
clientX: 150,
|
|
112
|
-
clientY: 150
|
|
113
|
-
});
|
|
114
|
-
const mouseUpEvent = new MouseEvent('mouseup', {
|
|
115
|
-
clientX: 150,
|
|
116
|
-
clientY: 150
|
|
117
|
-
});
|
|
118
|
-
const container = myNVL.getContainer();
|
|
119
|
-
container.dispatchEvent(mouseDownEvent);
|
|
120
|
-
container.dispatchEvent(mouseMoveEvent);
|
|
121
|
-
document.body.dispatchEvent(mouseUpEvent);
|
|
122
|
-
return new Promise((resolve) => {
|
|
123
|
-
expect(dragStartCallbackMock).toHaveBeenCalledTimes(0);
|
|
124
|
-
expect(dragCallbackMock).toHaveBeenCalledTimes(0);
|
|
125
|
-
expect(dragEndCallbackMock).toHaveBeenCalledTimes(0);
|
|
126
|
-
resolve();
|
|
127
|
-
});
|
|
128
|
-
});
|
|
129
|
-
test('dragging should not be invoked when the mouse is moved less than the drag threshold', () => {
|
|
130
|
-
dragNodeInteraction.updateCallback('onDragStart', dragStartCallbackMock);
|
|
131
|
-
dragNodeInteraction.updateCallback('onDrag', dragCallbackMock);
|
|
132
|
-
dragNodeInteraction.updateCallback('onDragEnd', dragEndCallbackMock);
|
|
133
|
-
expect(myNVL.getSelectedNodes()).toHaveLength(0);
|
|
134
|
-
const mouseDownEvent = new MouseEvent('mousedown', {
|
|
135
|
-
clientX: 10,
|
|
136
|
-
clientY: 10
|
|
137
|
-
});
|
|
138
|
-
const mouseMoveEvent = new MouseEvent('mousemove', {
|
|
139
|
-
buttons: 1,
|
|
140
|
-
clientX: 12,
|
|
141
|
-
clientY: 12
|
|
142
|
-
});
|
|
143
|
-
const mouseUpEvent = new MouseEvent('mouseup', {
|
|
144
|
-
clientX: 12,
|
|
145
|
-
clientY: 12
|
|
146
|
-
});
|
|
147
|
-
const container = myNVL.getContainer();
|
|
148
|
-
container.dispatchEvent(mouseDownEvent);
|
|
149
|
-
container.dispatchEvent(mouseMoveEvent);
|
|
150
|
-
document.body.dispatchEvent(mouseUpEvent);
|
|
151
|
-
return new Promise((resolve) => {
|
|
152
|
-
expect(dragStartCallbackMock).toHaveBeenCalledTimes(0);
|
|
153
|
-
expect(dragCallbackMock).toHaveBeenCalledTimes(0);
|
|
154
|
-
expect(dragEndCallbackMock).toHaveBeenCalledTimes(0);
|
|
155
|
-
resolve();
|
|
156
|
-
});
|
|
157
|
-
});
|
|
158
|
-
test('dragging outside the container should stop dragging but keep selection disabled until mouse release', () => {
|
|
159
|
-
dragNodeInteraction.updateCallback('onDragStart', dragStartCallbackMock);
|
|
160
|
-
dragNodeInteraction.updateCallback('onDrag', dragCallbackMock);
|
|
161
|
-
dragNodeInteraction.updateCallback('onDragEnd', dragEndCallbackMock);
|
|
162
|
-
const mouseDownEvent = new MouseEvent('mousedown', {
|
|
163
|
-
clientX: 10,
|
|
164
|
-
clientY: 10
|
|
165
|
-
});
|
|
166
|
-
const mouseMoveEvent = new MouseEvent('mousemove', {
|
|
167
|
-
buttons: 1,
|
|
168
|
-
clientX: 20,
|
|
169
|
-
clientY: 20
|
|
170
|
-
});
|
|
171
|
-
const mouseLeaveEvent = new MouseEvent('mouseleave', {
|
|
172
|
-
clientX: 1,
|
|
173
|
-
clientY: 1
|
|
174
|
-
});
|
|
175
|
-
const bodyMouseUpEvent = new MouseEvent('mouseup');
|
|
176
|
-
const container = myNVL.getContainer();
|
|
177
|
-
container.dispatchEvent(mouseDownEvent);
|
|
178
|
-
container.dispatchEvent(mouseMoveEvent);
|
|
179
|
-
container.dispatchEvent(mouseLeaveEvent);
|
|
180
|
-
return new Promise((resolve) => {
|
|
181
|
-
expect(dragStartCallbackMock).toHaveBeenCalledTimes(1);
|
|
182
|
-
expect(dragCallbackMock).toHaveBeenCalledTimes(1);
|
|
183
|
-
expect(document.body.style.getPropertyValue('user-select')).toBe('none');
|
|
184
|
-
document.body.dispatchEvent(bodyMouseUpEvent);
|
|
185
|
-
expect(document.body.style.getPropertyValue('user-select')).toBe('');
|
|
186
|
-
expect(dragEndCallbackMock).toHaveBeenCalledTimes(1);
|
|
187
|
-
resolve();
|
|
188
|
-
});
|
|
189
|
-
});
|
|
190
|
-
test('dragging should not work while performing a drawing action', () => {
|
|
191
|
-
dragNodeInteraction.updateCallback('onDragStart', dragStartCallbackMock);
|
|
192
|
-
dragNodeInteraction.updateCallback('onDrag', dragCallbackMock);
|
|
193
|
-
dragNodeInteraction.updateCallback('onDragEnd', dragEndCallbackMock);
|
|
194
|
-
const drawingMouseDownEvent = new MouseEvent('mousedown', {
|
|
195
|
-
clientX: 10,
|
|
196
|
-
clientY: 10 + NodeRadius + 1
|
|
197
|
-
});
|
|
198
|
-
const drawMouseMoveEvent = new MouseEvent('mousemove', {
|
|
199
|
-
buttons: 1,
|
|
200
|
-
clientX: 20,
|
|
201
|
-
clientY: 20
|
|
202
|
-
});
|
|
203
|
-
const mouseUpEvent = new MouseEvent('mouseup');
|
|
204
|
-
const container = myNVL.getContainer();
|
|
205
|
-
container.dispatchEvent(drawingMouseDownEvent);
|
|
206
|
-
container.dispatchEvent(drawMouseMoveEvent);
|
|
207
|
-
container.dispatchEvent(mouseUpEvent);
|
|
208
|
-
return new Promise((resolve) => {
|
|
209
|
-
expect(dragStartCallbackMock).not.toHaveBeenCalled();
|
|
210
|
-
expect(dragCallbackMock).not.toHaveBeenCalled();
|
|
211
|
-
expect(dragEndCallbackMock).not.toHaveBeenCalled();
|
|
212
|
-
resolve();
|
|
213
|
-
});
|
|
214
|
-
});
|
|
215
|
-
test('dragging should work after performing a drawing action', () => {
|
|
216
|
-
dragNodeInteraction.updateCallback('onDragStart', dragStartCallbackMock);
|
|
217
|
-
dragNodeInteraction.updateCallback('onDrag', dragCallbackMock);
|
|
218
|
-
dragNodeInteraction.updateCallback('onDragEnd', dragEndCallbackMock);
|
|
219
|
-
const drawingMouseDownEvent = new MouseEvent('mousedown', {
|
|
220
|
-
clientX: 10,
|
|
221
|
-
clientY: 10 + NodeRadius + 1
|
|
222
|
-
});
|
|
223
|
-
const mouseUpEvent = new MouseEvent('mouseup');
|
|
224
|
-
const dragMouseDownEvent = new MouseEvent('mousedown', {
|
|
225
|
-
clientX: 10,
|
|
226
|
-
clientY: 10
|
|
227
|
-
});
|
|
228
|
-
const dragMouseMoveEvent = new MouseEvent('mousemove', {
|
|
229
|
-
buttons: 1,
|
|
230
|
-
clientX: 20,
|
|
231
|
-
clientY: 20
|
|
232
|
-
});
|
|
233
|
-
const container = myNVL.getContainer();
|
|
234
|
-
container.dispatchEvent(drawingMouseDownEvent);
|
|
235
|
-
container.dispatchEvent(dragMouseMoveEvent);
|
|
236
|
-
container.dispatchEvent(mouseUpEvent);
|
|
237
|
-
container.dispatchEvent(dragMouseDownEvent);
|
|
238
|
-
container.dispatchEvent(dragMouseMoveEvent);
|
|
239
|
-
document.body.dispatchEvent(mouseUpEvent);
|
|
240
|
-
return new Promise((resolve) => {
|
|
241
|
-
expect(dragStartCallbackMock).toHaveBeenCalledTimes(1);
|
|
242
|
-
expect(dragCallbackMock).toHaveBeenCalledTimes(1);
|
|
243
|
-
expect(dragEndCallbackMock).toHaveBeenCalledTimes(1);
|
|
244
|
-
resolve();
|
|
245
|
-
});
|
|
246
|
-
});
|
|
247
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import '@testing-library/jest-dom';
|
|
@@ -1,374 +0,0 @@
|
|
|
1
|
-
import NVL from '@neo4j-nvl/base';
|
|
2
|
-
import '@testing-library/jest-dom';
|
|
3
|
-
import { HoverInteraction } from '../interaction-handlers/hover-interaction';
|
|
4
|
-
// jest.mock('@neo4j-nvl/base')
|
|
5
|
-
jest.mock('@neo4j-nvl/layout-workers');
|
|
6
|
-
describe('HoverInteraction', () => {
|
|
7
|
-
let hoverInteraction;
|
|
8
|
-
let myNVL;
|
|
9
|
-
const callbackMock = jest.fn();
|
|
10
|
-
beforeEach(() => {
|
|
11
|
-
myNVL = new NVL(document.createElement('div'), [
|
|
12
|
-
{ id: '0', x: 100, y: 100 },
|
|
13
|
-
{ id: '1', x: 200, y: 200 }
|
|
14
|
-
], [{ id: '10', from: '0', to: '1' }], { disableWebGL: true, initialZoom: 1, renderer: 'webgl' });
|
|
15
|
-
hoverInteraction = new HoverInteraction(myNVL, { drawShadowOnHover: true });
|
|
16
|
-
hoverInteraction.updateCallback('onHover', callbackMock);
|
|
17
|
-
});
|
|
18
|
-
afterEach(() => {
|
|
19
|
-
hoverInteraction.destroy();
|
|
20
|
-
myNVL.destroy();
|
|
21
|
-
callbackMock.mockReset();
|
|
22
|
-
jest.restoreAllMocks();
|
|
23
|
-
});
|
|
24
|
-
describe('handleHover', () => {
|
|
25
|
-
it('should register hover event on canvas', () => {
|
|
26
|
-
const mouseEvent = new MouseEvent('mousemove', {
|
|
27
|
-
clientX: 10,
|
|
28
|
-
clientY: 10
|
|
29
|
-
});
|
|
30
|
-
hoverInteraction.handleHover(mouseEvent);
|
|
31
|
-
expect(callbackMock).toHaveBeenCalledWith(undefined, { nodes: [], relationships: [], clusters: [] }, mouseEvent);
|
|
32
|
-
expect(callbackMock).toHaveBeenCalledTimes(1);
|
|
33
|
-
});
|
|
34
|
-
it('should register hover event for node', () => {
|
|
35
|
-
const mouseEvent = new MouseEvent('mousemove', {
|
|
36
|
-
clientX: 100,
|
|
37
|
-
clientY: 100
|
|
38
|
-
});
|
|
39
|
-
hoverInteraction.handleHover(mouseEvent);
|
|
40
|
-
expect(callbackMock).toHaveBeenCalledWith({ id: '0', x: 100, y: 100, hovered: true }, {
|
|
41
|
-
nodes: [
|
|
42
|
-
{
|
|
43
|
-
data: { id: '0', x: 100, y: 100, hovered: true },
|
|
44
|
-
distance: 0,
|
|
45
|
-
targetCoordinates: { x: 100, y: 100 },
|
|
46
|
-
pointerCoordinates: { x: 100, y: 100 },
|
|
47
|
-
distanceVector: { x: 0, y: 0 },
|
|
48
|
-
insideNode: true
|
|
49
|
-
}
|
|
50
|
-
],
|
|
51
|
-
relationships: [
|
|
52
|
-
{
|
|
53
|
-
data: { id: '10', from: '0', to: '1' },
|
|
54
|
-
distance: 0,
|
|
55
|
-
fromTargetCoordinates: { x: 100, y: 100 },
|
|
56
|
-
toTargetCoordinates: { x: 200, y: 200 },
|
|
57
|
-
pointerCoordinates: { x: 100, y: 100 }
|
|
58
|
-
}
|
|
59
|
-
],
|
|
60
|
-
clusters: []
|
|
61
|
-
}, mouseEvent);
|
|
62
|
-
expect(callbackMock).toHaveBeenCalledTimes(1);
|
|
63
|
-
});
|
|
64
|
-
it('should register hover event for relationship', () => {
|
|
65
|
-
const mouseEvent = new MouseEvent('mousemove', {
|
|
66
|
-
clientX: 150,
|
|
67
|
-
clientY: 150
|
|
68
|
-
});
|
|
69
|
-
hoverInteraction.handleHover(mouseEvent);
|
|
70
|
-
expect(callbackMock).toHaveBeenCalledWith({ id: '10', from: '0', to: '1', hovered: true }, {
|
|
71
|
-
nodes: [],
|
|
72
|
-
relationships: [
|
|
73
|
-
{
|
|
74
|
-
data: { id: '10', from: '0', to: '1', hovered: true },
|
|
75
|
-
distance: 0,
|
|
76
|
-
fromTargetCoordinates: { x: 100, y: 100 },
|
|
77
|
-
toTargetCoordinates: { x: 200, y: 200 },
|
|
78
|
-
pointerCoordinates: { x: 150, y: 150 }
|
|
79
|
-
}
|
|
80
|
-
],
|
|
81
|
-
clusters: []
|
|
82
|
-
}, mouseEvent);
|
|
83
|
-
expect(callbackMock).toHaveBeenCalledTimes(1);
|
|
84
|
-
});
|
|
85
|
-
it('should register un-hover event for node', () => {
|
|
86
|
-
const mouseEvent = new MouseEvent('mousemove', {
|
|
87
|
-
clientX: 100,
|
|
88
|
-
clientY: 100
|
|
89
|
-
});
|
|
90
|
-
hoverInteraction.handleHover(mouseEvent);
|
|
91
|
-
expect(callbackMock).toHaveBeenCalledWith({ id: '0', x: 100, y: 100, hovered: true }, {
|
|
92
|
-
nodes: [
|
|
93
|
-
{
|
|
94
|
-
data: { id: '0', x: 100, y: 100, hovered: true },
|
|
95
|
-
distance: 0,
|
|
96
|
-
targetCoordinates: { x: 100, y: 100 },
|
|
97
|
-
pointerCoordinates: { x: 100, y: 100 },
|
|
98
|
-
distanceVector: { x: 0, y: 0 },
|
|
99
|
-
insideNode: true
|
|
100
|
-
}
|
|
101
|
-
],
|
|
102
|
-
relationships: [
|
|
103
|
-
{
|
|
104
|
-
data: { id: '10', from: '0', to: '1' },
|
|
105
|
-
distance: 0,
|
|
106
|
-
fromTargetCoordinates: { x: 100, y: 100 },
|
|
107
|
-
toTargetCoordinates: { x: 200, y: 200 },
|
|
108
|
-
pointerCoordinates: { x: 100, y: 100 }
|
|
109
|
-
}
|
|
110
|
-
],
|
|
111
|
-
clusters: []
|
|
112
|
-
}, mouseEvent);
|
|
113
|
-
expect(callbackMock).toHaveBeenCalledTimes(1);
|
|
114
|
-
const mouseEvent2 = new MouseEvent('mousemove', {
|
|
115
|
-
clientX: 10,
|
|
116
|
-
clientY: 10
|
|
117
|
-
});
|
|
118
|
-
hoverInteraction.handleHover(mouseEvent2);
|
|
119
|
-
expect(callbackMock).toHaveBeenCalledWith({ id: '0', x: 100, y: 100, hovered: false }, {
|
|
120
|
-
nodes: [
|
|
121
|
-
{
|
|
122
|
-
data: { id: '0', x: 100, y: 100, hovered: false },
|
|
123
|
-
distance: 0,
|
|
124
|
-
targetCoordinates: { x: 100, y: 100 },
|
|
125
|
-
pointerCoordinates: { x: 100, y: 100 },
|
|
126
|
-
distanceVector: { x: 0, y: 0 },
|
|
127
|
-
insideNode: true
|
|
128
|
-
}
|
|
129
|
-
],
|
|
130
|
-
relationships: [
|
|
131
|
-
{
|
|
132
|
-
data: { id: '10', from: '0', to: '1' },
|
|
133
|
-
distance: 0,
|
|
134
|
-
fromTargetCoordinates: { x: 100, y: 100 },
|
|
135
|
-
toTargetCoordinates: { x: 200, y: 200 },
|
|
136
|
-
pointerCoordinates: { x: 100, y: 100 }
|
|
137
|
-
}
|
|
138
|
-
],
|
|
139
|
-
clusters: []
|
|
140
|
-
}, mouseEvent2);
|
|
141
|
-
expect(callbackMock).toHaveBeenCalledWith(undefined, { nodes: [], relationships: [], clusters: [] }, mouseEvent2);
|
|
142
|
-
expect(callbackMock).toHaveBeenCalledTimes(2);
|
|
143
|
-
});
|
|
144
|
-
it('should register un-hover event for relationship', () => {
|
|
145
|
-
const mouseEvent = new MouseEvent('mousemove', {
|
|
146
|
-
clientX: 150,
|
|
147
|
-
clientY: 150
|
|
148
|
-
});
|
|
149
|
-
hoverInteraction.handleHover(mouseEvent);
|
|
150
|
-
expect(callbackMock).toHaveBeenCalledWith({ id: '10', from: '0', to: '1', hovered: true }, {
|
|
151
|
-
nodes: [],
|
|
152
|
-
relationships: [
|
|
153
|
-
{
|
|
154
|
-
data: { id: '10', from: '0', to: '1', hovered: true },
|
|
155
|
-
distance: 0,
|
|
156
|
-
fromTargetCoordinates: { x: 100, y: 100 },
|
|
157
|
-
toTargetCoordinates: { x: 200, y: 200 },
|
|
158
|
-
pointerCoordinates: { x: 150, y: 150 }
|
|
159
|
-
}
|
|
160
|
-
],
|
|
161
|
-
clusters: []
|
|
162
|
-
}, mouseEvent);
|
|
163
|
-
expect(callbackMock).toHaveBeenCalledTimes(1);
|
|
164
|
-
const mouseEvent2 = new MouseEvent('mousemove', {
|
|
165
|
-
clientX: 10,
|
|
166
|
-
clientY: 10
|
|
167
|
-
});
|
|
168
|
-
hoverInteraction.handleHover(mouseEvent2);
|
|
169
|
-
expect(callbackMock).toHaveBeenCalledWith({ id: '10', from: '0', to: '1', hovered: false }, {
|
|
170
|
-
nodes: [],
|
|
171
|
-
relationships: [
|
|
172
|
-
{
|
|
173
|
-
data: { id: '10', from: '0', to: '1', hovered: false },
|
|
174
|
-
distance: 0,
|
|
175
|
-
fromTargetCoordinates: { x: 100, y: 100 },
|
|
176
|
-
toTargetCoordinates: { x: 200, y: 200 },
|
|
177
|
-
pointerCoordinates: { x: 150, y: 150 }
|
|
178
|
-
}
|
|
179
|
-
],
|
|
180
|
-
clusters: []
|
|
181
|
-
}, mouseEvent2);
|
|
182
|
-
expect(callbackMock).toHaveBeenCalledWith(undefined, { nodes: [], relationships: [], clusters: [] }, mouseEvent2);
|
|
183
|
-
expect(callbackMock).toHaveBeenCalledTimes(2);
|
|
184
|
-
});
|
|
185
|
-
it('should un-hover node and hover relationships when moving mouse from node to relationship', () => {
|
|
186
|
-
const mouseEvent = new MouseEvent('mousemove', {
|
|
187
|
-
clientX: 100,
|
|
188
|
-
clientY: 100
|
|
189
|
-
});
|
|
190
|
-
hoverInteraction.handleHover(mouseEvent);
|
|
191
|
-
expect(callbackMock).toHaveBeenCalledWith({ id: '0', x: 100, y: 100, hovered: true }, {
|
|
192
|
-
nodes: [
|
|
193
|
-
{
|
|
194
|
-
data: { id: '0', x: 100, y: 100, hovered: true },
|
|
195
|
-
distance: 0,
|
|
196
|
-
targetCoordinates: { x: 100, y: 100 },
|
|
197
|
-
pointerCoordinates: { x: 100, y: 100 },
|
|
198
|
-
distanceVector: { x: 0, y: 0 },
|
|
199
|
-
insideNode: true
|
|
200
|
-
}
|
|
201
|
-
],
|
|
202
|
-
relationships: [
|
|
203
|
-
{
|
|
204
|
-
data: { id: '10', from: '0', to: '1' },
|
|
205
|
-
distance: 0,
|
|
206
|
-
fromTargetCoordinates: { x: 100, y: 100 },
|
|
207
|
-
toTargetCoordinates: { x: 200, y: 200 },
|
|
208
|
-
pointerCoordinates: { x: 100, y: 100 }
|
|
209
|
-
}
|
|
210
|
-
],
|
|
211
|
-
clusters: []
|
|
212
|
-
}, mouseEvent);
|
|
213
|
-
expect(callbackMock).toHaveBeenCalledTimes(1);
|
|
214
|
-
const mouseEvent2 = new MouseEvent('mousemove', {
|
|
215
|
-
clientX: 150,
|
|
216
|
-
clientY: 150
|
|
217
|
-
});
|
|
218
|
-
hoverInteraction.handleHover(mouseEvent2);
|
|
219
|
-
expect(callbackMock).toHaveBeenCalledWith({ id: '0', x: 100, y: 100, hovered: false }, {
|
|
220
|
-
nodes: [
|
|
221
|
-
{
|
|
222
|
-
data: { id: '0', x: 100, y: 100, hovered: false },
|
|
223
|
-
distance: 0,
|
|
224
|
-
targetCoordinates: { x: 100, y: 100 },
|
|
225
|
-
pointerCoordinates: { x: 100, y: 100 },
|
|
226
|
-
distanceVector: { x: 0, y: 0 },
|
|
227
|
-
insideNode: true
|
|
228
|
-
}
|
|
229
|
-
],
|
|
230
|
-
relationships: [
|
|
231
|
-
{
|
|
232
|
-
data: { id: '10', from: '0', to: '1', hovered: true },
|
|
233
|
-
distance: 0,
|
|
234
|
-
fromTargetCoordinates: { x: 100, y: 100 },
|
|
235
|
-
toTargetCoordinates: { x: 200, y: 200 },
|
|
236
|
-
pointerCoordinates: { x: 100, y: 100 }
|
|
237
|
-
}
|
|
238
|
-
],
|
|
239
|
-
clusters: []
|
|
240
|
-
}, mouseEvent2);
|
|
241
|
-
expect(callbackMock).toHaveBeenCalledWith({ id: '10', from: '0', to: '1', hovered: true }, {
|
|
242
|
-
nodes: [],
|
|
243
|
-
relationships: [
|
|
244
|
-
{
|
|
245
|
-
data: { id: '10', from: '0', to: '1', hovered: true },
|
|
246
|
-
distance: 0,
|
|
247
|
-
fromTargetCoordinates: { x: 100, y: 100 },
|
|
248
|
-
toTargetCoordinates: { x: 200, y: 200 },
|
|
249
|
-
pointerCoordinates: { x: 150, y: 150 }
|
|
250
|
-
}
|
|
251
|
-
],
|
|
252
|
-
clusters: []
|
|
253
|
-
}, mouseEvent2);
|
|
254
|
-
expect(callbackMock).toHaveBeenCalledTimes(2);
|
|
255
|
-
});
|
|
256
|
-
it('should un-hover relationship and hover node when moving mouse from relationship to node', () => {
|
|
257
|
-
const mouseEvent = new MouseEvent('mousemove', {
|
|
258
|
-
clientX: 150,
|
|
259
|
-
clientY: 150
|
|
260
|
-
});
|
|
261
|
-
hoverInteraction.handleHover(mouseEvent);
|
|
262
|
-
expect(callbackMock).toHaveBeenCalledWith({ id: '10', from: '0', to: '1', hovered: true }, {
|
|
263
|
-
nodes: [],
|
|
264
|
-
relationships: [
|
|
265
|
-
{
|
|
266
|
-
data: { id: '10', from: '0', to: '1', hovered: true },
|
|
267
|
-
distance: 0,
|
|
268
|
-
fromTargetCoordinates: { x: 100, y: 100 },
|
|
269
|
-
toTargetCoordinates: { x: 200, y: 200 },
|
|
270
|
-
pointerCoordinates: { x: 150, y: 150 }
|
|
271
|
-
}
|
|
272
|
-
],
|
|
273
|
-
clusters: []
|
|
274
|
-
}, mouseEvent);
|
|
275
|
-
expect(callbackMock).toHaveBeenCalledTimes(1);
|
|
276
|
-
const mouseEvent2 = new MouseEvent('mousemove', {
|
|
277
|
-
clientX: 100,
|
|
278
|
-
clientY: 100
|
|
279
|
-
});
|
|
280
|
-
hoverInteraction.handleHover(mouseEvent2);
|
|
281
|
-
expect(callbackMock).toHaveBeenCalledWith({ id: '0', x: 100, y: 100, hovered: true }, {
|
|
282
|
-
nodes: [
|
|
283
|
-
{
|
|
284
|
-
data: { id: '0', x: 100, y: 100, hovered: true },
|
|
285
|
-
distance: 0,
|
|
286
|
-
targetCoordinates: { x: 100, y: 100 },
|
|
287
|
-
pointerCoordinates: { x: 100, y: 100 },
|
|
288
|
-
distanceVector: { x: 0, y: 0 },
|
|
289
|
-
insideNode: true
|
|
290
|
-
}
|
|
291
|
-
],
|
|
292
|
-
relationships: [
|
|
293
|
-
{
|
|
294
|
-
data: { id: '10', from: '0', to: '1', hovered: false },
|
|
295
|
-
distance: 0,
|
|
296
|
-
fromTargetCoordinates: { x: 100, y: 100 },
|
|
297
|
-
toTargetCoordinates: { x: 200, y: 200 },
|
|
298
|
-
pointerCoordinates: { x: 100, y: 100 }
|
|
299
|
-
}
|
|
300
|
-
],
|
|
301
|
-
clusters: []
|
|
302
|
-
}, mouseEvent2);
|
|
303
|
-
expect(callbackMock).toHaveBeenCalledWith({ id: '10', from: '0', to: '1', hovered: false }, {
|
|
304
|
-
nodes: [],
|
|
305
|
-
relationships: [
|
|
306
|
-
{
|
|
307
|
-
data: { id: '10', from: '0', to: '1', hovered: false },
|
|
308
|
-
distance: 0,
|
|
309
|
-
fromTargetCoordinates: { x: 100, y: 100 },
|
|
310
|
-
toTargetCoordinates: { x: 200, y: 200 },
|
|
311
|
-
pointerCoordinates: { x: 150, y: 150 }
|
|
312
|
-
}
|
|
313
|
-
],
|
|
314
|
-
clusters: []
|
|
315
|
-
}, mouseEvent2);
|
|
316
|
-
expect(callbackMock).toHaveBeenCalledTimes(2);
|
|
317
|
-
});
|
|
318
|
-
it('should report a hovered cluster', () => {
|
|
319
|
-
const nvlTargets = {
|
|
320
|
-
nodes: [],
|
|
321
|
-
relationships: [],
|
|
322
|
-
clusters: [
|
|
323
|
-
{
|
|
324
|
-
data: { id: 'group-a', nodeIds: ['0', '1'] },
|
|
325
|
-
pointerCoordinates: { x: 50, y: 50 },
|
|
326
|
-
hull: [
|
|
327
|
-
{ x: 0, y: 0 },
|
|
328
|
-
{ x: 100, y: 0 },
|
|
329
|
-
{ x: 100, y: 100 },
|
|
330
|
-
{ x: 0, y: 100 }
|
|
331
|
-
]
|
|
332
|
-
}
|
|
333
|
-
]
|
|
334
|
-
};
|
|
335
|
-
jest.spyOn(myNVL, 'getHits').mockImplementation((event) => Object.assign(event, { nvlTargets }));
|
|
336
|
-
const mouseEvent = new MouseEvent('mousemove', { clientX: 50, clientY: 50 });
|
|
337
|
-
hoverInteraction.handleHover(mouseEvent);
|
|
338
|
-
expect(callbackMock).toHaveBeenCalledWith(undefined, nvlTargets, mouseEvent);
|
|
339
|
-
expect(callbackMock).toHaveBeenCalledTimes(1);
|
|
340
|
-
});
|
|
341
|
-
it('should keep the cluster in the hit elements when hovering one of its nodes', () => {
|
|
342
|
-
const nvlTargets = {
|
|
343
|
-
nodes: [
|
|
344
|
-
{
|
|
345
|
-
data: { id: '0', x: 100, y: 100 },
|
|
346
|
-
distance: 0,
|
|
347
|
-
targetCoordinates: { x: 100, y: 100 },
|
|
348
|
-
pointerCoordinates: { x: 100, y: 100 },
|
|
349
|
-
distanceVector: { x: 0, y: 0 },
|
|
350
|
-
insideNode: true
|
|
351
|
-
}
|
|
352
|
-
],
|
|
353
|
-
relationships: [],
|
|
354
|
-
clusters: [
|
|
355
|
-
{
|
|
356
|
-
data: { id: 'group-a', nodeIds: ['0', '1'] },
|
|
357
|
-
pointerCoordinates: { x: 100, y: 100 },
|
|
358
|
-
hull: [
|
|
359
|
-
{ x: 0, y: 0 },
|
|
360
|
-
{ x: 200, y: 0 },
|
|
361
|
-
{ x: 200, y: 200 },
|
|
362
|
-
{ x: 0, y: 200 }
|
|
363
|
-
]
|
|
364
|
-
}
|
|
365
|
-
]
|
|
366
|
-
};
|
|
367
|
-
jest.spyOn(myNVL, 'getHits').mockImplementation((event) => Object.assign(event, { nvlTargets }));
|
|
368
|
-
const mouseEvent = new MouseEvent('mousemove', { clientX: 100, clientY: 100 });
|
|
369
|
-
hoverInteraction.handleHover(mouseEvent);
|
|
370
|
-
expect(callbackMock).toHaveBeenCalledWith({ id: '0', x: 100, y: 100 }, nvlTargets, mouseEvent);
|
|
371
|
-
expect(callbackMock).toHaveBeenCalledTimes(1);
|
|
372
|
-
});
|
|
373
|
-
});
|
|
374
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import '@testing-library/jest-dom';
|