@pie-lib/graphing 2.34.3-next.2 → 2.34.3-next.205

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 (218) hide show
  1. package/CHANGELOG.md +13 -67
  2. package/lib/axis/arrow.js +19 -55
  3. package/lib/axis/arrow.js.map +1 -1
  4. package/lib/axis/axes.js +106 -194
  5. package/lib/axis/axes.js.map +1 -1
  6. package/lib/axis/index.js +1 -6
  7. package/lib/axis/index.js.map +1 -1
  8. package/lib/bg.js +21 -49
  9. package/lib/bg.js.map +1 -1
  10. package/lib/container/actions.js +2 -8
  11. package/lib/container/actions.js.map +1 -1
  12. package/lib/container/index.js +14 -59
  13. package/lib/container/index.js.map +1 -1
  14. package/lib/container/marks.js +1 -6
  15. package/lib/container/marks.js.map +1 -1
  16. package/lib/container/middleware.js +2 -8
  17. package/lib/container/middleware.js.map +1 -1
  18. package/lib/container/reducer.js +1 -8
  19. package/lib/container/reducer.js.map +1 -1
  20. package/lib/coordinates-label.js +24 -54
  21. package/lib/coordinates-label.js.map +1 -1
  22. package/lib/graph-with-controls.js +120 -184
  23. package/lib/graph-with-controls.js.map +1 -1
  24. package/lib/graph.js +59 -116
  25. package/lib/graph.js.map +1 -1
  26. package/lib/grid-setup.js +169 -225
  27. package/lib/grid-setup.js.map +1 -1
  28. package/lib/grid.js +29 -74
  29. package/lib/grid.js.map +1 -1
  30. package/lib/index.js +1 -13
  31. package/lib/index.js.map +1 -1
  32. package/lib/key-legend.js +40 -85
  33. package/lib/key-legend.js.map +1 -1
  34. package/lib/label-svg-icon.js +1 -7
  35. package/lib/label-svg-icon.js.map +1 -1
  36. package/lib/labels.js +66 -122
  37. package/lib/labels.js.map +1 -1
  38. package/lib/mark-label.js +120 -163
  39. package/lib/mark-label.js.map +1 -1
  40. package/lib/toggle-bar.js +155 -243
  41. package/lib/toggle-bar.js.map +1 -1
  42. package/lib/tool-menu.js +16 -50
  43. package/lib/tool-menu.js.map +1 -1
  44. package/lib/tools/absolute/component.js +4 -10
  45. package/lib/tools/absolute/component.js.map +1 -1
  46. package/lib/tools/absolute/index.js +3 -16
  47. package/lib/tools/absolute/index.js.map +1 -1
  48. package/lib/tools/circle/bg-circle.js +42 -92
  49. package/lib/tools/circle/bg-circle.js.map +1 -1
  50. package/lib/tools/circle/component.js +78 -165
  51. package/lib/tools/circle/component.js.map +1 -1
  52. package/lib/tools/circle/index.js +3 -13
  53. package/lib/tools/circle/index.js.map +1 -1
  54. package/lib/tools/exponential/component.js +4 -10
  55. package/lib/tools/exponential/component.js.map +1 -1
  56. package/lib/tools/exponential/index.js +3 -18
  57. package/lib/tools/exponential/index.js.map +1 -1
  58. package/lib/tools/index.js +3 -16
  59. package/lib/tools/index.js.map +1 -1
  60. package/lib/tools/line/component.js +27 -48
  61. package/lib/tools/line/component.js.map +1 -1
  62. package/lib/tools/line/index.js +1 -6
  63. package/lib/tools/line/index.js.map +1 -1
  64. package/lib/tools/parabola/component.js +4 -10
  65. package/lib/tools/parabola/component.js.map +1 -1
  66. package/lib/tools/parabola/index.js +3 -16
  67. package/lib/tools/parabola/index.js.map +1 -1
  68. package/lib/tools/point/component.js +24 -71
  69. package/lib/tools/point/component.js.map +1 -1
  70. package/lib/tools/point/index.js +3 -11
  71. package/lib/tools/point/index.js.map +1 -1
  72. package/lib/tools/polygon/component.js +83 -184
  73. package/lib/tools/polygon/component.js.map +1 -1
  74. package/lib/tools/polygon/index.js +6 -23
  75. package/lib/tools/polygon/index.js.map +1 -1
  76. package/lib/tools/polygon/line.js +48 -91
  77. package/lib/tools/polygon/line.js.map +1 -1
  78. package/lib/tools/polygon/polygon.js +65 -98
  79. package/lib/tools/polygon/polygon.js.map +1 -1
  80. package/lib/tools/ray/component.js +41 -60
  81. package/lib/tools/ray/component.js.map +1 -1
  82. package/lib/tools/ray/index.js +1 -6
  83. package/lib/tools/ray/index.js.map +1 -1
  84. package/lib/tools/segment/component.js +25 -43
  85. package/lib/tools/segment/component.js.map +1 -1
  86. package/lib/tools/segment/index.js +1 -6
  87. package/lib/tools/segment/index.js.map +1 -1
  88. package/lib/tools/shared/arrow-head.js +69 -28
  89. package/lib/tools/shared/arrow-head.js.map +1 -1
  90. package/lib/tools/shared/icons/CorrectSVG.js +12 -8
  91. package/lib/tools/shared/icons/CorrectSVG.js.map +1 -1
  92. package/lib/tools/shared/icons/IncorrectSVG.js +12 -8
  93. package/lib/tools/shared/icons/IncorrectSVG.js.map +1 -1
  94. package/lib/tools/shared/icons/MissingSVG.js +12 -8
  95. package/lib/tools/shared/icons/MissingSVG.js.map +1 -1
  96. package/lib/tools/shared/line/index.js +140 -193
  97. package/lib/tools/shared/line/index.js.map +1 -1
  98. package/lib/tools/shared/line/line-path.js +70 -101
  99. package/lib/tools/shared/line/line-path.js.map +1 -1
  100. package/lib/tools/shared/line/with-root-edge.js +22 -56
  101. package/lib/tools/shared/line/with-root-edge.js.map +1 -1
  102. package/lib/tools/shared/point/arrow-point.js +21 -62
  103. package/lib/tools/shared/point/arrow-point.js.map +1 -1
  104. package/lib/tools/shared/point/arrow.js +23 -52
  105. package/lib/tools/shared/point/arrow.js.map +1 -1
  106. package/lib/tools/shared/point/base-point.js +54 -72
  107. package/lib/tools/shared/point/base-point.js.map +1 -1
  108. package/lib/tools/shared/point/index.js +22 -57
  109. package/lib/tools/shared/point/index.js.map +1 -1
  110. package/lib/tools/shared/styles.js +10 -38
  111. package/lib/tools/shared/styles.js.map +1 -1
  112. package/lib/tools/shared/types.js +2 -9
  113. package/lib/tools/shared/types.js.map +1 -1
  114. package/lib/tools/sine/component.js +8 -19
  115. package/lib/tools/sine/component.js.map +1 -1
  116. package/lib/tools/sine/index.js +3 -16
  117. package/lib/tools/sine/index.js.map +1 -1
  118. package/lib/tools/vector/component.js +24 -44
  119. package/lib/tools/vector/component.js.map +1 -1
  120. package/lib/tools/vector/index.js +1 -6
  121. package/lib/tools/vector/index.js.map +1 -1
  122. package/lib/undo-redo.js +29 -69
  123. package/lib/undo-redo.js.map +1 -1
  124. package/lib/use-debounce.js +4 -11
  125. package/lib/use-debounce.js.map +1 -1
  126. package/lib/utils.js +51 -128
  127. package/lib/utils.js.map +1 -1
  128. package/package.json +25 -29
  129. package/src/__tests__/graph-with-controls.test.jsx +28 -11
  130. package/src/__tests__/graph.test.jsx +104 -168
  131. package/src/__tests__/grid.test.jsx +8 -6
  132. package/src/__tests__/labels.test.jsx +25 -8
  133. package/src/__tests__/mark-label.test.jsx +12 -17
  134. package/src/__tests__/toggle-bar.test.jsx +92 -17
  135. package/src/__tests__/tool-menu.test.jsx +61 -12
  136. package/src/__tests__/undo-redo.test.jsx +7 -8
  137. package/src/__tests__/utils.js +3 -0
  138. package/src/axis/__tests__/arrow.test.jsx +16 -17
  139. package/src/axis/__tests__/axes.test.jsx +118 -122
  140. package/src/axis/arrow.jsx +7 -12
  141. package/src/axis/axes.jsx +45 -55
  142. package/src/coordinates-label.jsx +14 -18
  143. package/src/graph-with-controls.jsx +52 -59
  144. package/src/grid-setup.jsx +203 -205
  145. package/src/grid.jsx +2 -4
  146. package/src/key-legend.jsx +52 -56
  147. package/src/labels.jsx +24 -31
  148. package/src/mark-label.jsx +92 -81
  149. package/src/toggle-bar.jsx +135 -164
  150. package/src/tool-menu.jsx +1 -1
  151. package/src/tools/circle/__tests__/bg-circle.test.jsx +7 -9
  152. package/src/tools/circle/__tests__/component.test.jsx +17 -189
  153. package/src/tools/circle/bg-circle.jsx +20 -28
  154. package/src/tools/circle/component.jsx +28 -63
  155. package/src/tools/line/__tests__/component.test.jsx +7 -7
  156. package/src/tools/line/component.jsx +22 -15
  157. package/src/tools/point/__tests__/component.test.jsx +18 -43
  158. package/src/tools/point/component.jsx +1 -1
  159. package/src/tools/polygon/__tests__/component.test.jsx +18 -162
  160. package/src/tools/polygon/__tests__/line.test.jsx +7 -10
  161. package/src/tools/polygon/__tests__/polygon.test.jsx +7 -8
  162. package/src/tools/polygon/component.jsx +3 -4
  163. package/src/tools/polygon/line.jsx +30 -33
  164. package/src/tools/polygon/polygon.jsx +52 -45
  165. package/src/tools/ray/__tests__/component.test.jsx +7 -8
  166. package/src/tools/ray/component.jsx +38 -25
  167. package/src/tools/segment/__tests__/component.test.jsx +7 -8
  168. package/src/tools/segment/component.jsx +19 -18
  169. package/src/tools/shared/__tests__/arrow-head.test.jsx +14 -17
  170. package/src/tools/shared/arrow-head.jsx +60 -7
  171. package/src/tools/shared/icons/CorrectSVG.jsx +10 -0
  172. package/src/tools/shared/icons/IncorrectSVG.jsx +10 -0
  173. package/src/tools/shared/icons/MissingSVG.jsx +10 -0
  174. package/src/tools/shared/line/__tests__/index.test.jsx +19 -165
  175. package/src/tools/shared/line/__tests__/line-path.test.jsx +8 -8
  176. package/src/tools/shared/line/__tests__/with-root-edge.test.jsx +22 -22
  177. package/src/tools/shared/line/index.jsx +52 -7
  178. package/src/tools/shared/line/line-path.jsx +55 -59
  179. package/src/tools/shared/line/with-root-edge.jsx +1 -1
  180. package/src/tools/shared/point/__tests__/arrow-point.test.jsx +15 -11
  181. package/src/tools/shared/point/__tests__/base-point.test.jsx +14 -11
  182. package/src/tools/shared/point/arrow-point.jsx +10 -24
  183. package/src/tools/shared/point/arrow.jsx +5 -11
  184. package/src/tools/shared/point/base-point.jsx +42 -19
  185. package/src/tools/shared/point/index.jsx +27 -44
  186. package/src/tools/vector/__tests__/component.test.jsx +7 -8
  187. package/src/tools/vector/component.jsx +11 -16
  188. package/src/undo-redo.jsx +19 -21
  189. package/esm/index.css +0 -847
  190. package/esm/index.js +0 -239949
  191. package/esm/index.js.map +0 -1
  192. package/esm/package.json +0 -3
  193. package/src/__tests__/__snapshots__/graph-with-controls.test.jsx.snap +0 -237
  194. package/src/__tests__/__snapshots__/graph.test.jsx.snap +0 -211
  195. package/src/__tests__/__snapshots__/grid.test.jsx.snap +0 -54
  196. package/src/__tests__/__snapshots__/labels.test.jsx.snap +0 -30
  197. package/src/__tests__/__snapshots__/mark-label.test.jsx.snap +0 -45
  198. package/src/__tests__/__snapshots__/toggle-bar.test.jsx.snap +0 -7
  199. package/src/__tests__/__snapshots__/tool-menu.test.jsx.snap +0 -13
  200. package/src/__tests__/__snapshots__/undo-redo.test.jsx.snap +0 -14
  201. package/src/axis/__tests__/__snapshots__/arrow.test.jsx.snap +0 -33
  202. package/src/axis/__tests__/__snapshots__/axes.test.jsx.snap +0 -122
  203. package/src/tools/circle/__tests__/__snapshots__/bg-circle.test.jsx.snap +0 -46
  204. package/src/tools/circle/__tests__/__snapshots__/component.test.jsx.snap +0 -293
  205. package/src/tools/line/__tests__/__snapshots__/component.test.jsx.snap +0 -20
  206. package/src/tools/point/__tests__/__snapshots__/component.test.jsx.snap +0 -40
  207. package/src/tools/polygon/__tests__/__snapshots__/component.test.jsx.snap +0 -415
  208. package/src/tools/polygon/__tests__/__snapshots__/line.test.jsx.snap +0 -45
  209. package/src/tools/polygon/__tests__/__snapshots__/polygon.test.jsx.snap +0 -52
  210. package/src/tools/ray/__tests__/__snapshots__/component.test.jsx.snap +0 -23
  211. package/src/tools/segment/__tests__/__snapshots__/component.test.jsx.snap +0 -14
  212. package/src/tools/shared/__tests__/__snapshots__/arrow-head.test.jsx.snap +0 -27
  213. package/src/tools/shared/line/__tests__/__snapshots__/index.test.jsx.snap +0 -360
  214. package/src/tools/shared/line/__tests__/__snapshots__/line-path.test.jsx.snap +0 -58
  215. package/src/tools/shared/line/__tests__/__snapshots__/with-root-edge.test.jsx.snap +0 -63
  216. package/src/tools/shared/point/__tests__/__snapshots__/arrow-point.test.jsx.snap +0 -56
  217. package/src/tools/shared/point/__tests__/__snapshots__/base-point.test.jsx.snap +0 -44
  218. package/src/tools/vector/__tests__/__snapshots__/component.test.jsx.snap +0 -12
