@pie-lib/graphing 2.34.2-next.0 → 2.36.0-mui-update.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 (155) hide show
  1. package/CHANGELOG.md +16 -6
  2. package/lib/axis/arrow.js +19 -55
  3. package/lib/axis/arrow.js.map +1 -1
  4. package/lib/axis/axes.js +104 -186
  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 +23 -55
  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 +174 -224
  27. package/lib/grid-setup.js.map +1 -1
  28. package/lib/grid.js +28 -73
  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 +41 -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 +61 -119
  37. package/lib/labels.js.map +1 -1
  38. package/lib/mark-label.js +113 -163
  39. package/lib/mark-label.js.map +1 -1
  40. package/lib/toggle-bar.js +158 -242
  41. package/lib/toggle-bar.js.map +1 -1
  42. package/lib/tool-menu.js +16 -48
  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 +79 -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 +82 -183
  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 +3 -8
  91. package/lib/tools/shared/icons/CorrectSVG.js.map +1 -1
  92. package/lib/tools/shared/icons/IncorrectSVG.js +3 -8
  93. package/lib/tools/shared/icons/IncorrectSVG.js.map +1 -1
  94. package/lib/tools/shared/icons/MissingSVG.js +3 -8
  95. package/lib/tools/shared/icons/MissingSVG.js.map +1 -1
  96. package/lib/tools/shared/line/index.js +126 -187
  97. package/lib/tools/shared/line/index.js.map +1 -1
  98. package/lib/tools/shared/line/line-path.js +70 -100
  99. package/lib/tools/shared/line/line-path.js.map +1 -1
  100. package/lib/tools/shared/line/with-root-edge.js +21 -55
  101. package/lib/tools/shared/line/with-root-edge.js.map +1 -1
  102. package/lib/tools/shared/point/arrow-point.js +23 -62
  103. package/lib/tools/shared/point/arrow-point.js.map +1 -1
  104. package/lib/tools/shared/point/arrow.js +24 -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 +16 -13
  129. package/src/axis/arrow.jsx +7 -12
  130. package/src/axis/axes.jsx +40 -45
  131. package/src/coordinates-label.jsx +13 -18
  132. package/src/graph-with-controls.jsx +52 -59
  133. package/src/grid-setup.jsx +210 -206
  134. package/src/grid.jsx +1 -3
  135. package/src/key-legend.jsx +52 -56
  136. package/src/labels.jsx +21 -30
  137. package/src/mark-label.jsx +83 -81
  138. package/src/toggle-bar.jsx +155 -166
  139. package/src/tools/circle/bg-circle.jsx +20 -28
  140. package/src/tools/circle/component.jsx +28 -63
  141. package/src/tools/line/component.jsx +22 -15
  142. package/src/tools/polygon/component.jsx +1 -2
  143. package/src/tools/polygon/line.jsx +28 -32
  144. package/src/tools/polygon/polygon.jsx +52 -45
  145. package/src/tools/ray/component.jsx +38 -25
  146. package/src/tools/segment/component.jsx +19 -18
  147. package/src/tools/shared/arrow-head.jsx +60 -7
  148. package/src/tools/shared/line/index.jsx +39 -2
  149. package/src/tools/shared/line/line-path.jsx +54 -58
  150. package/src/tools/shared/point/arrow-point.jsx +10 -24
  151. package/src/tools/shared/point/arrow.jsx +5 -11
  152. package/src/tools/shared/point/base-point.jsx +42 -19
  153. package/src/tools/shared/point/index.jsx +27 -44
  154. package/src/tools/vector/component.jsx +11 -16
  155. package/src/undo-redo.jsx +19 -21
