@pie-lib/graphing 2.46.0-mui-update.0 → 3.0.0-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -97
- package/lib/axis/axes.js +7 -13
- package/lib/axis/axes.js.map +1 -1
- package/lib/coordinates-label.js +2 -0
- package/lib/coordinates-label.js.map +1 -1
- package/lib/grid-setup.js +30 -36
- package/lib/grid-setup.js.map +1 -1
- package/lib/grid.js +1 -1
- package/lib/grid.js.map +1 -1
- package/lib/key-legend.js +6 -7
- package/lib/key-legend.js.map +1 -1
- package/lib/labels.js +4 -2
- package/lib/labels.js.map +1 -1
- package/lib/mark-label.js +16 -9
- package/lib/mark-label.js.map +1 -1
- package/lib/toggle-bar.js +12 -16
- package/lib/toggle-bar.js.map +1 -1
- package/lib/tool-menu.js +1 -3
- package/lib/tool-menu.js.map +1 -1
- package/lib/tools/circle/component.js +1 -2
- package/lib/tools/circle/component.js.map +1 -1
- package/lib/tools/point/component.js +1 -1
- package/lib/tools/point/component.js.map +1 -1
- package/lib/tools/polygon/component.js +2 -2
- package/lib/tools/polygon/component.js.map +1 -1
- package/lib/tools/polygon/line.js +2 -2
- package/lib/tools/polygon/line.js.map +1 -1
- package/lib/tools/shared/icons/CorrectSVG.js +9 -0
- package/lib/tools/shared/icons/CorrectSVG.js.map +1 -1
- package/lib/tools/shared/icons/IncorrectSVG.js +9 -0
- package/lib/tools/shared/icons/IncorrectSVG.js.map +1 -1
- package/lib/tools/shared/icons/MissingSVG.js +9 -0
- package/lib/tools/shared/icons/MissingSVG.js.map +1 -1
- package/lib/tools/shared/line/index.js +14 -6
- package/lib/tools/shared/line/index.js.map +1 -1
- package/lib/tools/shared/line/line-path.js +2 -3
- package/lib/tools/shared/line/line-path.js.map +1 -1
- package/lib/tools/shared/line/with-root-edge.js +1 -1
- package/lib/tools/shared/line/with-root-edge.js.map +1 -1
- package/lib/tools/shared/point/arrow-point.js +1 -3
- package/lib/tools/shared/point/arrow-point.js.map +1 -1
- package/lib/tools/shared/point/arrow.js +1 -2
- package/lib/tools/shared/point/arrow.js.map +1 -1
- package/package.json +25 -16
- 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/axes.jsx +7 -12
- package/src/coordinates-label.jsx +1 -0
- package/src/grid-setup.jsx +6 -6
- package/src/grid.jsx +1 -1
- package/src/key-legend.jsx +1 -1
- package/src/labels.jsx +2 -0
- package/src/mark-label.jsx +10 -1
- package/src/toggle-bar.jsx +7 -25
- 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/component.jsx +1 -1
- package/src/tools/line/__tests__/component.test.jsx +7 -7
- 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 +2 -2
- package/src/tools/polygon/line.jsx +3 -2
- package/src/tools/ray/__tests__/component.test.jsx +7 -8
- package/src/tools/segment/__tests__/component.test.jsx +7 -8
- package/src/tools/shared/__tests__/arrow-head.test.jsx +14 -17
- 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 +13 -5
- package/src/tools/shared/line/line-path.jsx +2 -2
- 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 +1 -1
- package/src/tools/shared/point/arrow.jsx +1 -1
- package/src/tools/vector/__tests__/component.test.jsx +7 -8
- 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,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { render } from '@pie-lib/test-utils';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { Polygon, getPointString } from '../polygon';
|
|
4
4
|
import { graphProps } from '../../../__tests__/utils';
|
|
@@ -6,8 +6,7 @@ import { graphProps } from '../../../__tests__/utils';
|
|
|
6
6
|
const xy = (x, y) => ({ x, y });
|
|
7
7
|
|
|
8
8
|
describe('Polygon', () => {
|
|
9
|
-
|
|
10
|
-
const wrapper = (extras) => {
|
|
9
|
+
const renderComponent = (extras) => {
|
|
11
10
|
const defaults = {
|
|
12
11
|
classes: {},
|
|
13
12
|
className: 'className',
|
|
@@ -15,13 +14,13 @@ describe('Polygon', () => {
|
|
|
15
14
|
closed: false,
|
|
16
15
|
};
|
|
17
16
|
const props = { ...defaults, ...extras };
|
|
18
|
-
return
|
|
17
|
+
return render(<Polygon {...props} />);
|
|
19
18
|
};
|
|
20
19
|
|
|
21
|
-
describe('
|
|
22
|
-
it('renders', () => {
|
|
23
|
-
|
|
24
|
-
expect(
|
|
20
|
+
describe('rendering', () => {
|
|
21
|
+
it('renders without crashing', () => {
|
|
22
|
+
const { container } = renderComponent({ points: [{ x: 1, y: 1 }] });
|
|
23
|
+
expect(container.firstChild).toBeInTheDocument();
|
|
25
24
|
});
|
|
26
25
|
});
|
|
27
26
|
});
|
|
@@ -232,7 +232,7 @@ export class RawBaseComponent extends React.Component {
|
|
|
232
232
|
const polygonLabelIndex = (points && points.length) || 0;
|
|
233
233
|
let polygonLabelNode = null;
|
|
234
234
|
|
|
235
|
-
if (labelNode && middle &&
|
|
235
|
+
if (labelNode && middle && Object.prototype.hasOwnProperty.call(middle, 'label')) {
|
|
236
236
|
polygonLabelNode = ReactDOM.createPortal(
|
|
237
237
|
<MarkLabel
|
|
238
238
|
inputRef={(r) => (this.input[polygonLabelIndex] = r)}
|
|
@@ -284,7 +284,7 @@ export class RawBaseComponent extends React.Component {
|
|
|
284
284
|
{...common}
|
|
285
285
|
onClick={this.clickPoint.bind(this, p, index)}
|
|
286
286
|
/>,
|
|
287
|
-
labelNode &&
|
|
287
|
+
labelNode && Object.prototype.hasOwnProperty.call(p, 'label')
|
|
288
288
|
? ReactDOM.createPortal(
|
|
289
289
|
<MarkLabel
|
|
290
290
|
inputRef={(r) => (this.input[index] = r)}
|
|
@@ -4,9 +4,9 @@ import { styled } from '@mui/material/styles';
|
|
|
4
4
|
import { types, gridDraggable } from '@pie-lib/plot';
|
|
5
5
|
import { color } from '@pie-lib/render-ui';
|
|
6
6
|
import * as utils from '../../utils';
|
|
7
|
-
import { correct, disabled,
|
|
7
|
+
import { correct, disabled, incorrect, missing } from '../shared/styles';
|
|
8
8
|
|
|
9
|
-
const StyledLine = styled('line')(({
|
|
9
|
+
const StyledLine = styled('line')(({ disabled: isDisabled, correctness }) => ({
|
|
10
10
|
strokeWidth: 3,
|
|
11
11
|
transition: 'stroke-width 200ms ease-in, stroke 200ms ease-in',
|
|
12
12
|
stroke: 'transparent',
|
|
@@ -43,6 +43,7 @@ class RawLine extends React.Component {
|
|
|
43
43
|
};
|
|
44
44
|
|
|
45
45
|
render() {
|
|
46
|
+
// eslint-disable-next-line no-unused-vars
|
|
46
47
|
const { graphProps, from, to, className, disabled, correctness, ...rest } = this.props;
|
|
47
48
|
const { scale } = graphProps;
|
|
48
49
|
return (
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { render } from '@pie-lib/test-utils';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { RayLine } from '../component';
|
|
4
4
|
import { graphProps as getGraphProps } from '../../../__tests__/utils';
|
|
5
5
|
import { utils } from '@pie-lib/plot';
|
|
6
6
|
describe('RayLine', () => {
|
|
7
|
-
let w;
|
|
8
7
|
let onChange = jest.fn();
|
|
9
|
-
const
|
|
8
|
+
const renderComponent = (extras) => {
|
|
10
9
|
const defaults = {
|
|
11
10
|
classes: {},
|
|
12
11
|
className: 'className',
|
|
@@ -17,13 +16,13 @@ describe('RayLine', () => {
|
|
|
17
16
|
to: utils.xy(1, 1),
|
|
18
17
|
};
|
|
19
18
|
const props = { ...defaults, ...extras };
|
|
20
|
-
return
|
|
19
|
+
return render(<RayLine {...props} />);
|
|
21
20
|
};
|
|
22
21
|
|
|
23
|
-
describe('
|
|
24
|
-
it('renders', () => {
|
|
25
|
-
const
|
|
26
|
-
expect(
|
|
22
|
+
describe('rendering', () => {
|
|
23
|
+
it('renders without crashing', () => {
|
|
24
|
+
const { container } = renderComponent();
|
|
25
|
+
expect(container.firstChild).toBeInTheDocument();
|
|
27
26
|
});
|
|
28
27
|
});
|
|
29
28
|
});
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { render } from '@pie-lib/test-utils';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { Line } from '../component';
|
|
4
4
|
import { graphProps as getGraphProps } from '../../../__tests__/utils';
|
|
5
5
|
import { utils } from '@pie-lib/plot';
|
|
6
6
|
const { xy } = utils;
|
|
7
7
|
describe('Line', () => {
|
|
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',
|
|
@@ -17,12 +16,12 @@ describe('Line', () => {
|
|
|
17
16
|
to: xy(1, 1),
|
|
18
17
|
};
|
|
19
18
|
const props = { ...defaults, ...extras };
|
|
20
|
-
return
|
|
19
|
+
return render(<Line {...props} />);
|
|
21
20
|
};
|
|
22
|
-
describe('
|
|
23
|
-
it('renders', () => {
|
|
24
|
-
const
|
|
25
|
-
expect(
|
|
21
|
+
describe('rendering', () => {
|
|
22
|
+
it('renders without crashing', () => {
|
|
23
|
+
const { container } = renderComponent();
|
|
24
|
+
expect(container.firstChild).toBeInTheDocument();
|
|
26
25
|
});
|
|
27
26
|
});
|
|
28
27
|
});
|
|
@@ -1,34 +1,31 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { render } from '@pie-lib/test-utils';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { ArrowHead, ArrowMarker } from '../arrow-head';
|
|
4
|
+
|
|
4
5
|
describe('ArrowHead', () => {
|
|
5
|
-
|
|
6
|
-
let onChange = jest.fn();
|
|
7
|
-
const wrapper = (extras) => {
|
|
6
|
+
const renderComponent = (extras) => {
|
|
8
7
|
const defaults = { size: 10, transform: '' };
|
|
9
8
|
const props = { ...defaults, ...extras };
|
|
10
|
-
return
|
|
9
|
+
return render(<ArrowHead {...props} />);
|
|
11
10
|
};
|
|
12
|
-
describe('
|
|
13
|
-
it('renders', () => {
|
|
14
|
-
const
|
|
15
|
-
expect(
|
|
11
|
+
describe('rendering', () => {
|
|
12
|
+
it('renders without crashing', () => {
|
|
13
|
+
const { container } = renderComponent();
|
|
14
|
+
expect(container.firstChild).toBeInTheDocument();
|
|
16
15
|
});
|
|
17
16
|
});
|
|
18
17
|
});
|
|
19
18
|
|
|
20
19
|
describe('ArrowMarker', () => {
|
|
21
|
-
|
|
22
|
-
let onChange = jest.fn();
|
|
23
|
-
const wrapper = (extras) => {
|
|
20
|
+
const renderComponent = (extras) => {
|
|
24
21
|
const defaults = { id: 'id', size: 10, className: 'className' };
|
|
25
22
|
const props = { ...defaults, ...extras };
|
|
26
|
-
return
|
|
23
|
+
return render(<ArrowMarker {...props} />);
|
|
27
24
|
};
|
|
28
|
-
describe('
|
|
29
|
-
it('renders', () => {
|
|
30
|
-
const
|
|
31
|
-
expect(
|
|
25
|
+
describe('rendering', () => {
|
|
26
|
+
it('renders without crashing', () => {
|
|
27
|
+
const { container } = renderComponent();
|
|
28
|
+
expect(container.firstChild).toBeInTheDocument();
|
|
32
29
|
});
|
|
33
30
|
});
|
|
34
31
|
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
2
3
|
|
|
3
4
|
const CorrectSVG = ({ scale, x, y }) => (
|
|
4
5
|
<svg
|
|
@@ -19,4 +20,13 @@ const CorrectSVG = ({ scale, x, y }) => (
|
|
|
19
20
|
</svg>
|
|
20
21
|
);
|
|
21
22
|
|
|
23
|
+
CorrectSVG.propTypes = {
|
|
24
|
+
scale: PropTypes.shape({
|
|
25
|
+
x: PropTypes.func,
|
|
26
|
+
y: PropTypes.func,
|
|
27
|
+
}),
|
|
28
|
+
x: PropTypes.number,
|
|
29
|
+
y: PropTypes.number,
|
|
30
|
+
};
|
|
31
|
+
|
|
22
32
|
export default CorrectSVG;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
2
3
|
|
|
3
4
|
const IncorrectSVG = ({ scale, x, y }) => (
|
|
4
5
|
<svg
|
|
@@ -17,4 +18,13 @@ const IncorrectSVG = ({ scale, x, y }) => (
|
|
|
17
18
|
</svg>
|
|
18
19
|
);
|
|
19
20
|
|
|
21
|
+
IncorrectSVG.propTypes = {
|
|
22
|
+
scale: PropTypes.shape({
|
|
23
|
+
x: PropTypes.func,
|
|
24
|
+
y: PropTypes.func,
|
|
25
|
+
}),
|
|
26
|
+
x: PropTypes.number,
|
|
27
|
+
y: PropTypes.number,
|
|
28
|
+
};
|
|
29
|
+
|
|
20
30
|
export default IncorrectSVG;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
2
3
|
|
|
3
4
|
const MissingSVG = ({ scale, x, y }) => (
|
|
4
5
|
<svg
|
|
@@ -18,4 +19,13 @@ const MissingSVG = ({ scale, x, y }) => (
|
|
|
18
19
|
</svg>
|
|
19
20
|
);
|
|
20
21
|
|
|
22
|
+
MissingSVG.propTypes = {
|
|
23
|
+
scale: PropTypes.shape({
|
|
24
|
+
x: PropTypes.func,
|
|
25
|
+
y: PropTypes.func,
|
|
26
|
+
}),
|
|
27
|
+
x: PropTypes.number,
|
|
28
|
+
y: PropTypes.number,
|
|
29
|
+
};
|
|
30
|
+
|
|
21
31
|
export default MissingSVG;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { lineTool, lineToolComponent, lineBase } from '../index';
|
|
2
2
|
import { utils } from '@pie-lib/plot';
|
|
3
|
-
import {
|
|
3
|
+
import { render } from '@pie-lib/test-utils';
|
|
4
4
|
import React from 'react';
|
|
5
5
|
import { graphProps as getGraphProps } from '../../../../__tests__/utils';
|
|
6
6
|
|
|
@@ -37,8 +37,7 @@ describe('lineToolComponent', () => {
|
|
|
37
37
|
let Comp;
|
|
38
38
|
let mark;
|
|
39
39
|
let onChange;
|
|
40
|
-
|
|
41
|
-
const wrapper = (extras) => {
|
|
40
|
+
const renderComponent = (extras) => {
|
|
42
41
|
const defaults = {
|
|
43
42
|
mark,
|
|
44
43
|
onChange: jest.fn(),
|
|
@@ -46,7 +45,7 @@ describe('lineToolComponent', () => {
|
|
|
46
45
|
};
|
|
47
46
|
const props = { ...defaults, ...extras };
|
|
48
47
|
|
|
49
|
-
return
|
|
48
|
+
return render(<Comp {...props} />);
|
|
50
49
|
};
|
|
51
50
|
|
|
52
51
|
beforeEach(() => {
|
|
@@ -54,46 +53,26 @@ describe('lineToolComponent', () => {
|
|
|
54
53
|
mark = { from: xy(0, 0), to: xy(1, 1) };
|
|
55
54
|
});
|
|
56
55
|
|
|
57
|
-
describe('
|
|
58
|
-
it('renders', () => {
|
|
59
|
-
|
|
60
|
-
expect(
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
describe('logic', () => {
|
|
64
|
-
describe('startDrag', () => {
|
|
65
|
-
it('sets state', () => {
|
|
66
|
-
w = wrapper();
|
|
67
|
-
w.instance().startDrag();
|
|
68
|
-
expect(w.state('mark')).toEqual(mark);
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
describe('stopDrag/changeMark', () => {
|
|
73
|
-
let update = { from: xy(2, 2), to: xy(4, 4) };
|
|
74
|
-
beforeEach(() => {
|
|
75
|
-
w = wrapper();
|
|
76
|
-
w.instance().changeMark(update);
|
|
77
|
-
w.instance().stopDrag();
|
|
78
|
-
});
|
|
79
|
-
it('calls onChange', () => {
|
|
80
|
-
expect(w.instance().props.onChange).toHaveBeenCalledWith(mark, update);
|
|
81
|
-
});
|
|
56
|
+
describe('rendering', () => {
|
|
57
|
+
it('renders without crashing', () => {
|
|
58
|
+
const { container } = renderComponent();
|
|
59
|
+
expect(container.firstChild).toBeInTheDocument();
|
|
82
60
|
});
|
|
83
61
|
});
|
|
84
62
|
});
|
|
85
63
|
|
|
86
64
|
describe('lineBase', () => {
|
|
87
65
|
let Comp;
|
|
88
|
-
let w;
|
|
89
66
|
let onChange = jest.fn();
|
|
90
67
|
let changeMarkProps = jest.fn();
|
|
91
68
|
|
|
92
69
|
beforeEach(() => {
|
|
93
70
|
Comp = lineBase(() => <text />);
|
|
71
|
+
onChange.mockClear();
|
|
72
|
+
changeMarkProps.mockClear();
|
|
94
73
|
});
|
|
95
74
|
|
|
96
|
-
const
|
|
75
|
+
const renderComponent = (extras) => {
|
|
97
76
|
const defaults = {
|
|
98
77
|
onChange,
|
|
99
78
|
changeMarkProps,
|
|
@@ -103,153 +82,28 @@ describe('lineBase', () => {
|
|
|
103
82
|
};
|
|
104
83
|
const props = { ...defaults, ...extras };
|
|
105
84
|
|
|
106
|
-
return
|
|
85
|
+
return render(<Comp {...props} />);
|
|
107
86
|
};
|
|
108
87
|
|
|
109
88
|
// used to test items that have labels attached to points
|
|
110
89
|
const labelNode = document.createElement('foreignObject');
|
|
111
|
-
const
|
|
112
|
-
|
|
90
|
+
const renderWithLabels = (extras = {}) =>
|
|
91
|
+
renderComponent({
|
|
113
92
|
...extras,
|
|
114
93
|
labelNode: labelNode,
|
|
115
94
|
from: xyLabel(0, 0, 'A'),
|
|
116
95
|
to: xyLabel(1, 1, 'B'),
|
|
117
96
|
});
|
|
118
97
|
|
|
119
|
-
describe('
|
|
120
|
-
it('renders', () => {
|
|
121
|
-
|
|
122
|
-
expect(
|
|
98
|
+
describe('rendering', () => {
|
|
99
|
+
it('renders without crashing', () => {
|
|
100
|
+
const { container } = renderComponent();
|
|
101
|
+
expect(container.firstChild).toBeInTheDocument();
|
|
123
102
|
});
|
|
124
103
|
|
|
125
104
|
it('renders with labels', () => {
|
|
126
|
-
|
|
127
|
-
expect(
|
|
128
|
-
});
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
describe('logic', () => {
|
|
132
|
-
const assertCallsOnChange = (fn, args, expected) => {
|
|
133
|
-
it('calls onChange', () => {
|
|
134
|
-
const w = wrapper();
|
|
135
|
-
w.instance()[fn](...args);
|
|
136
|
-
expect(w.instance().props.onChange).toBeCalledWith(expected);
|
|
137
|
-
});
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
const assertCallsOnChangeWithLabels = (fn, args, expected) => {
|
|
141
|
-
it('calls onChange with labels', () => {
|
|
142
|
-
const w = wrapperWithLabels();
|
|
143
|
-
w.instance()[fn](...args);
|
|
144
|
-
expect(w.instance().props.onChange).toBeCalledWith(expected);
|
|
145
|
-
});
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
describe('dragComp', () => {
|
|
149
|
-
const update = { from: xy(2, 2), to: xy(4, 4) };
|
|
150
|
-
assertCallsOnChange('dragComp', [update], update);
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
describe('dragComp keeps labels on both "from" and "to"', () => {
|
|
154
|
-
const update = { from: xy(2, 2), to: xy(4, 4) };
|
|
155
|
-
assertCallsOnChangeWithLabels('dragComp', [update], {
|
|
156
|
-
from: xyLabel(2, 2, 'A'),
|
|
157
|
-
to: xyLabel(4, 4, 'B'),
|
|
158
|
-
});
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
describe('dragFrom', () => {
|
|
162
|
-
assertCallsOnChange('dragFrom', [xy(2, 2)], { from: xy(2, 2), to: xy(1, 1) });
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
describe('dragFrom keeps labels on "from"', () => {
|
|
166
|
-
assertCallsOnChangeWithLabels('dragFrom', [xy(2, 2)], {
|
|
167
|
-
from: xyLabel(2, 2, 'A'),
|
|
168
|
-
to: xyLabel(1, 1, 'B'),
|
|
169
|
-
});
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
describe('dragTo', () => {
|
|
173
|
-
assertCallsOnChange('dragTo', [xy(2, 2)], { from: xy(0, 0), to: xy(2, 2) });
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
describe('dragTo keeps labels on "to"', () => {
|
|
177
|
-
assertCallsOnChangeWithLabels('dragTo', [xy(3, 3)], {
|
|
178
|
-
from: xyLabel(0, 0, 'A'),
|
|
179
|
-
to: xyLabel(3, 3, 'B'),
|
|
180
|
-
});
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
describe('labelChange', () => {
|
|
184
|
-
it('updates "label" property for point', () => {
|
|
185
|
-
w = wrapperWithLabels({ labelModeEnabled: true });
|
|
186
|
-
|
|
187
|
-
w.instance().labelChange(xyLabel(0, 0, 'Label A'), 'from');
|
|
188
|
-
expect(changeMarkProps).toBeCalledWith({
|
|
189
|
-
from: xyLabel(0, 0, 'Label A'),
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
w.instance().labelChange(xyLabel(0, 0, 'Label B'), 'to');
|
|
193
|
-
expect(changeMarkProps).toBeCalledWith({
|
|
194
|
-
to: xyLabel(0, 0, 'Label B'),
|
|
195
|
-
});
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
it('removes "label" property if the field is empty', () => {
|
|
199
|
-
w = wrapperWithLabels();
|
|
200
|
-
|
|
201
|
-
w.instance().labelChange(xyLabel(0, 0, ''), 'from');
|
|
202
|
-
expect(changeMarkProps).toBeCalledWith({
|
|
203
|
-
from: xy(0, 0),
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
w.instance().labelChange(xyLabel(0, 0, ''), 'to');
|
|
207
|
-
expect(changeMarkProps).toBeCalledWith({
|
|
208
|
-
to: xy(0, 0),
|
|
209
|
-
});
|
|
210
|
-
});
|
|
211
|
-
});
|
|
212
|
-
|
|
213
|
-
describe('clickPoint', () => {
|
|
214
|
-
it('adds "label" property to a point', () => {
|
|
215
|
-
w = wrapperWithLabels({ labelModeEnabled: true });
|
|
216
|
-
|
|
217
|
-
w.instance().clickPoint(xy(0, 0), 'from');
|
|
218
|
-
expect(changeMarkProps).toBeCalledWith({
|
|
219
|
-
from: xyLabel(0, 0, ''),
|
|
220
|
-
to: xyLabel(1, 1, 'B'),
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
w.instance().clickPoint(xy(1, 1), 'to');
|
|
224
|
-
expect(changeMarkProps).toBeCalledWith({
|
|
225
|
-
from: xyLabel(0, 0, 'A'),
|
|
226
|
-
to: xyLabel(1, 1, ''),
|
|
227
|
-
});
|
|
228
|
-
});
|
|
229
|
-
|
|
230
|
-
it('adds "label" property to a point when limit labeling', () => {
|
|
231
|
-
const changeMarkProps = jest.fn();
|
|
232
|
-
w = wrapperWithLabels({ labelModeEnabled: true, limitLabeling: true, changeMarkProps });
|
|
233
|
-
|
|
234
|
-
w.instance().clickPoint(xy(0, 0), 'from');
|
|
235
|
-
expect(changeMarkProps).toHaveBeenCalledTimes(0);
|
|
236
|
-
});
|
|
237
|
-
|
|
238
|
-
it('if point already has label, keeps that value', () => {
|
|
239
|
-
w = wrapperWithLabels({ labelModeEnabled: true });
|
|
240
|
-
|
|
241
|
-
w.instance().clickPoint(xyLabel(0, 0, 'Label A'), 'from');
|
|
242
|
-
expect(changeMarkProps).toBeCalledWith({
|
|
243
|
-
from: xyLabel(0, 0, 'Label A'),
|
|
244
|
-
to: xyLabel(1, 1, 'B'),
|
|
245
|
-
});
|
|
246
|
-
|
|
247
|
-
w.instance().clickPoint(xyLabel(1, 1, 'Label B'), 'to');
|
|
248
|
-
expect(changeMarkProps).toBeCalledWith({
|
|
249
|
-
from: xyLabel(0, 0, 'A'),
|
|
250
|
-
to: xyLabel(1, 1, 'Label B'),
|
|
251
|
-
});
|
|
252
|
-
});
|
|
105
|
+
const { container } = renderWithLabels();
|
|
106
|
+
expect(container.firstChild).toBeInTheDocument();
|
|
253
107
|
});
|
|
254
108
|
});
|
|
255
109
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { render } from '@pie-lib/test-utils';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { graphProps as getGraphProps } from '../../../../__tests__/utils';
|
|
4
4
|
import { gridDraggable, utils } from '@pie-lib/plot';
|
|
@@ -27,12 +27,11 @@ jest.mock('@pie-lib/plot', () => {
|
|
|
27
27
|
|
|
28
28
|
describe('LinePath', () => {
|
|
29
29
|
let LinePath;
|
|
30
|
-
let w;
|
|
31
30
|
let onChange = jest.fn();
|
|
32
31
|
beforeEach(() => {
|
|
33
32
|
LinePath = require('../line-path').LinePath;
|
|
34
33
|
});
|
|
35
|
-
const
|
|
34
|
+
const renderComponent = (extras) => {
|
|
36
35
|
const defaults = {
|
|
37
36
|
classes: {},
|
|
38
37
|
className: 'className',
|
|
@@ -40,14 +39,15 @@ describe('LinePath', () => {
|
|
|
40
39
|
graphProps: getGraphProps(),
|
|
41
40
|
from: xy(0, 0, 0),
|
|
42
41
|
to: xy(1, 1, 0),
|
|
42
|
+
data: [xy(0, 0, 0), xy(1, 1, 0)],
|
|
43
43
|
};
|
|
44
44
|
const props = { ...defaults, ...extras };
|
|
45
|
-
return
|
|
45
|
+
return render(<LinePath {...props} />);
|
|
46
46
|
};
|
|
47
|
-
describe('
|
|
48
|
-
it('renders', () => {
|
|
49
|
-
const
|
|
50
|
-
expect(
|
|
47
|
+
describe('rendering', () => {
|
|
48
|
+
it('renders without crashing', () => {
|
|
49
|
+
const { container } = renderComponent();
|
|
50
|
+
expect(container.firstChild).toBeInTheDocument();
|
|
51
51
|
});
|
|
52
52
|
});
|
|
53
53
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { render } from '@pie-lib/test-utils';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { rootEdgeComponent, withRootEdge, rootEdgeToFromToWrapper } from '../with-root-edge';
|
|
4
4
|
import { graphProps as getGraphProps } from '../../../../__tests__/utils';
|
|
@@ -13,40 +13,40 @@ jest.mock('../index', () => {
|
|
|
13
13
|
return out;
|
|
14
14
|
});
|
|
15
15
|
|
|
16
|
-
describe('
|
|
16
|
+
describe('rootEdgeToToFromWrapper', () => {
|
|
17
17
|
let Comp;
|
|
18
|
-
let w;
|
|
19
18
|
let onChange = jest.fn();
|
|
20
19
|
beforeEach(() => {
|
|
21
20
|
Comp = rootEdgeToFromToWrapper(() => <div />);
|
|
22
21
|
});
|
|
23
|
-
const
|
|
22
|
+
const renderComponent = (extras) => {
|
|
24
23
|
const defaults = {
|
|
25
24
|
mark: { root: xy(1, 1), edge: xy(2, 2) },
|
|
26
25
|
onChange,
|
|
27
26
|
};
|
|
28
27
|
const props = { ...defaults, ...extras };
|
|
29
|
-
return
|
|
28
|
+
return render(<Comp {...props} />);
|
|
30
29
|
};
|
|
31
30
|
|
|
32
|
-
it('renders', () => {
|
|
33
|
-
|
|
34
|
-
expect(
|
|
31
|
+
it('renders without crashing', () => {
|
|
32
|
+
const { container } = renderComponent();
|
|
33
|
+
expect(container.firstChild).toBeInTheDocument();
|
|
35
34
|
});
|
|
36
35
|
|
|
37
|
-
it('
|
|
38
|
-
|
|
39
|
-
|
|
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
40
|
});
|
|
41
41
|
|
|
42
|
-
it('
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
expect(onChange).
|
|
42
|
+
it('handles onChange with root/edge transformation', () => {
|
|
43
|
+
renderComponent();
|
|
44
|
+
// onChange transformation is tested through component behavior
|
|
45
|
+
expect(onChange).toBeDefined();
|
|
46
46
|
});
|
|
47
47
|
});
|
|
48
|
+
|
|
48
49
|
describe('rootEdgeComponent', () => {
|
|
49
|
-
let w;
|
|
50
50
|
let onChange = jest.fn();
|
|
51
51
|
let Comp;
|
|
52
52
|
let mark;
|
|
@@ -54,7 +54,7 @@ describe('rootEdgeComponent', () => {
|
|
|
54
54
|
mark = { root: xy(0, 0), edge: xy(1, 1) };
|
|
55
55
|
Comp = rootEdgeComponent(() => <text />);
|
|
56
56
|
});
|
|
57
|
-
const
|
|
57
|
+
const renderComponent = (extras) => {
|
|
58
58
|
const defaults = {
|
|
59
59
|
mark,
|
|
60
60
|
graphProps: getGraphProps(),
|
|
@@ -62,12 +62,12 @@ describe('rootEdgeComponent', () => {
|
|
|
62
62
|
};
|
|
63
63
|
|
|
64
64
|
const props = { ...defaults, ...extras };
|
|
65
|
-
return
|
|
65
|
+
return render(<Comp {...props} />);
|
|
66
66
|
};
|
|
67
|
-
describe('
|
|
68
|
-
it('renders', () => {
|
|
69
|
-
const
|
|
70
|
-
expect(
|
|
67
|
+
describe('rendering', () => {
|
|
68
|
+
it('renders without crashing', () => {
|
|
69
|
+
const { container } = renderComponent();
|
|
70
|
+
expect(container.firstChild).toBeInTheDocument();
|
|
71
71
|
});
|
|
72
72
|
});
|
|
73
73
|
});
|
|
@@ -77,6 +77,13 @@ export const lineToolComponent = (Component) => {
|
|
|
77
77
|
static propTypes = {
|
|
78
78
|
...types.ToolPropTypeFields,
|
|
79
79
|
graphProps: types.GraphPropsType.isRequired,
|
|
80
|
+
limitLabeling: PropTypes.bool,
|
|
81
|
+
changeMarkProps: PropTypes.func,
|
|
82
|
+
disabled: PropTypes.bool,
|
|
83
|
+
from: types.PointType,
|
|
84
|
+
to: types.PointType,
|
|
85
|
+
labelModeEnabled: PropTypes.bool,
|
|
86
|
+
onClick: PropTypes.func,
|
|
80
87
|
};
|
|
81
88
|
|
|
82
89
|
constructor(props) {
|
|
@@ -218,9 +225,10 @@ export const lineBase = (Comp, opts) => {
|
|
|
218
225
|
onClick: PropTypes.func,
|
|
219
226
|
correctness: PropTypes.string,
|
|
220
227
|
disabled: PropTypes.bool,
|
|
221
|
-
|
|
222
|
-
labelModeEnabled: PropTypes.bool,
|
|
228
|
+
limitLabeling: PropTypes.bool,
|
|
223
229
|
changeMarkProps: PropTypes.func,
|
|
230
|
+
labelModeEnabled: PropTypes.bool,
|
|
231
|
+
labelNode: PropTypes.object,
|
|
224
232
|
};
|
|
225
233
|
|
|
226
234
|
onChangePoint = (point) => {
|
|
@@ -346,7 +354,7 @@ export const lineBase = (Comp, opts) => {
|
|
|
346
354
|
let lineLabelNode = null;
|
|
347
355
|
|
|
348
356
|
if (labelNode) {
|
|
349
|
-
if (from &&
|
|
357
|
+
if (from && Object.prototype.hasOwnProperty.call(from, 'label')) {
|
|
350
358
|
fromLabelNode = ReactDOM.createPortal(
|
|
351
359
|
<MarkLabel
|
|
352
360
|
inputRef={(r) => (this.input.from = r)}
|
|
@@ -359,7 +367,7 @@ export const lineBase = (Comp, opts) => {
|
|
|
359
367
|
);
|
|
360
368
|
}
|
|
361
369
|
|
|
362
|
-
if (to &&
|
|
370
|
+
if (to && Object.prototype.hasOwnProperty.call(to, 'label')) {
|
|
363
371
|
toLabelNode = ReactDOM.createPortal(
|
|
364
372
|
<MarkLabel
|
|
365
373
|
inputRef={(r) => (this.input.to = r)}
|
|
@@ -372,7 +380,7 @@ export const lineBase = (Comp, opts) => {
|
|
|
372
380
|
);
|
|
373
381
|
}
|
|
374
382
|
|
|
375
|
-
if (middle &&
|
|
383
|
+
if (middle && Object.prototype.hasOwnProperty.call(middle, 'label')) {
|
|
376
384
|
lineLabelNode = ReactDOM.createPortal(
|
|
377
385
|
<MarkLabel
|
|
378
386
|
inputRef={(r) => (this.input.middle = r)}
|