@pie-lib/charting 5.36.3-next.2 → 5.36.3-next.205
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 +24 -87
- package/lib/actions-button.js +60 -90
- package/lib/actions-button.js.map +1 -1
- package/lib/axes.js +162 -238
- package/lib/axes.js.map +1 -1
- package/lib/bars/bar.js +13 -41
- package/lib/bars/bar.js.map +1 -1
- package/lib/bars/common/bars.js +61 -137
- package/lib/bars/common/bars.js.map +1 -1
- package/lib/bars/common/correct-check-icon.js +5 -6
- package/lib/bars/common/correct-check-icon.js.map +1 -1
- package/lib/bars/histogram.js +13 -41
- package/lib/bars/histogram.js.map +1 -1
- package/lib/chart-setup.js +119 -195
- package/lib/chart-setup.js.map +1 -1
- package/lib/chart-type.js +52 -43
- package/lib/chart-type.js.map +1 -1
- package/lib/chart-types.js +1 -10
- package/lib/chart-types.js.map +1 -1
- package/lib/chart.js +73 -151
- package/lib/chart.js.map +1 -1
- package/lib/common/correctness-indicators.js +109 -52
- package/lib/common/correctness-indicators.js.map +1 -1
- package/lib/common/drag-handle.js +65 -108
- package/lib/common/drag-handle.js.map +1 -1
- package/lib/common/drag-icon.js +12 -12
- package/lib/common/drag-icon.js.map +1 -1
- package/lib/common/styles.js +6 -24
- package/lib/common/styles.js.map +1 -1
- package/lib/grid.js +43 -83
- package/lib/grid.js.map +1 -1
- package/lib/index.js +0 -6
- package/lib/index.js.map +1 -1
- package/lib/key-legend.js +63 -87
- package/lib/key-legend.js.map +1 -1
- package/lib/line/common/drag-handle.js +72 -100
- package/lib/line/common/drag-handle.js.map +1 -1
- package/lib/line/common/line.js +50 -96
- package/lib/line/common/line.js.map +1 -1
- package/lib/line/line-cross.js +79 -89
- package/lib/line/line-cross.js.map +1 -1
- package/lib/line/line-dot.js +58 -76
- package/lib/line/line-dot.js.map +1 -1
- package/lib/mark-label.js +84 -119
- package/lib/mark-label.js.map +1 -1
- package/lib/plot/common/plot.js +90 -148
- package/lib/plot/common/plot.js.map +1 -1
- package/lib/plot/dot.js +32 -58
- package/lib/plot/dot.js.map +1 -1
- package/lib/plot/line.js +39 -64
- package/lib/plot/line.js.map +1 -1
- package/lib/tool-menu.js +47 -83
- package/lib/tool-menu.js.map +1 -1
- package/lib/utils.js +31 -86
- 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
|
@@ -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;
|
package/src/key-legend.jsx
CHANGED
|
@@ -1,75 +1,77 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
|
-
import {
|
|
4
|
-
import Check from '@
|
|
5
|
-
import Close from '@
|
|
3
|
+
import { styled } from '@mui/material/styles';
|
|
4
|
+
import Check from '@mui/icons-material/Check';
|
|
5
|
+
import Close from '@mui/icons-material/Close';
|
|
6
6
|
import { color } from '@pie-lib/render-ui';
|
|
7
7
|
import Translator from '@pie-lib/translator';
|
|
8
8
|
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
},
|
|
19
|
-
row: {
|
|
20
|
-
display: 'flex',
|
|
21
|
-
alignItems: 'center',
|
|
22
|
-
gap: '12px',
|
|
23
|
-
},
|
|
24
|
-
title: {
|
|
25
|
-
fontSize: theme.typography.h6.fontSize,
|
|
26
|
-
fontWeight: '700',
|
|
27
|
-
},
|
|
28
|
-
smallText: {
|
|
29
|
-
marginLeft: '2px',
|
|
30
|
-
},
|
|
31
|
-
correctIcon: {
|
|
32
|
-
backgroundColor: color.correct(),
|
|
33
|
-
borderRadius: theme.spacing.unit * 2,
|
|
34
|
-
color: color.defaults.WHITE,
|
|
35
|
-
},
|
|
36
|
-
incorrectIcon: {
|
|
37
|
-
backgroundColor: color.incorrectWithIcon(),
|
|
38
|
-
borderRadius: theme.spacing.unit * 2,
|
|
39
|
-
color: color.defaults.WHITE,
|
|
40
|
-
},
|
|
9
|
+
const StyledContainer = styled('div')(({ theme }) => ({
|
|
10
|
+
backgroundColor: color.defaults.WHITE,
|
|
11
|
+
padding: theme.spacing(2),
|
|
12
|
+
width: '355px',
|
|
13
|
+
boxShadow: 'inset 0px 1px 5px 0px #9297A6',
|
|
14
|
+
display: 'flex',
|
|
15
|
+
flexDirection: 'column',
|
|
16
|
+
gap: '16px',
|
|
17
|
+
}));
|
|
41
18
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
})
|
|
19
|
+
const StyledRow = styled('div')(() => ({
|
|
20
|
+
display: 'flex',
|
|
21
|
+
alignItems: 'center',
|
|
22
|
+
gap: '12px',
|
|
23
|
+
}));
|
|
24
|
+
|
|
25
|
+
const StyledTitle = styled('div')(({ theme }) => ({
|
|
26
|
+
fontSize: theme.typography.h6.fontSize,
|
|
27
|
+
fontWeight: '700',
|
|
28
|
+
}));
|
|
29
|
+
|
|
30
|
+
const StyledSmallText = styled('div')(() => ({
|
|
31
|
+
marginLeft: '2px',
|
|
32
|
+
}));
|
|
33
|
+
|
|
34
|
+
const StyledCorrectIcon = styled(Check)(({ theme }) => ({
|
|
35
|
+
backgroundColor: color.correct(),
|
|
36
|
+
borderRadius: theme.spacing(2),
|
|
37
|
+
color: color.defaults.WHITE,
|
|
38
|
+
}));
|
|
39
|
+
|
|
40
|
+
const StyledIncorrectIcon = styled(Close)(({ theme }) => ({
|
|
41
|
+
backgroundColor: color.incorrectWithIcon(),
|
|
42
|
+
borderRadius: theme.spacing(2),
|
|
43
|
+
color: color.defaults.WHITE,
|
|
44
|
+
}));
|
|
45
|
+
|
|
46
|
+
const StyledLastRow = styled('div')(() => ({
|
|
47
|
+
marginLeft: '3px',
|
|
48
|
+
display: 'flex',
|
|
49
|
+
alignItems: 'center',
|
|
50
|
+
gap: '12px',
|
|
51
|
+
}));
|
|
49
52
|
|
|
50
53
|
const { translator } = Translator;
|
|
51
54
|
|
|
52
|
-
const KeyLegend = ({
|
|
53
|
-
<
|
|
54
|
-
<
|
|
55
|
-
<
|
|
56
|
-
<
|
|
57
|
-
<div
|
|
58
|
-
</
|
|
59
|
-
<
|
|
60
|
-
<
|
|
61
|
-
<div
|
|
62
|
-
</
|
|
63
|
-
<
|
|
64
|
-
<
|
|
65
|
-
<
|
|
66
|
-
</
|
|
67
|
-
</
|
|
55
|
+
const KeyLegend = ({ language }) => (
|
|
56
|
+
<StyledContainer>
|
|
57
|
+
<StyledTitle>Key</StyledTitle>
|
|
58
|
+
<StyledRow>
|
|
59
|
+
<StyledIncorrectIcon />
|
|
60
|
+
<div>{translator.t('charting.keyLegend.incorrectAnswer', { lng: language })}</div>
|
|
61
|
+
</StyledRow>
|
|
62
|
+
<StyledRow>
|
|
63
|
+
<StyledCorrectIcon />
|
|
64
|
+
<div>{translator.t('charting.keyLegend.correctAnswer', { lng: language })}</div>
|
|
65
|
+
</StyledRow>
|
|
66
|
+
<StyledLastRow>
|
|
67
|
+
<StyledCorrectIcon fontSize={'small'} />
|
|
68
|
+
<StyledSmallText>{translator.t('charting.keyLegend.correctKeyAnswer', { lng: language })}</StyledSmallText>
|
|
69
|
+
</StyledLastRow>
|
|
70
|
+
</StyledContainer>
|
|
68
71
|
);
|
|
69
72
|
|
|
70
73
|
KeyLegend.propTypes = {
|
|
71
|
-
classes: PropTypes.object.isRequired,
|
|
72
74
|
language: PropTypes.string,
|
|
73
75
|
};
|
|
74
76
|
|
|
75
|
-
export default
|
|
77
|
+
export default KeyLegend;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { shallow } from 'enzyme';
|
|
2
1
|
import React from 'react';
|
|
2
|
+
import { render } from '@pie-lib/test-utils';
|
|
3
3
|
import Line, { LineCross as LineChart } from '../line-cross';
|
|
4
4
|
import { graphProps } from './utils';
|
|
5
|
-
import { Bar as BarChart } from '../../bars/bar';
|
|
6
5
|
|
|
7
6
|
describe('LineChart', () => {
|
|
8
|
-
const
|
|
7
|
+
const renderComponent = (extras) => {
|
|
9
8
|
const defaults = {
|
|
10
9
|
classes: {},
|
|
11
10
|
className: 'className',
|
|
12
11
|
graphProps: graphProps(),
|
|
12
|
+
data: [],
|
|
13
13
|
xBand: () => {
|
|
14
14
|
return {
|
|
15
15
|
bandwidth: () => {},
|
|
@@ -17,22 +17,25 @@ describe('LineChart', () => {
|
|
|
17
17
|
},
|
|
18
18
|
};
|
|
19
19
|
const props = { ...defaults, ...extras };
|
|
20
|
-
return
|
|
20
|
+
return render(<LineChart {...props} />);
|
|
21
21
|
};
|
|
22
22
|
|
|
23
|
-
describe('
|
|
24
|
-
it('renders', () =>
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
describe('rendering', () => {
|
|
24
|
+
it('renders line cross chart', () => {
|
|
25
|
+
const { container } = renderComponent();
|
|
26
|
+
expect(container.firstChild).toBeInTheDocument();
|
|
27
|
+
});
|
|
27
28
|
});
|
|
28
29
|
|
|
29
30
|
describe('component', () => {
|
|
30
|
-
|
|
31
|
+
it('returns correct chart object', () => {
|
|
32
|
+
const chart = Line();
|
|
31
33
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
expect(chart).toEqual({
|
|
35
|
+
type: 'lineCross',
|
|
36
|
+
Component: LineChart,
|
|
37
|
+
name: 'Line Cross',
|
|
38
|
+
});
|
|
36
39
|
});
|
|
37
40
|
});
|
|
38
41
|
});
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { shallow } from 'enzyme';
|
|
2
1
|
import React from 'react';
|
|
2
|
+
import { render } from '@pie-lib/test-utils';
|
|
3
3
|
import Line, { LineDot as LineChart } from '../line-dot';
|
|
4
4
|
import { graphProps } from './utils';
|
|
5
|
-
import { Bar as BarChart } from '../../bars/bar';
|
|
6
5
|
|
|
7
6
|
describe('LineChart', () => {
|
|
8
|
-
const
|
|
7
|
+
const renderComponent = (extras) => {
|
|
9
8
|
const defaults = {
|
|
10
9
|
classes: {},
|
|
11
10
|
className: 'className',
|
|
12
11
|
graphProps: graphProps(),
|
|
12
|
+
data: [],
|
|
13
13
|
xBand: () => {
|
|
14
14
|
return {
|
|
15
15
|
bandwidth: () => {},
|
|
@@ -17,22 +17,25 @@ describe('LineChart', () => {
|
|
|
17
17
|
},
|
|
18
18
|
};
|
|
19
19
|
const props = { ...defaults, ...extras };
|
|
20
|
-
return
|
|
20
|
+
return render(<LineChart {...props} />);
|
|
21
21
|
};
|
|
22
22
|
|
|
23
|
-
describe('
|
|
24
|
-
it('renders', () =>
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
describe('rendering', () => {
|
|
24
|
+
it('renders line dot chart', () => {
|
|
25
|
+
const { container } = renderComponent();
|
|
26
|
+
expect(container.firstChild).toBeInTheDocument();
|
|
27
|
+
});
|
|
27
28
|
});
|
|
28
29
|
|
|
29
30
|
describe('component', () => {
|
|
30
|
-
|
|
31
|
+
it('returns correct chart object', () => {
|
|
32
|
+
const chart = Line();
|
|
31
33
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
expect(chart).toEqual({
|
|
35
|
+
type: 'lineDot',
|
|
36
|
+
Component: LineChart,
|
|
37
|
+
name: 'Line Dot',
|
|
38
|
+
});
|
|
36
39
|
});
|
|
37
40
|
});
|
|
38
41
|
});
|
|
@@ -1,13 +1,19 @@
|
|
|
1
|
+
import { scaleLinear, scaleBand } from 'd3-scale';
|
|
2
|
+
|
|
1
3
|
export const scaleMock = () => {
|
|
2
4
|
const fn = jest.fn((n) => n);
|
|
3
5
|
fn.invert = jest.fn((n) => n);
|
|
4
6
|
return fn;
|
|
5
7
|
};
|
|
6
8
|
|
|
9
|
+
export const createBandScale = (domain = [], range = [0, 400]) => {
|
|
10
|
+
return scaleBand().domain(domain).range(range).padding(0.1);
|
|
11
|
+
};
|
|
12
|
+
|
|
7
13
|
export const graphProps = (dmin = 0, dmax = 1, rmin = 0, rmax = 1) => ({
|
|
8
14
|
scale: {
|
|
9
|
-
x:
|
|
10
|
-
y:
|
|
15
|
+
x: scaleLinear().domain([dmin, dmax]).range([0, 400]),
|
|
16
|
+
y: scaleLinear().domain([rmin, rmax]).range([400, 0]),
|
|
11
17
|
},
|
|
12
18
|
snap: {
|
|
13
19
|
x: jest.fn((n) => n),
|