@pie-lib/graphing 2.14.22 → 2.15.1-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 (215) hide show
  1. package/CHANGELOG.md +13 -80
  2. package/NEXT.CHANGELOG.json +1 -0
  3. package/package.json +14 -7
  4. package/src/__tests__/__snapshots__/graph-with-controls.test.jsx.snap +237 -0
  5. package/src/__tests__/__snapshots__/graph.test.jsx.snap +211 -0
  6. package/src/__tests__/__snapshots__/grid.test.jsx.snap +54 -0
  7. package/src/__tests__/__snapshots__/labels.test.jsx.snap +30 -0
  8. package/src/__tests__/__snapshots__/mark-label.test.jsx.snap +45 -0
  9. package/src/__tests__/__snapshots__/toggle-bar.test.jsx.snap +7 -0
  10. package/src/__tests__/__snapshots__/tool-menu.test.jsx.snap +13 -0
  11. package/src/__tests__/__snapshots__/undo-redo.test.jsx.snap +14 -0
  12. package/src/__tests__/graph-with-controls.test.jsx +147 -0
  13. package/src/__tests__/graph.test.jsx +230 -0
  14. package/src/__tests__/grid.test.jsx +20 -0
  15. package/src/__tests__/labels.test.jsx +38 -0
  16. package/src/__tests__/mark-label.test.jsx +68 -0
  17. package/src/__tests__/toggle-bar.test.jsx +36 -0
  18. package/src/__tests__/tool-menu.test.jsx +29 -0
  19. package/src/__tests__/undo-redo.test.jsx +25 -0
  20. package/src/__tests__/use-debounce.test.js +21 -0
  21. package/src/__tests__/utils.js +38 -0
  22. package/src/__tests__/utils.test.js +151 -0
  23. package/src/axis/__tests__/__snapshots__/arrow.test.jsx.snap +33 -0
  24. package/src/axis/__tests__/__snapshots__/axes.test.jsx.snap +122 -0
  25. package/src/axis/__tests__/arrow.test.jsx +39 -0
  26. package/src/axis/__tests__/axes.test.jsx +220 -0
  27. package/src/axis/axes.jsx +5 -5
  28. package/src/container/index.jsx +2 -4
  29. package/src/coordinates-label.jsx +4 -3
  30. package/src/graph-with-controls.jsx +8 -10
  31. package/src/graph.jsx +22 -10
  32. package/src/grid.jsx +8 -10
  33. package/src/index.js +2 -2
  34. package/src/key-legend.jsx +145 -0
  35. package/src/label-svg-icon.jsx +39 -0
  36. package/src/labels.jsx +2 -1
  37. package/src/mark-label.jsx +149 -52
  38. package/src/toggle-bar.jsx +1 -2
  39. package/src/tool-menu.jsx +3 -26
  40. package/src/tools/absolute/__tests__/component.test.jsx +54 -0
  41. package/src/tools/absolute/component.jsx +23 -0
  42. package/src/tools/absolute/index.js +31 -0
  43. package/src/tools/circle/__tests__/__snapshots__/bg-circle.test.jsx.snap +46 -0
  44. package/src/tools/circle/__tests__/__snapshots__/component.test.jsx.snap +293 -0
  45. package/src/tools/circle/__tests__/bg-circle.test.jsx +28 -0
  46. package/src/tools/circle/__tests__/component.test.jsx +228 -0
  47. package/src/tools/circle/bg-circle.jsx +5 -4
  48. package/src/tools/circle/component.jsx +22 -8
  49. package/src/tools/exponential/__tests__/component.test.jsx +54 -0
  50. package/src/tools/exponential/component.jsx +23 -0
  51. package/src/tools/exponential/index.js +39 -0
  52. package/src/tools/index.js +38 -5
  53. package/src/tools/line/__tests__/__snapshots__/component.test.jsx.snap +20 -0
  54. package/src/tools/line/__tests__/component.test.jsx +36 -0
  55. package/src/tools/line/component.jsx +2 -1
  56. package/src/tools/parabola/__tests__/component.test.jsx +49 -0
  57. package/src/tools/parabola/component.jsx +7 -6
  58. package/src/tools/point/__tests__/__snapshots__/component.test.jsx.snap +40 -0
  59. package/src/tools/point/__tests__/component.test.jsx +66 -0
  60. package/src/tools/point/component.jsx +12 -6
  61. package/src/tools/polygon/__tests__/__snapshots__/component.test.jsx.snap +415 -0
  62. package/src/tools/polygon/__tests__/__snapshots__/line.test.jsx.snap +45 -0
  63. package/src/tools/polygon/__tests__/__snapshots__/polygon.test.jsx.snap +52 -0
  64. package/src/tools/polygon/__tests__/component.test.jsx +226 -0
  65. package/src/tools/polygon/__tests__/index.test.js +65 -0
  66. package/src/tools/polygon/__tests__/line.test.jsx +25 -0
  67. package/src/tools/polygon/__tests__/polygon.test.jsx +44 -0
  68. package/src/tools/polygon/component.jsx +39 -11
  69. package/src/tools/polygon/line.jsx +15 -7
  70. package/src/tools/polygon/polygon.jsx +7 -3
  71. package/src/tools/ray/__tests__/__snapshots__/component.test.jsx.snap +23 -0
  72. package/src/tools/ray/__tests__/component.test.jsx +29 -0
  73. package/src/tools/ray/component.jsx +2 -1
  74. package/src/tools/segment/__tests__/__snapshots__/component.test.jsx.snap +14 -0
  75. package/src/tools/segment/__tests__/component.test.jsx +28 -0
  76. package/src/tools/segment/component.jsx +2 -1
  77. package/src/tools/shared/__tests__/__snapshots__/arrow-head.test.jsx.snap +27 -0
  78. package/src/tools/shared/__tests__/arrow-head.test.jsx +34 -0
  79. package/src/tools/shared/icons/CorrectSVG.jsx +22 -0
  80. package/src/tools/shared/icons/IncorrectSVG.jsx +20 -0
  81. package/src/tools/shared/icons/MissingSVG.jsx +21 -0
  82. package/src/tools/shared/line/__tests__/__snapshots__/index.test.jsx.snap +360 -0
  83. package/src/tools/shared/line/__tests__/__snapshots__/line-path.test.jsx.snap +58 -0
  84. package/src/tools/shared/line/__tests__/__snapshots__/with-root-edge.test.jsx.snap +63 -0
  85. package/src/tools/shared/line/__tests__/index.test.jsx +255 -0
  86. package/src/tools/shared/line/__tests__/line-path.test.jsx +53 -0
  87. package/src/tools/shared/line/__tests__/with-root-edge.test.jsx +73 -0
  88. package/src/tools/shared/line/index.jsx +39 -13
  89. package/src/tools/shared/line/line-path.jsx +18 -7
  90. package/src/tools/shared/line/with-root-edge.jsx +10 -3
  91. package/src/tools/shared/point/__tests__/__snapshots__/arrow-point.test.jsx.snap +56 -0
  92. package/src/tools/shared/point/__tests__/__snapshots__/base-point.test.jsx.snap +44 -0
  93. package/src/tools/shared/point/__tests__/arrow-point.test.jsx +87 -0
  94. package/src/tools/shared/point/__tests__/base-point.test.jsx +84 -0
  95. package/src/tools/shared/point/arrow-point.jsx +4 -1
  96. package/src/tools/shared/point/arrow.jsx +4 -1
  97. package/src/tools/shared/point/base-point.jsx +28 -3
  98. package/src/tools/shared/point/index.jsx +7 -2
  99. package/src/tools/shared/styles.js +8 -3
  100. package/src/tools/sine/__tests__/component.test.jsx +51 -0
  101. package/src/tools/sine/component.jsx +7 -7
  102. package/src/tools/vector/__tests__/__snapshots__/component.test.jsx.snap +12 -0
  103. package/src/tools/vector/__tests__/component.test.jsx +26 -0
  104. package/src/tools/vector/component.jsx +2 -1
  105. package/src/undo-redo.jsx +0 -1
  106. package/src/utils.js +1 -1
  107. package/legacy.png +0 -0
  108. package/lib/axis/arrow.js +0 -115
  109. package/lib/axis/arrow.js.map +0 -1
  110. package/lib/axis/axes.js +0 -415
  111. package/lib/axis/axes.js.map +0 -1
  112. package/lib/axis/index.js +0 -26
  113. package/lib/axis/index.js.map +0 -1
  114. package/lib/bg.js +0 -139
  115. package/lib/bg.js.map +0 -1
  116. package/lib/container/actions.js +0 -24
  117. package/lib/container/actions.js.map +0 -1
  118. package/lib/container/index.js +0 -166
  119. package/lib/container/index.js.map +0 -1
  120. package/lib/container/marks.js +0 -27
  121. package/lib/container/marks.js.map +0 -1
  122. package/lib/container/middleware.js +0 -25
  123. package/lib/container/middleware.js.map +0 -1
  124. package/lib/container/reducer.js +0 -25
  125. package/lib/container/reducer.js.map +0 -1
  126. package/lib/coordinates-label.js +0 -107
  127. package/lib/coordinates-label.js.map +0 -1
  128. package/lib/graph-with-controls.js +0 -366
  129. package/lib/graph-with-controls.js.map +0 -1
  130. package/lib/graph.js +0 -354
  131. package/lib/graph.js.map +0 -1
  132. package/lib/grid-setup.js +0 -462
  133. package/lib/grid-setup.js.map +0 -1
  134. package/lib/grid.js +0 -184
  135. package/lib/grid.js.map +0 -1
  136. package/lib/index.js +0 -51
  137. package/lib/index.js.map +0 -1
  138. package/lib/labels.js +0 -298
  139. package/lib/labels.js.map +0 -1
  140. package/lib/mark-label.js +0 -210
  141. package/lib/mark-label.js.map +0 -1
  142. package/lib/toggle-bar.js +0 -337
  143. package/lib/toggle-bar.js.map +0 -1
  144. package/lib/tool-menu.js +0 -132
  145. package/lib/tool-menu.js.map +0 -1
  146. package/lib/tools/circle/bg-circle.js +0 -172
  147. package/lib/tools/circle/bg-circle.js.map +0 -1
  148. package/lib/tools/circle/component.js +0 -387
  149. package/lib/tools/circle/component.js.map +0 -1
  150. package/lib/tools/circle/index.js +0 -51
  151. package/lib/tools/circle/index.js.map +0 -1
  152. package/lib/tools/index.js +0 -79
  153. package/lib/tools/index.js.map +0 -1
  154. package/lib/tools/line/component.js +0 -102
  155. package/lib/tools/line/component.js.map +0 -1
  156. package/lib/tools/line/index.js +0 -16
  157. package/lib/tools/line/index.js.map +0 -1
  158. package/lib/tools/parabola/component.js +0 -33
  159. package/lib/tools/parabola/component.js.map +0 -1
  160. package/lib/tools/parabola/index.js +0 -63
  161. package/lib/tools/parabola/index.js.map +0 -1
  162. package/lib/tools/point/component.js +0 -181
  163. package/lib/tools/point/component.js.map +0 -1
  164. package/lib/tools/point/index.js +0 -32
  165. package/lib/tools/point/index.js.map +0 -1
  166. package/lib/tools/polygon/component.js +0 -505
  167. package/lib/tools/polygon/component.js.map +0 -1
  168. package/lib/tools/polygon/index.js +0 -106
  169. package/lib/tools/polygon/index.js.map +0 -1
  170. package/lib/tools/polygon/line.js +0 -151
  171. package/lib/tools/polygon/line.js.map +0 -1
  172. package/lib/tools/polygon/polygon.js +0 -162
  173. package/lib/tools/polygon/polygon.js.map +0 -1
  174. package/lib/tools/ray/component.js +0 -101
  175. package/lib/tools/ray/component.js.map +0 -1
  176. package/lib/tools/ray/index.js +0 -16
  177. package/lib/tools/ray/index.js.map +0 -1
  178. package/lib/tools/segment/component.js +0 -74
  179. package/lib/tools/segment/component.js.map +0 -1
  180. package/lib/tools/segment/index.js +0 -16
  181. package/lib/tools/segment/index.js.map +0 -1
  182. package/lib/tools/shared/arrow-head.js +0 -70
  183. package/lib/tools/shared/arrow-head.js.map +0 -1
  184. package/lib/tools/shared/line/index.js +0 -567
  185. package/lib/tools/shared/line/index.js.map +0 -1
  186. package/lib/tools/shared/line/line-path.js +0 -145
  187. package/lib/tools/shared/line/line-path.js.map +0 -1
  188. package/lib/tools/shared/line/with-root-edge.js +0 -144
  189. package/lib/tools/shared/line/with-root-edge.js.map +0 -1
  190. package/lib/tools/shared/point/arrow-point.js +0 -113
  191. package/lib/tools/shared/point/arrow-point.js.map +0 -1
  192. package/lib/tools/shared/point/arrow.js +0 -96
  193. package/lib/tools/shared/point/arrow.js.map +0 -1
  194. package/lib/tools/shared/point/base-point.js +0 -139
  195. package/lib/tools/shared/point/base-point.js.map +0 -1
  196. package/lib/tools/shared/point/index.js +0 -94
  197. package/lib/tools/shared/point/index.js.map +0 -1
  198. package/lib/tools/shared/styles.js +0 -49
  199. package/lib/tools/shared/styles.js.map +0 -1
  200. package/lib/tools/shared/types.js +0 -23
  201. package/lib/tools/shared/types.js.map +0 -1
  202. package/lib/tools/sine/component.js +0 -42
  203. package/lib/tools/sine/component.js.map +0 -1
  204. package/lib/tools/sine/index.js +0 -63
  205. package/lib/tools/sine/index.js.map +0 -1
  206. package/lib/tools/vector/component.js +0 -87
  207. package/lib/tools/vector/component.js.map +0 -1
  208. package/lib/tools/vector/index.js +0 -16
  209. package/lib/tools/vector/index.js.map +0 -1
  210. package/lib/undo-redo.js +0 -124
  211. package/lib/undo-redo.js.map +0 -1
  212. package/lib/use-debounce.js +0 -32
  213. package/lib/use-debounce.js.map +0 -1
  214. package/lib/utils.js +0 -307
  215. package/lib/utils.js.map +0 -1
