@pie-lib/graphing 2.14.22 → 2.16.0-beta.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.
Files changed (259) hide show
  1. package/CHANGELOG.md +9 -1
  2. package/NEXT.CHANGELOG.json +1 -0
  3. package/lib/__tests__/graph-with-controls.test.js +215 -0
  4. package/lib/__tests__/graph.test.js +290 -0
  5. package/lib/__tests__/grid.test.js +40 -0
  6. package/lib/__tests__/labels.test.js +59 -0
  7. package/lib/__tests__/mark-label.test.js +154 -0
  8. package/lib/__tests__/toggle-bar.test.js +54 -0
  9. package/lib/__tests__/tool-menu.test.js +43 -0
  10. package/lib/__tests__/undo-redo.test.js +42 -0
  11. package/lib/__tests__/use-debounce.test.js +28 -0
  12. package/lib/__tests__/utils.js +72 -0
  13. package/lib/__tests__/utils.test.js +133 -0
  14. package/lib/axis/__tests__/arrow.test.js +68 -0
  15. package/lib/axis/__tests__/axes.test.js +214 -0
  16. package/lib/axis/arrow.js +1 -1
  17. package/lib/axis/axes.js +6 -6
  18. package/lib/axis/index.js +1 -1
  19. package/lib/bg.js +1 -1
  20. package/lib/container/actions.js +1 -1
  21. package/lib/container/index.js +2 -5
  22. package/lib/container/marks.js +1 -1
  23. package/lib/container/middleware.js +1 -1
  24. package/lib/container/reducer.js +1 -1
  25. package/lib/coordinates-label.js +6 -4
  26. package/lib/graph-with-controls.js +9 -16
  27. package/lib/graph.js +30 -13
  28. package/lib/grid-setup.js +1 -1
  29. package/lib/grid.js +7 -15
  30. package/lib/index.js +9 -1
  31. package/lib/key-legend.js +246 -0
  32. package/lib/label-svg-icon.js +56 -0
  33. package/lib/labels.js +3 -2
  34. package/lib/mark-label.js +168 -57
  35. package/lib/toggle-bar.js +4 -5
  36. package/lib/tool-menu.js +3 -23
  37. package/lib/tools/absolute/__tests__/component.test.js +74 -0
  38. package/lib/tools/absolute/component.js +35 -0
  39. package/lib/tools/absolute/index.js +63 -0
  40. package/lib/tools/circle/__tests__/bg-circle.test.js +46 -0
  41. package/lib/tools/circle/__tests__/component.test.js +259 -0
  42. package/lib/tools/circle/bg-circle.js +5 -4
  43. package/lib/tools/circle/component.js +35 -16
  44. package/lib/tools/circle/index.js +1 -1
  45. package/lib/tools/exponential/__tests__/component.test.js +73 -0
  46. package/lib/tools/exponential/component.js +34 -0
  47. package/lib/tools/exponential/index.js +71 -0
  48. package/lib/tools/index.js +27 -7
  49. package/lib/tools/line/__tests__/component.test.js +56 -0
  50. package/lib/tools/line/component.js +3 -2
  51. package/lib/tools/line/index.js +1 -1
  52. package/lib/tools/parabola/__tests__/component.test.js +73 -0
  53. package/lib/tools/parabola/component.js +7 -6
  54. package/lib/tools/parabola/index.js +1 -1
  55. package/lib/tools/point/__tests__/component.test.js +97 -0
  56. package/lib/tools/point/component.js +15 -10
  57. package/lib/tools/point/index.js +1 -1
  58. package/lib/tools/polygon/__tests__/component.test.js +255 -0
  59. package/lib/tools/polygon/__tests__/index.test.js +95 -0
  60. package/lib/tools/polygon/__tests__/line.test.js +43 -0
  61. package/lib/tools/polygon/__tests__/polygon.test.js +73 -0
  62. package/lib/tools/polygon/component.js +26 -13
  63. package/lib/tools/polygon/index.js +1 -1
  64. package/lib/tools/polygon/line.js +13 -7
  65. package/lib/tools/polygon/polygon.js +7 -4
  66. package/lib/tools/ray/__tests__/component.test.js +48 -0
  67. package/lib/tools/ray/component.js +3 -2
  68. package/lib/tools/ray/index.js +1 -1
  69. package/lib/tools/segment/__tests__/component.test.js +48 -0
  70. package/lib/tools/segment/component.js +3 -2
  71. package/lib/tools/segment/index.js +1 -1
  72. package/lib/tools/shared/__tests__/arrow-head.test.js +62 -0
  73. package/lib/tools/shared/arrow-head.js +1 -1
  74. package/lib/tools/shared/icons/CorrectSVG.js +36 -0
  75. package/lib/tools/shared/icons/IncorrectSVG.js +36 -0
  76. package/lib/tools/shared/icons/MissingSVG.js +35 -0
  77. package/lib/tools/shared/line/__tests__/index.test.js +301 -0
  78. package/lib/tools/shared/line/__tests__/line-path.test.js +78 -0
  79. package/lib/tools/shared/line/__tests__/with-root-edge.test.js +122 -0
  80. package/lib/tools/shared/line/index.js +52 -20
  81. package/lib/tools/shared/line/line-path.js +14 -8
  82. package/lib/tools/shared/line/with-root-edge.js +20 -9
  83. package/lib/tools/shared/point/__tests__/arrow-point.test.js +137 -0
  84. package/lib/tools/shared/point/__tests__/base-point.test.js +134 -0
  85. package/lib/tools/shared/point/arrow-point.js +2 -2
  86. package/lib/tools/shared/point/arrow.js +2 -2
  87. package/lib/tools/shared/point/base-point.js +44 -8
  88. package/lib/tools/shared/point/index.js +5 -2
  89. package/lib/tools/shared/styles.js +17 -8
  90. package/lib/tools/shared/types.js +1 -1
  91. package/lib/tools/sine/__tests__/component.test.js +81 -0
  92. package/lib/tools/sine/component.js +14 -5
  93. package/lib/tools/sine/index.js +1 -1
  94. package/lib/tools/vector/__tests__/component.test.js +45 -0
  95. package/lib/tools/vector/component.js +3 -2
  96. package/lib/tools/vector/index.js +1 -1
  97. package/lib/undo-redo.js +1 -2
  98. package/lib/use-debounce.js +1 -1
  99. package/lib/utils.js +2 -2
  100. package/package.json +7 -7
  101. package/src/__tests__/__snapshots__/graph-with-controls.test.jsx.snap +237 -0
  102. package/src/__tests__/__snapshots__/graph.test.jsx.snap +211 -0
  103. package/src/__tests__/__snapshots__/grid.test.jsx.snap +54 -0
  104. package/src/__tests__/__snapshots__/labels.test.jsx.snap +30 -0
  105. package/src/__tests__/__snapshots__/mark-label.test.jsx.snap +45 -0
  106. package/src/__tests__/__snapshots__/toggle-bar.test.jsx.snap +7 -0
  107. package/src/__tests__/__snapshots__/tool-menu.test.jsx.snap +13 -0
  108. package/src/__tests__/__snapshots__/undo-redo.test.jsx.snap +14 -0
  109. package/src/__tests__/graph-with-controls.test.jsx +147 -0
  110. package/src/__tests__/graph.test.jsx +230 -0
  111. package/src/__tests__/grid.test.jsx +20 -0
  112. package/src/__tests__/labels.test.jsx +38 -0
  113. package/src/__tests__/mark-label.test.jsx +68 -0
  114. package/src/__tests__/toggle-bar.test.jsx +36 -0
  115. package/src/__tests__/tool-menu.test.jsx +29 -0
  116. package/src/__tests__/undo-redo.test.jsx +25 -0
  117. package/src/__tests__/use-debounce.test.js +21 -0
  118. package/src/__tests__/utils.js +38 -0
  119. package/src/__tests__/utils.test.js +151 -0
  120. package/src/axis/__tests__/__snapshots__/arrow.test.jsx.snap +33 -0
  121. package/src/axis/__tests__/__snapshots__/axes.test.jsx.snap +122 -0
  122. package/src/axis/__tests__/arrow.test.jsx +39 -0
  123. package/src/axis/__tests__/axes.test.jsx +220 -0
  124. package/src/axis/axes.jsx +5 -5
  125. package/src/container/index.jsx +2 -4
  126. package/src/coordinates-label.jsx +4 -3
  127. package/src/graph-with-controls.jsx +8 -10
  128. package/src/graph.jsx +22 -10
  129. package/src/grid-setup.jsx +9 -6
  130. package/src/grid.jsx +8 -10
  131. package/src/index.js +2 -2
  132. package/src/key-legend.jsx +115 -0
  133. package/src/label-svg-icon.jsx +39 -0
  134. package/src/labels.jsx +2 -1
  135. package/src/mark-label.jsx +149 -52
  136. package/src/toggle-bar.jsx +1 -2
  137. package/src/tool-menu.jsx +3 -26
  138. package/src/tools/absolute/__tests__/component.test.jsx +54 -0
  139. package/src/tools/absolute/component.jsx +23 -0
  140. package/src/tools/absolute/index.js +31 -0
  141. package/src/tools/circle/__tests__/__snapshots__/bg-circle.test.jsx.snap +46 -0
  142. package/src/tools/circle/__tests__/__snapshots__/component.test.jsx.snap +293 -0
  143. package/src/tools/circle/__tests__/bg-circle.test.jsx +28 -0
  144. package/src/tools/circle/__tests__/component.test.jsx +228 -0
  145. package/src/tools/circle/bg-circle.jsx +5 -4
  146. package/src/tools/circle/component.jsx +22 -8
  147. package/src/tools/exponential/__tests__/component.test.jsx +54 -0
  148. package/src/tools/exponential/component.jsx +23 -0
  149. package/src/tools/exponential/index.js +39 -0
  150. package/src/tools/index.js +38 -5
  151. package/src/tools/line/__tests__/__snapshots__/component.test.jsx.snap +20 -0
  152. package/src/tools/line/__tests__/component.test.jsx +36 -0
  153. package/src/tools/line/component.jsx +2 -1
  154. package/src/tools/parabola/__tests__/component.test.jsx +49 -0
  155. package/src/tools/parabola/component.jsx +7 -6
  156. package/src/tools/point/__tests__/__snapshots__/component.test.jsx.snap +40 -0
  157. package/src/tools/point/__tests__/component.test.jsx +66 -0
  158. package/src/tools/point/component.jsx +12 -6
  159. package/src/tools/polygon/__tests__/__snapshots__/component.test.jsx.snap +415 -0
  160. package/src/tools/polygon/__tests__/__snapshots__/line.test.jsx.snap +45 -0
  161. package/src/tools/polygon/__tests__/__snapshots__/polygon.test.jsx.snap +52 -0
  162. package/src/tools/polygon/__tests__/component.test.jsx +226 -0
  163. package/src/tools/polygon/__tests__/index.test.js +65 -0
  164. package/src/tools/polygon/__tests__/line.test.jsx +25 -0
  165. package/src/tools/polygon/__tests__/polygon.test.jsx +44 -0
  166. package/src/tools/polygon/component.jsx +39 -11
  167. package/src/tools/polygon/line.jsx +15 -7
  168. package/src/tools/polygon/polygon.jsx +7 -3
  169. package/src/tools/ray/__tests__/__snapshots__/component.test.jsx.snap +23 -0
  170. package/src/tools/ray/__tests__/component.test.jsx +29 -0
  171. package/src/tools/ray/component.jsx +2 -1
  172. package/src/tools/segment/__tests__/__snapshots__/component.test.jsx.snap +14 -0
  173. package/src/tools/segment/__tests__/component.test.jsx +28 -0
  174. package/src/tools/segment/component.jsx +2 -1
  175. package/src/tools/shared/__tests__/__snapshots__/arrow-head.test.jsx.snap +27 -0
  176. package/src/tools/shared/__tests__/arrow-head.test.jsx +34 -0
  177. package/src/tools/shared/icons/CorrectSVG.jsx +22 -0
  178. package/src/tools/shared/icons/IncorrectSVG.jsx +20 -0
  179. package/src/tools/shared/icons/MissingSVG.jsx +21 -0
  180. package/src/tools/shared/line/__tests__/__snapshots__/index.test.jsx.snap +360 -0
  181. package/src/tools/shared/line/__tests__/__snapshots__/line-path.test.jsx.snap +58 -0
  182. package/src/tools/shared/line/__tests__/__snapshots__/with-root-edge.test.jsx.snap +63 -0
  183. package/src/tools/shared/line/__tests__/index.test.jsx +255 -0
  184. package/src/tools/shared/line/__tests__/line-path.test.jsx +53 -0
  185. package/src/tools/shared/line/__tests__/with-root-edge.test.jsx +73 -0
  186. package/src/tools/shared/line/index.jsx +39 -13
  187. package/src/tools/shared/line/line-path.jsx +18 -7
  188. package/src/tools/shared/line/with-root-edge.jsx +10 -3
  189. package/src/tools/shared/point/__tests__/__snapshots__/arrow-point.test.jsx.snap +56 -0
  190. package/src/tools/shared/point/__tests__/__snapshots__/base-point.test.jsx.snap +44 -0
  191. package/src/tools/shared/point/__tests__/arrow-point.test.jsx +87 -0
  192. package/src/tools/shared/point/__tests__/base-point.test.jsx +84 -0
  193. package/src/tools/shared/point/arrow-point.jsx +4 -1
  194. package/src/tools/shared/point/arrow.jsx +4 -1
  195. package/src/tools/shared/point/base-point.jsx +28 -3
  196. package/src/tools/shared/point/index.jsx +7 -2
  197. package/src/tools/shared/styles.js +8 -3
  198. package/src/tools/sine/__tests__/component.test.jsx +51 -0
  199. package/src/tools/sine/component.jsx +7 -7
  200. package/src/tools/vector/__tests__/__snapshots__/component.test.jsx.snap +12 -0
  201. package/src/tools/vector/__tests__/component.test.jsx +26 -0
  202. package/src/tools/vector/component.jsx +2 -1
  203. package/src/undo-redo.jsx +0 -1
  204. package/src/utils.js +1 -1
  205. package/legacy.png +0 -0
  206. package/lib/axis/arrow.js.map +0 -1
  207. package/lib/axis/axes.js.map +0 -1
  208. package/lib/axis/index.js.map +0 -1
  209. package/lib/bg.js.map +0 -1
  210. package/lib/container/actions.js.map +0 -1
  211. package/lib/container/index.js.map +0 -1
  212. package/lib/container/marks.js.map +0 -1
  213. package/lib/container/middleware.js.map +0 -1
  214. package/lib/container/reducer.js.map +0 -1
  215. package/lib/coordinates-label.js.map +0 -1
  216. package/lib/graph-with-controls.js.map +0 -1
  217. package/lib/graph.js.map +0 -1
  218. package/lib/grid-setup.js.map +0 -1
  219. package/lib/grid.js.map +0 -1
  220. package/lib/index.js.map +0 -1
  221. package/lib/labels.js.map +0 -1
  222. package/lib/mark-label.js.map +0 -1
  223. package/lib/toggle-bar.js.map +0 -1
  224. package/lib/tool-menu.js.map +0 -1
  225. package/lib/tools/circle/bg-circle.js.map +0 -1
  226. package/lib/tools/circle/component.js.map +0 -1
  227. package/lib/tools/circle/index.js.map +0 -1
  228. package/lib/tools/index.js.map +0 -1
  229. package/lib/tools/line/component.js.map +0 -1
  230. package/lib/tools/line/index.js.map +0 -1
  231. package/lib/tools/parabola/component.js.map +0 -1
  232. package/lib/tools/parabola/index.js.map +0 -1
  233. package/lib/tools/point/component.js.map +0 -1
  234. package/lib/tools/point/index.js.map +0 -1
  235. package/lib/tools/polygon/component.js.map +0 -1
  236. package/lib/tools/polygon/index.js.map +0 -1
  237. package/lib/tools/polygon/line.js.map +0 -1
  238. package/lib/tools/polygon/polygon.js.map +0 -1
  239. package/lib/tools/ray/component.js.map +0 -1
  240. package/lib/tools/ray/index.js.map +0 -1
  241. package/lib/tools/segment/component.js.map +0 -1
  242. package/lib/tools/segment/index.js.map +0 -1
  243. package/lib/tools/shared/arrow-head.js.map +0 -1
  244. package/lib/tools/shared/line/index.js.map +0 -1
  245. package/lib/tools/shared/line/line-path.js.map +0 -1
  246. package/lib/tools/shared/line/with-root-edge.js.map +0 -1
  247. package/lib/tools/shared/point/arrow-point.js.map +0 -1
  248. package/lib/tools/shared/point/arrow.js.map +0 -1
  249. package/lib/tools/shared/point/base-point.js.map +0 -1
  250. package/lib/tools/shared/point/index.js.map +0 -1
  251. package/lib/tools/shared/styles.js.map +0 -1
  252. package/lib/tools/shared/types.js.map +0 -1
  253. package/lib/tools/sine/component.js.map +0 -1
  254. package/lib/tools/sine/index.js.map +0 -1
  255. package/lib/tools/vector/component.js.map +0 -1
  256. package/lib/tools/vector/index.js.map +0 -1
  257. package/lib/undo-redo.js.map +0 -1
  258. package/lib/use-debounce.js.map +0 -1
  259. package/lib/utils.js.map +0 -1
