@pie-lib/graphing-solution-set 2.34.3-next.2 → 2.34.3-next.203

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 (145) hide show
  1. package/CHANGELOG.md +15 -67
  2. package/lib/axis/arrow.js +19 -55
  3. package/lib/axis/arrow.js.map +1 -1
  4. package/lib/axis/axes.js +103 -193
  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 -60
  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 +129 -203
  23. package/lib/graph-with-controls.js.map +1 -1
  24. package/lib/graph.js +61 -126
  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 -12
  31. package/lib/index.js.map +1 -1
  32. package/lib/labels.js +85 -185
  33. package/lib/labels.js.map +1 -1
  34. package/lib/mark-label.js +39 -88
  35. package/lib/mark-label.js.map +1 -1
  36. package/lib/toggle-bar.js +155 -243
  37. package/lib/toggle-bar.js.map +1 -1
  38. package/lib/tool-menu.js +93 -200
  39. package/lib/tool-menu.js.map +1 -1
  40. package/lib/tools/index.js +2 -7
  41. package/lib/tools/index.js.map +1 -1
  42. package/lib/tools/line/component.js +48 -62
  43. package/lib/tools/line/component.js.map +1 -1
  44. package/lib/tools/line/index.js +1 -6
  45. package/lib/tools/line/index.js.map +1 -1
  46. package/lib/tools/polygon/component.js +76 -173
  47. package/lib/tools/polygon/component.js.map +1 -1
  48. package/lib/tools/polygon/index.js +6 -23
  49. package/lib/tools/polygon/index.js.map +1 -1
  50. package/lib/tools/polygon/line.js +48 -85
  51. package/lib/tools/polygon/line.js.map +1 -1
  52. package/lib/tools/polygon/polygon.js +62 -102
  53. package/lib/tools/polygon/polygon.js.map +1 -1
  54. package/lib/tools/shared/arrow-head.js +7 -20
  55. package/lib/tools/shared/arrow-head.js.map +1 -1
  56. package/lib/tools/shared/line/index.js +89 -185
  57. package/lib/tools/shared/line/index.js.map +1 -1
  58. package/lib/tools/shared/line/line-path.js +71 -95
  59. package/lib/tools/shared/line/line-path.js.map +1 -1
  60. package/lib/tools/shared/line/with-root-edge.js +22 -56
  61. package/lib/tools/shared/line/with-root-edge.js.map +1 -1
  62. package/lib/tools/shared/point/arrow-point.js +18 -45
  63. package/lib/tools/shared/point/arrow-point.js.map +1 -1
  64. package/lib/tools/shared/point/arrow.js +16 -42
  65. package/lib/tools/shared/point/arrow.js.map +1 -1
  66. package/lib/tools/shared/point/base-point.js +44 -58
  67. package/lib/tools/shared/point/base-point.js.map +1 -1
  68. package/lib/tools/shared/point/index.js +38 -52
  69. package/lib/tools/shared/point/index.js.map +1 -1
  70. package/lib/tools/shared/styles.js +8 -31
  71. package/lib/tools/shared/styles.js.map +1 -1
  72. package/lib/tools/shared/types.js +1 -5
  73. package/lib/tools/shared/types.js.map +1 -1
  74. package/lib/undo-redo.js +27 -67
  75. package/lib/undo-redo.js.map +1 -1
  76. package/lib/use-debounce.js +4 -11
  77. package/lib/use-debounce.js.map +1 -1
  78. package/lib/utils.js +56 -131
  79. package/lib/utils.js.map +1 -1
  80. package/package.json +26 -31
  81. package/src/__tests__/graph-with-controls.test.jsx +23 -10
  82. package/src/__tests__/graph.test.jsx +36 -171
  83. package/src/__tests__/grid.test.jsx +9 -6
  84. package/src/__tests__/labels.test.jsx +11 -8
  85. package/src/__tests__/mark-label.test.jsx +15 -17
  86. package/src/__tests__/toggle-bar.test.jsx +46 -17
  87. package/src/__tests__/tool-menu.test.jsx +12 -8
  88. package/src/__tests__/undo-redo.test.jsx +9 -8
  89. package/src/__tests__/utils.js +3 -0
  90. package/src/axis/__tests__/arrow.test.jsx +21 -17
  91. package/src/axis/__tests__/axes.test.jsx +117 -155
  92. package/src/axis/arrow.jsx +7 -12
  93. package/src/axis/axes.jsx +41 -51
  94. package/src/coordinates-label.jsx +13 -18
  95. package/src/graph-with-controls.jsx +90 -93
  96. package/src/grid-setup.jsx +203 -205
  97. package/src/grid.jsx +2 -4
  98. package/src/labels.jsx +84 -125
  99. package/src/mark-label.jsx +14 -25
  100. package/src/toggle-bar.jsx +135 -163
  101. package/src/tool-menu.jsx +136 -195
  102. package/src/tools/line/__tests__/component.test.jsx +7 -7
  103. package/src/tools/line/component.jsx +29 -29
  104. package/src/tools/polygon/__tests__/component.test.jsx +13 -152
  105. package/src/tools/polygon/__tests__/line.test.jsx +7 -9
  106. package/src/tools/polygon/__tests__/polygon.test.jsx +8 -8
  107. package/src/tools/polygon/component.jsx +2 -4
  108. package/src/tools/polygon/line.jsx +26 -24
  109. package/src/tools/polygon/polygon.jsx +35 -40
  110. package/src/tools/shared/__tests__/arrow-head.test.jsx +16 -17
  111. package/src/tools/shared/line/__tests__/index.test.jsx +26 -163
  112. package/src/tools/shared/line/__tests__/line-path.test.jsx +9 -9
  113. package/src/tools/shared/line/__tests__/with-root-edge.test.jsx +14 -24
  114. package/src/tools/shared/line/index.jsx +3 -3
  115. package/src/tools/shared/line/line-path.jsx +51 -48
  116. package/src/tools/shared/line/with-root-edge.jsx +1 -1
  117. package/src/tools/shared/point/__tests__/arrow-point.test.jsx +15 -11
  118. package/src/tools/shared/point/__tests__/base-point.test.jsx +14 -11
  119. package/src/tools/shared/point/base-point.jsx +33 -6
  120. package/src/tools/shared/point/index.jsx +30 -32
  121. package/src/undo-redo.jsx +16 -24
  122. package/esm/index.css +0 -847
  123. package/esm/index.js +0 -233259
  124. package/esm/index.js.map +0 -1
  125. package/esm/package.json +0 -3
  126. package/src/__tests__/__snapshots__/graph-with-controls.test.jsx.snap +0 -114
  127. package/src/__tests__/__snapshots__/graph.test.jsx.snap +0 -213
  128. package/src/__tests__/__snapshots__/grid.test.jsx.snap +0 -54
  129. package/src/__tests__/__snapshots__/labels.test.jsx.snap +0 -30
  130. package/src/__tests__/__snapshots__/mark-label.test.jsx.snap +0 -37
  131. package/src/__tests__/__snapshots__/toggle-bar.test.jsx.snap +0 -7
  132. package/src/__tests__/__snapshots__/tool-menu.test.jsx.snap +0 -35
  133. package/src/__tests__/__snapshots__/undo-redo.test.jsx.snap +0 -15
  134. package/src/axis/__tests__/__snapshots__/arrow.test.jsx.snap +0 -33
  135. package/src/axis/__tests__/__snapshots__/axes.test.jsx.snap +0 -122
  136. package/src/tools/line/__tests__/__snapshots__/component.test.jsx.snap +0 -20
  137. package/src/tools/polygon/__tests__/__snapshots__/component.test.jsx.snap +0 -94
  138. package/src/tools/polygon/__tests__/__snapshots__/line.test.jsx.snap +0 -44
  139. package/src/tools/polygon/__tests__/__snapshots__/polygon.test.jsx.snap +0 -53
  140. package/src/tools/shared/__tests__/__snapshots__/arrow-head.test.jsx.snap +0 -32
  141. package/src/tools/shared/line/__tests__/__snapshots__/index.test.jsx.snap +0 -360
  142. package/src/tools/shared/line/__tests__/__snapshots__/line-path.test.jsx.snap +0 -57
  143. package/src/tools/shared/line/__tests__/__snapshots__/with-root-edge.test.jsx.snap +0 -63
  144. package/src/tools/shared/point/__tests__/__snapshots__/arrow-point.test.jsx.snap +0 -55
  145. package/src/tools/shared/point/__tests__/__snapshots__/base-point.test.jsx.snap +0 -43