@@ -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)(({ theme }) => ({
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;
@@ -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,6 +1,5 @@
1
1
  import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
- import { withStyles } from '@material-ui/core/styles';
4
3
  import { ToolPropTypeFields } from '../shared/types';
5
4
  import { BasePoint } from '../shared/point';
6
5
  import chunk from 'lodash/chunk';
@@ -304,7 +303,7 @@ export class RawBaseComponent extends React.Component {
304
303
  }
305
304
  }
306
305
 
307
- export const BaseComponent = withStyles(() => ({}))(RawBaseComponent);
306
+ export const BaseComponent = RawBaseComponent;
308
307
 
309
308
  export default class Component extends React.Component {
310
309
  static propTypes = {
@@ -1,16 +1,35 @@
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, gridDraggable } from '@pie-lib/plot';
5
5
  import { color } from '@pie-lib/render-ui';
6
6
  import * as utils from '../../utils';
7
- import classNames from 'classnames';
8
7
  import { correct, disabled, disabledSecondary, incorrect, missing } from '../shared/styles';
9
8
 
9
+ const StyledLine = styled('line')(({ theme, disabled: isDisabled, correctness }) => ({
10
+ strokeWidth: 3,
11
+ transition: 'stroke-width 200ms ease-in, stroke 200ms ease-in',
12
+ stroke: 'transparent',
13
+ '&:hover': {
14
+ strokeWidth: 4,
15
+ stroke: color.defaults.BLACK,
16
+ },
17
+ ...(isDisabled && {
18
+ ...disabled('stroke'),
19
+ strokeWidth: 2,
20
+ }),
21
+ ...(correctness === 'correct' && correct('stroke')),
22
+ ...(correctness === 'incorrect' && incorrect('stroke')),
23
+ ...(correctness === 'missing' && {
24
+ ...missing('stroke'),
25
+ strokeWidth: 1,
26
+ strokeDasharray: '4 3',
27
+ }),
28
+ }));
29
+
10
30
  class RawLine extends React.Component {
11
31
  static propTypes = {
12
32
  className: PropTypes.string,
13
- classes: PropTypes.object,
14
33
  from: types.PointType,
15
34
  to: types.PointType,
16
35
  graphProps: types.GraphPropsType.isRequired,
@@ -24,47 +43,24 @@ class RawLine extends React.Component {
24
43
  };
25
44
 
26
45
  render() {
27
- const { graphProps, classes, from, to, className, disabled, correctness, ...rest } = this.props;
46
+ const { graphProps, from, to, className, disabled, correctness, ...rest } = this.props;
28
47
  const { scale } = graphProps;
29
48
  return (
30
- <line
49
+ <StyledLine
31
50
  x1={scale.x(from.x)}
32
51
  y1={scale.y(from.y)}
33
52
  x2={scale.x(to.x)}
34
53
  y2={scale.y(to.y)}
35
- className={classNames(classes.line, disabled && classes.disabledSecondary, className, classes[correctness])}
54
+ className={className}
55
+ disabled={disabled}
56
+ correctness={correctness}
36
57
  {...rest}
37
58
  />
38
59
  );
39
60
  }
40
61
  }
41
62
 
42
- export const Line = withStyles(() => ({
43
- line: {
44
- strokeWidth: 3,
45
- transition: 'stroke-width 200ms ease-in, stroke 200ms ease-in',
46
- stroke: 'transparent',
47
- '&:hover': {
48
- strokeWidth: 4,
49
- stroke: color.defaults.BLACK,
50
- },
51
- },
52
- disabled: {
53
- ...disabled('stroke'),
54
- strokeWidth: 2,
55
- },
56
- disabledSecondary: {
57
- ...disabledSecondary('stroke'),
58
- strokeWidth: 2,
59
- },
60
- correct: correct('stroke'),
61
- incorrect: incorrect('stroke'),
62
- missing: {
63
- ...missing('stroke'),
64
- strokeWidth: 1,
65
- strokeDasharray: '4 3',
66
- },
67
- }))(RawLine);
63
+ export const Line = RawLine;
68
64
 
69
65
  export default gridDraggable({
70
66
  bounds: (props, { domain, range }) => {
@@ -1,13 +1,38 @@
1
1
  import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
- import { withStyles } from '@material-ui/core/styles';
3
+ import { alpha, styled } from '@mui/material/styles';
4
4
  import { gridDraggable, types } from '@pie-lib/plot';
5
5
  import * as utils from '../../utils';
6
- import classNames from 'classnames';
7
6
  import { color } from '@pie-lib/render-ui';
8
- import { fade } from '@material-ui/core/styles/colorManipulator';
9
7
  import { correct, disabled, incorrect, missing } from '../shared/styles';
10
8
 
9
+ const StyledPolygon = styled('polygon')(({ theme, disabled: isDisabled, correctness }) => ({
10
+ fill: alpha(theme.palette.primary.light, 0.2),
11
+ strokeWidth: 2,
12
+ stroke: color.defaults.BLACK,
13
+ ...(isDisabled && disabled('stroke')),
14
+ ...(correctness === 'correct' && correct('stroke')),
15
+ ...(correctness === 'incorrect' && incorrect('stroke')),
16
+ ...(correctness === 'missing' && {
17
+ ...missing('stroke'),
18
+ stroke: 'inherit',
19
+ }),
20
+ }));
21
+
22
+ const StyledPolyline = styled('polyline')(({ theme, disabled: isDisabled, correctness }) => ({
23
+ fill: alpha(theme.palette.primary.light, 0.0),
24
+ strokeWidth: 2,
25
+ stroke: color.defaults.BLACK,
26
+ pointerEvents: 'none',
27
+ ...(isDisabled && disabled('stroke')),
28
+ ...(correctness === 'correct' && correct('stroke')),
29
+ ...(correctness === 'incorrect' && incorrect('stroke')),
30
+ ...(correctness === 'missing' && {
31
+ ...missing('stroke'),
32
+ stroke: 'inherit',
33
+ }),
34
+ }));
35
+
11
36
  export const getPointString = (points, scale) => {
12
37
  return (points || [])
13
38
  .map((p) => {
@@ -22,7 +47,6 @@ export const getPointString = (points, scale) => {
22
47
 
23
48
  export class RawPolygon extends React.Component {
24
49
  static propTypes = {
25
- classes: PropTypes.object,
26
50
  className: PropTypes.string,
27
51
  disabled: PropTypes.bool,
28
52
  points: PropTypes.arrayOf(types.PointType),
@@ -36,53 +60,36 @@ export class RawPolygon extends React.Component {
36
60
  };
37
61
 
38
62
  render() {
39
- const { points, classes, className, disabled, correctness, graphProps, closed, ...rest } = this.props;
63
+ const { points, className, disabled, correctness, graphProps, closed, ...rest } = this.props;
40
64
  const { scale } = graphProps;
41
65
 
42
66
  const pointString = getPointString(points, scale);
43
- const Tag = closed ? 'polygon' : 'polyline';
44
- return (
45
- <Tag
46
- points={pointString}
47
- className={classNames(
48
- closed && classes.closed,
49
- !closed && classes.open,
50
- disabled && classes.disabled,
51
- classes[correctness],
52
- className,
53
- )}
54
- {...rest}
55
- />
56
- );
67
+
68
+ if (closed) {
69
+ return (
70
+ <StyledPolygon
71
+ points={pointString}
72
+ className={className}
73
+ disabled={disabled}
74
+ correctness={correctness}
75
+ {...rest}
76
+ />
77
+ );
78
+ } else {
79
+ return (
80
+ <StyledPolyline
81
+ points={pointString}
82
+ className={className}
83
+ disabled={disabled}
84
+ correctness={correctness}
85
+ {...rest}
86
+ />
87
+ );
88
+ }
57
89
  }
58
90
  }
59
91
 
60
- export const Polygon = withStyles((theme) => ({
61
- closed: {
62
- fill: fade(theme.palette.primary.light, 0.2), // TODO hardcoded color
63
- strokeWidth: 2,
64
- stroke: color.defaults.BLACK,
65
- },
66
- open: {
67
- fill: fade(theme.palette.primary.light, 0.0), // TODO hardcoded color
68
- strokeWidth: 2,
69
- stroke: color.defaults.BLACK,
70
- pointerEvents: 'none',
71
- },
72
- disabled: {
73
- ...disabled('stroke'),
74
- },
75
- correct: {
76
- ...correct('stroke'),
77
- },
78
- incorrect: {
79
- ...incorrect('stroke'),
80
- },
81
- missing: {
82
- ...missing('stroke'),
83
- stroke: 'inherit',
84
- },
85
- }))(RawPolygon);
92
+ export const Polygon = RawPolygon;
86
93
 
87
94
  export default gridDraggable({
88
95
  bounds: (props, { domain, range }) => {
@@ -3,39 +3,55 @@ import React from 'react';
3
3
  import PropTypes from 'prop-types';
4
4
  import { ArrowMarker, genUid } from '../shared/arrow-head';
5
5
  import { trig, types } from '@pie-lib/plot';
6
- import { withStyles } from '@material-ui/core/styles';
7
6
  import classNames from 'classnames';
8
7
  import { thinnerShapesNeeded, getAdjustedGraphLimits } from '../../utils';
8
+ import { styled } from '@mui/material/styles';
9
9
 
10
- const rayStyles = (theme) => ({
11
- line: styles.line(theme),
12
- enabledArrow: styles.arrow(theme),
13
- disabledArrow: styles.disabledArrow(theme),
14
- disabled: styles.disabled(theme),
15
- disabledSecondary: styles.disabledSecondary(theme),
16
- correct: styles.correct(theme, 'stroke'),
17
- correctArrow: styles.correct(theme),
18
- incorrect: styles.incorrect(theme, 'stroke'),
19
- incorrectArrow: styles.incorrect(theme),
20
- missing: styles.missing(theme, 'stroke'),
21
- missingArrow: styles.missing(theme),
22
- });
10
+ const StyledRayRoot = styled('g')(({ theme, disabled, correctness }) => ({
11
+ '& line': {
12
+ ...styles.line(theme),
13
+ ...(disabled && styles.disabledSecondary(theme)),
14
+ ...(correctness === 'correct' && styles.correct(theme, 'stroke')),
15
+ ...(correctness === 'incorrect' && styles.incorrect(theme, 'stroke')),
16
+ ...(correctness === 'missing' && styles.missing(theme, 'stroke')),
17
+ },
18
+ '& .enabledArrow': {
19
+ ...styles.arrow(theme),
20
+ },
21
+ '& .disabledArrow': {
22
+ ...styles.disabledArrow(theme),
23
+ },
24
+ '& .correctArrow': {
25
+ ...styles.correct(theme),
26
+ },
27
+ '& .incorrectArrow': {
28
+ ...styles.incorrect(theme),
29
+ },
30
+ '& .missingArrow': {
31
+ ...styles.missing(theme),
32
+ },
33
+ }));
23
34
 
24
35
  export const RayLine = (props) => {
25
36
  const markerId = genUid();
26
- const { graphProps, from, to, classes, disabled, correctness, className, ...rest } = props;
37
+ const { graphProps, from, to, disabled, correctness, className, markerId: propMarkerId, ...rest } = props;
27
38
  const { scale } = graphProps;
28
39
  const { domain, range } = getAdjustedGraphLimits(graphProps);
29
40
  const [aToB] = trig.edges(domain, range)(from, to);
30
41
  const suffix = correctness || (disabled && 'disabled') || 'enabled';
42
+ const finalMarkerId = propMarkerId || markerId;
31
43
 
32
44
  return (
33
- <g>
45
+ <StyledRayRoot disabled={disabled} correctness={correctness}>
34
46
  <defs>
35
47
  <ArrowMarker
36
48
  size={thinnerShapesNeeded(graphProps) ? 4 : 5}
37
- id={`${props.markerId || markerId}-${suffix}`}
38
- className={classNames(classes[`${suffix}Arrow`])}
49
+ id={`${finalMarkerId}-${suffix}`}
50
+ className={classNames(
51
+ suffix === 'enabled' ? 'enabledArrow' :
52
+ suffix === 'disabled' ? 'disabledArrow' :
53
+ `${suffix}Arrow`
54
+ )}
39
55
  />
40
56
  </defs>
41
57
  <line
@@ -43,16 +59,15 @@ export const RayLine = (props) => {
43
59
  y1={scale.y(from.y)}
44
60
  x2={scale.x(aToB.x)}
45
61
  y2={scale.y(aToB.y)}
62
+ className={className}
63
+ markerEnd={`url(#${finalMarkerId}-${suffix})`}
46
64
  {...rest}
47
- className={classNames(classes.line, disabled && classes.disabledSecondary, classes[correctness], className)}
48
- markerEnd={`url(#${props.markerId || markerId}-${suffix})`}
49
65
  />
50
- </g>
66
+ </StyledRayRoot>
51
67
  );
52
68
  };
53
69
 
54
70
  RayLine.propTypes = {
55
- classes: PropTypes.object,
56
71
  className: PropTypes.string,
57
72
  disabled: PropTypes.bool,
58
73
  correctness: PropTypes.string,
@@ -62,9 +77,7 @@ RayLine.propTypes = {
62
77
  markerId: PropTypes.string,
63
78
  };
64
79
 
65
- const StyledRay = withStyles(rayStyles)(RayLine);
66
-
67
- const Ray = lineBase(StyledRay);
80
+ const Ray = lineBase(RayLine);
68
81
  const Component = lineToolComponent(Ray);
69
82
 
70
83
  export default Component;