@pie-lib/graphing 2.14.22-next.0 → 2.15.0-beta.1

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.
Files changed (193) hide show
  1. package/CHANGELOG.md +16 -75
  2. package/NEXT.CHANGELOG.json +1 -0
  3. package/lib/axis/axes.js +5 -5
  4. package/lib/axis/axes.js.map +1 -1
  5. package/lib/container/index.js +1 -4
  6. package/lib/container/index.js.map +1 -1
  7. package/lib/coordinates-label.js +5 -3
  8. package/lib/coordinates-label.js.map +1 -1
  9. package/lib/graph-with-controls.js +8 -15
  10. package/lib/graph-with-controls.js.map +1 -1
  11. package/lib/graph.js +29 -12
  12. package/lib/graph.js.map +1 -1
  13. package/lib/grid.js +6 -14
  14. package/lib/grid.js.map +1 -1
  15. package/lib/index.js +8 -0
  16. package/lib/index.js.map +1 -1
  17. package/lib/key-legend.js +246 -0
  18. package/lib/key-legend.js.map +1 -0
  19. package/lib/label-svg-icon.js +56 -0
  20. package/lib/label-svg-icon.js.map +1 -0
  21. package/lib/labels.js +2 -1
  22. package/lib/labels.js.map +1 -1
  23. package/lib/mark-label.js +167 -56
  24. package/lib/mark-label.js.map +1 -1
  25. package/lib/toggle-bar.js +3 -4
  26. package/lib/toggle-bar.js.map +1 -1
  27. package/lib/tool-menu.js +2 -22
  28. package/lib/tool-menu.js.map +1 -1
  29. package/lib/tools/absolute/component.js +35 -0
  30. package/lib/tools/absolute/component.js.map +1 -0
  31. package/lib/tools/absolute/index.js +63 -0
  32. package/lib/tools/absolute/index.js.map +1 -0
  33. package/lib/tools/circle/bg-circle.js +4 -3
  34. package/lib/tools/circle/bg-circle.js.map +1 -1
  35. package/lib/tools/circle/component.js +34 -15
  36. package/lib/tools/circle/component.js.map +1 -1
  37. package/lib/tools/exponential/component.js +34 -0
  38. package/lib/tools/exponential/component.js.map +1 -0
  39. package/lib/tools/exponential/index.js +71 -0
  40. package/lib/tools/exponential/index.js.map +1 -0
  41. package/lib/tools/index.js +26 -6
  42. package/lib/tools/index.js.map +1 -1
  43. package/lib/tools/line/component.js +2 -1
  44. package/lib/tools/line/component.js.map +1 -1
  45. package/lib/tools/parabola/component.js +6 -5
  46. package/lib/tools/parabola/component.js.map +1 -1
  47. package/lib/tools/point/component.js +14 -9
  48. package/lib/tools/point/component.js.map +1 -1
  49. package/lib/tools/polygon/component.js +25 -12
  50. package/lib/tools/polygon/component.js.map +1 -1
  51. package/lib/tools/polygon/line.js +12 -6
  52. package/lib/tools/polygon/line.js.map +1 -1
  53. package/lib/tools/polygon/polygon.js +6 -3
  54. package/lib/tools/polygon/polygon.js.map +1 -1
  55. package/lib/tools/ray/component.js +2 -1
  56. package/lib/tools/ray/component.js.map +1 -1
  57. package/lib/tools/segment/component.js +2 -1
  58. package/lib/tools/segment/component.js.map +1 -1
  59. package/lib/tools/shared/icons/CorrectSVG.js +36 -0
  60. package/lib/tools/shared/icons/CorrectSVG.js.map +1 -0
  61. package/lib/tools/shared/icons/IncorrectSVG.js +36 -0
  62. package/lib/tools/shared/icons/IncorrectSVG.js.map +1 -0
  63. package/lib/tools/shared/icons/MissingSVG.js +35 -0
  64. package/lib/tools/shared/icons/MissingSVG.js.map +1 -0
  65. package/lib/tools/shared/line/index.js +51 -19
  66. package/lib/tools/shared/line/index.js.map +1 -1
  67. package/lib/tools/shared/line/line-path.js +13 -7
  68. package/lib/tools/shared/line/line-path.js.map +1 -1
  69. package/lib/tools/shared/line/with-root-edge.js +19 -8
  70. package/lib/tools/shared/line/with-root-edge.js.map +1 -1
  71. package/lib/tools/shared/point/arrow-point.js +1 -1
  72. package/lib/tools/shared/point/arrow-point.js.map +1 -1
  73. package/lib/tools/shared/point/arrow.js +1 -1
  74. package/lib/tools/shared/point/arrow.js.map +1 -1
  75. package/lib/tools/shared/point/base-point.js +43 -7
  76. package/lib/tools/shared/point/base-point.js.map +1 -1
  77. package/lib/tools/shared/point/index.js +4 -1
  78. package/lib/tools/shared/point/index.js.map +1 -1
  79. package/lib/tools/shared/styles.js +16 -7
  80. package/lib/tools/shared/styles.js.map +1 -1
  81. package/lib/tools/sine/component.js +13 -4
  82. package/lib/tools/sine/component.js.map +1 -1
  83. package/lib/tools/vector/component.js +2 -1
  84. package/lib/tools/vector/component.js.map +1 -1
  85. package/lib/undo-redo.js +0 -1
  86. package/lib/undo-redo.js.map +1 -1
  87. package/lib/utils.js +1 -1
  88. package/lib/utils.js.map +1 -1
  89. package/package.json +15 -9
  90. package/src/__tests__/__snapshots__/graph-with-controls.test.jsx.snap +237 -0
  91. package/src/__tests__/__snapshots__/graph.test.jsx.snap +211 -0
  92. package/src/__tests__/__snapshots__/grid.test.jsx.snap +54 -0
  93. package/src/__tests__/__snapshots__/labels.test.jsx.snap +30 -0
  94. package/src/__tests__/__snapshots__/mark-label.test.jsx.snap +45 -0
  95. package/src/__tests__/__snapshots__/toggle-bar.test.jsx.snap +7 -0
  96. package/src/__tests__/__snapshots__/tool-menu.test.jsx.snap +13 -0
  97. package/src/__tests__/__snapshots__/undo-redo.test.jsx.snap +14 -0
  98. package/src/__tests__/graph-with-controls.test.jsx +147 -0
  99. package/src/__tests__/graph.test.jsx +230 -0
  100. package/src/__tests__/grid.test.jsx +20 -0
  101. package/src/__tests__/labels.test.jsx +38 -0
  102. package/src/__tests__/mark-label.test.jsx +68 -0
  103. package/src/__tests__/toggle-bar.test.jsx +36 -0
  104. package/src/__tests__/tool-menu.test.jsx +29 -0
  105. package/src/__tests__/undo-redo.test.jsx +25 -0
  106. package/src/__tests__/use-debounce.test.js +21 -0
  107. package/src/__tests__/utils.js +38 -0
  108. package/src/__tests__/utils.test.js +151 -0
  109. package/src/axis/__tests__/__snapshots__/arrow.test.jsx.snap +33 -0
  110. package/src/axis/__tests__/__snapshots__/axes.test.jsx.snap +122 -0
  111. package/src/axis/__tests__/arrow.test.jsx +39 -0
  112. package/src/axis/__tests__/axes.test.jsx +220 -0
  113. package/src/axis/axes.jsx +5 -5
  114. package/src/container/index.jsx +2 -4
  115. package/src/coordinates-label.jsx +4 -3
  116. package/src/graph-with-controls.jsx +8 -10
  117. package/src/graph.jsx +22 -10
  118. package/src/grid.jsx +8 -10
  119. package/src/index.js +2 -2
  120. package/src/key-legend.jsx +145 -0
  121. package/src/label-svg-icon.jsx +39 -0
  122. package/src/labels.jsx +2 -1
  123. package/src/mark-label.jsx +149 -52
  124. package/src/toggle-bar.jsx +1 -2
  125. package/src/tool-menu.jsx +3 -26
  126. package/src/tools/absolute/__tests__/component.test.jsx +54 -0
  127. package/src/tools/absolute/component.jsx +23 -0
  128. package/src/tools/absolute/index.js +31 -0
  129. package/src/tools/circle/__tests__/__snapshots__/bg-circle.test.jsx.snap +46 -0
  130. package/src/tools/circle/__tests__/__snapshots__/component.test.jsx.snap +293 -0
  131. package/src/tools/circle/__tests__/bg-circle.test.jsx +28 -0
  132. package/src/tools/circle/__tests__/component.test.jsx +228 -0
  133. package/src/tools/circle/bg-circle.jsx +5 -4
  134. package/src/tools/circle/component.jsx +22 -8
  135. package/src/tools/exponential/__tests__/component.test.jsx +54 -0
  136. package/src/tools/exponential/component.jsx +23 -0
  137. package/src/tools/exponential/index.js +39 -0
  138. package/src/tools/index.js +38 -5
  139. package/src/tools/line/__tests__/__snapshots__/component.test.jsx.snap +20 -0
  140. package/src/tools/line/__tests__/component.test.jsx +36 -0
  141. package/src/tools/line/component.jsx +2 -1
  142. package/src/tools/parabola/__tests__/component.test.jsx +49 -0
  143. package/src/tools/parabola/component.jsx +7 -6
  144. package/src/tools/point/__tests__/__snapshots__/component.test.jsx.snap +40 -0
  145. package/src/tools/point/__tests__/component.test.jsx +66 -0
  146. package/src/tools/point/component.jsx +12 -6
  147. package/src/tools/polygon/__tests__/__snapshots__/component.test.jsx.snap +415 -0
  148. package/src/tools/polygon/__tests__/__snapshots__/line.test.jsx.snap +45 -0
  149. package/src/tools/polygon/__tests__/__snapshots__/polygon.test.jsx.snap +52 -0
  150. package/src/tools/polygon/__tests__/component.test.jsx +226 -0
  151. package/src/tools/polygon/__tests__/index.test.js +65 -0
  152. package/src/tools/polygon/__tests__/line.test.jsx +25 -0
  153. package/src/tools/polygon/__tests__/polygon.test.jsx +44 -0
  154. package/src/tools/polygon/component.jsx +39 -11
  155. package/src/tools/polygon/line.jsx +15 -7
  156. package/src/tools/polygon/polygon.jsx +7 -3
  157. package/src/tools/ray/__tests__/__snapshots__/component.test.jsx.snap +23 -0
  158. package/src/tools/ray/__tests__/component.test.jsx +29 -0
  159. package/src/tools/ray/component.jsx +2 -1
  160. package/src/tools/segment/__tests__/__snapshots__/component.test.jsx.snap +14 -0
  161. package/src/tools/segment/__tests__/component.test.jsx +28 -0
  162. package/src/tools/segment/component.jsx +2 -1
  163. package/src/tools/shared/__tests__/__snapshots__/arrow-head.test.jsx.snap +27 -0
  164. package/src/tools/shared/__tests__/arrow-head.test.jsx +34 -0
  165. package/src/tools/shared/icons/CorrectSVG.jsx +22 -0
  166. package/src/tools/shared/icons/IncorrectSVG.jsx +20 -0
  167. package/src/tools/shared/icons/MissingSVG.jsx +21 -0
  168. package/src/tools/shared/line/__tests__/__snapshots__/index.test.jsx.snap +360 -0
  169. package/src/tools/shared/line/__tests__/__snapshots__/line-path.test.jsx.snap +58 -0
  170. package/src/tools/shared/line/__tests__/__snapshots__/with-root-edge.test.jsx.snap +63 -0
  171. package/src/tools/shared/line/__tests__/index.test.jsx +255 -0
  172. package/src/tools/shared/line/__tests__/line-path.test.jsx +53 -0
  173. package/src/tools/shared/line/__tests__/with-root-edge.test.jsx +73 -0
  174. package/src/tools/shared/line/index.jsx +39 -13
  175. package/src/tools/shared/line/line-path.jsx +18 -7
  176. package/src/tools/shared/line/with-root-edge.jsx +10 -3
  177. package/src/tools/shared/point/__tests__/__snapshots__/arrow-point.test.jsx.snap +56 -0
  178. package/src/tools/shared/point/__tests__/__snapshots__/base-point.test.jsx.snap +44 -0
  179. package/src/tools/shared/point/__tests__/arrow-point.test.jsx +87 -0
  180. package/src/tools/shared/point/__tests__/base-point.test.jsx +84 -0
  181. package/src/tools/shared/point/arrow-point.jsx +4 -1
  182. package/src/tools/shared/point/arrow.jsx +4 -1
  183. package/src/tools/shared/point/base-point.jsx +28 -3
  184. package/src/tools/shared/point/index.jsx +7 -2
  185. package/src/tools/shared/styles.js +8 -3
  186. package/src/tools/sine/__tests__/component.test.jsx +51 -0
  187. package/src/tools/sine/component.jsx +7 -7
  188. package/src/tools/vector/__tests__/__snapshots__/component.test.jsx.snap +12 -0
  189. package/src/tools/vector/__tests__/component.test.jsx +26 -0
  190. package/src/tools/vector/component.jsx +2 -1
  191. package/src/undo-redo.jsx +0 -1
  192. package/src/utils.js +1 -1
  193. package/legacy.png +0 -0
