@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,43 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`BasePoint snapshot renders 1`] = `
|
|
4
|
+
<RawBp
|
|
5
|
+
className="className"
|
|
6
|
+
classes={
|
|
7
|
+
Object {
|
|
8
|
+
"correct": "RawBp-correct-3",
|
|
9
|
+
"disabled": "RawBp-disabled-2",
|
|
10
|
+
"incorrect": "RawBp-incorrect-4",
|
|
11
|
+
"missing": "RawBp-missing-5",
|
|
12
|
+
"point": "RawBp-point-1",
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
graphProps={
|
|
16
|
+
Object {
|
|
17
|
+
"domain": Object {
|
|
18
|
+
"max": 1,
|
|
19
|
+
"min": 0,
|
|
20
|
+
"step": 1,
|
|
21
|
+
},
|
|
22
|
+
"range": Object {
|
|
23
|
+
"max": 1,
|
|
24
|
+
"min": 0,
|
|
25
|
+
"step": 1,
|
|
26
|
+
},
|
|
27
|
+
"scale": Object {
|
|
28
|
+
"x": [MockFunction],
|
|
29
|
+
"y": [MockFunction],
|
|
30
|
+
},
|
|
31
|
+
"size": Object {
|
|
32
|
+
"height": 400,
|
|
33
|
+
"width": 400,
|
|
34
|
+
},
|
|
35
|
+
"snap": Object {
|
|
36
|
+
"x": [MockFunction],
|
|
37
|
+
"y": [MockFunction],
|
|
38
|
+
},
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
onChange={[MockFunction]}
|
|
42
|
+
/>
|
|
43
|
+
`;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { shallow } from 'enzyme/build';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { ArrowPoint } from '../index';
|
|
4
|
+
import { graphProps } from '../../../../__tests__/utils';
|
|
5
|
+
import { bounds } from '../../../../utils';
|
|
6
|
+
import { gridDraggable, utils } from '@pie-lib/plot';
|
|
7
|
+
|
|
8
|
+
const { xy } = utils;
|
|
9
|
+
jest.mock('../../../../utils', () => {
|
|
10
|
+
const { point } = jest.requireActual('../../../../utils');
|
|
11
|
+
return {
|
|
12
|
+
bounds: jest.fn(),
|
|
13
|
+
point,
|
|
14
|
+
};
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
jest.mock('@pie-lib/plot/index', () => {
|
|
18
|
+
const { types, utils } = jest.requireActual('@pie-lib/plot/index');
|
|
19
|
+
return {
|
|
20
|
+
gridDraggable: jest.fn((opts) => (Comp) => Comp),
|
|
21
|
+
types,
|
|
22
|
+
utils,
|
|
23
|
+
};
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
describe('ArrowPoint', () => {
|
|
27
|
+
let w;
|
|
28
|
+
let onChange = jest.fn();
|
|
29
|
+
const wrapper = (extras) => {
|
|
30
|
+
const defaults = {
|
|
31
|
+
classes: {},
|
|
32
|
+
className: 'className',
|
|
33
|
+
onChange,
|
|
34
|
+
graphProps: graphProps(),
|
|
35
|
+
from: xy(0, 0),
|
|
36
|
+
to: xy(1, 1),
|
|
37
|
+
};
|
|
38
|
+
const props = { ...defaults, ...extras };
|
|
39
|
+
return shallow(<ArrowPoint {...props} />);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
describe('snapshot', () => {
|
|
43
|
+
it('renders', () => {
|
|
44
|
+
w = wrapper();
|
|
45
|
+
expect(w).toMatchSnapshot();
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
describe('gridDraggable options', () => {
|
|
49
|
+
let opts;
|
|
50
|
+
let domain;
|
|
51
|
+
let range;
|
|
52
|
+
beforeEach(() => {
|
|
53
|
+
domain = {
|
|
54
|
+
min: 0,
|
|
55
|
+
max: 1,
|
|
56
|
+
step: 1,
|
|
57
|
+
};
|
|
58
|
+
range = {
|
|
59
|
+
min: 0,
|
|
60
|
+
max: 1,
|
|
61
|
+
step: 1,
|
|
62
|
+
};
|
|
63
|
+
const w = wrapper();
|
|
64
|
+
opts = gridDraggable.mock.calls[0][0];
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
describe('bounds', () => {
|
|
68
|
+
it('calls utils.bounds with area', () => {
|
|
69
|
+
const result = opts.bounds({ x: 0, y: 0 }, { domain, range });
|
|
70
|
+
expect(bounds).toHaveBeenCalledWith({ left: 0, top: 0, bottom: 0, right: 0 }, domain, range);
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
describe('anchorPoint', () => {
|
|
74
|
+
it('returns x/y', () => {
|
|
75
|
+
const result = opts.anchorPoint({ x: 0, y: 0 });
|
|
76
|
+
expect(result).toEqual({ x: 0, y: 0 });
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
describe('fromDelta', () => {
|
|
81
|
+
it('returns a new point from the x/y + delta', () => {
|
|
82
|
+
const result = opts.fromDelta({ x: -1, y: 0 }, { x: 1, y: 3 });
|
|
83
|
+
expect(result).toEqual({ x: 0, y: 3 });
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
});
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { shallow } from 'enzyme/build';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { BasePoint } from '../index';
|
|
4
|
+
import { gridDraggable } from '@pie-lib/plot';
|
|
5
|
+
import { graphProps } from '../../../../__tests__/utils';
|
|
6
|
+
import { bounds } from '../../../../utils';
|
|
7
|
+
|
|
8
|
+
jest.mock('../../../../utils', () => {
|
|
9
|
+
const { point } = jest.requireActual('../../../../utils');
|
|
10
|
+
return {
|
|
11
|
+
bounds: jest.fn(),
|
|
12
|
+
point,
|
|
13
|
+
};
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
jest.mock('@pie-lib/plot/index', () => {
|
|
17
|
+
const { types, utils } = jest.requireActual('@pie-lib/plot/index');
|
|
18
|
+
return {
|
|
19
|
+
gridDraggable: jest.fn((opts) => (Comp) => Comp),
|
|
20
|
+
types,
|
|
21
|
+
utils,
|
|
22
|
+
};
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
describe('BasePoint', () => {
|
|
26
|
+
let w;
|
|
27
|
+
let onChange = jest.fn();
|
|
28
|
+
const wrapper = (extras) => {
|
|
29
|
+
const defaults = {
|
|
30
|
+
classes: {},
|
|
31
|
+
className: 'className',
|
|
32
|
+
onChange,
|
|
33
|
+
graphProps: graphProps(),
|
|
34
|
+
};
|
|
35
|
+
const props = { ...defaults, ...extras };
|
|
36
|
+
return shallow(<BasePoint {...props} />);
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
describe('snapshot', () => {
|
|
40
|
+
it('renders', () => {
|
|
41
|
+
w = wrapper();
|
|
42
|
+
expect(w).toMatchSnapshot();
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
describe('gridDraggable options', () => {
|
|
46
|
+
let opts;
|
|
47
|
+
let domain;
|
|
48
|
+
let range;
|
|
49
|
+
beforeEach(() => {
|
|
50
|
+
domain = {
|
|
51
|
+
min: 0,
|
|
52
|
+
max: 1,
|
|
53
|
+
step: 1,
|
|
54
|
+
};
|
|
55
|
+
range = {
|
|
56
|
+
min: 0,
|
|
57
|
+
max: 1,
|
|
58
|
+
step: 1,
|
|
59
|
+
};
|
|
60
|
+
const w = wrapper();
|
|
61
|
+
opts = gridDraggable.mock.calls[0][0];
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
describe('bounds', () => {
|
|
65
|
+
it('calls utils.bounds with area', () => {
|
|
66
|
+
const result = opts.bounds({ x: 0, y: 0 }, { domain, range });
|
|
67
|
+
expect(bounds).toHaveBeenCalledWith({ left: 0, top: 0, bottom: 0, right: 0 }, domain, range);
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
describe('anchorPoint', () => {
|
|
71
|
+
it('returns x/y', () => {
|
|
72
|
+
const result = opts.anchorPoint({ x: 0, y: 0 });
|
|
73
|
+
expect(result).toEqual({ x: 0, y: 0 });
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
describe('fromDelta', () => {
|
|
78
|
+
it('returns a new point from the x/y + delta', () => {
|
|
79
|
+
const result = opts.fromDelta({ x: -1, y: 0 }, { x: 1, y: 3 });
|
|
80
|
+
expect(result).toEqual({ x: 0, y: 3 });
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
});
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import classNames from 'classnames';
|
|
4
|
+
import { types } from '@pie-lib/plot';
|
|
5
|
+
import isEqual from 'lodash/isEqual';
|
|
6
|
+
import { getAngleDeg, arrowDimensions } from '../../../utils';
|
|
7
|
+
|
|
8
|
+
export class RawArrow extends React.Component {
|
|
9
|
+
static propTypes = {
|
|
10
|
+
classes: PropTypes.object,
|
|
11
|
+
className: PropTypes.string,
|
|
12
|
+
correctness: PropTypes.string,
|
|
13
|
+
disabled: PropTypes.bool,
|
|
14
|
+
x: PropTypes.number,
|
|
15
|
+
y: PropTypes.number,
|
|
16
|
+
from: PropTypes.shape({
|
|
17
|
+
x: PropTypes.number,
|
|
18
|
+
y: PropTypes.number,
|
|
19
|
+
}).isRequired,
|
|
20
|
+
to: PropTypes.shape({
|
|
21
|
+
x: PropTypes.number,
|
|
22
|
+
y: PropTypes.number,
|
|
23
|
+
}),
|
|
24
|
+
graphProps: types.GraphPropsType.isRequired,
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
static defaultProps = {
|
|
28
|
+
from: {},
|
|
29
|
+
to: {},
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
render() {
|
|
33
|
+
const { classes, className, x, y, disabled, correctness, graphProps, from, to, ...rest } = this.props;
|
|
34
|
+
// x & y are the initial coordinates for the arrow
|
|
35
|
+
// from & to are used only to calculate the angle that the arrow should be rotated with
|
|
36
|
+
|
|
37
|
+
const { scale } = graphProps;
|
|
38
|
+
const angle = getAngleDeg(from.x, from.y, to.x, to.y);
|
|
39
|
+
|
|
40
|
+
let points = '';
|
|
41
|
+
|
|
42
|
+
if (isEqual(from, to)) {
|
|
43
|
+
points = '0,0 0,0 0,0';
|
|
44
|
+
} else {
|
|
45
|
+
points = `0,0 ${arrowDimensions.vector},${arrowDimensions.vector * 2}
|
|
46
|
+
-${arrowDimensions.vector},${arrowDimensions.vector * 2}`;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
<g className={classNames(classes.point, disabled && classes.disabled, classes[correctness], className)} {...rest}>
|
|
51
|
+
<polygon
|
|
52
|
+
points={points}
|
|
53
|
+
transform={`
|
|
54
|
+
translate(${scale.x(x)}, ${scale.y(y)})
|
|
55
|
+
rotate(${angle} 0 0)`}
|
|
56
|
+
/>
|
|
57
|
+
</g>
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import classNames from 'classnames';
|
|
4
|
+
import { types } from '@pie-lib/plot';
|
|
5
|
+
import { ArrowHead } from '../arrow-head';
|
|
6
|
+
import { thinnerShapesNeeded } from '../../../utils';
|
|
7
|
+
|
|
8
|
+
export default class Arrow extends React.Component {
|
|
9
|
+
static propTypes = {
|
|
10
|
+
classes: PropTypes.object,
|
|
11
|
+
className: PropTypes.string,
|
|
12
|
+
correctness: PropTypes.string,
|
|
13
|
+
disabled: PropTypes.bool,
|
|
14
|
+
x: PropTypes.number.isRequired,
|
|
15
|
+
y: PropTypes.number.isRequired,
|
|
16
|
+
angle: PropTypes.number.isRequired,
|
|
17
|
+
graphProps: types.GraphPropsType.isRequired,
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
render() {
|
|
21
|
+
const { classes, angle, className, x, y, disabled, correctness, graphProps, ...rest } = this.props;
|
|
22
|
+
|
|
23
|
+
const size = thinnerShapesNeeded(graphProps) ? 12 : 14;
|
|
24
|
+
const { scale } = graphProps;
|
|
25
|
+
|
|
26
|
+
const scaledX = scale.x(x);
|
|
27
|
+
const scaledY = scale.y(y);
|
|
28
|
+
|
|
29
|
+
const transform = `rotate(${-angle}, ${scaledX},${scaledY})`;
|
|
30
|
+
const points = `${scaledX},${scaledY}
|
|
31
|
+
${scaledX - size},${scaledY - size / 2}
|
|
32
|
+
${scaledX - size}, ${scaledY + size / 2}`;
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<g className={classNames(classes.point, disabled && classes.disabled, classes[correctness], className)} {...rest}>
|
|
36
|
+
<ArrowHead size={size} transform={transform} points={points} />
|
|
37
|
+
</g>
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import classNames from 'classnames';
|
|
4
|
+
import { types } from '@pie-lib/plot';
|
|
5
|
+
import CoordinatesLabel from '../../../coordinates-label';
|
|
6
|
+
import ReactDOM from 'react-dom';
|
|
7
|
+
import { thinnerShapesNeeded } from '../../../utils';
|
|
8
|
+
import { color } from '@pie-lib/render-ui';
|
|
9
|
+
|
|
10
|
+
export class RawBp extends React.Component {
|
|
11
|
+
static propTypes = {
|
|
12
|
+
classes: PropTypes.object,
|
|
13
|
+
className: PropTypes.string,
|
|
14
|
+
coordinatesOnHover: PropTypes.bool,
|
|
15
|
+
correctness: PropTypes.string,
|
|
16
|
+
disabled: PropTypes.bool,
|
|
17
|
+
labelNode: PropTypes.object,
|
|
18
|
+
x: PropTypes.number,
|
|
19
|
+
y: PropTypes.number,
|
|
20
|
+
graphProps: types.GraphPropsType.isRequired,
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
constructor(props) {
|
|
24
|
+
super(props);
|
|
25
|
+
this.state = { showCoordinates: false };
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
render() {
|
|
29
|
+
const {
|
|
30
|
+
classes,
|
|
31
|
+
className,
|
|
32
|
+
coordinatesOnHover,
|
|
33
|
+
x,
|
|
34
|
+
y,
|
|
35
|
+
disabled,
|
|
36
|
+
correctness,
|
|
37
|
+
graphProps,
|
|
38
|
+
labelNode,
|
|
39
|
+
// we need to remove style from props
|
|
40
|
+
// eslint-disable-next-line no-unused-vars,react/prop-types
|
|
41
|
+
style,
|
|
42
|
+
onClick,
|
|
43
|
+
// Refactored RawBp component by isolating onTouchStart and onTouchEnd handlers to the outer circle, resolving erratic touch event behavior.
|
|
44
|
+
// Remaining props are now applied only to the inner circle for improved event handling consistency.
|
|
45
|
+
onTouchStart,
|
|
46
|
+
onTouchEnd,
|
|
47
|
+
...rest
|
|
48
|
+
} = this.props;
|
|
49
|
+
const { showCoordinates } = this.state;
|
|
50
|
+
const { scale } = graphProps;
|
|
51
|
+
const r = thinnerShapesNeeded(graphProps) ? 5 : 7;
|
|
52
|
+
|
|
53
|
+
return (
|
|
54
|
+
<>
|
|
55
|
+
<circle
|
|
56
|
+
style={{ fill: 'transparent', cursor: 'pointer', pointerEvents: 'all' }}
|
|
57
|
+
r={r * 3}
|
|
58
|
+
cx={scale.x(x)}
|
|
59
|
+
cy={scale.y(y)}
|
|
60
|
+
onMouseEnter={() => this.setState({ showCoordinates: true })}
|
|
61
|
+
onMouseLeave={() => this.setState({ showCoordinates: false })}
|
|
62
|
+
onTouchStart={onTouchStart}
|
|
63
|
+
onTouchEnd={onTouchEnd}
|
|
64
|
+
onClick={onClick}
|
|
65
|
+
/>
|
|
66
|
+
<g
|
|
67
|
+
className={classNames(classes.point, disabled && classes.disabled, classes[correctness], className)}
|
|
68
|
+
onMouseEnter={() => this.setState({ showCoordinates: true })}
|
|
69
|
+
onMouseLeave={() => this.setState({ showCoordinates: false })}
|
|
70
|
+
>
|
|
71
|
+
<circle
|
|
72
|
+
{...rest}
|
|
73
|
+
style={{ fill: color.defaults.BLACK, cursor: 'pointer' }}
|
|
74
|
+
r={r}
|
|
75
|
+
cx={scale.x(x)}
|
|
76
|
+
cy={scale.y(y)}
|
|
77
|
+
/>
|
|
78
|
+
{labelNode &&
|
|
79
|
+
coordinatesOnHover &&
|
|
80
|
+
showCoordinates &&
|
|
81
|
+
ReactDOM.createPortal(<CoordinatesLabel graphProps={graphProps} x={x} y={y} />, labelNode)}
|
|
82
|
+
</g>
|
|
83
|
+
</>
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { withStyles } from '@material-ui/core/styles/index';
|
|
2
|
+
import { gridDraggable } from '@pie-lib/plot';
|
|
3
|
+
import * as utils from '../../../utils';
|
|
4
|
+
import { disabled, correct, incorrect, missing } from '../styles';
|
|
5
|
+
import { RawBp } from './base-point';
|
|
6
|
+
import { RawArrow } from './arrow-point';
|
|
7
|
+
import { color } from '@pie-lib/render-ui';
|
|
8
|
+
import BaseArrow from './arrow';
|
|
9
|
+
|
|
10
|
+
const opts = {
|
|
11
|
+
bounds: (props, { domain, range }) => {
|
|
12
|
+
const { x, y } = props;
|
|
13
|
+
const area = { left: x, top: y, bottom: y, right: x };
|
|
14
|
+
|
|
15
|
+
return utils.bounds(area, domain, range);
|
|
16
|
+
},
|
|
17
|
+
anchorPoint: (props) => {
|
|
18
|
+
const { x, y } = props;
|
|
19
|
+
|
|
20
|
+
return { x, y };
|
|
21
|
+
},
|
|
22
|
+
fromDelta: (props, delta) => {
|
|
23
|
+
return utils.point(props).add(utils.point(delta));
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const styles = () => {
|
|
28
|
+
return {
|
|
29
|
+
point: {
|
|
30
|
+
'& circle, & polygon': {
|
|
31
|
+
cursor: 'pointer',
|
|
32
|
+
fill: color.defaults.SECONDARY,
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
disabled: {
|
|
36
|
+
'& circle, & polygon': {
|
|
37
|
+
...disabled(),
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
correct: {
|
|
41
|
+
'& circle, & polygon': {
|
|
42
|
+
...correct(),
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
incorrect: {
|
|
46
|
+
'& circle, & polygon': {
|
|
47
|
+
...incorrect(),
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
missing: {
|
|
51
|
+
'& circle, & polygon': {
|
|
52
|
+
...missing(),
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export const BasePoint = withStyles(styles)(gridDraggable(opts)(RawBp));
|
|
59
|
+
export const ArrowPoint = withStyles(styles)(gridDraggable(opts)(RawArrow));
|
|
60
|
+
export const Arrow = withStyles(styles)(gridDraggable(opts)(BaseArrow));
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { color } from '@pie-lib/render-ui';
|
|
2
|
+
|
|
3
|
+
export const disabled = (key = 'fill') => ({
|
|
4
|
+
[key]: color.disabled(),
|
|
5
|
+
pointerEvents: 'none',
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
export const correct = (key = 'fill') => ({
|
|
9
|
+
[key]: color.correct(),
|
|
10
|
+
pointerEvents: 'none',
|
|
11
|
+
});
|
|
12
|
+
export const incorrect = (key = 'fill') => ({
|
|
13
|
+
[key]: color.incorrect(),
|
|
14
|
+
pointerEvents: 'none',
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
export const missing = (key = 'fill') => ({
|
|
18
|
+
[key]: color.missing(),
|
|
19
|
+
pointerEvents: 'none',
|
|
20
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import classNames from 'classnames';
|
|
4
|
+
import Button from '@material-ui/core/Button';
|
|
5
|
+
import { withStyles } from '@material-ui/core';
|
|
6
|
+
import { color } from '@pie-lib/render-ui';
|
|
7
|
+
import Translator from '@pie-lib/translator';
|
|
8
|
+
|
|
9
|
+
const { translator } = Translator;
|
|
10
|
+
|
|
11
|
+
export class UndoRedo extends React.Component {
|
|
12
|
+
static propTypes = {
|
|
13
|
+
classes: PropTypes.object,
|
|
14
|
+
className: PropTypes.string,
|
|
15
|
+
onReset: PropTypes.func.isRequired,
|
|
16
|
+
language: PropTypes.string,
|
|
17
|
+
};
|
|
18
|
+
static defaultProps = {};
|
|
19
|
+
|
|
20
|
+
render() {
|
|
21
|
+
const { classes, className, onReset = false, language } = this.props;
|
|
22
|
+
return (
|
|
23
|
+
<div className={classNames(className)}>
|
|
24
|
+
<Button classes={{ root: classes.button }} onClick={() => onReset()}>
|
|
25
|
+
{translator.t('graphing.reset', { lng: language })}
|
|
26
|
+
</Button>
|
|
27
|
+
</div>
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const styles = (theme) => ({
|
|
33
|
+
button: {
|
|
34
|
+
color: color.text(),
|
|
35
|
+
fontWeight: 'bold',
|
|
36
|
+
marginBottom: theme.spacing.unit / 2,
|
|
37
|
+
'&:not(:last-of-type)': {
|
|
38
|
+
marginRight: theme.spacing.unit / 2,
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
undoRedoDiv: {
|
|
42
|
+
display: 'flex',
|
|
43
|
+
flexDirection: 'row',
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
export default withStyles(styles)(UndoRedo);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { useState, useEffect } from 'react';
|
|
2
|
+
|
|
3
|
+
export const useDebounce = (value, delay) => {
|
|
4
|
+
const [debouncedValue, setDebouncedValue] = useState(value);
|
|
5
|
+
|
|
6
|
+
useEffect(() => {
|
|
7
|
+
const handler = setTimeout(() => {
|
|
8
|
+
setDebouncedValue(value);
|
|
9
|
+
}, delay);
|
|
10
|
+
return () => clearTimeout(handler);
|
|
11
|
+
}, [value]);
|
|
12
|
+
return debouncedValue;
|
|
13
|
+
};
|