@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,54 @@
1
+ import React from 'react';
2
+ import { withRootEdge } from '../../shared/line/with-root-edge';
3
+ import { buildDataPoints, exponentialFromTwoPoints } from '@pie-lib/graphing-utils';
4
+ import { utils } from '@pie-lib/plot';
5
+
6
+ import { graphProps as getGraphProps } from '../../../__tests__/utils';
7
+
8
+ const { xy } = utils;
9
+
10
+ jest.mock('@pie-lib/graphing-utils', () => ({
11
+ buildDataPoints: jest.fn().mockReturnValue([]),
12
+ exponentialFromTwoPoints: jest.fn(() => jest.fn()),
13
+ getAmplitudeAndFreq: jest.fn().mockReturnValue({ freq: 4, amplitude: 1 }),
14
+ }));
15
+
16
+ jest.mock('../../shared/line/with-root-edge', () => ({
17
+ withRootEdge: jest.fn(),
18
+ rootEdgeComponent: jest.fn(),
19
+ }));
20
+
21
+ describe('Exponential', () => {
22
+ let fnBody;
23
+ let graphProps;
24
+ let root;
25
+ let edge;
26
+ let result;
27
+
28
+ beforeEach(() => {
29
+ require('../component');
30
+ fnBody = withRootEdge.mock.calls[0][0];
31
+ graphProps = getGraphProps();
32
+ root = xy(1, 1);
33
+ edge = xy(2, 2);
34
+
35
+ result = fnBody({ graphProps, root, edge });
36
+ });
37
+
38
+ it('fnBody is not null', () => {
39
+ expect(fnBody).toBeDefined();
40
+ });
41
+
42
+ it('calls buildDataPoints', () => {
43
+ const { domain, range } = graphProps;
44
+ expect(buildDataPoints).toHaveBeenCalledWith(domain, range, root, edge, expect.anything(), true);
45
+ });
46
+
47
+ it('calls exponentialFromTwoPoints', () => {
48
+ expect(exponentialFromTwoPoints).toHaveBeenCalledWith(root, edge);
49
+ });
50
+
51
+ it('returns dataPoints', () => {
52
+ expect(result).toEqual({ root, edge, dataPoints: [] });
53
+ });
54
+ });
@@ -0,0 +1,23 @@
1
+ import debug from 'debug';
2
+ import { buildDataPoints, exponentialFromTwoPoints } from '@pie-lib/graphing-utils';
3
+ import { withRootEdge, rootEdgeComponent } from '../shared/line/with-root-edge';
4
+
5
+ const log = debug('pie-lib:graphing:exponential');
6
+
7
+ const Exponential = withRootEdge((props) => {
8
+ const { root, edge, graphProps } = props;
9
+ const { domain, range } = graphProps;
10
+
11
+ const dataPoints =
12
+ edge && edge.x === root.x
13
+ ? []
14
+ : buildDataPoints(domain, range, root, edge, exponentialFromTwoPoints(root, edge), true);
15
+
16
+ log('dataPoints:', dataPoints);
17
+
18
+ return { root: props.root, edge: props.edge, dataPoints };
19
+ });
20
+
21
+ const Component = rootEdgeComponent(Exponential);
22
+
23
+ export default Component;
@@ -0,0 +1,39 @@
1
+ import Exponential from './component';
2
+ import debug from 'debug';
3
+ import { equalPoints, sameAxes } from '../../utils';
4
+
5
+ const log = debug('pie-lib:graphing:exponential');
6
+
7
+ export const tool = () => ({
8
+ type: 'exponential',
9
+ Component: Exponential,
10
+ complete: (data, mark) => ({ ...mark, building: false, closed: true }),
11
+ addPoint: (point, mark) => {
12
+ log('add point to exponential model: ', point, 'mark: ', mark);
13
+ if (mark && (equalPoints(mark.root, point) || sameAxes(mark.root, point))) {
14
+ return mark;
15
+ }
16
+
17
+ if (mark && mark.root.y * point.y < 0) {
18
+ return mark;
19
+ }
20
+
21
+ if (point.y === 0) {
22
+ return mark;
23
+ }
24
+
25
+ if (!mark) {
26
+ return {
27
+ type: 'exponential',
28
+ root: point,
29
+ edge: undefined,
30
+ closed: false,
31
+ building: true,
32
+ };
33
+ } else if (mark && !mark.root) {
34
+ throw new Error('no root - should never happen');
35
+ } else {
36
+ return { ...mark, edge: point, closed: true, building: false };
37
+ }
38
+ },
39
+ });
@@ -1,15 +1,48 @@
1
1
  import { tool as point } from './point';
