@pie-lib/graphing 2.14.22 → 2.15.0-beta.2

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 (215) hide show
  1. package/CHANGELOG.md +21 -72
  2. package/NEXT.CHANGELOG.json +1 -0
  3. package/package.json +15 -9
  4. package/src/__tests__/__snapshots__/graph-with-controls.test.jsx.snap +237 -0
  5. package/src/__tests__/__snapshots__/graph.test.jsx.snap +211 -0
  6. package/src/__tests__/__snapshots__/grid.test.jsx.snap +54 -0
  7. package/src/__tests__/__snapshots__/labels.test.jsx.snap +30 -0
  8. package/src/__tests__/__snapshots__/mark-label.test.jsx.snap +45 -0
  9. package/src/__tests__/__snapshots__/toggle-bar.test.jsx.snap +7 -0
  10. package/src/__tests__/__snapshots__/tool-menu.test.jsx.snap +13 -0
  11. package/src/__tests__/__snapshots__/undo-redo.test.jsx.snap +14 -0
  12. package/src/__tests__/graph-with-controls.test.jsx +147 -0
  13. package/src/__tests__/graph.test.jsx +230 -0
  14. package/src/__tests__/grid.test.jsx +20 -0
  15. package/src/__tests__/labels.test.jsx +38 -0
  16. package/src/__tests__/mark-label.test.jsx +68 -0
  17. package/src/__tests__/toggle-bar.test.jsx +36 -0
  18. package/src/__tests__/tool-menu.test.jsx +29 -0
  19. package/src/__tests__/undo-redo.test.jsx +25 -0
  20. package/src/__tests__/use-debounce.test.js +21 -0
  21. package/src/__tests__/utils.js +38 -0
  22. package/src/__tests__/utils.test.js +151 -0
  23. package/src/axis/__tests__/__snapshots__/arrow.test.jsx.snap +33 -0
  24. package/src/axis/__tests__/__snapshots__/axes.test.jsx.snap +122 -0
  25. package/src/axis/__tests__/arrow.test.jsx +39 -0
  26. package/src/axis/__tests__/axes.test.jsx +220 -0
  27. package/src/axis/axes.jsx +5 -5
  28. package/src/container/index.jsx +2 -4
  29. package/src/coordinates-label.jsx +4 -3
  30. package/src/graph-with-controls.jsx +8 -10
  31. package/src/graph.jsx +22 -10
  32. package/src/grid.jsx +8 -10
  33. package/src/index.js +2 -2
  34. package/src/key-legend.jsx +145 -0
  35. package/src/label-svg-icon.jsx +39 -0
  36. package/src/labels.jsx +2 -1
  37. package/src/mark-label.jsx +149 -52
  38. package/src/toggle-bar.jsx +1 -2
  39. package/src/tool-menu.jsx +3 -26
  40. package/src/tools/absolute/__tests__/component.test.jsx +54 -0
  41. package/src/tools/absolute/component.jsx +23 -0
  42. package/src/tools/absolute/index.js +31 -0
  43. package/src/tools/circle/__tests__/__snapshots__/bg-circle.test.jsx.snap +46 -0
  44. package/src/tools/circle/__tests__/__snapshots__/component.test.jsx.snap +293 -0
  45. package/src/tools/circle/__tests__/bg-circle.test.jsx +28 -0
  46. package/src/tools/circle/__tests__/component.test.jsx +228 -0
  47. package/src/tools/circle/bg-circle.jsx +5 -4
  48. package/src/tools/circle/component.jsx +22 -8
  49. package/src/tools/exponential/__tests__/component.test.jsx +54 -0
  50. package/src/tools/exponential/component.jsx +23 -0
  51. package/src/tools/exponential/index.js +39 -0
  52. package/src/tools/index.js +38 -5
  53. package/src/tools/line/__tests__/__snapshots__/component.test.jsx.snap +20 -0
  54. package/src/tools/line/__tests__/component.test.jsx +36 -0
  55. package/src/tools/line/component.jsx +2 -1
  56. package/src/tools/parabola/__tests__/component.test.jsx +49 -0
  57. package/src/tools/parabola/component.jsx +7 -6
  58. package/src/tools/point/__tests__/__snapshots__/component.test.jsx.snap +40 -0
  59. package/src/tools/point/__tests__/component.test.jsx +66 -0
  60. package/src/tools/point/component.jsx +12 -6
  61. package/src/tools/polygon/__tests__/__snapshots__/component.test.jsx.snap +415 -0
  62. package/src/tools/polygon/__tests__/__snapshots__/line.test.jsx.snap +45 -0
  63. package/src/tools/polygon/__tests__/__snapshots__/polygon.test.jsx.snap +52 -0
  64. package/src/tools/polygon/__tests__/component.test.jsx +226 -0
  65. package/src/tools/polygon/__tests__/index.test.js +65 -0
  66. package/src/tools/polygon/__tests__/line.test.jsx +25 -0
  67. package/src/tools/polygon/__tests__/polygon.test.jsx +44 -0
  68. package/src/tools/polygon/component.jsx +39 -11
  69. package/src/tools/polygon/line.jsx +15 -7
  70. package/src/tools/polygon/polygon.jsx +7 -3
  71. package/src/tools/ray/__tests__/__snapshots__/component.test.jsx.snap +23 -0
  72. package/src/tools/ray/__tests__/component.test.jsx +29 -0
  73. package/src/tools/ray/component.jsx +2 -1
  74. package/src/tools/segment/__tests__/__snapshots__/component.test.jsx.snap +14 -0
  75. package/src/tools/segment/__tests__/component.test.jsx +28 -0
  76. package/src/tools/segment/component.jsx +2 -1
  77. package/src/tools/shared/__tests__/__snapshots__/arrow-head.test.jsx.snap +27 -0
  78. package/src/tools/shared/__tests__/arrow-head.test.jsx +34 -0
  79. package/src/tools/shared/icons/CorrectSVG.jsx +22 -0
  80. package/src/tools/shared/icons/IncorrectSVG.jsx +20 -0
  81. package/src/tools/shared/icons/MissingSVG.jsx +21 -0
  82. package/src/tools/shared/line/__tests__/__snapshots__/index.test.jsx.snap +360 -0
  83. package/src/tools/shared/line/__tests__/__snapshots__/line-path.test.jsx.snap +58 -0
  84. package/src/tools/shared/line/__tests__/__snapshots__/with-root-edge.test.jsx.snap +63 -0
  85. package/src/tools/shared/line/__tests__/index.test.jsx +255 -0
  86. package/src/tools/shared/line/__tests__/line-path.test.jsx +53 -0
  87. package/src/tools/shared/line/__tests__/with-root-edge.test.jsx +73 -0
  88. package/src/tools/shared/line/index.jsx +39 -13
  89. package/src/tools/shared/line/line-path.jsx +18 -7
  90. package/src/tools/shared/line/with-root-edge.jsx +10 -3
  91. package/src/tools/shared/point/__tests__/__snapshots__/arrow-point.test.jsx.snap +56 -0
  92. package/src/tools/shared/point/__tests__/__snapshots__/base-point.test.jsx.snap +44 -0
  93. package/src/tools/shared/point/__tests__/arrow-point.test.jsx +87 -0
  94. package/src/tools/shared/point/__tests__/base-point.test.jsx +84 -0
  95. package/src/tools/shared/point/arrow-point.jsx +4 -1
  96. package/src/tools/shared/point/arrow.jsx +4 -1
  97. package/src/tools/shared/point/base-point.jsx +28 -3
  98. package/src/tools/shared/point/index.jsx +7 -2
  99. package/src/tools/shared/styles.js +8 -3
  100. package/src/tools/sine/__tests__/component.test.jsx +51 -0
  101. package/src/tools/sine/component.jsx +7 -7
  102. package/src/tools/vector/__tests__/__snapshots__/component.test.jsx.snap +12 -0
  103. package/src/tools/vector/__tests__/component.test.jsx +26 -0
  104. package/src/tools/vector/component.jsx +2 -1
  105. package/src/undo-redo.jsx +0 -1
  106. package/src/utils.js +1 -1
  107. package/legacy.png +0 -0
  108. package/lib/axis/arrow.js +0 -115
  109. package/lib/axis/arrow.js.map +0 -1
  110. package/lib/axis/axes.js +0 -415
  111. package/lib/axis/axes.js.map +0 -1
  112. package/lib/axis/index.js +0 -26
  113. package/lib/axis/index.js.map +0 -1
  114. package/lib/bg.js +0 -139
  115. package/lib/bg.js.map +0 -1
  116. package/lib/container/actions.js +0 -24
  117. package/lib/container/actions.js.map +0 -1
  118. package/lib/container/index.js +0 -166
  119. package/lib/container/index.js.map +0 -1
  120. package/lib/container/marks.js +0 -27
  121. package/lib/container/marks.js.map +0 -1
  122. package/lib/container/middleware.js +0 -25
  123. package/lib/container/middleware.js.map +0 -1
  124. package/lib/container/reducer.js +0 -25
  125. package/lib/container/reducer.js.map +0 -1
  126. package/lib/coordinates-label.js +0 -107
  127. package/lib/coordinates-label.js.map +0 -1
  128. package/lib/graph-with-controls.js +0 -366
  129. package/lib/graph-with-controls.js.map +0 -1
  130. package/lib/graph.js +0 -354
  131. package/lib/graph.js.map +0 -1
  132. package/lib/grid-setup.js +0 -462
  133. package/lib/grid-setup.js.map +0 -1
  134. package/lib/grid.js +0 -184
  135. package/lib/grid.js.map +0 -1
  136. package/lib/index.js +0 -51
  137. package/lib/index.js.map +0 -1
  138. package/lib/labels.js +0 -298
  139. package/lib/labels.js.map +0 -1
  140. package/lib/mark-label.js +0 -210
  141. package/lib/mark-label.js.map +0 -1
  142. package/lib/toggle-bar.js +0 -337
  143. package/lib/toggle-bar.js.map +0 -1
  144. package/lib/tool-menu.js +0 -132
  145. package/lib/tool-menu.js.map +0 -1
  146. package/lib/tools/circle/bg-circle.js +0 -172
  147. package/lib/tools/circle/bg-circle.js.map +0 -1
  148. package/lib/tools/circle/component.js +0 -387
  149. package/lib/tools/circle/component.js.map +0 -1
  150. package/lib/tools/circle/index.js +0 -51
  151. package/lib/tools/circle/index.js.map +0 -1
  152. package/lib/tools/index.js +0 -79
  153. package/lib/tools/index.js.map +0 -1
  154. package/lib/tools/line/component.js +0 -102
  155. package/lib/tools/line/component.js.map +0 -1
  156. package/lib/tools/line/index.js +0 -16
  157. package/lib/tools/line/index.js.map +0 -1
  158. package/lib/tools/parabola/component.js +0 -33
  159. package/lib/tools/parabola/component.js.map +0 -1
  160. package/lib/tools/parabola/index.js +0 -63
  161. package/lib/tools/parabola/index.js.map +0 -1
  162. package/lib/tools/point/component.js +0 -181
  163. package/lib/tools/point/component.js.map +0 -1
  164. package/lib/tools/point/index.js +0 -32
  165. package/lib/tools/point/index.js.map +0 -1
  166. package/lib/tools/polygon/component.js +0 -505
  167. package/lib/tools/polygon/component.js.map +0 -1
  168. package/lib/tools/polygon/index.js +0 -106
  169. package/lib/tools/polygon/index.js.map +0 -1
  170. package/lib/tools/polygon/line.js +0 -151
  171. package/lib/tools/polygon/line.js.map +0 -1
  172. package/lib/tools/polygon/polygon.js +0 -162
  173. package/lib/tools/polygon/polygon.js.map +0 -1
  174. package/lib/tools/ray/component.js +0 -101
  175. package/lib/tools/ray/component.js.map +0 -1
  176. package/lib/tools/ray/index.js +0 -16
  177. package/lib/tools/ray/index.js.map +0 -1
  178. package/lib/tools/segment/component.js +0 -74
  179. package/lib/tools/segment/component.js.map +0 -1
  180. package/lib/tools/segment/index.js +0 -16
  181. package/lib/tools/segment/index.js.map +0 -1
  182. package/lib/tools/shared/arrow-head.js +0 -70
  183. package/lib/tools/shared/arrow-head.js.map +0 -1
  184. package/lib/tools/shared/line/index.js +0 -567
  185. package/lib/tools/shared/line/index.js.map +0 -1
  186. package/lib/tools/shared/line/line-path.js +0 -145
  187. package/lib/tools/shared/line/line-path.js.map +0 -1
  188. package/lib/tools/shared/line/with-root-edge.js +0 -144
  189. package/lib/tools/shared/line/with-root-edge.js.map +0 -1
  190. package/lib/tools/shared/point/arrow-point.js +0 -113
  191. package/lib/tools/shared/point/arrow-point.js.map +0 -1
  192. package/lib/tools/shared/point/arrow.js +0 -96
  193. package/lib/tools/shared/point/arrow.js.map +0 -1
  194. package/lib/tools/shared/point/base-point.js +0 -139
  195. package/lib/tools/shared/point/base-point.js.map +0 -1
  196. package/lib/tools/shared/point/index.js +0 -94
  197. package/lib/tools/shared/point/index.js.map +0 -1
  198. package/lib/tools/shared/styles.js +0 -49
  199. package/lib/tools/shared/styles.js.map +0 -1
  200. package/lib/tools/shared/types.js +0 -23
  201. package/lib/tools/shared/types.js.map +0 -1
  202. package/lib/tools/sine/component.js +0 -42
  203. package/lib/tools/sine/component.js.map +0 -1
  204. package/lib/tools/sine/index.js +0 -63
  205. package/lib/tools/sine/index.js.map +0 -1
  206. package/lib/tools/vector/component.js +0 -87
  207. package/lib/tools/vector/component.js.map +0 -1
  208. package/lib/tools/vector/index.js +0 -16
  209. package/lib/tools/vector/index.js.map +0 -1
  210. package/lib/undo-redo.js +0 -124
  211. package/lib/undo-redo.js.map +0 -1
  212. package/lib/use-debounce.js +0 -32
  213. package/lib/use-debounce.js.map +0 -1
  214. package/lib/utils.js +0 -307
  215. package/lib/utils.js.map +0 -1