@@ -42,6 +42,7 @@ export class RawBaseCircle extends React.Component {
42
42
  labelNode: PropTypes.object,
43
43
  labelModeEnabled: PropTypes.bool,
44
44
  changeMarkProps: PropTypes.func,
45
+ limitLabeling: PropTypes.bool,
45
46
  };
46
47
 
47
48
  static defaultProps = {
@@ -128,8 +129,21 @@ export class RawBaseCircle extends React.Component {
128
129
  changeMarkProps({ [type]: update });
129
130
  };
130
131
 
131
- clickPoint = (point, type) => {
132
- const { changeMarkProps, from, to } = this.props;
132
+ clickPoint = (point, type, data) => {
133
+ const { changeMarkProps, disabled, from, to, labelModeEnabled, limitLabeling, onClick } = this.props;
134
+ if (!labelModeEnabled) {
135
+ onClick(point || data);
136
+ return;
137
+ }
138
+
139
+ if (disabled) {
140
+ return;
141
+ }
142
+
143
+ // limit labeling the points of the circle
144
+ if (limitLabeling) {
145
+ return;
146
+ }
133
147
 
134
148
  if (type === 'middle' && !point && from && to) {
135
149
  point = { ...point, ...getMiddleOfTwoPoints(from, to) };
@@ -224,7 +238,7 @@ export class RawBaseCircle extends React.Component {
224
238
  radius={radius}
225
239
  onDrag={this.dragCircle}
226
240
  {...common}
227
- onClick={labelModeEnabled ? () => this.clickPoint(middle, 'middle') : common.onClick}
241
+ onClick={(data) => this.clickPoint(middle, 'middle', data)}
228
242
  />
229
243
  {circleLabelNode}
230
244
 
@@ -237,7 +251,7 @@ export class RawBaseCircle extends React.Component {
237
251
  y={to.y}
238
252
  onDrag={this.dragTo}
239
253
  {...common}
240
- onClick={labelModeEnabled ? () => this.clickPoint(to, 'to') : common.onClick}
254
+ onClick={(data) => this.clickPoint(to, 'to', data)}
241
255
  />
242
256
  {toLabelNode}
243
257
 
@@ -251,7 +265,7 @@ export class RawBaseCircle extends React.Component {
251
265
  className={classes.from}
252
266
  onDrag={this.dragFrom}
253
267
  {...common}
254
- onClick={labelModeEnabled ? () => this.clickPoint(from, 'from') : common.onClick}
268
+ onClick={(data) => this.clickPoint(from, 'from', data)}
255
269
  />
256
270
  {fromLabelNode}
257
271
  </g>
@@ -262,16 +276,16 @@ export class RawBaseCircle extends React.Component {
262
276
  export const BaseCircle = withStyles(() => ({
263
277
  outerLine: {
264
278
  fill: 'rgb(0,0,0,0)', // TODO hardcoded color
265
- stroke: color.primaryLight(),
279
+ stroke: color.defaults.BLACK,
266
280
  strokeWidth: 4,
267
281
  '&:hover': {
268
282
  strokeWidth: 6,
269
- stroke: color.primaryDark(),
283
+ stroke: color.defaults.PRIMARY_DARK,
270
284
  },
271
285
  },
272
286
  root: {},
273
287
  bgCircleBuilding: {
274
- stroke: color.secondaryLight(),
288
+ stroke: color.defaults.BLACK,
275
289
  animation: 'opacityPulse 2s ease-out',
276
290
  animationIterationCount: 'infinite',
277
291
  opacity: 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