@pie-lib/graphing 4.0.24-beta.6 → 4.0.24-beta.7
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/lib/__tests__/bg.test.js +282 -0
- package/lib/__tests__/coordinates-label.test.js +276 -0
- package/lib/__tests__/graph-with-controls.test.js +275 -0
- package/lib/__tests__/graph.test.js +927 -0
- package/lib/__tests__/grid-setup.test.js +729 -0
- package/lib/__tests__/grid.test.js +29 -0
- package/lib/__tests__/key-legend.test.js +321 -0
- package/lib/__tests__/label-svg-icon.test.js +373 -0
- package/lib/__tests__/labels.test.js +61 -0
- package/lib/__tests__/mark-label.test.js +133 -0
- package/lib/__tests__/toggle-bar.test.js +197 -0
- package/lib/__tests__/tool-menu.test.js +151 -0
- package/lib/__tests__/undo-redo.test.js +31 -0
- package/lib/__tests__/use-debounce.test.js +24 -0
- package/lib/__tests__/utils.js +70 -0
- package/lib/__tests__/utils.test.js +123 -0
- package/lib/axis/__tests__/arrow.test.js +60 -0
- package/lib/axis/__tests__/axes.test.js +195 -0
- package/lib/container/__tests__/actions.test.js +108 -0
- package/lib/container/__tests__/index.test.js +503 -0
- package/lib/container/__tests__/marks.test.js +259 -0
- package/lib/container/__tests__/middleware.test.js +244 -0
- package/lib/container/__tests__/reducer.test.js +450 -0
- package/lib/tools/absolute/__tests__/component.test.js +65 -0
- package/lib/tools/circle/__tests__/bg-circle.test.js +33 -0
- package/lib/tools/circle/__tests__/component.test.js +615 -0
- package/lib/tools/circle/__tests__/index.test.js +576 -0
- package/lib/tools/exponential/__tests__/component.test.js +64 -0
- package/lib/tools/exponential/__tests__/index.test.js +828 -0
- package/lib/tools/line/__tests__/component.test.js +45 -0
- package/lib/tools/parabola/__tests__/component.test.js +64 -0
- package/lib/tools/parabola/__tests__/index.test.js +564 -0
- package/lib/tools/point/__tests__/component.test.js +434 -0
- package/lib/tools/point/__tests__/index.test.js +262 -0
- package/lib/tools/polygon/__tests__/component.test.js +485 -0
- package/lib/tools/polygon/__tests__/index.test.js +303 -0
- package/lib/tools/polygon/__tests__/line.test.js +50 -0
- package/lib/tools/polygon/__tests__/polygon.test.js +85 -0
- package/lib/tools/ray/__tests__/component.test.js +35 -0
- package/lib/tools/segment/__tests__/component.test.js +35 -0
- package/lib/tools/shared/__tests__/arrow-head.test.js +45 -0
- package/lib/tools/shared/line/__tests__/index.test.js +124 -0
- package/lib/tools/shared/line/__tests__/line-path.test.js +62 -0
- package/lib/tools/shared/line/__tests__/with-root-edge.test.js +90 -0
- package/lib/tools/shared/point/__tests__/arrow-point.test.js +127 -0
- package/lib/tools/shared/point/__tests__/base-point.test.js +122 -0
- package/lib/tools/sine/__tests__/component.test.js +72 -0
- package/lib/tools/vector/__tests__/component.test.js +32 -0
- package/package.json +3 -3
- package/src/__tests__/bg.test.jsx +250 -0
- package/src/__tests__/coordinates-label.test.jsx +243 -0
- package/src/__tests__/graph-with-controls.test.jsx +198 -0
- package/src/__tests__/graph.test.jsx +721 -0
- package/src/__tests__/grid-setup.test.jsx +645 -0
- package/src/__tests__/grid.test.jsx +22 -0
- package/src/__tests__/key-legend.test.jsx +260 -0
- package/src/__tests__/label-svg-icon.test.jsx +278 -0
- package/src/__tests__/labels.test.jsx +55 -0
- package/src/__tests__/mark-label.test.jsx +63 -0
- package/src/__tests__/toggle-bar.test.jsx +146 -0
- package/src/__tests__/tool-menu.test.jsx +115 -0
- package/src/__tests__/undo-redo.test.jsx +24 -0
- package/src/__tests__/use-debounce.test.js +21 -0
- package/src/__tests__/utils.js +41 -0
- package/src/__tests__/utils.test.js +105 -0
- package/src/axis/__tests__/arrow.test.jsx +38 -0
- package/src/axis/__tests__/axes.test.jsx +216 -0
- package/src/container/__tests__/actions.test.js +105 -0
- package/src/container/__tests__/index.test.jsx +319 -0
- package/src/container/__tests__/marks.test.js +172 -0
- package/src/container/__tests__/middleware.test.js +235 -0
- package/src/container/__tests__/reducer.test.js +324 -0
- package/src/tools/absolute/__tests__/component.test.jsx +53 -0
- package/src/tools/circle/__tests__/bg-circle.test.jsx +26 -0
- package/src/tools/circle/__tests__/component.test.jsx +494 -0
- package/src/tools/circle/__tests__/index.test.js +480 -0
- package/src/tools/exponential/__tests__/component.test.jsx +53 -0
- package/src/tools/exponential/__tests__/index.test.js +729 -0
- package/src/tools/line/__tests__/component.test.jsx +37 -0
- package/src/tools/parabola/__tests__/component.test.jsx +48 -0
- package/src/tools/parabola/__tests__/index.test.js +470 -0
- package/src/tools/point/__tests__/component.test.jsx +349 -0
- package/src/tools/point/__tests__/index.test.js +241 -0
- package/src/tools/polygon/__tests__/component.test.jsx +471 -0
- package/src/tools/polygon/__tests__/index.test.js +294 -0
- package/src/tools/polygon/__tests__/line.test.jsx +35 -0
- package/src/tools/polygon/__tests__/polygon.test.jsx +61 -0
- package/src/tools/ray/__tests__/component.test.jsx +29 -0
- package/src/tools/segment/__tests__/component.test.jsx +28 -0
- package/src/tools/shared/__tests__/arrow-head.test.jsx +31 -0
- package/src/tools/shared/line/__tests__/index.test.jsx +109 -0
- package/src/tools/shared/line/__tests__/line-path.test.jsx +53 -0
- package/src/tools/shared/line/__tests__/with-root-edge.test.jsx +73 -0
- package/src/tools/shared/point/__tests__/arrow-point.test.jsx +91 -0
- package/src/tools/shared/point/__tests__/base-point.test.jsx +87 -0
- package/src/tools/sine/__tests__/component.test.jsx +51 -0
- package/src/tools/vector/__tests__/component.test.jsx +25 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { render } from '@pie-lib/test-utils';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { rootEdgeComponent, rootEdgeToFromToWrapper } from '../with-root-edge';
|
|
4
|
+
import { graphProps as getGraphProps } from '../../../../__tests__/utils';
|
|
5
|
+
import { utils } from '@pie-lib/plot';
|
|
6
|
+
|
|
7
|
+
const { xy } = utils;
|
|
8
|
+
jest.mock('../index', () => {
|
|
9
|
+
const out = {
|
|
10
|
+
lineBase: jest.fn().mockReturnValue(() => <div />),
|
|
11
|
+
lineToolComponent: jest.fn().mockReturnValue(() => <div />),
|
|
12
|
+
};
|
|
13
|
+
return out;
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
describe('rootEdgeToToFromWrapper', () => {
|
|
17
|
+
let Comp;
|
|
18
|
+
let onChange = jest.fn();
|
|
19
|
+
beforeEach(() => {
|
|
20
|
+
Comp = rootEdgeToFromToWrapper(() => <div />);
|
|
21
|
+
});
|
|
22
|
+
const renderComponent = (extras) => {
|
|
23
|
+
const defaults = {
|
|
24
|
+
mark: { root: xy(1, 1), edge: xy(2, 2) },
|
|
25
|
+
onChange,
|
|
26
|
+
};
|
|
27
|
+
const props = { ...defaults, ...extras };
|
|
28
|
+
return render(<Comp {...props} />);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
it('renders without crashing', () => {
|
|
32
|
+
const { container } = renderComponent();
|
|
33
|
+
expect(container.firstChild).toBeInTheDocument();
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('passes mark as from/to', () => {
|
|
37
|
+
const { container } = renderComponent();
|
|
38
|
+
// Component transforms root/edge to from/to internally
|
|
39
|
+
expect(container.firstChild).toBeInTheDocument();
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('handles onChange with root/edge transformation', () => {
|
|
43
|
+
renderComponent();
|
|
44
|
+
// onChange transformation is tested through component behavior
|
|
45
|
+
expect(onChange).toBeDefined();
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
describe('rootEdgeComponent', () => {
|
|
50
|
+
let onChange = jest.fn();
|
|
51
|
+
let Comp;
|
|
52
|
+
let mark;
|
|
53
|
+
beforeEach(() => {
|
|
54
|
+
mark = { root: xy(0, 0), edge: xy(1, 1) };
|
|
55
|
+
Comp = rootEdgeComponent(() => <text />);
|
|
56
|
+
});
|
|
57
|
+
const renderComponent = (extras) => {
|
|
58
|
+
const defaults = {
|
|
59
|
+
mark,
|
|
60
|
+
graphProps: getGraphProps(),
|
|
61
|
+
onChange,
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const props = { ...defaults, ...extras };
|
|
65
|
+
return render(<Comp {...props} />);
|
|
66
|
+
};
|
|
67
|
+
describe('rendering', () => {
|
|
68
|
+
it('renders without crashing', () => {
|
|
69
|
+
const { container } = renderComponent();
|
|
70
|
+
expect(container.firstChild).toBeInTheDocument();
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
});
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { render } from '@pie-lib/test-utils';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { ArrowPoint } from '../index';
|
|
4
|
+
import { graphProps } from '../../../../__tests__/utils';
|
|
5
|
+
import { bounds } from '../../../../utils';
|
|
6
|
+
import { gridDraggable, utils } from '@pie-lib/plot';
|
|
7
|
+
|
|
8
|
+
const { xy } = utils;
|
|
9
|
+
jest.mock('../../../../utils', () => {
|
|
10
|
+
const { point, getAngleDeg, arrowDimensions } = jest.requireActual('../../../../utils');
|
|
11
|
+
return {
|
|
12
|
+
bounds: jest.fn(),
|
|
13
|
+
point,
|
|
14
|
+
getAngleDeg,
|
|
15
|
+
arrowDimensions,
|
|
16
|
+
};
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
jest.mock('@pie-lib/plot', () => {
|
|
20
|
+
const { types, utils } = jest.requireActual('@pie-lib/plot');
|
|
21
|
+
return {
|
|
22
|
+
gridDraggable: jest.fn((opts) => (Comp) => Comp),
|
|
23
|
+
types,
|
|
24
|
+
utils,
|
|
25
|
+
};
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
describe('ArrowPoint', () => {
|
|
29
|
+
let onChange = jest.fn();
|
|
30
|
+
const renderComponent = (extras) => {
|
|
31
|
+
const defaults = {
|
|
32
|
+
classes: {},
|
|
33
|
+
className: 'className',
|
|
34
|
+
onChange,
|
|
35
|
+
graphProps: graphProps(),
|
|
36
|
+
from: xy(0, 0),
|
|
37
|
+
to: xy(1, 1),
|
|
38
|
+
x: 0,
|
|
39
|
+
y: 0,
|
|
40
|
+
};
|
|
41
|
+
const props = { ...defaults, ...extras };
|
|
42
|
+
return render(<ArrowPoint {...props} />);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
describe('rendering', () => {
|
|
46
|
+
it('renders without crashing', () => {
|
|
47
|
+
const { container } = renderComponent();
|
|
48
|
+
expect(container.firstChild).toBeInTheDocument();
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
describe('gridDraggable options', () => {
|
|
53
|
+
let opts;
|
|
54
|
+
let domain;
|
|
55
|
+
let range;
|
|
56
|
+
beforeEach(() => {
|
|
57
|
+
domain = {
|
|
58
|
+
min: 0,
|
|
59
|
+
max: 1,
|
|
60
|
+
step: 1,
|
|
61
|
+
};
|
|
62
|
+
range = {
|
|
63
|
+
min: 0,
|
|
64
|
+
max: 1,
|
|
65
|
+
step: 1,
|
|
66
|
+
};
|
|
67
|
+
renderComponent();
|
|
68
|
+
opts = gridDraggable.mock.calls[gridDraggable.mock.calls.length - 1][0];
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
describe('bounds', () => {
|
|
72
|
+
it('calls utils.bounds with area', () => {
|
|
73
|
+
const result = opts.bounds({ x: 0, y: 0 }, { domain, range });
|
|
74
|
+
expect(bounds).toHaveBeenCalledWith({ left: 0, top: 0, bottom: 0, right: 0 }, domain, range);
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
describe('anchorPoint', () => {
|
|
78
|
+
it('returns x/y', () => {
|
|
79
|
+
const result = opts.anchorPoint({ x: 0, y: 0 });
|
|
80
|
+
expect(result).toEqual({ x: 0, y: 0 });
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
describe('fromDelta', () => {
|
|
85
|
+
it('returns a new point from the x/y + delta', () => {
|
|
86
|
+
const result = opts.fromDelta({ x: -1, y: 0 }, { x: 1, y: 3 });
|
|
87
|
+
expect(result).toEqual({ x: 0, y: 3 });
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
});
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { render } from '@pie-lib/test-utils';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { BasePoint } from '../index';
|
|
4
|
+
import { gridDraggable } from '@pie-lib/plot';
|
|
5
|
+
import { graphProps } from '../../../../__tests__/utils';
|
|
6
|
+
import { bounds } from '../../../../utils';
|
|
7
|
+
|
|
8
|
+
jest.mock('../../../../utils', () => {
|
|
9
|
+
const { point, thinnerShapesNeeded } = jest.requireActual('../../../../utils');
|
|
10
|
+
return {
|
|
11
|
+
bounds: jest.fn(),
|
|
12
|
+
point,
|
|
13
|
+
thinnerShapesNeeded,
|
|
14
|
+
};
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
jest.mock('@pie-lib/plot', () => {
|
|
18
|
+
const { types, utils } = jest.requireActual('@pie-lib/plot');
|
|
19
|
+
return {
|
|
20
|
+
gridDraggable: jest.fn((opts) => (Comp) => Comp),
|
|
21
|
+
types,
|
|
22
|
+
utils,
|
|
23
|
+
};
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
describe('BasePoint', () => {
|
|
27
|
+
let onChange = jest.fn();
|
|
28
|
+
const renderComponent = (extras) => {
|
|
29
|
+
const defaults = {
|
|
30
|
+
classes: {},
|
|
31
|
+
className: 'className',
|
|
32
|
+
onChange,
|
|
33
|
+
graphProps: graphProps(),
|
|
34
|
+
x: 0,
|
|
35
|
+
y: 0,
|
|
36
|
+
};
|
|
37
|
+
const props = { ...defaults, ...extras };
|
|
38
|
+
return render(<BasePoint {...props} />);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
describe('rendering', () => {
|
|
42
|
+
it('renders without crashing', () => {
|
|
43
|
+
const { container } = renderComponent();
|
|
44
|
+
expect(container.firstChild).toBeInTheDocument();
|
|
45
|
+
});
|
|
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
|
+
renderComponent();
|
|
64
|
+
opts = gridDraggable.mock.calls[gridDraggable.mock.calls.length - 1][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
|
+
expect(bounds).toHaveBeenCalledWith({ left: 0, top: 0, bottom: 0, right: 0 }, domain, range);
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
describe('anchorPoint', () => {
|
|
74
|
+
it('returns x/y', () => {
|
|
75
|
+
const result = opts.anchorPoint({ x: 0, y: 0 });
|
|
76
|
+
expect(result).toEqual({ x: 0, y: 0 });
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
describe('fromDelta', () => {
|
|
81
|
+
it('returns a new point from the x/y + delta', () => {
|
|
82
|
+
const result = opts.fromDelta({ x: -1, y: 0 }, { x: 1, y: 3 });
|
|
83
|
+
expect(result).toEqual({ x: 0, y: 3 });
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
});
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { withRootEdge } from '../../shared/line/with-root-edge';
|
|
2
|
+
import { buildDataPoints, sinY } from '@pie-lib/graphing-utils';
|
|
3
|
+
import { utils } from '@pie-lib/plot';
|
|
4
|
+
|
|
5
|
+
import { graphProps as getGraphProps } from '../../../__tests__/utils';
|
|
6
|
+
|
|
7
|
+
const { xy } = utils;
|
|
8
|
+
jest.mock('@pie-lib/graphing-utils', () => ({
|
|
9
|
+
sinY: jest.fn().mockReturnValue(0),
|
|
10
|
+
buildDataPoints: jest.fn().mockReturnValue([]),
|
|
11
|
+
parabolaFromTwoPoints: jest.fn(() => jest.fn()),
|
|
12
|
+
getAmplitudeAndFreq: jest.fn().mockReturnValue({ freq: 4, amplitude: 1 }),
|
|
13
|
+
FREQ_DIVIDER: 16,
|
|
14
|
+
}));
|
|
15
|
+
|
|
16
|
+
jest.mock('../../shared/line/with-root-edge', () => ({
|
|
17
|
+
withRootEdge: jest.fn(),
|
|
18
|
+
rootEdgeComponent: jest.fn(),
|
|
19
|
+
}));
|
|
20
|
+
describe('Parabola', () => {
|
|
21
|
+
let fnBody;
|
|
22
|
+
let graphProps;
|
|
23
|
+
let root;
|
|
24
|
+
let edge;
|
|
25
|
+
let result;
|
|
26
|
+
beforeEach(() => {
|
|
27
|
+
require('../component');
|
|
28
|
+
fnBody = withRootEdge.mock.calls[0][0];
|
|
29
|
+
graphProps = getGraphProps();
|
|
30
|
+
root = xy(0, 0);
|
|
31
|
+
edge = xy(1, 1);
|
|
32
|
+
|
|
33
|
+
result = fnBody({ graphProps, root, edge });
|
|
34
|
+
});
|
|
35
|
+
it('fnBody is not null', () => {
|
|
36
|
+
expect(fnBody).toBeDefined();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('calls buildDataPoints', () => {
|
|
40
|
+
const { domain, range } = graphProps;
|
|
41
|
+
expect(buildDataPoints).toHaveBeenCalledWith({ ...domain, step: 0.25 }, range, root, edge, expect.anything());
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('calls sinY', () => {
|
|
45
|
+
expect(sinY).toHaveBeenCalledWith(1, 4, expect.anything());
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('returns dataPoints', () => {
|
|
49
|
+
expect(result).toEqual({ root, edge, dataPoints: [] });
|
|
50
|
+
});
|
|
51
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { render } from '@pie-lib/test-utils';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { Line } from '../component';
|
|
4
|
+
import { graphProps as getGraphProps } from '../../../__tests__/utils';
|
|
5
|
+
import { utils } from '@pie-lib/plot';
|
|
6
|
+
|
|
7
|
+
describe('Line', () => {
|
|
8
|
+
const renderComponent = (extras) => {
|
|
9
|
+
const defaults = {
|
|
10
|
+
classes: {},
|
|
11
|
+
className: 'className',
|
|
12
|
+
graphProps: getGraphProps(),
|
|
13
|
+
from: utils.xy(0, 0),
|
|
14
|
+
to: utils.xy(1, 1),
|
|
15
|
+
};
|
|
16
|
+
const props = { ...defaults, ...extras };
|
|
17
|
+
return render(<Line {...props} />);
|
|
18
|
+
};
|
|
19
|
+
describe('rendering', () => {
|
|
20
|
+
it('renders without crashing', () => {
|
|
21
|
+
const { container } = renderComponent();
|
|
22
|
+
expect(container.firstChild).toBeInTheDocument();
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
});
|