@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,294 +0,0 @@
1
- import { addPointToArray, tool } from '../index';
2
- import Polygon from '../component';
3
-
4
- const xy = (x, y) => ({ x, y });
5
-
6
- /**
7
- * Test suite for polygon tool
8
- *
9
- * Note: equalPoints() uses roundNumber() which rounds to 4 decimal places.
10
- * - Values like 1.0001 and 1.0002 are considered DIFFERENT (round to 1.0001 and 1.0002)
11
- * - Values like 1.00001 and 1.00002 are considered EQUAL (both round to 1.0000)
12
- */
13
-
14
- describe('polygon', () => {
15
- describe('addPointToArray', () => {
16
- const assertAddPoint = (point, arr, expected) => {
17
- it(`returns expected result when adding point to array`, () => {
18
- const result = addPointToArray(point, arr);
19
- expect(result).toEqual(expected);
20
- });
21
- };
22
-
23
- assertAddPoint(xy(0, 0), [], { closed: false, points: [xy(0, 0)] });
24
- assertAddPoint(xy(0, 0), [xy(0, 0)], { closed: false, points: [xy(0, 0)] });
25
- assertAddPoint(xy(1, 1), [xy(0, 0)], {
26
- closed: false,
27
- points: [xy(0, 0), xy(1, 1)],
28
- });
29
-
30
- it('handles undefined array', () => {
31
- const result = addPointToArray(xy(1, 2), undefined);
32
- expect(result).toEqual({ points: [xy(1, 2)], closed: false });
33
- });
34
-
35
- it('handles null array', () => {
36
- const result = addPointToArray(xy(1, 2), null);
37
- expect(result).toEqual({ points: [xy(1, 2)], closed: false });
38
- });
39
-
40
- it('closes polygon when clicking first point', () => {
41
- const firstPoint = xy(1, 2);
42
- const points = [firstPoint, xy(3, 4), xy(5, 6)];
43
- const result = addPointToArray(firstPoint, points);
44
-
45
- expect(result).toEqual({ points, closed: true });
46
- });
47
-
48
- it('does not add duplicate point in middle', () => {
49
- const points = [xy(1, 2), xy(3, 4), xy(5, 6)];
50
- const result = addPointToArray(points[1], points);
51
-
52
- expect(result).toEqual({ points, closed: false });
53
- });
54
-
55
- it('adds new point to array with 2+ points', () => {
56
- const points = [xy(0, 0), xy(1, 1)];
57
- const newPoint = xy(2, 2);
58
- const result = addPointToArray(newPoint, points);
59
-
60
- expect(result).toEqual({
61
- points: [...points, newPoint],
62
- closed: false,
63
- });
64
- });
65
-
66
- it('handles points within rounding tolerance', () => {
67
- // roundNumber rounds to 4 decimal places
68
- // 1.0001 and 1.0002 round to different values after toFixed(4)
69
- const firstPoint = xy(1.0001, 2.0001);
70
- const closePoint = xy(1.0002, 2.0002);
71
- const result = addPointToArray(closePoint, [firstPoint]);
72
-
73
- // Since they round to different values, both points are added
74
- expect(result).toEqual({ points: [firstPoint, closePoint], closed: false });
75
- });
76
-
77
- it('handles points that round to exactly the same value', () => {
78
- // Points that round to exactly the same value after toFixed(4)
79
- const firstPoint = xy(1.0001, 2.0001);
80
- const samePoint = xy(1.0001, 2.0001);
81
- const result = addPointToArray(samePoint, [firstPoint]);
82
-
83
- // Since they round to the same value, point is not added
84
- expect(result).toEqual({ points: [firstPoint], closed: false });
85
- });
86
- });
87
- });
88
-
89
- describe('tool', () => {
90
- let t;
91
-
92
- beforeEach(() => {
93
- t = tool();
94
- });
95
-
96
- describe('tool structure', () => {
97
- it('creates polygon type', () => {
98
- expect(t.type).toEqual('polygon');
99
- });
100
-
101
- it('has Component property', () => {
102
- expect(t.Component).toBe(Polygon);
103
- });
104
-
105
- it('has complete method', () => {
106
- expect(typeof t.complete).toBe('function');
107
- });
108
-
109
- it('has addPoint method', () => {
110
- expect(typeof t.addPoint).toBe('function');
111
- });
112
- });
113
-
114
- describe('complete', () => {
115
- it('closes polygon', () => {
116
- expect(t.complete()).toEqual({ building: false, closed: true });
117
- });
118
-
119
- it('marks polygon as not building', () => {
120
- const mark = {
121
- type: 'polygon',
122
- points: [xy(1, 2), xy(3, 4)],
123
- closed: false,
124
- building: true,
125
- };
126
- const result = t.complete(null, mark);
127
-
128
- expect(result.building).toBe(false);
129
- });
130
-
131
- it('marks polygon as closed', () => {
132
- const mark = {
133
- type: 'polygon',
134
- points: [xy(1, 2), xy(3, 4)],
135
- closed: false,
136
- building: true,
137
- };
138
- const result = t.complete(null, mark);
139
-
140
- expect(result.closed).toBe(true);
141
- });
142
-
143
- it('preserves other mark properties', () => {
144
- const mark = {
145
- type: 'polygon',
146
- points: [xy(1, 2)],
147
- closed: false,
148
- building: true,
149
- label: 'Test',
150
- color: 'red',
151
- };
152
- const result = t.complete(null, mark);
153
-
154
- expect(result.label).toBe('Test');
155
- expect(result.color).toBe('red');
156
- });
157
- });
158
-
159
- describe('addPoint', () => {
160
- it('creates new polygon with first point', () => {
161
- const mark = t.addPoint({ x: 0, y: 0 });
162
- expect(mark).toEqual({
163
- type: 'polygon',
164
- points: [{ x: 0, y: 0 }],
165
- closed: false,
166
- building: true,
167
- });
168
- });
169
-
170
- it('adds second point to existing mark', () => {
171
- const mark = t.addPoint({ x: 0, y: 0 }, { points: [{ x: 1, y: 1 }] });
172
- expect(mark).toEqual({
173
- building: true,
174
- closed: false,
175
- points: [
176
- { x: 1, y: 1 },
177
- { x: 0, y: 0 },
178
- ],
179
- });
180
- });
181
-
182
- it('creates mark with building flag true', () => {
183
- const mark = t.addPoint(xy(1, 2));
184
- expect(mark.building).toBe(true);
185
- });
186
-
187
- it('creates mark with closed flag false', () => {
188
- const mark = t.addPoint(xy(1, 2));
189
- expect(mark.closed).toBe(false);
190
- });
191
-
192
- it('adds multiple points sequentially', () => {
193
- let mark = t.addPoint(xy(0, 0));
194
- mark = t.addPoint(xy(1, 1), mark);
195
- mark = t.addPoint(xy(2, 2), mark);
196
-
197
- expect(mark.points).toHaveLength(3);
198
- expect(mark.points).toEqual([xy(0, 0), xy(1, 1), xy(2, 2)]);
199
- });
200
-
201
- it('closes polygon when clicking first point', () => {
202
- const firstPoint = xy(1, 2);
203
- let mark = t.addPoint(firstPoint);
204
- mark = t.addPoint(xy(3, 4), mark);
205
- mark = t.addPoint(xy(5, 6), mark);
206
- mark = t.addPoint(firstPoint, mark);
207
-
208
- expect(mark.closed).toBe(true);
209
- expect(mark.building).toBe(false);
210
- });
211
-
212
- it('does not add duplicate points', () => {
213
- const point = xy(1, 2);
214
- let mark = t.addPoint(point);
215
- mark = t.addPoint(xy(3, 4), mark);
216
- // Adding the first point again would close it
217
- // Let's add it one more time after closing to test duplicate handling
218
- mark = t.addPoint(point, mark);
219
-
220
- // When we add the first point to a polygon with 2+ points, it closes
221
- expect(mark.points).toHaveLength(2);
222
- expect(mark.closed).toBe(true);
223
- expect(mark.building).toBe(false);
224
- });
225
-
226
- it('does not add duplicate non-first points', () => {
227
- const firstPoint = xy(1, 2);
228
- const secondPoint = xy(3, 4);
229
- let mark = t.addPoint(firstPoint);
230
- mark = t.addPoint(secondPoint, mark);
231
- mark = t.addPoint(xy(5, 6), mark);
232
- // Try to add the second point again (not the first point)
233
- mark = t.addPoint(secondPoint, mark);
234
-
235
- // Should not add the duplicate point
236
- expect(mark.points).toHaveLength(3);
237
- expect(mark.points).toEqual([firstPoint, secondPoint, xy(5, 6)]);
238
- expect(mark.closed).toBe(false);
239
- });
240
-
241
- it('preserves mark properties when adding points', () => {
242
- const mark = {
243
- type: 'polygon',
244
- points: [xy(1, 2)],
245
- closed: false,
246
- building: true,
247
- label: 'My Shape',
248
- };
249
-
250
- const result = t.addPoint(xy(3, 4), mark);
251
- expect(result.label).toBe('My Shape');
252
- });
253
- });
254
-
255
- describe('integration scenarios', () => {
256
- it('creates complete triangle', () => {
257
- const p1 = xy(0, 0);
258
- const p2 = xy(1, 0);
259
- const p3 = xy(0.5, 1);
260
-
261
- let mark = t.addPoint(p1);
262
- mark = t.addPoint(p2, mark);
263
- mark = t.addPoint(p3, mark);
264
- mark = t.addPoint(p1, mark);
265
-
266
- expect(mark.points).toEqual([p1, p2, p3]);
267
- expect(mark.closed).toBe(true);
268
- expect(mark.building).toBe(false);
269
- });
270
-
271
- it('creates complete square', () => {
272
- const points = [xy(0, 0), xy(1, 0), xy(1, 1), xy(0, 1)];
273
-
274
- let mark = t.addPoint(points[0]);
275
- points.slice(1).forEach((p) => {
276
- mark = t.addPoint(p, mark);
277
- });
278
- mark = t.addPoint(points[0], mark);
279
-
280
- expect(mark.points).toEqual(points);
281
- expect(mark.closed).toBe(true);
282
- });
283
-
284
- it('can force complete without closing', () => {
285
- let mark = t.addPoint(xy(0, 0));
286
- mark = t.addPoint(xy(1, 1), mark);
287
- mark = t.complete(null, mark);
288
-
289
- expect(mark.closed).toBe(true);
290
- expect(mark.building).toBe(false);
291
- expect(mark.points).toHaveLength(2);
292
- });
293
- });
294
- });
@@ -1,35 +0,0 @@
1
- import { render } from '@pie-lib/test-utils';
2
- import React from 'react';
3
- import { Line } from '../line';
4
- import { graphProps } from '../../../__tests__/utils';
5
-
6
- describe('Line', () => {
7
- const renderComponent = (extras) => {
8
- const defaults = {
9
- classes: {},
10
- className: 'className',
11
- graphProps: graphProps(),
12
- };
13
- const props = { ...defaults, ...extras };
14
- return render(<Line {...props} />);
15
- };
16
- describe('rendering', () => {
17
- it('renders without crashing', () => {
18
- const { container } = renderComponent();
19
- expect(container.firstChild).toBeInTheDocument();
20
- });
21
-
22
- it('renders with from and to points', () => {
23
- const { container } = renderComponent({
24
- from: { x: 0, y: 0 },
25
- to: { x: 5, y: 5 },
26
- });
27
- expect(container.firstChild).toBeInTheDocument();
28
- });
29
-
30
- it('renders with className', () => {
31
- const { container } = renderComponent({ className: 'custom-line' });
32
- expect(container.firstChild).toBeInTheDocument();
33
- });
34
- });
35
- });
@@ -1,61 +0,0 @@
1
- import { render } from '@pie-lib/test-utils';
2
- import React from 'react';
3
- import { getPointString, Polygon } from '../polygon';
4
- import { graphProps } from '../../../__tests__/utils';
5
-
6
- const xy = (x, y) => ({ x, y });
7
-
8
- describe('Polygon', () => {
9
- const renderComponent = (extras) => {
10
- const defaults = {
11
- classes: {},
12
- className: 'className',
13
- graphProps: graphProps(),
14
- closed: false,
15
- };
16
- const props = { ...defaults, ...extras };
17
- return render(<Polygon {...props} />);
18
- };
19
-
20
- describe('rendering', () => {
21
- it('renders without crashing', () => {
22
- const { container } = renderComponent({ points: [{ x: 1, y: 1 }] });
23
- expect(container.firstChild).toBeInTheDocument();
24
- });
25
-
26
- it('renders multiple points', () => {
27
- const points = [xy(0, 0), xy(1, 1), xy(2, 0)];
28
- const { container } = renderComponent({ points });
29
- expect(container.firstChild).toBeInTheDocument();
30
- });
31
-
32
- it('renders closed polygon', () => {
33
- const points = [xy(0, 0), xy(1, 1), xy(2, 0)];
34
- const { container } = renderComponent({ points, closed: true });
35
- expect(container.firstChild).toBeInTheDocument();
36
- });
37
-
38
- it('renders open polygon', () => {
39
- const points = [xy(0, 0), xy(1, 1)];
40
- const { container } = renderComponent({ points, closed: false });
41
- expect(container.firstChild).toBeInTheDocument();
42
- });
43
- });
44
- });
45
-
46
- describe('getPointString', () => {
47
- const assertString = (arr, expected) => {
48
- it('creates: ', () => {
49
- const result = getPointString(arr, {
50
- x: jest.fn((n) => n),
51
- y: jest.fn((n) => n),
52
- });
53
-
54
- expect(result).toEqual(expected);
55
- });
56
- };
57
-
58
- assertString([xy(1, 1)], '1,1');
59
- assertString([xy(1, 1), xy(2, 1)], '1,1 2,1');
60
- assertString([xy(1, 1), xy(2, 1), xy(4, 4)], '1,1 2,1 4,4');
61
- });
@@ -1,29 +0,0 @@
1
- import { render } from '@pie-lib/test-utils';
2
- import React from 'react';
3
- import { RayLine } from '../component';
4
- import { graphProps as getGraphProps } from '../../../__tests__/utils';
5
- import { utils } from '@pie-lib/plot';
6
-
7
- describe('RayLine', () => {
8
- let onChange = jest.fn();
9
- const renderComponent = (extras) => {
10
- const defaults = {
11
- classes: {},
12
- className: 'className',
13
- onChange,
14
- markerId: '1',
15
- graphProps: getGraphProps(),
16
- from: utils.xy(0, 0),
17
- to: utils.xy(1, 1),
18
- };
19
- const props = { ...defaults, ...extras };
20
- return render(<RayLine {...props} />);
21
- };
22
-
23
- describe('rendering', () => {
24
- it('renders without crashing', () => {
25
- const { container } = renderComponent();
26
- expect(container.firstChild).toBeInTheDocument();
27
- });
28
- });
29
- });
@@ -1,28 +0,0 @@
1
- import { render } from '@pie-lib/test-utils';
2
- import React from 'react';
3
- import { Line } from '../component';
4
- import { graphProps as getGraphProps } from '../../../__tests__/utils';
5
- import { utils } from '@pie-lib/plot';
6
-
7
- const { xy } = utils;
8
- describe('Line', () => {
9
- let onChange = jest.fn();
10
- const renderComponent = (extras) => {
11
- const defaults = {
12
- classes: {},
13
- className: 'className',
14
- onChange,
15
- graphProps: getGraphProps(),
16
- from: xy(0, 0),
17
- to: xy(1, 1),
18
- };
19
- const props = { ...defaults, ...extras };
20
- return render(<Line {...props} />);
21
- };
22
- describe('rendering', () => {
23
- it('renders without crashing', () => {
24
- const { container } = renderComponent();
25
- expect(container.firstChild).toBeInTheDocument();
26
- });
27
- });
28
- });
@@ -1,31 +0,0 @@
1
- import { render } from '@pie-lib/test-utils';
2
- import React from 'react';
3
- import { ArrowHead, ArrowMarker } from '../arrow-head';
4
-
5
- describe('ArrowHead', () => {
6
- const renderComponent = (extras) => {
7
- const defaults = { size: 10, transform: '' };
8
- const props = { ...defaults, ...extras };
9
- return render(<ArrowHead {...props} />);
10
- };
11
- describe('rendering', () => {
12
- it('renders without crashing', () => {
13
- const { container } = renderComponent();
14
- expect(container.firstChild).toBeInTheDocument();
15
- });
16
- });
17
- });
18
-
19
- describe('ArrowMarker', () => {
20
- const renderComponent = (extras) => {
21
- const defaults = { id: 'id', size: 10, className: 'className' };
22
- const props = { ...defaults, ...extras };
23
- return render(<ArrowMarker {...props} />);
24
- };
25
- describe('rendering', () => {
26
- it('renders without crashing', () => {
27
- const { container } = renderComponent();
28
- expect(container.firstChild).toBeInTheDocument();
29
- });
30
- });
31
- });
@@ -1,109 +0,0 @@
1
- import { lineBase, lineTool, lineToolComponent } from '../index';
2
- import { utils } from '@pie-lib/plot';
3
- import { render } from '@pie-lib/test-utils';
4
- import React from 'react';
5
- import { graphProps as getGraphProps } from '../../../../__tests__/utils';
6
-
7
- const { xy } = utils;
8
- const xyLabel = (x, y, label) => ({ x, y, label });
9
-
10
- describe('lineTool', () => {
11
- describe('addPoint', () => {
12
- let toolbar;
13
- beforeEach(() => {
14
- toolbar = lineTool('lineType', () => <div />)();
15
- });
16
- it('returns a building mark', () => {
17
- const result = toolbar.addPoint(xy(1, 1));
18
- expect(result).toEqual({
19
- type: 'lineType',
20
- building: true,
21
- from: xy(1, 1),
22
- });
23
- });
24
-
25
- it('returns a complete mark', () => {
26
- const result = toolbar.addPoint(xy(1, 1), { from: xy(0, 0) });
27
- expect(result).toEqual({
28
- building: false,
29
- from: xy(0, 0),
30
- to: xy(1, 1),
31
- });
32
- });
33
- });
34
- });
35
-
36
- describe('lineToolComponent', () => {
37
- let Comp;
38
- let mark;
39
- let onChange;
40
- const renderComponent = (extras) => {
41
- const defaults = {
42
- mark,
43
- onChange: jest.fn(),
44
- graphProps: getGraphProps(),
45
- };
46
- const props = { ...defaults, ...extras };
47
-
48
- return render(<Comp {...props} />);
49
- };
50
-
51
- beforeEach(() => {
52
- Comp = lineToolComponent(() => <text />);
53
- mark = { from: xy(0, 0), to: xy(1, 1) };
54
- });
55
-
56
- describe('rendering', () => {
57
- it('renders without crashing', () => {
58
- const { container } = renderComponent();
59
- expect(container.firstChild).toBeInTheDocument();
60
- });
61
- });
62
- });
63
-
64
- describe('lineBase', () => {
65
- let Comp;
66
- let onChange = jest.fn();
67
- let changeMarkProps = jest.fn();
68
-
69
- beforeEach(() => {
70
- Comp = lineBase(() => <text />);
71
- onChange.mockClear();
72
- changeMarkProps.mockClear();
73
- });
74
-
75
- const renderComponent = (extras) => {
76
- const defaults = {
77
- onChange,
78
- changeMarkProps,
79
- graphProps: getGraphProps(),
80
- from: xy(0, 0),
81
- to: xy(1, 1),
82
- };
83
- const props = { ...defaults, ...extras };
84
-
85
- return render(<Comp {...props} />);
86
- };
87
-
88
- // used to test items that have labels attached to points
89
- const labelNode = document.createElement('foreignObject');
90
- const renderWithLabels = (extras = {}) =>
91
- renderComponent({
92
- ...extras,
93
- labelNode: labelNode,
94
- from: xyLabel(0, 0, 'A'),
95
- to: xyLabel(1, 1, 'B'),
96
- });
97
-
98
- describe('rendering', () => {
99
- it('renders without crashing', () => {
100
- const { container } = renderComponent();
101
- expect(container.firstChild).toBeInTheDocument();
102
- });
103
-
104
- it('renders with labels', () => {
105
- const { container } = renderWithLabels();
106
- expect(container.firstChild).toBeInTheDocument();
107
- });
108
- });
109
- });
@@ -1,53 +0,0 @@
1
- import { render } from '@pie-lib/test-utils';
2
- import React from 'react';
3
- import { graphProps as getGraphProps } from '../../../../__tests__/utils';
4
- import { utils } from '@pie-lib/plot';
5
- import * as lineUtils from '../../../../utils';
6
-
7
- const { xy } = utils;
8
-
9
- const { bounds, pointsToArea } = lineUtils;
10
- jest.mock('../../../../utils', () => {
11
- const a = jest.requireActual('../../../../utils');
12
- return {
13
- pointsToArea: jest.fn().mockReturnValue({}),
14
- bounds: jest.fn().mockReturnValue({}),
15
- point: a.point,
16
- };
17
- });
18
-
19
- jest.mock('@pie-lib/plot', () => {
20
- const a = jest.requireActual('@pie-lib/plot');
21
- return {
22
- gridDraggable: jest.fn((opts) => jest.fn()),
23
- types: a.types,
24
- utils: a.utils,
25
- };
26
- });
27
-
28
- describe('LinePath', () => {
29
- let LinePath;
30
- let onChange = jest.fn();
31
- beforeEach(() => {
32
- LinePath = require('../line-path').LinePath;
33
- });
34
- const renderComponent = (extras) => {
35
- const defaults = {
36
- classes: {},
37
- className: 'className',
38
- onChange,
39
- graphProps: getGraphProps(),
40
- from: xy(0, 0, 0),
41
- to: xy(1, 1, 0),
42
- data: [xy(0, 0, 0), xy(1, 1, 0)],
43
- };
44
- const props = { ...defaults, ...extras };
45
- return render(<LinePath {...props} />);
46
- };
47
- describe('rendering', () => {
48
- it('renders without crashing', () => {
49
- const { container } = renderComponent();
50
- expect(container.firstChild).toBeInTheDocument();
51
- });
52
- });
53
- });