@pie-lib/graphing 2.34.3-next.2 → 2.34.4-next.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 (252) hide show
  1. package/CHANGELOG.md +6 -76
  2. package/lib/__tests__/graph-with-controls.test.js +226 -0
  3. package/lib/__tests__/graph.test.js +187 -0
  4. package/lib/__tests__/grid.test.js +29 -0
  5. package/lib/__tests__/labels.test.js +61 -0
  6. package/lib/__tests__/mark-label.test.js +133 -0
  7. package/lib/__tests__/toggle-bar.test.js +150 -0
  8. package/lib/__tests__/tool-menu.test.js +101 -0
  9. package/lib/__tests__/undo-redo.test.js +31 -0
  10. package/lib/__tests__/use-debounce.test.js +24 -0
  11. package/lib/__tests__/utils.js +70 -0
  12. package/lib/__tests__/utils.test.js +123 -0
  13. package/lib/axis/__tests__/arrow.test.js +60 -0
  14. package/lib/axis/__tests__/axes.test.js +195 -0
  15. package/lib/axis/arrow.js +20 -56
  16. package/lib/axis/arrow.js.map +1 -1
  17. package/lib/axis/axes.js +107 -195
  18. package/lib/axis/axes.js.map +1 -1
  19. package/lib/axis/index.js +2 -7
  20. package/lib/axis/index.js.map +1 -1
  21. package/lib/bg.js +22 -50
  22. package/lib/bg.js.map +1 -1
  23. package/lib/container/actions.js +3 -9
  24. package/lib/container/actions.js.map +1 -1
  25. package/lib/container/index.js +15 -60
  26. package/lib/container/index.js.map +1 -1
  27. package/lib/container/marks.js +2 -7
  28. package/lib/container/marks.js.map +1 -1
  29. package/lib/container/middleware.js +3 -9
  30. package/lib/container/middleware.js.map +1 -1
  31. package/lib/container/reducer.js +2 -9
  32. package/lib/container/reducer.js.map +1 -1
  33. package/lib/coordinates-label.js +25 -55
  34. package/lib/coordinates-label.js.map +1 -1
  35. package/lib/graph-with-controls.js +121 -185
  36. package/lib/graph-with-controls.js.map +1 -1
  37. package/lib/graph.js +60 -117
  38. package/lib/graph.js.map +1 -1
  39. package/lib/grid-setup.js +169 -225
  40. package/lib/grid-setup.js.map +1 -1
  41. package/lib/grid.js +30 -75
  42. package/lib/grid.js.map +1 -1
  43. package/lib/index.js +2 -14
  44. package/lib/index.js.map +1 -1
  45. package/lib/key-legend.js +41 -86
  46. package/lib/key-legend.js.map +1 -1
  47. package/lib/label-svg-icon.js +2 -8
  48. package/lib/label-svg-icon.js.map +1 -1
  49. package/lib/labels.js +66 -122
  50. package/lib/labels.js.map +1 -1
  51. package/lib/mark-label.js +121 -164
  52. package/lib/mark-label.js.map +1 -1
  53. package/lib/toggle-bar.js +156 -244
  54. package/lib/toggle-bar.js.map +1 -1
  55. package/lib/tool-menu.js +17 -51
  56. package/lib/tool-menu.js.map +1 -1
  57. package/lib/tools/absolute/__tests__/component.test.js +67 -0
  58. package/lib/tools/absolute/component.js +5 -11
  59. package/lib/tools/absolute/component.js.map +1 -1
  60. package/lib/tools/absolute/index.js +4 -17
  61. package/lib/tools/absolute/index.js.map +1 -1
  62. package/lib/tools/circle/__tests__/bg-circle.test.js +33 -0
  63. package/lib/tools/circle/__tests__/component.test.js +68 -0
  64. package/lib/tools/circle/bg-circle.js +43 -93
  65. package/lib/tools/circle/bg-circle.js.map +1 -1
  66. package/lib/tools/circle/component.js +79 -166
  67. package/lib/tools/circle/component.js.map +1 -1
  68. package/lib/tools/circle/index.js +4 -14
  69. package/lib/tools/circle/index.js.map +1 -1
  70. package/lib/tools/exponential/__tests__/component.test.js +66 -0
  71. package/lib/tools/exponential/component.js +5 -11
  72. package/lib/tools/exponential/component.js.map +1 -1
  73. package/lib/tools/exponential/index.js +4 -19
  74. package/lib/tools/exponential/index.js.map +1 -1
  75. package/lib/tools/index.js +4 -17
  76. package/lib/tools/index.js.map +1 -1
  77. package/lib/tools/line/__tests__/component.test.js +45 -0
  78. package/lib/tools/line/component.js +28 -49
  79. package/lib/tools/line/component.js.map +1 -1
  80. package/lib/tools/line/index.js +2 -7
  81. package/lib/tools/line/index.js.map +1 -1
  82. package/lib/tools/parabola/__tests__/component.test.js +66 -0
  83. package/lib/tools/parabola/component.js +5 -11
  84. package/lib/tools/parabola/component.js.map +1 -1
  85. package/lib/tools/parabola/index.js +4 -17
  86. package/lib/tools/parabola/index.js.map +1 -1
  87. package/lib/tools/point/__tests__/component.test.js +50 -0
  88. package/lib/tools/point/component.js +25 -72
  89. package/lib/tools/point/component.js.map +1 -1
  90. package/lib/tools/point/index.js +4 -12
  91. package/lib/tools/point/index.js.map +1 -1
  92. package/lib/tools/polygon/__tests__/component.test.js +85 -0
  93. package/lib/tools/polygon/__tests__/index.test.js +92 -0
  94. package/lib/tools/polygon/__tests__/line.test.js +29 -0
  95. package/lib/tools/polygon/__tests__/polygon.test.js +59 -0
  96. package/lib/tools/polygon/component.js +84 -185
  97. package/lib/tools/polygon/component.js.map +1 -1
  98. package/lib/tools/polygon/index.js +7 -24
  99. package/lib/tools/polygon/index.js.map +1 -1
  100. package/lib/tools/polygon/line.js +49 -92
  101. package/lib/tools/polygon/line.js.map +1 -1
  102. package/lib/tools/polygon/polygon.js +66 -99
  103. package/lib/tools/polygon/polygon.js.map +1 -1
  104. package/lib/tools/ray/__tests__/component.test.js +35 -0
  105. package/lib/tools/ray/component.js +42 -61
  106. package/lib/tools/ray/component.js.map +1 -1
  107. package/lib/tools/ray/index.js +2 -7
  108. package/lib/tools/ray/index.js.map +1 -1
  109. package/lib/tools/segment/__tests__/component.test.js +35 -0
  110. package/lib/tools/segment/component.js +26 -44
  111. package/lib/tools/segment/component.js.map +1 -1
  112. package/lib/tools/segment/index.js +2 -7
  113. package/lib/tools/segment/index.js.map +1 -1
  114. package/lib/tools/shared/__tests__/arrow-head.test.js +45 -0
  115. package/lib/tools/shared/arrow-head.js +70 -29
  116. package/lib/tools/shared/arrow-head.js.map +1 -1
  117. package/lib/tools/shared/icons/CorrectSVG.js +13 -9
  118. package/lib/tools/shared/icons/CorrectSVG.js.map +1 -1
  119. package/lib/tools/shared/icons/IncorrectSVG.js +13 -9
  120. package/lib/tools/shared/icons/IncorrectSVG.js.map +1 -1
  121. package/lib/tools/shared/icons/MissingSVG.js +13 -9
  122. package/lib/tools/shared/icons/MissingSVG.js.map +1 -1
  123. package/lib/tools/shared/line/__tests__/index.test.js +124 -0
  124. package/lib/tools/shared/line/__tests__/line-path.test.js +62 -0
  125. package/lib/tools/shared/line/__tests__/with-root-edge.test.js +91 -0
  126. package/lib/tools/shared/line/index.js +141 -194
  127. package/lib/tools/shared/line/index.js.map +1 -1
  128. package/lib/tools/shared/line/line-path.js +71 -102
  129. package/lib/tools/shared/line/line-path.js.map +1 -1
  130. package/lib/tools/shared/line/with-root-edge.js +23 -57
  131. package/lib/tools/shared/line/with-root-edge.js.map +1 -1
  132. package/lib/tools/shared/point/__tests__/arrow-point.test.js +127 -0
  133. package/lib/tools/shared/point/__tests__/base-point.test.js +122 -0
  134. package/lib/tools/shared/point/arrow-point.js +22 -63
  135. package/lib/tools/shared/point/arrow-point.js.map +1 -1
  136. package/lib/tools/shared/point/arrow.js +24 -53
  137. package/lib/tools/shared/point/arrow.js.map +1 -1
  138. package/lib/tools/shared/point/base-point.js +55 -73
  139. package/lib/tools/shared/point/base-point.js.map +1 -1
  140. package/lib/tools/shared/point/index.js +23 -58
  141. package/lib/tools/shared/point/index.js.map +1 -1
  142. package/lib/tools/shared/styles.js +11 -39
  143. package/lib/tools/shared/styles.js.map +1 -1
  144. package/lib/tools/shared/types.js +3 -10
  145. package/lib/tools/shared/types.js.map +1 -1
  146. package/lib/tools/sine/__tests__/component.test.js +72 -0
  147. package/lib/tools/sine/component.js +9 -20
  148. package/lib/tools/sine/component.js.map +1 -1
  149. package/lib/tools/sine/index.js +4 -17
  150. package/lib/tools/sine/index.js.map +1 -1
  151. package/lib/tools/vector/__tests__/component.test.js +32 -0
  152. package/lib/tools/vector/component.js +25 -45
  153. package/lib/tools/vector/component.js.map +1 -1
  154. package/lib/tools/vector/index.js +2 -7
  155. package/lib/tools/vector/index.js.map +1 -1
  156. package/lib/undo-redo.js +30 -70
  157. package/lib/undo-redo.js.map +1 -1
  158. package/lib/use-debounce.js +5 -12
  159. package/lib/use-debounce.js.map +1 -1
  160. package/lib/utils.js +52 -129
  161. package/lib/utils.js.map +1 -1
  162. package/package.json +25 -29
  163. package/src/__tests__/graph-with-controls.test.jsx +28 -11
  164. package/src/__tests__/graph.test.jsx +104 -168
  165. package/src/__tests__/grid.test.jsx +8 -6
  166. package/src/__tests__/labels.test.jsx +25 -8
  167. package/src/__tests__/mark-label.test.jsx +12 -17
  168. package/src/__tests__/toggle-bar.test.jsx +92 -17
  169. package/src/__tests__/tool-menu.test.jsx +61 -12
  170. package/src/__tests__/undo-redo.test.jsx +7 -8
  171. package/src/__tests__/utils.js +3 -0
  172. package/src/axis/__tests__/arrow.test.jsx +16 -17
  173. package/src/axis/__tests__/axes.test.jsx +118 -122
  174. package/src/axis/arrow.jsx +7 -12
  175. package/src/axis/axes.jsx +45 -55
  176. package/src/coordinates-label.jsx +14 -18
  177. package/src/graph-with-controls.jsx +52 -59
  178. package/src/grid-setup.jsx +210 -206
  179. package/src/grid.jsx +2 -4
  180. package/src/key-legend.jsx +52 -56
  181. package/src/labels.jsx +23 -30
  182. package/src/mark-label.jsx +92 -81
  183. package/src/toggle-bar.jsx +135 -164
  184. package/src/tool-menu.jsx +1 -1
  185. package/src/tools/circle/__tests__/bg-circle.test.jsx +7 -9
  186. package/src/tools/circle/__tests__/component.test.jsx +17 -189
  187. package/src/tools/circle/bg-circle.jsx +20 -28
  188. package/src/tools/circle/component.jsx +28 -63
  189. package/src/tools/line/__tests__/component.test.jsx +7 -7
  190. package/src/tools/line/component.jsx +22 -15
  191. package/src/tools/point/__tests__/component.test.jsx +18 -43
  192. package/src/tools/point/component.jsx +1 -1
  193. package/src/tools/polygon/__tests__/component.test.jsx +18 -162
  194. package/src/tools/polygon/__tests__/line.test.jsx +7 -10
  195. package/src/tools/polygon/__tests__/polygon.test.jsx +7 -8
  196. package/src/tools/polygon/component.jsx +3 -4
  197. package/src/tools/polygon/line.jsx +30 -33
  198. package/src/tools/polygon/polygon.jsx +52 -45
  199. package/src/tools/ray/__tests__/component.test.jsx +7 -8
  200. package/src/tools/ray/component.jsx +38 -25
  201. package/src/tools/segment/__tests__/component.test.jsx +7 -8
  202. package/src/tools/segment/component.jsx +19 -18
  203. package/src/tools/shared/__tests__/arrow-head.test.jsx +14 -17
  204. package/src/tools/shared/arrow-head.jsx +60 -7
  205. package/src/tools/shared/icons/CorrectSVG.jsx +10 -0
  206. package/src/tools/shared/icons/IncorrectSVG.jsx +10 -0
  207. package/src/tools/shared/icons/MissingSVG.jsx +10 -0
  208. package/src/tools/shared/line/__tests__/index.test.jsx +19 -165
  209. package/src/tools/shared/line/__tests__/line-path.test.jsx +8 -8
  210. package/src/tools/shared/line/__tests__/with-root-edge.test.jsx +22 -22
  211. package/src/tools/shared/line/index.jsx +52 -7
  212. package/src/tools/shared/line/line-path.jsx +55 -59
  213. package/src/tools/shared/line/with-root-edge.jsx +1 -1
  214. package/src/tools/shared/point/__tests__/arrow-point.test.jsx +15 -11
  215. package/src/tools/shared/point/__tests__/base-point.test.jsx +14 -11
  216. package/src/tools/shared/point/arrow-point.jsx +10 -24
  217. package/src/tools/shared/point/arrow.jsx +5 -11
  218. package/src/tools/shared/point/base-point.jsx +42 -19
  219. package/src/tools/shared/point/index.jsx +27 -44
  220. package/src/tools/vector/__tests__/component.test.jsx +7 -8
  221. package/src/tools/vector/component.jsx +11 -16
  222. package/src/undo-redo.jsx +19 -21
  223. package/esm/index.css +0 -847
  224. package/esm/index.js +0 -239949
  225. package/esm/index.js.map +0 -1
  226. package/esm/package.json +0 -3
  227. package/src/__tests__/__snapshots__/graph-with-controls.test.jsx.snap +0 -237
  228. package/src/__tests__/__snapshots__/graph.test.jsx.snap +0 -211
  229. package/src/__tests__/__snapshots__/grid.test.jsx.snap +0 -54
  230. package/src/__tests__/__snapshots__/labels.test.jsx.snap +0 -30
  231. package/src/__tests__/__snapshots__/mark-label.test.jsx.snap +0 -45
  232. package/src/__tests__/__snapshots__/toggle-bar.test.jsx.snap +0 -7
  233. package/src/__tests__/__snapshots__/tool-menu.test.jsx.snap +0 -13
  234. package/src/__tests__/__snapshots__/undo-redo.test.jsx.snap +0 -14
  235. package/src/axis/__tests__/__snapshots__/arrow.test.jsx.snap +0 -33
  236. package/src/axis/__tests__/__snapshots__/axes.test.jsx.snap +0 -122
  237. package/src/tools/circle/__tests__/__snapshots__/bg-circle.test.jsx.snap +0 -46
  238. package/src/tools/circle/__tests__/__snapshots__/component.test.jsx.snap +0 -293
  239. package/src/tools/line/__tests__/__snapshots__/component.test.jsx.snap +0 -20
  240. package/src/tools/point/__tests__/__snapshots__/component.test.jsx.snap +0 -40
  241. package/src/tools/polygon/__tests__/__snapshots__/component.test.jsx.snap +0 -415
  242. package/src/tools/polygon/__tests__/__snapshots__/line.test.jsx.snap +0 -45
  243. package/src/tools/polygon/__tests__/__snapshots__/polygon.test.jsx.snap +0 -52
  244. package/src/tools/ray/__tests__/__snapshots__/component.test.jsx.snap +0 -23
  245. package/src/tools/segment/__tests__/__snapshots__/component.test.jsx.snap +0 -14
  246. package/src/tools/shared/__tests__/__snapshots__/arrow-head.test.jsx.snap +0 -27
  247. package/src/tools/shared/line/__tests__/__snapshots__/index.test.jsx.snap +0 -360
  248. package/src/tools/shared/line/__tests__/__snapshots__/line-path.test.jsx.snap +0 -58
  249. package/src/tools/shared/line/__tests__/__snapshots__/with-root-edge.test.jsx.snap +0 -63
  250. package/src/tools/shared/point/__tests__/__snapshots__/arrow-point.test.jsx.snap +0 -56
  251. package/src/tools/shared/point/__tests__/__snapshots__/base-point.test.jsx.snap +0 -44
  252. package/src/tools/vector/__tests__/__snapshots__/component.test.jsx.snap +0 -12