2
2
  import { tool as circle } from './circle';
3
3
  import { tool as polygon } from './polygon';
4
- import { tool as sine } from './sine/index';
5
- import { tool as parabola } from './parabola/index';
4
+ import { tool as sine } from './sine';
5
+ import { tool as parabola } from './parabola';
6
6
  import { tool as line } from './line';
7
7
  import { tool as segment } from './segment';
8
8
  import { tool as ray } from './ray';
9
9
  import { tool as vector } from './vector';
10
+ import { tool as absolute } from './absolute';
11
+ import { tool as exponential } from './exponential';
10
12
 
11
- const allTools = ['circle', 'line', 'label', 'parabola', 'point', 'polygon', 'ray', 'segment', 'sine', 'vector'];
13
+ const allTools = [
14
+ 'circle',
15
+ 'line',
16
+ 'label',
17
+ 'parabola',
18
+ 'point',
19
+ 'polygon',
20
+ 'ray',
21
+ 'segment',
22
+ 'sine',
23
+ 'vector',
24
+ 'absolute',
25
+ 'exponential',
26
+ ];
12
27
 
13
- const toolsArr = [circle(), line(), parabola(), point(), polygon(), ray(), segment(), sine(), vector()];
28
+ // need this because now we should treat label as other tools PD-3736
29
+ const labelTool = {
30
+ type: 'label',
31
+ };
14
32
 