@@ -0,0 +1,211 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`Graph snapshot renders 1`] = `
4
+ <WithStyles(Root)
5
+ disabledLabels={false}
6
+ disabledTitle={false}
7
+ graphProps={
8
+ Object {
9
+ "domain": Object {
10
+ "max": 1,
11
+ "min": 0,
12
+ "step": 1,
13
+ },
14
+ "getRootNode": [Function],
15
+ "range": Object {
16
+ "max": 1,
17
+ "min": 0,
18
+ "step": 1,
19
+ },
20
+ "scale": Object {
21
+ "x": [Function],
22
+ "y": [Function],
23
+ },
24
+ "size": Object {
25
+ "height": 400,
26
+ "width": 400,
27
+ },
28
+ "snap": Object {
29
+ "x": [Function],
30
+ "y": [Function],
31
+ },
32
+ }
33
+ }
34
+ labelsPlaceholders={Object {}}
35
+ mathMlOptions={Object {}}
36
+ rootRef={[Function]}
37
+ >
38
+ <g>
39
+ <WithStyles(Grid)
40
+ graphProps={
41
+ Object {
42
+ "domain": Object {
43
+ "max": 1,
44
+ "min": 0,
45
+ "step": 1,
46
+ },
47
+ "getRootNode": [Function],
48
+ "range": Object {
49
+ "max": 1,
50
+ "min": 0,
51
+ "step": 1,
52
+ },
53
+ "scale": Object {
54
+ "x": [Function],
55
+ "y": [Function],
56
+ },
57
+ "size": Object {
58
+ "height": 400,
59
+ "width": 400,
60
+ },
61
+ "snap": Object {
62
+ "x": [Function],
63
+ "y": [Function],
64
+ },
65
+ }
66
+ }
67
+ />
68
+ <Axes
69
+ graphProps={
70
+ Object {
71
+ "domain": Object {
72
+ "max": 1,
73
+ "min": 0,
74
+ "step": 1,
75
+ },
76
+ "getRootNode": [Function],
77
+ "range": Object {
78
+ "max": 1,
79
+ "min": 0,
80
+ "step": 1,
81
+ },
82
+ "scale": Object {
83
+ "x": [Function],
84
+ "y": [Function],
85
+ },
86
+ "size": Object {
87
+ "height": 400,
88
+ "width": 400,
89
+ },
90
+ "snap": Object {
91
+ "x": [Function],
92
+ "y": [Function],
93
+ },
94
+ }
95
+ }
96
+ includeArrows={
97
+ Object {
98
+ "down": true,
99
+ "left": true,
100
+ "right": true,
101
+ "up": true,
102
+ }
103
+ }
104
+ />
105
+ <Bg
106
+ graphProps={
107
+ Object {
108
+ "domain": Object {
109
+ "max": 1,
110
+ "min": 0,
111
+ "step": 1,
112
+ },
113
+ "getRootNode": [Function],
114
+ "range": Object {
115
+ "max": 1,
116
+ "min": 0,
117
+ "step": 1,
118
+ },
119
+ "scale": Object {
120
+ "x": [Function],
121
+ "y": [Function],
122
+ },
123
+ "size": Object {
124
+ "height": 400,
125
+ "width": 400,
126
+ },
127
+ "snap": Object {
128
+ "x": [Function],
129
+ "y": [Function],
130
+ },
131
+ }
132
+ }
133
+ height={400}
134
+ onClick={[Function]}
135
+ width={400}
136
+ />
137
+ <mask
138
+ id="graph-1618"
139
+ >
140
+ <rect
141
+ fill="white"
142
+ height={446}
143
+ width={446}
144
+ x={-23}
145
+ y={-23}
146
+ />
147
+
148
+ </mask>
149
+ <g
150
+ id="marks"
151
+ mask="url('#graph-1618')"
152
+ >
153
+ <Point
154
+ graphProps={
155
+ Object {
156
+ "domain": Object {
157
+ "max": 1,
158
+ "min": 0,
159
+ "step": 1,
160
+ },
161
+ "getRootNode": [Function],
162
+ "range": Object {
163
+ "max": 1,
164
+ "min": 0,
165
+ "step": 1,
166
+ },
167
+ "scale": Object {
168
+ "x": [Function],
169
+ "y": [Function],
170
+ },
171
+ "size": Object {
172
+ "height": 400,
173
+ "width": 400,
174
+ },
175
+ "snap": Object {
176
+ "x": [Function],
177
+ "y": [Function],
178
+ },
179
+ }
180
+ }
181
+ isToolActive={false}
182
+ key="point-0"
183
+ mark={
184
+ Object {
185
+ "label": "Point",
186
+ "showLabel": true,
187
+ "type": "point",
188
+ "x": 2,
189
+ "y": 2,
190
+ }
191
+ }
192
+ onChange={[Function]}
193
+ onClick={[Function]}
194
+ onComplete={[Function]}
195
+ />
196
+ <foreignObject
197
+ height={400}
198
+ style={
199
+ Object {
200
+ "fontSize": "14px",
201
+ "pointerEvents": "none",
202
+ }
203
+ }
204
+ width={400}
205
+ x="0"
206
+ y="0"
207
+ />
208
+ </g>
209
+ </g>
210
+ </WithStyles(Root)>
211
+ `;
@@ -0,0 +1,54 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`Grid snapshot renders 1`] = `
4
+ <Fragment>
5
+ <r
6
+ columnTickValues={
7
+ Array [
8
+ 0,
9
+ 1,
10
+ ]
11
+ }
12
+ height={400}
13
+ innerRef={[Function]}
14
+ rowTickValues={
15
+ Array [
16
+ 0,
17
+ 1,
18
+ ]
19
+ }
20
+ stroke="#E1E6EC"
21
+ width={400}
22
+ xScale={
23
+ [MockFunction] {
24
+ "calls": Array [
25
+ Array [
26
+ 0,
27
+ ],
28
+ ],
29
+ "results": Array [
30
+ Object {
31
+ "type": "return",
32
+ "value": 0,
33
+ },
34
+ ],
35
+ }
36
+ }
37
+ yScale={
38
+ [MockFunction] {
39
+ "calls": Array [
40
+ Array [
41
+ 0,
42
+ ],
43
+ ],
44
+ "results": Array [
45
+ Object {
46
+ "type": "return",
47
+ "value": 0,
48
+ },
49
+ ],
50
+ }
51
+ }
52
+ />
53
+ </Fragment>
54
+ `;
@@ -0,0 +1,30 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`Labels snapshot renders 1`] = `
4
+ <Fragment>
5
+ <WithStyles(RawLabel)
6
+ key="left"
7
+ mathMlOptions={Object {}}
8
+ onChange={[Function]}
9
+ side="left"
10
+ />
11
+ <WithStyles(RawLabel)
12
+ key="top"
13
+ mathMlOptions={Object {}}
14
+ onChange={[Function]}
15
+ side="top"
16
+ />
17
+ <WithStyles(RawLabel)
18
+ key="bottom"
19
+ mathMlOptions={Object {}}
20
+ onChange={[Function]}
21
+ side="bottom"
22
+ />
23
+ <WithStyles(RawLabel)
24
+ key="right"
25
+ mathMlOptions={Object {}}
26
+ onChange={[Function]}
27
+ side="right"
28
+ />
29
+ </Fragment>
30
+ `;
@@ -0,0 +1,45 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`MarkLabel snapshot renders 1`] = `
4
+ <div
5
+ style={
6
+ Object {
7
+ "alignItems": "center",
8
+ "display": "flex",
9
+ "gap": "3px",
10
+ "left": 6,
11
+ "pointerEvents": "auto",
12
+ "position": "fixed",
13
+ "top": -4,
14
+ }
15
+ }
16
+ >
17
+ <LabelInput
18
+ _ref={[Function]}
19
+ inputClassName=""
20
+ onChange={[Function]}
21
+ />
22
+ </div>
23
+ `;
24
+
25
+ exports[`MarkLabel snapshot renders 2`] = `
26
+ <div
27
+ style={
28
+ Object {
29
+ "alignItems": "center",
30
+ "display": "flex",
31
+ "gap": "3px",
32
+ "left": 5,
33
+ "pointerEvents": "auto",
34
+ "position": "fixed",
35
+ "top": 5,
36
+ }
37
+ }
38
+ >
39
+ <LabelInput
40
+ _ref={[Function]}
41
+ inputClassName=""
42
+ onChange={[Function]}
43
+ />
44
+ </div>
45
+ `;
@@ -0,0 +1,7 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`ToggleBar snapshot renders 1`] = `
4
+ <div
5
+ className="className"
6
+ />
7
+ `;
@@ -0,0 +1,13 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`ToolMenu snapshot renders 1`] = `
4
+ <div
5
+ className="className"
6
+ >
7
+ <Component
8
+ onChange={[MockFunction]}
9
+ onChangeToolsOrder={[Function]}
10
+ options={Array []}
11
+ />
12
+ </div>
13
+ `;
@@ -0,0 +1,14 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`UndoRedo snapshot renders 1`] = `
4
+ <UndoRedo
5
+ classes={
6
+ Object {
7
+ "button": "UndoRedo-button-1",
8
+ }
9
+ }
10
+ onRedo={[MockFunction]}
11
+ onReset={[MockFunction]}
12
+ onUndo={[MockFunction]}
13
+ />
14
+ `;
@@ -0,0 +1,147 @@
1
+ import { shallow } from 'enzyme';
2
+ import React from 'react';
3
+
4
+ import { xy } from './utils';
5
+
6
+ import {
7
+ GraphWithControls,
8
+ setToolbarAvailability,
9
+ toolIsAvailable,
10
+ getAvailableTool,
11
+ filterByValidToolTypes,
12
+ filterByVisibleToolTypes,
13
+ } from '../graph-with-controls';
14
+ import { toolsArr, allTools, line as lineTool, point as pointTool } from '@pie-lib/tools';
15
+
16
+ const point = {
17
+ type: 'point',
18
+ x: 2,
19
+ y: 2,
20
+ label: 'Point',
21
+ showLabel: true,
22
+ };
23
+
24
+ const line = {
25
+ type: 'line',
26
+ from: { x: 0, y: 0 },
27
+ to: { x: 1, y: 1 },
28
+ label: 'Line',
29
+ building: true,
30
+ };
31
+
32
+ const circle = {
33
+ type: 'line',
34
+ edge: { x: 0, y: 0 },
35
+ root: { x: 2, y: 2 },
36
+ };
37
+
38
+ const marks = [point, line, circle];
39
+
40
+ describe('setToolbarAvailability', () => {
41
+ it('sets `toolbar: true` if tool should be displayed in toolbar - all tools', () => {
42
+ const result = setToolbarAvailability(allTools);
43
+ const allTrue = new Array(toolsArr.length).fill(true);
44
+
45
+ expect(result.map((r) => r.toolbar)).toEqual(allTrue);
46
+ });
47
+
48
+ it('sets `toolbar: true` if tool should be displayed in toolbar - few tools', () => {
49
+ const result = setToolbarAvailability(['line', 'circle']);
50
+ const allOthersFalse = new Array(toolsArr.length - 2).fill(false);
51
+
52
+ expect(result.filter((r) => r.type === 'line' || r.type === 'circle').map((r) => r.toolbar)).toEqual([true, true]);
53
+ expect(result.filter((r) => r.type !== 'line' && r.type !== 'circle').map((r) => r.toolbar)).toEqual(
54
+ allOthersFalse,
55
+ );
56
+ });
57
+ });
58
+
59
+ describe('toolIsAvailable', () => {
60
+ const tools = setToolbarAvailability(['line', 'circle']);
61
+
62
+ it('returns true if tool is available', () => {
63
+ expect(toolIsAvailable(tools, lineTool())).toEqual(true);
64
+ });
65
+
66
+ it('returns false if tool is not available', () => {
67
+ expect(toolIsAvailable(tools, pointTool())).toEqual(false);
68
+ });
69
+ });
70
+
71
+ describe('getAvailableTool', () => {
72
+ it('returns the first available tool in list if there is any', () => {
73
+ const tools = setToolbarAvailability(['line', 'circle']);
74
+
75
+ expect(getAvailableTool(tools).toolbar).toEqual(true);
76
+ });
77
+
78
+ it('returns undefined list if there is no available tool', () => {
79
+ const tools = setToolbarAvailability([]);
80
+
81
+ expect(getAvailableTool(tools)).toEqual(undefined);
82
+ });
83
+ });
84
+
85
+ describe('filterByValidToolTypes', () => {
86
+ it('filters marks by valid types', () => {
87
+ const marks = [{ type: 'point' }, { type: 'a' }, { type: 'b' }, { type: 'line' }, { type: 'c' }];
88
+
89
+ expect(filterByValidToolTypes(marks)).toEqual([{ type: 'point' }, { type: 'line' }]);
90
+ });
91
+ });
92
+
93
+ describe('filterByVisibleToolTypes', () => {
94
+ it('filters marks by the types that should be visible', () => {
95
+ expect(
96
+ filterByVisibleToolTypes(['line', 'circle'], [{ type: 'point' }, { type: 'line' }, { type: 'circle' }]),
97
+ ).toEqual([{ type: 'line' }, { type: 'circle' }]);
98
+
99
+ expect(
100
+ filterByVisibleToolTypes(['line', 'circle', 'point'], [{ type: 'point' }, { type: 'line' }, { type: 'circle' }]),
101
+ ).toEqual([{ type: 'point' }, { type: 'line' }, { type: 'circle' }]);
102
+
103
+ expect(filterByVisibleToolTypes(['line'], [{ type: 'point' }, { type: 'line' }, { type: 'circle' }])).toEqual([
104
+ { type: 'line' },
105
+ ]);
106
+
107
+ expect(filterByVisibleToolTypes(['segment'], [{ type: 'point' }, { type: 'line' }, { type: 'circle' }])).toEqual(
108
+ [],
109
+ );
110
+ });
111
+ });
112
+
113
+ describe('GraphWithControls', () => {
114
+ let w;
115
+ let onChangeMarks = jest.fn();
116
+
117
+ const defaultProps = () => ({
118
+ axesSettings: { includeArrows: true },
119
+ backgroundMarks: [point, line, circle],
120
+ classes: {},
121
+ className: '',
122
+ coordinatesOnHover: false,
123
+ domain: { min: 0, max: 10, step: 1 },
124
+ labels: { top: 'a', left: 'b', right: 'c', bottom: 'd' },
125
+ labelModeEnabled: true,
126
+ marks,
127
+ onChangeMarks,
128
+ range: { min: 0, max: 10, step: 1 },
129
+ size: { width: 500, height: 500 },
130
+ title: 'Title',
131
+ toolbarTools: allTools,
132
+ });
133
+ const initialProps = defaultProps();
134
+
135
+ const wrapper = (extras, opts) => {
136
+ const props = { ...initialProps, ...extras };
137
+
138
+ return shallow(<GraphWithControls {...props} />, opts);
139
+ };
140
+
141
+ describe('snapshot', () => {
142
+ it('renders', () => {
143
+ w = wrapper();
144
+ expect(w).toMatchSnapshot();
145
+ });
146
+ });
147
+ });