@pie-lib/charting 5.15.7-next.0 → 5.17.0-beta.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 +16 -0
- package/NEXT.CHANGELOG.json +1 -0
- package/lib/__tests__/axes.test.js +181 -0
- package/lib/__tests__/chart-setup.test.js +58 -0
- package/lib/__tests__/chart-type.test.js +42 -0
- package/lib/__tests__/chart.test.js +108 -0
- package/lib/__tests__/grid.test.js +48 -0
- package/lib/__tests__/mark-label.test.js +57 -0
- package/lib/__tests__/utils.js +56 -0
- package/lib/__tests__/utils.test.js +197 -0
- package/lib/axes.js +75 -30
- package/lib/bars/__tests__/bar.test.js +62 -0
- package/lib/bars/__tests__/histogram.test.js +64 -0
- package/lib/bars/__tests__/utils.js +56 -0
- package/lib/bars/bar.js +1 -1
- package/lib/bars/common/__tests__/bars.test.js +100 -0
- package/lib/bars/common/__tests__/utils.js +56 -0
- package/lib/bars/common/bars.js +36 -2
- package/lib/bars/histogram.js +1 -1
- package/lib/chart-setup.js +1 -1
- package/lib/chart-type.js +5 -5
- package/lib/chart-types.js +3 -3
- package/lib/chart.js +26 -11
- package/lib/common/__tests__/drag-handle.test.js +134 -0
- package/lib/common/__tests__/utils.js +56 -0
- package/lib/common/drag-handle.js +12 -6
- package/lib/common/drag-icon.js +8 -25
- package/lib/common/styles.js +1 -1
- package/lib/grid.js +1 -1
- package/lib/index.js +1 -1
- package/lib/line/__tests__/line-cross.test.js +64 -0
- package/lib/line/__tests__/line-dot.test.js +64 -0
- package/lib/line/__tests__/utils.js +56 -0
- package/lib/line/common/__tests__/drag-handle.test.js +134 -0
- package/lib/line/common/__tests__/line.test.js +128 -0
- package/lib/line/common/__tests__/utils.js +56 -0
- package/lib/line/common/drag-handle.js +10 -5
- package/lib/line/common/line.js +1 -1
- package/lib/line/line-cross.js +17 -6
- package/lib/line/line-dot.js +11 -3
- package/lib/mark-label.js +21 -12
- package/lib/plot/__tests__/dot.test.js +64 -0
- package/lib/plot/__tests__/line.test.js +64 -0
- package/lib/plot/__tests__/utils.js +56 -0
- package/lib/plot/common/__tests__/plot.test.js +103 -0
- package/lib/plot/common/__tests__/utils.js +56 -0
- package/lib/plot/common/plot.js +4 -2
- package/lib/plot/dot.js +2 -2
- package/lib/plot/line.js +2 -2
- package/lib/tool-menu.js +1 -5
- package/lib/utils.js +1 -1
- package/package.json +4 -4
- 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
- package/lib/axes.js.map +0 -1
- package/lib/bars/bar.js.map +0 -1
- package/lib/bars/common/bars.js.map +0 -1
- package/lib/bars/histogram.js.map +0 -1
- package/lib/chart-setup.js.map +0 -1
- package/lib/chart-type.js.map +0 -1
- package/lib/chart-types.js.map +0 -1
- package/lib/chart.js.map +0 -1
- package/lib/common/drag-handle.js.map +0 -1
- package/lib/common/drag-icon.js.map +0 -1
- package/lib/common/styles.js.map +0 -1
- package/lib/grid.js.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/line/common/drag-handle.js.map +0 -1
- package/lib/line/common/line.js.map +0 -1
- package/lib/line/line-cross.js.map +0 -1
- package/lib/line/line-dot.js.map +0 -1
- package/lib/mark-label.js.map +0 -1
- package/lib/plot/common/plot.js.map +0 -1
- package/lib/plot/dot.js.map +0 -1
- package/lib/plot/line.js.map +0 -1
- package/lib/tool-menu.js.map +0 -1
- package/lib/utils.js.map +0 -1
|
@@ -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
|
+
});
|
|
@@ -26,15 +26,21 @@ const RawDragHandle = ({
|
|
|
26
26
|
const scaleValue = getScale(width)?.scale;
|
|
27
27
|
|
|
28
28
|
return (
|
|
29
|
-
<svg x={x} y={scale.y(y) - 10} width={width} overflow="visible">
|
|
30
|
-
{isHovered && !correctness && interactive &&
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
29
|
+
<svg x={x} y={scale.y(y) - 10} width={width} overflow="visible" className={classes.svgOverflowVisible}>
|
|
30
|
+
{isHovered && !correctness && interactive && (
|
|
31
|
+
<DragIcon width={width} scaleValue={scaleValue} color={color} classes={classes} />
|
|
32
|
+
)}
|
|
33
|
+
{interactive && !correctness && (
|
|
34
|
+
<ellipse
|
|
35
|
+
cx={width / 2}
|
|
36
|
+
cy={10}
|
|
37
|
+
rx={width / 2}
|
|
38
|
+
// the drag icon has a 22px fixed r value, so the ry value is 3 times that in order to cover all the area
|
|
39
|
+
ry={66}
|
|
40
|
+
className={classNames(classes.transparentHandle, className)}
|
|
41
|
+
{...rest}
|
|
42
|
+
/>
|
|
43
|
+
)}
|
|
38
44
|
|
|
39
45
|
<defs>
|
|
40
46
|
<filter id="bottomShadow" x="0" y="0" width="140%" height="140%">
|
|
@@ -94,7 +100,6 @@ export const DragHandle = withStyles(() => ({
|
|
|
94
100
|
'&.non-interactive': disabled('fill'),
|
|
95
101
|
},
|
|
96
102
|
transparentHandle: {
|
|
97
|
-
height: '20px',
|
|
98
103
|
fill: 'transparent',
|
|
99
104
|
clipPath: 'polygon(50% 0%, 100% 0%, 100% 50%, 0% 50%, 0% 0%)',
|
|
100
105
|
},
|
|
@@ -110,6 +115,9 @@ export const DragHandle = withStyles(() => ({
|
|
|
110
115
|
'&.incorrect': incorrect('fill'),
|
|
111
116
|
'&.correct': correct('fill'),
|
|
112
117
|
},
|
|
118
|
+
svgOverflowVisible: {
|
|
119
|
+
overflow: 'visible !important',
|
|
120
|
+
},
|
|
113
121
|
}))(RawDragHandle);
|
|
114
122
|
|
|
115
123
|
export const D = gridDraggable({
|
package/src/common/drag-icon.jsx
CHANGED
|
@@ -1,33 +1,18 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { getAdjustedX, getScale } from '../utils';
|
|
3
3
|
|
|
4
|
-
const DragIcon = ({ width, scaleValue, color }) => (
|
|
4
|
+
const DragIcon = ({ width, scaleValue, color, classes }) => (
|
|
5
5
|
<svg
|
|
6
6
|
x={getAdjustedX(width, scaleValue)}
|
|
7
7
|
y={getScale(width)?.deltay}
|
|
8
8
|
color={color}
|
|
9
|
+
width={width}
|
|
10
|
+
height={width}
|
|
9
11
|
overflow="visible"
|
|
10
|
-
|
|
12
|
+
viewBox={`0 0 ${width} ${width}`}
|
|
13
|
+
className={classes.svgOverflowVisible}
|
|
11
14
|
>
|
|
12
|
-
<
|
|
13
|
-
<filter id="svgDropShadow" x="-20%" y="-20%" width="140%" height="140%">
|
|
14
|
-
<feGaussianBlur in="SourceAlpha" stdDeviation="3" />
|
|
15
|
-
<feOffset dx="0" dy="5" result="offsetblur" />
|
|
16
|
-
<feFlood floodColor="#00000033" />
|
|
17
|
-
<feComposite in2="offsetblur" operator="in" />
|
|
18
|
-
<feMerge>
|
|
19
|
-
<feMergeNode />
|
|
20
|
-
<feMergeNode in="SourceGraphic" />
|
|
21
|
-
</feMerge>
|
|
22
|
-
</filter>
|
|
23
|
-
</defs>
|
|
24
|
-
<g
|
|
25
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
26
|
-
filter="url(#filter0_d_2312_1804)"
|
|
27
|
-
fill="currentColor"
|
|
28
|
-
stroke="currentColor"
|
|
29
|
-
transform={`scale(${scaleValue})`}
|
|
30
|
-
>
|
|
15
|
+
<g xmlns="http://www.w3.org/2000/svg" fill="currentColor" stroke="currentColor" transform={`scale(${scaleValue})`}>
|
|
31
16
|
<circle cx="28.5" cy="23.5" r="22" fill="white" stroke="currentColor" />
|
|
32
17
|
<path
|
|
33
18
|
d="M33.5 21.25H23.4609C22.7578 21.25 22.4062 20.4297 22.9141 19.9219L27.9141 14.9219C28.2266 14.6094 28.7344 14.6094 29.0469 14.9219L34.0469 19.9219C34.5547 20.4297 34.2031 21.25 33.5 21.25Z"
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`LineChart snapshot renders 1`] = `
|
|
4
|
+
<Line
|
|
5
|
+
CustomDraggableComponent={[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[`LineChart snapshot renders without graphProps 1`] = `
|
|
39
|
+
<Line
|
|
40
|
+
CustomDraggableComponent={[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[`LineChart snapshot renders 1`] = `
|
|
4
|
+
<Line
|
|
5
|
+
CustomDraggableComponent={[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[`LineChart snapshot renders without graphProps 1`] = `
|
|
39
|
+
<Line
|
|
40
|
+
CustomDraggableComponent={[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 Line, { LineCross as LineChart } from '../line-cross';
|
|
4
|
+
import { graphProps } from './utils';
|
|
5
|
+
import { Bar as BarChart } from '../../bars/bar';
|
|
6
|
+
|
|
7
|
+
describe('LineChart', () => {
|
|
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(<LineChart {...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: 'lineCross',
|
|
34
|
+
Component: LineChart,
|
|
35
|
+
name: 'Line Cross',
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { shallow } from 'enzyme';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import Line, { LineDot as LineChart } from '../line-dot';
|
|
4
|
+
import { graphProps } from './utils';
|
|
5
|
+
import { Bar as BarChart } from '../../bars/bar';
|
|
6
|
+
|
|
7
|
+
describe('LineChart', () => {
|
|
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(<LineChart {...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: 'lineDot',
|
|
34
|
+
Component: LineChart,
|
|
35
|
+
name: 'Line Dot',
|
|
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,44 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`BasePoint snapshot renders 1`] = `
|
|
4
|
+
<RawDragHandle
|
|
5
|
+
className="className"
|
|
6
|
+
classes={
|
|
7
|
+
Object {
|
|
8
|
+
"handle": "RawDragHandle-handle-1",
|
|
9
|
+
"line": "RawDragHandle-line-3",
|
|
10
|
+
"transparentHandle": "RawDragHandle-transparentHandle-2",
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
graphProps={
|
|
14
|
+
Object {
|
|
15
|
+
"domain": Object {
|
|
16
|
+
"max": 1,
|
|
17
|
+
"min": 0,
|
|
18
|
+
"step": 1,
|
|
19
|
+
},
|
|
20
|
+
"range": Object {
|
|
21
|
+
"max": 1,
|
|
22
|
+
"min": 0,
|
|
23
|
+
"step": 1,
|
|
24
|
+
},
|
|
25
|
+
"scale": Object {
|
|
26
|
+
"x": [MockFunction],
|
|
27
|
+
"y": [MockFunction],
|
|
28
|
+
},
|
|
29
|
+
"size": Object {
|
|
30
|
+
"height": 400,
|
|
31
|
+
"width": 400,
|
|
32
|
+
},
|
|
33
|
+
"snap": Object {
|
|
34
|
+
"x": [MockFunction],
|
|
35
|
+
"y": [MockFunction],
|
|
36
|
+
},
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
onChange={[MockFunction]}
|
|
40
|
+
width={100}
|
|
41
|
+
x={0}
|
|
42
|
+
y={0}
|
|
43
|
+
/>
|
|
44
|
+
`;
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`Line snapshot renders 1`] = `
|
|
4
|
+
<t>
|
|
5
|
+
<WithStyles(RawLine)
|
|
6
|
+
className="className"
|
|
7
|
+
classes={Object {}}
|
|
8
|
+
data={
|
|
9
|
+
Array [
|
|
10
|
+
Object {
|
|
11
|
+
"label": "0",
|
|
12
|
+
"value": 0,
|
|
13
|
+
},
|
|
14
|
+
]
|
|
15
|
+
}
|
|
16
|
+
graphProps={
|
|
17
|
+
Object {
|
|
18
|
+
"domain": Object {
|
|
19
|
+
"max": 1,
|
|
20
|
+
"min": 0,
|
|
21
|
+
"step": 1,
|
|
22
|
+
},
|
|
23
|
+
"range": Object {
|
|
24
|
+
"max": 1,
|
|
25
|
+
"min": 0,
|
|
26
|
+
"step": 1,
|
|
27
|
+
},
|
|
28
|
+
"scale": Object {
|
|
29
|
+
"x": [MockFunction],
|
|
30
|
+
"y": [MockFunction],
|
|
31
|
+
},
|
|
32
|
+
"size": Object {
|
|
33
|
+
"height": 400,
|
|
34
|
+
"width": 400,
|
|
35
|
+
},
|
|
36
|
+
"snap": Object {
|
|
37
|
+
"x": [MockFunction],
|
|
38
|
+
"y": [MockFunction],
|
|
39
|
+
},
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
onChange={[Function]}
|
|
43
|
+
xBand={[Function]}
|
|
44
|
+
/>
|
|
45
|
+
</t>
|
|
46
|
+
`;
|
|
47
|
+
|
|
48
|
+
exports[`RawLine snapshot renders 1`] = `
|
|
49
|
+
<Fragment>
|
|
50
|
+
<u
|
|
51
|
+
data={
|
|
52
|
+
Array [
|
|
53
|
+
Object {
|
|
54
|
+
"label": "A",
|
|
55
|
+
"value": 0,
|
|
56
|
+
"x": 0,
|
|
57
|
+
"y": 0,
|
|
58
|
+
},
|
|
59
|
+
Object {
|
|
60
|
+
"label": "B",
|
|
61
|
+
"value": 1,
|
|
62
|
+
"x": 1,
|
|
63
|
+
"y": 1,
|
|
64
|
+
},
|
|
65
|
+
]
|
|
66
|
+
}
|
|
67
|
+
x={[Function]}
|
|
68
|
+
y={[Function]}
|
|
69
|
+
/>
|
|
70
|
+
<WithStyles(RawDragHandle)
|
|
71
|
+
graphProps={
|
|
72
|
+
Object {
|
|
73
|
+
"domain": Object {
|
|
74
|
+
"max": 1,
|
|
75
|
+
"min": 0,
|
|
76
|
+
"step": 1,
|
|
77
|
+
},
|
|
78
|
+
"range": Object {
|
|
79
|
+
"max": 1,
|
|
80
|
+
"min": 0,
|
|
81
|
+
"step": 1,
|
|
82
|
+
},
|
|
83
|
+
"scale": Object {
|
|
84
|
+
"x": [MockFunction],
|
|
85
|
+
"y": [MockFunction],
|
|
86
|
+
},
|
|
87
|
+
"size": Object {
|
|
88
|
+
"height": 400,
|
|
89
|
+
"width": 400,
|
|
90
|
+
},
|
|
91
|
+
"snap": Object {
|
|
92
|
+
"x": [MockFunction],
|
|
93
|
+
"y": [MockFunction],
|
|
94
|
+
},
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
key="point-0-0"
|
|
98
|
+
onDrag={[Function]}
|
|
99
|
+
onDragStart={[Function]}
|
|
100
|
+
onDragStop={[Function]}
|
|
101
|
+
r={6}
|
|
102
|
+
x={0}
|
|
103
|
+
y={0}
|
|
104
|
+
/>
|
|
105
|
+
<WithStyles(RawDragHandle)
|
|
106
|
+
graphProps={
|
|
107
|
+
Object {
|
|
108
|
+
"domain": Object {
|
|
109
|
+
"max": 1,
|
|
110
|
+
"min": 0,
|
|
111
|
+
"step": 1,
|
|
112
|
+
},
|
|
113
|
+
"range": Object {
|
|
114
|
+
"max": 1,
|
|
115
|
+
"min": 0,
|
|
116
|
+
"step": 1,
|
|
117
|
+
},
|
|
118
|
+
"scale": Object {
|
|
119
|
+
"x": [MockFunction],
|
|
120
|
+
"y": [MockFunction],
|
|
121
|
+
},
|
|
122
|
+
"size": Object {
|
|
123
|
+
"height": 400,
|
|
124
|
+
"width": 400,
|
|
125
|
+
},
|
|
126
|
+
"snap": Object {
|
|
127
|
+
"x": [MockFunction],
|
|
128
|
+
"y": [MockFunction],
|
|
129
|
+
},
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
key="point-1-1"
|
|
133
|
+
onDrag={[Function]}
|
|
134
|
+
onDragStart={[Function]}
|
|
135
|
+
onDragStop={[Function]}
|
|
136
|
+
r={6}
|
|
137
|
+
x={1}
|
|
138
|
+
y={1}
|
|
139
|
+
/>
|
|
140
|
+
</Fragment>
|
|
141
|
+
`;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { shallow } from 'enzyme/build';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import DragHandle from '../drag-handle';
|
|
4
|
+
import { gridDraggable } from '@pie-lib/plot';
|
|
5
|
+
import { graphProps } from './utils';
|
|
6
|
+
import { bounds } from '../../../utils';
|
|
7
|
+
|
|
8
|
+
jest.mock('../../../utils', () => {
|
|
9
|
+
const { point } = jest.requireActual('../../../utils');
|
|
10
|
+
return {
|
|
11
|
+
bounds: jest.fn(),
|
|
12
|
+
point,
|
|
13
|
+
};
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
jest.mock('@pie-lib/plot/index', () => {
|
|
17
|
+
const { types, utils } = jest.requireActual('@pie-lib/plot/index');
|
|
18
|
+
return {
|
|
19
|
+
gridDraggable: jest.fn((opts) => (Comp) => Comp),
|
|
20
|
+
types,
|
|
21
|
+
utils,
|
|
22
|
+
};
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
describe('BasePoint', () => {
|
|
26
|
+
let w;
|
|
27
|
+
let onChange = jest.fn();
|
|
28
|
+
const wrapper = (extras) => {
|
|
29
|
+
const defaults = {
|
|
30
|
+
classes: {},
|
|
31
|
+
className: 'className',
|
|
32
|
+
onChange,
|
|
33
|
+
graphProps: graphProps(),
|
|
34
|
+
x: 0,
|
|
35
|
+
y: 0,
|
|
36
|
+
width: 100,
|
|
37
|
+
};
|
|
38
|
+
const props = { ...defaults, ...extras };
|
|
39
|
+
return shallow(<DragHandle {...props} />);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
describe('snapshot', () => {
|
|
43
|
+
it('renders', () => {
|
|
44
|
+
w = wrapper();
|
|
45
|
+
expect(w).toMatchSnapshot();
|
|
46
|
+
});
|
|
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
|
+
|
|
67
|
+
describe('bounds', () => {
|
|
68
|
+
it('calls utils.bounds with area', () => {
|
|
69
|
+
const result = opts.bounds({ x: 0, y: 0 }, { domain, range });
|
|
70
|
+
|
|
71
|
+
expect(result).toEqual({ left: 0, top: 1, bottom: 0, right: 1 });
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
describe('anchorPoint', () => {
|
|
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
|
+
});
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
});
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { shallow } from 'enzyme';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import Line, { RawLine } from '../line';
|
|
4
|
+
import { graphProps } from './utils';
|
|
5
|
+
|
|
6
|
+
describe('Line', () => {
|
|
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(<Line {...props} />);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
describe('snapshot', () => {
|
|
25
|
+
it('renders', () => expect(wrapper()).toMatchSnapshot());
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
describe('logic', () => {
|
|
29
|
+
it('changeLine', () => {
|
|
30
|
+
const w = wrapper();
|
|
31
|
+
|
|
32
|
+
w.instance().changeLine(0, { dragValue: 1, label: '0' });
|
|
33
|
+
|
|
34
|
+
expect(onChange).toHaveBeenCalledWith([{ value: 1, label: '0' }]);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
describe('RawLine', () => {
|
|
40
|
+
const xBand = () => {};
|
|
41
|
+
xBand.bandwidth = () => {};
|
|
42
|
+
const onChange = jest.fn();
|
|
43
|
+
|
|
44
|
+
const wrapper = (extras) => {
|
|
45
|
+
const defaults = {
|
|
46
|
+
classes: {},
|
|
47
|
+
className: 'className',
|
|
48
|
+
graphProps: graphProps(),
|
|
49
|
+
xBand,
|
|
50
|
+
onChange,
|
|
51
|
+
data: [
|
|
52
|
+
{ label: 'A', value: 0 },
|
|
53
|
+
{ label: 'B', value: 1 },
|
|
54
|
+
],
|
|
55
|
+
label: 'label',
|
|
56
|
+
CustomBarElement: () => <div />,
|
|
57
|
+
};
|
|
58
|
+
const props = { ...defaults, ...extras };
|
|
59
|
+
return shallow(<RawLine {...props} />);
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
describe('snapshot', () => {
|
|
63
|
+
it('renders', () => expect(wrapper()).toMatchSnapshot());
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
describe('logic', () => {
|
|
67
|
+
const w = wrapper();
|
|
68
|
+
|
|
69
|
+
it('dragStop', () => {
|
|
70
|
+
w.instance().setState({
|
|
71
|
+
line: [
|
|
72
|
+
{ x: 0, y: 0, dragValue: 2 },
|
|
73
|
+
{ x: 1, y: 1 },
|
|
74
|
+
],
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
w.instance().dragStop(0);
|
|
78
|
+
|
|
79
|
+
expect(onChange).toHaveBeenCalledWith(0, { x: 0, y: 0, dragValue: 2 });
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
});
|