@pie-lib/graphing-solution-set 2.16.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.json +1 -0
- package/CHANGELOG.md +16 -0
- package/LICENSE.md +5 -0
- package/NEXT.CHANGELOG.json +1 -0
- package/lib/__tests__/graph-with-controls.test.js +191 -0
- package/lib/__tests__/graph.test.js +290 -0
- package/lib/__tests__/grid.test.js +40 -0
- package/lib/__tests__/labels.test.js +59 -0
- package/lib/__tests__/mark-label.test.js +154 -0
- package/lib/__tests__/toggle-bar.test.js +54 -0
- package/lib/__tests__/tool-menu.test.js +43 -0
- package/lib/__tests__/undo-redo.test.js +42 -0
- package/lib/__tests__/use-debounce.test.js +28 -0
- package/lib/__tests__/utils.js +72 -0
- package/lib/__tests__/utils.test.js +133 -0
- package/lib/axis/__tests__/arrow.test.js +68 -0
- package/lib/axis/__tests__/axes.test.js +214 -0
- package/lib/axis/arrow.js +115 -0
- package/lib/axis/axes.js +415 -0
- package/lib/axis/index.js +26 -0
- package/lib/bg.js +139 -0
- package/lib/container/actions.js +24 -0
- package/lib/container/index.js +166 -0
- package/lib/container/marks.js +27 -0
- package/lib/container/middleware.js +25 -0
- package/lib/container/reducer.js +25 -0
- package/lib/coordinates-label.js +109 -0
- package/lib/graph-with-controls.js +372 -0
- package/lib/graph.js +419 -0
- package/lib/grid-setup.js +462 -0
- package/lib/grid.js +176 -0
- package/lib/index.js +51 -0
- package/lib/labels.js +299 -0
- package/lib/mark-label.js +208 -0
- package/lib/toggle-bar.js +336 -0
- package/lib/tool-menu.js +325 -0
- package/lib/tools/index.js +29 -0
- package/lib/tools/line/__tests__/component.test.js +56 -0
- package/lib/tools/line/component.js +106 -0
- package/lib/tools/line/index.js +16 -0
- package/lib/tools/polygon/__tests__/component.test.js +245 -0
- package/lib/tools/polygon/__tests__/index.test.js +95 -0
- package/lib/tools/polygon/__tests__/line.test.js +43 -0
- package/lib/tools/polygon/__tests__/polygon.test.js +73 -0
- package/lib/tools/polygon/component.js +457 -0
- package/lib/tools/polygon/index.js +106 -0
- package/lib/tools/polygon/line.js +151 -0
- package/lib/tools/polygon/polygon.js +171 -0
- package/lib/tools/shared/__tests__/arrow-head.test.js +62 -0
- package/lib/tools/shared/arrow-head.js +75 -0
- package/lib/tools/shared/line/__tests__/index.test.js +291 -0
- package/lib/tools/shared/line/__tests__/line-path.test.js +78 -0
- package/lib/tools/shared/line/__tests__/with-root-edge.test.js +122 -0
- package/lib/tools/shared/line/index.js +637 -0
- package/lib/tools/shared/line/line-path.js +145 -0
- package/lib/tools/shared/line/with-root-edge.js +155 -0
- package/lib/tools/shared/point/__tests__/arrow-point.test.js +137 -0
- package/lib/tools/shared/point/__tests__/base-point.test.js +134 -0
- package/lib/tools/shared/point/arrow-point.js +113 -0
- package/lib/tools/shared/point/arrow.js +96 -0
- package/lib/tools/shared/point/base-point.js +151 -0
- package/lib/tools/shared/point/index.js +94 -0
- package/lib/tools/shared/styles.js +49 -0
- package/lib/tools/shared/types.js +19 -0
- package/lib/undo-redo.js +107 -0
- package/lib/use-debounce.js +32 -0
- package/lib/utils.js +314 -0
- package/package.json +50 -0
- package/src/__tests__/__snapshots__/graph-with-controls.test.jsx.snap +114 -0
- package/src/__tests__/__snapshots__/graph.test.jsx.snap +213 -0
- package/src/__tests__/__snapshots__/grid.test.jsx.snap +54 -0
- package/src/__tests__/__snapshots__/labels.test.jsx.snap +30 -0
- package/src/__tests__/__snapshots__/mark-label.test.jsx.snap +37 -0
- package/src/__tests__/__snapshots__/toggle-bar.test.jsx.snap +7 -0
- package/src/__tests__/__snapshots__/tool-menu.test.jsx.snap +35 -0
- package/src/__tests__/__snapshots__/undo-redo.test.jsx.snap +15 -0
- package/src/__tests__/graph-with-controls.test.jsx +131 -0
- package/src/__tests__/graph.test.jsx +230 -0
- package/src/__tests__/grid.test.jsx +20 -0
- package/src/__tests__/labels.test.jsx +38 -0
- package/src/__tests__/mark-label.test.jsx +68 -0
- package/src/__tests__/toggle-bar.test.jsx +36 -0
- package/src/__tests__/tool-menu.test.jsx +29 -0
- package/src/__tests__/undo-redo.test.jsx +25 -0
- package/src/__tests__/use-debounce.test.js +21 -0
- package/src/__tests__/utils.js +38 -0
- package/src/__tests__/utils.test.js +151 -0
- package/src/axis/__tests__/__snapshots__/arrow.test.jsx.snap +33 -0
- package/src/axis/__tests__/__snapshots__/axes.test.jsx.snap +122 -0
- package/src/axis/__tests__/arrow.test.jsx +39 -0
- package/src/axis/__tests__/axes.test.jsx +220 -0
- package/src/axis/arrow.jsx +62 -0
- package/src/axis/axes.jsx +307 -0
- package/src/axis/index.js +2 -0
- package/src/bg.jsx +96 -0
- package/src/container/actions.js +8 -0
- package/src/container/index.jsx +86 -0
- package/src/container/marks.js +14 -0
- package/src/container/middleware.js +7 -0
- package/src/container/reducer.js +5 -0
- package/src/coordinates-label.jsx +73 -0
- package/src/graph-with-controls.jsx +263 -0
- package/src/graph.jsx +334 -0
- package/src/grid-setup.jsx +427 -0
- package/src/grid.jsx +135 -0
- package/src/index.js +7 -0
- package/src/labels.jsx +214 -0
- package/src/mark-label.jsx +136 -0
- package/src/toggle-bar.jsx +242 -0
- package/src/tool-menu.jsx +294 -0
- package/src/tools/index.js +8 -0
- package/src/tools/line/__tests__/__snapshots__/component.test.jsx.snap +20 -0
- package/src/tools/line/__tests__/component.test.jsx +36 -0
- package/src/tools/line/component.jsx +77 -0
- package/src/tools/line/index.js +4 -0
- package/src/tools/polygon/__tests__/__snapshots__/component.test.jsx.snap +94 -0
- package/src/tools/polygon/__tests__/__snapshots__/line.test.jsx.snap +44 -0
- package/src/tools/polygon/__tests__/__snapshots__/polygon.test.jsx.snap +53 -0
- package/src/tools/polygon/__tests__/component.test.jsx +214 -0
- package/src/tools/polygon/__tests__/index.test.js +65 -0
- package/src/tools/polygon/__tests__/line.test.jsx +25 -0
- package/src/tools/polygon/__tests__/polygon.test.jsx +44 -0
- package/src/tools/polygon/component.jsx +336 -0
- package/src/tools/polygon/index.js +52 -0
- package/src/tools/polygon/line.jsx +78 -0
- package/src/tools/polygon/polygon.jsx +101 -0
- package/src/tools/shared/__tests__/__snapshots__/arrow-head.test.jsx.snap +32 -0
- package/src/tools/shared/__tests__/arrow-head.test.jsx +34 -0
- package/src/tools/shared/arrow-head.jsx +46 -0
- package/src/tools/shared/line/__tests__/__snapshots__/index.test.jsx.snap +360 -0
- package/src/tools/shared/line/__tests__/__snapshots__/line-path.test.jsx.snap +57 -0
- package/src/tools/shared/line/__tests__/__snapshots__/with-root-edge.test.jsx.snap +63 -0
- package/src/tools/shared/line/__tests__/index.test.jsx +247 -0
- package/src/tools/shared/line/__tests__/line-path.test.jsx +53 -0
- package/src/tools/shared/line/__tests__/with-root-edge.test.jsx +73 -0
- package/src/tools/shared/line/index.jsx +473 -0
- package/src/tools/shared/line/line-path.jsx +88 -0
- package/src/tools/shared/line/with-root-edge.jsx +97 -0
- package/src/tools/shared/point/__tests__/__snapshots__/arrow-point.test.jsx.snap +55 -0
- package/src/tools/shared/point/__tests__/__snapshots__/base-point.test.jsx.snap +43 -0
- package/src/tools/shared/point/__tests__/arrow-point.test.jsx +87 -0
- package/src/tools/shared/point/__tests__/base-point.test.jsx +84 -0
- package/src/tools/shared/point/arrow-point.jsx +60 -0
- package/src/tools/shared/point/arrow.jsx +40 -0
- package/src/tools/shared/point/base-point.jsx +86 -0
- package/src/tools/shared/point/index.jsx +60 -0
- package/src/tools/shared/styles.js +20 -0
- package/src/tools/shared/types.js +8 -0
- package/src/undo-redo.jsx +47 -0
- package/src/use-debounce.js +13 -0
- package/src/utils.js +234 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import Polygon from './component';
|
|
2
|
+
import { equalPoints } from '../../utils';
|
|
3
|
+
|
|
4
|
+
export const addPointToArray = (point, arr) => {
|
|
5
|
+
arr = arr || [];
|
|
6
|
+
|
|
7
|
+
if (arr.length === 0) {
|
|
8
|
+
return { points: [point], closed: false };
|
|
9
|
+
} else if (arr.length === 1) {
|
|
10
|
+
if (equalPoints(point, arr[0])) {
|
|
11
|
+
return { points: arr, closed: false };
|
|
12
|
+
} else {
|
|
13
|
+
return { points: [...arr, point], closed: false };
|
|
14
|
+
}
|
|
15
|
+
} else if (arr.length >= 2) {
|
|
16
|
+
const closed = equalPoints(point, arr[0]);
|
|
17
|
+
|
|
18
|
+
if (closed) {
|
|
19
|
+
return { points: arr, closed };
|
|
20
|
+
} else {
|
|
21
|
+
const hasPoint = !!arr.find((p) => equalPoints(p, point));
|
|
22
|
+
|
|
23
|
+
if (hasPoint) {
|
|
24
|
+
return { points: arr, closed: false };
|
|
25
|
+
} else {
|
|
26
|
+
return { points: [...arr, point], closed: false };
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export const tool = () => ({
|
|
33
|
+
type: 'polygon',
|
|
34
|
+
Component: Polygon,
|
|
35
|
+
complete: (data, mark) => {
|
|
36
|
+
return { ...mark, building: false, closed: true };
|
|
37
|
+
},
|
|
38
|
+
addPoint: (point, mark) => {
|
|
39
|
+
if (!mark) {
|
|
40
|
+
return {
|
|
41
|
+
type: 'polygon',
|
|
42
|
+
points: [point],
|
|
43
|
+
closed: false,
|
|
44
|
+
building: true,
|
|
45
|
+
};
|
|
46
|
+
} else {
|
|
47
|
+
const { closed, points } = addPointToArray(point, mark.points);
|
|
48
|
+
|
|
49
|
+
return { ...mark, closed, points, building: !closed };
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
});
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import { withStyles } from '@material-ui/core/styles';
|
|
4
|
+
import { types, gridDraggable } from '@pie-lib/plot';
|
|
5
|
+
import { color } from '@pie-lib/render-ui';
|
|
6
|
+
import * as utils from '../../utils';
|
|
7
|
+
import classNames from 'classnames';
|
|
8
|
+
import { correct, disabled, incorrect, missing } from '../shared/styles';
|
|
9
|
+
|
|
10
|
+
class RawLine extends React.Component {
|
|
11
|
+
static propTypes = {
|
|
12
|
+
className: PropTypes.string,
|
|
13
|
+
classes: PropTypes.object,
|
|
14
|
+
from: types.PointType,
|
|
15
|
+
to: types.PointType,
|
|
16
|
+
graphProps: types.GraphPropsType.isRequired,
|
|
17
|
+
disabled: PropTypes.bool,
|
|
18
|
+
correctness: PropTypes.string,
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
static defaultProps = {
|
|
22
|
+
from: {},
|
|
23
|
+
to: {},
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
render() {
|
|
27
|
+
const { graphProps, classes, from, to, className, disabled, correctness, ...rest } = this.props;
|
|
28
|
+
const { scale } = graphProps;
|
|
29
|
+
return (
|
|
30
|
+
<line
|
|
31
|
+
x1={scale.x(from.x)}
|
|
32
|
+
y1={scale.y(from.y)}
|
|
33
|
+
x2={scale.x(to.x)}
|
|
34
|
+
y2={scale.y(to.y)}
|
|
35
|
+
className={classNames(classes.line, disabled && classes.disabled, className, classes[correctness])}
|
|
36
|
+
{...rest}
|
|
37
|
+
/>
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export const Line = withStyles(() => ({
|
|
43
|
+
line: {
|
|
44
|
+
strokeWidth: 6,
|
|
45
|
+
transition: 'stroke-width 200ms ease-in, stroke 200ms ease-in',
|
|
46
|
+
stroke: 'transparent',
|
|
47
|
+
'&:hover': {
|
|
48
|
+
strokeWidth: 7,
|
|
49
|
+
stroke: color.defaults.SECONDARY,
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
disabled: {
|
|
53
|
+
...disabled('stroke'),
|
|
54
|
+
strokeWidth: 2,
|
|
55
|
+
},
|
|
56
|
+
correct: correct('stoke'),
|
|
57
|
+
incorrect: incorrect('stroke'),
|
|
58
|
+
missing: missing('stroke'),
|
|
59
|
+
}))(RawLine);
|
|
60
|
+
|
|
61
|
+
export default gridDraggable({
|
|
62
|
+
bounds: (props, { domain, range }) => {
|
|
63
|
+
const { from, to } = props;
|
|
64
|
+
const area = utils.lineToArea(from, to);
|
|
65
|
+
return utils.bounds(area, domain, range);
|
|
66
|
+
},
|
|
67
|
+
anchorPoint: (props) => {
|
|
68
|
+
const { from } = props;
|
|
69
|
+
return from;
|
|
70
|
+
},
|
|
71
|
+
fromDelta: (props, delta) => {
|
|
72
|
+
const { from, to } = props;
|
|
73
|
+
return {
|
|
74
|
+
from: utils.point(from).add(utils.point(delta)),
|
|
75
|
+
to: utils.point(to).add(utils.point(delta)),
|
|
76
|
+
};
|
|
77
|
+
},
|
|
78
|
+
})(Line);
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import { withStyles } from '@material-ui/core/styles';
|
|
4
|
+
import { gridDraggable, types } from '@pie-lib/plot';
|
|
5
|
+
import * as utils from '../../utils';
|
|
6
|
+
import classNames from 'classnames';
|
|
7
|
+
import { color } from '@pie-lib/render-ui';
|
|
8
|
+
import { fade } from '@material-ui/core/styles/colorManipulator';
|
|
9
|
+
import { correct, disabled, incorrect } from '../shared/styles';
|
|
10
|
+
|
|
11
|
+
export const getPointString = (points, scale) => {
|
|
12
|
+
return (points || [])
|
|
13
|
+
.map((p) => {
|
|
14
|
+
const scaledPoint = {
|
|
15
|
+
x: scale.x(p.x),
|
|
16
|
+
y: scale.y(p.y),
|
|
17
|
+
};
|
|
18
|
+
return `${scaledPoint.x},${scaledPoint.y}`;
|
|
19
|
+
})
|
|
20
|
+
.join(' ');
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export class RawPolygon extends React.Component {
|
|
24
|
+
static propTypes = {
|
|
25
|
+
classes: PropTypes.object,
|
|
26
|
+
className: PropTypes.string,
|
|
27
|
+
isSolution: PropTypes.bool,
|
|
28
|
+
points: PropTypes.arrayOf(types.PointType),
|
|
29
|
+
graphProps: types.GraphPropsType.isRequired,
|
|
30
|
+
closed: PropTypes.bool.isRequired,
|
|
31
|
+
correctness: PropTypes.string,
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
static defaultProps = {
|
|
35
|
+
points: [],
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
render() {
|
|
39
|
+
const { points, classes, className, correctness, graphProps, closed, isSolution, ...rest } = this.props;
|
|
40
|
+
const { scale } = graphProps;
|
|
41
|
+
|
|
42
|
+
const pointString = getPointString(points, scale);
|
|
43
|
+
const Tag = closed ? 'polygon' : 'polyline';
|
|
44
|
+
return (
|
|
45
|
+
<Tag
|
|
46
|
+
points={pointString}
|
|
47
|
+
className={classNames(isSolution ? classes.gssSolution : classes.gssClosed, classes[correctness], className)}
|
|
48
|
+
{...rest}
|
|
49
|
+
/>
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export const Polygon = withStyles((theme) => ({
|
|
55
|
+
closed: {
|
|
56
|
+
fill: fade(theme.palette.primary.light, 0.2), // TODO hardcoded color
|
|
57
|
+
strokeWidth: 2,
|
|
58
|
+
stroke: color.defaults.SECONDARY_LIGHT,
|
|
59
|
+
},
|
|
60
|
+
open: {
|
|
61
|
+
fill: fade(theme.palette.primary.light, 0.0), // TODO hardcoded color
|
|
62
|
+
strokeWidth: 2,
|
|
63
|
+
stroke: color.defaults.SECONDARY_LIGHT,
|
|
64
|
+
pointerEvents: 'none',
|
|
65
|
+
},
|
|
66
|
+
gssClosed: {
|
|
67
|
+
fill: 'transparent',
|
|
68
|
+
'&:hover': {
|
|
69
|
+
fill: 'rgb(0, 0, 0, 0.25)',
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
gssSolution: {
|
|
73
|
+
fill: 'rgb(60, 73, 150, 0.6)',
|
|
74
|
+
},
|
|
75
|
+
disabled: {
|
|
76
|
+
...disabled('stroke'),
|
|
77
|
+
},
|
|
78
|
+
correct: {
|
|
79
|
+
...correct('stroke'),
|
|
80
|
+
},
|
|
81
|
+
incorrect: {
|
|
82
|
+
...incorrect('stroke'),
|
|
83
|
+
},
|
|
84
|
+
}))(RawPolygon);
|
|
85
|
+
|
|
86
|
+
export default gridDraggable({
|
|
87
|
+
bounds: (props, { domain, range }) => {
|
|
88
|
+
const { points } = props;
|
|
89
|
+
const area = utils.polygonToArea(points);
|
|
90
|
+
return utils.bounds(area, domain, range);
|
|
91
|
+
},
|
|
92
|
+
anchorPoint: (props) => {
|
|
93
|
+
const { points } = props;
|
|
94
|
+
return points[0];
|
|
95
|
+
},
|
|
96
|
+
fromDelta: (props, delta) => {
|
|
97
|
+
const { points } = props;
|
|
98
|
+
|
|
99
|
+
return points.map((p) => utils.point(p).add(utils.point(delta)));
|
|
100
|
+
},
|
|
101
|
+
})(Polygon);
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`ArrowHead snapshot renders 1`] = `
|
|
4
|
+
<polygon
|
|
5
|
+
points="0,0 10,5 0,10"
|
|
6
|
+
transform=""
|
|
7
|
+
/>
|
|
8
|
+
`;
|
|
9
|
+
|
|
10
|
+
exports[`ArrowMarker snapshot renders 1`] = `
|
|
11
|
+
<marker
|
|
12
|
+
className="className"
|
|
13
|
+
id="id"
|
|
14
|
+
markerHeight={10}
|
|
15
|
+
markerWidth={10}
|
|
16
|
+
orient="auto-start-reverse"
|
|
17
|
+
refX={5}
|
|
18
|
+
refY={5}
|
|
19
|
+
style={
|
|
20
|
+
Object {
|
|
21
|
+
"fill": "#000000",
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
viewBox="0 0 10 10"
|
|
25
|
+
>
|
|
26
|
+
<ArrowHead
|
|
27
|
+
points=""
|
|
28
|
+
size={10}
|
|
29
|
+
transform=""
|
|
30
|
+
/>
|
|
31
|
+
</marker>
|
|
32
|
+
`;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { shallow } from 'enzyme';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { ArrowHead, ArrowMarker } from '../arrow-head';
|
|
4
|
+
describe('ArrowHead', () => {
|
|
5
|
+
let w;
|
|
6
|
+
let onChange = jest.fn();
|
|
7
|
+
const wrapper = (extras) => {
|
|
8
|
+
const defaults = { size: 10, transform: '' };
|
|
9
|
+
const props = { ...defaults, ...extras };
|
|
10
|
+
return shallow(<ArrowHead {...props} />);
|
|
11
|
+
};
|
|
12
|
+
describe('snapshot', () => {
|
|
13
|
+
it('renders', () => {
|
|
14
|
+
const w = wrapper();
|
|
15
|
+
expect(w).toMatchSnapshot();
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
describe('ArrowMarker', () => {
|
|
21
|
+
let w;
|
|
22
|
+
let onChange = jest.fn();
|
|
23
|
+
const wrapper = (extras) => {
|
|
24
|
+
const defaults = { id: 'id', size: 10, className: 'className' };
|
|
25
|
+
const props = { ...defaults, ...extras };
|
|
26
|
+
return shallow(<ArrowMarker {...props} />);
|
|
27
|
+
};
|
|
28
|
+
describe('snapshot', () => {
|
|
29
|
+
it('renders', () => {
|
|
30
|
+
const w = wrapper();
|
|
31
|
+
expect(w).toMatchSnapshot();
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import { color } from '@pie-lib/render-ui';
|
|
4
|
+
|
|
5
|
+
export const ArrowHead = ({ size, transform, points }) => (
|
|
6
|
+
<polygon points={points || `0,0 ${size},${size / 2} 0,${size}`} transform={transform} />
|
|
7
|
+
);
|
|
8
|
+
ArrowHead.propTypes = {
|
|
9
|
+
points: PropTypes.string,
|
|
10
|
+
size: PropTypes.number,
|
|
11
|
+
transform: PropTypes.string,
|
|
12
|
+
};
|
|
13
|
+
ArrowHead.defaultProps = {
|
|
14
|
+
points: '',
|
|
15
|
+
size: 10,
|
|
16
|
+
transform: '',
|
|
17
|
+
};
|
|
18
|
+
export const genUid = () => {
|
|
19
|
+
const v = (Math.random() * 1000).toFixed(0);
|
|
20
|
+
return `arrow-${v}`;
|
|
21
|
+
};
|
|
22
|
+
export const ArrowMarker = ({ id, size, className }) => {
|
|
23
|
+
return (
|
|
24
|
+
<marker
|
|
25
|
+
id={id}
|
|
26
|
+
viewBox={`0 0 ${size} ${size}`}
|
|
27
|
+
refX={size / 2}
|
|
28
|
+
refY={size / 2}
|
|
29
|
+
markerWidth={size}
|
|
30
|
+
markerHeight={size}
|
|
31
|
+
orient="auto-start-reverse"
|
|
32
|
+
className={className}
|
|
33
|
+
style={{ fill: color.defaults.BLACK }}
|
|
34
|
+
>
|
|
35
|
+
<ArrowHead size={size} />
|
|
36
|
+
</marker>
|
|
37
|
+
);
|
|
38
|
+
};
|
|
39
|
+
ArrowMarker.propTypes = {
|
|
40
|
+
id: PropTypes.string,
|
|
41
|
+
size: PropTypes.number,
|
|
42
|
+
className: PropTypes.string,
|
|
43
|
+
};
|
|
44
|
+
ArrowMarker.defaultProps = {
|
|
45
|
+
size: 5,
|
|
46
|
+
};
|
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`lineBase render renders 1`] = `
|
|
4
|
+
<g>
|
|
5
|
+
<GridDraggable
|
|
6
|
+
from={
|
|
7
|
+
Object {
|
|
8
|
+
"x": 0,
|
|
9
|
+
"y": 0,
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
graphProps={
|
|
13
|
+
Object {
|
|
14
|
+
"domain": Object {
|
|
15
|
+
"max": 1,
|
|
16
|
+
"min": 0,
|
|
17
|
+
"step": 1,
|
|
18
|
+
},
|
|
19
|
+
"range": Object {
|
|
20
|
+
"max": 1,
|
|
21
|
+
"min": 0,
|
|
22
|
+
"step": 1,
|
|
23
|
+
},
|
|
24
|
+
"scale": Object {
|
|
25
|
+
"x": [MockFunction],
|
|
26
|
+
"y": [MockFunction],
|
|
27
|
+
},
|
|
28
|
+
"size": Object {
|
|
29
|
+
"height": 400,
|
|
30
|
+
"width": 400,
|
|
31
|
+
},
|
|
32
|
+
"snap": Object {
|
|
33
|
+
"x": [MockFunction],
|
|
34
|
+
"y": [MockFunction],
|
|
35
|
+
},
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
onClick={[Function]}
|
|
39
|
+
onDrag={[Function]}
|
|
40
|
+
to={
|
|
41
|
+
Object {
|
|
42
|
+
"x": 1,
|
|
43
|
+
"y": 1,
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/>
|
|
47
|
+
<WithStyles(GridDraggable)
|
|
48
|
+
graphProps={
|
|
49
|
+
Object {
|
|
50
|
+
"domain": Object {
|
|
51
|
+
"max": 1,
|
|
52
|
+
"min": 0,
|
|
53
|
+
"step": 1,
|
|
54
|
+
},
|
|
55
|
+
"range": Object {
|
|
56
|
+
"max": 1,
|
|
57
|
+
"min": 0,
|
|
58
|
+
"step": 1,
|
|
59
|
+
},
|
|
60
|
+
"scale": Object {
|
|
61
|
+
"x": [MockFunction],
|
|
62
|
+
"y": [MockFunction],
|
|
63
|
+
},
|
|
64
|
+
"size": Object {
|
|
65
|
+
"height": 400,
|
|
66
|
+
"width": 400,
|
|
67
|
+
},
|
|
68
|
+
"snap": Object {
|
|
69
|
+
"x": [MockFunction],
|
|
70
|
+
"y": [MockFunction],
|
|
71
|
+
},
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
onClick={[Function]}
|
|
75
|
+
onDrag={[Function]}
|
|
76
|
+
x={0}
|
|
77
|
+
y={0}
|
|
78
|
+
/>
|
|
79
|
+
<WithStyles(GridDraggable)
|
|
80
|
+
angle={45}
|
|
81
|
+
graphProps={
|
|
82
|
+
Object {
|
|
83
|
+
"domain": Object {
|
|
84
|
+
"max": 1,
|
|
85
|
+
"min": 0,
|
|
86
|
+
"step": 1,
|
|
87
|
+
},
|
|
88
|
+
"range": Object {
|
|
89
|
+
"max": 1,
|
|
90
|
+
"min": 0,
|
|
91
|
+
"step": 1,
|
|
92
|
+
},
|
|
93
|
+
"scale": Object {
|
|
94
|
+
"x": [MockFunction],
|
|
95
|
+
"y": [MockFunction],
|
|
96
|
+
},
|
|
97
|
+
"size": Object {
|
|
98
|
+
"height": 400,
|
|
99
|
+
"width": 400,
|
|
100
|
+
},
|
|
101
|
+
"snap": Object {
|
|
102
|
+
"x": [MockFunction],
|
|
103
|
+
"y": [MockFunction],
|
|
104
|
+
},
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
onClick={[Function]}
|
|
108
|
+
onDrag={[Function]}
|
|
109
|
+
x={1}
|
|
110
|
+
y={1}
|
|
111
|
+
/>
|
|
112
|
+
</g>
|
|
113
|
+
`;
|
|
114
|
+
|
|
115
|
+
exports[`lineBase render renders with labels 1`] = `
|
|
116
|
+
<g>
|
|
117
|
+
<GridDraggable
|
|
118
|
+
from={
|
|
119
|
+
Object {
|
|
120
|
+
"label": "A",
|
|
121
|
+
"x": 0,
|
|
122
|
+
"y": 0,
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
graphProps={
|
|
126
|
+
Object {
|
|
127
|
+
"domain": Object {
|
|
128
|
+
"max": 1,
|
|
129
|
+
"min": 0,
|
|
130
|
+
"step": 1,
|
|
131
|
+
},
|
|
132
|
+
"range": Object {
|
|
133
|
+
"max": 1,
|
|
134
|
+
"min": 0,
|
|
135
|
+
"step": 1,
|
|
136
|
+
},
|
|
137
|
+
"scale": Object {
|
|
138
|
+
"x": [MockFunction],
|
|
139
|
+
"y": [MockFunction],
|
|
140
|
+
},
|
|
141
|
+
"size": Object {
|
|
142
|
+
"height": 400,
|
|
143
|
+
"width": 400,
|
|
144
|
+
},
|
|
145
|
+
"snap": Object {
|
|
146
|
+
"x": [MockFunction],
|
|
147
|
+
"y": [MockFunction],
|
|
148
|
+
},
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
onClick={[Function]}
|
|
152
|
+
onDrag={[Function]}
|
|
153
|
+
to={
|
|
154
|
+
Object {
|
|
155
|
+
"label": "B",
|
|
156
|
+
"x": 1,
|
|
157
|
+
"y": 1,
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
/>
|
|
161
|
+
<WithStyles(GridDraggable)
|
|
162
|
+
graphProps={
|
|
163
|
+
Object {
|
|
164
|
+
"domain": Object {
|
|
165
|
+
"max": 1,
|
|
166
|
+
"min": 0,
|
|
167
|
+
"step": 1,
|
|
168
|
+
},
|
|
169
|
+
"range": Object {
|
|
170
|
+
"max": 1,
|
|
171
|
+
"min": 0,
|
|
172
|
+
"step": 1,
|
|
173
|
+
},
|
|
174
|
+
"scale": Object {
|
|
175
|
+
"x": [MockFunction],
|
|
176
|
+
"y": [MockFunction],
|
|
177
|
+
},
|
|
178
|
+
"size": Object {
|
|
179
|
+
"height": 400,
|
|
180
|
+
"width": 400,
|
|
181
|
+
},
|
|
182
|
+
"snap": Object {
|
|
183
|
+
"x": [MockFunction],
|
|
184
|
+
"y": [MockFunction],
|
|
185
|
+
},
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
labelNode={<foreignobject />}
|
|
189
|
+
onClick={[Function]}
|
|
190
|
+
onDrag={[Function]}
|
|
191
|
+
x={0}
|
|
192
|
+
y={0}
|
|
193
|
+
/>
|
|
194
|
+
<Portal
|
|
195
|
+
containerInfo={<foreignobject />}
|
|
196
|
+
>
|
|
197
|
+
<WithStyles(MarkLabel)
|
|
198
|
+
disabled={true}
|
|
199
|
+
graphProps={
|
|
200
|
+
Object {
|
|
201
|
+
"domain": Object {
|
|
202
|
+
"max": 1,
|
|
203
|
+
"min": 0,
|
|
204
|
+
"step": 1,
|
|
205
|
+
},
|
|
206
|
+
"range": Object {
|
|
207
|
+
"max": 1,
|
|
208
|
+
"min": 0,
|
|
209
|
+
"step": 1,
|
|
210
|
+
},
|
|
211
|
+
"scale": Object {
|
|
212
|
+
"x": [MockFunction],
|
|
213
|
+
"y": [MockFunction],
|
|
214
|
+
},
|
|
215
|
+
"size": Object {
|
|
216
|
+
"height": 400,
|
|
217
|
+
"width": 400,
|
|
218
|
+
},
|
|
219
|
+
"snap": Object {
|
|
220
|
+
"x": [MockFunction],
|
|
221
|
+
"y": [MockFunction],
|
|
222
|
+
},
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
inputRef={[Function]}
|
|
226
|
+
mark={
|
|
227
|
+
Object {
|
|
228
|
+
"label": "A",
|
|
229
|
+
"x": 0,
|
|
230
|
+
"y": 0,
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
onChange={[Function]}
|
|
234
|
+
/>
|
|
235
|
+
</Portal>
|
|
236
|
+
<WithStyles(GridDraggable)
|
|
237
|
+
angle={45}
|
|
238
|
+
graphProps={
|
|
239
|
+
Object {
|
|
240
|
+
"domain": Object {
|
|
241
|
+
"max": 1,
|
|
242
|
+
"min": 0,
|
|
243
|
+
"step": 1,
|
|
244
|
+
},
|
|
245
|
+
"range": Object {
|
|
246
|
+
"max": 1,
|
|
247
|
+
"min": 0,
|
|
248
|
+
"step": 1,
|
|
249
|
+
},
|
|
250
|
+
"scale": Object {
|
|
251
|
+
"x": [MockFunction],
|
|
252
|
+
"y": [MockFunction],
|
|
253
|
+
},
|
|
254
|
+
"size": Object {
|
|
255
|
+
"height": 400,
|
|
256
|
+
"width": 400,
|
|
257
|
+
},
|
|
258
|
+
"snap": Object {
|
|
259
|
+
"x": [MockFunction],
|
|
260
|
+
"y": [MockFunction],
|
|
261
|
+
},
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
labelNode={<foreignobject />}
|
|
265
|
+
onClick={[Function]}
|
|
266
|
+
onDrag={[Function]}
|
|
267
|
+
x={1}
|
|
268
|
+
y={1}
|
|
269
|
+
/>
|
|
270
|
+
<Portal
|
|
271
|
+
containerInfo={<foreignobject />}
|
|
272
|
+
>
|
|
273
|
+
<WithStyles(MarkLabel)
|
|
274
|
+
disabled={true}
|
|
275
|
+
graphProps={
|
|
276
|
+
Object {
|
|
277
|
+
"domain": Object {
|
|
278
|
+
"max": 1,
|
|
279
|
+
"min": 0,
|
|
280
|
+
"step": 1,
|
|
281
|
+
},
|
|
282
|
+
"range": Object {
|
|
283
|
+
"max": 1,
|
|
284
|
+
"min": 0,
|
|
285
|
+
"step": 1,
|
|
286
|
+
},
|
|
287
|
+
"scale": Object {
|
|
288
|
+
"x": [MockFunction],
|
|
289
|
+
"y": [MockFunction],
|
|
290
|
+
},
|
|
291
|
+
"size": Object {
|
|
292
|
+
"height": 400,
|
|
293
|
+
"width": 400,
|
|
294
|
+
},
|
|
295
|
+
"snap": Object {
|
|
296
|
+
"x": [MockFunction],
|
|
297
|
+
"y": [MockFunction],
|
|
298
|
+
},
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
inputRef={[Function]}
|
|
302
|
+
mark={
|
|
303
|
+
Object {
|
|
304
|
+
"label": "B",
|
|
305
|
+
"x": 1,
|
|
306
|
+
"y": 1,
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
onChange={[Function]}
|
|
310
|
+
/>
|
|
311
|
+
</Portal>
|
|
312
|
+
</g>
|
|
313
|
+
`;
|
|
314
|
+
|
|
315
|
+
exports[`lineToolComponent snapshot renders 1`] = `
|
|
316
|
+
<Component
|
|
317
|
+
changeMarkProps={[Function]}
|
|
318
|
+
from={
|
|
319
|
+
Object {
|
|
320
|
+
"x": 0,
|
|
321
|
+
"y": 0,
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
graphProps={
|
|
325
|
+
Object {
|
|
326
|
+
"domain": Object {
|
|
327
|
+
"max": 1,
|
|
328
|
+
"min": 0,
|
|
329
|
+
"step": 1,
|
|
330
|
+
},
|
|
331
|
+
"range": Object {
|
|
332
|
+
"max": 1,
|
|
333
|
+
"min": 0,
|
|
334
|
+
"step": 1,
|
|
335
|
+
},
|
|
336
|
+
"scale": Object {
|
|
337
|
+
"x": [MockFunction],
|
|
338
|
+
"y": [MockFunction],
|
|
339
|
+
},
|
|
340
|
+
"size": Object {
|
|
341
|
+
"height": 400,
|
|
342
|
+
"width": 400,
|
|
343
|
+
},
|
|
344
|
+
"snap": Object {
|
|
345
|
+
"x": [MockFunction],
|
|
346
|
+
"y": [MockFunction],
|
|
347
|
+
},
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
onChange={[Function]}
|
|
351
|
+
onDragStart={[Function]}
|
|
352
|
+
onDragStop={[Function]}
|
|
353
|
+
to={
|
|
354
|
+
Object {
|
|
355
|
+
"x": 1,
|
|
356
|
+
"y": 1,
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
/>
|
|
360
|
+
`;
|