@pie-lib/graphing 2.34.3-next.0 → 2.34.3-next.162
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/esm/package.json +3 -0
- 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 +168 -224
- 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 +65 -121
- 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 +33 -21
- 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 +210 -206
- package/src/grid.jsx +2 -4
- package/src/key-legend.jsx +52 -56
- package/src/labels.jsx +23 -30
- 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/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,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,32 +1,35 @@
|
|
|
1
1
|
import { lineToolComponent, lineBase, styles } from '../shared/line';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import PropTypes from 'prop-types';
|
|
4
|
-
|
|
5
4
|
import { types } from '@pie-lib/plot';
|
|
6
|
-
import {
|
|
7
|
-
|
|
5
|
+
import { styled } from '@mui/material/styles';
|
|
6
|
+
|
|
7
|
+
const StyledLineRoot = styled('line')(({ theme, disabled, correctness }) => ({
|
|
8
|
+
...styles.line(theme),
|
|
9
|
+
...(disabled && {
|
|
10
|
+
...styles.disabled(theme),
|
|
11
|
+
...styles.disabledSecondary(theme),
|
|
12
|
+
}),
|
|
13
|
+
...(correctness === 'correct' && styles.correct(theme, 'stroke')),
|
|
14
|
+
...(correctness === 'incorrect' && styles.incorrect(theme, 'stroke')),
|
|
15
|
+
...(correctness === 'missing' && styles.missing(theme, 'stroke')),
|
|
16
|
+
}));
|
|
8
17
|
|
|
9
|
-
const lineStyles = (theme) => ({
|
|
10
|
-
line: styles.line(theme),
|
|
11
|
-
disabled: styles.disabled(theme),
|
|
12
|
-
disabledSecondary: styles.disabledSecondary(theme),
|
|
13
|
-
correct: styles.correct(theme, 'stroke'),
|
|
14
|
-
incorrect: styles.incorrect(theme, 'stroke'),
|
|
15
|
-
missing: styles.missing(theme, 'stroke'),
|
|
16
|
-
});
|
|
17
18
|
export const Line = (props) => {
|
|
18
|
-
const { className,
|
|
19
|
+
const { className, correctness, disabled, graphProps, from, to, ...rest } = props;
|
|
19
20
|
const { scale } = graphProps;
|
|
20
21
|
|
|
21
22
|
return (
|
|
22
|
-
<
|
|
23
|
+
<StyledLineRoot
|
|
23
24
|
stroke="green"
|
|
24
|
-
strokeWidth=
|
|
25
|
+
strokeWidth={6}
|
|
25
26
|
x1={scale.x(from.x)}
|
|
26
27
|
y1={scale.y(from.y)}
|
|
27
28
|
x2={scale.x(to.x)}
|
|
28
29
|
y2={scale.y(to.y)}
|
|
29
|
-
className={
|
|
30
|
+
className={className}
|
|
31
|
+
disabled={disabled}
|
|
32
|
+
correctness={correctness}
|
|
30
33
|
{...rest}
|
|
31
34
|
/>
|
|
32
35
|
);
|
|
@@ -34,7 +37,6 @@ export const Line = (props) => {
|
|
|
34
37
|
|
|
35
38
|
Line.propTypes = {
|
|
36
39
|
className: PropTypes.string,
|
|
37
|
-
classes: PropTypes.object,
|
|
38
40
|
correctness: PropTypes.string,
|
|
39
41
|
disabled: PropTypes.bool,
|
|
40
42
|
graphProps: PropTypes.any,
|
|
@@ -42,8 +44,7 @@ Line.propTypes = {
|
|
|
42
44
|
to: types.PointType,
|
|
43
45
|
};
|
|
44
46
|
|
|
45
|
-
const
|
|
46
|
-
const Segment = lineBase(StyledLine);
|
|
47
|
+
const Segment = lineBase(Line);
|
|
47
48
|
const Component = lineToolComponent(Segment);
|
|
48
49
|
|
|
49
50
|
export default Component;
|
|
@@ -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,13 +1,56 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
|
+
import { styled } from '@mui/material/styles';
|
|
4
|
+
import { color } from '@pie-lib/render-ui';
|
|
3
5
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
+
const StyledArrowHead = styled('polygon')(({ disabled, correctness }) => ({
|
|
7
|
+
fill: color.defaults.BLACK,
|
|
8
|
+
...(disabled && {
|
|
9
|
+
fill: color.disabled(),
|
|
10
|
+
}),
|
|
11
|
+
...(correctness === 'correct' && {
|
|
12
|
+
fill: color.correctWithIcon(),
|
|
13
|
+
}),
|
|
14
|
+
...(correctness === 'incorrect' && {
|
|
15
|
+
fill: color.incorrectWithIcon(),
|
|
16
|
+
}),
|
|
17
|
+
...(correctness === 'missing' && {
|
|
18
|
+
fill: color.missingWithIcon(),
|
|
19
|
+
}),
|
|
20
|
+
}));
|
|
21
|
+
|
|
22
|
+
const StyledMarker = styled('marker')(({ disabled, correctness }) => ({
|
|
23
|
+
'& polygon': {
|
|
24
|
+
fill: color.defaults.BLACK,
|
|
25
|
+
...(disabled && {
|
|
26
|
+
fill: color.disabled(),
|
|
27
|
+
}),
|
|
28
|
+
...(correctness === 'correct' && {
|
|
29
|
+
fill: color.correctWithIcon(),
|
|
30
|
+
}),
|
|
31
|
+
...(correctness === 'incorrect' && {
|
|
32
|
+
fill: color.incorrectWithIcon(),
|
|
33
|
+
}),
|
|
34
|
+
...(correctness === 'missing' && {
|
|
35
|
+
fill: color.missingWithIcon(),
|
|
36
|
+
}),
|
|
37
|
+
},
|
|
38
|
+
}));
|
|
39
|
+
|
|
40
|
+
export const ArrowHead = ({ size, transform, points, disabled, correctness }) => (
|
|
41
|
+
<StyledArrowHead
|
|
42
|
+
points={points || `0,0 ${size},${size / 2} 0,${size}`}
|
|
43
|
+
transform={transform}
|
|
44
|
+
disabled={disabled}
|
|
45
|
+
correctness={correctness}
|
|
46
|
+
/>
|
|
6
47
|
);
|
|
7
48
|
ArrowHead.propTypes = {
|
|
8
49
|
points: PropTypes.string,
|
|
9
50
|
size: PropTypes.number,
|
|
10
51
|
transform: PropTypes.string,
|
|
52
|
+
disabled: PropTypes.bool,
|
|
53
|
+
correctness: PropTypes.string,
|
|
11
54
|
};
|
|
12
55
|
ArrowHead.defaultProps = {
|
|
13
56
|
points: '',
|
|
@@ -18,9 +61,16 @@ export const genUid = () => {
|
|
|
18
61
|
const v = (Math.random() * 1000).toFixed(0);
|
|
19
62
|
return `arrow-${v}`;
|
|
20
63
|
};
|
|
21
|
-
export const ArrowMarker = ({ id, size, className }) => {
|
|
64
|
+
export const ArrowMarker = ({ id, size, className, disabled, correctness }) => {
|
|
65
|
+
// Parse styling info from className if provided (for backward compatibility)
|
|
66
|
+
const isDisabled = disabled || className?.includes('disabled');
|
|
67
|
+
const parsedCorrectness = correctness ||
|
|
68
|
+
(className?.includes('incorrect') ? 'incorrect' :
|
|
69
|
+
className?.includes('correct') ? 'correct' :
|
|
70
|
+
className?.includes('missing') ? 'missing' : null);
|
|
71
|
+
|
|
22
72
|
return (
|
|
23
|
-
<
|
|
73
|
+
<StyledMarker
|
|
24
74
|
id={id}
|
|
25
75
|
viewBox={`0 0 ${size} ${size}`}
|
|
26
76
|
refX={size / 2}
|
|
@@ -28,16 +78,19 @@ export const ArrowMarker = ({ id, size, className }) => {
|
|
|
28
78
|
markerWidth={size}
|
|
29
79
|
markerHeight={size}
|
|
30
80
|
orient="auto-start-reverse"
|
|
31
|
-
|
|
81
|
+
disabled={isDisabled}
|
|
82
|
+
correctness={parsedCorrectness}
|
|
32
83
|
>
|
|
33
|
-
<ArrowHead size={size} />
|
|
34
|
-
</
|
|
84
|
+
<ArrowHead size={size} disabled={isDisabled} correctness={parsedCorrectness} />
|
|
85
|
+
</StyledMarker>
|
|
35
86
|
);
|
|
36
87
|
};
|
|
37
88
|
ArrowMarker.propTypes = {
|
|
38
89
|
id: PropTypes.string,
|
|
39
90
|
size: PropTypes.number,
|
|
40
91
|
className: PropTypes.string,
|
|
92
|
+
disabled: PropTypes.bool,
|
|
93
|
+
correctness: PropTypes.string,
|
|
41
94
|
};
|
|
42
95
|
ArrowMarker.defaultProps = {
|
|
43
96
|
size: 5,
|
|
@@ -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
|
});
|