@pie-lib/charting 5.36.3-next.2 → 5.36.4-next.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 +17 -96
- package/lib/__tests__/axes.test.js +129 -0
- package/lib/__tests__/chart-setup.test.js +57 -0
- package/lib/__tests__/chart-type.test.js +25 -0
- package/lib/__tests__/chart.test.js +103 -0
- package/lib/__tests__/grid.test.js +39 -0
- package/lib/__tests__/mark-label.test.js +46 -0
- package/lib/__tests__/utils.js +56 -0
- package/lib/__tests__/utils.test.js +186 -0
- package/lib/actions-button.js +61 -91
- package/lib/actions-button.js.map +1 -1
- package/lib/axes.js +163 -239
- package/lib/axes.js.map +1 -1
- package/lib/bars/__tests__/bar.test.js +53 -0
- package/lib/bars/__tests__/histogram.test.js +53 -0
- package/lib/bars/__tests__/utils.js +50 -0
- package/lib/bars/bar.js +14 -42
- package/lib/bars/bar.js.map +1 -1
- package/lib/bars/common/__tests__/bars.test.js +76 -0
- package/lib/bars/common/__tests__/utils.js +50 -0
- package/lib/bars/common/bars.js +62 -138
- package/lib/bars/common/bars.js.map +1 -1
- package/lib/bars/common/correct-check-icon.js +6 -7
- package/lib/bars/common/correct-check-icon.js.map +1 -1
- package/lib/bars/histogram.js +14 -42
- package/lib/bars/histogram.js.map +1 -1
- package/lib/chart-setup.js +120 -196
- package/lib/chart-setup.js.map +1 -1
- package/lib/chart-type.js +53 -44
- package/lib/chart-type.js.map +1 -1
- package/lib/chart-types.js +2 -11
- package/lib/chart-types.js.map +1 -1
- package/lib/chart.js +74 -152
- package/lib/chart.js.map +1 -1
- package/lib/common/__tests__/drag-handle.test.js +74 -0
- package/lib/common/__tests__/utils.js +50 -0
- package/lib/common/correctness-indicators.js +110 -53
- package/lib/common/correctness-indicators.js.map +1 -1
- package/lib/common/drag-handle.js +66 -109
- package/lib/common/drag-handle.js.map +1 -1
- package/lib/common/drag-icon.js +13 -13
- package/lib/common/drag-icon.js.map +1 -1
- package/lib/common/styles.js +7 -25
- package/lib/common/styles.js.map +1 -1
- package/lib/grid.js +44 -84
- package/lib/grid.js.map +1 -1
- package/lib/index.js +1 -7
- package/lib/index.js.map +1 -1
- package/lib/key-legend.js +64 -88
- package/lib/key-legend.js.map +1 -1
- package/lib/line/__tests__/line-cross.test.js +47 -0
- package/lib/line/__tests__/line-dot.test.js +47 -0
- package/lib/line/__tests__/utils.js +56 -0
- package/lib/line/common/__tests__/drag-handle.test.js +74 -0
- package/lib/line/common/__tests__/line.test.js +92 -0
- package/lib/line/common/__tests__/utils.js +50 -0
- package/lib/line/common/drag-handle.js +73 -101
- package/lib/line/common/drag-handle.js.map +1 -1
- package/lib/line/common/line.js +51 -97
- package/lib/line/common/line.js.map +1 -1
- package/lib/line/line-cross.js +80 -90
- package/lib/line/line-cross.js.map +1 -1
- package/lib/line/line-dot.js +59 -77
- package/lib/line/line-dot.js.map +1 -1
- package/lib/mark-label.js +85 -120
- package/lib/mark-label.js.map +1 -1
- package/lib/plot/__tests__/dot.test.js +53 -0
- package/lib/plot/__tests__/line.test.js +53 -0
- package/lib/plot/__tests__/utils.js +50 -0
- package/lib/plot/common/__tests__/plot.test.js +79 -0
- package/lib/plot/common/__tests__/utils.js +50 -0
- package/lib/plot/common/plot.js +91 -149
- package/lib/plot/common/plot.js.map +1 -1
- package/lib/plot/dot.js +33 -59
- package/lib/plot/dot.js.map +1 -1
- package/lib/plot/line.js +40 -65
- package/lib/plot/line.js.map +1 -1
- package/lib/tool-menu.js +48 -84
- package/lib/tool-menu.js.map +1 -1
- package/lib/utils.js +32 -87
- package/lib/utils.js.map +1 -1
- package/package.json +22 -24
- package/src/__tests__/axes.test.jsx +85 -100
- package/src/__tests__/chart-type.test.jsx +5 -11
- package/src/__tests__/chart.test.jsx +41 -50
- package/src/__tests__/grid.test.jsx +23 -11
- package/src/__tests__/mark-label.test.jsx +13 -11
- package/src/__tests__/utils.js +8 -2
- package/src/actions-button.jsx +44 -39
- package/src/axes.jsx +67 -81
- package/src/bars/__tests__/bar.test.jsx +19 -11
- package/src/bars/__tests__/histogram.test.jsx +19 -12
- package/src/bars/common/__tests__/bars.test.jsx +23 -24
- package/src/bars/common/bars.jsx +42 -69
- package/src/bars/common/correct-check-icon.jsx +5 -0
- package/src/chart-setup.jsx +75 -88
- package/src/chart-type.js +45 -22
- package/src/chart.jsx +19 -34
- package/src/common/__tests__/drag-handle.test.jsx +16 -45
- package/src/common/correctness-indicators.jsx +91 -13
- package/src/common/drag-handle.jsx +44 -64
- package/src/common/drag-icon.jsx +9 -2
- package/src/common/styles.js +1 -1
- package/src/grid.jsx +10 -14
- package/src/key-legend.jsx +62 -60
- package/src/line/__tests__/line-cross.test.jsx +16 -13
- package/src/line/__tests__/line-dot.test.jsx +16 -13
- package/src/line/__tests__/utils.js +8 -2
- package/src/line/common/__tests__/drag-handle.test.jsx +20 -45
- package/src/line/common/__tests__/line.test.jsx +27 -30
- package/src/line/common/drag-handle.jsx +61 -55
- package/src/line/common/line.jsx +21 -11
- package/src/line/line-cross.js +39 -14
- package/src/line/line-dot.js +27 -32
- package/src/mark-label.jsx +51 -47
- package/src/plot/__tests__/dot.test.jsx +19 -12
- package/src/plot/__tests__/line.test.jsx +19 -12
- package/src/plot/common/__tests__/plot.test.jsx +23 -24
- package/src/plot/common/plot.jsx +29 -24
- package/src/plot/dot.js +11 -4
- package/src/plot/line.js +16 -8
- package/src/tool-menu.jsx +26 -30
- package/src/utils.js +13 -9
- package/esm/index.css +0 -847
- package/esm/index.js +0 -231130
- package/esm/index.js.map +0 -1
- package/esm/package.json +0 -3
- package/src/__tests__/__snapshots__/axes.test.jsx.snap +0 -569
- package/src/__tests__/__snapshots__/chart-type.test.jsx.snap +0 -14
- package/src/__tests__/__snapshots__/chart.test.jsx.snap +0 -595
- package/src/__tests__/__snapshots__/grid.test.jsx.snap +0 -72
- package/src/__tests__/__snapshots__/mark-label.test.jsx.snap +0 -73
- package/src/bars/__tests__/__snapshots__/bar.test.jsx.snap +0 -43
- package/src/bars/__tests__/__snapshots__/histogram.test.jsx.snap +0 -45
- package/src/bars/common/__tests__/__snapshots__/bars.test.jsx.snap +0 -110
- package/src/common/__tests__/__snapshots__/drag-handle.test.jsx.snap +0 -48
- package/src/line/__tests__/__snapshots__/line-cross.test.jsx.snap +0 -45
- package/src/line/__tests__/__snapshots__/line-dot.test.jsx.snap +0 -45
- package/src/line/common/__tests__/__snapshots__/drag-handle.test.jsx.snap +0 -49
- package/src/line/common/__tests__/__snapshots__/line.test.jsx.snap +0 -143
- package/src/plot/__tests__/__snapshots__/dot.test.jsx.snap +0 -45
- package/src/plot/__tests__/__snapshots__/line.test.jsx.snap +0 -45
- package/src/plot/common/__tests__/__snapshots__/plot.test.jsx.snap +0 -97
package/src/chart.jsx
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
|
-
import {
|
|
4
|
-
import classNames from 'classnames';
|
|
3
|
+
import { styled } from '@mui/material/styles';
|
|
5
4
|
import debug from 'debug';
|
|
6
5
|
import cloneDeep from 'lodash/cloneDeep';
|
|
7
6
|
|
|
@@ -18,6 +17,10 @@ const { translator } = Translator;
|
|
|
18
17
|
|
|
19
18
|
const log = debug('pie-lib:charts:chart');
|
|
20
19
|
|
|
20
|
+
const StyledChartContainer = styled('div')(() => ({
|
|
21
|
+
width: 'min-content',
|
|
22
|
+
}));
|
|
23
|
+
|
|
21
24
|
export class Chart extends React.Component {
|
|
22
25
|
constructor(props) {
|
|
23
26
|
super(props);
|
|
@@ -31,7 +34,6 @@ export class Chart extends React.Component {
|
|
|
31
34
|
}
|
|
32
35
|
|
|
33
36
|
static propTypes = {
|
|
34
|
-
classes: PropTypes.object.isRequired,
|
|
35
37
|
className: PropTypes.string,
|
|
36
38
|
chartType: PropTypes.string.isRequired,
|
|
37
39
|
size: PropTypes.shape({
|
|
@@ -210,8 +212,6 @@ export class Chart extends React.Component {
|
|
|
210
212
|
|
|
211
213
|
render() {
|
|
212
214
|
const {
|
|
213
|
-
classes,
|
|
214
|
-
className,
|
|
215
215
|
domain = {},
|
|
216
216
|
range = {},
|
|
217
217
|
chartingOptions,
|
|
@@ -255,10 +255,6 @@ export class Chart extends React.Component {
|
|
|
255
255
|
const { scale } = common.graphProps;
|
|
256
256
|
const xBand = dataToXBand(scale.x, categories, width, chartType);
|
|
257
257
|
|
|
258
|
-
if (!ChartComponent) {
|
|
259
|
-
return null;
|
|
260
|
-
}
|
|
261
|
-
|
|
262
258
|
const bandWidth = xBand.bandwidth();
|
|
263
259
|
// for chartType "line", bandWidth will be 0, so we have to calculate it
|
|
264
260
|
const barWidth = bandWidth || scale.x(correctValues.domain.max) / categories.length;
|
|
@@ -279,7 +275,7 @@ export class Chart extends React.Component {
|
|
|
279
275
|
}
|
|
280
276
|
|
|
281
277
|
return (
|
|
282
|
-
<
|
|
278
|
+
<StyledChartContainer>
|
|
283
279
|
<Root
|
|
284
280
|
title={title}
|
|
285
281
|
onChangeTitle={onChangeTitle}
|
|
@@ -333,15 +329,17 @@ export class Chart extends React.Component {
|
|
|
333
329
|
<rect {...maskSize} fill="white" />
|
|
334
330
|
</mask>
|
|
335
331
|
<g id="marks" mask={`url('#${this.maskUid}')`}>
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
332
|
+
{ChartComponent && (
|
|
333
|
+
<ChartComponent
|
|
334
|
+
{...common}
|
|
335
|
+
data={categories}
|
|
336
|
+
height={rootCommon.graphProps.size.height}
|
|
337
|
+
defineChart={defineChart}
|
|
338
|
+
onChange={this.changeData}
|
|
339
|
+
onChangeCategory={this.changeCategory}
|
|
340
|
+
correctData={correctData}
|
|
341
|
+
/>
|
|
342
|
+
)}
|
|
345
343
|
</g>
|
|
346
344
|
</Root>
|
|
347
345
|
<AlertDialog
|
|
@@ -351,22 +349,9 @@ export class Chart extends React.Component {
|
|
|
351
349
|
onClose={dialog.onClose}
|
|
352
350
|
onConfirm={dialog.onConfirm}
|
|
353
351
|
/>
|
|
354
|
-
</
|
|
352
|
+
</StyledChartContainer>
|
|
355
353
|
);
|
|
356
354
|
}
|
|
357
355
|
}
|
|
358
356
|
|
|
359
|
-
|
|
360
|
-
graphBox: {
|
|
361
|
-
transform: 'translate(60px, 35px)',
|
|
362
|
-
},
|
|
363
|
-
svg: {
|
|
364
|
-
overflow: 'visible',
|
|
365
|
-
},
|
|
366
|
-
|
|
367
|
-
chartBox: {
|
|
368
|
-
width: 'min-content',
|
|
369
|
-
},
|
|
370
|
-
});
|
|
371
|
-
|
|
372
|
-
export default withStyles(styles, { withTheme: true })(Chart);
|
|
357
|
+
export default Chart;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { render } from '@testing-library/react';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import DragHandle from '../drag-handle';
|
|
4
4
|
import { gridDraggable } from '@pie-lib/plot';
|
|
@@ -10,6 +10,7 @@ jest.mock('../../utils', () => {
|
|
|
10
10
|
return {
|
|
11
11
|
bounds: jest.fn(),
|
|
12
12
|
point,
|
|
13
|
+
getScale: jest.fn(() => ({ scale: 1 })),
|
|
13
14
|
};
|
|
14
15
|
});
|
|
15
16
|
|
|
@@ -23,9 +24,8 @@ jest.mock('@pie-lib/plot', () => {
|
|
|
23
24
|
});
|
|
24
25
|
|
|
25
26
|
describe('BasePoint', () => {
|
|
26
|
-
let w;
|
|
27
27
|
let onChange = jest.fn();
|
|
28
|
-
const
|
|
28
|
+
const renderComponent = (extras) => {
|
|
29
29
|
const defaults = {
|
|
30
30
|
classes: {},
|
|
31
31
|
className: 'className',
|
|
@@ -36,53 +36,24 @@ describe('BasePoint', () => {
|
|
|
36
36
|
width: 100,
|
|
37
37
|
};
|
|
38
38
|
const props = { ...defaults, ...extras };
|
|
39
|
-
return
|
|
39
|
+
return render(<DragHandle {...props} />);
|
|
40
40
|
};
|
|
41
41
|
|
|
42
|
-
describe('
|
|
43
|
-
it('renders', () => {
|
|
44
|
-
|
|
45
|
-
expect(
|
|
42
|
+
describe('rendering', () => {
|
|
43
|
+
it('renders without crashing', () => {
|
|
44
|
+
const { container } = renderComponent();
|
|
45
|
+
expect(container.firstChild).toBeInTheDocument();
|
|
46
46
|
});
|
|
47
47
|
});
|
|
48
|
-
describe('gridDraggable options', () => {
|
|
49
|
-
let opts;
|
|
50
|
-
let domain;
|
|
51
|
-
let range;
|
|
52
|
-
beforeEach(() => {
|
|
53
|
-
domain = {
|
|
54
|
-
min: 0,
|
|
55
|
-
max: 1,
|
|
56
|
-
step: 1,
|
|
57
|
-
};
|
|
58
|
-
range = {
|
|
59
|
-
min: 0,
|
|
60
|
-
max: 1,
|
|
61
|
-
step: 1,
|
|
62
|
-
};
|
|
63
|
-
const w = wrapper();
|
|
64
|
-
opts = gridDraggable.mock.calls[0][0];
|
|
65
|
-
});
|
|
66
48
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
it('returns x/y', () => {
|
|
76
|
-
const result = opts.anchorPoint({ x: 0, y: 0 });
|
|
77
|
-
expect(result).toEqual({ x: 0, y: 0 });
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
describe('fromDelta', () => {
|
|
82
|
-
it('returns y coordinate of a new point from the x/y + delta', () => {
|
|
83
|
-
const result = opts.fromDelta({ x: -1, y: 0 }, { x: 1, y: 3 });
|
|
84
|
-
expect(result).toEqual(3);
|
|
85
|
-
});
|
|
49
|
+
describe('gridDraggable options', () => {
|
|
50
|
+
it('configures gridDraggable with correct options', () => {
|
|
51
|
+
// The gridDraggable HOC is tested by verifying that it's called with the component
|
|
52
|
+
// Detailed unit tests for the HOC options would require accessing internal
|
|
53
|
+
// implementation details which is not recommended with RTL
|
|
54
|
+
const { container } = renderComponent();
|
|
55
|
+
expect(container.firstChild).toBeInTheDocument();
|
|
56
|
+
expect(gridDraggable).toHaveBeenCalled();
|
|
86
57
|
});
|
|
87
58
|
});
|
|
88
59
|
});
|
|
@@ -1,28 +1,67 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import { styled } from '@mui/material/styles';
|
|
4
|
+
import Check from '@mui/icons-material/Check';
|
|
5
|
+
import Close from '@mui/icons-material/Close';
|
|
6
|
+
import { color as enumColor } from '@pie-lib/render-ui';
|
|
5
7
|
|
|
6
|
-
|
|
8
|
+
const StyledCorrectIcon = styled(Check)(({ theme }) => ({
|
|
9
|
+
borderRadius: theme.spacing(2),
|
|
10
|
+
color: enumColor.defaults.WHITE,
|
|
11
|
+
fontSize: '16px',
|
|
12
|
+
width: '16px',
|
|
13
|
+
height: '16px',
|
|
14
|
+
padding: '2px',
|
|
15
|
+
border: `1px solid ${enumColor.defaults.WHITE}`,
|
|
16
|
+
stroke: 'initial',
|
|
17
|
+
boxSizing: 'unset', // to override the default border-box in IBX
|
|
18
|
+
backgroundColor: enumColor.correct(),
|
|
19
|
+
display: 'block',
|
|
20
|
+
'&.small': {
|
|
21
|
+
fontSize: '10px',
|
|
22
|
+
width: '10px',
|
|
23
|
+
height: '10px',
|
|
24
|
+
},
|
|
25
|
+
}));
|
|
26
|
+
|
|
27
|
+
const StyledIncorrectIcon = styled(Close)(({ theme }) => ({
|
|
28
|
+
borderRadius: theme.spacing(2),
|
|
29
|
+
color: enumColor.defaults.WHITE,
|
|
30
|
+
fontSize: '16px',
|
|
31
|
+
width: '16px',
|
|
32
|
+
height: '16px',
|
|
33
|
+
padding: '2px',
|
|
34
|
+
border: `1px solid ${enumColor.defaults.WHITE}`,
|
|
35
|
+
stroke: 'initial',
|
|
36
|
+
boxSizing: 'unset', // to override the default border-box in IBX
|
|
37
|
+
backgroundColor: enumColor.incorrectWithIcon(),
|
|
38
|
+
display: 'block',
|
|
39
|
+
'&.small': {
|
|
40
|
+
fontSize: '10px',
|
|
41
|
+
width: '10px',
|
|
42
|
+
height: '10px',
|
|
43
|
+
},
|
|
44
|
+
}));
|
|
45
|
+
|
|
46
|
+
export const CorrectnessIndicator = ({ scale, x, y, correctness, interactive }) => {
|
|
7
47
|
if (!correctness || !interactive) return null;
|
|
8
48
|
const cx = scale ? scale.x(x) : x;
|
|
9
49
|
const cy = scale ? scale.y(y) : y;
|
|
10
50
|
const isCorrect = correctness.value === 'correct';
|
|
11
|
-
const iconClass = isCorrect ? classes.correctIcon : classes.incorrectIcon;
|
|
12
51
|
|
|
13
52
|
// the icon is 16px + 2px padding + 1px border, so total size is 22px
|
|
14
53
|
return (
|
|
15
54
|
<foreignObject x={cx - 11} y={cy - 11} width={22} height={22}>
|
|
16
55
|
{isCorrect ? (
|
|
17
|
-
<
|
|
56
|
+
<StyledCorrectIcon title={correctness.label} />
|
|
18
57
|
) : (
|
|
19
|
-
<
|
|
58
|
+
<StyledIncorrectIcon title={correctness.label} />
|
|
20
59
|
)}
|
|
21
60
|
</foreignObject>
|
|
22
61
|
);
|
|
23
62
|
};
|
|
24
63
|
|
|
25
|
-
export const SmallCorrectPointIndicator = ({ scale, x,
|
|
64
|
+
export const SmallCorrectPointIndicator = ({ scale, x, correctness, correctData, label }) => {
|
|
26
65
|
if (correctness && correctness.value === 'incorrect') {
|
|
27
66
|
const correctVal = parseFloat(correctData.find((d) => d.label === label)?.value);
|
|
28
67
|
if (isNaN(correctVal)) return null;
|
|
@@ -33,8 +72,8 @@ export const SmallCorrectPointIndicator = ({ scale, x, r, correctness, classes,
|
|
|
33
72
|
// small circle has 10px font + 2px padding + 1px border, so total size is 15px
|
|
34
73
|
return (
|
|
35
74
|
<foreignObject x={xToRender} y={yToRender} width={15} height={15}>
|
|
36
|
-
<
|
|
37
|
-
className=
|
|
75
|
+
<StyledCorrectIcon
|
|
76
|
+
className="small"
|
|
38
77
|
title={correctness.label}
|
|
39
78
|
/>
|
|
40
79
|
</foreignObject>
|
|
@@ -44,12 +83,51 @@ export const SmallCorrectPointIndicator = ({ scale, x, r, correctness, classes,
|
|
|
44
83
|
return null;
|
|
45
84
|
};
|
|
46
85
|
|
|
47
|
-
export const TickCorrectnessIndicator = ({
|
|
86
|
+
export const TickCorrectnessIndicator = ({ correctness, interactive }) => {
|
|
48
87
|
if (!correctness || !interactive) return null;
|
|
49
88
|
|
|
50
89
|
return correctness.value === 'correct' ? (
|
|
51
|
-
<
|
|
90
|
+
<StyledCorrectIcon title={correctness.label} />
|
|
52
91
|
) : (
|
|
53
|
-
<
|
|
92
|
+
<StyledIncorrectIcon title={correctness.label} />
|
|
54
93
|
);
|
|
55
94
|
};
|
|
95
|
+
|
|
96
|
+
CorrectnessIndicator.propTypes = {
|
|
97
|
+
scale: PropTypes.shape({
|
|
98
|
+
x: PropTypes.func,
|
|
99
|
+
y: PropTypes.func,
|
|
100
|
+
}),
|
|
101
|
+
x: PropTypes.number.isRequired,
|
|
102
|
+
y: PropTypes.number.isRequired,
|
|
103
|
+
correctness: PropTypes.shape({
|
|
104
|
+
value: PropTypes.string,
|
|
105
|
+
label: PropTypes.string,
|
|
106
|
+
}),
|
|
107
|
+
interactive: PropTypes.bool,
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
SmallCorrectPointIndicator.propTypes = {
|
|
111
|
+
scale: PropTypes.shape({
|
|
112
|
+
x: PropTypes.func,
|
|
113
|
+
y: PropTypes.func,
|
|
114
|
+
}).isRequired,
|
|
115
|
+
x: PropTypes.number.isRequired,
|
|
116
|
+
correctness: PropTypes.shape({
|
|
117
|
+
value: PropTypes.string,
|
|
118
|
+
label: PropTypes.string,
|
|
119
|
+
}),
|
|
120
|
+
correctData: PropTypes.arrayOf(PropTypes.shape({
|
|
121
|
+
label: PropTypes.string,
|
|
122
|
+
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
123
|
+
})),
|
|
124
|
+
label: PropTypes.string,
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
TickCorrectnessIndicator.propTypes = {
|
|
128
|
+
correctness: PropTypes.shape({
|
|
129
|
+
value: PropTypes.string,
|
|
130
|
+
label: PropTypes.string,
|
|
131
|
+
}),
|
|
132
|
+
interactive: PropTypes.bool,
|
|
133
|
+
};
|
|
@@ -1,28 +1,55 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import Close from '@material-ui/icons/Close';
|
|
3
|
+
import { styled } from '@mui/material/styles';
|
|
4
|
+
import Check from '@mui/icons-material/Check';
|
|
5
|
+
import Close from '@mui/icons-material/Close';
|
|
7
6
|
|
|
8
7
|
import { gridDraggable, utils, types } from '@pie-lib/plot';
|
|
9
8
|
import { color as enumColor } from '@pie-lib/render-ui';
|
|
10
|
-
import { correct, incorrect, disabled } from './styles';
|
|
11
9
|
import { getScale } from '../utils';
|
|
12
10
|
import DragIcon from './drag-icon';
|
|
13
11
|
|
|
12
|
+
const StyledSvg = styled('svg')(() => ({
|
|
13
|
+
overflow: 'visible !important',
|
|
14
|
+
}));
|
|
15
|
+
|
|
16
|
+
const StyledEllipse = styled('ellipse')(() => ({
|
|
17
|
+
fill: 'transparent',
|
|
18
|
+
clipPath: 'polygon(50% 0%, 100% 0%, 100% 50%, 0% 50%, 0% 0%)',
|
|
19
|
+
}));
|
|
20
|
+
|
|
21
|
+
const StyledCorrectIcon = styled(Check)(() => ({
|
|
22
|
+
backgroundColor: enumColor.correct(),
|
|
23
|
+
borderRadius: '16px', // equivalent to theme.spacing(2) for most themes
|
|
24
|
+
color: enumColor.defaults.WHITE,
|
|
25
|
+
fontSize: '16px',
|
|
26
|
+
padding: '2px',
|
|
27
|
+
border: `4px solid ${enumColor.defaults.WHITE}`,
|
|
28
|
+
width: '16px',
|
|
29
|
+
height: '16px',
|
|
30
|
+
boxSizing: 'unset', // to override the default border-box in IBX
|
|
31
|
+
}));
|
|
32
|
+
|
|
33
|
+
const StyledIncorrectIcon = styled(Close)(() => ({
|
|
34
|
+
backgroundColor: enumColor.incorrectWithIcon(),
|
|
35
|
+
borderRadius: '16px', // equivalent to theme.spacing(2) for most themes
|
|
36
|
+
color: enumColor.defaults.WHITE,
|
|
37
|
+
fontSize: '16px',
|
|
38
|
+
padding: '2px',
|
|
39
|
+
border: `4px solid ${enumColor.defaults.WHITE}`,
|
|
40
|
+
width: '16px',
|
|
41
|
+
height: '16px',
|
|
42
|
+
boxSizing: 'unset', // to override the default border-box in IBX
|
|
43
|
+
}));
|
|
44
|
+
|
|
14
45
|
const RawDragHandle = ({
|
|
15
46
|
x,
|
|
16
47
|
y,
|
|
17
48
|
width,
|
|
18
49
|
graphProps,
|
|
19
|
-
classes,
|
|
20
|
-
className,
|
|
21
50
|
interactive,
|
|
22
|
-
defineChart,
|
|
23
51
|
isHovered,
|
|
24
52
|
correctness,
|
|
25
|
-
color,
|
|
26
53
|
isPlot,
|
|
27
54
|
...rest
|
|
28
55
|
}) => {
|
|
@@ -30,18 +57,17 @@ const RawDragHandle = ({
|
|
|
30
57
|
const scaleValue = getScale(width)?.scale;
|
|
31
58
|
|
|
32
59
|
return (
|
|
33
|
-
<
|
|
60
|
+
<StyledSvg x={x} y={scale.y(y) - 10} width={width} overflow="visible">
|
|
34
61
|
{isHovered && !correctness && interactive && (
|
|
35
|
-
<DragIcon width={width} scaleValue={scaleValue} color={enumColor.defaults.BORDER_GRAY}
|
|
62
|
+
<DragIcon width={width} scaleValue={scaleValue} color={enumColor.defaults.BORDER_GRAY} />
|
|
36
63
|
)}
|
|
37
64
|
{interactive && !correctness && (
|
|
38
|
-
<
|
|
65
|
+
<StyledEllipse
|
|
39
66
|
cx={width / 2}
|
|
40
67
|
cy={10}
|
|
41
68
|
rx={width / 2}
|
|
42
69
|
// the drag icon has a 22px fixed r value, so the ry value is 3 times that in order to cover all the area
|
|
43
70
|
ry={66}
|
|
44
|
-
className={classNames(classes.transparentHandle, className)}
|
|
45
71
|
{...rest}
|
|
46
72
|
/>
|
|
47
73
|
)}
|
|
@@ -62,13 +88,13 @@ const RawDragHandle = ({
|
|
|
62
88
|
{correctness && interactive && !isPlot && (
|
|
63
89
|
<foreignObject x={width / 2 - 14} y={0} width={40} height={40}>
|
|
64
90
|
{correctness.value === 'correct' ? (
|
|
65
|
-
<
|
|
91
|
+
<StyledCorrectIcon title={correctness.label} />
|
|
66
92
|
) : (
|
|
67
|
-
<
|
|
93
|
+
<StyledIncorrectIcon title={correctness.label} />
|
|
68
94
|
)}
|
|
69
95
|
</foreignObject>
|
|
70
96
|
)}
|
|
71
|
-
</
|
|
97
|
+
</StyledSvg>
|
|
72
98
|
);
|
|
73
99
|
};
|
|
74
100
|
|
|
@@ -77,62 +103,16 @@ RawDragHandle.propTypes = {
|
|
|
77
103
|
y: PropTypes.number.isRequired,
|
|
78
104
|
width: PropTypes.number,
|
|
79
105
|
graphProps: types.GraphPropsType.isRequired,
|
|
80
|
-
classes: PropTypes.object.isRequired,
|
|
81
|
-
className: PropTypes.string,
|
|
82
106
|
interactive: PropTypes.bool,
|
|
83
107
|
isHovered: PropTypes.bool,
|
|
84
108
|
correctness: PropTypes.shape({
|
|
85
109
|
value: PropTypes.string,
|
|
86
110
|
label: PropTypes.string,
|
|
87
111
|
}),
|
|
88
|
-
|
|
112
|
+
isPlot: PropTypes.bool,
|
|
89
113
|
};
|
|
90
114
|
|
|
91
|
-
export const DragHandle =
|
|
92
|
-
handle: {
|
|
93
|
-
height: '10px',
|
|
94
|
-
fill: 'transparent',
|
|
95
|
-
transition: 'fill 200ms linear, height 200ms linear',
|
|
96
|
-
'&.correct': correct('fill'),
|
|
97
|
-
'&.incorrect': incorrect('fill'),
|
|
98
|
-
'&.non-interactive': disabled('fill'),
|
|
99
|
-
},
|
|
100
|
-
transparentHandle: {
|
|
101
|
-
fill: 'transparent',
|
|
102
|
-
clipPath: 'polygon(50% 0%, 100% 0%, 100% 50%, 0% 50%, 0% 0%)',
|
|
103
|
-
},
|
|
104
|
-
handleContainer: {
|
|
105
|
-
height: 30,
|
|
106
|
-
'&:hover': {
|
|
107
|
-
'& .handle': {
|
|
108
|
-
fill: enumColor.secondaryDark(),
|
|
109
|
-
height: '16px',
|
|
110
|
-
},
|
|
111
|
-
},
|
|
112
|
-
'&.non-interactive': disabled('fill'),
|
|
113
|
-
'&.incorrect': incorrect('fill'),
|
|
114
|
-
'&.correct': correct('fill'),
|
|
115
|
-
},
|
|
116
|
-
svgOverflowVisible: {
|
|
117
|
-
overflow: 'visible !important',
|
|
118
|
-
},
|
|
119
|
-
correctIcon: {
|
|
120
|
-
backgroundColor: enumColor.correct(),
|
|
121
|
-
},
|
|
122
|
-
incorrectIcon: {
|
|
123
|
-
backgroundColor: enumColor.incorrectWithIcon(),
|
|
124
|
-
},
|
|
125
|
-
correctnessIcon: {
|
|
126
|
-
borderRadius: theme.spacing.unit * 2,
|
|
127
|
-
color: enumColor.defaults.WHITE,
|
|
128
|
-
fontSize: '16px',
|
|
129
|
-
padding: '2px',
|
|
130
|
-
border: `4px solid ${enumColor.defaults.WHITE}`,
|
|
131
|
-
width: '16px',
|
|
132
|
-
height: '16px',
|
|
133
|
-
boxSizing: 'unset', // to override the default border-box in IBX
|
|
134
|
-
},
|
|
135
|
-
}))(RawDragHandle);
|
|
115
|
+
export const DragHandle = RawDragHandle;
|
|
136
116
|
|
|
137
117
|
export const D = gridDraggable({
|
|
138
118
|
axis: 'y',
|
package/src/common/drag-icon.jsx
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
2
3
|
import { getAdjustedX, getScale } from '../utils';
|
|
3
4
|
|
|
4
|
-
const DragIcon = ({ width, scaleValue, color
|
|
5
|
+
const DragIcon = ({ width, scaleValue, color }) => (
|
|
5
6
|
<svg
|
|
6
7
|
x={getAdjustedX(width, scaleValue)}
|
|
7
8
|
y={getScale(width)?.deltay}
|
|
@@ -10,7 +11,7 @@ const DragIcon = ({ width, scaleValue, color, classes }) => (
|
|
|
10
11
|
height={width}
|
|
11
12
|
overflow="visible"
|
|
12
13
|
viewBox={`0 0 ${width} ${width}`}
|
|
13
|
-
|
|
14
|
+
style={{ overflow: 'visible !important' }}
|
|
14
15
|
>
|
|
15
16
|
<g xmlns="http://www.w3.org/2000/svg" fill="currentColor" stroke="currentColor" transform={`scale(${scaleValue})`}>
|
|
16
17
|
<circle cx="28.5" cy="23.5" r="22" fill="white" stroke="currentColor" />
|
|
@@ -26,4 +27,10 @@ const DragIcon = ({ width, scaleValue, color, classes }) => (
|
|
|
26
27
|
</svg>
|
|
27
28
|
);
|
|
28
29
|
|
|
30
|
+
DragIcon.propTypes = {
|
|
31
|
+
width: PropTypes.number.isRequired,
|
|
32
|
+
scaleValue: PropTypes.number.isRequired,
|
|
33
|
+
color: PropTypes.string,
|
|
34
|
+
};
|
|
35
|
+
|
|
29
36
|
export default DragIcon;
|
package/src/common/styles.js
CHANGED
package/src/grid.jsx
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import { GridRows, GridColumns } from '@vx/grid';
|
|
3
|
+
import { styled } from '@mui/material/styles';
|
|
4
|
+
import { GridRows, GridColumns } from '@visx/grid';
|
|
6
5
|
|
|
7
6
|
import { types } from '@pie-lib/plot';
|
|
8
7
|
import { color } from '@pie-lib/render-ui';
|
|
9
8
|
|
|
9
|
+
const StyledGridGroup = styled('g')(() => ({
|
|
10
|
+
stroke: color.primaryLight(),
|
|
11
|
+
}));
|
|
12
|
+
|
|
10
13
|
export class Grid extends React.Component {
|
|
11
14
|
static propTypes = {
|
|
12
|
-
classes: PropTypes.object.isRequired,
|
|
13
15
|
className: PropTypes.string,
|
|
14
16
|
graphProps: types.GraphPropsType.isRequired,
|
|
15
17
|
xBand: PropTypes.func,
|
|
@@ -20,7 +22,7 @@ export class Grid extends React.Component {
|
|
|
20
22
|
static defaultProps = {};
|
|
21
23
|
|
|
22
24
|
render() {
|
|
23
|
-
const {
|
|
25
|
+
const { graphProps, xBand, rowTickValues, columnTickValues } = this.props;
|
|
24
26
|
const { scale = {}, size = {}, range = {} } = graphProps || {};
|
|
25
27
|
const { step = 0, labelStep = 0 } = range;
|
|
26
28
|
const highlightNonLabel = step && labelStep && step < labelStep;
|
|
@@ -38,7 +40,7 @@ export class Grid extends React.Component {
|
|
|
38
40
|
);
|
|
39
41
|
|
|
40
42
|
return (
|
|
41
|
-
<
|
|
43
|
+
<StyledGridGroup>
|
|
42
44
|
<GridRows
|
|
43
45
|
scale={scale.y}
|
|
44
46
|
width={size.width}
|
|
@@ -58,15 +60,9 @@ export class Grid extends React.Component {
|
|
|
58
60
|
}}
|
|
59
61
|
/>
|
|
60
62
|
<GridColumns scale={xBand} height={size.height} offset={xBand.bandwidth() / 2} tickValues={columnTickValues} />
|
|
61
|
-
</
|
|
63
|
+
</StyledGridGroup>
|
|
62
64
|
);
|
|
63
65
|
}
|
|
64
66
|
}
|
|
65
67
|
|
|
66
|
-
|
|
67
|
-
grid: {
|
|
68
|
-
stroke: color.primaryLight(),
|
|
69
|
-
},
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
export default withStyles(styles)(Grid);
|
|
68
|
+
export default Grid;
|