@@ -10,6 +10,43 @@ import MarkLabel from '../../../mark-label';
10
10
  import isEmpty from 'lodash/isEmpty';
11
11
  import { color } from '@pie-lib/render-ui';
12
12
  import { getMiddleOfTwoPoints, equalPoints, sameAxes } from '../../../utils';
13
+ import { styled } from '@mui/material/styles';
14
+
15
+ const StyledLineGroup = styled('g')(({ disabled, correctness }) => ({
16
+ '& line': {
17
+ fill: 'transparent',
18
+ stroke: color.defaults.BLACK,
19
+ strokeWidth: 3,
20
+ transition: 'stroke 200ms ease-in, stroke-width 200ms ease-in',
21
+ '&:hover': {
22
+ strokeWidth: 6,
23
+ stroke: color.defaults.PRIMARY_DARK,
24
+ },
25
+ },
26
+ ...(disabled && {
27
+ '& line': {
28
+ ...disabledSecondary('stroke'),
29
+ strokeWidth: 2,
30
+ },
31
+ }),
32
+ ...(correctness === 'correct' && {
33
+ '& line': {
34
+ ...correct('stroke'),
35
+ },
36
+ }),
37
+ ...(correctness === 'incorrect' && {
38
+ '& line': {
39
+ ...incorrect('stroke'),
40
+ },
41
+ }),
42
+ ...(correctness === 'missing' && {
43
+ '& line': {
44
+ ...missing('stroke'),
45
+ strokeWidth: 1,
46
+ strokeDasharray: '4 3',
47
+ },
48
+ }),
49
+ }));
13
50
 
