@pie-lib/graphing 2.14.22 → 2.15.1-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.md +13 -80
- package/NEXT.CHANGELOG.json +1 -0
- package/package.json +14 -7
- package/src/__tests__/__snapshots__/graph-with-controls.test.jsx.snap +237 -0
- package/src/__tests__/__snapshots__/graph.test.jsx.snap +211 -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 +45 -0
- package/src/__tests__/__snapshots__/toggle-bar.test.jsx.snap +7 -0
- package/src/__tests__/__snapshots__/tool-menu.test.jsx.snap +13 -0
- package/src/__tests__/__snapshots__/undo-redo.test.jsx.snap +14 -0
- package/src/__tests__/graph-with-controls.test.jsx +147 -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/axes.jsx +5 -5
- package/src/container/index.jsx +2 -4
- package/src/coordinates-label.jsx +4 -3
- package/src/graph-with-controls.jsx +8 -10
- package/src/graph.jsx +22 -10
- package/src/grid.jsx +8 -10
- package/src/index.js +2 -2
- package/src/key-legend.jsx +145 -0
- package/src/label-svg-icon.jsx +39 -0
- package/src/labels.jsx +2 -1
- package/src/mark-label.jsx +149 -52
- package/src/toggle-bar.jsx +1 -2
- package/src/tool-menu.jsx +3 -26
- package/src/tools/absolute/__tests__/component.test.jsx +54 -0
- package/src/tools/absolute/component.jsx +23 -0
- package/src/tools/absolute/index.js +31 -0
- package/src/tools/circle/__tests__/__snapshots__/bg-circle.test.jsx.snap +46 -0
- package/src/tools/circle/__tests__/__snapshots__/component.test.jsx.snap +293 -0
- package/src/tools/circle/__tests__/bg-circle.test.jsx +28 -0
- package/src/tools/circle/__tests__/component.test.jsx +228 -0
- package/src/tools/circle/bg-circle.jsx +5 -4
- package/src/tools/circle/component.jsx +22 -8
- package/src/tools/exponential/__tests__/component.test.jsx +54 -0
- package/src/tools/exponential/component.jsx +23 -0
- package/src/tools/exponential/index.js +39 -0
- package/src/tools/index.js +38 -5
- 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 +2 -1
- package/src/tools/parabola/__tests__/component.test.jsx +49 -0
- package/src/tools/parabola/component.jsx +7 -6
- package/src/tools/point/__tests__/__snapshots__/component.test.jsx.snap +40 -0
- package/src/tools/point/__tests__/component.test.jsx +66 -0
- package/src/tools/point/component.jsx +12 -6
- package/src/tools/polygon/__tests__/__snapshots__/component.test.jsx.snap +415 -0
- package/src/tools/polygon/__tests__/__snapshots__/line.test.jsx.snap +45 -0
- package/src/tools/polygon/__tests__/__snapshots__/polygon.test.jsx.snap +52 -0
- package/src/tools/polygon/__tests__/component.test.jsx +226 -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 +39 -11
- package/src/tools/polygon/line.jsx +15 -7
- package/src/tools/polygon/polygon.jsx +7 -3
- package/src/tools/ray/__tests__/__snapshots__/component.test.jsx.snap +23 -0
- package/src/tools/ray/__tests__/component.test.jsx +29 -0
- package/src/tools/ray/component.jsx +2 -1
- package/src/tools/segment/__tests__/__snapshots__/component.test.jsx.snap +14 -0
- package/src/tools/segment/__tests__/component.test.jsx +28 -0
- package/src/tools/segment/component.jsx +2 -1
- package/src/tools/shared/__tests__/__snapshots__/arrow-head.test.jsx.snap +27 -0
- package/src/tools/shared/__tests__/arrow-head.test.jsx +34 -0
- package/src/tools/shared/icons/CorrectSVG.jsx +22 -0
- package/src/tools/shared/icons/IncorrectSVG.jsx +20 -0
- package/src/tools/shared/icons/MissingSVG.jsx +21 -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 +58 -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 +255 -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 +39 -13
- package/src/tools/shared/line/line-path.jsx +18 -7
- package/src/tools/shared/line/with-root-edge.jsx +10 -3
- package/src/tools/shared/point/__tests__/__snapshots__/arrow-point.test.jsx.snap +56 -0
- package/src/tools/shared/point/__tests__/__snapshots__/base-point.test.jsx.snap +44 -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 +4 -1
- package/src/tools/shared/point/arrow.jsx +4 -1
- package/src/tools/shared/point/base-point.jsx +28 -3
- package/src/tools/shared/point/index.jsx +7 -2
- package/src/tools/shared/styles.js +8 -3
- package/src/tools/sine/__tests__/component.test.jsx +51 -0
- package/src/tools/sine/component.jsx +7 -7
- package/src/tools/vector/__tests__/__snapshots__/component.test.jsx.snap +12 -0
- package/src/tools/vector/__tests__/component.test.jsx +26 -0
- package/src/tools/vector/component.jsx +2 -1
- package/src/undo-redo.jsx +0 -1
- package/src/utils.js +1 -1
- package/legacy.png +0 -0
- package/lib/axis/arrow.js +0 -115
- package/lib/axis/arrow.js.map +0 -1
- package/lib/axis/axes.js +0 -415
- package/lib/axis/axes.js.map +0 -1
- package/lib/axis/index.js +0 -26
- package/lib/axis/index.js.map +0 -1
- package/lib/bg.js +0 -139
- package/lib/bg.js.map +0 -1
- package/lib/container/actions.js +0 -24
- package/lib/container/actions.js.map +0 -1
- package/lib/container/index.js +0 -166
- package/lib/container/index.js.map +0 -1
- package/lib/container/marks.js +0 -27
- package/lib/container/marks.js.map +0 -1
- package/lib/container/middleware.js +0 -25
- package/lib/container/middleware.js.map +0 -1
- package/lib/container/reducer.js +0 -25
- package/lib/container/reducer.js.map +0 -1
- package/lib/coordinates-label.js +0 -107
- package/lib/coordinates-label.js.map +0 -1
- package/lib/graph-with-controls.js +0 -366
- package/lib/graph-with-controls.js.map +0 -1
- package/lib/graph.js +0 -354
- package/lib/graph.js.map +0 -1
- package/lib/grid-setup.js +0 -462
- package/lib/grid-setup.js.map +0 -1
- package/lib/grid.js +0 -184
- package/lib/grid.js.map +0 -1
- package/lib/index.js +0 -51
- package/lib/index.js.map +0 -1
- package/lib/labels.js +0 -298
- package/lib/labels.js.map +0 -1
- package/lib/mark-label.js +0 -210
- package/lib/mark-label.js.map +0 -1
- package/lib/toggle-bar.js +0 -337
- package/lib/toggle-bar.js.map +0 -1
- package/lib/tool-menu.js +0 -132
- package/lib/tool-menu.js.map +0 -1
- package/lib/tools/circle/bg-circle.js +0 -172
- package/lib/tools/circle/bg-circle.js.map +0 -1
- package/lib/tools/circle/component.js +0 -387
- package/lib/tools/circle/component.js.map +0 -1
- package/lib/tools/circle/index.js +0 -51
- package/lib/tools/circle/index.js.map +0 -1
- package/lib/tools/index.js +0 -79
- package/lib/tools/index.js.map +0 -1
- package/lib/tools/line/component.js +0 -102
- package/lib/tools/line/component.js.map +0 -1
- package/lib/tools/line/index.js +0 -16
- package/lib/tools/line/index.js.map +0 -1
- package/lib/tools/parabola/component.js +0 -33
- package/lib/tools/parabola/component.js.map +0 -1
- package/lib/tools/parabola/index.js +0 -63
- package/lib/tools/parabola/index.js.map +0 -1
- package/lib/tools/point/component.js +0 -181
- package/lib/tools/point/component.js.map +0 -1
- package/lib/tools/point/index.js +0 -32
- package/lib/tools/point/index.js.map +0 -1
- package/lib/tools/polygon/component.js +0 -505
- package/lib/tools/polygon/component.js.map +0 -1
- package/lib/tools/polygon/index.js +0 -106
- package/lib/tools/polygon/index.js.map +0 -1
- package/lib/tools/polygon/line.js +0 -151
- package/lib/tools/polygon/line.js.map +0 -1
- package/lib/tools/polygon/polygon.js +0 -162
- package/lib/tools/polygon/polygon.js.map +0 -1
- package/lib/tools/ray/component.js +0 -101
- package/lib/tools/ray/component.js.map +0 -1
- package/lib/tools/ray/index.js +0 -16
- package/lib/tools/ray/index.js.map +0 -1
- package/lib/tools/segment/component.js +0 -74
- package/lib/tools/segment/component.js.map +0 -1
- package/lib/tools/segment/index.js +0 -16
- package/lib/tools/segment/index.js.map +0 -1
- package/lib/tools/shared/arrow-head.js +0 -70
- package/lib/tools/shared/arrow-head.js.map +0 -1
- package/lib/tools/shared/line/index.js +0 -567
- package/lib/tools/shared/line/index.js.map +0 -1
- package/lib/tools/shared/line/line-path.js +0 -145
- package/lib/tools/shared/line/line-path.js.map +0 -1
- package/lib/tools/shared/line/with-root-edge.js +0 -144
- package/lib/tools/shared/line/with-root-edge.js.map +0 -1
- package/lib/tools/shared/point/arrow-point.js +0 -113
- package/lib/tools/shared/point/arrow-point.js.map +0 -1
- package/lib/tools/shared/point/arrow.js +0 -96
- package/lib/tools/shared/point/arrow.js.map +0 -1
- package/lib/tools/shared/point/base-point.js +0 -139
- package/lib/tools/shared/point/base-point.js.map +0 -1
- package/lib/tools/shared/point/index.js +0 -94
- package/lib/tools/shared/point/index.js.map +0 -1
- package/lib/tools/shared/styles.js +0 -49
- package/lib/tools/shared/styles.js.map +0 -1
- package/lib/tools/shared/types.js +0 -23
- package/lib/tools/shared/types.js.map +0 -1
- package/lib/tools/sine/component.js +0 -42
- package/lib/tools/sine/component.js.map +0 -1
- package/lib/tools/sine/index.js +0 -63
- package/lib/tools/sine/index.js.map +0 -1
- package/lib/tools/vector/component.js +0 -87
- package/lib/tools/vector/component.js.map +0 -1
- package/lib/tools/vector/index.js +0 -16
- package/lib/tools/vector/index.js.map +0 -1
- package/lib/undo-redo.js +0 -124
- package/lib/undo-redo.js.map +0 -1
- package/lib/use-debounce.js +0 -32
- package/lib/use-debounce.js.map +0 -1
- package/lib/utils.js +0 -307
- package/lib/utils.js.map +0 -1
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import Absolute from './component';
|
|
2
|
+
import debug from 'debug';
|
|
3
|
+
import { equalPoints, sameAxes } from '../../utils';
|
|
4
|
+
|
|
5
|
+
const log = debug('pie-lib:graphing:absolute');
|
|
6
|
+
|
|
7
|
+
export const tool = () => ({
|
|
8
|
+
type: 'absolute',
|
|
9
|
+
Component: Absolute,
|
|
10
|
+
complete: (data, mark) => ({ ...mark, building: false, closed: true }),
|
|
11
|
+
addPoint: (point, mark) => {
|
|
12
|
+
log('add point to absolute model: ', point, 'mark: ', mark);
|
|
13
|
+
if (mark && (equalPoints(mark.root, point) || sameAxes(mark.root, point))) {
|
|
14
|
+
return mark;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (!mark) {
|
|
18
|
+
return {
|
|
19
|
+
type: 'absolute',
|
|
20
|
+
root: point,
|
|
21
|
+
edge: undefined,
|
|
22
|
+
closed: false,
|
|
23
|
+
building: true,
|
|
24
|
+
};
|
|
25
|
+
} else if (mark && !mark.root) {
|
|
26
|
+
throw new Error('no root - should never happen');
|
|
27
|
+
} else {
|
|
28
|
+
return { ...mark, edge: point, closed: true, building: false };
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`BgCircle snapshot renders 1`] = `
|
|
4
|
+
<RawCircle
|
|
5
|
+
className="className"
|
|
6
|
+
classes={
|
|
7
|
+
Object {
|
|
8
|
+
"bgCircle": "RawCircle-bgCircle-1",
|
|
9
|
+
"correct": "RawCircle-correct-4",
|
|
10
|
+
"disabled": "RawCircle-disabled-2",
|
|
11
|
+
"disabledSecondary": "RawCircle-disabledSecondary-3",
|
|
12
|
+
"incorrect": "RawCircle-incorrect-5",
|
|
13
|
+
"missing": "RawCircle-missing-6",
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
graphProps={
|
|
17
|
+
Object {
|
|
18
|
+
"domain": Object {
|
|
19
|
+
"max": 1,
|
|
20
|
+
"min": 0,
|
|
21
|
+
"step": 1,
|
|
22
|
+
},
|
|
23
|
+
"range": Object {
|
|
24
|
+
"max": 1,
|
|
25
|
+
"min": 0,
|
|
26
|
+
"step": 1,
|
|
27
|
+
},
|
|
28
|
+
"scale": Object {
|
|
29
|
+
"x": [MockFunction],
|
|
30
|
+
"y": [MockFunction],
|
|
31
|
+
},
|
|
32
|
+
"size": Object {
|
|
33
|
+
"height": 400,
|
|
34
|
+
"width": 400,
|
|
35
|
+
},
|
|
36
|
+
"snap": Object {
|
|
37
|
+
"x": [MockFunction],
|
|
38
|
+
"y": [MockFunction],
|
|
39
|
+
},
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
onChange={[MockFunction]}
|
|
43
|
+
x={0}
|
|
44
|
+
y={0}
|
|
45
|
+
/>
|
|
46
|
+
`;
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`Component snapshot renders 1`] = `
|
|
4
|
+
<g>
|
|
5
|
+
<GridDraggable
|
|
6
|
+
className=""
|
|
7
|
+
graphProps={
|
|
8
|
+
Object {
|
|
9
|
+
"domain": Object {
|
|
10
|
+
"max": 1,
|
|
11
|
+
"min": 0,
|
|
12
|
+
"step": 1,
|
|
13
|
+
},
|
|
14
|
+
"range": Object {
|
|
15
|
+
"max": 1,
|
|
16
|
+
"min": 0,
|
|
17
|
+
"step": 1,
|
|
18
|
+
},
|
|
19
|
+
"scale": Object {
|
|
20
|
+
"x": [MockFunction],
|
|
21
|
+
"y": [MockFunction],
|
|
22
|
+
},
|
|
23
|
+
"size": Object {
|
|
24
|
+
"height": 400,
|
|
25
|
+
"width": 400,
|
|
26
|
+
},
|
|
27
|
+
"snap": Object {
|
|
28
|
+
"x": [MockFunction],
|
|
29
|
+
"y": [MockFunction],
|
|
30
|
+
},
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
onClick={[Function]}
|
|
34
|
+
onDrag={[Function]}
|
|
35
|
+
radius={1.4142135623730951}
|
|
36
|
+
x={0}
|
|
37
|
+
y={0}
|
|
38
|
+
/>
|
|
39
|
+
<WithStyles(GridDraggable)
|
|
40
|
+
graphProps={
|
|
41
|
+
Object {
|
|
42
|
+
"domain": Object {
|
|
43
|
+
"max": 1,
|
|
44
|
+
"min": 0,
|
|
45
|
+
"step": 1,
|
|
46
|
+
},
|
|
47
|
+
"range": Object {
|
|
48
|
+
"max": 1,
|
|
49
|
+
"min": 0,
|
|
50
|
+
"step": 1,
|
|
51
|
+
},
|
|
52
|
+
"scale": Object {
|
|
53
|
+
"x": [MockFunction],
|
|
54
|
+
"y": [MockFunction],
|
|
55
|
+
},
|
|
56
|
+
"size": Object {
|
|
57
|
+
"height": 400,
|
|
58
|
+
"width": 400,
|
|
59
|
+
},
|
|
60
|
+
"snap": Object {
|
|
61
|
+
"x": [MockFunction],
|
|
62
|
+
"y": [MockFunction],
|
|
63
|
+
},
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
onClick={[Function]}
|
|
67
|
+
onDrag={[Function]}
|
|
68
|
+
x={1}
|
|
69
|
+
y={1}
|
|
70
|
+
/>
|
|
71
|
+
<WithStyles(GridDraggable)
|
|
72
|
+
graphProps={
|
|
73
|
+
Object {
|
|
74
|
+
"domain": Object {
|
|
75
|
+
"max": 1,
|
|
76
|
+
"min": 0,
|
|
77
|
+
"step": 1,
|
|
78
|
+
},
|
|
79
|
+
"range": Object {
|
|
80
|
+
"max": 1,
|
|
81
|
+
"min": 0,
|
|
82
|
+
"step": 1,
|
|
83
|
+
},
|
|
84
|
+
"scale": Object {
|
|
85
|
+
"x": [MockFunction],
|
|
86
|
+
"y": [MockFunction],
|
|
87
|
+
},
|
|
88
|
+
"size": Object {
|
|
89
|
+
"height": 400,
|
|
90
|
+
"width": 400,
|
|
91
|
+
},
|
|
92
|
+
"snap": Object {
|
|
93
|
+
"x": [MockFunction],
|
|
94
|
+
"y": [MockFunction],
|
|
95
|
+
},
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
onClick={[Function]}
|
|
99
|
+
onDrag={[Function]}
|
|
100
|
+
x={0}
|
|
101
|
+
y={0}
|
|
102
|
+
/>
|
|
103
|
+
</g>
|
|
104
|
+
`;
|
|
105
|
+
|
|
106
|
+
exports[`Component snapshot renders with labels 1`] = `
|
|
107
|
+
<g>
|
|
108
|
+
<GridDraggable
|
|
109
|
+
className=""
|
|
110
|
+
graphProps={
|
|
111
|
+
Object {
|
|
112
|
+
"domain": Object {
|
|
113
|
+
"max": 1,
|
|
114
|
+
"min": 0,
|
|
115
|
+
"step": 1,
|
|
116
|
+
},
|
|
117
|
+
"range": Object {
|
|
118
|
+
"max": 1,
|
|
119
|
+
"min": 0,
|
|
120
|
+
"step": 1,
|
|
121
|
+
},
|
|
122
|
+
"scale": Object {
|
|
123
|
+
"x": [MockFunction],
|
|
124
|
+
"y": [MockFunction],
|
|
125
|
+
},
|
|
126
|
+
"size": Object {
|
|
127
|
+
"height": 400,
|
|
128
|
+
"width": 400,
|
|
129
|
+
},
|
|
130
|
+
"snap": Object {
|
|
131
|
+
"x": [MockFunction],
|
|
132
|
+
"y": [MockFunction],
|
|
133
|
+
},
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
onClick={[Function]}
|
|
137
|
+
onDrag={[Function]}
|
|
138
|
+
radius={1.4142135623730951}
|
|
139
|
+
x={0}
|
|
140
|
+
y={0}
|
|
141
|
+
/>
|
|
142
|
+
<WithStyles(GridDraggable)
|
|
143
|
+
graphProps={
|
|
144
|
+
Object {
|
|
145
|
+
"domain": Object {
|
|
146
|
+
"max": 1,
|
|
147
|
+
"min": 0,
|
|
148
|
+
"step": 1,
|
|
149
|
+
},
|
|
150
|
+
"range": Object {
|
|
151
|
+
"max": 1,
|
|
152
|
+
"min": 0,
|
|
153
|
+
"step": 1,
|
|
154
|
+
},
|
|
155
|
+
"scale": Object {
|
|
156
|
+
"x": [MockFunction],
|
|
157
|
+
"y": [MockFunction],
|
|
158
|
+
},
|
|
159
|
+
"size": Object {
|
|
160
|
+
"height": 400,
|
|
161
|
+
"width": 400,
|
|
162
|
+
},
|
|
163
|
+
"snap": Object {
|
|
164
|
+
"x": [MockFunction],
|
|
165
|
+
"y": [MockFunction],
|
|
166
|
+
},
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
labelNode={<foreignobject />}
|
|
170
|
+
onClick={[Function]}
|
|
171
|
+
onDrag={[Function]}
|
|
172
|
+
x={1}
|
|
173
|
+
y={1}
|
|
174
|
+
/>
|
|
175
|
+
<Portal
|
|
176
|
+
containerInfo={<foreignobject />}
|
|
177
|
+
>
|
|
178
|
+
<WithStyles(MarkLabel)
|
|
179
|
+
disabled={true}
|
|
180
|
+
graphProps={
|
|
181
|
+
Object {
|
|
182
|
+
"domain": Object {
|
|
183
|
+
"max": 1,
|
|
184
|
+
"min": 0,
|
|
185
|
+
"step": 1,
|
|
186
|
+
},
|
|
187
|
+
"range": Object {
|
|
188
|
+
"max": 1,
|
|
189
|
+
"min": 0,
|
|
190
|
+
"step": 1,
|
|
191
|
+
},
|
|
192
|
+
"scale": Object {
|
|
193
|
+
"x": [MockFunction],
|
|
194
|
+
"y": [MockFunction],
|
|
195
|
+
},
|
|
196
|
+
"size": Object {
|
|
197
|
+
"height": 400,
|
|
198
|
+
"width": 400,
|
|
199
|
+
},
|
|
200
|
+
"snap": Object {
|
|
201
|
+
"x": [MockFunction],
|
|
202
|
+
"y": [MockFunction],
|
|
203
|
+
},
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
inputRef={[Function]}
|
|
207
|
+
mark={
|
|
208
|
+
Object {
|
|
209
|
+
"label": "B",
|
|
210
|
+
"x": 1,
|
|
211
|
+
"y": 1,
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
onChange={[Function]}
|
|
215
|
+
/>
|
|
216
|
+
</Portal>
|
|
217
|
+
<WithStyles(GridDraggable)
|
|
218
|
+
graphProps={
|
|
219
|
+
Object {
|
|
220
|
+
"domain": Object {
|
|
221
|
+
"max": 1,
|
|
222
|
+
"min": 0,
|
|
223
|
+
"step": 1,
|
|
224
|
+
},
|
|
225
|
+
"range": Object {
|
|
226
|
+
"max": 1,
|
|
227
|
+
"min": 0,
|
|
228
|
+
"step": 1,
|
|
229
|
+
},
|
|
230
|
+
"scale": Object {
|
|
231
|
+
"x": [MockFunction],
|
|
232
|
+
"y": [MockFunction],
|
|
233
|
+
},
|
|
234
|
+
"size": Object {
|
|
235
|
+
"height": 400,
|
|
236
|
+
"width": 400,
|
|
237
|
+
},
|
|
238
|
+
"snap": Object {
|
|
239
|
+
"x": [MockFunction],
|
|
240
|
+
"y": [MockFunction],
|
|
241
|
+
},
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
labelNode={<foreignobject />}
|
|
245
|
+
onClick={[Function]}
|
|
246
|
+
onDrag={[Function]}
|
|
247
|
+
x={0}
|
|
248
|
+
y={0}
|
|
249
|
+
/>
|
|
250
|
+
<Portal
|
|
251
|
+
containerInfo={<foreignobject />}
|
|
252
|
+
>
|
|
253
|
+
<WithStyles(MarkLabel)
|
|
254
|
+
disabled={true}
|
|
255
|
+
graphProps={
|
|
256
|
+
Object {
|
|
257
|
+
"domain": Object {
|
|
258
|
+
"max": 1,
|
|
259
|
+
"min": 0,
|
|
260
|
+
"step": 1,
|
|
261
|
+
},
|
|
262
|
+
"range": Object {
|
|
263
|
+
"max": 1,
|
|
264
|
+
"min": 0,
|
|
265
|
+
"step": 1,
|
|
266
|
+
},
|
|
267
|
+
"scale": Object {
|
|
268
|
+
"x": [MockFunction],
|
|
269
|
+
"y": [MockFunction],
|
|
270
|
+
},
|
|
271
|
+
"size": Object {
|
|
272
|
+
"height": 400,
|
|
273
|
+
"width": 400,
|
|
274
|
+
},
|
|
275
|
+
"snap": Object {
|
|
276
|
+
"x": [MockFunction],
|
|
277
|
+
"y": [MockFunction],
|
|
278
|
+
},
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
inputRef={[Function]}
|
|
282
|
+
mark={
|
|
283
|
+
Object {
|
|
284
|
+
"label": "A",
|
|
285
|
+
"x": 0,
|
|
286
|
+
"y": 0,
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
onChange={[Function]}
|
|
290
|
+
/>
|
|
291
|
+
</Portal>
|
|
292
|
+
</g>
|
|
293
|
+
`;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { shallow } from 'enzyme';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { BgCircle } from '../bg-circle';
|
|
4
|
+
import { graphProps } from '../../../__tests__/utils';
|
|
5
|
+
|
|
6
|
+
describe('BgCircle', () => {
|
|
7
|
+
let w;
|
|
8
|
+
let onChange = jest.fn();
|
|
9
|
+
const wrapper = (extras) => {
|
|
10
|
+
const defaults = {
|
|
11
|
+
classes: {},
|
|
12
|
+
className: 'className',
|
|
13
|
+
onChange,
|
|
14
|
+
x: 0,
|
|
15
|
+
y: 0,
|
|
16
|
+
graphProps: graphProps(),
|
|
17
|
+
};
|
|
18
|
+
const props = { ...defaults, ...extras };
|
|
19
|
+
return shallow(<BgCircle {...props} />);
|
|
20
|
+
};
|
|
21
|
+
describe('snapshot', () => {
|
|
22
|
+
it('renders', () => {
|
|
23
|
+
w = wrapper();
|
|
24
|
+
expect(w).toMatchSnapshot();
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
describe('logic', () => {});
|
|
28
|
+
});
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import { shallow } from 'enzyme';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { graphProps, xy } from '../../../__tests__/utils';
|
|
4
|
+
|
|
5
|
+
import { RawBaseCircle } from '../component';
|
|
6
|
+
|
|
7
|
+
const xyLabel = (x, y, label) => ({ x, y, label });
|
|
8
|
+
|
|
9
|
+
describe('Component', () => {
|
|
10
|
+
let w;
|
|
11
|
+
let onChange = jest.fn();
|
|
12
|
+
let changeMarkProps = jest.fn();
|
|
13
|
+
|
|
14
|
+
const wrapper = (extras) => {
|
|
15
|
+
const defaults = {
|
|
16
|
+
classes: {},
|
|
17
|
+
className: 'className',
|
|
18
|
+
onChange,
|
|
19
|
+
changeMarkProps,
|
|
20
|
+
graphProps: graphProps(),
|
|
21
|
+
from: xy(0, 0),
|
|
22
|
+
to: xy(1, 1),
|
|
23
|
+
};
|
|
24
|
+
const props = { ...defaults, ...extras };
|
|
25
|
+
|
|
26
|
+
return shallow(<RawBaseCircle {...props} />);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
// used to test items that have labels attached to points
|
|
30
|
+
const labelNode = document.createElement('foreignObject');
|
|
31
|
+
const fromWithLabel = { x: 0, y: 0, label: 'A' };
|
|
32
|
+
const toWithLabel = { x: 1, y: 1, label: 'B' };
|
|
33
|
+
const wrapperWithLabels = (extras = {}) =>
|
|
34
|
+
wrapper({
|
|
35
|
+
...extras,
|
|
36
|
+
labelNode: labelNode,
|
|
37
|
+
from: fromWithLabel,
|
|
38
|
+
to: toWithLabel,
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
describe('snapshot', () => {
|
|
42
|
+
it('renders', () => {
|
|
43
|
+
w = wrapper();
|
|
44
|
+
expect(w).toMatchSnapshot();
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('renders with labels', () => {
|
|
48
|
+
w = wrapperWithLabels();
|
|
49
|
+
|
|
50
|
+
expect(w).toMatchSnapshot();
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
describe('logic', () => {
|
|
55
|
+
beforeEach(() => (w = wrapper()));
|
|
56
|
+
|
|
57
|
+
describe('dragFrom', () => {
|
|
58
|
+
it('calls onChange', () => {
|
|
59
|
+
w = wrapper();
|
|
60
|
+
w.instance().dragFrom(xy(1, 1));
|
|
61
|
+
expect(onChange).not.toHaveBeenCalledWith({
|
|
62
|
+
from: xy(1, 1),
|
|
63
|
+
to: xy(1, 1),
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
w.instance().dragFrom(xy(2, 2));
|
|
67
|
+
expect(onChange).toHaveBeenCalledWith({
|
|
68
|
+
from: xy(2, 2),
|
|
69
|
+
to: xy(1, 1),
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
describe('dragFrom keeps labels on "from"', () => {
|
|
75
|
+
it('calls onChange', () => {
|
|
76
|
+
w = wrapperWithLabels();
|
|
77
|
+
|
|
78
|
+
// drag "from" to { x: 1, y: 1 }
|
|
79
|
+
w.instance().dragFrom({ x: 1, y: 1 });
|
|
80
|
+
|
|
81
|
+
// won't change because points overlap
|
|
82
|
+
expect(onChange).not.toHaveBeenCalledWith({
|
|
83
|
+
from: xyLabel(1, 1, 'A'),
|
|
84
|
+
to: toWithLabel,
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
// wil change and will keep labels
|
|
88
|
+
w.instance().dragFrom({ x: 2, y: 2 });
|
|
89
|
+
expect(onChange).toHaveBeenCalledWith({
|
|
90
|
+
from: xyLabel(2, 2, 'A'),
|
|
91
|
+
to: toWithLabel,
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
describe('dragTo', () => {
|
|
97
|
+
it('calls onChange', () => {
|
|
98
|
+
w.instance().dragTo(xy(4, 4));
|
|
99
|
+
expect(onChange).toHaveBeenCalledWith({
|
|
100
|
+
from: xy(0, 0),
|
|
101
|
+
to: xy(4, 4),
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
describe('dragTo keeps labels on "to"', () => {
|
|
107
|
+
it('calls onChange', () => {
|
|
108
|
+
w = wrapperWithLabels();
|
|
109
|
+
|
|
110
|
+
// won't change because points overlap
|
|
111
|
+
w.instance().dragTo({ x: 0, y: 0 });
|
|
112
|
+
expect(onChange).not.toHaveBeenCalledWith({
|
|
113
|
+
from: fromWithLabel,
|
|
114
|
+
to: xyLabel(1, 1, 'B'),
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
// wil change and will keep labels
|
|
118
|
+
w.instance().dragTo({ x: 2, y: 2 });
|
|
119
|
+
expect(onChange).toHaveBeenCalledWith({
|
|
120
|
+
from: fromWithLabel,
|
|
121
|
+
to: xyLabel(2, 2, 'B'),
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
describe('dragCircle', () => {
|
|
127
|
+
it('calls onChange', () => {
|
|
128
|
+
w.instance().dragCircle(xy(1, 1));
|
|
129
|
+
expect(onChange).toHaveBeenCalledWith({
|
|
130
|
+
from: xy(1, 1),
|
|
131
|
+
to: xy(2, 2),
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
describe('dragCircle keeps labels on both "from" and "to"', () => {
|
|
137
|
+
it('calls onChange', () => {
|
|
138
|
+
w = wrapperWithLabels();
|
|
139
|
+
|
|
140
|
+
// wil change and will keep labels
|
|
141
|
+
w.instance().dragCircle({ x: 10, y: 10 });
|
|
142
|
+
expect(onChange).toHaveBeenCalledWith({
|
|
143
|
+
from: xyLabel(10, 10, 'A'),
|
|
144
|
+
to: xyLabel(11, 11, 'B'),
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
// wil change and will keep labels
|
|
148
|
+
w.instance().dragCircle({ x: 2, y: 2 });
|
|
149
|
+
expect(onChange).toHaveBeenCalledWith({
|
|
150
|
+
from: xyLabel(2, 2, 'A'),
|
|
151
|
+
to: xyLabel(3, 3, 'B'),
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
describe('labelChange', () => {
|
|
157
|
+
it('updates "label" property for point', () => {
|
|
158
|
+
w = wrapperWithLabels({ labelModeEnabled: true });
|
|
159
|
+
|
|
160
|
+
w.instance().labelChange(xyLabel(0, 0, 'Label A'), 'from');
|
|
161
|
+
expect(changeMarkProps).toBeCalledWith({
|
|
162
|
+
from: xyLabel(0, 0, 'Label A'),
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
w.instance().labelChange(xyLabel(0, 0, 'Label B'), 'to');
|
|
166
|
+
expect(changeMarkProps).toBeCalledWith({
|
|
167
|
+
to: xyLabel(0, 0, 'Label B'),
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
it('removes "label" property if the field is empty', () => {
|
|
172
|
+
w = wrapperWithLabels({ labelModeEnabled: true });
|
|
173
|
+
|
|
174
|
+
w.instance().labelChange(xyLabel(0, 0, ''), 'from');
|
|
175
|
+
expect(changeMarkProps).toBeCalledWith({
|
|
176
|
+
from: xy(0, 0),
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
w.instance().labelChange(xyLabel(0, 0, ''), 'to');
|
|
180
|
+
expect(changeMarkProps).toBeCalledWith({
|
|
181
|
+
to: xy(0, 0),
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
describe('clickPoint', () => {
|
|
187
|
+
it('adds "label" property to a point', () => {
|
|
188
|
+
w = wrapperWithLabels({ labelModeEnabled: true });
|
|
189
|
+
|
|
190
|
+
w.instance().clickPoint(xy(0, 0), 'from');
|
|
191
|
+
expect(changeMarkProps).toBeCalledWith({
|
|
192
|
+
from: xyLabel(0, 0, ''),
|
|
193
|
+
to: xyLabel(1, 1, 'B'),
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
w.instance().clickPoint(xy(1, 1), 'to');
|
|
197
|
+
expect(changeMarkProps).toBeCalledWith({
|
|
198
|
+
from: xyLabel(0, 0, 'A'),
|
|
199
|
+
to: xyLabel(1, 1, ''),
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
it('adds "label" property to a point when limit labeling', () => {
|
|
204
|
+
const changeMarkProps = jest.fn();
|
|
205
|
+
w = wrapperWithLabels({ labelModeEnabled: true, limitLabeling: true, changeMarkProps });
|
|
206
|
+
|
|
207
|
+
w.instance().clickPoint(xy(0, 0), 'from');
|
|
208
|
+
expect(changeMarkProps).toHaveBeenCalledTimes(0);
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
it('if point already has label, keeps that value', () => {
|
|
212
|
+
w = wrapperWithLabels({ labelModeEnabled: true });
|
|
213
|
+
|
|
214
|
+
w.instance().clickPoint(fromWithLabel, 'from');
|
|
215
|
+
expect(changeMarkProps).toBeCalledWith({
|
|
216
|
+
from: fromWithLabel,
|
|
217
|
+
to: xyLabel(1, 1, 'B'),
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
w.instance().clickPoint(toWithLabel, 'to');
|
|
221
|
+
expect(changeMarkProps).toBeCalledWith({
|
|
222
|
+
from: xyLabel(0, 0, 'A'),
|
|
223
|
+
to: toWithLabel,
|
|
224
|
+
});
|
|
225
|
+
});
|
|
226
|
+
});
|
|
227
|
+
});
|
|
228
|
+
});
|
|
@@ -5,7 +5,7 @@ import classNames from 'classnames';
|
|
|
5
5
|
import { types, gridDraggable } from '@pie-lib/plot';
|
|
6
6
|
import { color } from '@pie-lib/render-ui';
|
|
7
7
|
import * as utils from '../../utils';
|
|
8
|
-
import { disabled, correct, incorrect, missing } from '../shared/styles';
|
|
8
|
+
import { disabled, disabledSecondary, correct, incorrect, missing } from '../shared/styles';
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* A low level circle component
|
|
@@ -33,7 +33,7 @@ class RawCircle extends React.Component {
|
|
|
33
33
|
|
|
34
34
|
return (
|
|
35
35
|
<ellipse
|
|
36
|
-
className={classNames(classes.bgCircle, disabled && classes.
|
|
36
|
+
className={classNames(classes.bgCircle, disabled && classes.disabledSecondary, classes[correctness], className)}
|
|
37
37
|
cx={scale.x(x)}
|
|
38
38
|
cy={scale.y(y)}
|
|
39
39
|
rx={rx}
|
|
@@ -55,15 +55,16 @@ const applyStyle = (fn) => ({
|
|
|
55
55
|
const styles = () => ({
|
|
56
56
|
bgCircle: {
|
|
57
57
|
fill: 'transparent',
|
|
58
|
-
stroke: color.
|
|
58
|
+
stroke: color.defaults.BLACK,
|
|
59
59
|
strokeWidth: 3,
|
|
60
60
|
transition: 'stroke 200ms ease-in, stroke-width 200ms ease-in',
|
|
61
61
|
'&:hover': {
|
|
62
62
|
strokeWidth: 6,
|
|
63
|
-
stroke: color.
|
|
63
|
+
stroke: color.defaults.PRIMARY_DARK,
|
|
64
64
|
},
|
|
65
65
|
},
|
|
66
66
|
disabled: applyStyle(disabled),
|
|
67
|
+
disabledSecondary: applyStyle(disabledSecondary),
|
|
67
68
|
correct: applyStyle(correct),
|
|
68
69
|
incorrect: applyStyle(incorrect),
|
|
69
70
|
missing: applyStyle(missing),
|