@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
@@ -0,0 +1,44 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`BasePoint snapshot renders 1`] = `
4
+ <RawBp
5
+ className="className"
6
+ classes={
7
+ Object {
8
+ "correct": "RawBp-correct-4",
9
+ "disabled": "RawBp-disabled-2",
10
+ "disabledSecondary": "RawBp-disabledSecondary-3",
11
+ "incorrect": "RawBp-incorrect-5",
12
+ "missing": "RawBp-missing-6",
13
+ "point": "RawBp-point-1",
14
+ }
15
+ }
16
+ graphProps={
17
+ Object {
18
+ "domain": Object {
19
+ "max": 1,
20
+ "min": 0,
21
+ "step": 1,
22
+ },
23
+ "range": Object {
24
+ "max": 1,
25
+ "min": 0,
26
+ "step": 1,
27
+ },
28
+ "scale": Object {
29
+ "x": [MockFunction],
30
+ "y": [MockFunction],
31
+ },
32
+ "size": Object {
33
+ "height": 400,
34
+ "width": 400,
35
+ },
36
+ "snap": Object {
37
+ "x": [MockFunction],
38
+ "y": [MockFunction],
39
+ },
40
+ }
41
+ }
42
+ onChange={[MockFunction]}
43
+ />
44
+ `;
@@ -0,0 +1,87 @@
1
+ import { shallow } from 'enzyme/build';
2
+ import React from 'react';
3
+ import { ArrowPoint } from '../index';
4
+ import { graphProps } from '../../../../__tests__/utils';
5
+ import { bounds } from '../../../../utils';
6
+ import { gridDraggable, utils } from '@pie-lib/plot';
7
+
8
+ const { xy } = utils;
9
+ jest.mock('../../../../utils', () => {
10
+ const { point } = jest.requireActual('../../../../utils');
11
+ return {
12
+ bounds: jest.fn(),
13
+ point,
14
+ };
15
+ });
16
+
17
+ jest.mock('@pie-lib/plot/index', () => {
18
+ const { types, utils } = jest.requireActual('@pie-lib/plot/index');
19
+ return {
20
+ gridDraggable: jest.fn((opts) => (Comp) => Comp),
21
+ types,
22
+ utils,
23
+ };
24
+ });
25
+
26
+ describe('ArrowPoint', () => {
27
+ let w;
28
+ let onChange = jest.fn();
29
+ const wrapper = (extras) => {
30
+ const defaults = {
31
+ classes: {},
32
+ className: 'className',
33
+ onChange,
34
+ graphProps: graphProps(),
35
+ from: xy(0, 0),
36
+ to: xy(1, 1),
37
+ };
38
+ const props = { ...defaults, ...extras };
39
+ return shallow(<ArrowPoint {...props} />);
40
+ };
41
+
42
+ describe('snapshot', () => {
43
+ it('renders', () => {
44
+ w = wrapper();
45
+ expect(w).toMatchSnapshot();
46
+ });
47
+ });
48
+ describe('gridDraggable options', () => {
49
+ let opts;
50
+ let domain;
51
+ let range;
52
+ beforeEach(() => {
53
+ domain = {
54
+ min: 0,
55
+ max: 1,
56
+ step: 1,
57
+ };
58
+ range = {
59
+ min: 0,
60
+ max: 1,
61
+ step: 1,
62
+ };
63
+ const w = wrapper();
64
+ opts = gridDraggable.mock.calls[0][0];
65
+ });
66
+
67
+ describe('bounds', () => {
68
+ it('calls utils.bounds with area', () => {
69
+ const result = opts.bounds({ x: 0, y: 0 }, { domain, range });
70
+ expect(bounds).toHaveBeenCalledWith({ left: 0, top: 0, bottom: 0, right: 0 }, domain, range);
71
+ });
72
+ });
73
+ describe('anchorPoint', () => {
74
+ it('returns x/y', () => {
75
+ const result = opts.anchorPoint({ x: 0, y: 0 });
76
+ expect(result).toEqual({ x: 0, y: 0 });
77
+ });
78
+ });
79
+
80
+ describe('fromDelta', () => {
81
+ it('returns a new point from the x/y + delta', () => {
82
+ const result = opts.fromDelta({ x: -1, y: 0 }, { x: 1, y: 3 });
83
+ expect(result).toEqual({ x: 0, y: 3 });
84
+ });
85
+ });
86
+ });
87
+ });
@@ -0,0 +1,84 @@
1
+ import { shallow } from 'enzyme/build';
2
+ import React from 'react';
3
+ import { BasePoint } from '../index';
4
+ import { gridDraggable } from '@pie-lib/plot';
5
+ import { graphProps } from '../../../../__tests__/utils';
6
+ import { bounds } from '../../../../utils';
7
+
8
+ jest.mock('../../../../utils', () => {
9
+ const { point } = jest.requireActual('../../../../utils');
10
+ return {
11
+ bounds: jest.fn(),
12
+ point,
13
+ };
14
+ });
15
+
16
+ jest.mock('@pie-lib/plot/index', () => {
17
+ const { types, utils } = jest.requireActual('@pie-lib/plot/index');
18
+ return {
19
+ gridDraggable: jest.fn((opts) => (Comp) => Comp),
20
+ types,
21
+ utils,
22
+ };
23
+ });
24
+
25
+ describe('BasePoint', () => {
26
+ let w;
27
+ let onChange = jest.fn();
28
+ const wrapper = (extras) => {
29
+ const defaults = {
30
+ classes: {},
31
+ className: 'className',
32
+ onChange,
33
+ graphProps: graphProps(),
34
+ };
35
+ const props = { ...defaults, ...extras };
36
+ return shallow(<BasePoint {...props} />);
37
+ };
38
+
39
+ describe('snapshot', () => {
40
+ it('renders', () => {
41
+ w = wrapper();
42
+ expect(w).toMatchSnapshot();
43
+ });
44
+ });
45
+ describe('gridDraggable options', () => {
46
+ let opts;
47
+ let domain;
48
+ let range;
49
+ beforeEach(() => {
50
+ domain = {
51
+ min: 0,
52
+ max: 1,
53
+ step: 1,
54
+ };
55
+ range = {
56
+ min: 0,
57
+ max: 1,
58
+ step: 1,
59
+ };
60
+ const w = wrapper();
61
+ opts = gridDraggable.mock.calls[0][0];
62
+ });
63
+
64
+ describe('bounds', () => {
65
+ it('calls utils.bounds with area', () => {
66
+ const result = opts.bounds({ x: 0, y: 0 }, { domain, range });
67
+ expect(bounds).toHaveBeenCalledWith({ left: 0, top: 0, bottom: 0, right: 0 }, domain, range);
68
+ });
69
+ });
70
+ describe('anchorPoint', () => {
71
+ it('returns x/y', () => {
72
+ const result = opts.anchorPoint({ x: 0, y: 0 });
73
+ expect(result).toEqual({ x: 0, y: 0 });
74
+ });
75
+ });
76
+
77
+ describe('fromDelta', () => {
78
+ it('returns a new point from the x/y + delta', () => {
79
+ const result = opts.fromDelta({ x: -1, y: 0 }, { x: 1, y: 3 });
80
+ expect(result).toEqual({ x: 0, y: 3 });
81
+ });
82
+ });
83
+ });
84
+ });
@@ -47,7 +47,10 @@ export class RawArrow extends React.Component {
47
47
  }
