@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/line/common/line.jsx
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { Group } from '@
|
|
3
|
-
import { LinePath } from '@
|
|
2
|
+
import { Group } from '@visx/group';
|
|
3
|
+
import { LinePath } from '@visx/shape';
|
|
4
4
|
import PropTypes from 'prop-types';
|
|
5
5
|
import { types } from '@pie-lib/plot';
|
|
6
6
|
import DraggableHandle, { DragHandle } from './drag-handle';
|
|
7
|
-
import {
|
|
7
|
+
import { styled } from '@mui/material/styles';
|
|
8
8
|
import isEqual from 'lodash/isEqual';
|
|
9
9
|
import { color } from '@pie-lib/render-ui';
|
|
10
10
|
|
|
@@ -23,11 +23,17 @@ const getData = (data, domain) => {
|
|
|
23
23
|
}));
|
|
24
24
|
};
|
|
25
25
|
|
|
26
|
+
const StyledLinePath = styled(LinePath)(() => ({
|
|
27
|
+
fill: 'transparent',
|
|
28
|
+
stroke: color.defaults.TERTIARY,
|
|
29
|
+
strokeWidth: 3,
|
|
30
|
+
transition: 'stroke 200ms ease-in, stroke-width 200ms ease-in',
|
|
31
|
+
}));
|
|
32
|
+
|
|
26
33
|
export class RawLine extends React.Component {
|
|
27
34
|
static propTypes = {
|
|
28
35
|
onChange: PropTypes.func,
|
|
29
36
|
value: PropTypes.number,
|
|
30
|
-
classes: PropTypes.object,
|
|
31
37
|
label: PropTypes.string,
|
|
32
38
|
xBand: PropTypes.func,
|
|
33
39
|
index: PropTypes.number.isRequired,
|
|
@@ -40,6 +46,7 @@ export class RawLine extends React.Component {
|
|
|
40
46
|
}),
|
|
41
47
|
),
|
|
42
48
|
CustomDraggableComponent: PropTypes.func,
|
|
49
|
+
correctData: PropTypes.array,
|
|
43
50
|
};
|
|
44
51
|
|
|
45
52
|
static defaultProps = {
|
|
@@ -78,25 +85,25 @@ export class RawLine extends React.Component {
|
|
|
78
85
|
};
|
|
79
86
|
|
|
80
87
|
render() {
|
|
81
|
-
const { graphProps, data,
|
|
88
|
+
const { graphProps, data, CustomDraggableComponent, defineChart, correctData } = this.props;
|
|
82
89
|
const { line: lineState, dragging } = this.state;
|
|
83
90
|
const { scale } = graphProps;
|
|
84
91
|
const lineToUse = dragging ? lineState : getData(data, graphProps.domain);
|
|
85
92
|
|
|
86
93
|
return (
|
|
87
94
|
<React.Fragment>
|
|
88
|
-
<
|
|
95
|
+
<StyledLinePath
|
|
89
96
|
data={lineToUse}
|
|
90
97
|
x={(d) => scale.x(d.x)}
|
|
91
98
|
y={(d) => scale.y(d.dragValue !== undefined ? d.dragValue : d.y)}
|
|
92
|
-
className=
|
|
99
|
+
className="line"
|
|
93
100
|
/>
|
|
94
101
|
{lineToUse &&
|
|
95
102
|
lineToUse.map((point, i) => {
|
|
96
103
|
const r = 6;
|
|
97
104
|
const enableDraggable = defineChart || point.interactive;
|
|
98
105
|
const Component = enableDraggable ? DraggableHandle : DragHandle;
|
|
99
|
-
|
|
106
|
+
|
|
100
107
|
return (
|
|
101
108
|
<Component
|
|
102
109
|
key={`point-${point.x}-${i}`}
|
|
@@ -120,14 +127,14 @@ export class RawLine extends React.Component {
|
|
|
120
127
|
}
|
|
121
128
|
}
|
|
122
129
|
|
|
123
|
-
const StyledLine =
|
|
124
|
-
line: {
|
|
130
|
+
const StyledLine = styled(RawLine)(() => ({
|
|
131
|
+
'& .line': {
|
|
125
132
|
fill: 'transparent',
|
|
126
133
|
stroke: color.defaults.TERTIARY,
|
|
127
134
|
strokeWidth: 3,
|
|
128
135
|
transition: 'stroke 200ms ease-in, stroke-width 200ms ease-in',
|
|
129
136
|
},
|
|
130
|
-
}))
|
|
137
|
+
}));
|
|
131
138
|
|
|
132
139
|
export class Line extends React.Component {
|
|
133
140
|
static propTypes = {
|
|
@@ -135,6 +142,9 @@ export class Line extends React.Component {
|
|
|
135
142
|
onChange: PropTypes.func,
|
|
136
143
|
xBand: PropTypes.func,
|
|
137
144
|
graphProps: types.GraphPropsType.isRequired,
|
|
145
|
+
CustomDraggableComponent: PropTypes.func,
|
|
146
|
+
defineChart: PropTypes.bool,
|
|
147
|
+
correctData: PropTypes.array,
|
|
138
148
|
};
|
|
139
149
|
|
|
140
150
|
changeLine = (index, category) => {
|
package/src/line/line-cross.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import React, { useState } from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
|
-
import { LinePath } from '@
|
|
4
|
-
import { Group } from '@
|
|
5
|
-
import
|
|
3
|
+
import { LinePath } from '@visx/shape';
|
|
4
|
+
import { Group } from '@visx/group';
|
|
5
|
+
import { styled } from '@mui/material/styles';
|
|
6
6
|
|
|
7
7
|
import { color } from '@pie-lib/render-ui';
|
|
8
8
|
import { dataToXBand } from '../utils';
|
|
@@ -10,18 +10,44 @@ import { types } from '@pie-lib/plot';
|
|
|
10
10
|
import RawLine from './common/line';
|
|
11
11
|
import { CorrectnessIndicator, SmallCorrectPointIndicator } from '../common/correctness-indicators';
|
|
12
12
|
|
|
13
|
+
const StyledLinePath = styled(LinePath)(() => ({
|
|
14
|
+
stroke: color.defaults.TEXT,
|
|
15
|
+
transition: 'fill 200ms linear, height 200ms linear',
|
|
16
|
+
'&.non-interactive': {
|
|
17
|
+
stroke: color.disabled?.() || '#ccc',
|
|
18
|
+
},
|
|
19
|
+
}));
|
|
20
|
+
|
|
21
|
+
const StyledGroup = styled(Group)(({ correctness, interactive }) => ({
|
|
22
|
+
stroke: color.defaults.TEXT,
|
|
23
|
+
transition: 'fill 200ms linear, height 200ms linear',
|
|
24
|
+
...(correctness && !interactive && {
|
|
25
|
+
fill: `${color.defaults.BLACK} !important`,
|
|
26
|
+
stroke: `${color.defaults.BLACK} !important`,
|
|
27
|
+
}),
|
|
28
|
+
'&.non-interactive': {
|
|
29
|
+
stroke: color.disabled?.() || '#ccc',
|
|
30
|
+
},
|
|
31
|
+
}));
|
|
32
|
+
|
|
33
|
+
const StyledTransparentHandle = styled('circle')(() => ({
|
|
34
|
+
height: '20px',
|
|
35
|
+
fill: 'transparent',
|
|
36
|
+
stroke: 'transparent',
|
|
37
|
+
}));
|
|
38
|
+
|
|
13
39
|
const DraggableComponent = (props) => {
|
|
14
|
-
const {
|
|
40
|
+
const { className, scale, x, y, r, correctness, interactive, correctData, label, ...rest } = props;
|
|
15
41
|
const [hover, setHover] = useState(false);
|
|
16
42
|
|
|
17
43
|
const squareSize = r * 4;
|
|
18
44
|
const squareHalf = squareSize / 2;
|
|
19
45
|
const cx = scale.x(x);
|
|
20
46
|
const cy = scale.y(y);
|
|
21
|
-
|
|
47
|
+
|
|
22
48
|
return (
|
|
23
|
-
<
|
|
24
|
-
<
|
|
49
|
+
<StyledGroup className={className} correctness={correctness} interactive={interactive}>
|
|
50
|
+
<StyledLinePath
|
|
25
51
|
data={[
|
|
26
52
|
{ x: scale.x(x) - r, y: scale.y(y) + r },
|
|
27
53
|
{ x: scale.x(x) + r, y: scale.y(y) - r },
|
|
@@ -32,7 +58,7 @@ const DraggableComponent = (props) => {
|
|
|
32
58
|
strokeWidth={5}
|
|
33
59
|
style={{ pointerEvents: 'none' }}
|
|
34
60
|
/>
|
|
35
|
-
<
|
|
61
|
+
<StyledLinePath
|
|
36
62
|
data={[
|
|
37
63
|
{ x: scale.x(x) - r, y: scale.y(y) - r },
|
|
38
64
|
{ x: scale.x(x) + r, y: scale.y(y) + r },
|
|
@@ -55,11 +81,10 @@ const DraggableComponent = (props) => {
|
|
|
55
81
|
pointerEvents="none"
|
|
56
82
|
/>
|
|
57
83
|
)}
|
|
58
|
-
<
|
|
84
|
+
<StyledTransparentHandle
|
|
59
85
|
cx={cx}
|
|
60
86
|
cy={cy}
|
|
61
87
|
r={r * 2}
|
|
62
|
-
className={classNames(classes.transparentHandle)}
|
|
63
88
|
onMouseEnter={() => setHover(true)}
|
|
64
89
|
onMouseLeave={() => setHover(false)}
|
|
65
90
|
{...rest}
|
|
@@ -69,7 +94,6 @@ const DraggableComponent = (props) => {
|
|
|
69
94
|
scale={scale}
|
|
70
95
|
x={x}
|
|
71
96
|
y={y}
|
|
72
|
-
classes={classes}
|
|
73
97
|
r={r}
|
|
74
98
|
correctness={correctness}
|
|
75
99
|
interactive={interactive}
|
|
@@ -80,11 +104,10 @@ const DraggableComponent = (props) => {
|
|
|
80
104
|
x={x}
|
|
81
105
|
r={r}
|
|
82
106
|
correctness={correctness}
|
|
83
|
-
classes={classes}
|
|
84
107
|
correctData={correctData}
|
|
85
108
|
label={label}
|
|
86
109
|
/>
|
|
87
|
-
</
|
|
110
|
+
</StyledGroup>
|
|
88
111
|
);
|
|
89
112
|
};
|
|
90
113
|
|
|
@@ -94,11 +117,13 @@ DraggableComponent.propTypes = {
|
|
|
94
117
|
y: PropTypes.number,
|
|
95
118
|
r: PropTypes.number,
|
|
96
119
|
className: PropTypes.string,
|
|
97
|
-
classes: PropTypes.object,
|
|
98
120
|
correctness: PropTypes.shape({
|
|
99
121
|
value: PropTypes.string,
|
|
100
122
|
label: PropTypes.string,
|
|
101
123
|
}),
|
|
124
|
+
interactive: PropTypes.bool,
|
|
125
|
+
correctData: PropTypes.array,
|
|
126
|
+
label: PropTypes.string,
|
|
102
127
|
};
|
|
103
128
|
|
|
104
129
|
export class LineCross extends React.Component {
|
package/src/line/line-dot.js
CHANGED
|
@@ -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
|
|
|
5
5
|
import { types } from '@pie-lib/plot';
|
|
6
6
|
import { color } from '@pie-lib/render-ui';
|
|
@@ -8,49 +8,44 @@ import { dataToXBand } from '../utils';
|
|
|
8
8
|
import RawLine from './common/line';
|
|
9
9
|
import { CorrectnessIndicator, SmallCorrectPointIndicator } from '../common/correctness-indicators';
|
|
10
10
|
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
label,
|
|
22
|
-
...rest
|
|
23
|
-
}) => {
|
|
11
|
+
const StyledHandle = styled('circle')(() => ({}));
|
|
12
|
+
|
|
13
|
+
const StyledTransparentHandle = styled('circle')(() => ({
|
|
14
|
+
height: '20px',
|
|
15
|
+
fill: 'transparent', // keep it invisible
|
|
16
|
+
stroke: 'none',
|
|
17
|
+
pointerEvents: 'auto', // allow drag events
|
|
18
|
+
}));
|
|
19
|
+
|
|
20
|
+
const DraggableComponent = ({ scale, x, y, r, correctness, interactive, correctData, label, ...rest }) => {
|
|
24
21
|
const [isHovered, setIsHovered] = React.useState(false);
|
|
25
22
|
const allowRolloverEvent = !correctness && interactive;
|
|
26
23
|
|
|
27
24
|
return (
|
|
28
|
-
<g
|
|
29
|
-
|
|
25
|
+
<g
|
|
26
|
+
onMouseEnter={() => setIsHovered(true)}
|
|
27
|
+
onMouseLeave={() => setIsHovered(false)}
|
|
28
|
+
onTouchStart={() => setIsHovered(true)}
|
|
29
|
+
onTouchEnd={() => setIsHovered(false)}
|
|
30
|
+
>
|
|
31
|
+
<StyledTransparentHandle
|
|
30
32
|
cx={scale.x(x)}
|
|
31
33
|
cy={scale.y(y)}
|
|
32
34
|
r={r * 3}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
+
onMouseEnter={() => setIsHovered(true)}
|
|
36
|
+
onMouseLeave={() => setIsHovered(false)}
|
|
35
37
|
{...rest}
|
|
36
38
|
/>
|
|
37
|
-
<
|
|
39
|
+
<StyledHandle
|
|
38
40
|
cx={scale.x(x)}
|
|
39
41
|
cy={scale.y(y)}
|
|
40
42
|
r={r}
|
|
41
|
-
className={classNames(className, classes.handle, correctness && !interactive && classes.disabledPoint)}
|
|
42
|
-
{...rest}
|
|
43
|
-
/>
|
|
44
|
-
{/* show correctness indicators */}
|
|
45
|
-
<CorrectnessIndicator
|
|
46
|
-
scale={scale}
|
|
47
|
-
x={x}
|
|
48
|
-
y={y}
|
|
49
|
-
classes={classes}
|
|
50
|
-
r={r}
|
|
51
43
|
correctness={correctness}
|
|
52
44
|
interactive={interactive}
|
|
45
|
+
{...rest}
|
|
53
46
|
/>
|
|
47
|
+
{/* show correctness indicators */}
|
|
48
|
+
<CorrectnessIndicator scale={scale} x={x} y={y} r={r} correctness={correctness} interactive={interactive} />
|
|
54
49
|
|
|
55
50
|
{/* show correct point if answer was incorrect */}
|
|
56
51
|
<SmallCorrectPointIndicator
|
|
@@ -58,7 +53,6 @@ const DraggableComponent = ({
|
|
|
58
53
|
x={x}
|
|
59
54
|
r={r}
|
|
60
55
|
correctness={correctness}
|
|
61
|
-
classes={classes}
|
|
62
56
|
correctData={correctData}
|
|
63
57
|
label={label}
|
|
64
58
|
/>
|
|
@@ -84,12 +78,13 @@ DraggableComponent.propTypes = {
|
|
|
84
78
|
x: PropTypes.number,
|
|
85
79
|
y: PropTypes.number,
|
|
86
80
|
r: PropTypes.number,
|
|
87
|
-
className: PropTypes.string,
|
|
88
|
-
classes: PropTypes.object,
|
|
89
81
|
correctness: PropTypes.shape({
|
|
90
82
|
value: PropTypes.string,
|
|
91
83
|
label: PropTypes.string,
|
|
92
84
|
}),
|
|
85
|
+
interactive: PropTypes.bool,
|
|
86
|
+
correctData: PropTypes.array,
|
|
87
|
+
label: PropTypes.string,
|
|
93
88
|
};
|
|
94
89
|
|
|
95
90
|
export class LineDot extends React.Component {
|
package/src/mark-label.jsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, { useState, useCallback, useEffect, useRef } from 'react';
|
|
2
2
|
import classNames from 'classnames';
|
|
3
|
-
import {
|
|
3
|
+
import { styled } from '@mui/material/styles';
|
|
4
4
|
import AutosizeInput from 'react-input-autosize';
|
|
5
5
|
import PropTypes from 'prop-types';
|
|
6
6
|
|
|
@@ -9,46 +9,47 @@ import { correct, incorrect, disabled } from './common/styles';
|
|
|
9
9
|
import { color } from '@pie-lib/render-ui';
|
|
10
10
|
import { renderMath } from '@pie-lib/math-rendering';
|
|
11
11
|
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
fontSize: theme.typography.fontSize + 2,
|
|
29
|
-
fontFamily: theme.typography.fontFamily,
|
|
30
|
-
color: color.primaryDark(),
|
|
31
|
-
paddingTop: theme.typography.fontSize / 2,
|
|
12
|
+
const StyledContainer = styled('div')({
|
|
13
|
+
display: 'flex',
|
|
14
|
+
flexDirection: 'column',
|
|
15
|
+
alignItems: 'center',
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
// eslint-disable-next-line no-unused-vars
|
|
19
|
+
const StyledInput = styled('input')(({ theme }) => ({
|
|
20
|
+
float: 'right',
|
|
21
|
+
fontFamily: theme.typography.fontFamily,
|
|
22
|
+
fontSize: theme.typography.fontSize,
|
|
23
|
+
border: 'none',
|
|
24
|
+
'&.correct': correct('color'),
|
|
25
|
+
'&.incorrect': incorrect('color'),
|
|
26
|
+
'&.disabled': {
|
|
27
|
+
backgroundColor: 'transparent !important',
|
|
32
28
|
},
|
|
33
|
-
|
|
29
|
+
'&.error': { border: `2px solid ${theme.palette.error.main}` },
|
|
30
|
+
}));
|
|
31
|
+
|
|
32
|
+
const StyledMathInput = styled('div')(({ theme }) => ({
|
|
33
|
+
pointerEvents: 'auto',
|
|
34
|
+
textAlign: 'center',
|
|
35
|
+
fontSize: theme.typography.fontSize + 2,
|
|
36
|
+
fontFamily: theme.typography.fontFamily,
|
|
37
|
+
color: color.primaryDark(),
|
|
38
|
+
paddingTop: theme.typography.fontSize / 2,
|
|
39
|
+
'&.disabled': {
|
|
34
40
|
...disabled('color'),
|
|
35
41
|
backgroundColor: 'transparent !important',
|
|
36
42
|
},
|
|
37
|
-
error: {
|
|
43
|
+
'&.error': {
|
|
38
44
|
border: `2px solid ${theme.palette.error.main}`,
|
|
39
45
|
},
|
|
40
|
-
correct: {
|
|
46
|
+
'&.correct': {
|
|
41
47
|
...correct('color'),
|
|
42
48
|
},
|
|
43
|
-
incorrect: {
|
|
49
|
+
'&.incorrect': {
|
|
44
50
|
...incorrect('color'),
|
|
45
51
|
},
|
|
46
|
-
|
|
47
|
-
display: 'flex',
|
|
48
|
-
flexDirection: 'column',
|
|
49
|
-
alignItems: 'center',
|
|
50
|
-
},
|
|
51
|
-
});
|
|
52
|
+
}));
|
|
52
53
|
|
|
53
54
|
function isFractionFormat(label) {
|
|
54
55
|
const trimmedLabel = label?.trim() || '';
|
|
@@ -84,8 +85,7 @@ export const MarkLabel = (props) => {
|
|
|
84
85
|
const _ref = useCallback((node) => setInput(node), null);
|
|
85
86
|
|
|
86
87
|
const {
|
|
87
|
-
mark,
|
|
88
|
-
classes,
|
|
88
|
+
mark = {},
|
|
89
89
|
disabled,
|
|
90
90
|
inputRef: externalInputRef,
|
|
91
91
|
barWidth,
|
|
@@ -139,20 +139,22 @@ export const MarkLabel = (props) => {
|
|
|
139
139
|
}, []);
|
|
140
140
|
|
|
141
141
|
return (
|
|
142
|
-
<
|
|
142
|
+
<StyledContainer>
|
|
143
143
|
{correctnessIndicator}
|
|
144
144
|
{isMathRendering() ? (
|
|
145
|
-
<
|
|
145
|
+
<StyledMathInput
|
|
146
146
|
ref={(r) => {
|
|
147
147
|
root = r;
|
|
148
|
-
externalInputRef
|
|
148
|
+
if (typeof externalInputRef === 'function') {
|
|
149
|
+
externalInputRef(r);
|
|
150
|
+
}
|
|
149
151
|
}}
|
|
150
152
|
dangerouslySetInnerHTML={{ __html: getLabelMathFormat(label) }}
|
|
151
|
-
className={classNames(
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
153
|
+
className={classNames({
|
|
154
|
+
disabled: disabled,
|
|
155
|
+
error: error,
|
|
156
|
+
correct: mark.editable && correctness?.label === 'correct',
|
|
157
|
+
incorrect: mark.editable && correctness?.label === 'incorrect',
|
|
156
158
|
})}
|
|
157
159
|
onClick={() => setIsEditing(true)}
|
|
158
160
|
style={{
|
|
@@ -163,17 +165,19 @@ export const MarkLabel = (props) => {
|
|
|
163
165
|
visibility: isHiddenLabel ? 'hidden' : 'unset',
|
|
164
166
|
marginTop: correctnessIndicator ? '24px' : '0',
|
|
165
167
|
}}
|
|
166
|
-
></
|
|
168
|
+
></StyledMathInput>
|
|
167
169
|
) : (
|
|
168
170
|
<AutosizeInput
|
|
169
171
|
inputRef={(r) => {
|
|
170
172
|
_ref(r);
|
|
171
|
-
externalInputRef
|
|
173
|
+
if (typeof externalInputRef === 'function') {
|
|
174
|
+
externalInputRef(r);
|
|
175
|
+
}
|
|
172
176
|
}}
|
|
177
|
+
name='mark-label-input'
|
|
173
178
|
autoFocus={isEditing || autoFocus}
|
|
174
179
|
disabled={disabled}
|
|
175
180
|
inputClassName={classNames(
|
|
176
|
-
classes.input,
|
|
177
181
|
correctness && mark.editable ? correctness.label : null,
|
|
178
182
|
disabled && 'disabled',
|
|
179
183
|
error && 'error',
|
|
@@ -185,6 +189,7 @@ export const MarkLabel = (props) => {
|
|
|
185
189
|
boxSizing: 'border-box',
|
|
186
190
|
paddingLeft: 0,
|
|
187
191
|
paddingRight: 0,
|
|
192
|
+
border: 'none',
|
|
188
193
|
...extraStyle,
|
|
189
194
|
}}
|
|
190
195
|
value={label}
|
|
@@ -203,7 +208,7 @@ export const MarkLabel = (props) => {
|
|
|
203
208
|
onBlur={onChangeProp}
|
|
204
209
|
/>
|
|
205
210
|
)}
|
|
206
|
-
</
|
|
211
|
+
</StyledContainer>
|
|
207
212
|
);
|
|
208
213
|
};
|
|
209
214
|
|
|
@@ -213,7 +218,6 @@ MarkLabel.propTypes = {
|
|
|
213
218
|
error: PropTypes.any,
|
|
214
219
|
onChange: PropTypes.func,
|
|
215
220
|
graphProps: types.GraphPropsType,
|
|
216
|
-
classes: PropTypes.object,
|
|
217
221
|
inputRef: PropTypes.func,
|
|
218
222
|
mark: PropTypes.object,
|
|
219
223
|
barWidth: PropTypes.number,
|
|
@@ -227,4 +231,4 @@ MarkLabel.propTypes = {
|
|
|
227
231
|
correctnessIndicator: PropTypes.node,
|
|
228
232
|
};
|
|
229
233
|
|
|
230
|
-
export default
|
|
234
|
+
export default MarkLabel;
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { shallow } from 'enzyme';
|
|
2
1
|
import React from 'react';
|
|
2
|
+
import { render } from '@pie-lib/test-utils';
|
|
3
3
|
import Dot, { DotPlot } from '../dot';
|
|
4
4
|
import { graphProps } from './utils';
|
|
5
|
-
import { Bar as BarChart } from '../../bars/bar';
|
|
6
5
|
|
|
7
6
|
describe('DotPlot', () => {
|
|
8
|
-
const
|
|
7
|
+
const renderComponent = (extras) => {
|
|
9
8
|
const defaults = {
|
|
10
9
|
classes: {},
|
|
11
10
|
className: 'className',
|
|
@@ -17,22 +16,30 @@ describe('DotPlot', () => {
|
|
|
17
16
|
},
|
|
18
17
|
};
|
|
19
18
|
const props = { ...defaults, ...extras };
|
|
20
|
-
return
|
|
19
|
+
return render(<DotPlot {...props} />);
|
|
21
20
|
};
|
|
22
21
|
|
|
23
|
-
describe('
|
|
24
|
-
it('renders', () =>
|
|
22
|
+
describe('rendering', () => {
|
|
23
|
+
it('renders dot plot', () => {
|
|
24
|
+
const { container } = renderComponent();
|
|
25
|
+
expect(container.firstChild).toBeInTheDocument();
|
|
26
|
+
});
|
|
25
27
|
|
|
26
|
-
it('renders without graphProps', () =>
|
|
28
|
+
it('renders without graphProps', () => {
|
|
29
|
+
const { container } = renderComponent({ graphProps: undefined });
|
|
30
|
+
expect(container.firstChild).toBeInTheDocument();
|
|
31
|
+
});
|
|
27
32
|
});
|
|
28
33
|
|
|
29
34
|
describe('component', () => {
|
|
30
|
-
|
|
35
|
+
it('returns correct chart object', () => {
|
|
36
|
+
const chart = Dot();
|
|
31
37
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
38
|
+
expect(chart).toEqual({
|
|
39
|
+
type: 'dotPlot',
|
|
40
|
+
Component: DotPlot,
|
|
41
|
+
name: 'Dot Plot',
|
|
42
|
+
});
|
|
36
43
|
});
|
|
37
44
|
});
|
|
38
45
|
});
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { shallow } from 'enzyme';
|
|
2
1
|
import React from 'react';
|
|
2
|
+
import { render } from '@pie-lib/test-utils';
|
|
3
3
|
import Line, { LinePlot } from '../line';
|
|
4
4
|
import { graphProps } from './utils';
|
|
5
|
-
import { Bar as BarChart } from '../../bars/bar';
|
|
6
5
|
|
|
7
6
|
describe('LinePlot', () => {
|
|
8
|
-
const
|
|
7
|
+
const renderComponent = (extras) => {
|
|
9
8
|
const defaults = {
|
|
10
9
|
classes: {},
|
|
11
10
|
className: 'className',
|
|
@@ -17,22 +16,30 @@ describe('LinePlot', () => {
|
|
|
17
16
|
},
|
|
18
17
|
};
|
|
19
18
|
const props = { ...defaults, ...extras };
|
|
20
|
-
return
|
|
19
|
+
return render(<LinePlot {...props} />);
|
|
21
20
|
};
|
|
22
21
|
|
|
23
|
-
describe('
|
|
24
|
-
it('renders', () =>
|
|
22
|
+
describe('rendering', () => {
|
|
23
|
+
it('renders line plot', () => {
|
|
24
|
+
const { container } = renderComponent();
|
|
25
|
+
expect(container.firstChild).toBeInTheDocument();
|
|
26
|
+
});
|
|
25
27
|
|
|
26
|
-
it('renders without graphProps', () =>
|
|
28
|
+
it('renders without graphProps', () => {
|
|
29
|
+
const { container } = renderComponent({ graphProps: undefined });
|
|
30
|
+
expect(container.firstChild).toBeInTheDocument();
|
|
31
|
+
});
|
|
27
32
|
});
|
|
28
33
|
|
|
29
34
|
describe('component', () => {
|
|
30
|
-
|
|
35
|
+
it('returns correct chart object', () => {
|
|
36
|
+
const chart = Line();
|
|
31
37
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
38
|
+
expect(chart).toEqual({
|
|
39
|
+
type: 'linePlot',
|
|
40
|
+
Component: LinePlot,
|
|
41
|
+
name: 'Line Plot',
|
|
42
|
+
});
|
|
36
43
|
});
|
|
37
44
|
});
|
|
38
45
|
});
|