@pie-lib/graphing 2.14.22 → 2.15.0-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.
Files changed (193) hide show
  1. package/CHANGELOG.md +13 -80
  2. package/NEXT.CHANGELOG.json +1 -0
  3. package/lib/axis/axes.js +5 -5
  4. package/lib/axis/axes.js.map +1 -1
  5. package/lib/container/index.js +1 -4
  6. package/lib/container/index.js.map +1 -1
  7. package/lib/coordinates-label.js +5 -3
  8. package/lib/coordinates-label.js.map +1 -1
  9. package/lib/graph-with-controls.js +8 -15
  10. package/lib/graph-with-controls.js.map +1 -1
  11. package/lib/graph.js +29 -12
  12. package/lib/graph.js.map +1 -1
  13. package/lib/grid.js +6 -14
  14. package/lib/grid.js.map +1 -1
  15. package/lib/index.js +8 -0
  16. package/lib/index.js.map +1 -1
  17. package/lib/key-legend.js +246 -0
  18. package/lib/key-legend.js.map +1 -0
  19. package/lib/label-svg-icon.js +56 -0
  20. package/lib/label-svg-icon.js.map +1 -0
  21. package/lib/labels.js +2 -1
  22. package/lib/labels.js.map +1 -1
  23. package/lib/mark-label.js +167 -56
  24. package/lib/mark-label.js.map +1 -1
  25. package/lib/toggle-bar.js +3 -4
  26. package/lib/toggle-bar.js.map +1 -1
  27. package/lib/tool-menu.js +2 -22
  28. package/lib/tool-menu.js.map +1 -1
  29. package/lib/tools/absolute/component.js +35 -0
  30. package/lib/tools/absolute/component.js.map +1 -0
  31. package/lib/tools/absolute/index.js +63 -0
  32. package/lib/tools/absolute/index.js.map +1 -0
  33. package/lib/tools/circle/bg-circle.js +4 -3
  34. package/lib/tools/circle/bg-circle.js.map +1 -1
  35. package/lib/tools/circle/component.js +34 -15
  36. package/lib/tools/circle/component.js.map +1 -1
  37. package/lib/tools/exponential/component.js +34 -0
  38. package/lib/tools/exponential/component.js.map +1 -0
  39. package/lib/tools/exponential/index.js +71 -0
  40. package/lib/tools/exponential/index.js.map +1 -0
  41. package/lib/tools/index.js +26 -6
  42. package/lib/tools/index.js.map +1 -1
  43. package/lib/tools/line/component.js +2 -1
  44. package/lib/tools/line/component.js.map +1 -1
  45. package/lib/tools/parabola/component.js +6 -5
  46. package/lib/tools/parabola/component.js.map +1 -1
  47. package/lib/tools/point/component.js +14 -9
  48. package/lib/tools/point/component.js.map +1 -1
  49. package/lib/tools/polygon/component.js +25 -12
  50. package/lib/tools/polygon/component.js.map +1 -1
  51. package/lib/tools/polygon/line.js +12 -6
  52. package/lib/tools/polygon/line.js.map +1 -1
  53. package/lib/tools/polygon/polygon.js +6 -3
  54. package/lib/tools/polygon/polygon.js.map +1 -1
  55. package/lib/tools/ray/component.js +2 -1
  56. package/lib/tools/ray/component.js.map +1 -1
  57. package/lib/tools/segment/component.js +2 -1
  58. package/lib/tools/segment/component.js.map +1 -1
  59. package/lib/tools/shared/icons/CorrectSVG.js +36 -0
  60. package/lib/tools/shared/icons/CorrectSVG.js.map +1 -0
  61. package/lib/tools/shared/icons/IncorrectSVG.js +36 -0
  62. package/lib/tools/shared/icons/IncorrectSVG.js.map +1 -0
  63. package/lib/tools/shared/icons/MissingSVG.js +35 -0
  64. package/lib/tools/shared/icons/MissingSVG.js.map +1 -0
  65. package/lib/tools/shared/line/index.js +51 -19
  66. package/lib/tools/shared/line/index.js.map +1 -1
  67. package/lib/tools/shared/line/line-path.js +13 -7
  68. package/lib/tools/shared/line/line-path.js.map +1 -1
  69. package/lib/tools/shared/line/with-root-edge.js +19 -8
  70. package/lib/tools/shared/line/with-root-edge.js.map +1 -1
  71. package/lib/tools/shared/point/arrow-point.js +1 -1
  72. package/lib/tools/shared/point/arrow-point.js.map +1 -1
  73. package/lib/tools/shared/point/arrow.js +1 -1
  74. package/lib/tools/shared/point/arrow.js.map +1 -1
  75. package/lib/tools/shared/point/base-point.js +43 -7
  76. package/lib/tools/shared/point/base-point.js.map +1 -1
  77. package/lib/tools/shared/point/index.js +4 -1
  78. package/lib/tools/shared/point/index.js.map +1 -1
  79. package/lib/tools/shared/styles.js +16 -7
  80. package/lib/tools/shared/styles.js.map +1 -1
  81. package/lib/tools/sine/component.js +13 -4
  82. package/lib/tools/sine/component.js.map +1 -1
  83. package/lib/tools/vector/component.js +2 -1
  84. package/lib/tools/vector/component.js.map +1 -1
  85. package/lib/undo-redo.js +0 -1
  86. package/lib/undo-redo.js.map +1 -1
  87. package/lib/utils.js +1 -1
  88. package/lib/utils.js.map +1 -1
  89. package/package.json +15 -9
  90. package/src/__tests__/__snapshots__/graph-with-controls.test.jsx.snap +237 -0
  91. package/src/__tests__/__snapshots__/graph.test.jsx.snap +211 -0
  92. package/src/__tests__/__snapshots__/grid.test.jsx.snap +54 -0
  93. package/src/__tests__/__snapshots__/labels.test.jsx.snap +30 -0
  94. package/src/__tests__/__snapshots__/mark-label.test.jsx.snap +45 -0
  95. package/src/__tests__/__snapshots__/toggle-bar.test.jsx.snap +7 -0
  96. package/src/__tests__/__snapshots__/tool-menu.test.jsx.snap +13 -0
  97. package/src/__tests__/__snapshots__/undo-redo.test.jsx.snap +14 -0
  98. package/src/__tests__/graph-with-controls.test.jsx +147 -0
  99. package/src/__tests__/graph.test.jsx +230 -0
  100. package/src/__tests__/grid.test.jsx +20 -0
  101. package/src/__tests__/labels.test.jsx +38 -0
  102. package/src/__tests__/mark-label.test.jsx +68 -0
  103. package/src/__tests__/toggle-bar.test.jsx +36 -0
  104. package/src/__tests__/tool-menu.test.jsx +29 -0
  105. package/src/__tests__/undo-redo.test.jsx +25 -0
  106. package/src/__tests__/use-debounce.test.js +21 -0
  107. package/src/__tests__/utils.js +38 -0
  108. package/src/__tests__/utils.test.js +151 -0
  109. package/src/axis/__tests__/__snapshots__/arrow.test.jsx.snap +33 -0
  110. package/src/axis/__tests__/__snapshots__/axes.test.jsx.snap +122 -0
  111. package/src/axis/__tests__/arrow.test.jsx +39 -0
  112. package/src/axis/__tests__/axes.test.jsx +220 -0
  113. package/src/axis/axes.jsx +5 -5
  114. package/src/container/index.jsx +2 -4
  115. package/src/coordinates-label.jsx +4 -3
  116. package/src/graph-with-controls.jsx +8 -10
  117. package/src/graph.jsx +22 -10
  118. package/src/grid.jsx +8 -10
  119. package/src/index.js +2 -2
  120. package/src/key-legend.jsx +145 -0
  121. package/src/label-svg-icon.jsx +39 -0
  122. package/src/labels.jsx +2 -1
  123. package/src/mark-label.jsx +149 -52
  124. package/src/toggle-bar.jsx +1 -2
  125. package/src/tool-menu.jsx +3 -26
  126. package/src/tools/absolute/__tests__/component.test.jsx +54 -0
  127. package/src/tools/absolute/component.jsx +23 -0
  128. package/src/tools/absolute/index.js +31 -0
  129. package/src/tools/circle/__tests__/__snapshots__/bg-circle.test.jsx.snap +46 -0
  130. package/src/tools/circle/__tests__/__snapshots__/component.test.jsx.snap +293 -0
  131. package/src/tools/circle/__tests__/bg-circle.test.jsx +28 -0
  132. package/src/tools/circle/__tests__/component.test.jsx +228 -0
  133. package/src/tools/circle/bg-circle.jsx +5 -4
  134. package/src/tools/circle/component.jsx +22 -8
  135. package/src/tools/exponential/__tests__/component.test.jsx +54 -0
  136. package/src/tools/exponential/component.jsx +23 -0
  137. package/src/tools/exponential/index.js +39 -0
  138. package/src/tools/index.js +38 -5
  139. package/src/tools/line/__tests__/__snapshots__/component.test.jsx.snap +20 -0
  140. package/src/tools/line/__tests__/component.test.jsx +36 -0
  141. package/src/tools/line/component.jsx +2 -1
  142. package/src/tools/parabola/__tests__/component.test.jsx +49 -0
  143. package/src/tools/parabola/component.jsx +7 -6
  144. package/src/tools/point/__tests__/__snapshots__/component.test.jsx.snap +40 -0
  145. package/src/tools/point/__tests__/component.test.jsx +66 -0
  146. package/src/tools/point/component.jsx +12 -6
  147. package/src/tools/polygon/__tests__/__snapshots__/component.test.jsx.snap +415 -0
  148. package/src/tools/polygon/__tests__/__snapshots__/line.test.jsx.snap +45 -0
  149. package/src/tools/polygon/__tests__/__snapshots__/polygon.test.jsx.snap +52 -0
  150. package/src/tools/polygon/__tests__/component.test.jsx +226 -0
  151. package/src/tools/polygon/__tests__/index.test.js +65 -0
  152. package/src/tools/polygon/__tests__/line.test.jsx +25 -0
  153. package/src/tools/polygon/__tests__/polygon.test.jsx +44 -0
  154. package/src/tools/polygon/component.jsx +39 -11
  155. package/src/tools/polygon/line.jsx +15 -7
  156. package/src/tools/polygon/polygon.jsx +7 -3
  157. package/src/tools/ray/__tests__/__snapshots__/component.test.jsx.snap +23 -0
  158. package/src/tools/ray/__tests__/component.test.jsx +29 -0
  159. package/src/tools/ray/component.jsx +2 -1
  160. package/src/tools/segment/__tests__/__snapshots__/component.test.jsx.snap +14 -0
  161. package/src/tools/segment/__tests__/component.test.jsx +28 -0
  162. package/src/tools/segment/component.jsx +2 -1
  163. package/src/tools/shared/__tests__/__snapshots__/arrow-head.test.jsx.snap +27 -0
  164. package/src/tools/shared/__tests__/arrow-head.test.jsx +34 -0
  165. package/src/tools/shared/icons/CorrectSVG.jsx +22 -0
  166. package/src/tools/shared/icons/IncorrectSVG.jsx +20 -0
  167. package/src/tools/shared/icons/MissingSVG.jsx +21 -0
  168. package/src/tools/shared/line/__tests__/__snapshots__/index.test.jsx.snap +360 -0
  169. package/src/tools/shared/line/__tests__/__snapshots__/line-path.test.jsx.snap +58 -0
  170. package/src/tools/shared/line/__tests__/__snapshots__/with-root-edge.test.jsx.snap +63 -0
  171. package/src/tools/shared/line/__tests__/index.test.jsx +255 -0
  172. package/src/tools/shared/line/__tests__/line-path.test.jsx +53 -0
  173. package/src/tools/shared/line/__tests__/with-root-edge.test.jsx +73 -0
  174. package/src/tools/shared/line/index.jsx +39 -13
  175. package/src/tools/shared/line/line-path.jsx +18 -7
  176. package/src/tools/shared/line/with-root-edge.jsx +10 -3
  177. package/src/tools/shared/point/__tests__/__snapshots__/arrow-point.test.jsx.snap +56 -0
  178. package/src/tools/shared/point/__tests__/__snapshots__/base-point.test.jsx.snap +44 -0
  179. package/src/tools/shared/point/__tests__/arrow-point.test.jsx +87 -0
  180. package/src/tools/shared/point/__tests__/base-point.test.jsx +84 -0
  181. package/src/tools/shared/point/arrow-point.jsx +4 -1
  182. package/src/tools/shared/point/arrow.jsx +4 -1
  183. package/src/tools/shared/point/base-point.jsx +28 -3
  184. package/src/tools/shared/point/index.jsx +7 -2
  185. package/src/tools/shared/styles.js +8 -3
  186. package/src/tools/sine/__tests__/component.test.jsx +51 -0
  187. package/src/tools/sine/component.jsx +7 -7
  188. package/src/tools/vector/__tests__/__snapshots__/component.test.jsx.snap +12 -0
  189. package/src/tools/vector/__tests__/component.test.jsx +26 -0
  190. package/src/tools/vector/component.jsx +2 -1
  191. package/src/undo-redo.jsx +0 -1
  192. package/src/utils.js +1 -1
  193. package/legacy.png +0 -0
@@ -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
 
@@ -12,7 +12,7 @@ const styles = (theme) => ({
12
12
  fontSize: theme.typography.fontSize,
13
13
  borderRadius: '8px',
14
14
  background: theme.palette.common.white,
15
- color: color.primaryDark(),
15
+ color: color.defaults.PRIMARY_DARK,
16
16
  },
17
17
  inputLabel: {
18
18
  padding: 0,
@@ -20,8 +20,9 @@ const styles = (theme) => ({
20
20
  });
21
21
 
22
22
  export const getLabelPosition = (graphProps, x, y, labelLength) => {
23
- const { scale, domain } = graphProps;
24
- const topShift = 8;
23
+ const { scale, domain, range } = graphProps;
24
+ // treat corner cases for maximum and minimum
25
+ const topShift = y === range.min ? 16 : y === range.max ? 0 : 8;
25
26
  const leftShift = 10;
26
27
  const rightEdge = scale.x(x) + labelLength + leftShift;
27
28