48
48
 
49
49
  return (
50
- <g className={classNames(classes.point, disabled && classes.disabled, classes[correctness], className)} {...rest}>
50
+ <g
51
+ className={classNames(classes.point, disabled && classes.disabledSecondary, classes[correctness], className)}
52
+ {...rest}
53
+ >
51
54
  <polygon
52
55
  points={points}
53
56
  transform={`
@@ -32,7 +32,10 @@ export default class Arrow extends React.Component {
32
32
  ${scaledX - size}, ${scaledY + size / 2}`;
33
33
 
34
34
  return (
35
- <g className={classNames(classes.point, disabled && classes.disabled, classes[correctness], className)} {...rest}>
35
+ <g
36
+ className={classNames(classes.point, disabled && classes.disabledSecondary, classes[correctness], className)}
37
+ {...rest}
38
+ >
36
39
  <ArrowHead size={size} transform={transform} points={points} />
37
40
  </g>
38
41
  );
@@ -5,6 +5,9 @@ import { types } from '@pie-lib/plot';
5
5
  import CoordinatesLabel from '../../../coordinates-label';
6
6
  import ReactDOM from 'react-dom';
7
7
  import { thinnerShapesNeeded } from '../../../utils';
8
+ import MissingSVG from '../icons/MissingSVG';
9
+ import CorrectSVG from '../icons/CorrectSVG';
10
+ import IncorrectSVG from '../icons/IncorrectSVG';
8
11
 
9
12
  export class RawBp extends React.Component {
10
13
  static propTypes = {
@@ -38,11 +41,31 @@ export class RawBp extends React.Component {
38
41
  // we need to remove style from props
39
42
  // eslint-disable-next-line no-unused-vars,react/prop-types
40
43
  style,
44
+ onClick,
45
+ // Refactored RawBp component by isolating onTouchStart and onTouchEnd handlers to the outer circle, resolving erratic touch event behavior.
46
+ // Remaining props are now applied only to the inner circle for improved event handling consistency.
47
+ onTouchStart,
48
+ onTouchEnd,
41
49
  ...rest
42
50
  } = this.props;
43
51
  const { showCoordinates } = this.state;
44
52
  const { scale } = graphProps;
45
53
  const r = thinnerShapesNeeded(graphProps) ? 5 : 7;
54
+ let SvgComponent;
55
+ switch (correctness) {
56
+ case 'missing':
57
+ SvgComponent = MissingSVG;
58
+ break;
59
+ case 'correct':
60
+ SvgComponent = CorrectSVG;
61
+ break;
62
+ case 'incorrect':
63
+ SvgComponent = IncorrectSVG;
64
+ break;
65
+ default:
66
+ SvgComponent = null;
67
+ break;
68
+ }
46
69
 
47
70
  return (
48
71
  <>
@@ -53,15 +76,17 @@ export class RawBp extends React.Component {
53
76
  cy={scale.y(y)}
54
77
  onMouseEnter={() => this.setState({ showCoordinates: true })}
55
78
  onMouseLeave={() => this.setState({ showCoordinates: false })}
56
- {...rest}
79
+ onTouchStart={onTouchStart}
80
+ onTouchEnd={onTouchEnd}
81
+ onClick={onClick}
57
82
  />
58
83
  <g
59
- className={classNames(classes.point, disabled && classes.disabled, classes[correctness], className)}
84
+ className={classNames(classes.point, disabled && classes.disabledSecondary, classes[correctness], className)}
60
85
  onMouseEnter={() => this.setState({ showCoordinates: true })}
61
86
  onMouseLeave={() => this.setState({ showCoordinates: false })}
62
- {...rest}
63
87
  >
64
88
  <circle {...rest} r={r} cx={scale.x(x)} cy={scale.y(y)} />
89
+ {SvgComponent && <SvgComponent scale={scale} x={x} y={y} />}
65
90
  {labelNode &&
66
91
  coordinatesOnHover &&
67
92
  showCoordinates &&
@@ -1,7 +1,7 @@
1
1
  import { withStyles } from '@material-ui/core/styles/index';
2
2
  import { gridDraggable } from '@pie-lib/plot';
3
3
  import * as utils from '../../../utils';
4
- import { disabled, correct, incorrect, missing } from '../styles';
4
+ import { disabled, correct, incorrect, missing, disabledSecondary } from '../styles';
5
5
  import { RawBp } from './base-point';
6
6
  import { RawArrow } from './arrow-point';
7
7
  import { color } from '@pie-lib/render-ui';
@@ -29,7 +29,7 @@ const styles = () => {
29
29
  point: {
30
30
  '& circle, & polygon': {
31
31
  cursor: 'pointer',
32
- fill: color.secondary(),
32
+ fill: color.defaults.BLACK,
33
33
  },
34
34
  },
35
35
  disabled: {
@@ -37,6 +37,11 @@ const styles = () => {
37
37
  ...disabled(),
38
38
  },
39
39
  },
40
+ disabledSecondary: {
41
+ '& circle, & polygon': {
42
+ ...disabledSecondary(),
43
+ },
44
+ },
40
45
  correct: {
41
46
  '& circle, & polygon': {
42
47
  ...correct(),
@@ -5,16 +5,21 @@ export const disabled = (key = 'fill') => ({
5
5
  pointerEvents: 'none',
6
6
  });
7
7
 
8
+ export const disabledSecondary = (key = 'fill') => ({
9
+ [key]: color.disabledSecondary(),
10
+ pointerEvents: 'none',
11
+ });
12
+
8
13
  export const correct = (key = 'fill') => ({
9
- [key]: color.correct(),
14
+ [key]: color.correctWithIcon(),
10
15
  pointerEvents: 'none',
11
16
  });
12
17
  export const incorrect = (key = 'fill') => ({
13
- [key]: color.incorrect(),
18
+ [key]: color.incorrectWithIcon(),
14
19
  pointerEvents: 'none',
15
20
  });
16
21
 
17
22
  export const missing = (key = 'fill') => ({
18
- [key]: color.missing(),
23
+ [key]: color.missingWithIcon(),
19
24
  pointerEvents: 'none',
20
25
  });
@@ -0,0 +1,51 @@
1
+ import { withRootEdge } from '../../shared/line/with-root-edge';
2
+ import { buildDataPoints, sinY } from '@pie-lib/graphing-utils';
3
+ import { utils } from '@pie-lib/plot';
4
+
5
+ import { graphProps as getGraphProps } from '../../../__tests__/utils';
6
+
7
+ const { xy } = utils;
8
+ jest.mock('@pie-lib/graphing-utils/index', () => ({
9
+ sinY: jest.fn().mockReturnValue(0),
10
+ buildDataPoints: jest.fn().mockReturnValue([]),
11
+ parabolaFromTwoPoints: jest.fn(() => jest.fn()),
12
+ getAmplitudeAndFreq: jest.fn().mockReturnValue({ freq: 4, amplitude: 1 }),
13
+ FREQ_DIVIDER: 16,
14
+ }));
15
+
16
+ jest.mock('../../shared/line/with-root-edge', () => ({
17
+ withRootEdge: jest.fn(),
18
+ rootEdgeComponent: jest.fn(),
19
+ }));
20
+ describe('Parabola', () => {
21
+ let fnBody;
22
+ let graphProps;
23
+ let root;
24
+ let edge;
25
+ let result;
26
+ beforeEach(() => {
27
+ require('../component');
28
+ fnBody = withRootEdge.mock.calls[0][0];
29
+ graphProps = getGraphProps();
30
+ root = xy(0, 0);
31
+ edge = xy(1, 1);
32
+
33
+ result = fnBody({ graphProps, root, edge });
34
+ });
35
+ it('fnBody is not null', () => {
36
+ expect(fnBody).toBeDefined();
37
+ });
38
+
39
+ it('calls buildDataPoints', () => {
40
+ const { domain, range } = graphProps;
41
+ expect(buildDataPoints).toHaveBeenCalledWith({ ...domain, step: 0.25 }, range, root, edge, expect.anything());
42
+ });
43
+
44
+ it('calls sinY', () => {
45
+ expect(sinY).toHaveBeenCalledWith(1, 4, expect.anything());
46
+ });
47
+
48
+ it('returns dataPoints', () => {
49
+ expect(result).toEqual({ root, edge, dataPoints: [] });
50
+ });
51
+ });
@@ -4,29 +4,29 @@ import { withRootEdge, rootEdgeComponent } from '../shared/line/with-root-edge';
4
4
 
5
5
  const log = debug('pie-lib:graphing:sine');
6
6
 
7
- log('sine...');
8
-
9
7
  const Sine = withRootEdge((props) => {
10
- const { domain } = props.graphProps;
8
+ const { root, edge, graphProps } = props;
9
+ const { domain, range } = graphProps;
11
10
 
12
- const { root, edge } = props;
13
11
  const { amplitude, freq } = getAmplitudeAndFreq(root, edge);
14
12
  const interval = freq / FREQ_DIVIDER;
13
+
15
14
  log('[getPoints] amplitude:', amplitude, 'freq:', freq);
16
15
 
17
16
  const dataPoints =
18
17
  edge && edge.x === root.x
19
18
  ? []
20
19
  : buildDataPoints(
21
- domain.min,
22
- domain.max,
20
+ { ...domain, step: interval },
21
+ range,
23
22
  root,
24
23
  edge,
25
- interval,
26
24
  sinY(amplitude, freq, { phase: root.x, vertical: root.y }),
27
25
  );
26
+
28
27
  return { root: props.root, edge: props.edge, dataPoints };
29
28
  });
30
29
 
31
30
  const Component = rootEdgeComponent(Sine);
31
+
32
32
  export default Component;
@@ -0,0 +1,12 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`Line snapshot renders 1`] = `
4
+ <line
5
+ className="className"
6
+ strokeDasharray={-5.585786437626905}
7
+ x1={0}
8
+ x2={1}
9
+ y1={0}
10
+ y2={1}
11
+ />
12
+ `;
@@ -0,0 +1,26 @@
1
+ import { shallow } from 'enzyme';
2
+ import React from 'react';
3
+ import { Line } from '../component';
4
+ import { graphProps as getGraphProps } from '../../../__tests__/utils';
5
+ import { utils } from '@pie-lib/plot';
6
+
7
+ describe('Line', () => {
8
+ let w;
9
+ const wrapper = (extras) => {
10
+ const defaults = {
11
+ classes: {},
12
+ className: 'className',
13
+ graphProps: getGraphProps(),
14
+ from: utils.xy(0, 0),
15
+ to: utils.xy(1, 1),
16
+ };
17
+ const props = { ...defaults, ...extras };
18
+ return shallow(<Line {...props} />);
19
+ };
20
+ describe('snapshot', () => {
21
+ it('renders', () => {
22
+ const w = wrapper();
23
+ expect(w).toMatchSnapshot();
24
+ });
25
+ });
26
+ });
@@ -10,6 +10,7 @@ import { getDistanceBetweenTwoPoints } from '../../utils';
10
10
  const lineStyles = (theme) => ({
11
11
  line: styles.line(theme),
12
12
  disabled: styles.disabled(theme),
13
+ disabledSecondary: styles.disabledSecondary(theme),
13
14
  correct: styles.correct(theme, 'stroke'),
14
15
  incorrect: styles.incorrect(theme, 'stroke'),
15
16
  missing: styles.missing(theme, 'stroke'),
@@ -32,7 +33,7 @@ export const Line = (props) => {
32
33
 
33
34
  return (
34
35
  <line
35
- className={classNames(classes.line, disabled && classes.disabled, classes[correctness], className)}
36
+ className={classNames(classes.line, disabled && classes.disabledSecondary, classes[correctness], className)}
36
37
  x1={startPoint.x}
37
38
  y1={startPoint.y}
38
39
  x2={endPoint.x}
package/src/undo-redo.jsx CHANGED
@@ -40,7 +40,6 @@ export class UndoRedo extends React.Component {
40
40
  const styles = (theme) => ({
41
41
  button: {
42
42
  color: color.text(),
43
- backgroundColor: color.background(),
44
43
  marginBottom: theme.spacing.unit / 2,
45
44
  '&:not(:last-of-type)': {
46
45
  marginRight: theme.spacing.unit / 2,
package/src/utils.js CHANGED
@@ -203,7 +203,7 @@ export const isDuplicatedMark = (mark, marks, oldMark) => {
203
203
  }
204
204
 
205
205
  const duplicated = filteredMarks.find((m) => {
206
- if (type === 'circle' || type === 'parabola' || type === 'sine') {
206
+ if (type === 'circle' || type === 'parabola' || type === 'sine' || type === 'absolute' || type === 'exponential') {
207
207
  const { root, edge } = mark;
208
208
 
209
209
  return (equalPoints(root, m.root) && equalPoints(edge, m.edge)) || (type === 'circle' && isSameCircle(m, mark));
package/legacy.png DELETED
Binary file
package/lib/axis/arrow.js DELETED
@@ -1,115 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports["default"] = exports.Arrow = void 0;
9
-
10
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
11
-
12
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
13
-
14
- var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
15
-
16
- var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
17
-
18
- var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
19
-
20
- var _react = _interopRequireDefault(require("react"));
21
-
22
- var _propTypes = _interopRequireDefault(require("prop-types"));
23
-
24
- var _classnames = _interopRequireDefault(require("classnames"));
25
-
26
- var _styles = require("@material-ui/core/styles");
27
-
28
- var _plot = require("@pie-lib/plot");
29
-
30
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }
31
-
32
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
33
-
34
- var style = function style(theme) {
35
- return {
36
- root: {
37
- fill: "var(--arrow-color, ".concat(theme.palette.common.black, ")")
38
- }
39
- };
40
- };
41
-
42
- var Arrow = /*#__PURE__*/function (_React$Component) {
43
- (0, _inherits2["default"])(Arrow, _React$Component);
44
-
45
- var _super = _createSuper(Arrow);
46
-
47
- function Arrow() {
48
- (0, _classCallCheck2["default"])(this, Arrow);
49
- return _super.apply(this, arguments);
50
- }
51
-
52
- (0, _createClass2["default"])(Arrow, [{
53
- key: "render",
54
- value: function render() {
55
- var _this$props = this.props,
56
- x = _this$props.x,
57
- y = _this$props.y,
58
- classes = _this$props.classes,
59
- className = _this$props.className,
60
- scale = _this$props.scale;
61
- var names = (0, _classnames["default"])(classes.root, className);
62
- var direction = this.props.direction || 'left';
63
- var xv = scale.x(x);
64
- var yv = scale.y(y);
65
- var transform = '';
66
-
67
- var getTransform = function getTransform(x, y, rotate) {
68
- return "translate(".concat(x, ", ").concat(y, ") rotate(").concat(rotate, ")");
69
- };
70
-
71
- if (direction === 'left') {
72
- transform = getTransform(xv - 15, yv, 0);
73
- }
74
-
75
- if (direction === 'right') {
76
- transform = getTransform(xv + 15, yv, 180);
77
- }
78
-
79
- if (direction === 'up') {
80
- transform = getTransform(xv, yv - 15, 90);
81
- }
82
-
83
- if (direction === 'down') {
84
- transform = getTransform(xv, yv + 15, 270);
85
- }
86
-
87
- return /*#__PURE__*/_react["default"].createElement("path", {
88
- d: "m 0,0 8,-5 0,10 -8,-5",
89
- transform: transform,
90
- className: names
91
- });
92
- }
93
- }]);
94
- return Arrow;
95
- }(_react["default"].Component);
96
-
97
- exports.Arrow = Arrow;
98
- Arrow.propTypes = {
99
- y: _propTypes["default"].number,
100
- x: _propTypes["default"].number,
101
- direction: _propTypes["default"].oneOf(['left', 'right', 'up', 'down']),
102
- classes: _propTypes["default"].object.isRequired,
103
- className: _propTypes["default"].string,
104
- scale: _plot.types.ScaleType.isRequired
105
- };
106
- Arrow.defaultProps = {
107
- y: 0,
108
- x: 0,
109
- direction: 'left'
110
- };
111
-
112
- var _default = (0, _styles.withStyles)(style)(Arrow);
113
-
114
- exports["default"] = _default;
115
- //# sourceMappingURL=arrow.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/axis/arrow.jsx"],"names":["style","theme","root","fill","palette","common","black","Arrow","props","x","y","classes","className","scale","names","direction","xv","yv","transform","getTransform","rotate","React","Component","propTypes","PropTypes","number","oneOf","object","isRequired","string","types","ScaleType","defaultProps"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AAEA;;AACA;;AACA;;;;;;AAEA,IAAMA,KAAK,GAAG,SAARA,KAAQ,CAACC,KAAD;AAAA,SAAY;AACxBC,IAAAA,IAAI,EAAE;AACJC,MAAAA,IAAI,+BAAwBF,KAAK,CAACG,OAAN,CAAcC,MAAd,CAAqBC,KAA7C;AADA;AADkB,GAAZ;AAAA,CAAd;;IAMaC,K;;;;;;;;;;;;WACX,kBAAS;AACP,wBAA4C,KAAKC,KAAjD;AAAA,UAAQC,CAAR,eAAQA,CAAR;AAAA,UAAWC,CAAX,eAAWA,CAAX;AAAA,UAAcC,OAAd,eAAcA,OAAd;AAAA,UAAuBC,SAAvB,eAAuBA,SAAvB;AAAA,UAAkCC,KAAlC,eAAkCA,KAAlC;AACA,UAAMC,KAAK,GAAG,4BAAWH,OAAO,CAACT,IAAnB,EAAyBU,SAAzB,CAAd;AACA,UAAIG,SAAS,GAAG,KAAKP,KAAL,CAAWO,SAAX,IAAwB,MAAxC;AAEA,UAAMC,EAAE,GAAGH,KAAK,CAACJ,CAAN,CAAQA,CAAR,CAAX;AACA,UAAMQ,EAAE,GAAGJ,KAAK,CAACH,CAAN,CAAQA,CAAR,CAAX;AAEA,UAAIQ,SAAS,GAAG,EAAhB;;AAEA,UAAMC,YAAY,GAAG,SAAfA,YAAe,CAACV,CAAD,EAAIC,CAAJ,EAAOU,MAAP;AAAA,mCAA+BX,CAA/B,eAAqCC,CAArC,sBAAkDU,MAAlD;AAAA,OAArB;;AAEA,UAAIL,SAAS,KAAK,MAAlB,EAA0B;AACxBG,QAAAA,SAAS,GAAGC,YAAY,CAACH,EAAE,GAAG,EAAN,EAAUC,EAAV,EAAc,CAAd,CAAxB;AACD;;AAED,UAAIF,SAAS,KAAK,OAAlB,EAA2B;AACzBG,QAAAA,SAAS,GAAGC,YAAY,CAACH,EAAE,GAAG,EAAN,EAAUC,EAAV,EAAc,GAAd,CAAxB;AACD;;AAED,UAAIF,SAAS,KAAK,IAAlB,EAAwB;AACtBG,QAAAA,SAAS,GAAGC,YAAY,CAACH,EAAD,EAAKC,EAAE,GAAG,EAAV,EAAc,EAAd,CAAxB;AACD;;AAED,UAAIF,SAAS,KAAK,MAAlB,EAA0B;AACxBG,QAAAA,SAAS,GAAGC,YAAY,CAACH,EAAD,EAAKC,EAAE,GAAG,EAAV,EAAc,GAAd,CAAxB;AACD;;AAED,0BAAO;AAAM,QAAA,CAAC,EAAC,uBAAR;AAAgC,QAAA,SAAS,EAAEC,SAA3C;AAAsD,QAAA,SAAS,EAAEJ;AAAjE,QAAP;AACD;;;EA9BwBO,kBAAMC,S;;;AAiCjCf,KAAK,CAACgB,SAAN,GAAkB;AAChBb,EAAAA,CAAC,EAAEc,sBAAUC,MADG;AAEhBhB,EAAAA,CAAC,EAAEe,sBAAUC,MAFG;AAGhBV,EAAAA,SAAS,EAAES,sBAAUE,KAAV,CAAgB,CAAC,MAAD,EAAS,OAAT,EAAkB,IAAlB,EAAwB,MAAxB,CAAhB,CAHK;AAIhBf,EAAAA,OAAO,EAAEa,sBAAUG,MAAV,CAAiBC,UAJV;AAKhBhB,EAAAA,SAAS,EAAEY,sBAAUK,MALL;AAMhBhB,EAAAA,KAAK,EAAEiB,YAAMC,SAAN,CAAgBH;AANP,CAAlB;AASArB,KAAK,CAACyB,YAAN,GAAqB;AACnBtB,EAAAA,CAAC,EAAE,CADgB;AAEnBD,EAAAA,CAAC,EAAE,CAFgB;AAGnBM,EAAAA,SAAS,EAAE;AAHQ,CAArB;;eAMe,wBAAWf,KAAX,EAAkBO,KAAlB,C","sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\n\nimport classNames from 'classnames';\nimport { withStyles } from '@material-ui/core/styles';\nimport { types } from '@pie-lib/plot';\n\nconst style = (theme) => ({\n root: {\n fill: `var(--arrow-color, ${theme.palette.common.black})`,\n },\n});\n\nexport class Arrow extends React.Component {\n render() {\n const { x, y, classes, className, scale } = this.props;\n const names = classNames(classes.root, className);\n let direction = this.props.direction || 'left';\n\n const xv = scale.x(x);\n const yv = scale.y(y);\n\n let transform = '';\n\n const getTransform = (x, y, rotate) => `translate(${x}, ${y}) rotate(${rotate})`;\n\n if (direction === 'left') {\n transform = getTransform(xv - 15, yv, 0);\n }\n\n if (direction === 'right') {\n transform = getTransform(xv + 15, yv, 180);\n }\n\n if (direction === 'up') {\n transform = getTransform(xv, yv - 15, 90);\n }\n\n if (direction === 'down') {\n transform = getTransform(xv, yv + 15, 270);\n }\n\n return <path d=\"m 0,0 8,-5 0,10 -8,-5\" transform={transform} className={names} />;\n }\n}\n\nArrow.propTypes = {\n y: PropTypes.number,\n x: PropTypes.number,\n direction: PropTypes.oneOf(['left', 'right', 'up', 'down']),\n classes: PropTypes.object.isRequired,\n className: PropTypes.string,\n scale: types.ScaleType.isRequired,\n};\n\nArrow.defaultProps = {\n y: 0,\n x: 0,\n direction: 'left',\n};\n\nexport default withStyles(style)(Arrow);\n"],"file":"arrow.js"}