@pie-lib/graphing 2.34.3-next.2 → 2.34.3-next.203
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 +13 -67
- package/lib/axis/arrow.js +19 -55
- package/lib/axis/arrow.js.map +1 -1
- package/lib/axis/axes.js +106 -194
- package/lib/axis/axes.js.map +1 -1
- package/lib/axis/index.js +1 -6
- package/lib/axis/index.js.map +1 -1
- package/lib/bg.js +21 -49
- package/lib/bg.js.map +1 -1
- package/lib/container/actions.js +2 -8
- package/lib/container/actions.js.map +1 -1
- package/lib/container/index.js +14 -59
- package/lib/container/index.js.map +1 -1
- package/lib/container/marks.js +1 -6
- package/lib/container/marks.js.map +1 -1
- package/lib/container/middleware.js +2 -8
- package/lib/container/middleware.js.map +1 -1
- package/lib/container/reducer.js +1 -8
- package/lib/container/reducer.js.map +1 -1
- package/lib/coordinates-label.js +24 -54
- package/lib/coordinates-label.js.map +1 -1
- package/lib/graph-with-controls.js +120 -184
- package/lib/graph-with-controls.js.map +1 -1
- package/lib/graph.js +59 -116
- package/lib/graph.js.map +1 -1
- package/lib/grid-setup.js +169 -225
- package/lib/grid-setup.js.map +1 -1
- package/lib/grid.js +29 -74
- package/lib/grid.js.map +1 -1
- package/lib/index.js +1 -13
- package/lib/index.js.map +1 -1
- package/lib/key-legend.js +40 -85
- package/lib/key-legend.js.map +1 -1
- package/lib/label-svg-icon.js +1 -7
- package/lib/label-svg-icon.js.map +1 -1
- package/lib/labels.js +66 -122
- package/lib/labels.js.map +1 -1
- package/lib/mark-label.js +120 -163
- package/lib/mark-label.js.map +1 -1
- package/lib/toggle-bar.js +155 -243
- package/lib/toggle-bar.js.map +1 -1
- package/lib/tool-menu.js +16 -50
- package/lib/tool-menu.js.map +1 -1
- package/lib/tools/absolute/component.js +4 -10
- package/lib/tools/absolute/component.js.map +1 -1
- package/lib/tools/absolute/index.js +3 -16
- package/lib/tools/absolute/index.js.map +1 -1
- package/lib/tools/circle/bg-circle.js +42 -92
- package/lib/tools/circle/bg-circle.js.map +1 -1
- package/lib/tools/circle/component.js +78 -165
- package/lib/tools/circle/component.js.map +1 -1
- package/lib/tools/circle/index.js +3 -13
- package/lib/tools/circle/index.js.map +1 -1
- package/lib/tools/exponential/component.js +4 -10
- package/lib/tools/exponential/component.js.map +1 -1
- package/lib/tools/exponential/index.js +3 -18
- package/lib/tools/exponential/index.js.map +1 -1
- package/lib/tools/index.js +3 -16
- package/lib/tools/index.js.map +1 -1
- package/lib/tools/line/component.js +27 -48
- package/lib/tools/line/component.js.map +1 -1
- package/lib/tools/line/index.js +1 -6
- package/lib/tools/line/index.js.map +1 -1
- package/lib/tools/parabola/component.js +4 -10
- package/lib/tools/parabola/component.js.map +1 -1
- package/lib/tools/parabola/index.js +3 -16
- package/lib/tools/parabola/index.js.map +1 -1
- package/lib/tools/point/component.js +24 -71
- package/lib/tools/point/component.js.map +1 -1
- package/lib/tools/point/index.js +3 -11
- package/lib/tools/point/index.js.map +1 -1
- package/lib/tools/polygon/component.js +83 -184
- package/lib/tools/polygon/component.js.map +1 -1
- package/lib/tools/polygon/index.js +6 -23
- package/lib/tools/polygon/index.js.map +1 -1
- package/lib/tools/polygon/line.js +48 -91
- package/lib/tools/polygon/line.js.map +1 -1
- package/lib/tools/polygon/polygon.js +65 -98
- package/lib/tools/polygon/polygon.js.map +1 -1
- package/lib/tools/ray/component.js +41 -60
- package/lib/tools/ray/component.js.map +1 -1
- package/lib/tools/ray/index.js +1 -6
- package/lib/tools/ray/index.js.map +1 -1
- package/lib/tools/segment/component.js +25 -43
- package/lib/tools/segment/component.js.map +1 -1
- package/lib/tools/segment/index.js +1 -6
- package/lib/tools/segment/index.js.map +1 -1
- package/lib/tools/shared/arrow-head.js +69 -28
- package/lib/tools/shared/arrow-head.js.map +1 -1
- package/lib/tools/shared/icons/CorrectSVG.js +12 -8
- package/lib/tools/shared/icons/CorrectSVG.js.map +1 -1
- package/lib/tools/shared/icons/IncorrectSVG.js +12 -8
- package/lib/tools/shared/icons/IncorrectSVG.js.map +1 -1
- package/lib/tools/shared/icons/MissingSVG.js +12 -8
- package/lib/tools/shared/icons/MissingSVG.js.map +1 -1
- package/lib/tools/shared/line/index.js +140 -193
- package/lib/tools/shared/line/index.js.map +1 -1
- package/lib/tools/shared/line/line-path.js +70 -101
- package/lib/tools/shared/line/line-path.js.map +1 -1
- package/lib/tools/shared/line/with-root-edge.js +22 -56
- package/lib/tools/shared/line/with-root-edge.js.map +1 -1
- package/lib/tools/shared/point/arrow-point.js +21 -62
- package/lib/tools/shared/point/arrow-point.js.map +1 -1
- package/lib/tools/shared/point/arrow.js +23 -52
- package/lib/tools/shared/point/arrow.js.map +1 -1
- package/lib/tools/shared/point/base-point.js +54 -72
- package/lib/tools/shared/point/base-point.js.map +1 -1
- package/lib/tools/shared/point/index.js +22 -57
- package/lib/tools/shared/point/index.js.map +1 -1
- package/lib/tools/shared/styles.js +10 -38
- package/lib/tools/shared/styles.js.map +1 -1
- package/lib/tools/shared/types.js +2 -9
- package/lib/tools/shared/types.js.map +1 -1
- package/lib/tools/sine/component.js +8 -19
- package/lib/tools/sine/component.js.map +1 -1
- package/lib/tools/sine/index.js +3 -16
- package/lib/tools/sine/index.js.map +1 -1
- package/lib/tools/vector/component.js +24 -44
- package/lib/tools/vector/component.js.map +1 -1
- package/lib/tools/vector/index.js +1 -6
- package/lib/tools/vector/index.js.map +1 -1
- package/lib/undo-redo.js +29 -69
- package/lib/undo-redo.js.map +1 -1
- package/lib/use-debounce.js +4 -11
- package/lib/use-debounce.js.map +1 -1
- package/lib/utils.js +51 -128
- package/lib/utils.js.map +1 -1
- package/package.json +25 -29
- package/src/__tests__/graph-with-controls.test.jsx +28 -11
- package/src/__tests__/graph.test.jsx +104 -168
- package/src/__tests__/grid.test.jsx +8 -6
- package/src/__tests__/labels.test.jsx +25 -8
- package/src/__tests__/mark-label.test.jsx +12 -17
- package/src/__tests__/toggle-bar.test.jsx +92 -17
- package/src/__tests__/tool-menu.test.jsx +61 -12
- package/src/__tests__/undo-redo.test.jsx +7 -8
- package/src/__tests__/utils.js +3 -0
- package/src/axis/__tests__/arrow.test.jsx +16 -17
- package/src/axis/__tests__/axes.test.jsx +118 -122
- package/src/axis/arrow.jsx +7 -12
- package/src/axis/axes.jsx +45 -55
- package/src/coordinates-label.jsx +14 -18
- package/src/graph-with-controls.jsx +52 -59
- package/src/grid-setup.jsx +203 -205
- package/src/grid.jsx +2 -4
- package/src/key-legend.jsx +52 -56
- package/src/labels.jsx +24 -31
- package/src/mark-label.jsx +92 -81
- package/src/toggle-bar.jsx +135 -164
- package/src/tool-menu.jsx +1 -1
- package/src/tools/circle/__tests__/bg-circle.test.jsx +7 -9
- package/src/tools/circle/__tests__/component.test.jsx +17 -189
- package/src/tools/circle/bg-circle.jsx +20 -28
- package/src/tools/circle/component.jsx +28 -63
- package/src/tools/line/__tests__/component.test.jsx +7 -7
- package/src/tools/line/component.jsx +22 -15
- package/src/tools/point/__tests__/component.test.jsx +18 -43
- package/src/tools/point/component.jsx +1 -1
- package/src/tools/polygon/__tests__/component.test.jsx +18 -162
- package/src/tools/polygon/__tests__/line.test.jsx +7 -10
- package/src/tools/polygon/__tests__/polygon.test.jsx +7 -8
- package/src/tools/polygon/component.jsx +3 -4
- package/src/tools/polygon/line.jsx +30 -33
- package/src/tools/polygon/polygon.jsx +52 -45
- package/src/tools/ray/__tests__/component.test.jsx +7 -8
- package/src/tools/ray/component.jsx +38 -25
- package/src/tools/segment/__tests__/component.test.jsx +7 -8
- package/src/tools/segment/component.jsx +19 -18
- package/src/tools/shared/__tests__/arrow-head.test.jsx +14 -17
- package/src/tools/shared/arrow-head.jsx +60 -7
- package/src/tools/shared/icons/CorrectSVG.jsx +10 -0
- package/src/tools/shared/icons/IncorrectSVG.jsx +10 -0
- package/src/tools/shared/icons/MissingSVG.jsx +10 -0
- package/src/tools/shared/line/__tests__/index.test.jsx +19 -165
- package/src/tools/shared/line/__tests__/line-path.test.jsx +8 -8
- package/src/tools/shared/line/__tests__/with-root-edge.test.jsx +22 -22
- package/src/tools/shared/line/index.jsx +52 -7
- package/src/tools/shared/line/line-path.jsx +55 -59
- package/src/tools/shared/line/with-root-edge.jsx +1 -1
- package/src/tools/shared/point/__tests__/arrow-point.test.jsx +15 -11
- package/src/tools/shared/point/__tests__/base-point.test.jsx +14 -11
- package/src/tools/shared/point/arrow-point.jsx +10 -24
- package/src/tools/shared/point/arrow.jsx +5 -11
- package/src/tools/shared/point/base-point.jsx +42 -19
- package/src/tools/shared/point/index.jsx +27 -44
- package/src/tools/vector/__tests__/component.test.jsx +7 -8
- package/src/tools/vector/component.jsx +11 -16
- package/src/undo-redo.jsx +19 -21
- package/esm/index.css +0 -847
- package/esm/index.js +0 -239949
- package/esm/index.js.map +0 -1
- package/esm/package.json +0 -3
- package/src/__tests__/__snapshots__/graph-with-controls.test.jsx.snap +0 -237
- package/src/__tests__/__snapshots__/graph.test.jsx.snap +0 -211
- package/src/__tests__/__snapshots__/grid.test.jsx.snap +0 -54
- package/src/__tests__/__snapshots__/labels.test.jsx.snap +0 -30
- package/src/__tests__/__snapshots__/mark-label.test.jsx.snap +0 -45
- package/src/__tests__/__snapshots__/toggle-bar.test.jsx.snap +0 -7
- package/src/__tests__/__snapshots__/tool-menu.test.jsx.snap +0 -13
- package/src/__tests__/__snapshots__/undo-redo.test.jsx.snap +0 -14
- package/src/axis/__tests__/__snapshots__/arrow.test.jsx.snap +0 -33
- package/src/axis/__tests__/__snapshots__/axes.test.jsx.snap +0 -122
- package/src/tools/circle/__tests__/__snapshots__/bg-circle.test.jsx.snap +0 -46
- package/src/tools/circle/__tests__/__snapshots__/component.test.jsx.snap +0 -293
- package/src/tools/line/__tests__/__snapshots__/component.test.jsx.snap +0 -20
- package/src/tools/point/__tests__/__snapshots__/component.test.jsx.snap +0 -40
- package/src/tools/polygon/__tests__/__snapshots__/component.test.jsx.snap +0 -415
- package/src/tools/polygon/__tests__/__snapshots__/line.test.jsx.snap +0 -45
- package/src/tools/polygon/__tests__/__snapshots__/polygon.test.jsx.snap +0 -52
- package/src/tools/ray/__tests__/__snapshots__/component.test.jsx.snap +0 -23
- package/src/tools/segment/__tests__/__snapshots__/component.test.jsx.snap +0 -14
- package/src/tools/shared/__tests__/__snapshots__/arrow-head.test.jsx.snap +0 -27
- package/src/tools/shared/line/__tests__/__snapshots__/index.test.jsx.snap +0 -360
- package/src/tools/shared/line/__tests__/__snapshots__/line-path.test.jsx.snap +0 -58
- package/src/tools/shared/line/__tests__/__snapshots__/with-root-edge.test.jsx.snap +0 -63
- package/src/tools/shared/point/__tests__/__snapshots__/arrow-point.test.jsx.snap +0 -56
- package/src/tools/shared/point/__tests__/__snapshots__/base-point.test.jsx.snap +0 -44
- package/src/tools/vector/__tests__/__snapshots__/component.test.jsx.snap +0 -12
|
@@ -1,36 +1,111 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { render, screen } from '@pie-lib/test-utils';
|
|
2
|
+
import userEvent from '@testing-library/user-event';
|
|
2
3
|
import React from 'react';
|
|
3
4
|
|
|
4
5
|
import { ToggleBar } from '../toggle-bar';
|
|
5
6
|
|
|
7
|
+
// Mock DragProvider to avoid @dnd-kit React version conflicts
|
|
8
|
+
jest.mock('@pie-lib/drag', () => ({
|
|
9
|
+
DragProvider: ({ children }) => <div data-testid="drag-provider">{children}</div>,
|
|
10
|
+
}));
|
|
11
|
+
|
|
12
|
+
// Mock Translator to return the key as-is for testing
|
|
13
|
+
jest.mock('@pie-lib/translator', () => ({
|
|
14
|
+
translator: {
|
|
15
|
+
t: (key) => {
|
|
16
|
+
// Extract tool name from key like "graphing.point" -> "point"
|
|
17
|
+
const parts = key.split('.');
|
|
18
|
+
return parts[parts.length - 1];
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
}));
|
|
22
|
+
|
|
6
23
|
describe('ToggleBar', () => {
|
|
7
|
-
let w;
|
|
8
24
|
let onChange = jest.fn();
|
|
9
|
-
|
|
25
|
+
let onChangeToolsOrder = jest.fn();
|
|
26
|
+
|
|
27
|
+
beforeEach(() => {
|
|
28
|
+
onChange.mockClear();
|
|
29
|
+
onChangeToolsOrder.mockClear();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const renderComponent = (extras) => {
|
|
10
33
|
const defaults = {
|
|
11
|
-
classes: {},
|
|
12
34
|
className: 'className',
|
|
13
35
|
onChange,
|
|
14
|
-
|
|
36
|
+
onChangeToolsOrder,
|
|
37
|
+
options: ['point', 'line'],
|
|
38
|
+
language: 'en',
|
|
15
39
|
};
|
|
16
40
|
const props = { ...defaults, ...extras };
|
|
17
|
-
return
|
|
41
|
+
return render(<ToggleBar {...props} />);
|
|
18
42
|
};
|
|
19
43
|
|
|
20
|
-
describe('
|
|
21
|
-
it('renders', () => {
|
|
22
|
-
|
|
23
|
-
expect(
|
|
44
|
+
describe('rendering', () => {
|
|
45
|
+
it('renders without crashing', () => {
|
|
46
|
+
const { container } = renderComponent();
|
|
47
|
+
expect(container.firstChild).toBeInTheDocument();
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('renders tool buttons for valid tools', () => {
|
|
51
|
+
renderComponent({ options: ['point', 'line', 'circle'] });
|
|
52
|
+
expect(screen.getByText(/point/i)).toBeInTheDocument();
|
|
53
|
+
expect(screen.getByText(/line/i)).toBeInTheDocument();
|
|
54
|
+
expect(screen.getByText(/circle/i)).toBeInTheDocument();
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('does not render invalid tool options', () => {
|
|
58
|
+
renderComponent({ options: ['point', 'invalid-tool', 'line'] });
|
|
59
|
+
expect(screen.getByText(/point/i)).toBeInTheDocument();
|
|
60
|
+
expect(screen.getByText(/line/i)).toBeInTheDocument();
|
|
61
|
+
expect(screen.queryByText(/invalid-tool/i)).not.toBeInTheDocument();
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('highlights selected tool', () => {
|
|
65
|
+
const { container } = renderComponent({ selectedToolType: 'line' });
|
|
66
|
+
const selectedButton = screen.getByText(/line/i).closest('button');
|
|
67
|
+
expect(selectedButton).toHaveAttribute('value', 'line');
|
|
24
68
|
});
|
|
25
69
|
});
|
|
26
70
|
|
|
27
|
-
describe('
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
71
|
+
describe('interactions', () => {
|
|
72
|
+
it('calls onChange when tool button is clicked', async () => {
|
|
73
|
+
const user = userEvent.setup();
|
|
74
|
+
renderComponent({ options: ['point', 'line'] });
|
|
75
|
+
|
|
76
|
+
const pointButton = screen.getByText(/point/i).closest('button');
|
|
77
|
+
await user.click(pointButton);
|
|
78
|
+
|
|
79
|
+
expect(onChange).toHaveBeenCalledWith('point');
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('calls onChange with selected tool type', async () => {
|
|
83
|
+
const user = userEvent.setup();
|
|
84
|
+
renderComponent({ options: ['point', 'line'], selectedToolType: 'point' });
|
|
85
|
+
|
|
86
|
+
const lineButton = screen.getByText(/line/i).closest('button');
|
|
87
|
+
await user.click(lineButton);
|
|
88
|
+
|
|
89
|
+
expect(onChange).toHaveBeenCalledWith('line');
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('disables buttons when disabled prop is true', () => {
|
|
93
|
+
renderComponent({ disabled: true, options: ['point', 'line'] });
|
|
94
|
+
|
|
95
|
+
const pointButton = screen.getByText(/point/i).closest('button');
|
|
96
|
+
const lineButton = screen.getByText(/line/i).closest('button');
|
|
97
|
+
|
|
98
|
+
expect(pointButton).toBeDisabled();
|
|
99
|
+
expect(lineButton).toBeDisabled();
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it('does not call onChange when disabled', () => {
|
|
103
|
+
renderComponent({ disabled: true, options: ['point'] });
|
|
104
|
+
|
|
105
|
+
const pointButton = screen.getByText(/point/i).closest('button');
|
|
106
|
+
expect(pointButton).toBeDisabled();
|
|
107
|
+
// Note: Cannot test click on disabled button with pointer-events: none
|
|
108
|
+
// The disabled state is verified above
|
|
34
109
|
});
|
|
35
110
|
});
|
|
36
111
|
});
|
|
@@ -1,29 +1,78 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { render, screen } from '@pie-lib/test-utils';
|
|
2
|
+
import userEvent from '@testing-library/user-event';
|
|
2
3
|
import React from 'react';
|
|
3
4
|
|
|
4
5
|
import ToolMenu from '../tool-menu';
|
|
5
6
|
|
|
7
|
+
// Mock DragProvider to avoid @dnd-kit React version conflicts
|
|
8
|
+
jest.mock('@pie-lib/drag', () => ({
|
|
9
|
+
DragProvider: ({ children }) => <div data-testid="drag-provider">{children}</div>,
|
|
10
|
+
}));
|
|
11
|
+
|
|
6
12
|
describe('ToolMenu', () => {
|
|
7
|
-
let w;
|
|
8
13
|
let onChange = jest.fn();
|
|
9
|
-
|
|
14
|
+
let onChangeTools = jest.fn();
|
|
15
|
+
|
|
16
|
+
beforeEach(() => {
|
|
17
|
+
onChange.mockClear();
|
|
18
|
+
onChangeTools.mockClear();
|
|
19
|
+
});
|
|
10
20
|
|
|
11
|
-
const
|
|
21
|
+
const renderComponent = (extras) => {
|
|
12
22
|
const defaults = {
|
|
13
|
-
classes: {},
|
|
14
23
|
className: 'className',
|
|
15
24
|
onChange,
|
|
16
|
-
|
|
17
|
-
|
|
25
|
+
onChangeTools,
|
|
26
|
+
currentToolType: 'point',
|
|
27
|
+
toolbarTools: ['point', 'line'],
|
|
28
|
+
language: 'en',
|
|
18
29
|
};
|
|
19
30
|
const props = { ...defaults, ...extras };
|
|
20
|
-
return
|
|
31
|
+
return render(<ToolMenu {...props} />);
|
|
21
32
|
};
|
|
22
33
|
|
|
23
|
-
describe('
|
|
24
|
-
it('renders', () => {
|
|
25
|
-
|
|
26
|
-
expect(
|
|
34
|
+
describe('rendering', () => {
|
|
35
|
+
it('renders without crashing', () => {
|
|
36
|
+
const { container } = renderComponent();
|
|
37
|
+
expect(container.firstChild).toBeInTheDocument();
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('renders ToggleBar with correct props', () => {
|
|
41
|
+
renderComponent({ toolbarTools: ['point', 'line', 'circle'] });
|
|
42
|
+
expect(screen.getByText(/point/i)).toBeInTheDocument();
|
|
43
|
+
expect(screen.getByText(/line/i)).toBeInTheDocument();
|
|
44
|
+
expect(screen.getByText(/circle/i)).toBeInTheDocument();
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('passes currentToolType to ToggleBar', () => {
|
|
48
|
+
renderComponent({ currentToolType: 'line' });
|
|
49
|
+
const selectedButton = screen.getByText(/line/i).closest('button');
|
|
50
|
+
expect(selectedButton).toBeInTheDocument();
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
describe('interactions', () => {
|
|
55
|
+
it('calls onChange when tool is selected', async () => {
|
|
56
|
+
const user = userEvent.setup();
|
|
57
|
+
renderComponent();
|
|
58
|
+
|
|
59
|
+
const lineButton = screen.getByText(/line/i).closest('button');
|
|
60
|
+
await user.click(lineButton);
|
|
61
|
+
|
|
62
|
+
expect(onChange).toHaveBeenCalledWith('line');
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('calls onChangeTools when tools order changes', () => {
|
|
66
|
+
renderComponent({ draggableTools: true });
|
|
67
|
+
// Note: Drag-and-drop testing requires more complex setup with @dnd-kit/test-utils
|
|
68
|
+
// For now, we verify the component renders with draggableTools enabled
|
|
69
|
+
expect(screen.getByText(/point/i)).toBeInTheDocument();
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('disables tools when disabled prop is true', () => {
|
|
73
|
+
renderComponent({ disabled: true });
|
|
74
|
+
const pointButton = screen.getByText(/point/i).closest('button');
|
|
75
|
+
expect(pointButton).toBeDisabled();
|
|
27
76
|
});
|
|
28
77
|
});
|
|
29
78
|
});
|
|
@@ -1,25 +1,24 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { render } from '@pie-lib/test-utils';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import UndoRedo from '../undo-redo';
|
|
4
4
|
|
|
5
5
|
describe('UndoRedo', () => {
|
|
6
|
-
let w;
|
|
7
6
|
let onUndo = jest.fn();
|
|
8
7
|
let onRedo = jest.fn();
|
|
9
8
|
let onReset = jest.fn();
|
|
10
|
-
const
|
|
9
|
+
const renderComponent = (extras) => {
|
|
11
10
|
const defaults = {
|
|
12
11
|
onUndo,
|
|
13
12
|
onRedo,
|
|
14
13
|
onReset,
|
|
15
14
|
};
|
|
16
15
|
const props = { ...defaults, ...extras };
|
|
17
|
-
return
|
|
16
|
+
return render(<UndoRedo {...props} />);
|
|
18
17
|
};
|
|
19
|
-
describe('
|
|
20
|
-
it('renders', () => {
|
|
21
|
-
|
|
22
|
-
expect(
|
|
18
|
+
describe('rendering', () => {
|
|
19
|
+
it('renders without crashing', () => {
|
|
20
|
+
const { container } = renderComponent();
|
|
21
|
+
expect(container.firstChild).toBeInTheDocument();
|
|
23
22
|
});
|
|
24
23
|
});
|
|
25
24
|
});
|
package/src/__tests__/utils.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { render } from '@pie-lib/test-utils';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { Arrow } from '../arrow';
|
|
4
4
|
|
|
5
5
|
describe('Arrow', () => {
|
|
6
|
-
let w;
|
|
7
6
|
let onChange = jest.fn();
|
|
8
|
-
const
|
|
7
|
+
const renderComponent = (extras) => {
|
|
9
8
|
const defaults = {
|
|
10
9
|
classes: {},
|
|
11
10
|
className: 'className',
|
|
@@ -16,24 +15,24 @@ describe('Arrow', () => {
|
|
|
16
15
|
},
|
|
17
16
|
};
|
|
18
17
|
const props = { ...defaults, ...extras };
|
|
19
|
-
return
|
|
18
|
+
return render(<Arrow {...props} />);
|
|
20
19
|
};
|
|
21
|
-
describe('
|
|
22
|
-
it('up', () => {
|
|
23
|
-
|
|
24
|
-
expect(
|
|
20
|
+
describe('rendering', () => {
|
|
21
|
+
it('renders with direction up', () => {
|
|
22
|
+
const { container } = renderComponent({ direction: 'up' });
|
|
23
|
+
expect(container.firstChild).toBeInTheDocument();
|
|
25
24
|
});
|
|
26
|
-
it('down', () => {
|
|
27
|
-
|
|
28
|
-
expect(
|
|
25
|
+
it('renders with direction down', () => {
|
|
26
|
+
const { container } = renderComponent({ direction: 'down' });
|
|
27
|
+
expect(container.firstChild).toBeInTheDocument();
|
|
29
28
|
});
|
|
30
|
-
it('left', () => {
|
|
31
|
-
|
|
32
|
-
expect(
|
|
29
|
+
it('renders with direction left', () => {
|
|
30
|
+
const { container } = renderComponent({ direction: 'left' });
|
|
31
|
+
expect(container.firstChild).toBeInTheDocument();
|
|
33
32
|
});
|
|
34
|
-
it('right', () => {
|
|
35
|
-
|
|
36
|
-
expect(
|
|
33
|
+
it('renders with direction right', () => {
|
|
34
|
+
const { container } = renderComponent({ direction: 'right' });
|
|
35
|
+
expect(container.firstChild).toBeInTheDocument();
|
|
37
36
|
});
|
|
38
37
|
});
|
|
39
38
|
});
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { render } from '@pie-lib/test-utils';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { graphProps } from '../../__tests__/utils';
|
|
4
4
|
|
|
5
5
|
import Axes, { RawXAxis, RawYAxis, firstNegativeValue, sharedValues } from '../axes';
|
|
6
6
|
|
|
7
7
|
describe('RawXAxis', () => {
|
|
8
|
-
let w;
|
|
9
8
|
let onChange = jest.fn();
|
|
10
|
-
const
|
|
9
|
+
const renderComponent = (extras) => {
|
|
11
10
|
const defaults = {
|
|
12
11
|
classes: {},
|
|
13
12
|
className: 'className',
|
|
@@ -19,22 +18,25 @@ describe('RawXAxis', () => {
|
|
|
19
18
|
up: true,
|
|
20
19
|
down: true,
|
|
21
20
|
},
|
|
21
|
+
columnTicksValues: [-1, 0, 1],
|
|
22
|
+
skipValues: [],
|
|
23
|
+
distanceFromOriginToFirstNegativeY: 0,
|
|
24
|
+
dy: 0,
|
|
22
25
|
};
|
|
23
26
|
const props = { ...defaults, ...extras };
|
|
24
|
-
return
|
|
27
|
+
return render(<RawXAxis {...props} />);
|
|
25
28
|
};
|
|
26
|
-
describe('
|
|
27
|
-
it('renders', () => {
|
|
28
|
-
|
|
29
|
-
expect(
|
|
29
|
+
describe('rendering', () => {
|
|
30
|
+
it('renders without crashing', () => {
|
|
31
|
+
const { container } = renderComponent();
|
|
32
|
+
expect(container.firstChild).toBeInTheDocument();
|
|
30
33
|
});
|
|
31
34
|
});
|
|
32
35
|
});
|
|
33
36
|
|
|
34
37
|
describe('RawYAxis', () => {
|
|
35
|
-
let w;
|
|
36
38
|
let onChange = jest.fn();
|
|
37
|
-
const
|
|
39
|
+
const renderComponent = (extras) => {
|
|
38
40
|
const defaults = {
|
|
39
41
|
classes: {},
|
|
40
42
|
className: 'className',
|
|
@@ -46,14 +48,16 @@ describe('RawYAxis', () => {
|
|
|
46
48
|
up: true,
|
|
47
49
|
down: true,
|
|
48
50
|
},
|
|
51
|
+
rowTickValues: [-1, 0, 1],
|
|
52
|
+
skipValues: [],
|
|
49
53
|
};
|
|
50
54
|
const props = { ...defaults, ...extras };
|
|
51
|
-
return
|
|
55
|
+
return render(<RawYAxis {...props} />);
|
|
52
56
|
};
|
|
53
|
-
describe('
|
|
54
|
-
it('renders', () => {
|
|
55
|
-
|
|
56
|
-
expect(
|
|
57
|
+
describe('rendering', () => {
|
|
58
|
+
it('renders without crashing', () => {
|
|
59
|
+
const { container } = renderComponent();
|
|
60
|
+
expect(container.firstChild).toBeInTheDocument();
|
|
57
61
|
});
|
|
58
62
|
});
|
|
59
63
|
});
|
|
@@ -61,11 +65,13 @@ describe('RawYAxis', () => {
|
|
|
61
65
|
const customScaleMock = (distance) => {
|
|
62
66
|
const fn = jest.fn((n) => n * distance);
|
|
63
67
|
fn.invert = jest.fn((n) => n * distance);
|
|
68
|
+
fn.domain = jest.fn(() => fn);
|
|
69
|
+
fn.range = jest.fn(() => fn);
|
|
70
|
+
fn.copy = jest.fn(() => customScaleMock(distance));
|
|
64
71
|
return fn;
|
|
65
72
|
};
|
|
66
73
|
|
|
67
|
-
describe
|
|
68
|
-
let w;
|
|
74
|
+
describe('Axes', () => {
|
|
69
75
|
let onChange = jest.fn();
|
|
70
76
|
|
|
71
77
|
const customGraphProps = {
|
|
@@ -88,7 +94,7 @@ describe.only('Axes', () => {
|
|
|
88
94
|
},
|
|
89
95
|
};
|
|
90
96
|
|
|
91
|
-
const
|
|
97
|
+
const renderComponent = (extras) => {
|
|
92
98
|
const defaults = {
|
|
93
99
|
classes: {},
|
|
94
100
|
className: 'className',
|
|
@@ -97,124 +103,114 @@ describe.only('Axes', () => {
|
|
|
97
103
|
};
|
|
98
104
|
|
|
99
105
|
const props = { ...defaults, ...extras };
|
|
100
|
-
return
|
|
106
|
+
return render(<Axes {...props} />);
|
|
101
107
|
};
|
|
102
|
-
describe('
|
|
103
|
-
it('renders', () => {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
expect(result).toEqual({
|
|
107
|
-
columnTicksValues: expect.arrayContaining([-2, -1, 0, 1, 2]),
|
|
108
|
-
distanceFromOriginToFirstNegativeX: 150,
|
|
109
|
-
firstNegativeX: -1,
|
|
110
|
-
});
|
|
108
|
+
describe('rendering', () => {
|
|
109
|
+
it('renders without crashing', () => {
|
|
110
|
+
const { container } = renderComponent();
|
|
111
|
+
expect(container.firstChild).toBeInTheDocument();
|
|
111
112
|
});
|
|
112
113
|
});
|
|
113
|
-
describe('yValues', () => {
|
|
114
|
-
it('renders', () => {
|
|
115
|
-
w = wrapper();
|
|
116
|
-
const result = w.instance().yValues();
|
|
117
|
-
expect(result).toEqual({
|
|
118
|
-
rowTickValues: expect.arrayContaining([-2, -1, 0, 1, 2]),
|
|
119
|
-
distanceFromOriginToFirstNegativeY: 200,
|
|
120
|
-
firstNegativeY: -1,
|
|
121
|
-
});
|
|
122
|
-
});
|
|
123
|
-
});
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
describe('firstNegativeValue should return undefiend for undefined interval', () => {
|
|
127
|
-
const interval = undefined;
|
|
128
|
-
const result = firstNegativeValue(interval);
|
|
129
|
-
expect(result).toEqual(undefined);
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
describe('firstNegativeValue should return undefiend for empty interval', () => {
|
|
133
|
-
const interval = [];
|
|
134
|
-
const result = firstNegativeValue(interval);
|
|
135
|
-
expect(result).toEqual(undefined);
|
|
136
114
|
});
|
|
137
115
|
|
|
138
|
-
describe('firstNegativeValue
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
describe('firstNegativeValue should return first negative number from interval', () => {
|
|
145
|
-
const interval = [1, 5, 7, -2, 4, 5, -1];
|
|
146
|
-
const result = firstNegativeValue(interval);
|
|
147
|
-
expect(result).toEqual(-2);
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
describe('skipValue should be empty array if firstNegativeValue for one of the axes is undefined', () => {
|
|
151
|
-
// x
|
|
152
|
-
const intervalX = [1, 2, 3, 4, 5, 6];
|
|
153
|
-
const firstNegativeX = firstNegativeValue(intervalX);
|
|
154
|
-
const distanceFromOriginToFirstNegativeX = -22;
|
|
155
|
-
|
|
156
|
-
// y
|
|
157
|
-
const intervalY = [-1, -2, 1, 2, 3, 4, 5, 6];
|
|
158
|
-
const firstNegativeY = firstNegativeValue(intervalY);
|
|
159
|
-
const distanceFromOriginToFirstNegativeY = -22;
|
|
116
|
+
describe('firstNegativeValue', () => {
|
|
117
|
+
it('should return undefined for undefined interval', () => {
|
|
118
|
+
const interval = undefined;
|
|
119
|
+
const result = firstNegativeValue(interval);
|
|
120
|
+
expect(result).toEqual(undefined);
|
|
121
|
+
});
|
|
160
122
|
|
|
161
|
-
|
|
123
|
+
it('should return undefined for empty interval', () => {
|
|
124
|
+
const interval = [];
|
|
125
|
+
const result = firstNegativeValue(interval);
|
|
126
|
+
expect(result).toEqual(undefined);
|
|
127
|
+
});
|
|
162
128
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
deltaAllowance,
|
|
169
|
-
);
|
|
129
|
+
it('should return undefined if there is no negative in interval array', () => {
|
|
130
|
+
const interval = [1, 5, 7, 4, 5];
|
|
131
|
+
const result = firstNegativeValue(interval);
|
|
132
|
+
expect(result).toEqual(undefined);
|
|
133
|
+
});
|
|
170
134
|
|
|
171
|
-
|
|
135
|
+
it('should return first negative number from interval', () => {
|
|
136
|
+
const interval = [1, 5, 7, -2, 4, 5, -1];
|
|
137
|
+
const result = firstNegativeValue(interval);
|
|
138
|
+
expect(result).toEqual(-2);
|
|
139
|
+
});
|
|
172
140
|
});
|
|
173
141
|
|
|
174
|
-
describe('
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
142
|
+
describe('sharedValues', () => {
|
|
143
|
+
it('should be empty array if firstNegativeValue for one of the axes is undefined', () => {
|
|
144
|
+
// x
|
|
145
|
+
const intervalX = [1, 2, 3, 4, 5, 6];
|
|
146
|
+
const firstNegativeX = firstNegativeValue(intervalX);
|
|
147
|
+
const distanceFromOriginToFirstNegativeX = -22;
|
|
148
|
+
|
|
149
|
+
// y
|
|
150
|
+
const intervalY = [-1, -2, 1, 2, 3, 4, 5, 6];
|
|
151
|
+
const firstNegativeY = firstNegativeValue(intervalY);
|
|
152
|
+
const distanceFromOriginToFirstNegativeY = -22;
|
|
153
|
+
|
|
154
|
+
const deltaAllowance = 5;
|
|
155
|
+
|
|
156
|
+
const result = sharedValues(
|
|
157
|
+
firstNegativeX,
|
|
158
|
+
firstNegativeY,
|
|
159
|
+
distanceFromOriginToFirstNegativeX,
|
|
160
|
+
distanceFromOriginToFirstNegativeY,
|
|
161
|
+
deltaAllowance,
|
|
162
|
+
);
|
|
163
|
+
|
|
164
|
+
expect(result).toEqual([]);
|
|
165
|
+
});
|
|
194
166
|
|
|
195
|
-
|
|
196
|
-
|
|
167
|
+
it('should be empty array if firstNegativeX and firstNegativeY are equal but they do not overlap', () => {
|
|
168
|
+
// x
|
|
169
|
+
const intervalX = [-1, -2, 1, 2, 3, 4, 5, 6];
|
|
170
|
+
const firstNegativeX = firstNegativeValue(intervalX);
|
|
171
|
+
const distanceFromOriginToFirstNegativeX = -7;
|
|
197
172
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
const distanceFromOriginToFirstNegativeX = -20;
|
|
173
|
+
// y
|
|
174
|
+
const intervalY = [-1, -2, 1, 2, 3, 4, 5, 6];
|
|
175
|
+
const firstNegativeY = firstNegativeValue(intervalY);
|
|
176
|
+
const distanceFromOriginToFirstNegativeY = -22;
|
|
203
177
|
|
|
204
|
-
|
|
205
|
-
const intervalY = [-1, -2, 1, 2, 3, 4, 5, 6];
|
|
206
|
-
const firstNegativeY = firstNegativeValue(intervalY);
|
|
207
|
-
const distanceFromOriginToFirstNegativeY = -22;
|
|
178
|
+
const deltaAllowance = 5;
|
|
208
179
|
|
|
209
|
-
|
|
180
|
+
const result = sharedValues(
|
|
181
|
+
firstNegativeX,
|
|
182
|
+
firstNegativeY,
|
|
183
|
+
distanceFromOriginToFirstNegativeX,
|
|
184
|
+
distanceFromOriginToFirstNegativeY,
|
|
185
|
+
deltaAllowance,
|
|
186
|
+
);
|
|
210
187
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
firstNegativeY,
|
|
214
|
-
distanceFromOriginToFirstNegativeX,
|
|
215
|
-
distanceFromOriginToFirstNegativeY,
|
|
216
|
-
deltaAllowance,
|
|
217
|
-
);
|
|
188
|
+
expect(result).toEqual([]);
|
|
189
|
+
});
|
|
218
190
|
|
|
219
|
-
|
|
191
|
+
it('should be -1 if firstNegativeX and firstNegativeY are equal and they overlap', () => {
|
|
192
|
+
// x
|
|
193
|
+
const intervalX = [-1, -2, 1, 2, 3, 4, 5, 6];
|
|
194
|
+
const firstNegativeX = firstNegativeValue(intervalX);
|
|
195
|
+
const distanceFromOriginToFirstNegativeX = -20;
|
|
196
|
+
|
|
197
|
+
// y
|
|
198
|
+
const intervalY = [-1, -2, 1, 2, 3, 4, 5, 6];
|
|
199
|
+
const firstNegativeY = firstNegativeValue(intervalY);
|
|
200
|
+
const distanceFromOriginToFirstNegativeY = -22;
|
|
201
|
+
|
|
202
|
+
const deltaAllowance = 5;
|
|
203
|
+
const dy = -20; // dy needs to be within the range for the condition to pass
|
|
204
|
+
|
|
205
|
+
const result = sharedValues(
|
|
206
|
+
firstNegativeX,
|
|
207
|
+
firstNegativeY,
|
|
208
|
+
distanceFromOriginToFirstNegativeX,
|
|
209
|
+
distanceFromOriginToFirstNegativeY,
|
|
210
|
+
deltaAllowance,
|
|
211
|
+
dy,
|
|
212
|
+
);
|
|
213
|
+
|
|
214
|
+
expect(result).toEqual([-1]);
|
|
215
|
+
});
|
|
220
216
|
});
|
package/src/axis/arrow.jsx
CHANGED
|
@@ -1,20 +1,16 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
3
|
|
|
4
|
-
import
|
|
5
|
-
import { withStyles } from '@material-ui/core/styles';
|
|
4
|
+
import { styled } from '@mui/material/styles';
|
|
6
5
|
import { types } from '@pie-lib/plot';
|
|
7
6
|
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
},
|
|
12
|
-
});
|
|
7
|
+
const StyledPath = styled('path')(({ theme }) => ({
|
|
8
|
+
fill: `var(--arrow-color, ${theme.palette.common.black})`,
|
|
9
|
+
}));
|
|
13
10
|
|
|
14
11
|
export class Arrow extends React.Component {
|
|
15
12
|
render() {
|
|
16
|
-
const { x, y,
|
|
17
|
-
const names = classNames(classes.root, className);
|
|
13
|
+
const { x, y, className, scale } = this.props;
|
|
18
14
|
let direction = this.props.direction || 'left';
|
|
19
15
|
|
|
20
16
|
const xv = scale.x(x);
|
|
@@ -40,7 +36,7 @@ export class Arrow extends React.Component {
|
|
|
40
36
|
transform = getTransform(xv, yv + 15, 270);
|
|
41
37
|
}
|
|
42
38
|
|
|
43
|
-
return <
|
|
39
|
+
return <StyledPath d="m 0,0 8,-5 0,10 -8,-5" transform={transform} className={className} />;
|
|
44
40
|
}
|
|
45
41
|
}
|
|
46
42
|
|
|
@@ -48,7 +44,6 @@ Arrow.propTypes = {
|
|
|
48
44
|
y: PropTypes.number,
|
|
49
45
|
x: PropTypes.number,
|
|
50
46
|
direction: PropTypes.oneOf(['left', 'right', 'up', 'down']),
|
|
51
|
-
classes: PropTypes.object.isRequired,
|
|
52
47
|
className: PropTypes.string,
|
|
53
48
|
scale: types.ScaleType.isRequired,
|
|
54
49
|
};
|
|
@@ -59,4 +54,4 @@ Arrow.defaultProps = {
|
|
|
59
54
|
direction: 'left',
|
|
60
55
|
};
|
|
61
56
|
|
|
62
|
-
export default
|
|
57
|
+
export default Arrow;
|