@pie-lib/graphing-solution-set 2.34.1 → 2.35.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.
- package/CHANGELOG.md +10 -15
- package/lib/axis/arrow.js +19 -55
- package/lib/axis/arrow.js.map +1 -1
- package/lib/axis/axes.js +101 -184
- package/lib/axis/axes.js.map +1 -1
- package/lib/axis/index.js +1 -6
- package/lib/axis/index.js.map +1 -1
- package/lib/bg.js +21 -49
- package/lib/bg.js.map +1 -1
- package/lib/container/actions.js +2 -8
- package/lib/container/actions.js.map +1 -1
- package/lib/container/index.js +14 -60
- package/lib/container/index.js.map +1 -1
- package/lib/container/marks.js +1 -6
- package/lib/container/marks.js.map +1 -1
- package/lib/container/middleware.js +2 -8
- package/lib/container/middleware.js.map +1 -1
- package/lib/container/reducer.js +1 -8
- package/lib/container/reducer.js.map +1 -1
- package/lib/coordinates-label.js +23 -55
- package/lib/coordinates-label.js.map +1 -1
- package/lib/graph-with-controls.js +132 -203
- package/lib/graph-with-controls.js.map +1 -1
- package/lib/graph.js +61 -126
- package/lib/graph.js.map +1 -1
- package/lib/grid-setup.js +161 -223
- package/lib/grid-setup.js.map +1 -1
- package/lib/grid.js +28 -73
- package/lib/grid.js.map +1 -1
- package/lib/index.js +1 -12
- package/lib/index.js.map +1 -1
- package/lib/labels.js +84 -184
- package/lib/labels.js.map +1 -1
- package/lib/mark-label.js +40 -88
- package/lib/mark-label.js.map +1 -1
- package/lib/toggle-bar.js +158 -242
- package/lib/toggle-bar.js.map +1 -1
- package/lib/tool-menu.js +93 -200
- package/lib/tool-menu.js.map +1 -1
- package/lib/tools/index.js +2 -7
- package/lib/tools/index.js.map +1 -1
- package/lib/tools/line/component.js +48 -62
- package/lib/tools/line/component.js.map +1 -1
- package/lib/tools/line/index.js +1 -6
- package/lib/tools/line/index.js.map +1 -1
- package/lib/tools/polygon/component.js +75 -172
- package/lib/tools/polygon/component.js.map +1 -1
- package/lib/tools/polygon/index.js +6 -23
- package/lib/tools/polygon/index.js.map +1 -1
- package/lib/tools/polygon/line.js +48 -85
- package/lib/tools/polygon/line.js.map +1 -1
- package/lib/tools/polygon/polygon.js +64 -102
- package/lib/tools/polygon/polygon.js.map +1 -1
- package/lib/tools/shared/arrow-head.js +7 -20
- package/lib/tools/shared/arrow-head.js.map +1 -1
- package/lib/tools/shared/line/index.js +86 -182
- package/lib/tools/shared/line/index.js.map +1 -1
- package/lib/tools/shared/line/line-path.js +70 -94
- package/lib/tools/shared/line/line-path.js.map +1 -1
- package/lib/tools/shared/line/with-root-edge.js +21 -55
- package/lib/tools/shared/line/with-root-edge.js.map +1 -1
- package/lib/tools/shared/point/arrow-point.js +18 -45
- package/lib/tools/shared/point/arrow-point.js.map +1 -1
- package/lib/tools/shared/point/arrow.js +16 -42
- package/lib/tools/shared/point/arrow.js.map +1 -1
- package/lib/tools/shared/point/base-point.js +22 -52
- package/lib/tools/shared/point/base-point.js.map +1 -1
- package/lib/tools/shared/point/index.js +30 -52
- package/lib/tools/shared/point/index.js.map +1 -1
- package/lib/tools/shared/styles.js +8 -31
- package/lib/tools/shared/styles.js.map +1 -1
- package/lib/tools/shared/types.js +1 -5
- package/lib/tools/shared/types.js.map +1 -1
- package/lib/undo-redo.js +27 -67
- package/lib/undo-redo.js.map +1 -1
- package/lib/use-debounce.js +4 -11
- package/lib/use-debounce.js.map +1 -1
- package/lib/utils.js +56 -131
- package/lib/utils.js.map +1 -1
- package/package.json +16 -14
- package/src/axis/arrow.jsx +7 -12
- package/src/axis/axes.jsx +32 -37
- package/src/coordinates-label.jsx +13 -18
- package/src/graph-with-controls.jsx +90 -93
- package/src/grid-setup.jsx +204 -206
- package/src/grid.jsx +1 -3
- package/src/labels.jsx +83 -124
- package/src/mark-label.jsx +14 -25
- package/src/toggle-bar.jsx +155 -166
- package/src/tool-menu.jsx +136 -195
- package/src/tools/line/component.jsx +29 -29
- package/src/tools/polygon/component.jsx +1 -3
- package/src/tools/polygon/line.jsx +26 -24
- package/src/tools/polygon/polygon.jsx +34 -39
- package/src/tools/shared/line/line-path.jsx +50 -47
- package/src/tools/shared/point/index.jsx +22 -34
- package/src/undo-redo.jsx +16 -24
package/src/axis/axes.jsx
CHANGED
|
@@ -3,7 +3,7 @@ import { Axis } from '@vx/axis';
|
|
|
3
3
|
import { types } from '@pie-lib/plot';
|
|
4
4
|
import PropTypes from 'prop-types';
|
|
5
5
|
import Arrow from './arrow';
|
|
6
|
-
import {
|
|
6
|
+
import { styled } from '@mui/material/styles';
|
|
7
7
|
import { countWords, findLongestWord, amountToIncreaseWidth, getTickValues } from '../utils';
|
|
8
8
|
import { color, Readable } from '@pie-lib/render-ui';
|
|
9
9
|
|
|
@@ -21,33 +21,36 @@ const AxisDefaultProps = {
|
|
|
21
21
|
},
|
|
22
22
|
};
|
|
23
23
|
|
|
24
|
-
const
|
|
25
|
-
line: {
|
|
24
|
+
const StyledAxis = styled(Axis)(({ theme }) => ({
|
|
25
|
+
'& .vx-axis-line': {
|
|
26
26
|
stroke: '#8a92c0',
|
|
27
27
|
strokeWidth: 4,
|
|
28
28
|
},
|
|
29
|
-
|
|
30
|
-
fill: '#8a92c0',
|
|
31
|
-
},
|
|
32
|
-
tick: {
|
|
29
|
+
'& .vx-axis-tick': {
|
|
33
30
|
fill: color.defaults.BLACK,
|
|
34
31
|
'& > line': {
|
|
35
32
|
stroke: '#8a92c0',
|
|
36
33
|
},
|
|
37
34
|
},
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
35
|
+
}));
|
|
36
|
+
|
|
37
|
+
const LabelContainer = styled('div')(({ theme }) => ({
|
|
38
|
+
fontSize: theme.typography.fontSize,
|
|
39
|
+
}));
|
|
40
|
+
|
|
41
|
+
const AxisLabelHolder = styled('div')(({ theme }) => ({
|
|
42
|
+
padding: 0,
|
|
43
|
+
margin: 0,
|
|
44
|
+
textAlign: 'center',
|
|
45
|
+
'* > *': {
|
|
43
46
|
margin: 0,
|
|
44
|
-
|
|
45
|
-
'* > *': {
|
|
46
|
-
margin: 0,
|
|
47
|
-
padding: 0,
|
|
48
|
-
},
|
|
49
|
-
fontSize: theme.typography.fontSize,
|
|
47
|
+
padding: 0,
|
|
50
48
|
},
|
|
49
|
+
fontSize: theme.typography.fontSize,
|
|
50
|
+
}));
|
|
51
|
+
|
|
52
|
+
const StyledArrow = styled(Arrow)({
|
|
53
|
+
fill: '#8a92c0',
|
|
51
54
|
});
|
|
52
55
|
|
|
53
56
|
const tickLabelStyles = {
|
|
@@ -84,7 +87,6 @@ export const firstNegativeValue = (interval) => (interval || []).find((element)
|
|
|
84
87
|
export class RawXAxis extends React.Component {
|
|
85
88
|
static propTypes = {
|
|
86
89
|
...AxisPropTypes,
|
|
87
|
-
classes: PropTypes.object,
|
|
88
90
|
graphProps: types.GraphPropsType.isRequired,
|
|
89
91
|
};
|
|
90
92
|
static defaultProps = AxisDefaultProps;
|
|
@@ -92,7 +94,6 @@ export class RawXAxis extends React.Component {
|
|
|
92
94
|
render() {
|
|
93
95
|
const {
|
|
94
96
|
includeArrows,
|
|
95
|
-
classes,
|
|
96
97
|
graphProps,
|
|
97
98
|
columnTicksValues,
|
|
98
99
|
skipValues,
|
|
@@ -125,27 +126,25 @@ export class RawXAxis extends React.Component {
|
|
|
125
126
|
|
|
126
127
|
return (
|
|
127
128
|
<React.Fragment>
|
|
128
|
-
<
|
|
129
|
-
axisLineClassName={classes.line}
|
|
129
|
+
<StyledAxis
|
|
130
130
|
scale={scale.x}
|
|
131
131
|
top={scale.y(0)}
|
|
132
132
|
left={0}
|
|
133
133
|
label={domain.label}
|
|
134
134
|
rangePadding={8}
|
|
135
|
-
tickClassName={classes.tick}
|
|
136
135
|
tickFormat={(value) => value}
|
|
137
136
|
tickLabelProps={labelProps}
|
|
138
137
|
tickValues={tickValues}
|
|
139
138
|
/>
|
|
140
139
|
{includeArrows && includeArrows.left && (
|
|
141
|
-
<
|
|
140
|
+
<StyledArrow direction="left" x={domain.min} y={0} scale={scale} />
|
|
142
141
|
)}
|
|
143
142
|
{includeArrows && includeArrows.right && (
|
|
144
|
-
<
|
|
143
|
+
<StyledArrow direction="right" x={domain.max} y={0} scale={scale} />
|
|
145
144
|
)}
|
|
146
145
|
{domain.axisLabel && (
|
|
147
146
|
<foreignObject x={size.width + 17} y={scale.y(0) - 9} width={necessaryWidth} height={20 * necessaryRows}>
|
|
148
|
-
<
|
|
147
|
+
<LabelContainer dangerouslySetInnerHTML={{ __html: domain.axisLabel }} />
|
|
149
148
|
</foreignObject>
|
|
150
149
|
)}
|
|
151
150
|
</React.Fragment>
|
|
@@ -153,7 +152,7 @@ export class RawXAxis extends React.Component {
|
|
|
153
152
|
}
|
|
154
153
|
}
|
|
155
154
|
|
|
156
|
-
const XAxis =
|
|
155
|
+
const XAxis = RawXAxis;
|
|
157
156
|
|
|
158
157
|
export class RawYAxis extends React.Component {
|
|
159
158
|
static propTypes = {
|
|
@@ -163,7 +162,7 @@ export class RawYAxis extends React.Component {
|
|
|
163
162
|
static defaultProps = AxisDefaultProps;
|
|
164
163
|
|
|
165
164
|
render() {
|
|
166
|
-
const {
|
|
165
|
+
const { includeArrows, graphProps, skipValues, rowTickValues } = this.props;
|
|
167
166
|
const { scale, range, size } = graphProps || {};
|
|
168
167
|
|
|
169
168
|
const necessaryWidth = range.axisLabel ? amountToIncreaseWidth(range.axisLabel.length) : 0;
|
|
@@ -172,8 +171,7 @@ export class RawYAxis extends React.Component {
|
|
|
172
171
|
|
|
173
172
|
return (
|
|
174
173
|
<React.Fragment>
|
|
175
|
-
<
|
|
176
|
-
axisLineClassName={classes.line}
|
|
174
|
+
<StyledAxis
|
|
177
175
|
orientation={'left'}
|
|
178
176
|
scale={scale.y}
|
|
179
177
|
top={0}
|
|
@@ -183,7 +181,6 @@ export class RawYAxis extends React.Component {
|
|
|
183
181
|
labelProps={{ 'data-pie-readable': false }}
|
|
184
182
|
rangePadding={8}
|
|
185
183
|
tickLength={10}
|
|
186
|
-
tickClassName={classes.tick}
|
|
187
184
|
tickFormat={customTickFormat}
|
|
188
185
|
tickLabelProps={(value) => {
|
|
189
186
|
let digits = value.toLocaleString().replace(/[.-]/g, '').length || 1;
|
|
@@ -199,17 +196,16 @@ export class RawYAxis extends React.Component {
|
|
|
199
196
|
tickTextAnchor={'bottom'}
|
|
200
197
|
tickValues={rowTickValues}
|
|
201
198
|
/>
|
|
202
|
-
|
|
203
199
|
{includeArrows && includeArrows.down && (
|
|
204
|
-
<
|
|
200
|
+
<StyledArrow direction="down" x={0} y={range.min} scale={scale} />
|
|
205
201
|
)}
|
|
206
202
|
{includeArrows && includeArrows.up && (
|
|
207
|
-
<
|
|
203
|
+
<StyledArrow direction="up" x={0} y={range.max} scale={scale} />
|
|
208
204
|
)}
|
|
209
205
|
{range.axisLabel && (
|
|
210
206
|
<foreignObject x={scale.x(0) - necessaryWidth / 2} y={-33} width={necessaryWidth} height="20">
|
|
211
207
|
<Readable false>
|
|
212
|
-
<
|
|
208
|
+
<AxisLabelHolder dangerouslySetInnerHTML={{ __html: range.axisLabel }} />
|
|
213
209
|
</Readable>
|
|
214
210
|
</foreignObject>
|
|
215
211
|
)}
|
|
@@ -218,12 +214,11 @@ export class RawYAxis extends React.Component {
|
|
|
218
214
|
}
|
|
219
215
|
}
|
|
220
216
|
|
|
221
|
-
const YAxis =
|
|
217
|
+
const YAxis = RawYAxis;
|
|
222
218
|
|
|
223
219
|
export default class Axes extends React.Component {
|
|
224
220
|
static propTypes = {
|
|
225
221
|
...AxisPropTypes,
|
|
226
|
-
classes: PropTypes.object,
|
|
227
222
|
graphProps: types.GraphPropsType.isRequired,
|
|
228
223
|
};
|
|
229
224
|
static defaultProps = AxisDefaultProps;
|
|
@@ -2,22 +2,20 @@ import React from 'react';
|
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
3
|
import { types } from '@pie-lib/plot';
|
|
4
4
|
import { color } from '@pie-lib/render-ui';
|
|
5
|
-
import {
|
|
6
|
-
import InputBase from '@material
|
|
5
|
+
import { styled } from '@mui/material/styles';
|
|
6
|
+
import InputBase from '@mui/material/InputBase';
|
|
7
7
|
import { roundNumber } from './utils';
|
|
8
8
|
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
},
|
|
17
|
-
inputLabel: {
|
|
9
|
+
const StyledInputBase = styled(InputBase)(({ theme }) => ({
|
|
10
|
+
fontFamily: theme.typography.fontFamily,
|
|
11
|
+
fontSize: theme.typography.fontSize,
|
|
12
|
+
borderRadius: '8px',
|
|
13
|
+
background: theme.palette.common.white,
|
|
14
|
+
color: color.defaults.BLACK,
|
|
15
|
+
'& .MuiInputBase-input': {
|
|
18
16
|
padding: 0,
|
|
19
17
|
},
|
|
20
|
-
});
|
|
18
|
+
}));
|
|
21
19
|
|
|
22
20
|
export const getLabelPosition = (graphProps, x, y, labelLength) => {
|
|
23
21
|
const { scale, domain, range } = graphProps;
|
|
@@ -39,7 +37,7 @@ export const getLabelPosition = (graphProps, x, y, labelLength) => {
|
|
|
39
37
|
};
|
|
40
38
|
};
|
|
41
39
|
|
|
42
|
-
export const CoordinatesLabel = ({ x, y, graphProps
|
|
40
|
+
export const CoordinatesLabel = ({ x, y, graphProps }) => {
|
|
43
41
|
const label = `(${roundNumber(x)}, ${roundNumber(y)})`;
|
|
44
42
|
const labelLength = (label.length || 0) * 6;
|
|
45
43
|
const labelPosition = getLabelPosition(graphProps, x, y, labelLength);
|
|
@@ -53,10 +51,8 @@ export const CoordinatesLabel = ({ x, y, graphProps, classes }) => {
|
|
|
53
51
|
};
|
|
54
52
|
|
|
55
53
|
return (
|
|
56
|
-
<
|
|
54
|
+
<StyledInputBase
|
|
57
55
|
style={style}
|
|
58
|
-
classes={{ input: classes.inputLabel }}
|
|
59
|
-
className={classes.input}
|
|
60
56
|
value={label}
|
|
61
57
|
inputProps={{ ariaLabel: 'naked' }}
|
|
62
58
|
/>
|
|
@@ -65,9 +61,8 @@ export const CoordinatesLabel = ({ x, y, graphProps, classes }) => {
|
|
|
65
61
|
|
|
66
62
|
CoordinatesLabel.propTypes = {
|
|
67
63
|
graphProps: types.GraphPropsType,
|
|
68
|
-
classes: PropTypes.object,
|
|
69
64
|
x: PropTypes.number,
|
|
70
65
|
y: PropTypes.number,
|
|
71
66
|
};
|
|
72
67
|
|
|
73
|
-
export default
|
|
68
|
+
export default CoordinatesLabel;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
|
-
import {
|
|
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 {
|
|
13
|
-
|
|
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) => ({
|
|
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) =>
|
|
37
|
+
const getDefaultCurrentTool = (toolType) =>
|
|
38
|
+
toolsArr.find((tool) => tool.type === toolType) || null;
|
|
30
39
|
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
40
|
+
const GraphWithControlsRoot = styled('div')(({ theme }) => ({
|
|
41
|
+
display: 'flex',
|
|
42
|
+
flexDirection: 'column',
|
|
43
|
+
width: 'min-content',
|
|
44
|
+
}));
|
|
45
|
+
|
|
46
|
+
const Controls = styled('div')(({ theme }) => ({
|
|
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)(({ theme }) => ({
|
|
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
|
-
|
|
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),
|
|
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) =>
|
|
136
|
+
changeCurrentTool = (tool, tools) =>
|
|
137
|
+
this.setState({ currentTool: tools.find((t) => t.type === tool) });
|
|
92
138
|
|
|
93
|
-
toggleLabelMode = () =>
|
|
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
|
-
|
|
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
|
-
<
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
202
|
+
<UndoRedoOuterDiv>
|
|
203
|
+
<UndoRedo
|
|
204
|
+
onUndo={onUndo}
|
|
205
|
+
onRedo={onRedo}
|
|
206
|
+
onReset={onCustomReset}
|
|
207
|
+
language={language}
|
|
208
|
+
/>
|
|
209
|
+
</UndoRedoOuterDiv>
|
|
169
210
|
)}
|
|
170
|
-
|
|
211
|
+
</>
|
|
171
212
|
);
|
|
172
213
|
|
|
173
214
|
return (
|
|
174
|
-
<
|
|
215
|
+
<GraphWithControlsRoot className={classNames(className)}>
|
|
175
216
|
{!disableToolbar && (
|
|
176
|
-
<
|
|
217
|
+
<Controls>
|
|
177
218
|
{collapsibleToolbar ? (
|
|
178
|
-
<Collapsible
|
|
179
|
-
{gssActions}
|
|
180
|
-
</Collapsible>
|
|
219
|
+
<Collapsible title={collapsibleToolbarTitle}>{gssActions}</Collapsible>
|
|
181
220
|
) : (
|
|
182
221
|
gssActions
|
|
183
222
|
)}
|
|
184
|
-
</
|
|
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
|
-
</
|
|
255
|
+
</GraphWithControlsRoot>
|
|
217
256
|
);
|
|
218
257
|
}
|
|
219
258
|
}
|
|
220
259
|
|
|
221
|
-
|
|
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;
|