@pie-lib/graphing 4.1.0-beta.7 → 4.1.0-beta.9

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 (145) hide show
  1. package/package.json +3 -3
  2. package/lib/__tests__/bg.test.js +0 -282
  3. package/lib/__tests__/bg.test.js.map +0 -1
  4. package/lib/__tests__/coordinates-label.test.js +0 -276
  5. package/lib/__tests__/coordinates-label.test.js.map +0 -1
  6. package/lib/__tests__/graph-with-controls.test.js +0 -275
  7. package/lib/__tests__/graph-with-controls.test.js.map +0 -1
  8. package/lib/__tests__/graph.test.js +0 -927
  9. package/lib/__tests__/graph.test.js.map +0 -1
  10. package/lib/__tests__/grid-setup.test.js +0 -729
  11. package/lib/__tests__/grid-setup.test.js.map +0 -1
  12. package/lib/__tests__/grid.test.js +0 -29
  13. package/lib/__tests__/grid.test.js.map +0 -1
  14. package/lib/__tests__/key-legend.test.js +0 -321
  15. package/lib/__tests__/key-legend.test.js.map +0 -1
  16. package/lib/__tests__/label-svg-icon.test.js +0 -373
  17. package/lib/__tests__/label-svg-icon.test.js.map +0 -1
  18. package/lib/__tests__/labels.test.js +0 -61
  19. package/lib/__tests__/labels.test.js.map +0 -1
  20. package/lib/__tests__/mark-label.test.js +0 -133
  21. package/lib/__tests__/mark-label.test.js.map +0 -1
  22. package/lib/__tests__/toggle-bar.test.js +0 -197
  23. package/lib/__tests__/toggle-bar.test.js.map +0 -1
  24. package/lib/__tests__/tool-menu.test.js +0 -151
  25. package/lib/__tests__/tool-menu.test.js.map +0 -1
  26. package/lib/__tests__/undo-redo.test.js +0 -31
  27. package/lib/__tests__/undo-redo.test.js.map +0 -1
  28. package/lib/__tests__/use-debounce.test.js +0 -24
  29. package/lib/__tests__/use-debounce.test.js.map +0 -1
  30. package/lib/__tests__/utils.js +0 -70
  31. package/lib/__tests__/utils.js.map +0 -1
  32. package/lib/__tests__/utils.test.js +0 -123
  33. package/lib/__tests__/utils.test.js.map +0 -1
  34. package/lib/axis/__tests__/arrow.test.js +0 -60
  35. package/lib/axis/__tests__/arrow.test.js.map +0 -1
  36. package/lib/axis/__tests__/axes.test.js +0 -195
  37. package/lib/axis/__tests__/axes.test.js.map +0 -1
  38. package/lib/container/__tests__/actions.test.js +0 -108
  39. package/lib/container/__tests__/actions.test.js.map +0 -1
  40. package/lib/container/__tests__/index.test.js +0 -503
  41. package/lib/container/__tests__/index.test.js.map +0 -1
  42. package/lib/container/__tests__/marks.test.js +0 -259
  43. package/lib/container/__tests__/marks.test.js.map +0 -1
  44. package/lib/container/__tests__/middleware.test.js +0 -244
  45. package/lib/container/__tests__/middleware.test.js.map +0 -1
  46. package/lib/container/__tests__/reducer.test.js +0 -450
  47. package/lib/container/__tests__/reducer.test.js.map +0 -1
  48. package/lib/tools/absolute/__tests__/component.test.js +0 -65
  49. package/lib/tools/absolute/__tests__/component.test.js.map +0 -1
  50. package/lib/tools/circle/__tests__/bg-circle.test.js +0 -33
  51. package/lib/tools/circle/__tests__/bg-circle.test.js.map +0 -1
  52. package/lib/tools/circle/__tests__/component.test.js +0 -615
  53. package/lib/tools/circle/__tests__/component.test.js.map +0 -1
  54. package/lib/tools/circle/__tests__/index.test.js +0 -576
  55. package/lib/tools/circle/__tests__/index.test.js.map +0 -1
  56. package/lib/tools/exponential/__tests__/component.test.js +0 -64
  57. package/lib/tools/exponential/__tests__/component.test.js.map +0 -1
  58. package/lib/tools/exponential/__tests__/index.test.js +0 -828
  59. package/lib/tools/exponential/__tests__/index.test.js.map +0 -1
  60. package/lib/tools/line/__tests__/component.test.js +0 -45
  61. package/lib/tools/line/__tests__/component.test.js.map +0 -1
  62. package/lib/tools/parabola/__tests__/component.test.js +0 -64
  63. package/lib/tools/parabola/__tests__/component.test.js.map +0 -1
  64. package/lib/tools/parabola/__tests__/index.test.js +0 -564
  65. package/lib/tools/parabola/__tests__/index.test.js.map +0 -1
  66. package/lib/tools/point/__tests__/component.test.js +0 -434
  67. package/lib/tools/point/__tests__/component.test.js.map +0 -1
  68. package/lib/tools/point/__tests__/index.test.js +0 -262
  69. package/lib/tools/point/__tests__/index.test.js.map +0 -1
  70. package/lib/tools/polygon/__tests__/component.test.js +0 -485
  71. package/lib/tools/polygon/__tests__/component.test.js.map +0 -1
  72. package/lib/tools/polygon/__tests__/index.test.js +0 -303
  73. package/lib/tools/polygon/__tests__/index.test.js.map +0 -1
  74. package/lib/tools/polygon/__tests__/line.test.js +0 -50
  75. package/lib/tools/polygon/__tests__/line.test.js.map +0 -1
  76. package/lib/tools/polygon/__tests__/polygon.test.js +0 -85
  77. package/lib/tools/polygon/__tests__/polygon.test.js.map +0 -1
  78. package/lib/tools/ray/__tests__/component.test.js +0 -35
  79. package/lib/tools/ray/__tests__/component.test.js.map +0 -1
  80. package/lib/tools/segment/__tests__/component.test.js +0 -35
  81. package/lib/tools/segment/__tests__/component.test.js.map +0 -1
  82. package/lib/tools/shared/__tests__/arrow-head.test.js +0 -45
  83. package/lib/tools/shared/__tests__/arrow-head.test.js.map +0 -1
  84. package/lib/tools/shared/line/__tests__/index.test.js +0 -124
  85. package/lib/tools/shared/line/__tests__/index.test.js.map +0 -1
  86. package/lib/tools/shared/line/__tests__/line-path.test.js +0 -62
  87. package/lib/tools/shared/line/__tests__/line-path.test.js.map +0 -1
  88. package/lib/tools/shared/line/__tests__/with-root-edge.test.js +0 -90
  89. package/lib/tools/shared/line/__tests__/with-root-edge.test.js.map +0 -1
  90. package/lib/tools/shared/point/__tests__/arrow-point.test.js +0 -127
  91. package/lib/tools/shared/point/__tests__/arrow-point.test.js.map +0 -1
  92. package/lib/tools/shared/point/__tests__/base-point.test.js +0 -122
  93. package/lib/tools/shared/point/__tests__/base-point.test.js.map +0 -1
  94. package/lib/tools/sine/__tests__/component.test.js +0 -72
  95. package/lib/tools/sine/__tests__/component.test.js.map +0 -1
  96. package/lib/tools/vector/__tests__/component.test.js +0 -32
  97. package/lib/tools/vector/__tests__/component.test.js.map +0 -1
  98. package/src/__tests__/bg.test.jsx +0 -250
  99. package/src/__tests__/coordinates-label.test.jsx +0 -243
  100. package/src/__tests__/graph-with-controls.test.jsx +0 -198
  101. package/src/__tests__/graph.test.jsx +0 -721
  102. package/src/__tests__/grid-setup.test.jsx +0 -645
  103. package/src/__tests__/grid.test.jsx +0 -22
  104. package/src/__tests__/key-legend.test.jsx +0 -260
  105. package/src/__tests__/label-svg-icon.test.jsx +0 -278
  106. package/src/__tests__/labels.test.jsx +0 -55
  107. package/src/__tests__/mark-label.test.jsx +0 -63
  108. package/src/__tests__/toggle-bar.test.jsx +0 -146
  109. package/src/__tests__/tool-menu.test.jsx +0 -115
  110. package/src/__tests__/undo-redo.test.jsx +0 -24
  111. package/src/__tests__/use-debounce.test.js +0 -21
  112. package/src/__tests__/utils.js +0 -41
  113. package/src/__tests__/utils.test.js +0 -105
  114. package/src/axis/__tests__/arrow.test.jsx +0 -38
  115. package/src/axis/__tests__/axes.test.jsx +0 -216
  116. package/src/container/__tests__/actions.test.js +0 -105
  117. package/src/container/__tests__/index.test.jsx +0 -319
  118. package/src/container/__tests__/marks.test.js +0 -172
  119. package/src/container/__tests__/middleware.test.js +0 -235
  120. package/src/container/__tests__/reducer.test.js +0 -324
  121. package/src/tools/absolute/__tests__/component.test.jsx +0 -53
  122. package/src/tools/circle/__tests__/bg-circle.test.jsx +0 -26
  123. package/src/tools/circle/__tests__/component.test.jsx +0 -494
  124. package/src/tools/circle/__tests__/index.test.js +0 -480
  125. package/src/tools/exponential/__tests__/component.test.jsx +0 -53
  126. package/src/tools/exponential/__tests__/index.test.js +0 -729
  127. package/src/tools/line/__tests__/component.test.jsx +0 -37
  128. package/src/tools/parabola/__tests__/component.test.jsx +0 -48
  129. package/src/tools/parabola/__tests__/index.test.js +0 -470
  130. package/src/tools/point/__tests__/component.test.jsx +0 -349
  131. package/src/tools/point/__tests__/index.test.js +0 -241
  132. package/src/tools/polygon/__tests__/component.test.jsx +0 -471
  133. package/src/tools/polygon/__tests__/index.test.js +0 -294
  134. package/src/tools/polygon/__tests__/line.test.jsx +0 -35
  135. package/src/tools/polygon/__tests__/polygon.test.jsx +0 -61
  136. package/src/tools/ray/__tests__/component.test.jsx +0 -29
  137. package/src/tools/segment/__tests__/component.test.jsx +0 -28
  138. package/src/tools/shared/__tests__/arrow-head.test.jsx +0 -31
  139. package/src/tools/shared/line/__tests__/index.test.jsx +0 -109
  140. package/src/tools/shared/line/__tests__/line-path.test.jsx +0 -53
  141. package/src/tools/shared/line/__tests__/with-root-edge.test.jsx +0 -73
  142. package/src/tools/shared/point/__tests__/arrow-point.test.jsx +0 -91
  143. package/src/tools/shared/point/__tests__/base-point.test.jsx +0 -87
  144. package/src/tools/sine/__tests__/component.test.jsx +0 -51
  145. package/src/tools/vector/__tests__/component.test.jsx +0 -25