@@ -1,21 +1,14 @@
1
1
  import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
- import { withStyles } from '@material-ui/core/styles';
4
3
  import classNames from 'classnames';
5
4
  import { types, gridDraggable } from '@pie-lib/plot';
6
5
  import { color } from '@pie-lib/render-ui';
7
6
  import * as utils from '../../utils';
8
7
  import { disabled, disabledSecondary, correct, incorrect, missing } from '../shared/styles';
8
+ import { styled } from '@mui/material/styles';
9
9
 
10
- /**
11
- * A low level circle component
12
- *
13
- * TODO: This and base point have a lot of similarities - merge commonality
14
- *
15
- */
16
10
  class RawCircle extends React.Component {
17
11
  static propTypes = {
18
- classes: PropTypes.object.isRequired,
19
12
  className: PropTypes.string,
20
13
  correctness: PropTypes.string,
21
14
  disabled: PropTypes.bool,
@@ -26,14 +19,14 @@ class RawCircle extends React.Component {
26
19
  };
27
20
 
28
21
  render() {
29
- const { classes, disabled, className, correctness, x, y, radius, graphProps, ...rest } = this.props;
22
+ const { disabled, className, correctness, x, y, radius, graphProps, ...rest } = this.props;
30
23
  const { scale } = graphProps;
31
24
  const rx = Math.abs(scale.x(x + radius) - scale.x(x));
32
25
  const ry = Math.abs(scale.y(y + radius) - scale.y(y));
33
26
 
34
27
  return (
35
- <ellipse
36
- className={classNames(classes.bgCircle, disabled && classes.disabledSecondary, classes[correctness], className)}
28
+ <StyledEllipse
29
+ className={classNames(className, disabled && 'disabledSecondary', correctness)}
37
30
  cx={scale.x(x)}
38
31
  cy={scale.y(y)}
39
32
  rx={rx}
@@ -44,6 +37,7 @@ class RawCircle extends React.Component {
44
37
  }
45
38
  }
46
39
 
40
+ // helper to convert old style functions
47
41
  const applyStyle = (fn) => ({
48
42
  ...fn('stroke'),
49
43
  '&:hover': {
@@ -52,25 +46,23 @@ const applyStyle = (fn) => ({
52
46
  },
53
47
  });
54
48
 
55
- const styles = () => ({
56
- bgCircle: {
57
- fill: 'transparent',
58
- stroke: color.defaults.BLACK,
59
- strokeWidth: 3,
60
- transition: 'stroke 200ms ease-in, stroke-width 200ms ease-in',
61
- '&:hover': {
62
- strokeWidth: 6,
63
- stroke: color.defaults.PRIMARY_DARK,
64
- },
49
+ const StyledEllipse = styled('ellipse')(() => ({
50
+ fill: 'transparent',
51
+ stroke: color.defaults.BLACK,
52
+ strokeWidth: 3,
53
+ transition: 'stroke 200ms ease-in, stroke-width 200ms ease-in',
54
+ '&:hover': {
55
+ strokeWidth: 6,
56
+ stroke: color.defaults.PRIMARY_DARK,
65
57
  },
66
- disabled: applyStyle(disabled),
67
- disabledSecondary: applyStyle(disabledSecondary),
68
- correct: applyStyle(correct),
69
- incorrect: applyStyle(incorrect),
70
- missing: applyStyle(missing),
71
- });
58
+ '&.disabled': applyStyle(disabled),
59
+ '&.disabledSecondary': applyStyle(disabledSecondary),
60
+ '&.correct': applyStyle(correct),
61
+ '&.incorrect': applyStyle(incorrect),
62
+ '&.missing': applyStyle(missing),
63
+ }));
72
64
 
73
- export const BgCircle = withStyles(styles)(RawCircle);
65
+ export const BgCircle = RawCircle;
74
66
 
75
67
  export default gridDraggable({
76
68
  bounds: (props, { domain, range }) => {
@@ -1,18 +1,18 @@
1
1
  import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
- import { withStyles } from '@material-ui/core/styles';
3
+ import classNames from 'classnames';
4
4
  import { BasePoint } from '../shared/point';
5
5
  import BgCircle from './bg-circle';
6
6
  import { getMiddleOfTwoPoints, point, equalPoints } from '../../utils';
7
- import classNames from 'classnames';
8
7
  import { types } from '@pie-lib/plot';
9
8
  import { rootEdgeComponent } from '../shared/line/with-root-edge';
10
9
  import ReactDOM from 'react-dom';
11
10
  import MarkLabel from '../../mark-label';
12
11
  import isEmpty from 'lodash/isEmpty';
13
12
  import { color } from '@pie-lib/render-ui';
13
+ import { styled, keyframes } from '@mui/material/styles';
14
14
 
15
- const opacityPulsate = (opacity) => ({
15
+ const opacityPulsate = (opacity) => keyframes({
16
16
  '0%': { opacity: '0.0' },
17
17
  '50%': { opacity },
18
18
  '100%': { opacity: '0.0' },
@@ -26,7 +26,6 @@ const getRadius = (from, outer) => {
26
26
  export class RawBaseCircle extends React.Component {
27
27
  static propTypes = {
28
28
  building: PropTypes.bool,
29
- classes: PropTypes.object.isRequired,
30
29
  className: PropTypes.string,
31
30
  coordinatesOnHover: PropTypes.bool,
32
31
  correctness: PropTypes.string,
@@ -53,12 +52,10 @@ export class RawBaseCircle extends React.Component {
53
52
  const { middle, onChange } = this.props;
54
53
  const { from, to } = point;
55
54
 
56
- // because point.from.label and point.to.label can be different
57
55
  if (!equalPoints(from, to)) {
58
56
  if (middle) {
59
57
  point.middle = { ...middle, ...getMiddleOfTwoPoints(from, to) };
60
58
  }
61
-
62
59
  onChange(point);
63
60
  }
64
61
  };
@@ -66,10 +63,7 @@ export class RawBaseCircle extends React.Component {
66
63
  dragFrom = (draggedFrom) => {
67
64
  const { from, to } = this.props;
68
65
 
69
- if (from.label) {
70
- draggedFrom.label = from.label;
71
- }
72
-
66
+ if (from.label) draggedFrom.label = from.label;
73
67
  if (!equalPoints(draggedFrom, to)) {
74
68
  this.onChangePoint({ from: draggedFrom, to });
75
69
  }
@@ -78,10 +72,7 @@ export class RawBaseCircle extends React.Component {
78
72
  dragTo = (draggedTo) => {
79
73
  const { from, to } = this.props;
80
74
 
81
- if (to.label) {
82
- draggedTo.label = to.label;
83
- }
84
-
75
+ if (to.label) draggedTo.label = to.label;
85
76
  if (!equalPoints(from, draggedTo)) {
86
77
  this.onChangePoint({ from, to: draggedTo });
87
78
  }
@@ -92,58 +83,36 @@ export class RawBaseCircle extends React.Component {
92
83
  const diff = point(from).sub(point(draggedFrom));
93
84
  const draggedTo = point(to).sub(diff);
94
85
 
95
- if (from.label) {
96
- draggedFrom.label = from.label;
97
- }
98
-
99
- if (to.label) {
100
- draggedTo.label = to.label;
101
- }
86
+ if (from.label) draggedFrom.label = from.label;
87
+ if (to.label) draggedTo.label = to.label;
102
88
 
103
89
  const updated = { from: draggedFrom, to: draggedTo };
104
-
105
90
  if (middle) {
106
91
  updated.middle = { ...middle, ...getMiddleOfTwoPoints(draggedFrom, draggedTo) };
107
92
  }
108
93
 
109
94
  this.setState(
110
- {
111
- draggedroot: undefined,
112
- draggedOuter: undefined,
113
- isCircleDrag: false,
114
- },
115
- () => {
116
- onChange(updated);
117
- },
95
+ { draggedroot: undefined, draggedOuter: undefined, isCircleDrag: false },
96
+ () => onChange(updated),
118
97
  );
119
98
  };
120
99
 
121
100
  labelChange = (point, type) => {
122
101
  const { changeMarkProps } = this.props;
123
102
  const update = { ...point };
124
-
125
- if (!point.label || isEmpty(point.label)) {
126
- delete update.label;
127
- }
128
-
103
+ if (!point.label || isEmpty(point.label)) delete update.label;
129
104
  changeMarkProps({ [type]: update });
130
105
  };
131
106
 
132
107
  clickPoint = (point, type, data) => {
133
108
  const { changeMarkProps, disabled, from, to, labelModeEnabled, limitLabeling, onClick } = this.props;
109
+
134
110
  if (!labelModeEnabled) {
135
111
  onClick(point || data);
136
112
  return;
137
113
  }
138
114
 
139
- if (disabled) {
140
- return;
141
- }
142
-
143
- // limit labeling the points of the circle
144
- if (limitLabeling) {
145
- return;
146
- }
115
+ if (disabled || limitLabeling) return;
147
116
 
148
117
  if (type === 'middle' && !point && from && to) {
149
118
  point = { ...point, ...getMiddleOfTwoPoints(from, to) };
@@ -156,7 +125,6 @@ export class RawBaseCircle extends React.Component {
156
125
  }
157
126
  };
158
127
 
159
- // IMPORTANT, do not remove
160
128
  input = {};
161
129
 
162
130
  render() {
@@ -165,9 +133,8 @@ export class RawBaseCircle extends React.Component {
165
133
  to,
166
134
  middle,
167
135
  disabled,
168
- classes,
169
- coordinatesOnHover,
170
136
  building,
137
+ coordinatesOnHover,
171
138
  onDragStart,
172
139
  onDragStop,
173
140
  onClick,
@@ -176,10 +143,9 @@ export class RawBaseCircle extends React.Component {
176
143
  labelNode,
177
144
  labelModeEnabled,
178
145
  } = this.props;
179
- const common = { onDragStart, onDragStop, graphProps, onClick };
180
146
 
147
+ const common = { onDragStart, onDragStop, graphProps, onClick };
181
148
  to = to || from;
182
-
183
149
  const radius = getRadius(from, to);
184
150
 
185
151
  let fromLabelNode = null;
@@ -187,7 +153,7 @@ export class RawBaseCircle extends React.Component {
187
153
  let circleLabelNode = null;
188
154
 
189
155
  if (labelNode) {
190
- if (from && from.hasOwnProperty('label')) {
156
+ if (from?.label !== undefined) {
191
157
  fromLabelNode = ReactDOM.createPortal(
192
158
  <MarkLabel
193
159
  inputRef={(r) => (this.input.from = r)}
@@ -200,7 +166,7 @@ export class RawBaseCircle extends React.Component {
200
166
  );
201
167
  }
202
168
 
203
- if (to && to.hasOwnProperty('label')) {
169
+ if (to?.label !== undefined) {
204
170
  toLabelNode = ReactDOM.createPortal(
205
171
  <MarkLabel
206
172
  inputRef={(r) => (this.input.to = r)}
@@ -213,7 +179,7 @@ export class RawBaseCircle extends React.Component {
213
179
  );
214
180
  }
215
181
 
216
- if (middle && middle.hasOwnProperty('label')) {
182
+ if (middle?.label !== undefined) {
217
183
  circleLabelNode = ReactDOM.createPortal(
218
184
  <MarkLabel
219
185
  inputRef={(r) => (this.input.middle = r)}
@@ -229,10 +195,10 @@ export class RawBaseCircle extends React.Component {
229
195
 
230
196
  return (
231
197
  <g>
232
- <BgCircle
198
+ <StyledBgCircle
233
199
  disabled={building || disabled}
234
200
  correctness={correctness}
235
- className={classNames(building && classes.bgCircleBuilding)}
201
+ className={classNames(building && 'bgCircleBuilding')}
236
202
  x={from.x}
237
203
  y={from.y}
238
204
  radius={radius}
@@ -262,7 +228,7 @@ export class RawBaseCircle extends React.Component {
262
228
  labelNode={labelNode}
263
229
  x={from.x}
264
230
  y={from.y}
265
- className={classes.from}
231
+ className="from"
266
232
  onDrag={this.dragFrom}
267
233
  {...common}
268
234
  onClick={(data) => this.clickPoint(from, 'from', data)}
@@ -273,9 +239,10 @@ export class RawBaseCircle extends React.Component {
273
239
  }
274
240
  }
275
241
 
276
- export const BaseCircle = withStyles(() => ({
277
- outerLine: {
278
- fill: 'rgb(0,0,0,0)', // TODO hardcoded color
242
+ // MUI v5 styled() replaces withStyles
243
+ const StyledBgCircle = styled(BgCircle)(() => ({
244
+ '&.outerLine': {
245
+ fill: 'rgba(0,0,0,0)',
279
246
  stroke: color.defaults.BLACK,
280
247
  strokeWidth: 4,
281
248
  '&:hover': {
@@ -283,15 +250,13 @@ export const BaseCircle = withStyles(() => ({
283
250
  stroke: color.defaults.PRIMARY_DARK,
284
251
  },
285
252
  },
286
- root: {},
287
- bgCircleBuilding: {
253
+ '&.bgCircleBuilding': {
288
254
  stroke: color.defaults.BLACK,
289
- animation: 'opacityPulse 2s ease-out',
290
- animationIterationCount: 'infinite',
255
+ animation: `${opacityPulsate('0.3')} 2s ease-out infinite`,
291
256
  opacity: 1,
292
257
  },
293
- '@keyframes opacityPulse': opacityPulsate('0.3'),
294
- }))(RawBaseCircle);
258
+ }));
295
259
 
260
+ export const BaseCircle = RawBaseCircle;
296
261
  const Component = rootEdgeComponent(BaseCircle);
297
262
  export default Component;
@@ -1,4 +1,4 @@
1
- import { shallow } from 'enzyme';
1
+ import { render } from '@pie-lib/test-utils';
2
2
  import React from 'react';
3
3
  import { ArrowedLine } from '../component';
4
4
  import { graphProps as getGraphProps } from '../../../__tests__/utils';
@@ -15,9 +15,8 @@ jest.mock('@pie-lib/plot', () => {
15
15
  });
16
16
 
17
17
  describe('ArrowedLine', () => {
18
- let w;
19
18
  let onChange = jest.fn();
20
- const wrapper = (extras) => {
19
+ const renderComponent = (extras) => {
21
20
  const defaults = {
22
21
  classes: {},
23
22
  className: 'className',
@@ -26,11 +25,12 @@ describe('ArrowedLine', () => {
26
25
  graphProps: getGraphProps(),
27
26
  };
28
27
  const props = { ...defaults, ...extras };
29
- return shallow(<ArrowedLine {...props} />);
28
+ return render(<ArrowedLine {...props} />);
30
29
  };
31
- describe('snapshot', () => {
32
- it('renders', () => {
33
- expect(wrapper()).toMatchSnapshot();
30
+ describe('rendering', () => {
31
+ it('renders without crashing', () => {
32
+ const { container } = renderComponent();
33
+ expect(container.firstChild).toBeInTheDocument();
34
34
  });
35
35
  });
36
36
  });
@@ -3,11 +3,11 @@ import React from 'react';
3
3
  import PropTypes from 'prop-types';
4
4
  import { trig, types } from '@pie-lib/plot';
5
5
  import classNames from 'classnames';
6
- import { withStyles } from '@material-ui/core/styles';
7
6
  import { ArrowMarker, genUid } from '../shared/arrow-head';
8
7
  import { thinnerShapesNeeded, getAdjustedGraphLimits } from '../../utils';
8
+ import { styled } from '@mui/material/styles';
9
9
 
10
- const lineStyles = (theme) => ({
10
+ const StyledArrowedLineRoot = styled('g')(({ theme }) => ({
11
11
  line: styles.line(theme),
12
12
  enabledArrow: styles.arrow(theme),
13
13
  disabledArrow: styles.disabledArrow(theme),
@@ -19,23 +19,28 @@ const lineStyles = (theme) => ({
19
19
  incorrectArrow: styles.incorrect(theme),
20
20
  missing: styles.missing(theme, 'stroke'),
21
21
  missingArrow: styles.missing(theme),
22
- });
22
+ }));
23
23
 
24
24
  export const ArrowedLine = (props) => {
25
25
  const markerId = genUid();
26
- const { className, classes, correctness, disabled, graphProps, from, to, ...rest } = props;
26
+ const { className, correctness, disabled, graphProps, from, to, markerId: propMarkerId, ...rest } = props;
27
27
  const { scale } = graphProps;
28
28
  const { domain, range } = getAdjustedGraphLimits(graphProps);
29
29
  const [eFrom, eTo] = trig.edges(domain, range)(from, to);
30
30
  const suffix = correctness || (disabled && 'disabled') || 'enabled';
31
+ const finalMarkerId = propMarkerId || markerId;
31
32
 
32
33
  return (
33
- <g>
34
+ <StyledArrowedLineRoot>
34
35
  <defs>
35
36
  <ArrowMarker
36
37
  size={thinnerShapesNeeded(graphProps) ? 4 : 5}
37
- id={`${props.markerId || markerId}-${suffix}`}
38
- className={classNames(classes[`${suffix}Arrow`])}
38
+ id={`${finalMarkerId}-${suffix}`}
39
+ className={classNames(
40
+ suffix === 'enabled' ? 'enabledArrow' :
41
+ suffix === 'disabled' ? 'disabledArrow' :
42
+ `${suffix}Arrow`
43
+ )}
39
44
  />
40
45
  </defs>
41
46
  <line
@@ -43,18 +48,22 @@ export const ArrowedLine = (props) => {
43
48
  y1={scale.y(eFrom.y)}
44
49
  x2={scale.x(eTo.x)}
45
50
  y2={scale.y(eTo.y)}
46
- className={classNames(classes.line, disabled && classes.disabledSecondary, classes[correctness], className)}
47
- markerEnd={`url(#${props.markerId || markerId}-${suffix})`}
48
- markerStart={`url(#${props.markerId || markerId}-${suffix})`}
51
+ className={classNames(
52
+ 'line',
53
+ disabled && 'disabledSecondary',
54
+ correctness,
55
+ className
56
+ )}
57
+ markerEnd={`url(#${finalMarkerId}-${suffix})`}
58
+ markerStart={`url(#${finalMarkerId}-${suffix})`}
49
59
  {...rest}
50
60
  />
51
- </g>
61
+ </StyledArrowedLineRoot>
52
62
  );
53
63
  };
54
64
 
55
65
  ArrowedLine.propTypes = {
56
66
  className: PropTypes.string,
57
- classes: PropTypes.object,
58
67
  correctness: PropTypes.string,
59
68
  disabled: PropTypes.bool,
60
69
  graphProps: types.GraphPropsType,
@@ -63,9 +72,7 @@ ArrowedLine.propTypes = {
63
72
  markerId: PropTypes.string,
64
73
  };
65
74
 
66
- const StyledArrowedLine = withStyles(lineStyles)(ArrowedLine);
67
-
68
- const Line = lineBase(StyledArrowedLine);
75
+ const Line = lineBase(ArrowedLine);
69
76
  const Component = lineToolComponent(Line);
70
77
 
71
78
  export default Component;
@@ -1,13 +1,17 @@
1
- import { shallow } from 'enzyme';
1
+ import { render } from '@pie-lib/test-utils';
2
2
  import React from 'react';
3
3
  import { graphProps, xy } from '../../../__tests__/utils';
4
4
 
5
5
  import Component from '../component';
6
6
 
7
7
  describe('Component', () => {
8
- let w;
9
8
  let onChange = jest.fn();
10
- const wrapper = (extras, opts) => {
9
+
10
+ beforeEach(() => {
11
+ onChange.mockClear();
12
+ });
13
+
14
+ const renderComponent = (extras) => {
11
15
  const defaults = {
12
16
  classes: {},
13
17
  className: 'className',
@@ -15,52 +19,23 @@ describe('Component', () => {
15
19
  graphProps: graphProps(),
16
20
  };
17
21
  const props = { ...defaults, ...extras };
18
- return shallow(<Component {...props} />, opts);
22
+ return render(<Component {...props} />);
19
23
  };
20
24
 
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
- });
25
+ describe('rendering', () => {
26
+ it('renders without crashing', () => {
27
+ const { container } = renderComponent();
28
+ expect(container.firstChild).toBeInTheDocument();
35
29
  });
36
30
 
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
- });
31
+ it('renders with mark', () => {
32
+ const { container } = renderComponent({ mark: { ...xy(0, 0) } });
33
+ expect(container.firstChild).toBeInTheDocument();
45
34
  });
46
35
 
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
- });
36
+ it('renders with label', () => {
37
+ const { container } = renderComponent({ mark: { label: 'foo', ...xy(0, 0) } });
38
+ expect(container.firstChild).toBeInTheDocument();
64
39
  });
65
40
  });
66
41
  });
@@ -101,7 +101,7 @@ export class Point extends React.Component {
101
101
  }}
102
102
  />
103
103
  {labelNode &&
104
- mark.hasOwnProperty('label') &&
104
+ Object.prototype.hasOwnProperty.call(mark, 'label') &&
105
105
  ReactDOM.createPortal(
106
106
  <MarkLabel
107
107
  inputRef={(r) => (this.input = r)}