@@ -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: theme.typography.fontSize,
16
- border: `solid 1px ${color.secondary()}`,
31
+ fontSize: '10px',
32
+ border: `solid 1px ${color.defaults.SECONDARY}`,
17
33
  borderRadius: '3px',
18
- color: color.primaryDark(),
34
+ color: color.defaults.PRIMARY_DARK,
35
+ backgroundColor: color.defaults.WHITE,
19
36
  },
20
37
  disabled: {
21
- border: `solid 1px ${color.primaryDark()}`,
22
- background: theme.palette.background.paper,
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 = 10;
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, position, fontSize) => {
84
+ export const coordinates = (graphProps, mark, rect = { width: 0, height: 0 }, position) => {
46
85
  const { scale } = graphProps;
47
- const shift = 10;
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: `${(scale.x(mark.x) + shift) / font}rem`, top: `${(scale.y(mark.y) + shift) / font}rem` };
54
- }
55
-
56
- case 'bottom-left': {
57
- return {
58
- left: `${(scale.x(mark.x) - shift - rect.width) / font}rem`,
59
- top: `${(scale.y(mark.y) + shift) / font}rem`,
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, fontSize);
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
- return (
117
- <AutosizeInput
118
- inputRef={(r) => {
119
- _ref(r);
120
- externalInputRef(r);
121
- }}
159
+ const renderInput = (inputClass, labelValue) => (
160
+ <LabelInput
161
+ _ref={_ref}
162
+ externalInputRef={externalInputRef}
163
+ label={labelValue}
122
164
  disabled={disabledInput}
123
- inputClassName={cn(classes.input, {
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 = {
@@ -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/index';
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, showLabel) => {
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, showLabel)}
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
+ `;