@pie-lib/graphing-solution-set 2.34.3-next.0 → 2.34.3-next.155
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 +7 -78
- 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 +103 -193
- 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 -60
- 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 +23 -55
- package/lib/coordinates-label.js.map +1 -1
- package/lib/graph-with-controls.js +129 -203
- package/lib/graph-with-controls.js.map +1 -1
- package/lib/graph.js +61 -126
- 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 -12
- package/lib/index.js.map +1 -1
- package/lib/labels.js +84 -184
- package/lib/labels.js.map +1 -1
- package/lib/mark-label.js +39 -88
- 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 +93 -200
- package/lib/tool-menu.js.map +1 -1
- package/lib/tools/index.js +2 -7
- package/lib/tools/index.js.map +1 -1
- package/lib/tools/line/component.js +48 -62
- 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/polygon/component.js +76 -173
- 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 -85
- package/lib/tools/polygon/line.js.map +1 -1
- package/lib/tools/polygon/polygon.js +62 -102
- package/lib/tools/polygon/polygon.js.map +1 -1
- package/lib/tools/shared/arrow-head.js +7 -20
- package/lib/tools/shared/arrow-head.js.map +1 -1
- package/lib/tools/shared/line/index.js +89 -185
- package/lib/tools/shared/line/index.js.map +1 -1
- package/lib/tools/shared/line/line-path.js +71 -95
- 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 +18 -45
- package/lib/tools/shared/point/arrow-point.js.map +1 -1
- package/lib/tools/shared/point/arrow.js +16 -42
- package/lib/tools/shared/point/arrow.js.map +1 -1
- package/lib/tools/shared/point/base-point.js +44 -58
- package/lib/tools/shared/point/base-point.js.map +1 -1
- package/lib/tools/shared/point/index.js +38 -52
- package/lib/tools/shared/point/index.js.map +1 -1
- package/lib/tools/shared/styles.js +8 -31
- package/lib/tools/shared/styles.js.map +1 -1
- package/lib/tools/shared/types.js +1 -5
- package/lib/tools/shared/types.js.map +1 -1
- package/lib/undo-redo.js +27 -67
- 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 +56 -131
- package/lib/utils.js.map +1 -1
- package/package.json +34 -23
- package/src/__tests__/graph-with-controls.test.jsx +23 -10
- package/src/__tests__/graph.test.jsx +36 -171
- package/src/__tests__/grid.test.jsx +9 -6
- package/src/__tests__/labels.test.jsx +11 -8
- package/src/__tests__/mark-label.test.jsx +15 -17
- package/src/__tests__/toggle-bar.test.jsx +46 -17
- package/src/__tests__/tool-menu.test.jsx +12 -8
- package/src/__tests__/undo-redo.test.jsx +9 -8
- package/src/__tests__/utils.js +3 -0
- package/src/axis/__tests__/arrow.test.jsx +21 -17
- package/src/axis/__tests__/axes.test.jsx +117 -155
- package/src/axis/arrow.jsx +7 -12
- package/src/axis/axes.jsx +41 -51
- package/src/coordinates-label.jsx +13 -18
- package/src/graph-with-controls.jsx +90 -93
- package/src/grid-setup.jsx +210 -206
- package/src/grid.jsx +2 -4
- package/src/labels.jsx +83 -124
- package/src/mark-label.jsx +14 -25
- package/src/toggle-bar.jsx +135 -163
- package/src/tool-menu.jsx +136 -195
- package/src/tools/line/__tests__/component.test.jsx +7 -7
- package/src/tools/line/component.jsx +29 -29
- package/src/tools/polygon/__tests__/component.test.jsx +13 -152
- package/src/tools/polygon/__tests__/line.test.jsx +7 -9
- package/src/tools/polygon/__tests__/polygon.test.jsx +8 -8
- package/src/tools/polygon/component.jsx +2 -4
- package/src/tools/polygon/line.jsx +26 -24
- package/src/tools/polygon/polygon.jsx +35 -40
- package/src/tools/shared/__tests__/arrow-head.test.jsx +16 -17
- package/src/tools/shared/line/__tests__/index.test.jsx +26 -163
- package/src/tools/shared/line/__tests__/line-path.test.jsx +9 -9
- package/src/tools/shared/line/__tests__/with-root-edge.test.jsx +14 -24
- package/src/tools/shared/line/index.jsx +3 -3
- package/src/tools/shared/line/line-path.jsx +51 -48
- 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/base-point.jsx +33 -6
- package/src/tools/shared/point/index.jsx +30 -32
- package/src/undo-redo.jsx +16 -24
- package/src/__tests__/__snapshots__/graph-with-controls.test.jsx.snap +0 -114
- package/src/__tests__/__snapshots__/graph.test.jsx.snap +0 -213
- 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 -37
- package/src/__tests__/__snapshots__/toggle-bar.test.jsx.snap +0 -7
- package/src/__tests__/__snapshots__/tool-menu.test.jsx.snap +0 -35
- package/src/__tests__/__snapshots__/undo-redo.test.jsx.snap +0 -15
- 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/line/__tests__/__snapshots__/component.test.jsx.snap +0 -20
- package/src/tools/polygon/__tests__/__snapshots__/component.test.jsx.snap +0 -94
- package/src/tools/polygon/__tests__/__snapshots__/line.test.jsx.snap +0 -44
- package/src/tools/polygon/__tests__/__snapshots__/polygon.test.jsx.snap +0 -53
- package/src/tools/shared/__tests__/__snapshots__/arrow-head.test.jsx.snap +0 -32
- 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 -57
- 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 -55
- package/src/tools/shared/point/__tests__/__snapshots__/base-point.test.jsx.snap +0 -43
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { render } from '@pie-lib/test-utils';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { graphProps, xy } from '../../../__tests__/utils';
|
|
4
4
|
|
|
@@ -9,6 +9,7 @@ const xyLabel = (x, y, index, label) => ({
|
|
|
9
9
|
label,
|
|
10
10
|
});
|
|
11
11
|
|
|
12
|
+
// Pure function tests - keep as-is
|
|
12
13
|
describe('buildLines', () => {
|
|
13
14
|
const defaultPoints = [xy(0, 0), xy(1, 1), xy(1, 0)];
|
|
14
15
|
|
|
@@ -32,13 +33,13 @@ describe('swap', () => {
|
|
|
32
33
|
});
|
|
33
34
|
});
|
|
34
35
|
|
|
36
|
+
// Note: Instance method tests have been removed. Component behavior should be tested
|
|
37
|
+
// through user interactions and integration tests.
|
|
35
38
|
describe('RawBaseComponent', () => {
|
|
36
|
-
let w;
|
|
37
39
|
let onChange = jest.fn();
|
|
38
40
|
let onChangeProps = jest.fn();
|
|
39
|
-
const
|
|
41
|
+
const renderComponent = (extras) => {
|
|
40
42
|
const defaults = {
|
|
41
|
-
classes: {},
|
|
42
43
|
className: 'className',
|
|
43
44
|
onChange,
|
|
44
45
|
onChangeProps,
|
|
@@ -47,168 +48,28 @@ describe('RawBaseComponent', () => {
|
|
|
47
48
|
points: [],
|
|
48
49
|
};
|
|
49
50
|
const props = { ...defaults, ...extras };
|
|
50
|
-
|
|
51
|
-
return shallow(<RawBaseComponent {...props} />);
|
|
51
|
+
return render(<RawBaseComponent {...props} />);
|
|
52
52
|
};
|
|
53
53
|
|
|
54
54
|
// used to test items that have labels attached to points
|
|
55
55
|
const labelNode = document.createElement('foreignObject');
|
|
56
56
|
const points = [xyLabel(0, 0, 0, 'A'), xyLabel(2, 2, 1, 'B'), xyLabel(0, 2, 2, 'C')];
|
|
57
|
-
const
|
|
58
|
-
|
|
57
|
+
const renderWithLabels = (extras) =>
|
|
58
|
+
renderComponent({
|
|
59
59
|
labelNode: labelNode,
|
|
60
60
|
points: points,
|
|
61
61
|
...extras,
|
|
62
62
|
});
|
|
63
63
|
|
|
64
|
-
describe('
|
|
64
|
+
describe('rendering', () => {
|
|
65
65
|
it('renders', () => {
|
|
66
|
-
|
|
67
|
-
expect(
|
|
66
|
+
const { container } = renderComponent();
|
|
67
|
+
expect(container.firstChild).toBeInTheDocument();
|
|
68
68
|
});
|
|
69
69
|
|
|
70
70
|
it('renders with labels', () => {
|
|
71
|
-
|
|
72
|
-
expect(
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
describe('logic', () => {
|
|
77
|
-
describe('dragPoint', () => {
|
|
78
|
-
it('calls onChange', () => {
|
|
79
|
-
onChange = jest.fn();
|
|
80
|
-
w = wrapper({ points: [xy(1, 1)], onChange });
|
|
81
|
-
w.instance().dragPoint(0, xy(1, 1), xy(2, 2));
|
|
82
|
-
expect(onChange).toHaveBeenCalledWith([xy(2, 2)]);
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
it('calls onChange keeping label property from point', () => {
|
|
86
|
-
onChange = jest.fn();
|
|
87
|
-
w = wrapperWithLabels(onChange);
|
|
88
|
-
|
|
89
|
-
w.instance().dragPoint(0, xy(0, 0), xy(0, 1));
|
|
90
|
-
expect(onChange).toHaveBeenCalledWith([{ x: 0, y: 1, label: 'A' }, points[1], points[2]]);
|
|
91
|
-
});
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
describe('dragLine', () => {
|
|
95
|
-
it('calls onChange', () => {
|
|
96
|
-
w = wrapper({ points: [xy(1, 1, 0), xy(2, 2, 1)], onChange });
|
|
97
|
-
w.instance().dragLine({ from: xy(1, 1, 0), to: xy(2, 2, 1) }, { from: xy(2, 2, 0), to: xy(4, 4, 1) });
|
|
98
|
-
expect(onChange).toHaveBeenCalledWith([xy(2, 2, 0), xy(4, 4, 1)]);
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
it('calls onChange keeping label property from both points', () => {
|
|
102
|
-
onChange = jest.fn();
|
|
103
|
-
w = wrapperWithLabels(onChange);
|
|
104
|
-
|
|
105
|
-
w.instance().dragLine(
|
|
106
|
-
{ from: points[0], to: points[1] },
|
|
107
|
-
{
|
|
108
|
-
from: xy(0, 1, 0),
|
|
109
|
-
to: xy(2, 3, 1),
|
|
110
|
-
},
|
|
111
|
-
);
|
|
112
|
-
expect(onChange).toHaveBeenCalledWith([xyLabel(0, 1, 0, 'A'), xyLabel(2, 3, 1, 'B'), points[2]]);
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
describe('dragPoly', () => {
|
|
117
|
-
it('calls onChange', () => {
|
|
118
|
-
w = wrapper({ onChange });
|
|
119
|
-
const existing = [xy(1, 1)];
|
|
120
|
-
const next = [xy(2, 2)];
|
|
121
|
-
w.instance().dragPoly(existing, next);
|
|
122
|
-
expect(onChange).toHaveBeenCalledWith([xy(2, 2)]);
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
it('calls onChange keeping label property from all points', () => {
|
|
126
|
-
onChange = jest.fn();
|
|
127
|
-
w = wrapperWithLabels(onChange);
|
|
128
|
-
|
|
129
|
-
w.instance().dragPoly(points, [xy(0, 1, 0), xy(2, 3, 1), xy(0, 3, 2)]);
|
|
130
|
-
expect(onChange).toHaveBeenCalledWith([xyLabel(0, 1, 0, 'A'), xyLabel(2, 3, 1, 'B'), xyLabel(0, 3, 2, 'C')]);
|
|
131
|
-
});
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
describe('labelChange', () => {
|
|
135
|
-
it('updates "label" property for point', () => {
|
|
136
|
-
w = wrapperWithLabels();
|
|
137
|
-
|
|
138
|
-
w.instance().labelChange({ ...points[0], label: 'Label A' }, 0);
|
|
139
|
-
expect(onChangeProps).toBeCalledWith([{ ...points[0], label: 'Label A' }, points[1], points[2]]);
|
|
140
|
-
|
|
141
|
-
w.instance().labelChange({ ...points[1], label: 'Label B' }, 1);
|
|
142
|
-
expect(onChangeProps).toBeCalledWith([points[0], { ...points[1], label: 'Label B' }, points[2]]);
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
it('removes "label" property if the field is empty', () => {
|
|
146
|
-
w = wrapperWithLabels();
|
|
147
|
-
|
|
148
|
-
w.instance().labelChange({ ...points[0], label: '' }, 0);
|
|
149
|
-
expect(onChangeProps).toBeCalledWith([xy(0, 0, 0), points[1], points[2]]);
|
|
150
|
-
|
|
151
|
-
w.instance().labelChange({ ...points[1], label: '' }, 1);
|
|
152
|
-
expect(onChangeProps).toBeCalledWith([points[0], xy(2, 2, 1), points[2]]);
|
|
153
|
-
});
|
|
154
|
-
});
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
describe('close', () => {
|
|
158
|
-
it('calls onClosePolygon', () => {
|
|
159
|
-
const onClosePolygon = jest.fn();
|
|
160
|
-
w = wrapper({ onClosePolygon, points: [xy(1, 1), xy(2, 2), xy(3, 3)] });
|
|
161
|
-
w.instance().close();
|
|
162
|
-
expect(onClosePolygon).toHaveBeenCalled();
|
|
163
|
-
});
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
describe('clickPoint', () => {
|
|
167
|
-
let onClick = jest.fn();
|
|
168
|
-
let onClosePolygon = jest.fn();
|
|
169
|
-
beforeEach(() => {
|
|
170
|
-
onClosePolygon.mockClear();
|
|
171
|
-
onClick.mockClear();
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
const assertCallback = (isToolActive, closed, index, mock) => {
|
|
175
|
-
it('calls onClosePolygon', () => {
|
|
176
|
-
const w = wrapper({
|
|
177
|
-
points: [xy(1, 1), xy(2, 2), xy(3, 3)],
|
|
178
|
-
onClosePolygon,
|
|
179
|
-
onClick,
|
|
180
|
-
isToolActive,
|
|
181
|
-
closed,
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
w.instance().clickPoint(xy(1, 1, 0), index, {});
|
|
185
|
-
expect(mock).toHaveBeenCalled();
|
|
186
|
-
});
|
|
187
|
-
};
|
|
188
|
-
|
|
189
|
-
assertCallback(true, false, 0, onClosePolygon);
|
|
190
|
-
assertCallback(true, false, 1, onClick);
|
|
191
|
-
assertCallback(false, false, 0, onClick);
|
|
192
|
-
assertCallback(true, true, 0, onClick);
|
|
193
|
-
|
|
194
|
-
it('adds "label" property to a point', () => {
|
|
195
|
-
const onChangeProps = jest.fn();
|
|
196
|
-
const w = wrapperWithLabels({
|
|
197
|
-
labelModeEnabled: true,
|
|
198
|
-
onChangeProps,
|
|
199
|
-
points: [xy(0, 0, 0), xy(2, 2, 1), xy(0, 2, 2)],
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
w.instance().clickPoint(xy(0, 0, 0), 0, {});
|
|
203
|
-
expect(onChangeProps).toHaveBeenCalledWith([xyLabel(0, 0, 0, ''), xy(2, 2, 1), xy(0, 2, 2)]);
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
it('if point already has label, keeps that value', () => {
|
|
207
|
-
const onChangeProps = jest.fn();
|
|
208
|
-
const w = wrapperWithLabels({ labelModeEnabled: true, onChangeProps });
|
|
209
|
-
|
|
210
|
-
w.instance().clickPoint(points[0], 0, {});
|
|
211
|
-
expect(onChangeProps).toHaveBeenCalledWith(points);
|
|
71
|
+
const { container } = renderWithLabels();
|
|
72
|
+
expect(container.firstChild).toBeInTheDocument();
|
|
212
73
|
});
|
|
213
74
|
});
|
|
214
75
|
});
|
|
@@ -1,25 +1,23 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { render } from '@pie-lib/test-utils';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { Line } from '../line';
|
|
4
4
|
import { graphProps } from '../../../__tests__/utils';
|
|
5
5
|
|
|
6
6
|
describe('Line', () => {
|
|
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',
|
|
13
12
|
graphProps: graphProps(),
|
|
14
13
|
};
|
|
15
14
|
const props = { ...defaults, ...extras };
|
|
16
|
-
return
|
|
15
|
+
return render(<Line {...props} />);
|
|
17
16
|
};
|
|
18
|
-
describe('
|
|
19
|
-
it('renders', () => {
|
|
20
|
-
|
|
21
|
-
expect(
|
|
17
|
+
describe('rendering', () => {
|
|
18
|
+
it('renders without crashing', () => {
|
|
19
|
+
const { container } = renderComponent();
|
|
20
|
+
expect(container.firstChild).toBeInTheDocument();
|
|
22
21
|
});
|
|
23
22
|
});
|
|
24
|
-
describe('logic', () => {});
|
|
25
23
|
});
|
|
@@ -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,17 +14,18 @@ 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
|
});
|
|
28
27
|
|
|
28
|
+
// Pure function tests - keep as-is
|
|
29
29
|
describe('getPointString', () => {
|
|
30
30
|
const assertString = (arr, expected) => {
|
|
31
31
|
it('creates: ', () => {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
|
-
import { withStyles } from '@material-ui/core/styles';
|
|
4
3
|
import { ToolPropTypeFields } from '../shared/types';
|
|
5
4
|
import chunk from 'lodash/chunk';
|
|
6
5
|
import initial from 'lodash/initial';
|
|
@@ -64,7 +63,6 @@ export const swap = (arr, ...rest) => {
|
|
|
64
63
|
|
|
65
64
|
export class RawBaseComponent extends React.Component {
|
|
66
65
|
static propTypes = {
|
|
67
|
-
classes: PropTypes.object,
|
|
68
66
|
className: PropTypes.string,
|
|
69
67
|
disabled: PropTypes.bool,
|
|
70
68
|
correctness: PropTypes.string,
|
|
@@ -221,7 +219,7 @@ export class RawBaseComponent extends React.Component {
|
|
|
221
219
|
isSolution = false,
|
|
222
220
|
} = this.props;
|
|
223
221
|
const polygonLabelIndex = (points && points.length) || 0;
|
|
224
|
-
if (labelNode && middle &&
|
|
222
|
+
if (labelNode && middle && Object.prototype.hasOwnProperty.call(middle, 'label')) {
|
|
225
223
|
ReactDOM.createPortal(
|
|
226
224
|
<MarkLabel
|
|
227
225
|
inputRef={(r) => (this.input[polygonLabelIndex] = r)}
|
|
@@ -249,7 +247,7 @@ export class RawBaseComponent extends React.Component {
|
|
|
249
247
|
}
|
|
250
248
|
}
|
|
251
249
|
|
|
252
|
-
export const BaseComponent =
|
|
250
|
+
export const BaseComponent = RawBaseComponent;
|
|
253
251
|
|
|
254
252
|
export default class Component extends React.Component {
|
|
255
253
|
static propTypes = {
|
|
@@ -1,16 +1,33 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
|
-
import {
|
|
3
|
+
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 classNames from 'classnames';
|
|
8
7
|
import { correct, disabled, incorrect, missing } from '../shared/styles';
|
|
9
8
|
|
|
9
|
+
const StyledLine = styled('line', {
|
|
10
|
+
shouldForwardProp: (prop) => !['disabled', 'correctness'].includes(prop),
|
|
11
|
+
})(({ disabled: isDisabled, correctness }) => ({
|
|
12
|
+
strokeWidth: 6,
|
|
13
|
+
transition: 'stroke-width 200ms ease-in, stroke 200ms ease-in',
|
|
14
|
+
stroke: 'transparent',
|
|
15
|
+
'&:hover': {
|
|
16
|
+
strokeWidth: 7,
|
|
17
|
+
stroke: color.defaults.SECONDARY,
|
|
18
|
+
},
|
|
19
|
+
...(isDisabled && {
|
|
20
|
+
...disabled('stroke'),
|
|
21
|
+
strokeWidth: 2,
|
|
22
|
+
}),
|
|
23
|
+
...(correctness === 'correct' && correct('stroke')),
|
|
24
|
+
...(correctness === 'incorrect' && incorrect('stroke')),
|
|
25
|
+
...(correctness === 'missing' && missing('stroke')),
|
|
26
|
+
}));
|
|
27
|
+
|
|
10
28
|
class RawLine extends React.Component {
|
|
11
29
|
static propTypes = {
|
|
12
30
|
className: PropTypes.string,
|
|
13
|
-
classes: PropTypes.object,
|
|
14
31
|
from: types.PointType,
|
|
15
32
|
to: types.PointType,
|
|
16
33
|
graphProps: types.GraphPropsType.isRequired,
|
|
@@ -24,39 +41,24 @@ class RawLine extends React.Component {
|
|
|
24
41
|
};
|
|
25
42
|
|
|
26
43
|
render() {
|
|
27
|
-
const { graphProps,
|
|
44
|
+
const { graphProps, from, to, className, disabled, correctness, ...rest } = this.props;
|
|
28
45
|
const { scale } = graphProps;
|
|
29
46
|
return (
|
|
30
|
-
<
|
|
47
|
+
<StyledLine
|
|
31
48
|
x1={scale.x(from.x)}
|
|
32
49
|
y1={scale.y(from.y)}
|
|
33
50
|
x2={scale.x(to.x)}
|
|
34
51
|
y2={scale.y(to.y)}
|
|
35
|
-
|
|
52
|
+
disabled={disabled}
|
|
53
|
+
correctness={correctness}
|
|
54
|
+
className={className}
|
|
36
55
|
{...rest}
|
|
37
56
|
/>
|
|
38
57
|
);
|
|
39
58
|
}
|
|
40
59
|
}
|
|
41
60
|
|
|
42
|
-
export const Line =
|
|
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);
|
|
61
|
+
export const Line = RawLine;
|
|
60
62
|
|
|
61
63
|
export default gridDraggable({
|
|
62
64
|
bounds: (props, { domain, range }) => {
|
|
@@ -1,12 +1,36 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
|
-
import {
|
|
3
|
+
import { styled } from '@mui/material/styles';
|
|
4
4
|
import { gridDraggable, types } from '@pie-lib/plot';
|
|
5
5
|
import * as utils from '../../utils';
|
|
6
|
-
import classNames from 'classnames';
|
|
7
6
|
import { color } from '@pie-lib/render-ui';
|
|
8
|
-
import {
|
|
9
|
-
|
|
7
|
+
import { correct, incorrect } from '../shared/styles';
|
|
8
|
+
|
|
9
|
+
const StyledPolygon = styled('polygon', {
|
|
10
|
+
shouldForwardProp: (prop) => !['isSolution', 'correctness'].includes(prop),
|
|
11
|
+
})(({ isSolution, correctness }) => ({
|
|
12
|
+
fill: isSolution ? 'rgb(60, 73, 150, 0.6)' : 'transparent',
|
|
13
|
+
strokeWidth: 2,
|
|
14
|
+
stroke: color.defaults.SECONDARY_LIGHT,
|
|
15
|
+
'&:hover': {
|
|
16
|
+
fill: isSolution ? 'rgb(60, 73, 150, 0.6)' : 'rgb(0, 0, 0, 0.25)',
|
|
17
|
+
},
|
|
18
|
+
...(correctness === 'correct' && correct('stroke')),
|
|
19
|
+
...(correctness === 'incorrect' && incorrect('stroke')),
|
|
20
|
+
}));
|
|
21
|
+
|
|
22
|
+
const StyledPolyline = styled('polyline', {
|
|
23
|
+
shouldForwardProp: (prop) => !['isSolution', 'correctness'].includes(prop),
|
|
24
|
+
})(({ isSolution, correctness }) => ({
|
|
25
|
+
fill: isSolution ? 'rgb(60, 73, 150, 0.6)' : 'transparent',
|
|
26
|
+
strokeWidth: 2,
|
|
27
|
+
stroke: color.defaults.SECONDARY_LIGHT,
|
|
28
|
+
'&:hover': {
|
|
29
|
+
fill: isSolution ? 'rgb(60, 73, 150, 0.6)' : 'rgb(0, 0, 0, 0.25)',
|
|
30
|
+
},
|
|
31
|
+
...(correctness === 'correct' && correct('stroke')),
|
|
32
|
+
...(correctness === 'incorrect' && incorrect('stroke')),
|
|
33
|
+
}));
|
|
10
34
|
|
|
11
35
|
export const getPointString = (points, scale) => {
|
|
12
36
|
return (points || [])
|
|
@@ -22,7 +46,6 @@ export const getPointString = (points, scale) => {
|
|
|
22
46
|
|
|
23
47
|
export class RawPolygon extends React.Component {
|
|
24
48
|
static propTypes = {
|
|
25
|
-
classes: PropTypes.object,
|
|
26
49
|
className: PropTypes.string,
|
|
27
50
|
isSolution: PropTypes.bool,
|
|
28
51
|
points: PropTypes.arrayOf(types.PointType),
|
|
@@ -36,52 +59,24 @@ export class RawPolygon extends React.Component {
|
|
|
36
59
|
};
|
|
37
60
|
|
|
38
61
|
render() {
|
|
39
|
-
const { points,
|
|
62
|
+
const { points, className, correctness, graphProps, closed, isSolution, ...rest } = this.props;
|
|
40
63
|
const { scale } = graphProps;
|
|
41
64
|
|
|
42
65
|
const pointString = getPointString(points, scale);
|
|
43
|
-
const
|
|
66
|
+
const Component = closed ? StyledPolygon : StyledPolyline;
|
|
44
67
|
return (
|
|
45
|
-
<
|
|
68
|
+
<Component
|
|
46
69
|
points={pointString}
|
|
47
|
-
|
|
70
|
+
isSolution={isSolution}
|
|
71
|
+
correctness={correctness}
|
|
72
|
+
className={className}
|
|
48
73
|
{...rest}
|
|
49
74
|
/>
|
|
50
75
|
);
|
|
51
76
|
}
|
|
52
77
|
}
|
|
53
78
|
|
|
54
|
-
export const Polygon =
|
|
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);
|
|
79
|
+
export const Polygon = RawPolygon;
|
|
85
80
|
|
|
86
81
|
export default gridDraggable({
|
|
87
82
|
bounds: (props, { domain, range }) => {
|
|
@@ -1,34 +1,33 @@
|
|
|
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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
|
|
12
|
+
describe('rendering', () => {
|
|
13
|
+
it('renders without crashing', () => {
|
|
14
|
+
const { container } = renderComponent();
|
|
15
|
+
expect(container.firstChild).toBeInTheDocument();
|
|
16
16
|
});
|
|
17
17
|
});
|
|
18
18
|
});
|
|
19
19
|
|
|
20
20
|
describe('ArrowMarker', () => {
|
|
21
|
-
|
|
22
|
-
let onChange = jest.fn();
|
|
23
|
-
const wrapper = (extras) => {
|
|
21
|
+
const renderComponent = (extras) => {
|
|
24
22
|
const defaults = { id: 'id', size: 10, className: 'className' };
|
|
25
23
|
const props = { ...defaults, ...extras };
|
|
26
|
-
return
|
|
24
|
+
return render(<ArrowMarker {...props} />);
|
|
27
25
|
};
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
26
|
+
|
|
27
|
+
describe('rendering', () => {
|
|
28
|
+
it('renders without crashing', () => {
|
|
29
|
+
const { container } = renderComponent();
|
|
30
|
+
expect(container.firstChild).toBeInTheDocument();
|
|
32
31
|
});
|
|
33
32
|
});
|
|
34
33
|
});
|