14
51
  export const lineTool = (type, Component) => () => ({
15
52
  type,
@@ -40,6 +77,13 @@ export const lineToolComponent = (Component) => {
40
77
  static propTypes = {
41
78
  ...types.ToolPropTypeFields,
42
79
  graphProps: types.GraphPropsType.isRequired,
80
+ limitLabeling: PropTypes.bool,
81
+ changeMarkProps: PropTypes.func,
82
+ disabled: PropTypes.bool,
83
+ from: types.PointType,
84
+ to: types.PointType,
85
+ labelModeEnabled: PropTypes.bool,
86
+ onClick: PropTypes.func,
43
87
  };
44
88
 
45
89
  constructor(props) {
@@ -181,9 +225,10 @@ export const lineBase = (Comp, opts) => {
181
225
  onClick: PropTypes.func,
182
226
  correctness: PropTypes.string,
183
227
  disabled: PropTypes.bool,
184
- labelNode: PropTypes.object,
185
- labelModeEnabled: PropTypes.bool,
228
+ limitLabeling: PropTypes.bool,
186
229
  changeMarkProps: PropTypes.func,
230
+ labelModeEnabled: PropTypes.bool,
231
+ labelNode: PropTypes.object,
187
232
  };
188
233
 
189
234
  onChangePoint = (point) => {
@@ -309,7 +354,7 @@ export const lineBase = (Comp, opts) => {
309
354
  let lineLabelNode = null;
310
355
 
311
356
  if (labelNode) {
312
- if (from && from.hasOwnProperty('label')) {
357
+ if (from && Object.prototype.hasOwnProperty.call(from, 'label')) {
313
358
  fromLabelNode = ReactDOM.createPortal(
314
359
  <MarkLabel
315
360
  inputRef={(r) => (this.input.from = r)}
@@ -322,7 +367,7 @@ export const lineBase = (Comp, opts) => {
322
367
  );
323
368
  }
324
369
 
325
- if (to && to.hasOwnProperty('label')) {
370
+ if (to && Object.prototype.hasOwnProperty.call(to, 'label')) {
326
371
  toLabelNode = ReactDOM.createPortal(
327
372
  <MarkLabel
328
373
  inputRef={(r) => (this.input.to = r)}
@@ -335,7 +380,7 @@ export const lineBase = (Comp, opts) => {
335
380
  );
336
381
  }
337
382
 
338
- if (middle && middle.hasOwnProperty('label')) {
383
+ if (middle && Object.prototype.hasOwnProperty.call(middle, 'label')) {
339
384
  lineLabelNode = ReactDOM.createPortal(
340
385
  <MarkLabel
341
386
  inputRef={(r) => (this.input.middle = r)}
@@ -350,7 +395,7 @@ export const lineBase = (Comp, opts) => {
350
395
  }
351
396
 
352
397
  return (
353
- <g>
398
+ <StyledLineGroup disabled={disabled} correctness={correctness}>
354
399
  {to && (
355
400
  <DraggableComp
356
401
  from={from}
@@ -387,7 +432,7 @@ export const lineBase = (Comp, opts) => {
387
432
  />
388
433
  )}
389
434
  {toLabelNode}
390
- </g>
435
+ </StyledLineGroup>
391
436
  );
392
437
  }
393
438
  }
@@ -1,16 +1,56 @@
1
1
  import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
- import { withStyles } from '@material-ui/core/styles';
3
+ import { styled } from '@mui/material/styles';
4
4
  import { types } from '@pie-lib/plot';
5
- import classNames from 'classnames';
6
5
  import { disabled, correct, incorrect, missing, disabledSecondary } from '../styles';
7
- import * as vx from '@vx/shape';
6
+ import * as vx from '@visx/shape';
8
7
  import { color } from '@pie-lib/render-ui';
9
8
 
9
+ const dragging = () => ({
10
+ strokeWidth: 4,
11
+ stroke: color.defaults.BLACK,
12
+ });
13
+
14
+ const StyledDrawLine = styled(vx.LinePath)(({ disabled: isDisabled, correctness }) => ({
15
+ fill: 'none',
16
+ strokeWidth: 2,
17
+ stroke: color.black(),
18
+ ...(isDisabled && {
19
+ ...disabledSecondary('stroke'),
20
+ strokeWidth: 2,
21
+ }),
22
+ ...(correctness === 'correct' && correct('stroke')),
23
+ ...(correctness === 'incorrect' && incorrect('stroke')),
24
+ ...(correctness === 'missing' && {
25
+ ...missing('stroke'),
26
+ strokeWidth: 1,
27
+ strokeDasharray: '4 3',
28
+ }),
29
+ }));
30
+
31
+ const StyledLine = styled(vx.LinePath)(({ theme, disabled: isDisabled, correctness, isDragging }) => ({
32
+ strokeWidth: 3,
33
+ fill: 'none',
34
+ transition: 'stroke-width 200ms ease-in, stroke 200ms ease-in',
35
+ stroke: 'transparent',
36
+ '&:hover': dragging(theme),
37
+ ...(isDragging && dragging(theme)),
38
+ ...(isDisabled && {
39
+ ...disabled('stroke'),
40
+ strokeWidth: 2,
41
+ }),
42
+ ...(correctness === 'correct' && correct('stroke')),
43
+ ...(correctness === 'incorrect' && incorrect('stroke')),
44
+ ...(correctness === 'missing' && {
45
+ ...missing('stroke'),
46
+ strokeWidth: 1,
47
+ strokeDasharray: '4 3',
48
+ }),
49
+ }));
50
+
10
51
  export class RawLinePath extends React.Component {
11
52
  static propTypes = {
12
53
  className: PropTypes.string,
13
- classes: PropTypes.object,
14
54
  data: PropTypes.arrayOf(PropTypes.arrayOf(PropTypes.number)),
15
55
  graphProps: types.GraphPropsType.isRequired,
16
56
  disabled: PropTypes.bool,
@@ -27,30 +67,24 @@ export class RawLinePath extends React.Component {
27
67
 
28
68
  render() {
29
69
  /* eslint-disable no-unused-vars */
30
- const { data, classes, className, disabled, correctness, from, to, graphProps, isDragging, ...rest } = this.props;
70
+ const { data, className, disabled, correctness, from, to, graphProps, isDragging, ...rest } = this.props;
31
71
  /* eslint-enable */
32
72
 
33
73
  return (
34
74
  <React.Fragment>
35
- <vx.LinePath
75
+ <StyledDrawLine
36
76
  data={data}
37
- className={classNames(
38
- classes.drawLine,
39
- disabled && classes.disabledSecondary,
40
- classes[correctness],
41
- className,
42
- )}
77
+ className={className}
78
+ disabled={disabled}
79
+ correctness={correctness}
43
80
  {...rest}
44
81
  />
45
- <vx.LinePath
82
+ <StyledLine
46
83
  data={data}
47
- className={classNames(
48
- classes.line,
49
- isDragging && classes.dragging,
50
- disabled && classes.disabledSecondary,
51
- classes[correctness],
52
- className,
53
- )}
84
+ className={className}
85
+ isDragging={isDragging}
86
+ disabled={disabled}
87
+ correctness={correctness}
54
88
  {...rest}
55
89
  />
56
90
  </React.Fragment>
@@ -58,42 +92,4 @@ export class RawLinePath extends React.Component {
58
92
  }
59
93
  }
60
94
 
61
- const dragging = () => ({
62
- strokeWidth: 4,
63
- stroke: color.defaults.BLACK,
64
- });
65
-
66
- export const LinePath = withStyles((theme) => ({
67
- drawLine: {
68
- fill: 'none',
69
- strokeWidth: 2,
70
- stroke: color.black(),
71
- },
72
- line: {
73
- strokeWidth: 3,
74
- fill: 'none',
75
- transition: 'stroke-width 200ms ease-in, stroke 200ms ease-in',
76
- stroke: 'transparent',
77
- '&:hover': dragging(theme),
78
- },
79
- dragging: dragging(theme),
80
- disabled: {
81
- ...disabled('stroke'),
82
- strokeWidth: 2,
83
- },
84
- disabledSecondary: {
85
- ...disabledSecondary('stroke'),
86
- strokeWidth: 2,
87
- },
88
- correct: {
89
- ...correct('stroke'),
90
- },
91
- incorrect: {
92
- ...incorrect('stroke'),
93
- },
94
- missing: {
95
- ...missing('stroke'),
96
- strokeWidth: 1,
97
- strokeDasharray: '4 3',
98
- },
99
- }))(RawLinePath);
95
+ export const LinePath = RawLinePath;
@@ -2,7 +2,7 @@ import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
  import { types } from '@pie-lib/plot';
4
4
  import { LinePath } from './line-path';
5
- import { curveMonotoneX } from '@vx/curve';
5
+ import { curveMonotoneX } from '@visx/curve';
6
6
  import { lineBase, lineToolComponent } from './index';
7
7
 
8
8
  const toRootEdge = (m) => {
@@ -1,4 +1,4 @@
1
- import { shallow } from 'enzyme/build';
1
+ import { render } from '@pie-lib/test-utils';
2
2
  import React from 'react';
3
3
  import { ArrowPoint } from '../index';
4
4
  import { graphProps } from '../../../../__tests__/utils';
@@ -7,10 +7,12 @@ import { gridDraggable, utils } from '@pie-lib/plot';
7
7
 
8
8
  const { xy } = utils;
9
9
  jest.mock('../../../../utils', () => {
10
- const { point } = jest.requireActual('../../../../utils');
10
+ const { point, getAngleDeg, arrowDimensions } = jest.requireActual('../../../../utils');
11
11
  return {
12
12
  bounds: jest.fn(),
13
13
  point,
14
+ getAngleDeg,
15
+ arrowDimensions,
14
16
  };
15
17
  });
16
18
 
@@ -24,9 +26,8 @@ jest.mock('@pie-lib/plot', () => {
24
26
  });
25
27
 
26
28
  describe('ArrowPoint', () => {
27
- let w;
28
29
  let onChange = jest.fn();
29
- const wrapper = (extras) => {
30
+ const renderComponent = (extras) => {
30
31
  const defaults = {
31
32
  classes: {},
32
33
  className: 'className',
@@ -34,17 +35,20 @@ describe('ArrowPoint', () => {
34
35
  graphProps: graphProps(),
35
36
  from: xy(0, 0),
36
37
  to: xy(1, 1),
38
+ x: 0,
39
+ y: 0,
37
40
  };
38
41
  const props = { ...defaults, ...extras };
39
- return shallow(<ArrowPoint {...props} />);
42
+ return render(<ArrowPoint {...props} />);
40
43
  };
41
44
 
42
- describe('snapshot', () => {
43
- it('renders', () => {
44
- w = wrapper();
45
- expect(w).toMatchSnapshot();
45
+ describe('rendering', () => {
46
+ it('renders without crashing', () => {
47
+ const { container } = renderComponent();
48
+ expect(container.firstChild).toBeInTheDocument();
46
49
  });
47
50
  });
51
+
48
52
  describe('gridDraggable options', () => {
49
53
  let opts;
50
54
  let domain;
@@ -60,8 +64,8 @@ describe('ArrowPoint', () => {
60
64
  max: 1,
61
65
  step: 1,
62
66
  };
63
- const w = wrapper();
64
- opts = gridDraggable.mock.calls[0][0];
67
+ renderComponent();
68
+ opts = gridDraggable.mock.calls[gridDraggable.mock.calls.length - 1][0];
65
69
  });
66
70
 
67
71
  describe('bounds', () => {
@@ -1,4 +1,4 @@
1
- import { shallow } from 'enzyme/build';
1
+ import { render } from '@pie-lib/test-utils';
2
2
  import React from 'react';
3
3
  import { BasePoint } from '../index';
4
4
  import { gridDraggable } from '@pie-lib/plot';
@@ -6,10 +6,11 @@ import { graphProps } from '../../../../__tests__/utils';
6
6
  import { bounds } from '../../../../utils';
7
7
 
8
8
  jest.mock('../../../../utils', () => {
9
- const { point } = jest.requireActual('../../../../utils');
9
+ const { point, thinnerShapesNeeded } = jest.requireActual('../../../../utils');
10
10
  return {
11
11
  bounds: jest.fn(),
12
12
  point,
13
+ thinnerShapesNeeded,
13
14
  };
14
15
  });
15
16
 
@@ -23,25 +24,27 @@ jest.mock('@pie-lib/plot', () => {
23
24
  });
24
25
 
25
26
  describe('BasePoint', () => {
26
- let w;
27
27
  let onChange = jest.fn();
28
- const wrapper = (extras) => {
28
+ const renderComponent = (extras) => {
29
29
  const defaults = {
30
30
  classes: {},
31
31
  className: 'className',
32
32
  onChange,
33
33
  graphProps: graphProps(),
34
+ x: 0,
35
+ y: 0,
34
36
  };
35
37
  const props = { ...defaults, ...extras };
36
- return shallow(<BasePoint {...props} />);
38
+ return render(<BasePoint {...props} />);
37
39
  };
38
40
 
39
- describe('snapshot', () => {
40
- it('renders', () => {
41
- w = wrapper();
42
- expect(w).toMatchSnapshot();
41
+ describe('rendering', () => {
42
+ it('renders without crashing', () => {
43
+ const { container } = renderComponent();
44
+ expect(container.firstChild).toBeInTheDocument();
43
45
  });
44
46
  });
47
+
45
48
  describe('gridDraggable options', () => {
46
49
  let opts;
47
50
  let domain;
@@ -57,8 +60,8 @@ describe('BasePoint', () => {
57
60
  max: 1,
58
61
  step: 1,
59
62
  };
60
- const w = wrapper();
61
- opts = gridDraggable.mock.calls[0][0];
63
+ renderComponent();
64
+ opts = gridDraggable.mock.calls[gridDraggable.mock.calls.length - 1][0];
62
65
  });
63
66
 
64
67
  describe('bounds', () => {
@@ -1,18 +1,15 @@
1
1
  import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
- import classNames from 'classnames';
4
3
  import { types } from '@pie-lib/plot';
5
- import isEqual from 'lodash/isEqual';
6
4
  import { getAngleDeg, arrowDimensions } from '../../../utils';
7
5
 
8
6
  export class RawArrow extends React.Component {
9
7
  static propTypes = {
10
- classes: PropTypes.object,
11
8
  className: PropTypes.string,
12
9
  correctness: PropTypes.string,
13
10
  disabled: PropTypes.bool,
14
- x: PropTypes.number,
15
- y: PropTypes.number,
11
+ x: PropTypes.number.isRequired,
12
+ y: PropTypes.number.isRequired,
16
13
  from: PropTypes.shape({
17
14
  x: PropTypes.number,
18
15
  y: PropTypes.number,
@@ -30,32 +27,21 @@ export class RawArrow extends React.Component {
30
27
  };
31
28
 
32
29
  render() {
33
- const { classes, className, x, y, disabled, correctness, graphProps, from, to, ...rest } = this.props;
34
- // x & y are the initial coordinates for the arrow
35
- // from & to are used only to calculate the angle that the arrow should be rotated with
36
-
30
+ const { className, x, y, graphProps, from, to, ...rest } = this.props;
37
31
  const { scale } = graphProps;
38
- const angle = getAngleDeg(from.x, from.y, to.x, to.y);
39
32
 
40
- let points = '';
33
+ const angle = from && to ? getAngleDeg(from.x, from.y, to.x, to.y) : 0;
41
34
 
42
- if (isEqual(from, to)) {
43
- points = '0,0 0,0 0,0';
44
- } else {
45
- points = `0,0 ${arrowDimensions.vector},${arrowDimensions.vector * 2}
46
- -${arrowDimensions.vector},${arrowDimensions.vector * 2}`;
47
- }
35
+ const points =
36
+ from && to && (from.x !== to.x || from.y !== to.y)
37
+ ? `0,0 ${arrowDimensions.vector},${arrowDimensions.vector * 2} -${arrowDimensions.vector},${arrowDimensions.vector * 2}`
38
+ : '0,0 0,0 0,0';
48
39
 
49
40
  return (
50
- <g
51
- className={classNames(classes.point, disabled && classes.disabledSecondary, classes[correctness], className)}
52
- {...rest}
53
- >
41
+ <g className={className} {...rest}>
54
42
  <polygon
55
43
  points={points}
56
- transform={`
57
- translate(${scale.x(x)}, ${scale.y(y)})
58
- rotate(${angle} 0 0)`}
44
+ transform={`translate(${scale.x(x)}, ${scale.y(y)}) rotate(${angle} 0 0)`}
59
45
  />
60
46
  </g>
61
47
  );
@@ -1,13 +1,11 @@
1
1
  import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
- import classNames from 'classnames';
4
3
  import { types } from '@pie-lib/plot';
5
4
  import { ArrowHead } from '../arrow-head';
6
5
  import { thinnerShapesNeeded } from '../../../utils';
7
6
 
8
- export default class Arrow extends React.Component {
7
+ export class BaseArrow extends React.Component {
9
8
  static propTypes = {
10
- classes: PropTypes.object,
11
9
  className: PropTypes.string,
12
10
  correctness: PropTypes.string,
13
11
  disabled: PropTypes.bool,
@@ -18,8 +16,7 @@ export default class Arrow extends React.Component {
18
16
  };
19
17
 
20
18
  render() {
21
- const { classes, angle, className, x, y, disabled, correctness, graphProps, ...rest } = this.props;
22
-
19
+ const { className, angle, x, y, correctness, graphProps, ...rest } = this.props;
23
20
  const size = thinnerShapesNeeded(graphProps) ? 12 : 14;
24
21
  const { scale } = graphProps;
25
22
 
@@ -29,14 +26,11 @@ export default class Arrow extends React.Component {
29
26
  const transform = `rotate(${-angle}, ${scaledX},${scaledY})`;
30
27
  const points = `${scaledX},${scaledY}
31
28
  ${scaledX - size},${scaledY - size / 2}
32
- ${scaledX - size}, ${scaledY + size / 2}`;
29
+ ${scaledX - size},${scaledY + size / 2}`;
33
30
 
34
31
  return (
35
- <g
36
- className={classNames(classes.point, disabled && classes.disabledSecondary, classes[correctness], className)}
37
- {...rest}
38
- >
39
- <ArrowHead size={size} transform={transform} points={points} />
32
+ <g className={className} {...rest}>
33
+ <ArrowHead size={size} transform={transform} points={points} correctness={correctness} />
40
34
  </g>
41
35
  );
42
36
  }
@@ -1,35 +1,58 @@
1
1
  import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
- import classNames from 'classnames';
4
3
  import { types } from '@pie-lib/plot';
5
- import CoordinatesLabel from '../../../coordinates-label';
6
4
  import ReactDOM from 'react-dom';
5
+ import { styled } from '@mui/material/styles';
6
+
7
+ import CoordinatesLabel from '../../../coordinates-label';
7
8
  import { thinnerShapesNeeded } from '../../../utils';
8
9
  import MissingSVG from '../icons/MissingSVG';
9
10
  import CorrectSVG from '../icons/CorrectSVG';
10
11
  import IncorrectSVG from '../icons/IncorrectSVG';
12
+ import * as styles from '../styles';
13
+
14
+ const StyledPointGroup = styled('g')(({ disabled, correctness }) => ({
15
+ cursor: 'pointer',
16
+ '& circle': {
17
+ fill: 'currentColor',
18
+ },
19
+ ...(disabled && {
20
+ ...styles.disabled('fill'),
21
+ ...styles.disabled('color'),
22
+ }),
23
+ ...(correctness === 'correct' && {
24
+ ...styles.correct('fill'),
25
+ ...styles.correct('color'),
26
+ }),
27
+ ...(correctness === 'incorrect' && {
28
+ ...styles.incorrect('fill'),
29
+ ...styles.incorrect('color'),
30
+ }),
31
+ ...(correctness === 'missing' && {
32
+ ...styles.missing('fill'),
33
+ ...styles.missing('color'),
34
+ }),
35
+ }));
11
36
 
12
37
  export class RawBp extends React.Component {
13
38
  static propTypes = {
14
- classes: PropTypes.object,
15
39
  className: PropTypes.string,
16
40
  coordinatesOnHover: PropTypes.bool,
17
41
  correctness: PropTypes.string,
18
42
  disabled: PropTypes.bool,
19
43
  labelNode: PropTypes.object,
20
- x: PropTypes.number,
21
- y: PropTypes.number,
44
+ x: PropTypes.number.isRequired,
45
+ y: PropTypes.number.isRequired,
22
46
  graphProps: types.GraphPropsType.isRequired,
47
+ onClick: PropTypes.func,
48
+ onTouchStart: PropTypes.func,
49
+ onTouchEnd: PropTypes.func,
23
50
  };
24
51
 
25
- constructor(props) {
26
- super(props);
27
- this.state = { showCoordinates: false };
28
- }
52
+ state = { showCoordinates: false };
29
53
 
30
54
  render() {
31
55
  const {
32
- classes,
33
56
  className,
34
57
  coordinatesOnHover,
35
58
  x,
@@ -38,19 +61,16 @@ export class RawBp extends React.Component {
38
61
  correctness,
39
62
  graphProps,
40
63
  labelNode,
41
- // we need to remove style from props
42
- // eslint-disable-next-line no-unused-vars,react/prop-types
43
- style,
44
64
  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
65
  onTouchStart,
48
66
  onTouchEnd,
49
67
  ...rest
50
68
  } = this.props;
69
+
51
70
  const { showCoordinates } = this.state;
52
71
  const { scale } = graphProps;
53
72
  const r = thinnerShapesNeeded(graphProps) ? 5 : 7;
73
+
54
74
  let SvgComponent;
55
75
  switch (correctness) {
56
76
  case 'missing':
@@ -64,11 +84,11 @@ export class RawBp extends React.Component {
64
84
  break;
65
85
  default:
66
86
  SvgComponent = null;
67
- break;
68
87
  }
69
88
 
70
89
  return (
71
90
  <>
91
+ {/* Outer invisible circle for easier touch/click */}
72
92
  <circle
73
93
  style={{ fill: 'transparent', cursor: 'pointer', pointerEvents: 'all' }}
74
94
  r={r * 3}
@@ -80,8 +100,11 @@ export class RawBp extends React.Component {
80
100
  onTouchEnd={onTouchEnd}
81
101
  onClick={onClick}
82
102
  />
83
- <g
84
- className={classNames(classes.point, disabled && classes.disabledSecondary, classes[correctness], className)}
103
+ {/* Actual point */}
104
+ <StyledPointGroup
105
+ className={className}
106
+ disabled={disabled}
107
+ correctness={correctness}
85
108
  onMouseEnter={() => this.setState({ showCoordinates: true })}
86
109
  onMouseLeave={() => this.setState({ showCoordinates: false })}
87
110
  >
@@ -91,7 +114,7 @@ export class RawBp extends React.Component {
91
114
  coordinatesOnHover &&
92
115
  showCoordinates &&
93
116
  ReactDOM.createPortal(<CoordinatesLabel graphProps={graphProps} x={x} y={y} />, labelNode)}
94
- </g>
117
+ </StyledPointGroup>
95
118
  </>
96
119
  );
97
120
  }