@@ -1,37 +0,0 @@
1
- import { render } from '@pie-lib/test-utils';
2
- import React from 'react';
3
- import { ArrowedLine } from '../component';
4
- import { graphProps as getGraphProps } from '../../../__tests__/utils';
5
-
6
- jest.mock('@pie-lib/plot', () => {
7
- const a = jest.requireActual('@pie-lib/plot');
8
- return {
9
- types: a.types,
10
- gridDraggable: a.gridDraggable,
11
- utils: a.utils,
12
- trig: {
13
- edges: jest.fn(() => jest.fn().mockReturnValue([0, 0])),
14
- },
15
- };
16
- });
17
-
18
- describe('ArrowedLine', () => {
19
- let onChange = jest.fn();
20
- const renderComponent = (extras) => {
21
- const defaults = {
22
- classes: {},
23
- className: 'className',
24
- onChange,
25
- markerId: '1',
26
- graphProps: getGraphProps(),
27
- };
28
- const props = { ...defaults, ...extras };
29
- return render(<ArrowedLine {...props} />);
30
- };
31
- describe('rendering', () => {
32
- it('renders without crashing', () => {
33
- const { container } = renderComponent();
34
- expect(container.firstChild).toBeInTheDocument();
35
- });
36
- });
37
- });
@@ -1,48 +0,0 @@
1
- import { withRootEdge } from '../../shared/line/with-root-edge';
2
- import { buildDataPoints, parabolaFromTwoPoints } 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
- jest.mock('@pie-lib/graphing-utils', () => ({
9
- buildDataPoints: jest.fn().mockReturnValue([]),
10
- parabolaFromTwoPoints: jest.fn(() => jest.fn()),
11
- getAmplitudeAndFreq: jest.fn().mockReturnValue({ freq: 4, amplitude: 1 }),
12
- }));
13
-
14
- jest.mock('../../shared/line/with-root-edge', () => ({
15
- withRootEdge: jest.fn(),
16
- rootEdgeComponent: jest.fn(),
17
- }));
18
- describe('Parabola', () => {
19
- let fnBody;
20
- let graphProps;
21
- let root;
22
- let edge;
23
- let result;
24
- beforeEach(() => {
25
- require('../component');
26
- fnBody = withRootEdge.mock.calls[0][0];
27
- graphProps = getGraphProps();
28
- root = xy(0, 0);
29
- edge = xy(1, 1);
30
-
31
- result = fnBody({ graphProps, root, edge });
32
- });
33
- it('fnBody is not null', () => {
34
- expect(fnBody).toBeDefined();
35
- });
36
-
37
- it('calls buildDataPoints', () => {
38
- const { domain, range } = graphProps;
39
- expect(buildDataPoints).toHaveBeenCalledWith(domain, range, root, edge, expect.anything(), true);
40
- });
41
- it('calls parabolaFromTwoPoints', () => {
42
- expect(parabolaFromTwoPoints).toHaveBeenCalledWith(root, edge);
43
- });
44
-
45
- it('returns dataPoints', () => {
46
- expect(result).toEqual({ root, edge, dataPoints: [] });
47
- });
48
- });
@@ -1,470 +0,0 @@
1
- import { tool } from '../index';
2
- import Parabola from '../component';
3
-
4
- describe('parabola tool', () => {
5
- let parabolaTool;
6
-
7
- beforeEach(() => {
8
- parabolaTool = tool();
9
- });
10
-
11
- describe('tool structure', () => {
12
- it('returns an object with required properties', () => {
13
- expect(parabolaTool).toHaveProperty('type', 'parabola');
14
- expect(parabolaTool).toHaveProperty('Component', Parabola);
15
- expect(parabolaTool).toHaveProperty('complete');
16
- expect(parabolaTool).toHaveProperty('addPoint');
17
- });
18
-
19
- it('has correct type', () => {
20
- expect(parabolaTool.type).toBe('parabola');
21
- });
22
-
23
- it('uses Parabola component', () => {
24
- expect(parabolaTool.Component).toBe(Parabola);
25
- });
26
- });
27
-
28
- describe('addPoint', () => {
29
- describe('no existing mark', () => {
30
- it('creates new parabola with root point', () => {
31
- const point = { x: 1, y: 2 };
32
- const result = parabolaTool.addPoint(point, null);
33
-
34
- expect(result).toEqual({
35
- type: 'parabola',
36
- root: point,
37
- edge: undefined,
38
- closed: false,
39
- building: true,
40
- });
41
- });
42
-
43
- it('creates parabola with undefined argument', () => {
44
- const point = { x: 3, y: 4 };
45
- const result = parabolaTool.addPoint(point);
46
-
47
- expect(result).toEqual({
48
- type: 'parabola',
49
- root: point,
50
- edge: undefined,
51
- closed: false,
52
- building: true,
53
- });
54
- });
55
-
56
- it('marks parabola as building', () => {
57
- const result = parabolaTool.addPoint({ x: 0, y: 0 });
58
-
59
- expect(result.building).toBe(true);
60
- expect(result.closed).toBe(false);
61
- });
62
-
63
- it('initializes with undefined edge', () => {
64
- const result = parabolaTool.addPoint({ x: 1, y: 1 });
65
-
66
- expect(result.edge).toBeUndefined();
67
- });
68
- });
69
-
70
- describe('existing mark with root', () => {
71
- it('adds edge point to complete parabola', () => {
72
- const root = { x: 1, y: 2 };
73
- const edge = { x: 3, y: 4 };
74
- const mark = {
75
- type: 'parabola',
76
- root,
77
- edge: undefined,
78
- closed: false,
79
- building: true,
80
- };
81
-
82
- const result = parabolaTool.addPoint(edge, mark);
83
-
84
- expect(result).toEqual({
85
- type: 'parabola',
86
- root,
87
- edge,
88
- closed: true,
89
- building: false,
90
- });
91
- });
92
-
93
- it('closes parabola when edge is added', () => {
94
- const mark = {
95
- type: 'parabola',
96
- root: { x: 0, y: 0 },
97
- edge: undefined,
98
- closed: false,
99
- building: true,
100
- };
101
-
102
- const result = parabolaTool.addPoint({ x: 1, y: 1 }, mark);
103
-
104
- expect(result.closed).toBe(true);
105
- expect(result.building).toBe(false);
106
- });
107
-
108
- it('preserves other mark properties when adding edge', () => {
109
- const mark = {
110
- type: 'parabola',
111
- root: { x: 1, y: 2 },
112
- edge: undefined,
113
- closed: false,
114
- building: true,
115
- label: 'My Parabola',
116
- color: 'blue',
117
- };
118
-
119
- const result = parabolaTool.addPoint({ x: 3, y: 4 }, mark);
120
-
121
- expect(result.label).toBe('My Parabola');
122
- expect(result.color).toBe('blue');
123
- });
124
- });
125
-
126
- describe('duplicate points', () => {
127
- it('returns same mark when clicking root point again', () => {
128
- const root = { x: 1, y: 2 };
129
- const mark = {
130
- type: 'parabola',
131
- root,
132
- edge: undefined,
133
- closed: false,
134
- building: true,
135
- };
136
-
137
- const result = parabolaTool.addPoint(root, mark);
138
-
139
- expect(result).toBe(mark);
140
- });
141
-
142
- it('returns same mark when clicking near root point', () => {
143
- const root = { x: 1.00001, y: 2.00001 };
144
- const nearRoot = { x: 1.00002, y: 2.00002 };
145
- const mark = {
146
- type: 'parabola',
147
- root,
148
- edge: undefined,
149
- closed: false,
150
- building: true,
151
- };
152
-
153
- const result = parabolaTool.addPoint(nearRoot, mark);
154
-
155
- expect(result).toBe(mark);
156
- });
157
- });
158
-
159
- describe('same axes constraint', () => {
160
- it('returns same mark when clicking on same x-axis as root', () => {
161
- const root = { x: 5, y: 3 };
162
- const sameXPoint = { x: 5, y: 7 };
163
- const mark = {
164
- type: 'parabola',
165
- root,
166
- edge: undefined,
167
- closed: false,
168
- building: true,
169
- };
170
-
171
- const result = parabolaTool.addPoint(sameXPoint, mark);
172
-
173
- expect(result).toBe(mark);
174
- });
175
-
176
- it('returns same mark when clicking on same y-axis as root', () => {
177
- const root = { x: 3, y: 5 };
178
- const sameYPoint = { x: 7, y: 5 };
179
- const mark = {
180
- type: 'parabola',
181
- root,
182
- edge: undefined,
183
- closed: false,
184
- building: true,
185
- };
186
-
187
- const result = parabolaTool.addPoint(sameYPoint, mark);
188
-
189
- expect(result).toBe(mark);
190
- });
191
-
192
- it('allows edge point on different axes', () => {
193
- const root = { x: 3, y: 5 };
194
- const edge = { x: 7, y: 9 };
195
- const mark = {
196
- type: 'parabola',
197
- root,
198
- edge: undefined,
199
- closed: false,
200
- building: true,
201
- };
202
-
203
- const result = parabolaTool.addPoint(edge, mark);
204
-
205
- expect(result).not.toBe(mark);
206
- expect(result.edge).toEqual(edge);
207
- });
208
-
209
- it('handles points within rounding tolerance on same x-axis', () => {
210
- const root = { x: 5.00001, y: 3 };
211
- const nearSameX = { x: 5.00002, y: 7 };
212
- const mark = {
213
- type: 'parabola',
214
- root,
215
- edge: undefined,
216
- closed: false,
217
- building: true,
218
- };
219
-
220
- const result = parabolaTool.addPoint(nearSameX, mark);
221
-
222
- expect(result).toBe(mark);
223
- });
224
-
225
- it('handles points within rounding tolerance on same y-axis', () => {
226
- const root = { x: 3, y: 5.00001 };
227
- const nearSameY = { x: 7, y: 5.00002 };
228
- const mark = {
229
- type: 'parabola',
230
- root,
231
- edge: undefined,
232
- closed: false,
233
- building: true,
234
- };
235
-
236
- const result = parabolaTool.addPoint(nearSameY, mark);
237
-
238
- expect(result).toBe(mark);
239
- });
240
- });
241
-
242
- describe('error handling', () => {
243
- it('throws error when mark exists but has no root', () => {
244
- const mark = {
245
- type: 'parabola',
246
- edge: undefined,
247
- closed: false,
248
- building: true,
249
- };
250
-
251
- expect(() => {
252
- parabolaTool.addPoint({ x: 1, y: 2 }, mark);
253
- }).toThrow('no root - should never happen');
254
- });
255
-
256
- it('throws error when mark has null root', () => {
257
- const mark = {
258
- type: 'parabola',
259
- root: null,
260
- edge: undefined,
261
- closed: false,
262
- building: true,
263
- };
264
-
265
- expect(() => {
266
- parabolaTool.addPoint({ x: 1, y: 2 }, mark);
267
- }).toThrow('no root - should never happen');
268
- });
269
-
270
- it('throws error when mark has undefined root', () => {
271
- const mark = {
272
- type: 'parabola',
273
- root: undefined,
274
- edge: undefined,
275
- closed: false,
276
- building: true,
277
- };
278
-
279
- expect(() => {
280
- parabolaTool.addPoint({ x: 1, y: 2 }, mark);
281
- }).toThrow('no root - should never happen');
282
- });
283
- });
284
-
285
- describe('coordinates', () => {
286
- it('handles negative coordinates', () => {
287
- const root = { x: -3, y: -5 };
288
- const result = parabolaTool.addPoint(root);
289
-
290
- expect(result.root).toEqual(root);
291
- });
292
-
293
- it('handles zero coordinates', () => {
294
- const root = { x: 0, y: 0 };
295
- const result = parabolaTool.addPoint(root);
296
-
297
- expect(result.root).toEqual(root);
298
- });
299
-
300
- it('handles decimal coordinates', () => {
301
- const root = { x: 1.5, y: 2.75 };
302
- const result = parabolaTool.addPoint(root);
303
-
304
- expect(result.root).toEqual(root);
305
- });
306
-
307
- it('creates parabola with negative root and positive edge', () => {
308
- const mark = parabolaTool.addPoint({ x: -2, y: -3 });
309
- const result = parabolaTool.addPoint({ x: 1, y: 2 }, mark);
310
-
311
- expect(result.root).toEqual({ x: -2, y: -3 });
312
- expect(result.edge).toEqual({ x: 1, y: 2 });
313
- });
314
- });
315
- });
316
-
317
- describe('complete', () => {
318
- it('marks parabola as complete and closed', () => {
319
- const mark = {
320
- type: 'parabola',
321
- root: { x: 1, y: 2 },
322
- edge: { x: 3, y: 4 },
323
- closed: false,
324
- building: true,
325
- };
326
-
327
- const result = parabolaTool.complete(null, mark);
328
-
329
- expect(result).toEqual({
330
- type: 'parabola',
331
- root: mark.root,
332
- edge: mark.edge,
333
- closed: true,
334
- building: false,
335
- });
336
- });
337
-
338
- it('sets building to false', () => {
339
- const mark = {
340
- type: 'parabola',
341
- root: { x: 0, y: 0 },
342
- edge: undefined,
343
- closed: false,
344
- building: true,
345
- };
346
-
347
- const result = parabolaTool.complete(null, mark);
348
-
349
- expect(result.building).toBe(false);
350
- });
351
-
352
- it('sets closed to true', () => {
353
- const mark = {
354
- type: 'parabola',
355
- root: { x: 0, y: 0 },
356
- edge: undefined,
357
- closed: false,
358
- building: true,
359
- };
360
-
361
- const result = parabolaTool.complete(null, mark);
362
-
363
- expect(result.closed).toBe(true);
364
- });
365
-
366
- it('preserves all mark properties', () => {
367
- const mark = {
368
- type: 'parabola',
369
- root: { x: 1, y: 2 },
370
- edge: { x: 3, y: 4 },
371
- closed: false,
372
- building: true,
373
- label: 'Test Parabola',
374
- color: 'green',
375
- id: 456,
376
- };
377
-
378
- const result = parabolaTool.complete(null, mark);
379
-
380
- expect(result.label).toBe('Test Parabola');
381
- expect(result.color).toBe('green');
382
- expect(result.id).toBe(456);
383
- });
384
-
385
- it('can force complete parabola with only root', () => {
386
- const mark = {
387
- type: 'parabola',
388
- root: { x: 1, y: 2 },
389
- edge: undefined,
390
- closed: false,
391
- building: true,
392
- };
393
-
394
- const result = parabolaTool.complete(null, mark);
395
-
396
- expect(result.closed).toBe(true);
397
- expect(result.building).toBe(false);
398
- expect(result.edge).toBeUndefined();
399
- });
400
- });
401
-
402
- describe('integration scenarios', () => {
403
- it('creates complete parabola with two clicks', () => {
404
- const root = { x: 0, y: 0 };
405
- const edge = { x: 2, y: 4 };
406
-
407
- let mark = parabolaTool.addPoint(root);
408
- expect(mark.building).toBe(true);
409
- expect(mark.closed).toBe(false);
410
-
411
- mark = parabolaTool.addPoint(edge, mark);
412
- expect(mark.root).toEqual(root);
413
- expect(mark.edge).toEqual(edge);
414
- expect(mark.building).toBe(false);
415
- expect(mark.closed).toBe(true);
416
- });
417
-
418
- it('ignores clicks on same axis during construction', () => {
419
- const root = { x: 0, y: 0 };
420
- let mark = parabolaTool.addPoint(root);
421
-
422
- // Try to add point on same x-axis
423
- const sameXMark = parabolaTool.addPoint({ x: 0, y: 5 }, mark);
424
- expect(sameXMark).toBe(mark);
425
- expect(sameXMark.edge).toBeUndefined();
426
-
427
- // Try to add point on same y-axis
428
- const sameYMark = parabolaTool.addPoint({ x: 5, y: 0 }, mark);
429
- expect(sameYMark).toBe(mark);
430
- expect(sameYMark.edge).toBeUndefined();
431
-
432
- // Add valid edge point
433
- const finalMark = parabolaTool.addPoint({ x: 2, y: 4 }, mark);
434
- expect(finalMark.edge).toEqual({ x: 2, y: 4 });
435
- expect(finalMark.closed).toBe(true);
436
- });
437
-
438
- it('ignores duplicate clicks on root', () => {
439
- const root = { x: 1, y: 2 };
440
- let mark = parabolaTool.addPoint(root);
441
-
442
- // Click root again
443
- const sameMark = parabolaTool.addPoint(root, mark);
444
- expect(sameMark).toBe(mark);
445
- expect(sameMark.edge).toBeUndefined();
446
- });
447
-
448
- it('handles typical parabola in different quadrants', () => {
449
- // Quadrant 1
450
- let mark1 = parabolaTool.addPoint({ x: 1, y: 1 });
451
- mark1 = parabolaTool.addPoint({ x: 2, y: 3 }, mark1);
452
- expect(mark1.closed).toBe(true);
453
-
454
- // Quadrant 2
455
- let mark2 = parabolaTool.addPoint({ x: -1, y: 1 });
456
- mark2 = parabolaTool.addPoint({ x: -2, y: 3 }, mark2);
457
- expect(mark2.closed).toBe(true);
458
-
459
- // Quadrant 3
460
- let mark3 = parabolaTool.addPoint({ x: -1, y: -1 });
461
- mark3 = parabolaTool.addPoint({ x: -2, y: -3 }, mark3);
462
- expect(mark3.closed).toBe(true);
463
-
464
- // Quadrant 4
465
- let mark4 = parabolaTool.addPoint({ x: 1, y: -1 });
466
- mark4 = parabolaTool.addPoint({ x: 2, y: -3 }, mark4);
467
- expect(mark4.closed).toBe(true);
468
- });
469
- });
470
- });