@pie-lib/graphing-solution-set 2.34.3-next.0 → 2.34.3-next.155

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 (142) hide show
  1. package/CHANGELOG.md +7 -78
  2. package/esm/package.json +3 -0
  3. package/lib/axis/arrow.js +19 -55
  4. package/lib/axis/arrow.js.map +1 -1
  5. package/lib/axis/axes.js +103 -193
  6. package/lib/axis/axes.js.map +1 -1
  7. package/lib/axis/index.js +1 -6
  8. package/lib/axis/index.js.map +1 -1
  9. package/lib/bg.js +21 -49
  10. package/lib/bg.js.map +1 -1
  11. package/lib/container/actions.js +2 -8
  12. package/lib/container/actions.js.map +1 -1
  13. package/lib/container/index.js +14 -60
  14. package/lib/container/index.js.map +1 -1
  15. package/lib/container/marks.js +1 -6
  16. package/lib/container/marks.js.map +1 -1
  17. package/lib/container/middleware.js +2 -8
  18. package/lib/container/middleware.js.map +1 -1
  19. package/lib/container/reducer.js +1 -8
  20. package/lib/container/reducer.js.map +1 -1
  21. package/lib/coordinates-label.js +23 -55
  22. package/lib/coordinates-label.js.map +1 -1
  23. package/lib/graph-with-controls.js +129 -203
  24. package/lib/graph-with-controls.js.map +1 -1
  25. package/lib/graph.js +61 -126
  26. package/lib/graph.js.map +1 -1
  27. package/lib/grid-setup.js +168 -224
  28. package/lib/grid-setup.js.map +1 -1
  29. package/lib/grid.js +29 -74
  30. package/lib/grid.js.map +1 -1
  31. package/lib/index.js +1 -12
  32. package/lib/index.js.map +1 -1
  33. package/lib/labels.js +84 -184
  34. package/lib/labels.js.map +1 -1
  35. package/lib/mark-label.js +39 -88
  36. package/lib/mark-label.js.map +1 -1
  37. package/lib/toggle-bar.js +155 -243
  38. package/lib/toggle-bar.js.map +1 -1
  39. package/lib/tool-menu.js +93 -200
  40. package/lib/tool-menu.js.map +1 -1
  41. package/lib/tools/index.js +2 -7
  42. package/lib/tools/index.js.map +1 -1
  43. package/lib/tools/line/component.js +48 -62
  44. package/lib/tools/line/component.js.map +1 -1
  45. package/lib/tools/line/index.js +1 -6
  46. package/lib/tools/line/index.js.map +1 -1
  47. package/lib/tools/polygon/component.js +76 -173
  48. package/lib/tools/polygon/component.js.map +1 -1
  49. package/lib/tools/polygon/index.js +6 -23
  50. package/lib/tools/polygon/index.js.map +1 -1
  51. package/lib/tools/polygon/line.js +48 -85
  52. package/lib/tools/polygon/line.js.map +1 -1
  53. package/lib/tools/polygon/polygon.js +62 -102
  54. package/lib/tools/polygon/polygon.js.map +1 -1
  55. package/lib/tools/shared/arrow-head.js +7 -20
  56. package/lib/tools/shared/arrow-head.js.map +1 -1
  57. package/lib/tools/shared/line/index.js +89 -185
  58. package/lib/tools/shared/line/index.js.map +1 -1
  59. package/lib/tools/shared/line/line-path.js +71 -95
  60. package/lib/tools/shared/line/line-path.js.map +1 -1
  61. package/lib/tools/shared/line/with-root-edge.js +22 -56
  62. package/lib/tools/shared/line/with-root-edge.js.map +1 -1
  63. package/lib/tools/shared/point/arrow-point.js +18 -45
  64. package/lib/tools/shared/point/arrow-point.js.map +1 -1
  65. package/lib/tools/shared/point/arrow.js +16 -42
  66. package/lib/tools/shared/point/arrow.js.map +1 -1
  67. package/lib/tools/shared/point/base-point.js +44 -58
  68. package/lib/tools/shared/point/base-point.js.map +1 -1
  69. package/lib/tools/shared/point/index.js +38 -52
  70. package/lib/tools/shared/point/index.js.map +1 -1
  71. package/lib/tools/shared/styles.js +8 -31
  72. package/lib/tools/shared/styles.js.map +1 -1
  73. package/lib/tools/shared/types.js +1 -5
  74. package/lib/tools/shared/types.js.map +1 -1
  75. package/lib/undo-redo.js +27 -67
  76. package/lib/undo-redo.js.map +1 -1
  77. package/lib/use-debounce.js +4 -11
  78. package/lib/use-debounce.js.map +1 -1
  79. package/lib/utils.js +56 -131
  80. package/lib/utils.js.map +1 -1
  81. package/package.json +34 -23
  82. package/src/__tests__/graph-with-controls.test.jsx +23 -10
  83. package/src/__tests__/graph.test.jsx +36 -171
  84. package/src/__tests__/grid.test.jsx +9 -6
  85. package/src/__tests__/labels.test.jsx +11 -8
  86. package/src/__tests__/mark-label.test.jsx +15 -17
  87. package/src/__tests__/toggle-bar.test.jsx +46 -17
  88. package/src/__tests__/tool-menu.test.jsx +12 -8
  89. package/src/__tests__/undo-redo.test.jsx +9 -8
  90. package/src/__tests__/utils.js +3 -0
  91. package/src/axis/__tests__/arrow.test.jsx +21 -17
  92. package/src/axis/__tests__/axes.test.jsx +117 -155
  93. package/src/axis/arrow.jsx +7 -12
  94. package/src/axis/axes.jsx +41 -51
  95. package/src/coordinates-label.jsx +13 -18
  96. package/src/graph-with-controls.jsx +90 -93
  97. package/src/grid-setup.jsx +210 -206
  98. package/src/grid.jsx +2 -4
  99. package/src/labels.jsx +83 -124
  100. package/src/mark-label.jsx +14 -25
  101. package/src/toggle-bar.jsx +135 -163
  102. package/src/tool-menu.jsx +136 -195
  103. package/src/tools/line/__tests__/component.test.jsx +7 -7
  104. package/src/tools/line/component.jsx +29 -29
  105. package/src/tools/polygon/__tests__/component.test.jsx +13 -152
  106. package/src/tools/polygon/__tests__/line.test.jsx +7 -9
  107. package/src/tools/polygon/__tests__/polygon.test.jsx +8 -8
  108. package/src/tools/polygon/component.jsx +2 -4
  109. package/src/tools/polygon/line.jsx +26 -24
  110. package/src/tools/polygon/polygon.jsx +35 -40
  111. package/src/tools/shared/__tests__/arrow-head.test.jsx +16 -17
  112. package/src/tools/shared/line/__tests__/index.test.jsx +26 -163
  113. package/src/tools/shared/line/__tests__/line-path.test.jsx +9 -9
  114. package/src/tools/shared/line/__tests__/with-root-edge.test.jsx +14 -24
  115. package/src/tools/shared/line/index.jsx +3 -3
  116. package/src/tools/shared/line/line-path.jsx +51 -48
  117. package/src/tools/shared/line/with-root-edge.jsx +1 -1
  118. package/src/tools/shared/point/__tests__/arrow-point.test.jsx +15 -11
  119. package/src/tools/shared/point/__tests__/base-point.test.jsx +14 -11
  120. package/src/tools/shared/point/base-point.jsx +33 -6
  121. package/src/tools/shared/point/index.jsx +30 -32
  122. package/src/undo-redo.jsx +16 -24
  123. package/src/__tests__/__snapshots__/graph-with-controls.test.jsx.snap +0 -114
  124. package/src/__tests__/__snapshots__/graph.test.jsx.snap +0 -213
  125. package/src/__tests__/__snapshots__/grid.test.jsx.snap +0 -54
  126. package/src/__tests__/__snapshots__/labels.test.jsx.snap +0 -30
  127. package/src/__tests__/__snapshots__/mark-label.test.jsx.snap +0 -37
  128. package/src/__tests__/__snapshots__/toggle-bar.test.jsx.snap +0 -7
  129. package/src/__tests__/__snapshots__/tool-menu.test.jsx.snap +0 -35
  130. package/src/__tests__/__snapshots__/undo-redo.test.jsx.snap +0 -15
  131. package/src/axis/__tests__/__snapshots__/arrow.test.jsx.snap +0 -33
  132. package/src/axis/__tests__/__snapshots__/axes.test.jsx.snap +0 -122
  133. package/src/tools/line/__tests__/__snapshots__/component.test.jsx.snap +0 -20
  134. package/src/tools/polygon/__tests__/__snapshots__/component.test.jsx.snap +0 -94
  135. package/src/tools/polygon/__tests__/__snapshots__/line.test.jsx.snap +0 -44
  136. package/src/tools/polygon/__tests__/__snapshots__/polygon.test.jsx.snap +0 -53
  137. package/src/tools/shared/__tests__/__snapshots__/arrow-head.test.jsx.snap +0 -32
  138. package/src/tools/shared/line/__tests__/__snapshots__/index.test.jsx.snap +0 -360
  139. package/src/tools/shared/line/__tests__/__snapshots__/line-path.test.jsx.snap +0 -57
  140. package/src/tools/shared/line/__tests__/__snapshots__/with-root-edge.test.jsx.snap +0 -63
  141. package/src/tools/shared/point/__tests__/__snapshots__/arrow-point.test.jsx.snap +0 -55
  142. package/src/tools/shared/point/__tests__/__snapshots__/base-point.test.jsx.snap +0 -43