@@ -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 classNames from 'classnames';
5
5
  import uniq from 'lodash/uniq';
6
6
  import isString from 'lodash/isString';
@@ -9,11 +9,19 @@ import ToolMenu from './tool-menu';
9
9
  import Graph, { graphPropTypes } from './graph';
10
10
  import UndoRedo from './undo-redo';
11
11
  import { allTools, toolsArr } from './tools';
12
- import { ExpansionPanel, ExpansionPanelDetails, ExpansionPanelSummary, Typography } from '@material-ui/core';
13
- import ExpandMoreIcon from '@material-ui/icons/ExpandMore';
12
+ import {
13
+ Accordion,
14
+ AccordionDetails,
15
+ AccordionSummary,
16
+ Typography,
17
+ } from '@mui/material';
18
+ import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
14
19
 
15
20
  export const setToolbarAvailability = (toolbarTools) =>
16
- toolsArr.map((tA) => ({ ...tA, toolbar: !!toolbarTools.find((t) => t === tA.type) })) || [];
21
+ toolsArr.map((tA) => ({
22
+ ...tA,
23
+ toolbar: !!toolbarTools.find((t) => t === tA.type),
24
+ })) || [];
17
25
 
18
26
  export const toolIsAvailable = (tools, currentTool) =>
19
27
  currentTool && tools && (tools.find((tool) => tool.type === currentTool.type) || {}).toolbar;