15
- export { allTools, toolsArr, circle, line, point, parabola, polygon, ray, sine, vector };
33
+ const toolsArr = [
34
+ circle(),
35
+ line(),
36
+ parabola(),
37
+ point(),
38
+ polygon(),
39
+ ray(),
40
+ segment(),
41
+ sine(),
42
+ vector(),
43
+ absolute(),
44
+ exponential(),
45
+ labelTool,
46
+ ];
47
+
48
+ export { allTools, toolsArr, circle, line, point, parabola, polygon, ray, sine, vector, absolute, exponential };
@@ -0,0 +1,20 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`ArrowedLine snapshot renders 1`] = `
4
+ <g>
5
+ <defs>
6
+ <ArrowMarker
7
+ className=""
8
+ id="1-enabled"
9
+ size={5}
10
+ />
11
+ </defs>
12
+ <line
13
+ className="className"
14
+ markerEnd="url(#1-enabled)"
15
+ markerId="1"
16
+ markerStart="url(#1-enabled)"
17
+ onChange={[MockFunction]}
18
+ />
19
+ </g>
20
+ `;
@@ -0,0 +1,36 @@
1
+ import { shallow } from 'enzyme';
2
+ import React from 'react';
3
+ import { ArrowedLine } from '../component';
4
+ import { graphProps as getGraphProps } from '../../../__tests__/utils';
5
+ jest.mock('@pie-lib/plot/index', () => {
6
+ const a = jest.requireActual('@pie-lib/plot/index');
7
+ return {
8
+ types: a.types,
9
+ gridDraggable: a.gridDraggable,
10
+ utils: a.utils,
11
+ trig: {
12
+ edges: jest.fn(() => jest.fn().mockReturnValue([0, 0])),
13
+ },
14
+ };
15
+ });
16
+
17
+ describe('ArrowedLine', () => {
18
+ let w;
19
+ let onChange = jest.fn();
20
+ const wrapper = (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 shallow(<ArrowedLine {...props} />);
30
+ };
31
+ describe('snapshot', () => {
32
+ it('renders', () => {
33
+ expect(wrapper()).toMatchSnapshot();
34
+ });
35
+ });
36
+ });
@@ -12,6 +12,7 @@ const lineStyles = (theme) => ({
12
12
  enabledArrow: styles.arrow(theme),
13
13
  disabledArrow: styles.disabledArrow(theme),
14
14
  disabled: styles.disabled(theme),
15
+ disabledSecondary: styles.disabledSecondary(theme),
15
16
  correct: styles.correct(theme, 'stroke'),
16
17
  correctArrow: styles.correct(theme),
17
18
  incorrect: styles.incorrect(theme, 'stroke'),
@@ -42,7 +43,7 @@ export const ArrowedLine = (props) => {
42
43
  y1={scale.y(eFrom.y)}
43
44
  x2={scale.x(eTo.x)}
44
45
  y2={scale.y(eTo.y)}
45
- className={classNames(classes.line, disabled && classes.disabled, classes[correctness], className)}
46
+ className={classNames(classes.line, disabled && classes.disabledSecondary, classes[correctness], className)}
46
47
  markerEnd={`url(#${props.markerId || markerId}-${suffix})`}
47
48
  markerStart={`url(#${props.markerId || markerId}-${suffix})`}
48
49
  {...rest}
@@ -0,0 +1,49 @@
1
+ import React from 'react';
2
+ import { withRootEdge } from '../../shared/line/with-root-edge';
3
+ import { buildDataPoints, parabolaFromTwoPoints } from '@pie-lib/graphing-utils';
4
+ import { utils } from '@pie-lib/plot';
5
+
6
+ import { graphProps as getGraphProps } from '../../../__tests__/utils';
7
+
8
+ const { xy } = utils;
9
+ jest.mock('@pie-lib/graphing-utils', () => ({
10
+ buildDataPoints: jest.fn().mockReturnValue([]),
11
+ parabolaFromTwoPoints: jest.fn(() => jest.fn()),
12
+ getAmplitudeAndFreq: jest.fn().mockReturnValue({ freq: 4, amplitude: 1 }),
13
+ }));
14
+
15
+ jest.mock('../../shared/line/with-root-edge', () => ({
16
+ withRootEdge: jest.fn(),
17
+ rootEdgeComponent: jest.fn(),
18
+ }));
19
+ describe('Parabola', () => {
20
+ let fnBody;
21
+ let graphProps;
22
+ let root;
23
+ let edge;
24
+ let result;
25
+ beforeEach(() => {
26
+ require('../component');
27
+ fnBody = withRootEdge.mock.calls[0][0];
28
+ graphProps = getGraphProps();
29
+ root = xy(0, 0);
30
+ edge = xy(1, 1);
31
+
32
+ result = fnBody({ graphProps, root, edge });
33
+ });
34
+ it('fnBody is not null', () => {
35
+ expect(fnBody).toBeDefined();
36
+ });
37
+
38
+ it('calls buildDataPoints', () => {
39
+ const { domain, range } = graphProps;
40
+ expect(buildDataPoints).toHaveBeenCalledWith(domain, range, root, edge, expect.anything(), true);
41
+ });
42
+ it('calls parabolaFromTwoPoints', () => {
43
+ expect(parabolaFromTwoPoints).toHaveBeenCalledWith(root, edge);
44
+ });
45
+
46
+ it('returns dataPoints', () => {
47
+ expect(result).toEqual({ root, edge, dataPoints: [] });
48
+ });
49
+ });
@@ -2,21 +2,22 @@ import debug from 'debug';
2
2
  import { buildDataPoints, parabolaFromTwoPoints } from '@pie-lib/graphing-utils';
3
3
  import { withRootEdge, rootEdgeComponent } from '../shared/line/with-root-edge';
4
4
 
5
- const log = debug('pie-lib:graphing:sine');
5
+ const log = debug('pie-lib:graphing:parabola');
6
6
 
7
7
  const Parabola = withRootEdge((props) => {
8
- const { domain } = props.graphProps;
9
-
10
- const { root, edge } = props;
11
- const interval = 1;
8
+ const { root, edge, graphProps } = props;
9
+ const { domain, range } = graphProps;
12
10
 
13
11
  const dataPoints =
14
12
  edge && edge.x === root.x
15
13
  ? []
16
- : buildDataPoints(domain.min, domain.max, root, edge, domain.step || interval, parabolaFromTwoPoints(root, edge));
14
+ : buildDataPoints(domain, range, root, edge, parabolaFromTwoPoints(root, edge), true);
15
+
17
16
  log('dataPoints:', dataPoints);
17
+
18
18
  return { root: props.root, edge: props.edge, dataPoints };
19
19
  });
20
20
 
21
21
  const Component = rootEdgeComponent(Parabola);
22
+
22
23
  export default Component;
@@ -0,0 +1,40 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`Component snapshot renders 1`] = `
4
+ <Fragment>
5
+ <WithStyles(GridDraggable)
6
+ graphProps={
7
+ Object {
8
+ "domain": Object {
9
+ "max": 1,
10
+ "min": 0,
11
+ "step": 1,
12
+ },
13
+ "range": Object {
14
+ "max": 1,
15
+ "min": 0,
16
+ "step": 1,
17
+ },
18
+ "scale": Object {
19
+ "x": [MockFunction],
20
+ "y": [MockFunction],
21
+ },
22
+ "size": Object {
23
+ "height": 400,
24
+ "width": 400,
25
+ },
26
+ "snap": Object {
27
+ "x": [MockFunction],
28
+ "y": [MockFunction],
29
+ },
30
+ }
31
+ }
32
+ onClick={[Function]}
33
+ onDrag={[Function]}
34
+ onDragStart={[Function]}
35
+ onDragStop={[Function]}
36
+ onTouchEnd={[Function]}
37
+ onTouchStart={[Function]}
38
+ />
39
+ </Fragment>
40
+ `;
@@ -0,0 +1,66 @@
1
+ import { shallow } from 'enzyme';
2
+ import React from 'react';
3
+ import { graphProps, xy } from '../../../__tests__/utils';
4
+
5
+ import Component from '../component';
6
+
7
+ describe('Component', () => {
8
+ let w;
9
+ let onChange = jest.fn();
10
+ const wrapper = (extras, opts) => {
11
+ const defaults = {
12
+ classes: {},
13
+ className: 'className',
14
+ onChange,
15
+ graphProps: graphProps(),
16
+ };
17
+ const props = { ...defaults, ...extras };
18
+ return shallow(<Component {...props} />, opts);
19
+ };
20
+
21
+ describe('snapshot', () => {
22
+ it('renders', () => {
23
+ w = wrapper();
24
+ expect(w).toMatchSnapshot();
25
+ });
26
+ });
27
+
28
+ describe('logic', () => {
29
+ describe('move', () => {
30
+ it('calls onChange', () => {
31
+ const w = wrapper({ mark: { ...xy(0, 0) } });
32
+ w.instance().move({ x: 1, y: 1 });
33
+ expect(w.state('mark')).toMatchObject({ ...xy(1, 1) });
34
+ });
35
+ });
36
+
37
+ describe('labelChange', () => {
38
+ it('callsOnChange with label removed', () => {
39
+ const mark = { label: 'foo' };
40
+ const update = {};
41
+ const w = wrapper({ mark });
42
+ w.instance().labelChange(undefined);
43
+ expect(onChange).toHaveBeenCalledWith(mark, update);
44
+ });
45
+ });
46
+
47
+ describe('clickPoint', () => {
48
+ let mark;
49
+ let w;
50
+ beforeEach(() => {
51
+ mark = { label: 'foo' };
52
+ w = wrapper({ mark, labelModeEnabled: true }, { disableLifecycleMethods: true });
53
+ w.instance().input = {
54
+ focus: jest.fn(),
55
+ };
56
+ w.instance().clickPoint();
57
+ });
58
+ it('calls onChange if labelModeEnabeld', () => {
59
+ expect(onChange).toHaveBeenCalledWith(mark, { label: '', ...mark });
60
+ });
61
+ it('calls input.focus', () => {
62
+ expect(w.instance().input.focus).toHaveBeenCalled();
63
+ });
64
+ });
65
+ });
66
+ });
@@ -60,13 +60,19 @@ export class Point extends React.Component {
60
60
  clickPoint = () => {
61
61
  const { labelModeEnabled, onChange, onClick, mark } = this.props;
62
62
 
63
- if (labelModeEnabled) {
64
- onChange(mark, { label: '', ...mark });
65
- if (this.input) {
66
- this.input.focus();
67
- }
68
- } else {
63
+ if (!labelModeEnabled) {
69
64
  onClick(mark);
65
+ return;
66
+ }
67
+
68
+ if (mark.disabled) {
69
+ return;
70
+ }
71
+
72
+ onChange(mark, { label: '', ...mark });
73
+
74
+ if (this.input) {
75
+ this.input.focus();
70
76
  }
71
77
  };
72
78