@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
@@ -0,0 +1,226 @@
1
+ import { shallow } from 'enzyme';
2
+ import React from 'react';
3
+ import { graphProps, xy } from '../../../__tests__/utils';
4
+
5
+ import { RawBaseComponent, buildLines, swap } from '../component';
6
+
7
+ const xyLabel = (x, y, index, label) => ({
8
+ ...xy(x, y, index),
9
+ label,
10
+ });
11
+
12
+ describe('buildLines', () => {
13
+ const defaultPoints = [xy(0, 0), xy(1, 1), xy(1, 0)];
14
+
15
+ const assertBuildLines = (points, closed, expected) => {
16
+ it(`builds points and lines for ${points} = ${expected}`, () => {
17
+ const result = buildLines(points);
18
+ expect(result).toMatchObject([
19
+ { from: xy(0, 0, 0), to: xy(1, 1, 1) },
20
+ { from: xy(1, 1, 1), to: xy(1, 0, 2) },
21
+ ]);
22
+ });
23
+ };
24
+
25
+ assertBuildLines(defaultPoints, true, []);
26
+ });
27
+
28
+ describe('swap', () => {
29
+ it('swaps pairs', () => {
30
+ const result = swap([xy(0, 0, 0), xy(1, 1, 1), xy(2, 2, 2)], xy(0, 0, 0), xy(3, 3, 0));
31
+ expect(result).toEqual([xy(3, 3, 0), xy(1, 1, 1), xy(2, 2, 2)]);
32
+ });
33
+ });
34
+
35
+ describe('RawBaseComponent', () => {
36
+ let w;
37
+ let onChange = jest.fn();
38
+ let onChangeProps = jest.fn();
39
+ const wrapper = (extras) => {
40
+ const defaults = {
41
+ classes: {},
42
+ className: 'className',
43
+ onChange,
44
+ onChangeProps,
45
+ onClosePolygon: jest.fn(),
46
+ graphProps: graphProps(),
47
+ points: [],
48
+ };
49
+ const props = { ...defaults, ...extras };
50
+
51
+ return shallow(<RawBaseComponent {...props} />);
52
+ };
53
+
54
+ // used to test items that have labels attached to points
55
+ const labelNode = document.createElement('foreignObject');
56
+ const points = [xyLabel(0, 0, 0, 'A'), xyLabel(2, 2, 1, 'B'), xyLabel(0, 2, 2, 'C')];
57
+ const wrapperWithLabels = (extras) =>
58
+ wrapper({
59
+ labelNode: labelNode,
60
+ points: points,
61
+ ...extras,
62
+ });
63
+
64
+ describe('snapshot', () => {
65
+ it('renders', () => {
66
+ w = wrapper();
67
+ expect(w).toMatchSnapshot();
68
+ });
69
+
70
+ it('renders with labels', () => {
71
+ w = wrapperWithLabels();
72
+ expect(w).toMatchSnapshot();
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('adds "label" property to a point when limit labeling', () => {
207
+ const onChangeProps = jest.fn();
208
+ const w = wrapperWithLabels({
209
+ labelModeEnabled: true,
210
+ onChangeProps,
211
+ limitLabeling: true,
212
+ });
213
+
214
+ w.instance().clickPoint(xy(0, 0, 0), 0, {});
215
+ expect(onChangeProps).toHaveBeenCalledTimes(0);
216
+ });
217
+
218
+ it('if point already has label, keeps that value', () => {
219
+ const onChangeProps = jest.fn();
220
+ const w = wrapperWithLabels({ labelModeEnabled: true, onChangeProps });
221
+
222
+ w.instance().clickPoint(points[0], 0, {});
223
+ expect(onChangeProps).toHaveBeenCalledWith(points);
224
+ });
225
+ });
226
+ });
@@ -0,0 +1,65 @@
1
+ import { addPointToArray, tool } from '../index';
2
+
3
+ const xy = (x, y) => ({ x, y });
4
+
5
+ describe('polygon', () => {
6
+ describe('addPointToArray', () => {
7
+ const assertAddPoint = (point, arr, expected) => {
8
+ it(`returns ${expected} when adding ${point} to ${arr}`, () => {
9
+ const result = addPointToArray(point, arr);
10
+ expect(result).toEqual(expected);
11
+ });
12
+ };
13
+ assertAddPoint(xy(0, 0), [], { closed: false, points: [xy(0, 0)] });
14
+ assertAddPoint(xy(0, 0), [xy(0, 0)], { closed: false, points: [xy(0, 0)] });
15
+ assertAddPoint(xy(1, 1), [xy(0, 0)], {
16
+ closed: false,
17
+ points: [xy(0, 0), xy(1, 1)],
18
+ });
19
+ assertAddPoint(xy(1, 1), [xy(0, 0)], {
20
+ closed: false,
21
+ points: [xy(0, 0), xy(1, 1)],
22
+ });
23
+ });
24
+ });
25
+
26
+ describe('tool', () => {
27
+ let t;
28
+ beforeEach(() => {
29
+ t = tool();
30
+ });
31
+
32
+ it('creates polygon type', () => {
33
+ expect(t.type).toEqual('polygon');
34
+ });
35
+
36
+ describe('complete', () => {
37
+ it('closes polygon', () => {
38
+ expect(t.complete()).toEqual({ building: false, closed: true });
39
+ });
40
+ });
41
+
42
+ describe('addPoint', () => {
43
+ it('creates new point', () => {
44
+ const mark = t.addPoint({ x: 0, y: 0 });
45
+ expect(mark).toEqual({
46
+ type: 'polygon',
47
+ points: [{ x: 0, y: 0 }],
48
+ closed: false,
49
+ building: true,
50
+ });
51
+ });
52
+
53
+ it('adds the point', () => {
54
+ const mark = t.addPoint({ x: 0, y: 0 }, { points: [{ x: 1, y: 1 }] });
55
+ expect(mark).toEqual({
56
+ building: true,
57
+ closed: false,
58
+ points: [
59
+ { x: 1, y: 1 },
60
+ { x: 0, y: 0 },
61
+ ],
62
+ });
63
+ });
64
+ });
65
+ });
@@ -0,0 +1,25 @@
1
+ import { shallow } from 'enzyme';
2
+ import React from 'react';
3
+ import { Line } from '../line';
4
+ import { graphProps } from '../../../__tests__/utils';
5
+
6
+ describe('Line', () => {
7
+ let w;
8
+ let onChange = jest.fn();
9
+ const wrapper = (extras) => {
10
+ const defaults = {
11
+ classes: {},
12
+ className: 'className',
13
+ graphProps: graphProps(),
14
+ };
15
+ const props = { ...defaults, ...extras };
16
+ return shallow(<Line {...props} />);
17
+ };
18
+ describe('snapshot', () => {
19
+ it('renders', () => {
20
+ w = wrapper();
21
+ expect(w).toMatchSnapshot();
22
+ });
23
+ });
24
+ describe('logic', () => {});
25
+ });
@@ -0,0 +1,44 @@
1
+ import { shallow } from 'enzyme';
2
+ import React from 'react';
3
+ import { Polygon, getPointString } from '../polygon';
4
+ import { graphProps } from '../../../__tests__/utils';
5
+
6
+ const xy = (x, y) => ({ x, y });
7
+
8
+ describe('Polygon', () => {
9
+ let w;
10
+ const wrapper = (extras) => {
11
+ const defaults = {
12
+ classes: {},
13
+ className: 'className',
14
+ graphProps: graphProps(),
15
+ closed: false,
16
+ };
17
+ const props = { ...defaults, ...extras };
18
+ return shallow(<Polygon {...props} />);
19
+ };
20
+
21
+ describe('snapshot', () => {
22
+ it('renders', () => {
23
+ w = wrapper({ points: [{ x: 1, y: 1 }] });
24
+ expect(w).toMatchSnapshot();
25
+ });
26
+ });
27
+ });
28
+
29
+ describe('getPointString', () => {
30
+ const assertString = (arr, expected) => {
31
+ it('creates: ', () => {
32
+ const result = getPointString(arr, {
33
+ x: jest.fn((n) => n),
34
+ y: jest.fn((n) => n),
35
+ });
36
+
37
+ expect(result).toEqual(expected);
38
+ });
39
+ };
40
+
41
+ assertString([xy(1, 1)], '1,1');
42
+ assertString([xy(1, 1), xy(2, 1)], '1,1 2,1');
43
+ assertString([xy(1, 1), xy(2, 1), xy(4, 4)], '1,1 2,1 4,4');
44
+ });
@@ -5,11 +5,10 @@ import { ToolPropTypeFields } from '../shared/types';
5
5
  import { BasePoint } from '../shared/point';
6
6
  import chunk from 'lodash/chunk';
7
7
  import initial from 'lodash/initial';
8
- import isEqual from 'lodash/isEqual';
9
8
  import debug from 'debug';
10
9
  import Line from './line';
11
10
  import DraggablePolygon, { Polygon } from './polygon';
12
- import { types, utils } from '@pie-lib/plot';
11
+ import { types } from '@pie-lib/plot';
13
12
  import invariant from 'invariant';
14
13
  import ReactDOM from 'react-dom';
15
14
  import MarkLabel from '../../mark-label';
@@ -84,6 +83,7 @@ export class RawBaseComponent extends React.Component {
84
83
  middle: PropTypes.object,
85
84
  labelNode: PropTypes.object,
86
85
  labelModeEnabled: PropTypes.bool,
86
+ limitLabeling: PropTypes.bool,
87
87
  onChangeLabelProps: PropTypes.func,
88
88
  onChangeProps: PropTypes.func,
89
89
  };
@@ -165,9 +165,24 @@ export class RawBaseComponent extends React.Component {
165
165
  };
166
166
 
167
167
  clickPoint = (point, index, data) => {
168
- const { closed, onClick, isToolActive, labelModeEnabled, onChangeProps, onChangeLabelProps, points } = this.props;
168
+ const {
169
+ closed,
170
+ disabled,
171
+ onClick,
172
+ isToolActive,
173
+ labelModeEnabled,
174
+ limitLabeling,
175
+ onChangeProps,
176
+ onChangeLabelProps,
177
+ points,
178
+ } = this.props;
169
179
 
170
180
  if (labelModeEnabled) {
181
+ // limit labeling the points of the polygon
182
+ if (disabled || limitLabeling) {
183
+ return;
184
+ }
185
+
171
186
  if (points && index === points.length) {
172
187
  const { a, b } = getRightestPoints(points);
173
188
  const middle = { label: '', ...point, ...getMiddleOfTwoPoints(a, b) };
@@ -183,13 +198,16 @@ export class RawBaseComponent extends React.Component {
183
198
  if (this.input[index]) {
184
199
  this.input[index].focus();
185
200
  }
186
- } else {
187
- if (isToolActive && !closed && index === 0) {
188
- this.close();
189
- } else {
190
- onClick(data);
191
- }
201
+
202
+ return;
203
+ }
204
+
205
+ if (isToolActive && !closed && index === 0) {
206
+ this.close();
207
+ return;
192
208
  }
209
+
210
+ onClick(point || data);
193
211
  };
194
212
 
195
213
  // IMPORTANT, do not remove
@@ -264,8 +282,8 @@ export class RawBaseComponent extends React.Component {
264
282
  x={p.x}
265
283
  y={p.y}
266
284
  onDrag={this.dragPoint.bind(this, index, p)}
267
- onClick={this.clickPoint.bind(this, p, index)}
268
285
  {...common}
286
+ onClick={this.clickPoint.bind(this, p, index)}
269
287
  />,
270
288
  labelNode && p.hasOwnProperty('label')
271
289
  ? ReactDOM.createPortal(
@@ -349,7 +367,16 @@ export default class Component extends React.Component {
349
367
  };
350
368
 
351
369
  render() {
352
- const { coordinatesOnHover, mark, graphProps, onClick, isToolActive, labelNode, labelModeEnabled } = this.props;
370
+ const {
371
+ coordinatesOnHover,
372
+ mark,
373
+ graphProps,
374
+ onClick,
375
+ isToolActive,
376
+ labelNode,
377
+ labelModeEnabled,
378
+ limitLabeling,
379
+ } = this.props;
353
380
  const { mark: stateMark } = this.state;
354
381
 
355
382
  return (
@@ -367,6 +394,7 @@ export default class Component extends React.Component {
367
394
  isToolActive={isToolActive}
368
395
  labelNode={labelNode}
369
396
  labelModeEnabled={labelModeEnabled}
397
+ limitLabeling={limitLabeling}
370
398
  />
371
399
  );
372
400
  }
@@ -5,7 +5,7 @@ import { types, gridDraggable } from '@pie-lib/plot';
5
5
  import { color } from '@pie-lib/render-ui';
6
6
  import * as utils from '../../utils';
7
7
  import classNames from 'classnames';
8
- import { correct, disabled, incorrect, missing } from '../shared/styles';
8
+ import { correct, disabled, disabledSecondary, incorrect, missing } from '../shared/styles';
9
9
 
10
10
  class RawLine extends React.Component {
11
11
  static propTypes = {
@@ -32,7 +32,7 @@ class RawLine extends React.Component {
32
32
  y1={scale.y(from.y)}
33
33
  x2={scale.x(to.x)}
34
34
  y2={scale.y(to.y)}
35
- className={classNames(classes.line, disabled && classes.disabled, className, classes[correctness])}
35
+ className={classNames(classes.line, disabled && classes.disabledSecondary, className, classes[correctness])}
36
36
  {...rest}
37
37
  />
38
38
  );
@@ -41,21 +41,29 @@ class RawLine extends React.Component {
41
41
 
42
42
  export const Line = withStyles(() => ({
43
43
  line: {
44
- strokeWidth: 6,
44
+ strokeWidth: 3,
45
45
  transition: 'stroke-width 200ms ease-in, stroke 200ms ease-in',
46
46
  stroke: 'transparent',
47
47
  '&:hover': {
48
- strokeWidth: 7,
49
- stroke: color.secondary(),
48
+ strokeWidth: 4,
49
+ stroke: color.defaults.BLACK,
50
50
  },
51
51
  },
52
52
  disabled: {
53
53
  ...disabled('stroke'),
54
54
  strokeWidth: 2,
55
55
  },
56
- correct: correct('stoke'),
56
+ disabledSecondary: {
57
+ ...disabledSecondary('stroke'),
58
+ strokeWidth: 2,
59
+ },
60
+ correct: correct('stroke'),
57
61
  incorrect: incorrect('stroke'),
58
- missing: missing('stroke'),
62
+ missing: {
63
+ ...missing('stroke'),
64
+ strokeWidth: 1,
65
+ strokeDasharray: '4 3',
66
+ },
59
67
  }))(RawLine);
60
68
 
61
69
  export default gridDraggable({
@@ -6,7 +6,7 @@ import * as utils from '../../utils';
6
6
  import classNames from 'classnames';
7
7
  import { color } from '@pie-lib/render-ui';
8
8
  import { fade } from '@material-ui/core/styles/colorManipulator';
9
- import { correct, disabled, incorrect } from '../shared/styles';
9
+ import { correct, disabled, incorrect, missing } from '../shared/styles';
10
10
 
11
11
  export const getPointString = (points, scale) => {
12
12
  return (points || [])
@@ -61,12 +61,12 @@ export const Polygon = withStyles((theme) => ({
61
61
  closed: {
62
62
  fill: fade(theme.palette.primary.light, 0.2), // TODO hardcoded color
63
63
  strokeWidth: 2,
64
- stroke: color.secondaryLight(),
64
+ stroke: color.defaults.BLACK,
65
65
  },
66
66
  open: {
67
67
  fill: fade(theme.palette.primary.light, 0.0), // TODO hardcoded color
68
68
  strokeWidth: 2,
69
- stroke: color.secondaryLight(),
69
+ stroke: color.defaults.BLACK,
70
70
  pointerEvents: 'none',
71
71
  },
72
72
  disabled: {
@@ -78,6 +78,10 @@ export const Polygon = withStyles((theme) => ({
78
78
  incorrect: {
79
79
  ...incorrect('stroke'),
80
80
  },
81
+ missing: {
82
+ ...missing('stroke'),
83
+ stroke: 'inherit',
84
+ },
81
85
  }))(RawPolygon);
82
86
 
83
87
  export default gridDraggable({
@@ -0,0 +1,23 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`RayLine snapshot renders 1`] = `
4
+ <g>
5
+ <defs>
6
+ <ArrowMarker
7
+ className=""
8
+ id="1-enabled"
9
+ size={5}
10
+ />
11
+ </defs>
12
+ <line
13
+ className="className"
14
+ markerEnd="url(#1-enabled)"
15
+ markerId="1"
16
+ onChange={[MockFunction]}
17
+ x1={0}
18
+ x2={1.0375}
19
+ y1={0}
20
+ y2={1.0375}
21
+ />
22
+ </g>
23
+ `;
@@ -0,0 +1,29 @@
1
+ import { shallow } from 'enzyme';
2
+ import React from 'react';
3
+ import { RayLine } from '../component';
4
+ import { graphProps as getGraphProps } from '../../../__tests__/utils';
5
+ import { utils } from '@pie-lib/plot';
6
+ describe('RayLine', () => {
7
+ let w;
8
+ let onChange = jest.fn();
9
+ const wrapper = (extras) => {
10
+ const defaults = {
11
+ classes: {},
12
+ className: 'className',
13
+ onChange,
14
+ markerId: '1',
15
+ graphProps: getGraphProps(),
16
+ from: utils.xy(0, 0),
17
+ to: utils.xy(1, 1),
18
+ };
19
+ const props = { ...defaults, ...extras };
20
+ return shallow(<RayLine {...props} />);
21
+ };
22
+
23
+ describe('snapshot', () => {
24
+ it('renders', () => {
25
+ const w = wrapper();
26
+ expect(w).toMatchSnapshot();
27
+ });
28
+ });
29
+ });
@@ -12,6 +12,7 @@ const rayStyles = (theme) => ({
12
12
  enabledArrow: styles.arrow(theme),
13
13
  disabledArrow: styles.disabledArrow(theme),
14
14
  disabled: styles.disabled(theme),
15
+ disabledSecondary: styles.disabledSecondary(theme),
15
16
  correct: styles.correct(theme, 'stroke'),
16
17
  correctArrow: styles.correct(theme),
17
18
  incorrect: styles.incorrect(theme, 'stroke'),
@@ -43,7 +44,7 @@ export const RayLine = (props) => {
43
44
  x2={scale.x(aToB.x)}
44
45
  y2={scale.y(aToB.y)}
45
46
  {...rest}
46
- className={classNames(classes.line, disabled && classes.disabled, classes[correctness], className)}
47
+ className={classNames(classes.line, disabled && classes.disabledSecondary, classes[correctness], className)}
47
48
  markerEnd={`url(#${props.markerId || markerId}-${suffix})`}
48
49
  />
49
50
  </g>
@@ -0,0 +1,14 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`Line snapshot renders 1`] = `
4
+ <line
5
+ className="className"
6
+ onChange={[MockFunction]}
7
+ stroke="green"
8
+ strokeWidth="6"
9
+ x1={0}
10
+ x2={1}
11
+ y1={0}
12
+ y2={1}
13
+ />
14
+ `;
@@ -0,0 +1,28 @@
1
+ import { shallow } from 'enzyme';
2
+ import React from 'react';
3
+ import { Line } from '../component';
4
+ import { graphProps as getGraphProps } from '../../../__tests__/utils';
5
+ import { utils } from '@pie-lib/plot';
6
+ const { xy } = utils;
7
+ describe('Line', () => {
8
+ let w;
9
+ let onChange = jest.fn();
10
+ const wrapper = (extras) => {
11
+ const defaults = {
12
+ classes: {},
13
+ className: 'className',
14
+ onChange,
15
+ graphProps: getGraphProps(),
16
+ from: xy(0, 0),
17
+ to: xy(1, 1),
18
+ };
19
+ const props = { ...defaults, ...extras };
20
+ return shallow(<Line {...props} />);
21
+ };
22
+ describe('snapshot', () => {
23
+ it('renders', () => {
24
+ const w = wrapper();
25
+ expect(w).toMatchSnapshot();
26
+ });
27
+ });
28
+ });
@@ -9,6 +9,7 @@ import classNames from 'classnames';
9
9
  const lineStyles = (theme) => ({
10
10
  line: styles.line(theme),
11
11
  disabled: styles.disabled(theme),
12
+ disabledSecondary: styles.disabledSecondary(theme),
12
13
  correct: styles.correct(theme, 'stroke'),
13
14
  incorrect: styles.incorrect(theme, 'stroke'),
14
15
  missing: styles.missing(theme, 'stroke'),
@@ -25,7 +26,7 @@ export const Line = (props) => {
25
26
  y1={scale.y(from.y)}
26
27
  x2={scale.x(to.x)}
27
28
  y2={scale.y(to.y)}
28
- className={classNames(classes.line, disabled && classes.disabled, classes[correctness], className)}
29
+ className={classNames(classes.line, disabled && classes.disabledSecondary, classes[correctness], className)}
29
30
  {...rest}
30
31
  />
31
32
  );