@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
@@ -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;