@@ -0,0 +1,25 @@
1
+ import { shallow } from 'enzyme';
2
+ import React from 'react';
3
+ import UndoRedo from '../undo-redo';
4
+
5
+ describe('UndoRedo', () => {
6
+ let w;
7
+ let onUndo = jest.fn();
8
+ let onRedo = jest.fn();
9
+ let onReset = jest.fn();
10
+ const wrapper = (extras) => {
11
+ const defaults = {
12
+ onUndo,
13
+ onRedo,
14
+ onReset,
15
+ };
16
+ const props = { ...defaults, ...extras };
17
+ return shallow(<UndoRedo {...props} />);
18
+ };
19
+ describe('snapshot', () => {
20
+ it('renders', () => {
21
+ w = wrapper();
22
+ expect(w).toMatchSnapshot();
23
+ });
24
+ });
25
+ });
@@ -0,0 +1,21 @@
1
+ import { useState, useEffect } from 'react';
2
+ import { useDebounce } from '../use-debounce';
3
+
4
+ jest.useFakeTimers();
5
+
6
+ jest.mock('react', () => ({
7
+ useState: jest.fn(),
8
+ useEffect: jest.fn((fn, deps) => fn()),
9
+ }));
10
+
11
+ describe('useDebounce', () => {
12
+ it('..', () => {
13
+ const debouncedValue = null;
14
+ const setDebouncedValue = jest.fn();
15
+
16
+ useState.mockReturnValue([debouncedValue, setDebouncedValue]);
17
+ useDebounce('foo', 1000);
18
+ jest.runAllTimers();
19
+ expect(setDebouncedValue).toHaveBeenCalledWith('foo');
20
+ });
21
+ });
@@ -0,0 +1,38 @@
1
+ export const scaleMock = () => {
2
+ const fn = jest.fn((n) => n);
3
+ fn.invert = jest.fn((n) => n);
4
+ return fn;
5
+ };
6
+
7
+ export const graphProps = (dmin = 0, dmax = 1, rmin = 0, rmax = 1) => ({
8
+ scale: {
9
+ x: scaleMock(),
10
+ y: scaleMock(),
11
+ },
12
+ snap: {
13
+ x: jest.fn((n) => n),
14
+ y: jest.fn((n) => n),
15
+ },
16
+ domain: {
17
+ min: dmin,
18
+ max: dmax,
19
+ step: 1,
20
+ },
21
+ range: {
22
+ min: rmin,
23
+ max: rmax,
24
+ step: 1,
25
+ },
26
+ size: {
27
+ width: 400,
28
+ height: 400,
29
+ },
30
+ });
31
+
32
+ export const xy = (x, y, index) => {
33
+ const out = { x, y, index };
34
+ if (!Number.isFinite(index)) {
35
+ delete out.index;
36
+ }
37
+ return out;
38
+ };
@@ -0,0 +1,151 @@
1
+ import * as utils from '../utils';
2
+
3
+ const xy = (x, y) => ({ x, y });
4
+
5
+ const tick = (isMajor, v) => ({
6
+ major: isMajor,
7
+ value: v,
8
+ x: v,
9
+ });
10
+
11
+ const major = tick.bind(null, true);
12
+ const minor = tick.bind(null, false);
13
+
14
+ describe('utils', () => {
15
+ describe('polygonToArea', () => {
16
+ const assertPolygon = (points, area) => {
17
+ it(`converts ${points} -> ${area}`, () => {
18
+ const result = utils.polygonToArea(points);
19
+ expect(result).toEqual(area);
20
+ });
21
+ };
22
+ assertPolygon([xy(0, 0), xy(1, 1), xy(1, -1)], {
23
+ left: 0,
24
+ top: 1,
25
+ bottom: -1,
26
+ right: 1,
27
+ });
28
+ assertPolygon([xy(0, 0), xy(3, 0), xy(2, -1), xy(4, -3), xy(1, -4), xy(2, -2)], {
29
+ left: 0,
30
+ top: 0,
31
+ bottom: -4,
32
+ right: 4,
33
+ });
34
+ });
35
+
36
+ describe('lineToArea', () => {
37
+ const assertLine = (from, to, expected) => {
38
+ it(`${from},${to} => ${expected}`, () => {
39
+ const result = utils.lineToArea(from, to);
40
+ expect(result).toEqual(expected);
41
+ });
42
+ };
43
+
44
+ assertLine(xy(1, 1), xy(2, 2), { left: 1, top: 2, bottom: 1, right: 2 });
45
+ assertLine(xy(-1, 4), xy(4, -3), {
46
+ left: -1,
47
+ top: 4,
48
+ bottom: -3,
49
+ right: 4,
50
+ });
51
+ });
52
+
53
+ describe('getTickValues', () => {
54
+ const assertGetTickValues = (props, expected) => {
55
+ it(` => ${expected}`, () => {
56
+ const result = utils.getTickValues(props);
57
+ expect(result).toEqual(expected);
58
+ });
59
+ };
60
+
61
+ assertGetTickValues({ min: 0, max: 10, step: 1 }, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
62
+ assertGetTickValues({ min: 0, max: 3, step: 0.5 }, [0, 0.5, 1, 1.5, 2, 2.5, 3]);
63
+ assertGetTickValues({ min: -0.2, max: 2, step: 0.6 }, [0, 0.6, 1.2, 1.8]);
64
+ assertGetTickValues({ min: -3.4, max: 6.2, step: 1.2 }, [0, -1.2, -2.4, 1.2, 2.4, 3.6, 4.8, 6]);
65
+
66
+ assertGetTickValues({ min: 0.6, max: 4.8, step: 0.3 }, [
67
+ 0.6,
68
+ 0.9,
69
+ 1.2,
70
+ 1.5,
71
+ 1.8,
72
+ 2.1,
73
+ 2.4,
74
+ 2.7,
75
+ 3.0,
76
+ 3.3,
77
+ 3.6,
78
+ 3.9,
79
+ 4.2,
80
+ 4.5,
81
+ 4.8,
82
+ ]);
83
+ assertGetTickValues({ min: 0.5, max: 4.9, step: 0.3 }, [
84
+ 0.6,
85
+ 0.9,
86
+ 1.2,
87
+ 1.5,
88
+ 1.8,
89
+ 2.1,
90
+ 2.4,
91
+ 2.7,
92
+ 3.0,
93
+ 3.3,
94
+ 3.6,
95
+ 3.9,
96
+ 4.2,
97
+ 4.5,
98
+ 4.8,
99
+ ]);
100
+ assertGetTickValues({ min: 0, max: 3, step: 0.125 }, [
101
+ 0,
102
+ 0.125,
103
+ 0.25,
104
+ 0.375,
105
+ 0.5,
106
+ 0.625,
107
+ 0.75,
108
+ 0.875,
109
+ 1,
110
+ 1.125,
111
+ 1.25,
112
+ 1.375,
113
+ 1.5,
114
+ 1.625,
115
+ 1.75,
116
+ 1.875,
117
+ 2,
118
+ 2.125,
119
+ 2.25,
120
+ 2.375,
121
+ 2.5,
122
+ 2.625,
123
+ 2.75,
124
+ 2.875,
125
+ 3,
126
+ ]);
127
+ });
128
+
129
+ describe('countWords', () => {
130
+ it('should return 1 if label is undefined', () => {
131
+ const label = undefined;
132
+ const result = utils.countWords(label);
133
+
134
+ expect(result).toEqual(1);
135
+ });
136
+
137
+ it('should return 1 if label is null', () => {
138
+ const label = null;
139
+ const result = utils.countWords(label);
140
+
141
+ expect(result).toEqual(1);
142
+ });
143
+
144
+ it('should return 3 if label has 3 words', () => {
145
+ const label = 'Number of months';
146
+ const result = utils.countWords(label);
147
+
148
+ expect(result).toEqual(3);
149
+ });
150
+ });
151
+ });
@@ -0,0 +1,33 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`Arrow snapshot down 1`] = `
4
+ <path
5
+ className="className"
6
+ d="m 0,0 8,-5 0,10 -8,-5"
7
+ transform="translate(0, 15) rotate(270)"
8
+ />
9
+ `;
10
+
11
+ exports[`Arrow snapshot left 1`] = `
12
+ <path
13
+ className="className"
14
+ d="m 0,0 8,-5 0,10 -8,-5"
15
+ transform="translate(-15, 0) rotate(0)"
16
+ />
17
+ `;
18
+
19
+ exports[`Arrow snapshot right 1`] = `
20
+ <path
21
+ className="className"
22
+ d="m 0,0 8,-5 0,10 -8,-5"
23
+ transform="translate(15, 0) rotate(180)"
24
+ />
25
+ `;
26
+
27
+ exports[`Arrow snapshot up 1`] = `
28
+ <path
29
+ className="className"
30
+ d="m 0,0 8,-5 0,10 -8,-5"
31
+ transform="translate(0, -15) rotate(90)"
32
+ />
33
+ `;
@@ -0,0 +1,122 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`RawXAxis snapshot renders 1`] = `
4
+ <Fragment>
5
+ <F
6
+ left={0}
7
+ scale={[MockFunction]}
8
+ tickFormat={[Function]}
9
+ tickLabelProps={[Function]}
10
+ top={0}
11
+ />
12
+ <WithStyles(Arrow)
13
+ direction="left"
14
+ scale={
15
+ Object {
16
+ "x": [MockFunction],
17
+ "y": [MockFunction] {
18
+ "calls": Array [
19
+ Array [
20
+ 0,
21
+ ],
22
+ ],
23
+ "results": Array [
24
+ Object {
25
+ "type": "return",
26
+ "value": 0,
27
+ },
28
+ ],
29
+ },
30
+ }
31
+ }
32
+ x={0}
33
+ y={0}
34
+ />
35
+ <WithStyles(Arrow)
36
+ direction="right"
37
+ scale={
38
+ Object {
39
+ "x": [MockFunction],
40
+ "y": [MockFunction] {
41
+ "calls": Array [
42
+ Array [
43
+ 0,
44
+ ],
45
+ ],
46
+ "results": Array [
47
+ Object {
48
+ "type": "return",
49
+ "value": 0,
50
+ },
51
+ ],
52
+ },
53
+ }
54
+ }
55
+ x={1}
56
+ y={0}
57
+ />
58
+ </Fragment>
59
+ `;
60
+
61
+ exports[`RawYAxis snapshot renders 1`] = `
62
+ <Fragment>
63
+ <F
64
+ height={400}
65
+ hideZero={true}
66
+ left={0}
67
+ orientation="left"
68
+ scale={[MockFunction]}
69
+ tickFormat={[Function]}
70
+ tickLabelProps={[Function]}
71
+ tickLength={10}
72
+ tickTextAnchor="bottom"
73
+ top={0}
74
+ />
75
+ <WithStyles(Arrow)
76
+ direction="down"
77
+ scale={
78
+ Object {
79
+ "x": [MockFunction] {
80
+ "calls": Array [
81
+ Array [
82
+ 0,
83
+ ],
84
+ ],
85
+ "results": Array [
86
+ Object {
87
+ "type": "return",
88
+ "value": 0,
89
+ },
90
+ ],
91
+ },
92
+ "y": [MockFunction],
93
+ }
94
+ }
95
+ x={0}
96
+ y={0}
97
+ />
98
+ <WithStyles(Arrow)
99
+ direction="up"
100
+ scale={
101
+ Object {
102
+ "x": [MockFunction] {
103
+ "calls": Array [
104
+ Array [
105
+ 0,
106
+ ],
107
+ ],
108
+ "results": Array [
109
+ Object {
110
+ "type": "return",
111
+ "value": 0,
112
+ },
113
+ ],
114
+ },
115
+ "y": [MockFunction],
116
+ }
117
+ }
118
+ x={0}
119
+ y={1}
120
+ />
121
+ </Fragment>
122
+ `;
@@ -0,0 +1,39 @@
1
+ import { shallow } from 'enzyme';
2
+ import React from 'react';
3
+ import { Arrow } from '../arrow';
4
+
5
+ describe('Arrow', () => {
6
+ let w;
7
+ let onChange = jest.fn();
8
+ const wrapper = (extras) => {
9
+ const defaults = {
10
+ classes: {},
11
+ className: 'className',
12
+ onChange,
13
+ scale: {
14
+ x: jest.fn((n) => n),
15
+ y: jest.fn((n) => n),
16
+ },
17
+ };
18
+ const props = { ...defaults, ...extras };
19
+ return shallow(<Arrow {...props} />);
20
+ };
21
+ describe('snapshot', () => {
22
+ it('up', () => {
23
+ w = wrapper({ direction: 'up' });
24
+ expect(w).toMatchSnapshot();
25
+ });
26
+ it('down', () => {
27
+ w = wrapper({ direction: 'down' });
28
+ expect(w).toMatchSnapshot();
29
+ });
30
+ it('left', () => {
31
+ w = wrapper({ direction: 'left' });
32
+ expect(w).toMatchSnapshot();
33
+ });
34
+ it('right', () => {
35
+ w = wrapper({ direction: 'right' });
36
+ expect(w).toMatchSnapshot();
37
+ });
38
+ });
39
+ });
@@ -0,0 +1,220 @@
1
+ import { shallow } from 'enzyme';
2
+ import React from 'react';
3
+ import { graphProps } from '../../__tests__/utils';
4
+
5
+ import Axes, { RawXAxis, RawYAxis, firstNegativeValue, sharedValues } from '../axes';
6
+
7
+ describe('RawXAxis', () => {
8
+ let w;
9
+ let onChange = jest.fn();
10
+ const wrapper = (extras) => {
11
+ const defaults = {
12
+ classes: {},
13
+ className: 'className',
14
+ onChange,
15
+ graphProps: graphProps(),
16
+ includeArrows: {
17
+ left: true,
18
+ right: true,
19
+ up: true,
20
+ down: true,
21
+ },
22
+ };
23
+ const props = { ...defaults, ...extras };
24
+ return shallow(<RawXAxis {...props} />);
25
+ };
26
+ describe('snapshot', () => {
27
+ it('renders', () => {
28
+ w = wrapper();
29
+ expect(w).toMatchSnapshot();
30
+ });
31
+ });
32
+ });
33
+
34
+ describe('RawYAxis', () => {
35
+ let w;
36
+ let onChange = jest.fn();
37
+ const wrapper = (extras) => {
38
+ const defaults = {
39
+ classes: {},
40
+ className: 'className',
41
+ onChange,
42
+ graphProps: graphProps(),
43
+ includeArrows: {
44
+ left: true,
45
+ right: true,
46
+ up: true,
47
+ down: true,
48
+ },
49
+ };
50
+ const props = { ...defaults, ...extras };
51
+ return shallow(<RawYAxis {...props} />);
52
+ };
53
+ describe('snapshot', () => {
54
+ it('renders', () => {
55
+ w = wrapper();
56
+ expect(w).toMatchSnapshot();
57
+ });
58
+ });
59
+ });
60
+
61
+ const customScaleMock = (distance) => {
62
+ const fn = jest.fn((n) => n * distance);
63
+ fn.invert = jest.fn((n) => n * distance);
64
+ return fn;
65
+ };
66
+
67
+ describe.only('Axes', () => {
68
+ let w;
69
+ let onChange = jest.fn();
70
+
71
+ const customGraphProps = {
72
+ ...graphProps(),
73
+ domain: {
74
+ min: -2,
75
+ max: 2,
76
+ labelStep: 1,
77
+ step: 1,
78
+ },
79
+ range: {
80
+ min: -2,
81
+ max: 2,
82
+ step: 1,
83
+ labelStep: 1,
84
+ },
85
+ scale: {
86
+ x: customScaleMock(200),
87
+ y: customScaleMock(150),
88
+ },
89
+ };
90
+
91
+ const wrapper = (extras) => {
92
+ const defaults = {
93
+ classes: {},
94
+ className: 'className',
95
+ onChange,
96
+ graphProps: customGraphProps,
97
+ };
98
+
99
+ const props = { ...defaults, ...extras };
100
+ return shallow(<Axes {...props} />);
101
+ };
102
+ describe('xValues', () => {
103
+ it('renders', () => {
104
+ w = wrapper();
105
+ const result = w.instance().xValues();
106
+ expect(result).toEqual({
107
+ columnTicksValues: expect.arrayContaining([-2, -1, 0, 1, 2]),
108
+ distanceFromOriginToFirstNegativeX: 150,
109
+ firstNegativeX: -1,
110
+ });
111
+ });
112
+ });
113
+ describe('yValues', () => {
114
+ it('renders', () => {
115
+ w = wrapper();
116
+ const result = w.instance().yValues();
117
+ expect(result).toEqual({
118
+ rowTickValues: expect.arrayContaining([-2, -1, 0, 1, 2]),
119
+ distanceFromOriginToFirstNegativeY: 200,
120
+ firstNegativeY: -1,
121
+ });
122
+ });
123
+ });
124
+ });
125
+
126
+ describe('firstNegativeValue should return undefiend for undefined interval', () => {
127
+ const interval = undefined;
128
+ const result = firstNegativeValue(interval);
129
+ expect(result).toEqual(undefined);
130
+ });
131
+
132
+ describe('firstNegativeValue should return undefiend for empty interval', () => {
133
+ const interval = [];
134
+ const result = firstNegativeValue(interval);
135
+ expect(result).toEqual(undefined);
136
+ });
137
+
138
+ describe('firstNegativeValue should return undefined if there is no negative in interval array', () => {
139
+ const interval = [1, 5, 7, 4, 5];
140
+ const result = firstNegativeValue(interval);
141
+ expect(result).toEqual(undefined);
142
+ });
143
+
144
+ describe('firstNegativeValue should return first negative number from interval', () => {
145
+ const interval = [1, 5, 7, -2, 4, 5, -1];
146
+ const result = firstNegativeValue(interval);
147
+ expect(result).toEqual(-2);
148
+ });
149
+
150
+ describe('skipValue should be empty array if firstNegativeValue for one of the axes is undefined', () => {
151
+ // x
152
+ const intervalX = [1, 2, 3, 4, 5, 6];
153
+ const firstNegativeX = firstNegativeValue(intervalX);
154
+ const distanceFromOriginToFirstNegativeX = -22;
155
+
156
+ // y
157
+ const intervalY = [-1, -2, 1, 2, 3, 4, 5, 6];
158
+ const firstNegativeY = firstNegativeValue(intervalY);
159
+ const distanceFromOriginToFirstNegativeY = -22;
160
+
161
+ const deltaAllowance = 5;
162
+
163
+ const result = sharedValues(
164
+ firstNegativeX,
165
+ firstNegativeY,
166
+ distanceFromOriginToFirstNegativeX,
167
+ distanceFromOriginToFirstNegativeY,
168
+ deltaAllowance,
169
+ );
170
+
171
+ expect(result).toEqual([]);
172
+ });
173
+
174
+ describe('skipValue should be empty array if firstNegativeX and firstNegativeY are equal but they do not overlap', () => {
175
+ // x
176
+ const intervalX = [-1, -2, 1, 2, 3, 4, 5, 6];
177
+ const firstNegativeX = firstNegativeValue(intervalX);
178
+ const distanceFromOriginToFirstNegativeX = -7;
179
+
180
+ // y
181
+ const intervalY = [-1, -2, 1, 2, 3, 4, 5, 6];
182
+ const firstNegativeY = firstNegativeValue(intervalY);
183
+ const distanceFromOriginToFirstNegativeY = -22;
184
+
185
+ const deltaAllowance = 5;
186
+
187
+ const result = sharedValues(
188
+ firstNegativeX,
189
+ firstNegativeY,
190
+ distanceFromOriginToFirstNegativeX,
191
+ distanceFromOriginToFirstNegativeY,
192
+ deltaAllowance,
193
+ );
194
+
195
+ expect(result).toEqual([]);
196
+ });
197
+
198
+ describe('skipValue should be -1 if firstNegativeX and firstNegativeY are equal and they overlap', () => {
199
+ // x
200
+ const intervalX = [-1, -2, 1, 2, 3, 4, 5, 6];
201
+ const firstNegativeX = firstNegativeValue(intervalX);
202
+ const distanceFromOriginToFirstNegativeX = -20;
203
+
204
+ // y
205
+ const intervalY = [-1, -2, 1, 2, 3, 4, 5, 6];
206
+ const firstNegativeY = firstNegativeValue(intervalY);
207
+ const distanceFromOriginToFirstNegativeY = -22;
208
+
209
+ const deltaAllowance = 5;
210
+
211
+ const result = sharedValues(
212
+ firstNegativeX,
213
+ firstNegativeY,
214
+ distanceFromOriginToFirstNegativeX,
215
+ distanceFromOriginToFirstNegativeY,
216
+ deltaAllowance,
217
+ );
218
+
219
+ expect(result).toEqual([-1]);
220
+ });
package/src/axis/axes.jsx CHANGED
@@ -23,16 +23,16 @@ const AxisDefaultProps = {
23
23
 
24
24
  const axisStyles = (theme) => ({
25
25
  line: {
26
- stroke: color.primary(),
27
- strokeWidth: 5,
26
+ stroke: color.defaults.PRIMARY,
27
+ strokeWidth: 3,
28
28
  },
29
29
  arrow: {
30
- fill: color.primary(),
30
+ fill: color.defaults.PRIMARY,
31
31
  },
32
32
  tick: {
33
- fill: color.primary(),
33
+ fill: color.defaults.PRIMARY,
34
34
  '& > line': {
35
- stroke: color.primary(),
35
+ stroke: color.defaults.PRIMARY,
36
36
  },
37
37
  },
38
38
  labelFontSize: {
@@ -8,7 +8,7 @@ import PropTypes from 'prop-types';
8
8
  import isEqual from 'lodash/isEqual';
9
9
  import { ActionCreators } from 'redux-undo';
10
10
  import GraphWithControls from '../graph-with-controls';
11
- import { lastActionMiddleware, getLastAction } from './middleware';
11
+ import { lastActionMiddleware } from './middleware';
12
12
 
13
13
  const mapStateToProps = (s) => ({
14
14
  marks: s.marks.present,
@@ -58,11 +58,9 @@ class Root extends React.Component {
58
58
  onStoreChange = () => {
59
59
  const { marks, onChangeMarks } = this.props;
60
60
  const storeState = this.store.getState();
61
- const lastAction = getLastAction();
62
- const isUndoOperation = lastAction.type.includes('UNDO') || lastAction.type.includes('REDO');
63
61
 
64
62
  if (!isEqual(storeState.marks.present, marks)) {
65
- onChangeMarks(storeState.marks.present, isUndoOperation);
63
+ onChangeMarks(storeState.marks.present);
66
64
  }
67
65
  };
68
66