@pie-lib/graphing 4.0.23 → 4.0.24-beta.1
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 +0 -92
- package/lib/mark-label.js +7 -197
- package/lib/mark-label.js.map +1 -1
- package/lib/tools/circle/component.js +3 -34
- package/lib/tools/circle/component.js.map +1 -1
- package/lib/tools/point/component.js +8 -29
- package/lib/tools/point/component.js.map +1 -1
- package/lib/tools/polygon/component.js +6 -31
- package/lib/tools/polygon/component.js.map +1 -1
- package/lib/tools/shared/line/index.js +3 -34
- package/lib/tools/shared/line/index.js.map +1 -1
- package/package.json +17 -17
- package/src/mark-label.jsx +8 -209
- package/src/tools/circle/component.jsx +3 -26
- package/src/tools/point/component.jsx +8 -21
- package/src/tools/polygon/component.jsx +6 -24
- package/src/tools/shared/line/index.jsx +3 -26
- package/LICENSE.md +0 -5
- package/src/__tests__/bg.test.jsx +0 -250
- package/src/__tests__/coordinates-label.test.jsx +0 -243
- package/src/__tests__/graph-with-controls.test.jsx +0 -198
- package/src/__tests__/graph.test.jsx +0 -796
- package/src/__tests__/grid-setup.test.jsx +0 -645
- package/src/__tests__/grid.test.jsx +0 -22
- package/src/__tests__/key-legend.test.jsx +0 -260
- package/src/__tests__/label-svg-icon.test.jsx +0 -278
- package/src/__tests__/labels.test.jsx +0 -55
- package/src/__tests__/mark-label.test.jsx +0 -437
- package/src/__tests__/toggle-bar.test.jsx +0 -146
- package/src/__tests__/tool-menu.test.jsx +0 -115
- package/src/__tests__/undo-redo.test.jsx +0 -24
- package/src/__tests__/use-debounce.test.js +0 -21
- package/src/__tests__/utils.js +0 -41
- package/src/__tests__/utils.test.js +0 -105
- package/src/axis/__tests__/arrow.test.jsx +0 -38
- package/src/axis/__tests__/axes.test.jsx +0 -216
- package/src/container/__tests__/actions.test.js +0 -105
- package/src/container/__tests__/index.test.jsx +0 -319
- package/src/container/__tests__/marks.test.js +0 -172
- package/src/container/__tests__/middleware.test.js +0 -235
- package/src/container/__tests__/reducer.test.js +0 -324
- package/src/tools/absolute/__tests__/component.test.jsx +0 -53
- package/src/tools/circle/__tests__/bg-circle.test.jsx +0 -26
- package/src/tools/circle/__tests__/component.test.jsx +0 -494
- package/src/tools/circle/__tests__/index.test.js +0 -480
- package/src/tools/exponential/__tests__/component.test.jsx +0 -53
- package/src/tools/exponential/__tests__/index.test.js +0 -729
- package/src/tools/line/__tests__/component.test.jsx +0 -37
- package/src/tools/parabola/__tests__/component.test.jsx +0 -48
- package/src/tools/parabola/__tests__/index.test.js +0 -470
- package/src/tools/point/__tests__/component.test.jsx +0 -475
- package/src/tools/point/__tests__/index.test.js +0 -241
- package/src/tools/polygon/__tests__/component.test.jsx +0 -471
- package/src/tools/polygon/__tests__/index.test.js +0 -294
- package/src/tools/polygon/__tests__/line.test.jsx +0 -35
- package/src/tools/polygon/__tests__/polygon.test.jsx +0 -61
- package/src/tools/ray/__tests__/component.test.jsx +0 -29
- package/src/tools/segment/__tests__/component.test.jsx +0 -28
- package/src/tools/shared/__tests__/arrow-head.test.jsx +0 -31
- package/src/tools/shared/line/__tests__/index.test.jsx +0 -109
- package/src/tools/shared/line/__tests__/line-path.test.jsx +0 -53
- package/src/tools/shared/line/__tests__/with-root-edge.test.jsx +0 -73
- package/src/tools/shared/point/__tests__/arrow-point.test.jsx +0 -91
- package/src/tools/shared/point/__tests__/base-point.test.jsx +0 -87
- package/src/tools/sine/__tests__/component.test.jsx +0 -51
- package/src/tools/vector/__tests__/component.test.jsx +0 -25
|
@@ -1,480 +0,0 @@
|
|
|
1
|
-
import { tool } from '../index';
|
|
2
|
-
import { equalPoints } from '../../../utils';
|
|
3
|
-
|
|
4
|
-
jest.mock('../../../utils', () => ({
|
|
5
|
-
equalPoints: jest.fn(),
|
|
6
|
-
}));
|
|
7
|
-
|
|
8
|
-
describe('circle tool', () => {
|
|
9
|
-
let circleTool;
|
|
10
|
-
|
|
11
|
-
beforeEach(() => {
|
|
12
|
-
jest.clearAllMocks();
|
|
13
|
-
circleTool = tool();
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
describe('tool configuration', () => {
|
|
17
|
-
it('creates a tool object', () => {
|
|
18
|
-
expect(circleTool).toBeDefined();
|
|
19
|
-
expect(typeof circleTool).toBe('object');
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
it('has type circle', () => {
|
|
23
|
-
expect(circleTool.type).toBe('circle');
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it('has a Component', () => {
|
|
27
|
-
expect(circleTool.Component).toBeDefined();
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it('has hover function', () => {
|
|
31
|
-
expect(typeof circleTool.hover).toBe('function');
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it('has addPoint function', () => {
|
|
35
|
-
expect(typeof circleTool.addPoint).toBe('function');
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
describe('hover', () => {
|
|
40
|
-
it('returns mark with edge point', () => {
|
|
41
|
-
const point = { x: 5, y: 10 };
|
|
42
|
-
const mark = { type: 'circle', root: { x: 0, y: 0 } };
|
|
43
|
-
|
|
44
|
-
const result = circleTool.hover(point, mark);
|
|
45
|
-
|
|
46
|
-
expect(result).toEqual({ ...mark, edge: point });
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it('updates existing mark with new edge', () => {
|
|
50
|
-
const point = { x: 7, y: 8 };
|
|
51
|
-
const mark = {
|
|
52
|
-
type: 'circle',
|
|
53
|
-
root: { x: 1, y: 1 },
|
|
54
|
-
edge: { x: 3, y: 3 },
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
const result = circleTool.hover(point, mark);
|
|
58
|
-
|
|
59
|
-
expect(result.edge).toEqual(point);
|
|
60
|
-
expect(result.root).toEqual(mark.root);
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it('preserves mark properties', () => {
|
|
64
|
-
const point = { x: 5, y: 5 };
|
|
65
|
-
const mark = {
|
|
66
|
-
type: 'circle',
|
|
67
|
-
root: { x: 0, y: 0 },
|
|
68
|
-
label: 'Circle A',
|
|
69
|
-
correctness: { value: 'correct' },
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
const result = circleTool.hover(point, mark);
|
|
73
|
-
|
|
74
|
-
expect(result.label).toBe('Circle A');
|
|
75
|
-
expect(result.correctness).toEqual({ value: 'correct' });
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it('handles null mark', () => {
|
|
79
|
-
const point = { x: 5, y: 10 };
|
|
80
|
-
const mark = null;
|
|
81
|
-
|
|
82
|
-
const result = circleTool.hover(point, mark);
|
|
83
|
-
|
|
84
|
-
expect(result).toEqual({ edge: point });
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
it('handles undefined mark', () => {
|
|
88
|
-
const point = { x: 5, y: 10 };
|
|
89
|
-
const mark = undefined;
|
|
90
|
-
|
|
91
|
-
const result = circleTool.hover(point, mark);
|
|
92
|
-
|
|
93
|
-
expect(result).toEqual({ edge: point });
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
it('works with negative coordinates', () => {
|
|
97
|
-
const point = { x: -5, y: -10 };
|
|
98
|
-
const mark = { type: 'circle', root: { x: -1, y: -1 } };
|
|
99
|
-
|
|
100
|
-
const result = circleTool.hover(point, mark);
|
|
101
|
-
|
|
102
|
-
expect(result.edge).toEqual(point);
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
it('works with decimal coordinates', () => {
|
|
106
|
-
const point = { x: 3.5, y: 7.8 };
|
|
107
|
-
const mark = { type: 'circle', root: { x: 1.2, y: 2.4 } };
|
|
108
|
-
|
|
109
|
-
const result = circleTool.hover(point, mark);
|
|
110
|
-
|
|
111
|
-
expect(result.edge).toEqual(point);
|
|
112
|
-
});
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
describe('addPoint', () => {
|
|
116
|
-
describe('first point (creating root)', () => {
|
|
117
|
-
it('creates new circle mark when no mark exists', () => {
|
|
118
|
-
const point = { x: 5, y: 10 };
|
|
119
|
-
const mark = null;
|
|
120
|
-
equalPoints.mockReturnValue(false);
|
|
121
|
-
|
|
122
|
-
const result = circleTool.addPoint(point, mark);
|
|
123
|
-
|
|
124
|
-
expect(result).toEqual({
|
|
125
|
-
type: 'circle',
|
|
126
|
-
root: point,
|
|
127
|
-
building: true,
|
|
128
|
-
});
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
it('creates building circle with correct properties', () => {
|
|
132
|
-
const point = { x: 3, y: 7 };
|
|
133
|
-
equalPoints.mockReturnValue(false);
|
|
134
|
-
|
|
135
|
-
const result = circleTool.addPoint(point, null);
|
|
136
|
-
|
|
137
|
-
expect(result.type).toBe('circle');
|
|
138
|
-
expect(result.root).toEqual(point);
|
|
139
|
-
expect(result.building).toBe(true);
|
|
140
|
-
expect(result.edge).toBeUndefined();
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
it('works with negative coordinates', () => {
|
|
144
|
-
const point = { x: -5, y: -10 };
|
|
145
|
-
equalPoints.mockReturnValue(false);
|
|
146
|
-
|
|
147
|
-
const result = circleTool.addPoint(point, null);
|
|
148
|
-
|
|
149
|
-
expect(result.root).toEqual(point);
|
|
150
|
-
expect(result.building).toBe(true);
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
it('works with zero coordinates', () => {
|
|
154
|
-
const point = { x: 0, y: 0 };
|
|
155
|
-
equalPoints.mockReturnValue(false);
|
|
156
|
-
|
|
157
|
-
const result = circleTool.addPoint(point, null);
|
|
158
|
-
|
|
159
|
-
expect(result.root).toEqual(point);
|
|
160
|
-
expect(result.building).toBe(true);
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
it('works with decimal coordinates', () => {
|
|
164
|
-
const point = { x: 3.5, y: 7.25 };
|
|
165
|
-
equalPoints.mockReturnValue(false);
|
|
166
|
-
|
|
167
|
-
const result = circleTool.addPoint(point, null);
|
|
168
|
-
|
|
169
|
-
expect(result.root).toEqual(point);
|
|
170
|
-
expect(result.building).toBe(true);
|
|
171
|
-
});
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
describe('second point (completing circle)', () => {
|
|
175
|
-
it('completes circle when adding edge point', () => {
|
|
176
|
-
const root = { x: 0, y: 0 };
|
|
177
|
-
const edge = { x: 5, y: 5 };
|
|
178
|
-
const mark = {
|
|
179
|
-
type: 'circle',
|
|
180
|
-
root,
|
|
181
|
-
building: true,
|
|
182
|
-
};
|
|
183
|
-
equalPoints.mockReturnValue(false);
|
|
184
|
-
|
|
185
|
-
const result = circleTool.addPoint(edge, mark);
|
|
186
|
-
|
|
187
|
-
expect(result).toEqual({
|
|
188
|
-
...mark,
|
|
189
|
-
edge,
|
|
190
|
-
building: false,
|
|
191
|
-
});
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
it('sets building to false', () => {
|
|
195
|
-
const mark = {
|
|
196
|
-
type: 'circle',
|
|
197
|
-
root: { x: 1, y: 1 },
|
|
198
|
-
building: true,
|
|
199
|
-
};
|
|
200
|
-
const point = { x: 5, y: 5 };
|
|
201
|
-
equalPoints.mockReturnValue(false);
|
|
202
|
-
|
|
203
|
-
const result = circleTool.addPoint(point, mark);
|
|
204
|
-
|
|
205
|
-
expect(result.building).toBe(false);
|
|
206
|
-
});
|
|
207
|
-
|
|
208
|
-
it('preserves mark type', () => {
|
|
209
|
-
const mark = {
|
|
210
|
-
type: 'circle',
|
|
211
|
-
root: { x: 1, y: 1 },
|
|
212
|
-
building: true,
|
|
213
|
-
};
|
|
214
|
-
const point = { x: 5, y: 5 };
|
|
215
|
-
equalPoints.mockReturnValue(false);
|
|
216
|
-
|
|
217
|
-
const result = circleTool.addPoint(point, mark);
|
|
218
|
-
|
|
219
|
-
expect(result.type).toBe('circle');
|
|
220
|
-
});
|
|
221
|
-
|
|
222
|
-
it('preserves root when adding edge', () => {
|
|
223
|
-
const root = { x: 2, y: 3 };
|
|
224
|
-
const mark = {
|
|
225
|
-
type: 'circle',
|
|
226
|
-
root,
|
|
227
|
-
building: true,
|
|
228
|
-
};
|
|
229
|
-
const edge = { x: 8, y: 9 };
|
|
230
|
-
equalPoints.mockReturnValue(false);
|
|
231
|
-
|
|
232
|
-
const result = circleTool.addPoint(edge, mark);
|
|
233
|
-
|
|
234
|
-
expect(result.root).toEqual(root);
|
|
235
|
-
expect(result.edge).toEqual(edge);
|
|
236
|
-
});
|
|
237
|
-
|
|
238
|
-
it('works with large radius', () => {
|
|
239
|
-
const root = { x: 0, y: 0 };
|
|
240
|
-
const edge = { x: 100, y: 100 };
|
|
241
|
-
const mark = {
|
|
242
|
-
type: 'circle',
|
|
243
|
-
root,
|
|
244
|
-
building: true,
|
|
245
|
-
};
|
|
246
|
-
equalPoints.mockReturnValue(false);
|
|
247
|
-
|
|
248
|
-
const result = circleTool.addPoint(edge, mark);
|
|
249
|
-
|
|
250
|
-
expect(result.edge).toEqual(edge);
|
|
251
|
-
expect(result.building).toBe(false);
|
|
252
|
-
});
|
|
253
|
-
|
|
254
|
-
it('works with small radius', () => {
|
|
255
|
-
const root = { x: 5, y: 5 };
|
|
256
|
-
const edge = { x: 5.1, y: 5.1 };
|
|
257
|
-
const mark = {
|
|
258
|
-
type: 'circle',
|
|
259
|
-
root,
|
|
260
|
-
building: true,
|
|
261
|
-
};
|
|
262
|
-
equalPoints.mockReturnValue(false);
|
|
263
|
-
|
|
264
|
-
const result = circleTool.addPoint(edge, mark);
|
|
265
|
-
|
|
266
|
-
expect(result.edge).toEqual(edge);
|
|
267
|
-
expect(result.building).toBe(false);
|
|
268
|
-
});
|
|
269
|
-
});
|
|
270
|
-
|
|
271
|
-
describe('same point handling', () => {
|
|
272
|
-
it('returns same mark when clicking same point as root', () => {
|
|
273
|
-
const point = { x: 5, y: 10 };
|
|
274
|
-
const mark = {
|
|
275
|
-
type: 'circle',
|
|
276
|
-
root: point,
|
|
277
|
-
building: true,
|
|
278
|
-
};
|
|
279
|
-
equalPoints.mockReturnValue(true);
|
|
280
|
-
|
|
281
|
-
const result = circleTool.addPoint(point, mark);
|
|
282
|
-
|
|
283
|
-
expect(result).toBe(mark);
|
|
284
|
-
});
|
|
285
|
-
|
|
286
|
-
it('calls equalPoints with correct arguments', () => {
|
|
287
|
-
const point = { x: 5, y: 10 };
|
|
288
|
-
const mark = {
|
|
289
|
-
type: 'circle',
|
|
290
|
-
root: { x: 5, y: 10 },
|
|
291
|
-
building: true,
|
|
292
|
-
};
|
|
293
|
-
equalPoints.mockReturnValue(true);
|
|
294
|
-
|
|
295
|
-
circleTool.addPoint(point, mark);
|
|
296
|
-
|
|
297
|
-
expect(equalPoints).toHaveBeenCalledWith(mark.root, point);
|
|
298
|
-
});
|
|
299
|
-
|
|
300
|
-
it('prevents zero-radius circle', () => {
|
|
301
|
-
const point = { x: 5, y: 10 };
|
|
302
|
-
const mark = {
|
|
303
|
-
type: 'circle',
|
|
304
|
-
root: { x: 5, y: 10 },
|
|
305
|
-
building: true,
|
|
306
|
-
};
|
|
307
|
-
equalPoints.mockReturnValue(true);
|
|
308
|
-
|
|
309
|
-
const result = circleTool.addPoint(point, mark);
|
|
310
|
-
|
|
311
|
-
// Should return unchanged mark, not complete the circle
|
|
312
|
-
expect(result).toBe(mark);
|
|
313
|
-
expect(result.building).toBe(true);
|
|
314
|
-
});
|
|
315
|
-
});
|
|
316
|
-
|
|
317
|
-
describe('edge cases', () => {
|
|
318
|
-
it('handles undefined mark on first click', () => {
|
|
319
|
-
const point = { x: 5, y: 10 };
|
|
320
|
-
equalPoints.mockReturnValue(false);
|
|
321
|
-
|
|
322
|
-
const result = circleTool.addPoint(point, undefined);
|
|
323
|
-
|
|
324
|
-
expect(result.type).toBe('circle');
|
|
325
|
-
expect(result.root).toEqual(point);
|
|
326
|
-
expect(result.building).toBe(true);
|
|
327
|
-
});
|
|
328
|
-
|
|
329
|
-
it('handles mark with additional properties', () => {
|
|
330
|
-
const mark = {
|
|
331
|
-
type: 'circle',
|
|
332
|
-
root: { x: 1, y: 1 },
|
|
333
|
-
building: true,
|
|
334
|
-
label: 'Circle 1',
|
|
335
|
-
correctness: { value: 'correct' },
|
|
336
|
-
};
|
|
337
|
-
const point = { x: 5, y: 5 };
|
|
338
|
-
equalPoints.mockReturnValue(false);
|
|
339
|
-
|
|
340
|
-
const result = circleTool.addPoint(point, mark);
|
|
341
|
-
|
|
342
|
-
expect(result.label).toBe('Circle 1');
|
|
343
|
-
expect(result.correctness).toEqual({ value: 'correct' });
|
|
344
|
-
expect(result.edge).toEqual(point);
|
|
345
|
-
expect(result.building).toBe(false);
|
|
346
|
-
});
|
|
347
|
-
|
|
348
|
-
it('handles mark with existing edge', () => {
|
|
349
|
-
const mark = {
|
|
350
|
-
type: 'circle',
|
|
351
|
-
root: { x: 0, y: 0 },
|
|
352
|
-
edge: { x: 3, y: 3 },
|
|
353
|
-
building: true,
|
|
354
|
-
};
|
|
355
|
-
const newEdge = { x: 5, y: 5 };
|
|
356
|
-
equalPoints.mockReturnValue(false);
|
|
357
|
-
|
|
358
|
-
const result = circleTool.addPoint(newEdge, mark);
|
|
359
|
-
|
|
360
|
-
expect(result.edge).toEqual(newEdge);
|
|
361
|
-
expect(result.building).toBe(false);
|
|
362
|
-
});
|
|
363
|
-
|
|
364
|
-
it('works with point at origin', () => {
|
|
365
|
-
const point = { x: 0, y: 0 };
|
|
366
|
-
equalPoints.mockReturnValue(false);
|
|
367
|
-
|
|
368
|
-
const result = circleTool.addPoint(point, null);
|
|
369
|
-
|
|
370
|
-
expect(result.root).toEqual(point);
|
|
371
|
-
expect(result.building).toBe(true);
|
|
372
|
-
});
|
|
373
|
-
|
|
374
|
-
it('works with very large coordinates', () => {
|
|
375
|
-
const point = { x: 1000, y: 1000 };
|
|
376
|
-
equalPoints.mockReturnValue(false);
|
|
377
|
-
|
|
378
|
-
const result = circleTool.addPoint(point, null);
|
|
379
|
-
|
|
380
|
-
expect(result.root).toEqual(point);
|
|
381
|
-
expect(result.building).toBe(true);
|
|
382
|
-
});
|
|
383
|
-
|
|
384
|
-
it('works with negative coordinates', () => {
|
|
385
|
-
const point = { x: -10, y: -20 };
|
|
386
|
-
equalPoints.mockReturnValue(false);
|
|
387
|
-
|
|
388
|
-
const result = circleTool.addPoint(point, null);
|
|
389
|
-
|
|
390
|
-
expect(result.root).toEqual(point);
|
|
391
|
-
expect(result.building).toBe(true);
|
|
392
|
-
});
|
|
393
|
-
});
|
|
394
|
-
|
|
395
|
-
describe('immutability', () => {
|
|
396
|
-
it('does not mutate original mark when adding edge', () => {
|
|
397
|
-
const mark = {
|
|
398
|
-
type: 'circle',
|
|
399
|
-
root: { x: 1, y: 1 },
|
|
400
|
-
building: true,
|
|
401
|
-
};
|
|
402
|
-
const originalMark = { ...mark };
|
|
403
|
-
const point = { x: 5, y: 5 };
|
|
404
|
-
equalPoints.mockReturnValue(false);
|
|
405
|
-
|
|
406
|
-
const result = circleTool.addPoint(point, mark);
|
|
407
|
-
|
|
408
|
-
expect(mark).toEqual(originalMark);
|
|
409
|
-
expect(result).not.toBe(mark);
|
|
410
|
-
});
|
|
411
|
-
|
|
412
|
-
it('does not mutate original mark when returning same', () => {
|
|
413
|
-
const mark = {
|
|
414
|
-
type: 'circle',
|
|
415
|
-
root: { x: 5, y: 10 },
|
|
416
|
-
building: true,
|
|
417
|
-
};
|
|
418
|
-
const point = { x: 5, y: 10 };
|
|
419
|
-
equalPoints.mockReturnValue(true);
|
|
420
|
-
|
|
421
|
-
const result = circleTool.addPoint(point, mark);
|
|
422
|
-
|
|
423
|
-
expect(result).toBe(mark);
|
|
424
|
-
});
|
|
425
|
-
});
|
|
426
|
-
});
|
|
427
|
-
|
|
428
|
-
describe('integration scenarios', () => {
|
|
429
|
-
it('handles full circle creation flow', () => {
|
|
430
|
-
equalPoints.mockReturnValue(false);
|
|
431
|
-
|
|
432
|
-
// First click - create root
|
|
433
|
-
const firstPoint = { x: 5, y: 5 };
|
|
434
|
-
const mark1 = circleTool.addPoint(firstPoint, null);
|
|
435
|
-
expect(mark1.root).toEqual(firstPoint);
|
|
436
|
-
expect(mark1.building).toBe(true);
|
|
437
|
-
|
|
438
|
-
// Hover - show preview
|
|
439
|
-
const hoverPoint = { x: 10, y: 10 };
|
|
440
|
-
const mark2 = circleTool.hover(hoverPoint, mark1);
|
|
441
|
-
expect(mark2.edge).toEqual(hoverPoint);
|
|
442
|
-
|
|
443
|
-
// Second click - complete circle
|
|
444
|
-
const secondPoint = { x: 10, y: 5 };
|
|
445
|
-
const mark3 = circleTool.addPoint(secondPoint, mark1);
|
|
446
|
-
expect(mark3.root).toEqual(firstPoint);
|
|
447
|
-
expect(mark3.edge).toEqual(secondPoint);
|
|
448
|
-
expect(mark3.building).toBe(false);
|
|
449
|
-
});
|
|
450
|
-
|
|
451
|
-
it('handles attempted zero-radius circle', () => {
|
|
452
|
-
const point = { x: 5, y: 5 };
|
|
453
|
-
|
|
454
|
-
// First click
|
|
455
|
-
equalPoints.mockReturnValue(false);
|
|
456
|
-
const mark1 = circleTool.addPoint(point, null);
|
|
457
|
-
|
|
458
|
-
// Second click at same point
|
|
459
|
-
equalPoints.mockReturnValue(true);
|
|
460
|
-
const mark2 = circleTool.addPoint(point, mark1);
|
|
461
|
-
|
|
462
|
-
// Should return unchanged mark
|
|
463
|
-
expect(mark2).toBe(mark1);
|
|
464
|
-
expect(mark2.building).toBe(true);
|
|
465
|
-
});
|
|
466
|
-
|
|
467
|
-
it('handles circle with labels', () => {
|
|
468
|
-
equalPoints.mockReturnValue(false);
|
|
469
|
-
|
|
470
|
-
const firstPoint = { x: 0, y: 0, label: 'Center' };
|
|
471
|
-
const mark1 = circleTool.addPoint(firstPoint, null);
|
|
472
|
-
|
|
473
|
-
const secondPoint = { x: 5, y: 0, label: 'Edge' };
|
|
474
|
-
const mark2 = circleTool.addPoint(secondPoint, mark1);
|
|
475
|
-
|
|
476
|
-
expect(mark2.root.label).toBe('Center');
|
|
477
|
-
expect(mark2.building).toBe(false);
|
|
478
|
-
});
|
|
479
|
-
});
|
|
480
|
-
});
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { withRootEdge } from '../../shared/line/with-root-edge';
|
|
2
|
-
import { buildDataPoints, exponentialFromTwoPoints } from '@pie-lib/graphing-utils';
|
|
3
|
-
import { utils } from '@pie-lib/plot';
|
|
4
|
-
|
|
5
|
-
import { graphProps as getGraphProps } from '../../../__tests__/utils';
|
|
6
|
-
|
|
7
|
-
const { xy } = utils;
|
|
8
|
-
|
|
9
|
-
jest.mock('@pie-lib/graphing-utils', () => ({
|
|
10
|
-
buildDataPoints: jest.fn().mockReturnValue([]),
|
|
11
|
-
exponentialFromTwoPoints: jest.fn(() => jest.fn()),
|
|
12
|
-
getAmplitudeAndFreq: jest.fn().mockReturnValue({ freq: 4, amplitude: 1 }),
|
|
13
|
-
}));
|
|
14
|
-
|
|
15
|
-
jest.mock('../../shared/line/with-root-edge', () => ({
|
|
16
|
-
withRootEdge: jest.fn(),
|
|
17
|
-
rootEdgeComponent: jest.fn(),
|
|
18
|
-
}));
|
|
19
|
-
|
|
20
|
-
describe('Exponential', () => {
|
|
21
|
-
let fnBody;
|
|
22
|
-
let graphProps;
|
|
23
|
-
let root;
|
|
24
|
-
let edge;
|
|
25
|
-
let result;
|
|
26
|
-
|
|
27
|
-
beforeEach(() => {
|
|
28
|
-
require('../component');
|
|
29
|
-
fnBody = withRootEdge.mock.calls[0][0];
|
|
30
|
-
graphProps = getGraphProps();
|
|
31
|
-
root = xy(1, 1);
|
|
32
|
-
edge = xy(2, 2);
|
|
33
|
-
|
|
34
|
-
result = fnBody({ graphProps, root, edge });
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it('fnBody is not null', () => {
|
|
38
|
-
expect(fnBody).toBeDefined();
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it('calls buildDataPoints', () => {
|
|
42
|
-
const { domain, range } = graphProps;
|
|
43
|
-
expect(buildDataPoints).toHaveBeenCalledWith(domain, range, root, edge, expect.anything(), true);
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it('calls exponentialFromTwoPoints', () => {
|
|
47
|
-
expect(exponentialFromTwoPoints).toHaveBeenCalledWith(root, edge);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it('returns dataPoints', () => {
|
|
51
|
-
expect(result).toEqual({ root, edge, dataPoints: [] });
|
|
52
|
-
});
|
|
53
|
-
});
|