package/src/labels.jsx CHANGED
@@ -1,6 +1,6 @@
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
5
  import { color, Readable } from '@pie-lib/render-ui';
6
6
  import EditableHtml from '@pie-lib/editable-html';
@@ -16,24 +16,15 @@ const rotations = {
16
16
  export const getTransform = (side, width, height) => {
17
17
  const t = (x, y, rotate) => `translate(${x}, ${y}), rotate(${rotate})`;
18
18
 
19
- if (side === 'left') {
20
- return t(-20, height / 2, rotations[side]);
21
- }
22
- if (side === 'right') {
23
- return t(width + 30, height / 2, rotations[side]);
24
- }
25
- if (side === 'top') {
26
- return t(width / 2, -20, rotations[side]);
27
- }
28
- if (side === 'bottom') {
29
- return t(width / 2, height + 30, rotations[side]);
30
- }
19
+ if (side === 'left') return t(-20, height / 2, rotations[side]);
20
+ if (side === 'right') return t(width + 30, height / 2, rotations[side]);
21
+ if (side === 'top') return t(width / 2, -20, rotations[side]);
22
+ if (side === 'bottom') return t(width / 2, height + 30, rotations[side]);
31
23
  };
32
24
 
33
25
  const getY = (side, height) => {
34
26
  switch (side) {
35
27
  case 'left':
36
- return -height;
37
28
  case 'top':
38
29
  return -height;
39
30
  case 'right':
@@ -43,15 +34,40 @@ const getY = (side, height) => {
43
34
  }
44
35
  };
45
36
 
37
+ const PREFIX = 'Label';
38
+ const classes = {
39
+ label: `${PREFIX}-label`,
40
+ axisLabel: `${PREFIX}-axisLabel`,
41
+ disabledAxisLabel: `${PREFIX}-disabledAxisLabel`,
42
+ bottomLabel: `${PREFIX}-bottomLabel`,
43
+ };
44
+
45
+ const Root = styled('div')(({ theme }) => ({
46
+ [`& .${classes.label}`]: {
47
+ fill: color.defaults.SECONDARY,
48
+ },
49
+ [`& .${classes.axisLabel}`]: {
50
+ fontSize: theme.typography.fontSize - 2,
51
+ textAlign: 'center',
52
+ padding: '0 4px',
53
+ },
54
+ [`& .${classes.disabledAxisLabel}`]: {
55
+ pointerEvents: 'none',
56
+ },
57
+ [`& .${classes.bottomLabel}`]: {
58
+ marginTop: '44px',
59
+ },
60
+ }));
61
+
46
62
  class RawLabel extends React.Component {
47
63
  static propTypes = {
48
64
  text: PropTypes.string,
49
65
  side: PropTypes.string,
50
- classes: PropTypes.object,
51
66
  disabledLabel: PropTypes.bool,
52
67
  placeholder: PropTypes.string,
53
68
  graphProps: types.GraphPropsType.isRequired,
54
69
  onChange: PropTypes.func,
70
+ mathMlOptions: PropTypes.object,
55
71
  };
56
72
 
57
73
  static defaultProps = {
@@ -59,7 +75,7 @@ class RawLabel extends React.Component {
59
75
  };
60
76
 
61
77
  render() {
62
- const { disabledLabel, placeholder, text, side, graphProps, classes, onChange, mathMlOptions = {} } = this.props;
78
+ const { disabledLabel, placeholder, text, side, graphProps, onChange, mathMlOptions = {} } = this.props;
63
79
  const { size, domain, range } = graphProps;
64
80
  const totalHeight = (size.height || 500) + (range.padding || 0) * 2;
65
81
  const totalWidth = (size.width || 500) + (domain.padding || 0) * 2;
@@ -70,67 +86,45 @@ class RawLabel extends React.Component {
70
86
  const y = getY(side, height);
71
87
  const finalHeight = side === 'bottom' ? height + 22 : height + 18;
72
88
 
73
- const activePlugins = [
74
- 'bold',
75
- 'italic',
76
- 'underline',
77
- 'strikethrough',
78
- 'math',
79
- // 'languageCharacters'
80
- ];
89
+ const activePlugins = ['bold', 'italic', 'underline', 'strikethrough', 'math'];
81
90
 
82
91
  return (
83
- <foreignObject
84
- x={-(width / 2)}
85
- y={y}
86
- width={width}
87
- height={finalHeight}
88
- transform={transform}
89
- textAnchor="middle"
90
- >
91
- <Readable false>
92
- <EditableHtml
93
- className={cn(
94
- {
95
- [classes.bottomLabel]: side === 'bottom',
96
- [classes.disabledAxisLabel]: disabledLabel,
97
- },
98
- classes.axisLabel,
99
- )}
100
- markup={text || ''}
101
- onChange={onChange}
102
- placeholder={!disabledLabel && placeholder}
103
- toolbarOpts={{
104
- position: side === 'bottom' ? 'top' : 'bottom',
105
- noPadding: true,
106
- noBorder: true,
107
- }}
108
- activePlugins={activePlugins}
109
- mathMlOptions={mathMlOptions}
110
- />
111
- </Readable>
112
- </foreignObject>
92
+ <Root>
93
+ <foreignObject
94
+ x={-(width / 2)}
95
+ y={y}
96
+ width={width}
97
+ height={finalHeight}
98
+ transform={transform}
99
+ textAnchor="middle"
100
+ >
101
+ <Readable>
102
+ <EditableHtml
103
+ className={cn(
104
+ {
105
+ [classes.bottomLabel]: side === 'bottom',
106
+ [classes.disabledAxisLabel]: disabledLabel,
107
+ },
108
+ classes.axisLabel,
109
+ )}
110
+ markup={text || ''}
111
+ onChange={onChange}
112
+ placeholder={!disabledLabel && placeholder}
113
+ toolbarOpts={{
114
+ position: side === 'bottom' ? 'top' : 'bottom',
115
+ noPadding: true,
116
+ noBorder: true,
117
+ }}
118
+ activePlugins={activePlugins}
119
+ mathMlOptions={mathMlOptions}
120
+ />
121
+ </Readable>
122
+ </foreignObject>
123
+ </Root>
113
124
  );
114
125
  }
115
126
  }
116
127
 
117
- const Label = withStyles((theme) => ({
118
- label: {
119
- fill: color.defaults.SECONDARY,
120
- },
121
- axisLabel: {
122
- fontSize: theme.typography.fontSize - 2,
123
- textAlign: 'center',
124
- padding: '0 4px',
125
- },
126
- disabledAxisLabel: {
127
- pointerEvents: 'none',
128
- },
129
- bottomLabel: {
130
- marginTop: '44px',
131
- },
132
- }))(RawLabel);
133
-
134
128
  export const LabelType = {
135
129
  left: PropTypes.string,
136
130
  top: PropTypes.string,
@@ -140,24 +134,17 @@ export const LabelType = {
140
134
 
141
135
  export class Labels extends React.Component {
142
136
  static propTypes = {
143
- classes: PropTypes.object,
144
- className: PropTypes.string,
145
137
  disabledLabels: PropTypes.bool,
146
138
  placeholders: PropTypes.object,
147
139
  value: PropTypes.shape(LabelType),
148
140
  graphProps: PropTypes.object,
149
- onChange: PropTypes.object,
141
+ onChange: PropTypes.func,
142
+ mathMlOptions: PropTypes.object,
150
143
  };
151
144
 
152
- static defaultProps = {};
153
-
154
145
  onChangeLabel = (newValue, side) => {
155
146
  const { value, onChange } = this.props;
156
- const labels = {
157
- ...value,
158
- [side]: newValue,
159
- };
160
-
147
+ const labels = { ...value, [side]: newValue };
161
148
  onChange(labels);
162
149
  };
163
150
 
@@ -165,50 +152,22 @@ export class Labels extends React.Component {
165
152
  const { disabledLabels, placeholders = {}, value = {}, graphProps, mathMlOptions = {} } = this.props;
166
153
 
167
154
  return (
168
- <React.Fragment>
169
- <Label
170
- key="left"
171
- side="left"
172
- text={value.left}
173
- disabledLabel={disabledLabels}
174
- placeholder={placeholders.left}
175
- graphProps={graphProps}
176
- onChange={(value) => this.onChangeLabel(value, 'left')}
177
- mathMlOptions={mathMlOptions}
178
- />
179
- <Label
180
- key="top"
181
- side="top"
182
- text={value.top}
183
- disabledLabel={disabledLabels}
184
- placeholder={placeholders.top}
185
- graphProps={graphProps}
186
- onChange={(value) => this.onChangeLabel(value, 'top')}
187
- mathMlOptions={mathMlOptions}
188
- />
189
- <Label
190
- key="bottom"
191
- side="bottom"
192
- text={value.bottom}
193
- disabledLabel={disabledLabels}
194
- placeholder={placeholders.bottom}
195
- graphProps={graphProps}
196
- onChange={(value) => this.onChangeLabel(value, 'bottom')}
197
- mathMlOptions={mathMlOptions}
198
- />
199
- <Label
200
- key="right"
201
- side="right"
202
- text={value.right}
203
- disabledLabel={disabledLabels}
204
- placeholder={placeholders.right}
205
- graphProps={graphProps}
206
- onChange={(value) => this.onChangeLabel(value, 'right')}
207
- mathMlOptions={mathMlOptions}
208
- />
209
- </React.Fragment>
155
+ <>
156
+ {['left', 'top', 'bottom', 'right'].map((side) => (
157
+ <RawLabel
158
+ key={side}
159
+ side={side}
160
+ text={value[side]}
161
+ disabledLabel={disabledLabels}
162
+ placeholder={placeholders[side]}
163
+ graphProps={graphProps}
164
+ onChange={(val) => this.onChangeLabel(val, side)}
165
+ mathMlOptions={mathMlOptions}
166
+ />
167
+ ))}
168
+ </>
210
169
  );
211
170
  }
212
171
  }
213
172
 
214
- export default Labels;
173
+ export default RawLabel;
@@ -1,32 +1,25 @@
1
1
  import React, { useState, useCallback, useEffect } from 'react';
2
- import cn from 'classnames';
3
2
  import PropTypes from 'prop-types';
4
- import { withStyles } from '@material-ui/core/styles';
3
+ import { styled } from '@mui/material/styles';
5
4
  import AutosizeInput from 'react-input-autosize';
6
5
  import { useDebounce } from './use-debounce';
7
6
  import { types } from '@pie-lib/plot';
8
7
  import { color } from '@pie-lib/render-ui';
9
8
 
10
- const styles = (theme) => ({
11
- input: {
9
+ const StyledAutosizeInput = styled(AutosizeInput, {
10
+ shouldForwardProp: (prop) => !['disabled', 'markDisabled'].includes(prop),
11
+ })(({ theme, disabled, markDisabled }) => ({
12
+ '& input': {
12
13
  float: 'right',
13
- padding: theme.spacing.unit * 0.5,
14
+ padding: theme.spacing(0.5),
14
15
  fontFamily: theme.typography.fontFamily,
15
16
  fontSize: theme.typography.fontSize,
16
- border: `solid 1px ${color.defaults.SECONDARY}`,
17
+ border: `solid 1px ${disabled ? color.defaults.PRIMARY_DARK : markDisabled ? color.disabled() : color.defaults.SECONDARY}`,
17
18
  borderRadius: '3px',
18
- color: color.defaults.PRIMARY_DARK,
19
+ color: markDisabled ? color.disabled() : color.defaults.PRIMARY_DARK,
20
+ background: (disabled || markDisabled) ? theme.palette.background.paper : 'transparent',
19
21
  },
20
- disabled: {
21
- border: `solid 1px ${color.defaults.PRIMARY_DARK}`,
22
- background: theme.palette.background.paper,
23
- },
24
- disabledMark: {
25
- border: `solid 1px ${color.disabled()}`,
26
- background: theme.palette.background.paper,
27
- color: color.disabled(),
28
- },
29
- });
22
+ }));
30
23
 
31
24
  export const position = (graphProps, mark, rect) => {
32
25
  rect = rect || { width: 0, height: 0 };
@@ -73,7 +66,7 @@ export const MarkLabel = (props) => {
73
66
  const [input, setInput] = useState(null);
74
67
  const _ref = useCallback((node) => setInput(node));
75
68
 
76
- const { mark, graphProps, classes, disabled, inputRef: externalInputRef, theme } = props;
69
+ const { mark, graphProps, disabled, inputRef: externalInputRef } = props;
77
70
 
78
71
  const [label, setLabel] = useState(mark.label);
79
72
 
@@ -106,16 +99,13 @@ export const MarkLabel = (props) => {
106
99
  const disabledInput = disabled || mark.disabled;
107
100
 
108
101
  return (
109
- <AutosizeInput
102
+ <StyledAutosizeInput
110
103
  inputRef={(r) => {
111
104
  _ref(r);
112
105
  externalInputRef(r);
113
106
  }}
114
107
  disabled={disabledInput}
115
- inputClassName={cn(classes.input, {
116
- [classes.disabled]: disabled,
117
- [classes.disabledMark]: mark.disabled,
118
- })}
108
+ markDisabled={mark.disabled}
119
109
  value={label}
120
110
  style={style}
121
111
  onChange={onChange}
@@ -127,10 +117,9 @@ MarkLabel.propTypes = {
127
117
  disabled: PropTypes.bool,
128
118
  onChange: PropTypes.func,
129
119
  graphProps: types.GraphPropsType,
130
- classes: PropTypes.object,
131
120
  inputRef: PropTypes.func,
132
121
  mark: PropTypes.object,
133
122
  theme: PropTypes.object,
134
123
  };
135
124
 
136
- export default withStyles(styles, { withTheme: true })(MarkLabel);
125
+ export default MarkLabel;