@@ -26,26 +34,66 @@ export const filterByValidToolTypes = (backgroundMarks) =>
26
34
  export const filterByVisibleToolTypes = (toolbarTools, marks) =>
27
35
  marks.filter((bM) => !!toolbarTools.find((tool) => tool === bM.type));
28
36
 
29
- const getDefaultCurrentTool = (toolType) => toolsArr.find((tool) => tool.type === toolType) || null;
37
+ const getDefaultCurrentTool = (toolType) =>
38
+ toolsArr.find((tool) => tool.type === toolType) || null;
30
39
 
31
- const Collapsible = ({ classes, children, title }) => (
32
- <ExpansionPanel elevation={0} className={classes.expansionPanel} disabledGutters={true} square={true}>
33
- <ExpansionPanelSummary
34
- classes={{
35
- root: classes.summaryRoot,
36
- content: classes.summaryContent,
37
- }}
38
- expandIcon={<ExpandMoreIcon />}
39
- >
40
- <Typography variant="subheading">{title}</Typography>
41
- </ExpansionPanelSummary>
42
- <ExpansionPanelDetails className={classes.details}>{children}</ExpansionPanelDetails>
43
- </ExpansionPanel>
40
+ const GraphWithControlsRoot = styled('div')(() => ({
41
+ display: 'flex',
42
+ flexDirection: 'column',
43
+ width: 'min-content',
44
+ }));
45
+
46
+ const Controls = styled('div')(() => ({
47
+ display: 'flex',
48
+ justifyContent: 'space-between',
49
+ padding: 'calc(1.25rem - 12px) calc(1.25rem - 12px) 1.25rem',
50
+ color: color.text(),
51
+ backgroundColor: '#9FA8DA',
52
+ '& button': {
53
+ fontSize: '0.875rem',
54
+ padding: '0.25rem .3rem',
55
+ width: '5rem',
56
+ },
57
+ }));
58
+
59
+ const StyledAccordion = styled(Accordion)(() => ({
60
+ backgroundColor: color.primaryLight(),
61
+ width: '100%',
62
+ boxShadow: 'none',
63
+ }));
64
+
65
+ const StyledAccordionSummary = styled(AccordionSummary)(({ theme }) => ({
66
+ padding: `0 ${theme.spacing(1)}`,
67
+ minHeight: '32px !important',
68
+ '& .MuiAccordionSummary-content': {
69
+ margin: '4px 0 !important',
70
+ },
71
+ }));
72
+
73
+ const StyledAccordionDetails = styled(AccordionDetails)(({ theme }) => ({
74
+ padding: 0,
75
+ marginTop: theme.spacing(1),
76
+ display: 'flex',
77
+ justifyContent: 'space-between',
78
+ }));
79
+
80
+ const UndoRedoOuterDiv = styled('div')(() => ({
81
+ display: 'flex',
82
+ flexDirection: 'column',
83
+ marginTop: '.5rem',
84
+ }));
85
+
86
+ const Collapsible = ({ children, title }) => (
87
+ <StyledAccordion square disableGutters>
88
+ <StyledAccordionSummary expandIcon={<ExpandMoreIcon />}>
89
+ <Typography variant="subtitle1">{title}</Typography>
90
+ </StyledAccordionSummary>
91
+ <StyledAccordionDetails>{children}</StyledAccordionDetails>
92
+ </StyledAccordion>
44
93
  );
45
94
 
46
95
  Collapsible.propTypes = {
47
- classes: PropTypes.object,
48
- children: PropTypes.array,
96
+ children: PropTypes.node,
49
97
  title: PropTypes.string,
50
98
  };
51
99
 
@@ -55,7 +103,7 @@ export class GraphWithControls extends React.Component {
55
103
  onUndo: PropTypes.func,
56
104
  onRedo: PropTypes.func,
57
105
  onReset: PropTypes.func,
58
- toolbarTools: PropTypes.arrayOf(PropTypes.string), // array of tool types that have to be displayed in the toolbar, same shape as 'allTools'
106
+ toolbarTools: PropTypes.arrayOf(PropTypes.string),
59
107
  language: PropTypes.string,
60
108
  };
61
109
 
@@ -71,7 +119,6 @@ export class GraphWithControls extends React.Component {
71
119
 
72
120
  constructor(props) {
73
121
  super(props);
74
-
75
122
  this.state = {
76
123
  currentTool: getDefaultCurrentTool(props.defaultTool),
77
124
  labelModeEnabled: false,
@@ -80,23 +127,22 @@ export class GraphWithControls extends React.Component {
80
127
 
81
128
  componentDidUpdate(prevProps) {
82
129
  const { defaultTool } = this.props;
83
-
84
130
  if (prevProps.defaultTool !== defaultTool) {
85
131
  const currentTool = getDefaultCurrentTool(defaultTool);
86
-
87
132
  this.setState({ currentTool });
88
133
  }
89
134
  }
90
135
 
91
- changeCurrentTool = (tool, tools) => this.setState({ currentTool: tools.find((t) => t.type === tool) });
136
+ changeCurrentTool = (tool, tools) =>
137
+ this.setState({ currentTool: tools.find((t) => t.type === tool) });
92
138
 
93
- toggleLabelMode = () => this.setState((state) => ({ labelModeEnabled: !state.labelModeEnabled }));
139
+ toggleLabelMode = () =>
140
+ this.setState((state) => ({ labelModeEnabled: !state.labelModeEnabled }));
94
141
 
95
142
  render() {
96
143
  let { currentTool, labelModeEnabled } = this.state;
97
144
  const {
98
145
  axesSettings,
99
- classes,
100
146
  className,
101
147
  coordinatesOnHover,
102
148
  collapsibleToolbar,
@@ -126,15 +172,11 @@ export class GraphWithControls extends React.Component {
126
172
  onSolutionSetSelected,
127
173
  onCustomReset,
128
174
  } = this.props;
175
+
129
176
  let { backgroundMarks, marks, toolbarTools } = this.props;
130
177
 
131
- // make sure only valid tool types are kept (string) and without duplicates
132
178
  toolbarTools = uniq(toolbarTools || []).filter((tT) => !!isString(tT)) || [];
133
-
134
- // keep only the backgroundMarks that have valid types
135
179
  backgroundMarks = filterByValidToolTypes(backgroundMarks || []);
136
-
137
- // keep only the marks that have types which appear in toolbar
138
180
  marks = filterByVisibleToolTypes(toolbarTools, marks || []);
139
181
 
140
182
  if (gssLineData && gssLineData.lineA && marks[0] && marks[0].type === 'line')
@@ -143,14 +185,12 @@ export class GraphWithControls extends React.Component {
143
185
  marks[1].fill = gssLineData.lineB.lineType;
144
186
 
145
187
  const tools = setToolbarAvailability(toolbarTools);
146
-
147
- // set current tool if there's no current tool or if the existing one is no longer available
148
188
  if (!currentTool || !toolIsAvailable(tools, currentTool)) {
149
189
  currentTool = getAvailableTool(tools);
150
190
  }
151
191
 
152
192
  const gssActions = gssLineData && (
153
- <React.Fragment>
193
+ <>
154
194
  <ToolMenu
155
195
  numberOfLines={gssLineData.numberOfLines}
156
196
  gssLineData={gssLineData}
@@ -159,29 +199,28 @@ export class GraphWithControls extends React.Component {
159
199
  language={language}
160
200
  />
161
201
  {!disabled && (
162
- <UndoRedo
163
- className={classes.undoRedoOuterDiv}
164
- onUndo={onUndo}
165
- onRedo={onRedo}
166
- onReset={onCustomReset}
167
- language={language}
168
- />
202
+ <UndoRedoOuterDiv>
203
+ <UndoRedo
204
+ onUndo={onUndo}
205
+ onRedo={onRedo}
206
+ onReset={onCustomReset}
207
+ language={language}
208
+ />
209
+ </UndoRedoOuterDiv>
169
210
  )}
170
- </React.Fragment>
211
+ </>
171
212
  );
172
213
 
173
214
  return (
174
- <div className={classNames(classes.graphWithControls, className)}>
215
+ <GraphWithControlsRoot className={classNames(className)}>
175
216
  {!disableToolbar && (
176
- <div className={classes.controls}>
217
+ <Controls>
177
218
  {collapsibleToolbar ? (
178
- <Collapsible classes={classes} title={collapsibleToolbarTitle}>
179
- {gssActions}
180
- </Collapsible>
219
+ <Collapsible title={collapsibleToolbarTitle}>{gssActions}</Collapsible>
181
220
  ) : (
182
221
  gssActions
183
222
  )}
184
- </div>
223
+ </Controls>
185
224
  )}
186
225
 
187
226
  <div ref={(r) => (this.labelNode = r)} />
@@ -213,51 +252,9 @@ export class GraphWithControls extends React.Component {
213
252
  onSolutionSetSelected={onSolutionSetSelected}
214
253
  disabled={!!disabled}
215
254
  />
216
- </div>
255
+ </GraphWithControlsRoot>
217
256
  );
218
257
  }
219
258
  }
220
259
 
221
- const styles = (theme) => ({
222
- graphWithControls: {
223
- display: 'flex',
224
- flexDirection: 'column',
225
- width: 'min-content',
226
- },
227
- controls: {
228
- display: 'flex',
229
- justifyContent: 'space-between',
230
- padding: 'calc(1.25rem - 12px) calc(1.25rem - 12px) 1.25rem',
231
- color: color.text(),
232
- backgroundColor: '#9FA8DA',
233
- '& button': {
234
- fontSize: '0.875rem',
235
- padding: '0.25rem .3rem',
236
- width: '5rem',
237
- },
238
- },
239
- expansionPanel: {
240
- backgroundColor: color.primaryLight(),
241
- width: '100%',
242
- },
243
- summaryRoot: {
244
- padding: `0 ${theme.spacing.unit}px`,
245
- minHeight: '32px !important',
246
- },
247
- summaryContent: {
248
- margin: '4px 0 !important',
249
- },
250
- details: {
251
- padding: 0,
252
- marginTop: theme.spacing.unit,
253
- display: 'flex',
254
- justifyContent: 'space-between',
255
- },
256
- undoRedoOuterDiv: {
257
- display: 'flex',
258
- flexDirection: 'column',
259
- marginTop: '.5rem',
260
- },
261
- });
262
-
263
- export default withStyles(styles)(GraphWithControls);
260
+ export default GraphWithControls;