@pie-lib/charting 5.15.7-next.0 → 5.16.0-beta.1
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 +35 -65
- package/NEXT.CHANGELOG.json +1 -0
- package/lib/axes.js +74 -29
- package/lib/axes.js.map +1 -1
- package/lib/bars/common/bars.js +35 -1
- package/lib/bars/common/bars.js.map +1 -1
- package/lib/chart-type.js +4 -4
- package/lib/chart-type.js.map +1 -1
- package/lib/chart-types.js +2 -2
- package/lib/chart-types.js.map +1 -1
- package/lib/chart.js +25 -10
- package/lib/chart.js.map +1 -1
- package/lib/common/drag-handle.js +11 -5
- package/lib/common/drag-handle.js.map +1 -1
- package/lib/common/drag-icon.js +7 -24
- package/lib/common/drag-icon.js.map +1 -1
- package/lib/line/common/drag-handle.js +9 -4
- package/lib/line/common/drag-handle.js.map +1 -1
- package/lib/line/line-cross.js +16 -5
- package/lib/line/line-cross.js.map +1 -1
- package/lib/line/line-dot.js +10 -2
- package/lib/line/line-dot.js.map +1 -1
- package/lib/mark-label.js +20 -11
- package/lib/mark-label.js.map +1 -1
- package/lib/plot/common/plot.js +3 -1
- package/lib/plot/common/plot.js.map +1 -1
- package/lib/plot/dot.js +1 -1
- package/lib/plot/dot.js.map +1 -1
- package/lib/plot/line.js +1 -1
- package/lib/plot/line.js.map +1 -1
- package/lib/tool-menu.js +0 -4
- package/lib/tool-menu.js.map +1 -1
- package/package.json +32 -5
- package/src/__tests__/__snapshots__/axes.test.jsx.snap +564 -0
- package/src/__tests__/__snapshots__/chart-type.test.jsx.snap +14 -0
- package/src/__tests__/__snapshots__/chart.test.jsx.snap +610 -0
- package/src/__tests__/__snapshots__/grid.test.jsx.snap +28 -0
- package/src/__tests__/__snapshots__/mark-label.test.jsx.snap +67 -0
- package/src/__tests__/axes.test.jsx +146 -0
- package/src/__tests__/chart-setup.test.jsx +47 -0
- package/src/__tests__/chart-type.test.jsx +29 -0
- package/src/__tests__/chart.test.jsx +87 -0
- package/src/__tests__/grid.test.jsx +25 -0
- package/src/__tests__/mark-label.test.jsx +31 -0
- package/src/__tests__/utils.js +30 -0
- package/src/__tests__/utils.test.js +100 -0
- package/src/axes.jsx +59 -23
- package/src/bars/__tests__/__snapshots__/bar.test.jsx.snap +43 -0
- package/src/bars/__tests__/__snapshots__/histogram.test.jsx.snap +45 -0
- package/src/bars/__tests__/bar.test.jsx +37 -0
- package/src/bars/__tests__/histogram.test.jsx +38 -0
- package/src/bars/__tests__/utils.js +30 -0
- package/src/bars/common/__tests__/__snapshots__/bars.test.jsx.snap +110 -0
- package/src/bars/common/__tests__/bars.test.jsx +69 -0
- package/src/bars/common/__tests__/utils.js +30 -0
- package/src/bars/common/bars.jsx +37 -1
- package/src/chart-type.js +7 -3
- package/src/chart-types.js +2 -2
- package/src/chart.jsx +15 -5
- package/src/common/__tests__/__snapshots__/drag-handle.test.jsx.snap +45 -0
- package/src/common/__tests__/drag-handle.test.jsx +88 -0
- package/src/common/__tests__/utils.js +30 -0
- package/src/common/drag-handle.jsx +18 -10
- package/src/common/drag-icon.jsx +6 -21
- package/src/line/__tests__/__snapshots__/line-cross.test.jsx.snap +45 -0
- package/src/line/__tests__/__snapshots__/line-dot.test.jsx.snap +45 -0
- package/src/line/__tests__/line-cross.test.jsx +38 -0
- package/src/line/__tests__/line-dot.test.jsx +38 -0
- package/src/line/__tests__/utils.js +30 -0
- package/src/line/common/__tests__/__snapshots__/drag-handle.test.jsx.snap +44 -0
- package/src/line/common/__tests__/__snapshots__/line.test.jsx.snap +141 -0
- package/src/line/common/__tests__/drag-handle.test.jsx +88 -0
- package/src/line/common/__tests__/line.test.jsx +82 -0
- package/src/line/common/__tests__/utils.js +30 -0
- package/src/line/common/drag-handle.jsx +9 -4
- package/src/line/line-cross.js +4 -1
- package/src/line/line-dot.js +17 -7
- package/src/mark-label.jsx +19 -7
- package/src/plot/__tests__/__snapshots__/dot.test.jsx.snap +45 -0
- package/src/plot/__tests__/__snapshots__/line.test.jsx.snap +45 -0
- package/src/plot/__tests__/dot.test.jsx +38 -0
- package/src/plot/__tests__/line.test.jsx +38 -0
- package/src/plot/__tests__/utils.js +30 -0
- package/src/plot/common/__tests__/__snapshots__/plot.test.jsx.snap +96 -0
- package/src/plot/common/__tests__/plot.test.jsx +70 -0
- package/src/plot/common/__tests__/utils.js +30 -0
- package/src/plot/common/plot.jsx +6 -1
- package/src/plot/dot.js +1 -1
- package/src/plot/line.js +1 -1
- package/src/tool-menu.jsx +0 -4
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export const scaleMock = () => {
|
|
2
|
+
const fn = jest.fn((n) => n);
|
|
3
|
+
fn.invert = jest.fn((n) => n);
|
|
4
|
+
return fn;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export const graphProps = (dmin = 0, dmax = 1, rmin = 0, rmax = 1) => ({
|
|
8
|
+
scale: {
|
|
9
|
+
x: scaleMock(),
|
|
10
|
+
y: scaleMock(),
|
|
11
|
+
},
|
|
12
|
+
snap: {
|
|
13
|
+
x: jest.fn((n) => n),
|
|
14
|
+
y: jest.fn((n) => n),
|
|
15
|
+
},
|
|
16
|
+
domain: {
|
|
17
|
+
min: dmin,
|
|
18
|
+
max: dmax,
|
|
19
|
+
step: 1,
|
|
20
|
+
},
|
|
21
|
+
range: {
|
|
22
|
+
min: rmin,
|
|
23
|
+
max: rmax,
|
|
24
|
+
step: 1,
|
|
25
|
+
},
|
|
26
|
+
size: {
|
|
27
|
+
width: 400,
|
|
28
|
+
height: 400,
|
|
29
|
+
},
|
|
30
|
+
});
|
|
@@ -52,20 +52,25 @@ class RawDragHandle extends React.Component {
|
|
|
52
52
|
|
|
53
53
|
export const DragHandle = withStyles(() => ({
|
|
54
54
|
handle: {
|
|
55
|
-
fill: color.
|
|
55
|
+
fill: color.defaults.SECONDARY,
|
|
56
56
|
transition: 'fill 200ms linear, height 200ms linear',
|
|
57
57
|
'&:hover': {
|
|
58
|
-
fill: color.
|
|
58
|
+
fill: color.defaults.SECONDARY_DARK,
|
|
59
59
|
},
|
|
60
60
|
'&.correct': correct('fill'),
|
|
61
61
|
'&.incorrect': incorrect('fill'),
|
|
62
62
|
'&.non-interactive': disabled('fill'),
|
|
63
63
|
},
|
|
64
|
+
transparentHandle: {
|
|
65
|
+
height: '20px',
|
|
66
|
+
fill: 'transparent',
|
|
67
|
+
stroke: 'transparent',
|
|
68
|
+
},
|
|
64
69
|
line: {
|
|
65
|
-
stroke: color.
|
|
70
|
+
stroke: color.defaults.SECONDARY,
|
|
66
71
|
transition: 'fill 200ms linear, height 200ms linear',
|
|
67
72
|
'&:hover': {
|
|
68
|
-
stroke: color.
|
|
73
|
+
stroke: color.defaults.SECONDARY_DARK,
|
|
69
74
|
},
|
|
70
75
|
'&.non-interactive': disabled('stroke'),
|
|
71
76
|
'&.correct': correct('stroke'),
|
package/src/line/line-cross.js
CHANGED
|
@@ -11,7 +11,7 @@ const DraggableComponent = (props) => {
|
|
|
11
11
|
const { classes = {}, className, scale, x, y, r, correctness, ...rest } = props;
|
|
12
12
|
|
|
13
13
|
return (
|
|
14
|
-
<Group
|
|
14
|
+
<Group className={classNames(className, classes.line, correctness && correctness.value)}>
|
|
15
15
|
<LinePath
|
|
16
16
|
data={[
|
|
17
17
|
{ x: scale.x(x) - r, y: scale.y(y) + r },
|
|
@@ -21,6 +21,7 @@ const DraggableComponent = (props) => {
|
|
|
21
21
|
x={(d) => d.x}
|
|
22
22
|
y={(d) => d.y}
|
|
23
23
|
strokeWidth={5}
|
|
24
|
+
style={{ pointerEvents: 'none' }}
|
|
24
25
|
/>
|
|
25
26
|
<LinePath
|
|
26
27
|
data={[
|
|
@@ -31,7 +32,9 @@ const DraggableComponent = (props) => {
|
|
|
31
32
|
x={(d) => d.x}
|
|
32
33
|
y={(d) => d.y}
|
|
33
34
|
strokeWidth={5}
|
|
35
|
+
style={{ pointerEvents: 'none' }}
|
|
34
36
|
/>
|
|
37
|
+
<circle cx={scale.x(x)} cy={scale.y(y)} r={r * 2} className={classNames(classes.transparentHandle)} {...rest} />
|
|
35
38
|
</Group>
|
|
36
39
|
);
|
|
37
40
|
};
|
package/src/line/line-dot.js
CHANGED
|
@@ -6,13 +6,23 @@ import RawLine from './common/line';
|
|
|
6
6
|
import classNames from 'classnames';
|
|
7
7
|
|
|
8
8
|
const DraggableComponent = ({ scale, x, y, className, classes, r, correctness, ...rest }) => (
|
|
9
|
-
<
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
9
|
+
<g>
|
|
10
|
+
<circle
|
|
11
|
+
cx={scale.x(x)}
|
|
12
|
+
cy={scale.y(y)}
|
|
13
|
+
r={r * 3}
|
|
14
|
+
className={classNames(classes.transparentHandle, className)}
|
|
15
|
+
style={{ pointerEvents: 'none' }}
|
|
16
|
+
{...rest}
|
|
17
|
+
/>
|
|
18
|
+
<circle
|
|
19
|
+
cx={scale.x(x)}
|
|
20
|
+
cy={scale.y(y)}
|
|
21
|
+
r={r}
|
|
22
|
+
className={classNames(className, classes.handle, correctness && correctness.value)}
|
|
23
|
+
{...rest}
|
|
24
|
+
/>
|
|
25
|
+
</g>
|
|
16
26
|
);
|
|
17
27
|
|
|
18
28
|
DraggableComponent.propTypes = {
|
package/src/mark-label.jsx
CHANGED
|
@@ -18,7 +18,6 @@ const styles = (theme) => ({
|
|
|
18
18
|
'&.correct': correct('color'),
|
|
19
19
|
'&.incorrect': incorrect('color'),
|
|
20
20
|
'&.disabled': {
|
|
21
|
-
...disabled('color'),
|
|
22
21
|
backgroundColor: 'transparent !important',
|
|
23
22
|
},
|
|
24
23
|
'&.error': { border: `2px solid ${theme.palette.error.main}` },
|
|
@@ -26,9 +25,10 @@ const styles = (theme) => ({
|
|
|
26
25
|
mathInput: {
|
|
27
26
|
pointerEvents: 'auto',
|
|
28
27
|
textAlign: 'center',
|
|
29
|
-
fontSize: theme.typography.fontSize,
|
|
28
|
+
fontSize: theme.typography.fontSize + 2,
|
|
30
29
|
fontFamily: theme.typography.fontFamily,
|
|
31
30
|
color: color.primaryDark(),
|
|
31
|
+
paddingTop: theme.typography.fontSize / 2,
|
|
32
32
|
},
|
|
33
33
|
disabled: {
|
|
34
34
|
...disabled('color'),
|
|
@@ -88,6 +88,7 @@ export const MarkLabel = (props) => {
|
|
|
88
88
|
correctness,
|
|
89
89
|
autoFocus,
|
|
90
90
|
error,
|
|
91
|
+
isHiddenLabel,
|
|
91
92
|
} = props;
|
|
92
93
|
|
|
93
94
|
const [label, setLabel] = useState(mark.label);
|
|
@@ -128,16 +129,25 @@ export const MarkLabel = (props) => {
|
|
|
128
129
|
|
|
129
130
|
return isMathRendering() ? (
|
|
130
131
|
<div
|
|
131
|
-
ref={(r) =>
|
|
132
|
+
ref={(r) => {
|
|
133
|
+
root = r;
|
|
134
|
+
externalInputRef(r);
|
|
135
|
+
}}
|
|
132
136
|
dangerouslySetInnerHTML={{ __html: getLabelMathFormat(label) }}
|
|
133
137
|
className={classNames(classes.mathInput, {
|
|
134
138
|
[classes.disabled]: disabled,
|
|
135
139
|
[classes.error]: error,
|
|
136
|
-
[classes.correct]:
|
|
137
|
-
[classes.incorrect]:
|
|
140
|
+
[classes.correct]: mark.editable && correctness?.label === 'correct',
|
|
141
|
+
[classes.incorrect]: mark.editable && correctness?.label === 'incorrect',
|
|
138
142
|
})}
|
|
139
143
|
onClick={() => setIsEditing(true)}
|
|
140
|
-
style={{
|
|
144
|
+
style={{
|
|
145
|
+
minWidth: barWidth,
|
|
146
|
+
position: 'fixed',
|
|
147
|
+
transformOrigin: 'left',
|
|
148
|
+
transform: `rotate(${rotate}deg)`,
|
|
149
|
+
visibility: isHiddenLabel ? 'hidden' : 'unset',
|
|
150
|
+
}}
|
|
141
151
|
></div>
|
|
142
152
|
) : (
|
|
143
153
|
<AutosizeInput
|
|
@@ -149,7 +159,7 @@ export const MarkLabel = (props) => {
|
|
|
149
159
|
disabled={disabled}
|
|
150
160
|
inputClassName={classNames(
|
|
151
161
|
classes.input,
|
|
152
|
-
correctness && correctness.label,
|
|
162
|
+
correctness && mark.editable ? correctness.label : null,
|
|
153
163
|
disabled && 'disabled',
|
|
154
164
|
error && 'error',
|
|
155
165
|
)}
|
|
@@ -171,6 +181,7 @@ export const MarkLabel = (props) => {
|
|
|
171
181
|
minWidth: barWidth,
|
|
172
182
|
transformOrigin: 'left',
|
|
173
183
|
transform: `rotate(${rotate}deg)`,
|
|
184
|
+
visibility: isHiddenLabel ? 'hidden' : 'unset',
|
|
174
185
|
}}
|
|
175
186
|
onChange={onChange}
|
|
176
187
|
onBlur={onChangeProp}
|
|
@@ -193,6 +204,7 @@ MarkLabel.propTypes = {
|
|
|
193
204
|
value: PropTypes.string,
|
|
194
205
|
label: PropTypes.string,
|
|
195
206
|
}),
|
|
207
|
+
isHiddenLabel: PropTypes.bool,
|
|
196
208
|
};
|
|
197
209
|
|
|
198
210
|
export default withStyles(styles)(MarkLabel);
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`DotPlot snapshot renders 1`] = `
|
|
4
|
+
<Plot
|
|
5
|
+
CustomBarElement={[Function]}
|
|
6
|
+
className="className"
|
|
7
|
+
classes={Object {}}
|
|
8
|
+
graphProps={
|
|
9
|
+
Object {
|
|
10
|
+
"domain": Object {
|
|
11
|
+
"max": 1,
|
|
12
|
+
"min": 0,
|
|
13
|
+
"step": 1,
|
|
14
|
+
},
|
|
15
|
+
"range": Object {
|
|
16
|
+
"max": 1,
|
|
17
|
+
"min": 0,
|
|
18
|
+
"step": 1,
|
|
19
|
+
},
|
|
20
|
+
"scale": Object {
|
|
21
|
+
"x": [MockFunction],
|
|
22
|
+
"y": [MockFunction],
|
|
23
|
+
},
|
|
24
|
+
"size": Object {
|
|
25
|
+
"height": 400,
|
|
26
|
+
"width": 400,
|
|
27
|
+
},
|
|
28
|
+
"snap": Object {
|
|
29
|
+
"x": [MockFunction],
|
|
30
|
+
"y": [MockFunction],
|
|
31
|
+
},
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
xBand={[Function]}
|
|
35
|
+
/>
|
|
36
|
+
`;
|
|
37
|
+
|
|
38
|
+
exports[`DotPlot snapshot renders without graphProps 1`] = `
|
|
39
|
+
<Plot
|
|
40
|
+
CustomBarElement={[Function]}
|
|
41
|
+
className="className"
|
|
42
|
+
classes={Object {}}
|
|
43
|
+
xBand={[Function]}
|
|
44
|
+
/>
|
|
45
|
+
`;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`LinePlot snapshot renders 1`] = `
|
|
4
|
+
<Plot
|
|
5
|
+
CustomBarElement={[Function]}
|
|
6
|
+
className="className"
|
|
7
|
+
classes={Object {}}
|
|
8
|
+
graphProps={
|
|
9
|
+
Object {
|
|
10
|
+
"domain": Object {
|
|
11
|
+
"max": 1,
|
|
12
|
+
"min": 0,
|
|
13
|
+
"step": 1,
|
|
14
|
+
},
|
|
15
|
+
"range": Object {
|
|
16
|
+
"max": 1,
|
|
17
|
+
"min": 0,
|
|
18
|
+
"step": 1,
|
|
19
|
+
},
|
|
20
|
+
"scale": Object {
|
|
21
|
+
"x": [MockFunction],
|
|
22
|
+
"y": [MockFunction],
|
|
23
|
+
},
|
|
24
|
+
"size": Object {
|
|
25
|
+
"height": 400,
|
|
26
|
+
"width": 400,
|
|
27
|
+
},
|
|
28
|
+
"snap": Object {
|
|
29
|
+
"x": [MockFunction],
|
|
30
|
+
"y": [MockFunction],
|
|
31
|
+
},
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
xBand={[Function]}
|
|
35
|
+
/>
|
|
36
|
+
`;
|
|
37
|
+
|
|
38
|
+
exports[`LinePlot snapshot renders without graphProps 1`] = `
|
|
39
|
+
<Plot
|
|
40
|
+
CustomBarElement={[Function]}
|
|
41
|
+
className="className"
|
|
42
|
+
classes={Object {}}
|
|
43
|
+
xBand={[Function]}
|
|
44
|
+
/>
|
|
45
|
+
`;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { shallow } from 'enzyme';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import Dot, { DotPlot } from '../dot';
|
|
4
|
+
import { graphProps } from './utils';
|
|
5
|
+
import { Bar as BarChart } from '../../bars/bar';
|
|
6
|
+
|
|
7
|
+
describe('DotPlot', () => {
|
|
8
|
+
const wrapper = (extras) => {
|
|
9
|
+
const defaults = {
|
|
10
|
+
classes: {},
|
|
11
|
+
className: 'className',
|
|
12
|
+
graphProps: graphProps(),
|
|
13
|
+
xBand: () => {
|
|
14
|
+
return {
|
|
15
|
+
bandwidth: () => {},
|
|
16
|
+
};
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
const props = { ...defaults, ...extras };
|
|
20
|
+
return shallow(<DotPlot {...props} />);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
describe('snapshot', () => {
|
|
24
|
+
it('renders', () => expect(wrapper()).toMatchSnapshot());
|
|
25
|
+
|
|
26
|
+
it('renders without graphProps', () => expect(wrapper({ graphProps: undefined })).toMatchSnapshot());
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
describe('component', () => {
|
|
30
|
+
const chart = Dot();
|
|
31
|
+
|
|
32
|
+
expect(chart).toEqual({
|
|
33
|
+
type: 'dotPlot',
|
|
34
|
+
Component: DotPlot,
|
|
35
|
+
name: 'Dot Plot',
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { shallow } from 'enzyme';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import Line, { LinePlot } from '../line';
|
|
4
|
+
import { graphProps } from './utils';
|
|
5
|
+
import { Bar as BarChart } from '../../bars/bar';
|
|
6
|
+
|
|
7
|
+
describe('LinePlot', () => {
|
|
8
|
+
const wrapper = (extras) => {
|
|
9
|
+
const defaults = {
|
|
10
|
+
classes: {},
|
|
11
|
+
className: 'className',
|
|
12
|
+
graphProps: graphProps(),
|
|
13
|
+
xBand: () => {
|
|
14
|
+
return {
|
|
15
|
+
bandwidth: () => {},
|
|
16
|
+
};
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
const props = { ...defaults, ...extras };
|
|
20
|
+
return shallow(<LinePlot {...props} />);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
describe('snapshot', () => {
|
|
24
|
+
it('renders', () => expect(wrapper()).toMatchSnapshot());
|
|
25
|
+
|
|
26
|
+
it('renders without graphProps', () => expect(wrapper({ graphProps: undefined })).toMatchSnapshot());
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
describe('component', () => {
|
|
30
|
+
const chart = Line();
|
|
31
|
+
|
|
32
|
+
expect(chart).toEqual({
|
|
33
|
+
type: 'linePlot',
|
|
34
|
+
Component: LinePlot,
|
|
35
|
+
name: 'Line Plot',
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export const scaleMock = () => {
|
|
2
|
+
const fn = jest.fn((n) => n);
|
|
3
|
+
fn.invert = jest.fn((n) => n);
|
|
4
|
+
return fn;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export const graphProps = (dmin = 0, dmax = 1, rmin = 0, rmax = 1) => ({
|
|
8
|
+
scale: {
|
|
9
|
+
x: scaleMock(),
|
|
10
|
+
y: scaleMock(),
|
|
11
|
+
},
|
|
12
|
+
snap: {
|
|
13
|
+
x: jest.fn((n) => n),
|
|
14
|
+
y: jest.fn((n) => n),
|
|
15
|
+
},
|
|
16
|
+
domain: {
|
|
17
|
+
min: dmin,
|
|
18
|
+
max: dmax,
|
|
19
|
+
step: 1,
|
|
20
|
+
},
|
|
21
|
+
range: {
|
|
22
|
+
min: rmin,
|
|
23
|
+
max: rmax,
|
|
24
|
+
step: 1,
|
|
25
|
+
},
|
|
26
|
+
size: {
|
|
27
|
+
width: 400,
|
|
28
|
+
height: 400,
|
|
29
|
+
},
|
|
30
|
+
});
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`Plot snapshot renders 1`] = `
|
|
4
|
+
<t>
|
|
5
|
+
<WithStyles(RawPlot)
|
|
6
|
+
graphProps={
|
|
7
|
+
Object {
|
|
8
|
+
"domain": Object {
|
|
9
|
+
"max": 1,
|
|
10
|
+
"min": 0,
|
|
11
|
+
"step": 1,
|
|
12
|
+
},
|
|
13
|
+
"range": Object {
|
|
14
|
+
"max": 1,
|
|
15
|
+
"min": 0,
|
|
16
|
+
"step": 1,
|
|
17
|
+
},
|
|
18
|
+
"scale": Object {
|
|
19
|
+
"x": [MockFunction],
|
|
20
|
+
"y": [MockFunction],
|
|
21
|
+
},
|
|
22
|
+
"size": Object {
|
|
23
|
+
"height": 400,
|
|
24
|
+
"width": 400,
|
|
25
|
+
},
|
|
26
|
+
"snap": Object {
|
|
27
|
+
"x": [MockFunction],
|
|
28
|
+
"y": [MockFunction],
|
|
29
|
+
},
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
index={0}
|
|
33
|
+
key="bar-0-0-0"
|
|
34
|
+
label="0"
|
|
35
|
+
onChangeCategory={[Function]}
|
|
36
|
+
value={0}
|
|
37
|
+
xBand={[Function]}
|
|
38
|
+
/>
|
|
39
|
+
</t>
|
|
40
|
+
`;
|
|
41
|
+
|
|
42
|
+
exports[`RawPlot snapshot renders 1`] = `
|
|
43
|
+
<Fragment>
|
|
44
|
+
<g
|
|
45
|
+
onMouseEnter={[Function]}
|
|
46
|
+
onMouseLeave={[Function]}
|
|
47
|
+
onTouchEnd={[Function]}
|
|
48
|
+
onTouchStart={[Function]}
|
|
49
|
+
>
|
|
50
|
+
<WithStyles(RawDragHandle)
|
|
51
|
+
color="var(--pie-primary-dark, #283593)"
|
|
52
|
+
graphProps={
|
|
53
|
+
Object {
|
|
54
|
+
"domain": Object {
|
|
55
|
+
"max": 1,
|
|
56
|
+
"min": 0,
|
|
57
|
+
"step": 1,
|
|
58
|
+
},
|
|
59
|
+
"range": Object {
|
|
60
|
+
"max": 1,
|
|
61
|
+
"min": 0,
|
|
62
|
+
"step": 1,
|
|
63
|
+
},
|
|
64
|
+
"scale": Object {
|
|
65
|
+
"x": [MockFunction],
|
|
66
|
+
"y": [MockFunction] {
|
|
67
|
+
"calls": Array [
|
|
68
|
+
Array [
|
|
69
|
+
NaN,
|
|
70
|
+
],
|
|
71
|
+
],
|
|
72
|
+
"results": Array [
|
|
73
|
+
Object {
|
|
74
|
+
"type": "return",
|
|
75
|
+
"value": NaN,
|
|
76
|
+
},
|
|
77
|
+
],
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
"size": Object {
|
|
81
|
+
"height": 400,
|
|
82
|
+
"width": 400,
|
|
83
|
+
},
|
|
84
|
+
"snap": Object {
|
|
85
|
+
"x": [MockFunction],
|
|
86
|
+
"y": [MockFunction],
|
|
87
|
+
},
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
isHovered={false}
|
|
91
|
+
onDrag={[Function]}
|
|
92
|
+
onDragStop={[Function]}
|
|
93
|
+
/>
|
|
94
|
+
</g>
|
|
95
|
+
</Fragment>
|
|
96
|
+
`;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { shallow } from 'enzyme';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import Plot, { RawPlot } from '@pie-lib/plot';
|
|
4
|
+
import { graphProps } from './utils';
|
|
5
|
+
|
|
6
|
+
describe('Plot', () => {
|
|
7
|
+
const xBand = () => {};
|
|
8
|
+
xBand.bandwidth = () => {};
|
|
9
|
+
const onChange = jest.fn();
|
|
10
|
+
|
|
11
|
+
const wrapper = (extras) => {
|
|
12
|
+
const defaults = {
|
|
13
|
+
classes: {},
|
|
14
|
+
className: 'className',
|
|
15
|
+
graphProps: graphProps(),
|
|
16
|
+
xBand,
|
|
17
|
+
onChange,
|
|
18
|
+
data: [{ value: 0, label: '0' }],
|
|
19
|
+
};
|
|
20
|
+
const props = { ...defaults, ...extras };
|
|
21
|
+
return shallow(<Plot {...props} />);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
describe('snapshot', () => {
|
|
25
|
+
it('renders', () => expect(wrapper()).toMatchSnapshot());
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
describe('RawPlot', () => {
|
|
30
|
+
const xBand = () => {};
|
|
31
|
+
xBand.bandwidth = () => {};
|
|
32
|
+
const onChangeCategory = jest.fn();
|
|
33
|
+
|
|
34
|
+
const wrapper = (extras) => {
|
|
35
|
+
const defaults = {
|
|
36
|
+
classes: {},
|
|
37
|
+
className: 'className',
|
|
38
|
+
graphProps: graphProps(),
|
|
39
|
+
xBand,
|
|
40
|
+
onChangeCategory,
|
|
41
|
+
data: [],
|
|
42
|
+
label: 'label',
|
|
43
|
+
CustomBarElement: () => <div />,
|
|
44
|
+
};
|
|
45
|
+
const props = { ...defaults, ...extras };
|
|
46
|
+
return shallow(<RawPlot {...props} />);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
describe('snapshot', () => {
|
|
50
|
+
it('renders', () => expect(wrapper()).toMatchSnapshot());
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
describe('logic', () => {
|
|
54
|
+
const w = wrapper();
|
|
55
|
+
|
|
56
|
+
it('dragStop', () => {
|
|
57
|
+
w.instance().dragStop();
|
|
58
|
+
|
|
59
|
+
expect(onChangeCategory).not.toHaveBeenCalled();
|
|
60
|
+
|
|
61
|
+
w.instance().setState({
|
|
62
|
+
dragValue: 2,
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
w.instance().dragStop();
|
|
66
|
+
|
|
67
|
+
expect(onChangeCategory).toHaveBeenCalledWith({ label: 'label', value: 2 });
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export const scaleMock = () => {
|
|
2
|
+
const fn = jest.fn((n) => n);
|
|
3
|
+
fn.invert = jest.fn((n) => n);
|
|
4
|
+
return fn;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export const graphProps = (dmin = 0, dmax = 1, rmin = 0, rmax = 1) => ({
|
|
8
|
+
scale: {
|
|
9
|
+
x: scaleMock(),
|
|
10
|
+
y: scaleMock(),
|
|
11
|
+
},
|
|
12
|
+
snap: {
|
|
13
|
+
x: jest.fn((n) => n),
|
|
14
|
+
y: jest.fn((n) => n),
|
|
15
|
+
},
|
|
16
|
+
domain: {
|
|
17
|
+
min: dmin,
|
|
18
|
+
max: dmax,
|
|
19
|
+
step: 1,
|
|
20
|
+
},
|
|
21
|
+
range: {
|
|
22
|
+
min: rmin,
|
|
23
|
+
max: rmax,
|
|
24
|
+
step: 1,
|
|
25
|
+
},
|
|
26
|
+
size: {
|
|
27
|
+
width: 400,
|
|
28
|
+
height: 400,
|
|
29
|
+
},
|
|
30
|
+
});
|
package/src/plot/common/plot.jsx
CHANGED
|
@@ -101,7 +101,12 @@ export class RawPlot extends React.Component {
|
|
|
101
101
|
|
|
102
102
|
return (
|
|
103
103
|
<React.Fragment>
|
|
104
|
-
<g
|
|
104
|
+
<g
|
|
105
|
+
onMouseEnter={this.handleMouseEnter}
|
|
106
|
+
onMouseLeave={this.handleMouseLeave}
|
|
107
|
+
onTouchStart={this.handleMouseEnter}
|
|
108
|
+
onTouchEnd={this.handleMouseLeave}
|
|
109
|
+
>
|
|
105
110
|
{isHovered && (
|
|
106
111
|
<rect
|
|
107
112
|
x={barX}
|
package/src/plot/dot.js
CHANGED
|
@@ -2,7 +2,7 @@ import React from 'react';
|
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
3
|
import { types } from '@pie-lib/plot';
|
|
4
4
|
import { dataToXBand } from '../utils';
|
|
5
|
-
import Plot from './
|
|
5
|
+
import Plot from './comm@pie-lib/plot';
|
|
6
6
|
import { Circle } from '@vx/shape';
|
|
7
7
|
|
|
8
8
|
const CustomBarElement = (props) => {
|
package/src/plot/line.js
CHANGED
|
@@ -2,7 +2,7 @@ import React from 'react';
|
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
3
|
import { types } from '@pie-lib/plot';
|
|
4
4
|
import { dataToXBand } from '../utils';
|
|
5
|
-
import Plot from './
|
|
5
|
+
import Plot from './comm@pie-lib/plot';
|
|
6
6
|
import { LinePath } from '@vx/shape';
|
|
7
7
|
import { Group } from '@vx/group';
|
|
8
8
|
|
package/src/tool-menu.jsx
CHANGED
|
@@ -12,12 +12,8 @@ const { translator } = Translator;
|
|
|
12
12
|
|
|
13
13
|
const buttonStyles = (theme) => ({
|
|
14
14
|
root: {
|
|
15
|
-
backgroundColor: color.background(),
|
|
16
15
|
color: color.text(),
|
|
17
16
|
border: `1px solid ${color.secondary()}`,
|
|
18
|
-
'&:hover': {
|
|
19
|
-
backgroundColor: color.secondaryLight(),
|
|
20
|
-
},
|
|
21
17
|
fontSize: theme.typography.fontSize,
|
|
22
18
|
},
|
|
23
19
|
selected: {
|