@pie-lib/graphing 2.14.22-next.0 → 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.md +16 -0
- package/NEXT.CHANGELOG.json +1 -0
- package/lib/__tests__/graph-with-controls.test.js +215 -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 +1 -1
- package/lib/axis/axes.js +6 -6
- package/lib/axis/index.js +1 -1
- package/lib/bg.js +1 -1
- package/lib/container/actions.js +1 -1
- package/lib/container/index.js +2 -5
- package/lib/container/marks.js +1 -1
- package/lib/container/middleware.js +1 -1
- package/lib/container/reducer.js +1 -1
- package/lib/coordinates-label.js +6 -4
- package/lib/graph-with-controls.js +9 -16
- package/lib/graph.js +30 -13
- package/lib/grid-setup.js +1 -1
- package/lib/grid.js +7 -15
- package/lib/index.js +9 -1
- package/lib/key-legend.js +246 -0
- package/lib/label-svg-icon.js +56 -0
- package/lib/labels.js +3 -2
- package/lib/mark-label.js +168 -57
- package/lib/toggle-bar.js +4 -5
- package/lib/tool-menu.js +3 -23
- package/lib/tools/absolute/__tests__/component.test.js +74 -0
- package/lib/tools/absolute/component.js +35 -0
- package/lib/tools/absolute/index.js +63 -0
- package/lib/tools/circle/__tests__/bg-circle.test.js +46 -0
- package/lib/tools/circle/__tests__/component.test.js +259 -0
- package/lib/tools/circle/bg-circle.js +5 -4
- package/lib/tools/circle/component.js +35 -16
- package/lib/tools/circle/index.js +1 -1
- package/lib/tools/exponential/__tests__/component.test.js +73 -0
- package/lib/tools/exponential/component.js +34 -0
- package/lib/tools/exponential/index.js +71 -0
- package/lib/tools/index.js +27 -7
- package/lib/tools/line/__tests__/component.test.js +56 -0
- package/lib/tools/line/component.js +3 -2
- package/lib/tools/line/index.js +1 -1
- package/lib/tools/parabola/__tests__/component.test.js +73 -0
- package/lib/tools/parabola/component.js +7 -6
- package/lib/tools/parabola/index.js +1 -1
- package/lib/tools/point/__tests__/component.test.js +97 -0
- package/lib/tools/point/component.js +15 -10
- package/lib/tools/point/index.js +1 -1
- package/lib/tools/polygon/__tests__/component.test.js +255 -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 +26 -13
- package/lib/tools/polygon/index.js +1 -1
- package/lib/tools/polygon/line.js +13 -7
- package/lib/tools/polygon/polygon.js +7 -4
- package/lib/tools/ray/__tests__/component.test.js +48 -0
- package/lib/tools/ray/component.js +3 -2
- package/lib/tools/ray/index.js +1 -1
- package/lib/tools/segment/__tests__/component.test.js +48 -0
- package/lib/tools/segment/component.js +3 -2
- package/lib/tools/segment/index.js +1 -1
- package/lib/tools/shared/__tests__/arrow-head.test.js +62 -0
- package/lib/tools/shared/arrow-head.js +1 -1
- package/lib/tools/shared/icons/CorrectSVG.js +36 -0
- package/lib/tools/shared/icons/IncorrectSVG.js +36 -0
- package/lib/tools/shared/icons/MissingSVG.js +35 -0
- package/lib/tools/shared/line/__tests__/index.test.js +301 -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 +52 -20
- package/lib/tools/shared/line/line-path.js +14 -8
- package/lib/tools/shared/line/with-root-edge.js +20 -9
- 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 +2 -2
- package/lib/tools/shared/point/arrow.js +2 -2
- package/lib/tools/shared/point/base-point.js +44 -8
- package/lib/tools/shared/point/index.js +5 -2
- package/lib/tools/shared/styles.js +17 -8
- package/lib/tools/shared/types.js +1 -1
- package/lib/tools/sine/__tests__/component.test.js +81 -0
- package/lib/tools/sine/component.js +14 -5
- package/lib/tools/sine/index.js +1 -1
- package/lib/tools/vector/__tests__/component.test.js +45 -0
- package/lib/tools/vector/component.js +3 -2
- package/lib/tools/vector/index.js +1 -1
- package/lib/undo-redo.js +1 -2
- package/lib/use-debounce.js +1 -1
- package/lib/utils.js +2 -2
- package/package.json +7 -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-setup.jsx +9 -6
- package/src/grid.jsx +8 -10
- package/src/index.js +2 -2
- package/src/key-legend.jsx +115 -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.map +0 -1
- package/lib/axis/axes.js.map +0 -1
- package/lib/axis/index.js.map +0 -1
- package/lib/bg.js.map +0 -1
- package/lib/container/actions.js.map +0 -1
- package/lib/container/index.js.map +0 -1
- package/lib/container/marks.js.map +0 -1
- package/lib/container/middleware.js.map +0 -1
- package/lib/container/reducer.js.map +0 -1
- package/lib/coordinates-label.js.map +0 -1
- package/lib/graph-with-controls.js.map +0 -1
- package/lib/graph.js.map +0 -1
- package/lib/grid-setup.js.map +0 -1
- package/lib/grid.js.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/labels.js.map +0 -1
- package/lib/mark-label.js.map +0 -1
- package/lib/toggle-bar.js.map +0 -1
- package/lib/tool-menu.js.map +0 -1
- package/lib/tools/circle/bg-circle.js.map +0 -1
- package/lib/tools/circle/component.js.map +0 -1
- package/lib/tools/circle/index.js.map +0 -1
- package/lib/tools/index.js.map +0 -1
- package/lib/tools/line/component.js.map +0 -1
- package/lib/tools/line/index.js.map +0 -1
- package/lib/tools/parabola/component.js.map +0 -1
- package/lib/tools/parabola/index.js.map +0 -1
- package/lib/tools/point/component.js.map +0 -1
- package/lib/tools/point/index.js.map +0 -1
- package/lib/tools/polygon/component.js.map +0 -1
- package/lib/tools/polygon/index.js.map +0 -1
- package/lib/tools/polygon/line.js.map +0 -1
- package/lib/tools/polygon/polygon.js.map +0 -1
- package/lib/tools/ray/component.js.map +0 -1
- package/lib/tools/ray/index.js.map +0 -1
- package/lib/tools/segment/component.js.map +0 -1
- package/lib/tools/segment/index.js.map +0 -1
- package/lib/tools/shared/arrow-head.js.map +0 -1
- package/lib/tools/shared/line/index.js.map +0 -1
- package/lib/tools/shared/line/line-path.js.map +0 -1
- package/lib/tools/shared/line/with-root-edge.js.map +0 -1
- package/lib/tools/shared/point/arrow-point.js.map +0 -1
- package/lib/tools/shared/point/arrow.js.map +0 -1
- package/lib/tools/shared/point/base-point.js.map +0 -1
- package/lib/tools/shared/point/index.js.map +0 -1
- package/lib/tools/shared/styles.js.map +0 -1
- package/lib/tools/shared/types.js.map +0 -1
- package/lib/tools/sine/component.js.map +0 -1
- package/lib/tools/sine/index.js.map +0 -1
- package/lib/tools/vector/component.js.map +0 -1
- package/lib/tools/vector/index.js.map +0 -1
- package/lib/undo-redo.js.map +0 -1
- package/lib/use-debounce.js.map +0 -1
- package/lib/utils.js.map +0 -1
package/src/mark-label.jsx
CHANGED
|
@@ -6,32 +6,71 @@ import AutosizeInput from 'react-input-autosize';
|
|
|
6
6
|
import { useDebounce } from './use-debounce';
|
|
7
7
|
import { types } from '@pie-lib/plot';
|
|
8
8
|
import { color } from '@pie-lib/render-ui';
|
|
9
|
+
import SvgIcon from './label-svg-icon';
|
|
10
|
+
|
|
11
|
+
const inputStyles = (theme) => ({
|
|
12
|
+
float: 'right',
|
|
13
|
+
padding: theme.spacing.unit * 0.5,
|
|
14
|
+
borderRadius: '4px',
|
|
15
|
+
fontSize: '10px',
|
|
16
|
+
backgroundColor: color.defaults.WHITE,
|
|
17
|
+
});
|
|
9
18
|
|
|
10
19
|
const styles = (theme) => ({
|
|
20
|
+
inputStudent: {
|
|
21
|
+
...inputStyles(theme),
|
|
22
|
+
padding: '0',
|
|
23
|
+
border: 'none',
|
|
24
|
+
color: 'inherit',
|
|
25
|
+
fontWeight: 'bold',
|
|
26
|
+
},
|
|
11
27
|
input: {
|
|
12
28
|
float: 'right',
|
|
13
29
|
padding: theme.spacing.unit * 0.5,
|
|
14
30
|
fontFamily: theme.typography.fontFamily,
|
|
15
|
-
fontSize:
|
|
16
|
-
border: `solid 1px ${color.
|
|
31
|
+
fontSize: '10px',
|
|
32
|
+
border: `solid 1px ${color.defaults.SECONDARY}`,
|
|
17
33
|
borderRadius: '3px',
|
|
18
|
-
color: color.
|
|
34
|
+
color: color.defaults.PRIMARY_DARK,
|
|
35
|
+
backgroundColor: color.defaults.WHITE,
|
|
19
36
|
},
|
|
20
37
|
disabled: {
|
|
21
|
-
border: `solid 1px ${color.
|
|
22
|
-
|
|
38
|
+
border: `solid 1px ${color.defaults.PRIMARY_DARK}`,
|
|
39
|
+
backgroundColor: color.defaults.WHITE,
|
|
40
|
+
'-webkit-opacity': '1',
|
|
23
41
|
},
|
|
24
42
|
disabledMark: {
|
|
25
43
|
border: `solid 1px ${color.disabled()}`,
|
|
26
|
-
background: theme.palette.background.paper,
|
|
27
44
|
color: color.disabled(),
|
|
45
|
+
'-webkit-text-fill-color': color.disabled(),
|
|
46
|
+
},
|
|
47
|
+
inputCorrect: {
|
|
48
|
+
...inputStyles(theme),
|
|
49
|
+
color: color.defaults.CORRECT_WITH_ICON,
|
|
50
|
+
border: `solid 1px ${color.defaults.CORRECT_WITH_ICON}`,
|
|
51
|
+
},
|
|
52
|
+
inputIncorrect: {
|
|
53
|
+
...inputStyles(theme),
|
|
54
|
+
color: color.defaults.INCORRECT_WITH_ICON,
|
|
55
|
+
border: `solid 1px ${color.defaults.INCORRECT_WITH_ICON}`,
|
|
56
|
+
},
|
|
57
|
+
inputMissing: {
|
|
58
|
+
...inputStyles(theme),
|
|
59
|
+
color: color.defaults.MISSING_WITH_ICON,
|
|
60
|
+
border: `solid 1px ${color.defaults.MISSING_WITH_ICON}`,
|
|
61
|
+
fontWeight: 'bold',
|
|
62
|
+
},
|
|
63
|
+
incorrect: {
|
|
64
|
+
...inputStyles(theme),
|
|
65
|
+
color: color.defaults.INCORRECT_WITH_ICON,
|
|
66
|
+
fontWeight: 'bold',
|
|
67
|
+
padding: '0',
|
|
28
68
|
},
|
|
29
69
|
});
|
|
30
70
|
|
|
31
|
-
export const position = (graphProps, mark, rect) => {
|
|
32
|
-
rect = rect || { width: 0, height: 0 };
|
|
71
|
+
export const position = (graphProps, mark, rect = { width: 0, height: 0 }) => {
|
|
33
72
|
const { scale, domain, range } = graphProps;
|
|
34
|
-
const shift =
|
|
73
|
+
const shift = 5;
|
|
35
74
|
|
|
36
75
|
const rightEdge = scale.x(mark.x) + rect.width + shift;
|
|
37
76
|
const bottomEdge = scale.y(mark.y) + rect.height + shift;
|
|
@@ -42,40 +81,37 @@ export const position = (graphProps, mark, rect) => {
|
|
|
42
81
|
return `${v}-${h}`;
|
|
43
82
|
};
|
|
44
83
|
|
|
45
|
-
export const coordinates = (graphProps, mark, rect,
|
|
84
|
+
export const coordinates = (graphProps, mark, rect = { width: 0, height: 0 }, position) => {
|
|
46
85
|
const { scale } = graphProps;
|
|
47
|
-
const shift =
|
|
48
|
-
const font = fontSize ? fontSize : 16;
|
|
49
|
-
rect = rect || { width: 0, height: 0 };
|
|
86
|
+
const shift = 5;
|
|
50
87
|
|
|
51
88
|
switch (position) {
|
|
52
|
-
case 'bottom-right':
|
|
53
|
-
return { left:
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
case '
|
|
57
|
-
return {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
case 'top-left': {
|
|
64
|
-
return {
|
|
65
|
-
left: `${(scale.x(mark.x) - shift - rect.width) / font}rem`,
|
|
66
|
-
top: `${(scale.y(mark.y) - shift - rect.height) / font}rem`,
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
case 'top-right': {
|
|
71
|
-
return {
|
|
72
|
-
left: `${(scale.x(mark.x) + shift) / font}rem`,
|
|
73
|
-
top: `${(scale.y(mark.y) - shift - rect.height) / font}rem`,
|
|
74
|
-
};
|
|
75
|
-
}
|
|
89
|
+
case 'bottom-right':
|
|
90
|
+
return { left: scale.x(mark.x) + shift, top: scale.y(mark.y) + shift };
|
|
91
|
+
case 'bottom-left':
|
|
92
|
+
return { left: scale.x(mark.x) - shift - rect.width, top: scale.y(mark.y) + shift };
|
|
93
|
+
case 'top-left':
|
|
94
|
+
return { left: scale.x(mark.x) - shift - rect.width, top: scale.y(mark.y) - shift - rect.height };
|
|
95
|
+
case 'top-right':
|
|
96
|
+
return { left: scale.x(mark.x) + shift, top: scale.y(mark.y) - shift - rect.height };
|
|
97
|
+
default:
|
|
98
|
+
return {};
|
|
76
99
|
}
|
|
77
100
|
};
|
|
78
101
|
|
|
102
|
+
const LabelInput = ({ _ref, externalInputRef, label, disabled, inputClassName, onChange }) => (
|
|
103
|
+
<AutosizeInput
|
|
104
|
+
inputRef={(r) => {
|
|
105
|
+
_ref(r);
|
|
106
|
+
externalInputRef(r);
|
|
107
|
+
}}
|
|
108
|
+
disabled={disabled}
|
|
109
|
+
inputClassName={inputClassName}
|
|
110
|
+
value={label}
|
|
111
|
+
onChange={onChange}
|
|
112
|
+
/>
|
|
113
|
+
);
|
|
114
|
+
|
|
79
115
|
export const MarkLabel = (props) => {
|
|
80
116
|
const [input, setInput] = useState(null);
|
|
81
117
|
const _ref = useCallback((node) => setInput(node));
|
|
@@ -83,7 +119,7 @@ export const MarkLabel = (props) => {
|
|
|
83
119
|
const { mark, graphProps, classes, disabled, inputRef: externalInputRef, theme } = props;
|
|
84
120
|
|
|
85
121
|
const [label, setLabel] = useState(mark.label);
|
|
86
|
-
|
|
122
|
+
const { correctness, correctnesslabel, correctlabel } = mark;
|
|
87
123
|
const onChange = (e) => setLabel(e.target.value);
|
|
88
124
|
|
|
89
125
|
const debouncedLabel = useDebounce(label, 200);
|
|
@@ -100,35 +136,96 @@ export const MarkLabel = (props) => {
|
|
|
100
136
|
}
|
|
101
137
|
}, [debouncedLabel]);
|
|
102
138
|
|
|
103
|
-
const fontSize = theme && theme.typography ? theme.typography.fontSize + 2 : 16;
|
|
104
139
|
const rect = input ? input.getBoundingClientRect() : { width: 0, height: 0 };
|
|
105
140
|
const pos = position(graphProps, mark, rect);
|
|
106
|
-
const leftTop = coordinates(graphProps, mark, rect, pos
|
|
141
|
+
const leftTop = coordinates(graphProps, mark, rect, pos);
|
|
107
142
|
|
|
108
143
|
const style = {
|
|
109
144
|
position: 'fixed',
|
|
110
145
|
pointerEvents: 'auto',
|
|
146
|
+
display: 'flex',
|
|
147
|
+
alignItems: 'center',
|
|
148
|
+
gap: '3px',
|
|
111
149
|
...leftTop,
|
|
112
150
|
};
|
|
113
151
|
|
|
152
|
+
const secondLabelStyle = {
|
|
153
|
+
...style,
|
|
154
|
+
top: leftTop.top + 25,
|
|
155
|
+
};
|
|
156
|
+
|
|
114
157
|
const disabledInput = disabled || mark.disabled;
|
|
115
158
|
|
|
116
|
-
|
|
117
|
-
<
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
}}
|
|
159
|
+
const renderInput = (inputClass, labelValue) => (
|
|
160
|
+
<LabelInput
|
|
161
|
+
_ref={_ref}
|
|
162
|
+
externalInputRef={externalInputRef}
|
|
163
|
+
label={labelValue}
|
|
122
164
|
disabled={disabledInput}
|
|
123
|
-
inputClassName={cn(
|
|
124
|
-
[classes.disabled]: disabled,
|
|
125
|
-
[classes.disabledMark]: mark.disabled,
|
|
126
|
-
})}
|
|
127
|
-
value={label}
|
|
128
|
-
style={style}
|
|
165
|
+
inputClassName={cn(inputClass)}
|
|
129
166
|
onChange={onChange}
|
|
130
167
|
/>
|
|
131
168
|
);
|
|
169
|
+
|
|
170
|
+
if (correctness === 'correct' && correctnesslabel === 'correct' && correctlabel) {
|
|
171
|
+
return (
|
|
172
|
+
<div className={classes.inputCorrect} style={style}>
|
|
173
|
+
<SvgIcon type="correct" />
|
|
174
|
+
{renderInput(classes.inputStudent, correctlabel)}
|
|
175
|
+
</div>
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// avoid rendering empty label when a correct point without label was provided
|
|
180
|
+
if (correctness === 'correct' && correctnesslabel === 'correct' && !correctlabel) {
|
|
181
|
+
return null;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
if (correctness === 'correct' && correctnesslabel === 'incorrect') {
|
|
185
|
+
return (
|
|
186
|
+
<>
|
|
187
|
+
<div className={classes.inputIncorrect} style={style}>
|
|
188
|
+
<SvgIcon type="incorrect" />
|
|
189
|
+
{label === '' ? (
|
|
190
|
+
<SvgIcon type="empty" style={{ marginLeft: '3px' }} />
|
|
191
|
+
) : (
|
|
192
|
+
renderInput(classes.inputStudent, label)
|
|
193
|
+
)}
|
|
194
|
+
</div>
|
|
195
|
+
<div className={classes.inputMissing} style={secondLabelStyle}>
|
|
196
|
+
{renderInput(classes.inputStudent, correctlabel)}
|
|
197
|
+
</div>
|
|
198
|
+
</>
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
if (correctness === 'missing') {
|
|
203
|
+
return (
|
|
204
|
+
<div className={classes.inputMissing} style={style}>
|
|
205
|
+
{renderInput(classes.inputStudent, label)}
|
|
206
|
+
</div>
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
if (correctness === 'incorrect') {
|
|
211
|
+
return (
|
|
212
|
+
<div className={classes.incorrect} style={style}>
|
|
213
|
+
{renderInput(classes.inputStudent, label)}
|
|
214
|
+
</div>
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
return (
|
|
219
|
+
<div style={style}>
|
|
220
|
+
{renderInput(
|
|
221
|
+
cn(classes.input, {
|
|
222
|
+
[classes.disabled]: disabled,
|
|
223
|
+
[classes.disabledMark]: mark.disabled,
|
|
224
|
+
}),
|
|
225
|
+
label,
|
|
226
|
+
)}
|
|
227
|
+
</div>
|
|
228
|
+
);
|
|
132
229
|
};
|
|
133
230
|
|
|
134
231
|
MarkLabel.propTypes = {
|
package/src/toggle-bar.jsx
CHANGED
|
@@ -4,7 +4,7 @@ import { withStyles } from '@material-ui/core/styles';
|
|
|
4
4
|
import cn from 'classnames';
|
|
5
5
|
import Button from '@material-ui/core/Button';
|
|
6
6
|
import { color } from '@pie-lib/render-ui';
|
|
7
|
-
import { allTools } from './tools
|
|
7
|
+
import { allTools } from './tools';
|
|
8
8
|
import { withDragContext, DragSource, DropTarget } from '@pie-lib/drag';
|
|
9
9
|
import Translator from '@pie-lib/translator';
|
|
10
10
|
|
|
@@ -135,7 +135,6 @@ const styles = (theme) => ({
|
|
|
135
135
|
marginRight: theme.spacing.unit / 2,
|
|
136
136
|
marginBottom: theme.spacing.unit / 2,
|
|
137
137
|
color: color.text(),
|
|
138
|
-
backgroundColor: color.background(),
|
|
139
138
|
},
|
|
140
139
|
under: {
|
|
141
140
|
position: 'absolute',
|
package/src/tool-menu.jsx
CHANGED
|
@@ -12,7 +12,6 @@ export class ToolMenu extends React.Component {
|
|
|
12
12
|
draggableTools: PropTypes.bool,
|
|
13
13
|
labelModeEnabled: PropTypes.bool,
|
|
14
14
|
onChange: PropTypes.func,
|
|
15
|
-
onToggleLabelMode: PropTypes.func,
|
|
16
15
|
onChangeTools: PropTypes.func,
|
|
17
16
|
toolbarTools: PropTypes.arrayOf(PropTypes.string),
|
|
18
17
|
language: PropTypes.string,
|
|
@@ -22,33 +21,15 @@ export class ToolMenu extends React.Component {
|
|
|
22
21
|
toolbarTools: [],
|
|
23
22
|
};
|
|
24
23
|
|
|
25
|
-
updateToolsOrder = (tools
|
|
24
|
+
updateToolsOrder = (tools) => {
|
|
26
25
|
const { onChangeTools } = this.props;
|
|
27
|
-
|
|
28
|
-
if (showLabel) {
|
|
29
|
-
tools.push('label');
|
|
30
|
-
}
|
|
31
|
-
|
|
32
26
|
onChangeTools(tools);
|
|
33
27
|
};
|
|
34
28
|
|
|
35
29
|
render() {
|
|
36
|
-
const {
|
|
37
|
-
className,
|
|
38
|
-
currentToolType,
|
|
39
|
-
disabled,
|
|
40
|
-
draggableTools,
|
|
41
|
-
labelModeEnabled,
|
|
42
|
-
onToggleLabelMode,
|
|
43
|
-
onChange,
|
|
44
|
-
language
|
|
45
|
-
} = this.props;
|
|
30
|
+
const { className, currentToolType, disabled, draggableTools, onChange, language } = this.props;
|
|
46
31
|
let { toolbarTools } = this.props;
|
|
47
32
|
|
|
48
|
-
const showLabel = toolbarTools && toolbarTools.some((t) => t === 'label');
|
|
49
|
-
|
|
50
|
-
toolbarTools = (toolbarTools || []).filter((tT) => tT !== 'label');
|
|
51
|
-
|
|
52
33
|
return (
|
|
53
34
|
<div className={classNames(className)}>
|
|
54
35
|
<ToggleBar
|
|
@@ -57,13 +38,9 @@ export class ToolMenu extends React.Component {
|
|
|
57
38
|
options={toolbarTools}
|
|
58
39
|
selectedToolType={currentToolType}
|
|
59
40
|
onChange={onChange}
|
|
60
|
-
onChangeToolsOrder={(tools) => this.updateToolsOrder(tools
|
|
41
|
+
onChangeToolsOrder={(tools) => this.updateToolsOrder(tools)}
|
|
61
42
|
language={language}
|
|
62
43
|
/>
|
|
63
|
-
|
|
64
|
-
{showLabel && (
|
|
65
|
-
<MiniButton disabled={disabled} value={'Label'} onClick={onToggleLabelMode} selected={labelModeEnabled} language={language} />
|
|
66
|
-
)}
|
|
67
44
|
</div>
|
|
68
45
|
);
|
|
69
46
|
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { withRootEdge } from '../../shared/line/with-root-edge';
|
|
3
|
+
import { buildDataPoints, absoluteFromTwoPoints } from '@pie-lib/graphing-utils';
|
|
4
|
+
import { utils } from '@pie-lib/plot';
|
|
5
|
+
|
|
6
|
+
import { graphProps as getGraphProps } from '../../../__tests__/utils';
|
|
7
|
+
|
|
8
|
+
const { xy } = utils;
|
|
9
|
+
|
|
10
|
+
jest.mock('@pie-lib/graphing-utils', () => ({
|
|
11
|
+
buildDataPoints: jest.fn().mockReturnValue([]),
|
|
12
|
+
absoluteFromTwoPoints: jest.fn(() => jest.fn()),
|
|
13
|
+
getAmplitudeAndFreq: jest.fn().mockReturnValue({ freq: 4, amplitude: 1 }),
|
|
14
|
+
}));
|
|
15
|
+
|
|
16
|
+
jest.mock('../../shared/line/with-root-edge', () => ({
|
|
17
|
+
withRootEdge: jest.fn(),
|
|
18
|
+
rootEdgeComponent: jest.fn(),
|
|
19
|
+
}));
|
|
20
|
+
|
|
21
|
+
describe('Absolute', () => {
|
|
22
|
+
let fnBody;
|
|
23
|
+
let graphProps;
|
|
24
|
+
let root;
|
|
25
|
+
let edge;
|
|
26
|
+
let result;
|
|
27
|
+
|
|
28
|
+
beforeEach(() => {
|
|
29
|
+
require('../component');
|
|
30
|
+
fnBody = withRootEdge.mock.calls[0][0];
|
|
31
|
+
graphProps = getGraphProps();
|
|
32
|
+
root = xy(0, 0);
|
|
33
|
+
edge = xy(1, 1);
|
|
34
|
+
|
|
35
|
+
result = fnBody({ graphProps, root, edge });
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('fnBody is not null', () => {
|
|
39
|
+
expect(fnBody).toBeDefined();
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('calls buildDataPoints', () => {
|
|
43
|
+
const { domain, range } = graphProps;
|
|
44
|
+
expect(buildDataPoints).toHaveBeenCalledWith(domain, range, root, edge, expect.anything(), true);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('calls absoluteFromTwoPoints', () => {
|
|
48
|
+
expect(absoluteFromTwoPoints).toHaveBeenCalledWith(root, edge);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('returns dataPoints', () => {
|
|
52
|
+
expect(result).toEqual({ enableCurve: false, root, edge, dataPoints: [] });
|
|
53
|
+
});
|
|
54
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import debug from 'debug';
|
|
2
|
+
import { buildDataPoints, absoluteFromTwoPoints } from '@pie-lib/graphing-utils';
|
|
3
|
+
import { withRootEdge, rootEdgeComponent } from '../shared/line/with-root-edge';
|
|
4
|
+
|
|
5
|
+
const log = debug('pie-lib:graphing:absolute');
|
|
6
|
+
|
|
7
|
+
const Absolute = withRootEdge((props) => {
|
|
8
|
+
const { root, edge, graphProps } = props;
|
|
9
|
+
const { domain, range } = graphProps;
|
|
10
|
+
|
|
11
|
+
const dataPoints =
|
|
12
|
+
edge && edge.x === root.x
|
|
13
|
+
? []
|
|
14
|
+
: buildDataPoints(domain, range, root, edge, absoluteFromTwoPoints(root, edge), true);
|
|
15
|
+
|
|
16
|
+
log('dataPoints:', dataPoints);
|
|
17
|
+
|
|
18
|
+
return { root: props.root, edge: props.edge, dataPoints, enableCurve: false };
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
const Component = rootEdgeComponent(Absolute);
|
|
22
|
+
|
|
23
|
+
export default Component;
|
|
@@ -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
|
+
`;
|