@pie-lib/graphing-solution-set 4.1.0-beta.8 → 5.0.0-next.20261002094057

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 (262) hide show
  1. package/dist/_virtual/_rolldown/runtime.js +20 -0
  2. package/dist/autosize-input.d.ts +10 -0
  3. package/dist/autosize-input.js +66 -0
  4. package/dist/axis/arrow.d.ts +13 -0
  5. package/dist/axis/arrow.js +34 -0
  6. package/dist/axis/axes.d.ts +132 -0
  7. package/dist/axis/axes.js +214 -0
  8. package/dist/axis/index.d.ts +10 -0
  9. package/dist/bg.d.ts +51 -0
  10. package/dist/bg.js +44 -0
  11. package/dist/container/actions.d.ts +15 -0
  12. package/dist/container/actions.js +7 -0
  13. package/dist/container/index.d.ts +58 -0
  14. package/dist/container/index.js +48 -0
  15. package/dist/container/marks.d.ts +10 -0
  16. package/dist/container/marks.js +11 -0
  17. package/dist/container/middleware.d.ts +10 -0
  18. package/dist/container/middleware.js +4 -0
  19. package/dist/container/reducer.d.ts +14 -0
  20. package/dist/container/reducer.js +7 -0
  21. package/dist/coordinates-label.d.ts +50 -0
  22. package/dist/coordinates-label.js +46 -0
  23. package/dist/graph-with-controls.d.ts +85 -0
  24. package/dist/graph-with-controls.js +155 -0
  25. package/dist/graph.d.ts +119 -0
  26. package/dist/graph.js +221 -0
  27. package/dist/grid-setup.d.ts +27 -0
  28. package/dist/grid-setup.js +307 -0
  29. package/dist/grid.d.ts +43 -0
  30. package/dist/grid.js +59 -0
  31. package/dist/index.d.ts +14 -0
  32. package/dist/index.js +6 -0
  33. package/dist/labels.d.ts +73 -0
  34. package/dist/labels.js +134 -0
  35. package/dist/mark-label.d.ts +50 -0
  36. package/dist/mark-label.js +84 -0
  37. package/dist/node_modules/.bun/@visx_axis@4.0.0_d84c32d47042070f/node_modules/@visx/axis/esm/axis/Axis.js +67 -0
  38. package/dist/node_modules/.bun/@visx_axis@4.0.0_d84c32d47042070f/node_modules/@visx/axis/esm/axis/AxisRenderer.js +66 -0
  39. package/dist/node_modules/.bun/@visx_axis@4.0.0_d84c32d47042070f/node_modules/@visx/axis/esm/axis/Ticks.js +39 -0
  40. package/dist/node_modules/.bun/@visx_axis@4.0.0_d84c32d47042070f/node_modules/@visx/axis/esm/constants/orientation.js +9 -0
  41. package/dist/node_modules/.bun/@visx_axis@4.0.0_d84c32d47042070f/node_modules/@visx/axis/esm/utils/createPoint.js +14 -0
  42. package/dist/node_modules/.bun/@visx_axis@4.0.0_d84c32d47042070f/node_modules/@visx/axis/esm/utils/getAxisRangePaddingConfig.js +13 -0
  43. package/dist/node_modules/.bun/@visx_axis@4.0.0_d84c32d47042070f/node_modules/@visx/axis/esm/utils/getLabelTransform.js +16 -0
  44. package/dist/node_modules/.bun/@visx_axis@4.0.0_d84c32d47042070f/node_modules/@visx/axis/esm/utils/getTickFormatter.js +8 -0
  45. package/dist/node_modules/.bun/@visx_axis@4.0.0_d84c32d47042070f/node_modules/@visx/axis/esm/utils/getTickPosition.js +14 -0
  46. package/dist/node_modules/.bun/@visx_grid@4.0.0_d84c32d47042070f/node_modules/@visx/grid/esm/grids/Grid.js +43 -0
  47. package/dist/node_modules/.bun/@visx_grid@4.0.0_d84c32d47042070f/node_modules/@visx/grid/esm/grids/GridColumns.js +46 -0
  48. package/dist/node_modules/.bun/@visx_grid@4.0.0_d84c32d47042070f/node_modules/@visx/grid/esm/grids/GridRows.js +46 -0
  49. package/dist/node_modules/.bun/@visx_grid@4.0.0_d84c32d47042070f/node_modules/@visx/grid/esm/utils/getScaleBandwidth.js +6 -0
  50. package/dist/node_modules/.bun/@visx_group@4.0.0_d84c32d47042070f/node_modules/@visx/group/esm/Group.js +17 -0
  51. package/dist/node_modules/.bun/@visx_point@4.0.0/node_modules/@visx/point/esm/Point.js +20 -0
  52. package/dist/node_modules/.bun/@visx_scale@4.0.0/node_modules/@visx/scale/esm/utils/coerceNumber.js +10 -0
  53. package/dist/node_modules/.bun/@visx_scale@4.0.0/node_modules/@visx/scale/esm/utils/getTicks.js +7 -0
  54. package/dist/node_modules/.bun/@visx_scale@4.0.0/node_modules/@visx/scale/esm/utils/toString.js +6 -0
  55. package/dist/node_modules/.bun/@visx_shape@4.0.0_d84c32d47042070f/node_modules/@visx/shape/esm/shapes/Line.js +27 -0
  56. package/dist/node_modules/.bun/@visx_text@4.0.0_d84c32d47042070f/node_modules/@visx/text/esm/Text.js +27 -0
  57. package/dist/node_modules/.bun/@visx_text@4.0.0_d84c32d47042070f/node_modules/@visx/text/esm/hooks/useText.js +68 -0
  58. package/dist/node_modules/.bun/@visx_text@4.0.0_d84c32d47042070f/node_modules/@visx/text/esm/util/getStringWidth.js +19 -0
  59. package/dist/node_modules/.bun/@visx_text@4.0.0_d84c32d47042070f/node_modules/@visx/text/esm/util/memoize.js +13 -0
  60. package/dist/node_modules/.bun/balanced-match@0.4.2/node_modules/balanced-match/index.js +32 -0
  61. package/dist/node_modules/.bun/balanced-match@1.0.2/node_modules/balanced-match/index.js +33 -0
  62. package/dist/node_modules/.bun/classnames@2.5.1/node_modules/classnames/index.js +32 -0
  63. package/dist/node_modules/.bun/clsx@2.1.1/node_modules/clsx/dist/clsx.js +16 -0
  64. package/dist/node_modules/.bun/invariant@2.2.4/node_modules/invariant/browser.js +28 -0
  65. package/dist/node_modules/.bun/math-expression-evaluator@1.4.0/node_modules/math-expression-evaluator/src/formula_evaluator.js +37 -0
  66. package/dist/node_modules/.bun/math-expression-evaluator@1.4.0/node_modules/math-expression-evaluator/src/lexer.js +509 -0
  67. package/dist/node_modules/.bun/math-expression-evaluator@1.4.0/node_modules/math-expression-evaluator/src/math_function.js +108 -0
  68. package/dist/node_modules/.bun/math-expression-evaluator@1.4.0/node_modules/math-expression-evaluator/src/postfix.js +31 -0
  69. package/dist/node_modules/.bun/math-expression-evaluator@1.4.0/node_modules/math-expression-evaluator/src/postfix_evaluator.js +45 -0
  70. package/dist/node_modules/.bun/reduce-css-calc@1.3.0/node_modules/reduce-css-calc/index.js +49 -0
  71. package/dist/node_modules/.bun/reduce-function-call@1.0.3/node_modules/reduce-function-call/index.js +34 -0
  72. package/dist/node_modules/.bun/redux-undo@1.1.0/node_modules/redux-undo/dist/redux-undo.js +185 -0
  73. package/dist/node_modules/.bun/redux@5.0.1/node_modules/redux/dist/redux.js +198 -0
  74. package/dist/tool-menu.d.ts +21 -0
  75. package/dist/tool-menu.js +188 -0
  76. package/dist/tools/index.d.ts +17 -0
  77. package/dist/tools/index.js +12 -0
  78. package/dist/tools/line/component.d.ts +113 -0
  79. package/dist/tools/line/component.js +58 -0
  80. package/dist/tools/line/index.d.ts +13 -0
  81. package/dist/tools/line/index.js +6 -0
  82. package/dist/tools/polygon/component.d.ts +117 -0
  83. package/dist/tools/polygon/component.js +194 -0
  84. package/dist/tools/polygon/index.d.ts +19 -0
  85. package/dist/tools/polygon/index.js +55 -0
  86. package/dist/tools/polygon/polygon.d.ts +122 -0
  87. package/dist/tools/polygon/polygon.js +62 -0
  88. package/dist/tools/shared/arrow-head.d.ts +43 -0
  89. package/dist/tools/shared/arrow-head.js +37 -0
  90. package/dist/tools/shared/line/index.d.ts +240 -0
  91. package/dist/tools/shared/line/index.js +320 -0
  92. package/dist/tools/shared/point/arrow-point.d.ts +57 -0
  93. package/dist/tools/shared/point/arrow-point.js +47 -0
  94. package/dist/tools/shared/point/arrow.d.ts +46 -0
  95. package/dist/tools/shared/point/arrow.js +36 -0
  96. package/dist/tools/shared/point/base-point.d.ts +50 -0
  97. package/dist/tools/shared/point/base-point.js +88 -0
  98. package/dist/tools/shared/point/index.d.ts +217 -0
  99. package/dist/tools/shared/point/index.js +51 -0
  100. package/dist/tools/shared/styles.d.ts +24 -0
  101. package/dist/tools/shared/styles.js +17 -0
  102. package/dist/tools/shared/types.d.ts +15 -0
  103. package/dist/tools/shared/types.js +10 -0
  104. package/dist/undo-redo.d.ts +20 -0
  105. package/dist/undo-redo.js +33 -0
  106. package/dist/use-debounce.d.ts +9 -0
  107. package/dist/use-debounce.js +13 -0
  108. package/dist/utils.d.ts +58 -0
  109. package/dist/utils.js +72 -0
  110. package/package.json +52 -42
  111. package/CHANGELOG.json +0 -1
  112. package/CHANGELOG.md +0 -449
  113. package/lib/axis/arrow.js +0 -79
  114. package/lib/axis/arrow.js.map +0 -1
  115. package/lib/axis/axes.js +0 -327
  116. package/lib/axis/axes.js.map +0 -1
  117. package/lib/axis/index.js +0 -21
  118. package/lib/axis/index.js.map +0 -1
  119. package/lib/bg.js +0 -114
  120. package/lib/bg.js.map +0 -1
  121. package/lib/container/actions.js +0 -18
  122. package/lib/container/actions.js.map +0 -1
  123. package/lib/container/index.js +0 -129
  124. package/lib/container/index.js.map +0 -1
  125. package/lib/container/marks.js +0 -22
  126. package/lib/container/marks.js.map +0 -1
  127. package/lib/container/middleware.js +0 -19
  128. package/lib/container/middleware.js.map +0 -1
  129. package/lib/container/reducer.js +0 -18
  130. package/lib/container/reducer.js.map +0 -1
  131. package/lib/coordinates-label.js +0 -77
  132. package/lib/coordinates-label.js.map +0 -1
  133. package/lib/graph-with-controls.js +0 -297
  134. package/lib/graph-with-controls.js.map +0 -1
  135. package/lib/graph.js +0 -353
  136. package/lib/graph.js.map +0 -1
  137. package/lib/grid-setup.js +0 -414
  138. package/lib/grid-setup.js.map +0 -1
  139. package/lib/grid.js +0 -131
  140. package/lib/grid.js.map +0 -1
  141. package/lib/index.js +0 -40
  142. package/lib/index.js.map +0 -1
  143. package/lib/labels.js +0 -199
  144. package/lib/labels.js.map +0 -1
  145. package/lib/mark-label.js +0 -159
  146. package/lib/mark-label.js.map +0 -1
  147. package/lib/toggle-bar.js +0 -248
  148. package/lib/toggle-bar.js.map +0 -1
  149. package/lib/tool-menu.js +0 -218
  150. package/lib/tool-menu.js.map +0 -1
  151. package/lib/tools/index.js +0 -24
  152. package/lib/tools/index.js.map +0 -1
  153. package/lib/tools/line/component.js +0 -92
  154. package/lib/tools/line/component.js.map +0 -1
  155. package/lib/tools/line/index.js +0 -11
  156. package/lib/tools/line/index.js.map +0 -1
  157. package/lib/tools/polygon/component.js +0 -358
  158. package/lib/tools/polygon/component.js.map +0 -1
  159. package/lib/tools/polygon/index.js +0 -89
  160. package/lib/tools/polygon/index.js.map +0 -1
  161. package/lib/tools/polygon/line.js +0 -114
  162. package/lib/tools/polygon/line.js.map +0 -1
  163. package/lib/tools/polygon/polygon.js +0 -128
  164. package/lib/tools/polygon/polygon.js.map +0 -1
  165. package/lib/tools/shared/arrow-head.js +0 -62
  166. package/lib/tools/shared/arrow-head.js.map +0 -1
  167. package/lib/tools/shared/line/index.js +0 -539
  168. package/lib/tools/shared/line/index.js.map +0 -1
  169. package/lib/tools/shared/line/line-path.js +0 -121
  170. package/lib/tools/shared/line/line-path.js.map +0 -1
  171. package/lib/tools/shared/line/with-root-edge.js +0 -121
  172. package/lib/tools/shared/line/with-root-edge.js.map +0 -1
  173. package/lib/tools/shared/point/arrow-point.js +0 -86
  174. package/lib/tools/shared/point/arrow-point.js.map +0 -1
  175. package/lib/tools/shared/point/arrow.js +0 -70
  176. package/lib/tools/shared/point/arrow.js.map +0 -1
  177. package/lib/tools/shared/point/base-point.js +0 -137
  178. package/lib/tools/shared/point/base-point.js.map +0 -1
  179. package/lib/tools/shared/point/index.js +0 -80
  180. package/lib/tools/shared/point/index.js.map +0 -1
  181. package/lib/tools/shared/styles.js +0 -26
  182. package/lib/tools/shared/styles.js.map +0 -1
  183. package/lib/tools/shared/types.js +0 -15
  184. package/lib/tools/shared/types.js.map +0 -1
  185. package/lib/undo-redo.js +0 -67
  186. package/lib/undo-redo.js.map +0 -1
  187. package/lib/use-debounce.js +0 -25
  188. package/lib/use-debounce.js.map +0 -1
  189. package/lib/utils.js +0 -235
  190. package/lib/utils.js.map +0 -1
  191. package/src/__tests__/bg.test.jsx +0 -250
  192. package/src/__tests__/coordinates-label.test.jsx +0 -243
  193. package/src/__tests__/graph-with-controls.test.jsx +0 -184
  194. package/src/__tests__/graph.test.jsx +0 -93
  195. package/src/__tests__/grid-setup.test.jsx +0 -645
  196. package/src/__tests__/grid.test.jsx +0 -23
  197. package/src/__tests__/labels.test.jsx +0 -41
  198. package/src/__tests__/mark-label.test.jsx +0 -66
  199. package/src/__tests__/toggle-bar.test.jsx +0 -106
  200. package/src/__tests__/tool-menu.test.jsx +0 -453
  201. package/src/__tests__/undo-redo.test.jsx +0 -26
  202. package/src/__tests__/use-debounce.test.js +0 -21
  203. package/src/__tests__/utils.js +0 -41
  204. package/src/__tests__/utils.test.js +0 -105
  205. package/src/axis/__tests__/arrow.test.jsx +0 -43
  206. package/src/axis/__tests__/axes.test.jsx +0 -182
  207. package/src/axis/arrow.jsx +0 -57
  208. package/src/axis/axes.jsx +0 -284
  209. package/src/axis/index.js +0 -3
  210. package/src/bg.jsx +0 -96
  211. package/src/container/__tests__/actions.test.js +0 -105
  212. package/src/container/__tests__/index.test.jsx +0 -227
  213. package/src/container/__tests__/marks.test.js +0 -172
  214. package/src/container/__tests__/middleware.test.js +0 -235
  215. package/src/container/__tests__/reducer.test.js +0 -324
  216. package/src/container/actions.js +0 -8
  217. package/src/container/index.jsx +0 -93
  218. package/src/container/marks.js +0 -14
  219. package/src/container/middleware.js +0 -7
  220. package/src/container/reducer.js +0 -5
  221. package/src/coordinates-label.jsx +0 -62
  222. package/src/graph-with-controls.jsx +0 -242
  223. package/src/graph.jsx +0 -333
  224. package/src/grid-setup.jsx +0 -432
  225. package/src/grid.jsx +0 -133
  226. package/src/index.js +0 -7
  227. package/src/labels.jsx +0 -173
  228. package/src/mark-label.jsx +0 -125
  229. package/src/toggle-bar.jsx +0 -221
  230. package/src/tool-menu.jsx +0 -235
  231. package/src/tools/index.js +0 -8
  232. package/src/tools/line/__tests__/component.test.jsx +0 -37
  233. package/src/tools/line/component.jsx +0 -77
  234. package/src/tools/line/index.js +0 -4
  235. package/src/tools/polygon/__tests__/component.test.jsx +0 -487
  236. package/src/tools/polygon/__tests__/index.test.js +0 -65
  237. package/src/tools/polygon/__tests__/line.test.jsx +0 -23
  238. package/src/tools/polygon/__tests__/polygon.test.jsx +0 -44
  239. package/src/tools/polygon/component.jsx +0 -324
  240. package/src/tools/polygon/index.js +0 -52
  241. package/src/tools/polygon/line.jsx +0 -80
  242. package/src/tools/polygon/polygon.jsx +0 -93
  243. package/src/tools/shared/__tests__/arrow-head.test.jsx +0 -33
  244. package/src/tools/shared/arrow-head.jsx +0 -46
  245. package/src/tools/shared/line/__tests__/index.test.jsx +0 -553
  246. package/src/tools/shared/line/__tests__/line-path.test.jsx +0 -56
  247. package/src/tools/shared/line/__tests__/with-root-edge.test.jsx +0 -488
  248. package/src/tools/shared/line/index.jsx +0 -471
  249. package/src/tools/shared/line/line-path.jsx +0 -85
  250. package/src/tools/shared/line/with-root-edge.jsx +0 -97
  251. package/src/tools/shared/point/__tests__/arrow-point.test.jsx +0 -91
  252. package/src/tools/shared/point/__tests__/arrow.test.jsx +0 -469
  253. package/src/tools/shared/point/__tests__/base-point.test.jsx +0 -87
  254. package/src/tools/shared/point/arrow-point.jsx +0 -60
  255. package/src/tools/shared/point/arrow.jsx +0 -40
  256. package/src/tools/shared/point/base-point.jsx +0 -113
  257. package/src/tools/shared/point/index.jsx +0 -58
  258. package/src/tools/shared/styles.js +0 -20
  259. package/src/tools/shared/types.js +0 -8
  260. package/src/undo-redo.jsx +0 -37
  261. package/src/use-debounce.js +0 -13
  262. package/src/utils.js +0 -230
package/src/axis/index.js DELETED
@@ -1,3 +0,0 @@
1
- import Axes, { AxisPropTypes } from './axes';
2
-
3
- export { Axes, AxisPropTypes };
package/src/bg.jsx DELETED
@@ -1,96 +0,0 @@
1
- import React from 'react';
2
- import PropTypes from 'prop-types';
3
- import { pointer, select } from 'd3-selection';
4
- import { types, utils } from '@pie-lib/plot';
5
- import { getTickValues, thinnerShapesNeeded } from './utils';
6
-
7
- export default class Bg extends React.Component {
8
- static propTypes = {
9
- width: PropTypes.number.isRequired,
10
- height: PropTypes.number.isRequired,
11
- onClick: PropTypes.func.isRequired,
12
- graphProps: types.GraphPropsType.isRequired,
13
- };
14
-
15
- static defaultProps = {};
16
-
17
- componentDidMount() {
18
- const rect = select(this.rect);
19
-
20
- rect.on('click', (event) => this.onRectClick(rect, event));
21
- }
22
-
23
- shouldComponentUpdate(nextProps) {
24
- return (
25
- !utils.isDomainRangeEqual(this.props.graphProps, nextProps.graphProps) ||
26
- this.props.width !== nextProps.width ||
27
- this.props.height !== nextProps.height
28
- );
29
- }
30
-
31
- getRectPadding = () => {
32
- const { graphProps } = this.props;
33
-
34
- return thinnerShapesNeeded(graphProps) ? 6 : 10;
35
- };
36
-
37
- /**
38
- * Note: we use d3 click + pointer to give us domain values directly.
39
- * Saves us having to calculate them ourselves from a MouseEvent.
40
- */
41
- onRectClick = (rect, event) => {
42
- const { onClick, graphProps } = this.props;
43
- const { scale } = graphProps;
44
-
45
- const padding = this.getRectPadding();
46
- const coords = pointer(event, rect.node());
47
-
48
- // decrease the padding from coordinates to indicate the correct point clicked
49
- const x = scale.x.invert(coords[0] - padding);
50
- const y = scale.y.invert(coords[1] - padding);
51
-
52
- const rowTicks = getTickValues(graphProps.range);
53
- const columnTicks = getTickValues(graphProps.domain);
54
-
55
- const closest = (ticks, value) => {
56
- return (
57
- ticks.length &&
58
- ticks.reduce((prev, curr) => {
59
- const currentDistance = Math.abs(curr - value);
60
- const previousDistance = Math.abs(prev - value);
61
-
62
- return currentDistance <= previousDistance ? curr : prev;
63
- })
64
- );
65
- };
66
-
67
- let snapped = {};
68
-
69
- if (columnTicks.indexOf(x) >= 0 && rowTicks.indexOf(y) >= 0) {
70
- snapped.x = x;
71
- snapped.y = y;
72
- } else {
73
- snapped.x = closest(columnTicks, x);
74
- snapped.y = closest(rowTicks, y);
75
- }
76
-
77
- onClick(snapped);
78
- };
79
-
80
- render() {
81
- const { width, height } = this.props;
82
- const padding = this.getRectPadding();
83
-
84
- // expand the size of clickable area so a small area outside the edges of the grid lines to be clickable
85
- return (
86
- <rect
87
- ref={(rect) => (this.rect = rect)}
88
- transform={`translate(-${padding}, -${padding})`}
89
- fill="red"
90
- fillOpacity="0.0"
91
- width={width + padding * 2}
92
- height={height + padding * 2}
93
- />
94
- );
95
- }
96
- }
@@ -1,105 +0,0 @@
1
- import { addMark, changeMarks } from '../actions';
2
-
3
- describe('container actions', () => {
4
- describe('addMark', () => {
5
- it('creates ADD_MARK action', () => {
6
- const action = addMark();
7
- expect(action).toEqual({
8
- type: 'ADD_MARK',
9
- });
10
- });
11
-
12
- it('creates action without parameters', () => {
13
- const action = addMark();
14
- expect(action.type).toBe('ADD_MARK');
15
- expect(Object.keys(action)).toEqual(['type']);
16
- });
17
- });
18
-
19
- describe('changeMarks', () => {
20
- it('creates CHANGE_MARKS action with marks', () => {
21
- const marks = [{ id: 1, type: 'point' }];
22
- const action = changeMarks(marks);
23
-
24
- expect(action).toEqual({
25
- type: 'CHANGE_MARKS',
26
- marks,
27
- });
28
- });
29
-
30
- it('creates action with empty marks array', () => {
31
- const marks = [];
32
- const action = changeMarks(marks);
33
-
34
- expect(action).toEqual({
35
- type: 'CHANGE_MARKS',
36
- marks: [],
37
- });
38
- });
39
-
40
- it('creates action with multiple marks', () => {
41
- const marks = [
42
- { id: 1, type: 'point', x: 1, y: 2 },
43
- { id: 2, type: 'line', from: { x: 0, y: 0 }, to: { x: 5, y: 5 } },
44
- ];
45
- const action = changeMarks(marks);
46
-
47
- expect(action.marks).toEqual(marks);
48
- expect(action.marks.length).toBe(2);
49
- });
50
-
51
- it('creates action with null marks', () => {
52
- const marks = null;
53
- const action = changeMarks(marks);
54
-
55
- expect(action).toEqual({
56
- type: 'CHANGE_MARKS',
57
- marks: null,
58
- });
59
- });
60
-
61
- it('creates action with undefined marks', () => {
62
- const marks = undefined;
63
- const action = changeMarks(marks);
64
-
65
- expect(action).toEqual({
66
- type: 'CHANGE_MARKS',
67
- marks: undefined,
68
- });
69
- });
70
-
71
- it('preserves mark properties', () => {
72
- const marks = [
73
- {
74
- id: 1,
75
- type: 'point',
76
- x: 10,
77
- y: 20,
78
- label: 'A',
79
- correctness: { value: 'correct' },
80
- },
81
- ];
82
- const action = changeMarks(marks);
83
-
84
- expect(action.marks[0]).toEqual(marks[0]);
85
- expect(action.marks[0].correctness).toBeDefined();
86
- });
87
- });
88
-
89
- describe('action types', () => {
90
- it('has consistent action type strings', () => {
91
- const addMarkAction = addMark();
92
- const changeMarksAction = changeMarks([]);
93
-
94
- expect(typeof addMarkAction.type).toBe('string');
95
- expect(typeof changeMarksAction.type).toBe('string');
96
- });
97
-
98
- it('has unique action types', () => {
99
- const addMarkAction = addMark();
100
- const changeMarksAction = changeMarks([]);
101
-
102
- expect(addMarkAction.type).not.toBe(changeMarksAction.type);
103
- });
104
- });
105
- });
@@ -1,227 +0,0 @@
1
- import React from 'react';
2
- import { render } from '@pie-lib/test-utils';
3
- import Root, { GraphContainer } from '../index';
4
-
5
- jest.mock('../../graph-with-controls', () => {
6
- return function GraphWithControls({ marks, onChangeMarks, onUndo, onRedo, onReset, disabled }) {
7
- return (
8
- <div data-testid="graph-with-controls">
9
- <div data-testid="marks-count">{marks?.length || 0}</div>
10
- {disabled && <div data-testid="disabled-indicator">Disabled</div>}
11
- <button data-testid="change-marks" onClick={() => onChangeMarks && onChangeMarks([{ id: 1 }])}>
12
- Change
13
- </button>
14
- <button data-testid="undo" onClick={onUndo}>
15
- Undo
16
- </button>
17
- <button data-testid="redo" onClick={onRedo}>
18
- Redo
19
- </button>
20
- <button data-testid="reset" onClick={onReset}>
21
- Reset
22
- </button>
23
- </div>
24
- );
25
- };
26
- });
27
-
28
- jest.mock('@pie-lib/drag', () => ({
29
- DragProvider: ({ children }) => <div data-testid="drag-provider">{children}</div>,
30
- }));
31
-
32
- describe('Container Root Component', () => {
33
- const defaultProps = {
34
- marks: [],
35
- onChangeMarks: jest.fn(),
36
- };
37
-
38
- const renderComponent = (props = {}) => {
39
- return render(<Root {...defaultProps} {...props} />);
40
- };
41
-
42
- describe('rendering', () => {
43
- it('renders without crashing', () => {
44
- const { container } = renderComponent();
45
- expect(container).toBeInTheDocument();
46
- });
47
-
48
- it('renders GraphWithControls', () => {
49
- const { getByTestId } = renderComponent();
50
- expect(getByTestId('graph-with-controls')).toBeInTheDocument();
51
- });
52
-
53
- it('renders with Provider when no correctness set', () => {
54
- const { container } = renderComponent({ marks: [{ id: 1, type: 'point' }] });
55
- expect(container.querySelector('[data-testid="graph-with-controls"]')).toBeInTheDocument();
56
- });
57
-
58
- it('renders directly when correctness is set', () => {
59
- const marks = [{ id: 1, type: 'point', correctness: { value: 'correct' } }];
60
- const { getByTestId } = renderComponent({ marks });
61
-
62
- expect(getByTestId('graph-with-controls')).toBeInTheDocument();
63
- expect(getByTestId('disabled-indicator')).toBeInTheDocument();
64
- });
65
-
66
- it('passes marks to GraphWithControls', () => {
67
- const marks = [{ id: 1 }, { id: 2 }];
68
- const { getByTestId } = renderComponent({ marks });
69
- expect(getByTestId('marks-count')).toHaveTextContent('2');
70
- });
71
- });
72
-
73
- describe('componentDidUpdate', () => {
74
- it('updates store when marks prop changes', () => {
75
- const onChangeMarks = jest.fn();
76
- const { rerender } = render(<Root marks={[]} onChangeMarks={onChangeMarks} />);
77
-
78
- const newMarks = [{ id: 1, type: 'point' }];
79
- rerender(<Root marks={newMarks} onChangeMarks={onChangeMarks} />);
80
-
81
- expect(onChangeMarks).not.toHaveBeenCalled();
82
- });
83
-
84
- it('does not update when marks are equal', () => {
85
- const marks = [{ id: 1, type: 'point' }];
86
- const onChangeMarks = jest.fn();
87
- const { rerender } = render(<Root marks={marks} onChangeMarks={onChangeMarks} />);
88
-
89
- onChangeMarks.mockClear();
90
-
91
- rerender(<Root marks={marks} onChangeMarks={onChangeMarks} />);
92
-
93
- expect(onChangeMarks).not.toHaveBeenCalled();
94
- });
95
-
96
- it('handles marks changing from empty to non-empty', () => {
97
- const onChangeMarks = jest.fn();
98
- const { rerender } = render(<Root marks={[]} onChangeMarks={onChangeMarks} />);
99
-
100
- const newMarks = [{ id: 1 }];
101
-
102
- expect(() => {
103
- rerender(<Root marks={newMarks} onChangeMarks={onChangeMarks} />);
104
- }).not.toThrow();
105
- });
106
-
107
- it('handles marks changing from non-empty to empty', () => {
108
- const onChangeMarks = jest.fn();
109
- const { rerender } = render(<Root marks={[{ id: 1 }]} onChangeMarks={onChangeMarks} />);
110
-
111
- expect(() => {
112
- rerender(<Root marks={[]} onChangeMarks={onChangeMarks} />);
113
- }).not.toThrow();
114
- });
115
- });
116
-
117
- describe('correctness handling', () => {
118
- it('disables when any mark has correctness', () => {
119
- const marks = [
120
- { id: 1, type: 'point' },
121
- { id: 2, type: 'point', correctness: { value: 'correct' } },
122
- ];
123
- const { getByTestId } = renderComponent({ marks });
124
-
125
- expect(getByTestId('disabled-indicator')).toBeInTheDocument();
126
- });
127
-
128
- it('renders without Provider when correctness is set', () => {
129
- const marks = [{ id: 1, correctness: { value: 'correct' } }];
130
- const { container } = renderComponent({ marks });
131
-
132
- expect(container.querySelector('[data-testid="graph-with-controls"]')).toBeInTheDocument();
133
- });
134
-
135
- it('does not disable when no correctness is set', () => {
136
- const marks = [
137
- { id: 1, type: 'point' },
138
- { id: 2, type: 'line' },
139
- ];
140
- const { queryByTestId } = renderComponent({ marks });
141
-
142
- expect(queryByTestId('disabled-indicator')).not.toBeInTheDocument();
143
- });
144
-
145
- it('handles correctness with different values', () => {
146
- const marks = [{ id: 1, correctness: { value: 'incorrect' } }];
147
- const { getByTestId } = renderComponent({ marks });
148
-
149
- expect(getByTestId('disabled-indicator')).toBeInTheDocument();
150
- });
151
-
152
- it('handles empty correctness object', () => {
153
- const marks = [{ id: 1, correctness: {} }];
154
- const { getByTestId } = renderComponent({ marks });
155
-
156
- expect(getByTestId('disabled-indicator')).toBeInTheDocument();
157
- });
158
- });
159
-
160
- describe('props forwarding', () => {
161
- it('forwards additional props to GraphWithControls', () => {
162
- const { container } = renderComponent({
163
- className: 'custom-class',
164
- size: { width: 500, height: 500 },
165
- });
166
-
167
- expect(container.querySelector('[data-testid="graph-with-controls"]')).toBeInTheDocument();
168
- });
169
-
170
- it('does not forward onChangeMarks and marks to GraphWithControls', () => {
171
- const { getByTestId } = renderComponent({
172
- marks: [{ id: 1 }],
173
- onChangeMarks: jest.fn(),
174
- otherProp: 'test',
175
- });
176
-
177
- expect(getByTestId('graph-with-controls')).toBeInTheDocument();
178
- });
179
- });
180
-
181
- describe('edge cases', () => {
182
- it('handles empty marks array', () => {
183
- const { container } = renderComponent({ marks: [] });
184
- expect(container).toBeInTheDocument();
185
- });
186
-
187
- it('handles marks with complex structure', () => {
188
- const marks = [
189
- {
190
- id: 1,
191
- type: 'line',
192
- from: { x: 0, y: 0 },
193
- to: { x: 10, y: 10 },
194
- label: 'Line A',
195
- correctness: { value: 'correct', label: 'Correct!' },
196
- },
197
- ];
198
- const { getByTestId } = renderComponent({ marks });
199
- expect(getByTestId('graph-with-controls')).toBeInTheDocument();
200
- });
201
-
202
- it('handles switching between correctness states', () => {
203
- const { rerender } = render(<Root marks={[{ id: 1 }]} onChangeMarks={jest.fn()} />);
204
-
205
- rerender(<Root marks={[{ id: 1, correctness: { value: 'correct' } }]} onChangeMarks={jest.fn()} />);
206
-
207
- rerender(<Root marks={[{ id: 1 }]} onChangeMarks={jest.fn()} />);
208
-
209
- expect(document.querySelector('[data-testid="graph-with-controls"]')).toBeInTheDocument();
210
- });
211
- });
212
- });
213
-
214
- describe('GraphContainer (connected component)', () => {
215
- it('is a connected component', () => {
216
- expect(GraphContainer).toBeDefined();
217
- expect(GraphContainer.displayName).toContain('Connect');
218
- });
219
-
220
- it('maps state to props', () => {
221
- expect(GraphContainer).toBeDefined();
222
- });
223
-
224
- it('maps dispatch to props', () => {
225
- expect(GraphContainer).toBeDefined();
226
- });
227
- });
@@ -1,172 +0,0 @@
1
- import marks from '../marks';
2
-
3
- describe('marks reducer', () => {
4
- describe('initial state', () => {
5
- it('returns empty array as initial state', () => {
6
- const state = marks(undefined, { type: 'INIT' });
7
- expect(state).toEqual([]);
8
- });
9
-
10
- it('handles no state parameter', () => {
11
- const state = marks(undefined, { type: 'UNKNOWN_ACTION' });
12
- expect(Array.isArray(state)).toBe(true);
13
- });
14
- });
15
-
16
- describe('CHANGE_MARKS action', () => {
17
- it('updates state with new marks', () => {
18
- const initialState = [];
19
- const newMarks = [{ id: 1, type: 'point' }];
20
- const action = { type: 'CHANGE_MARKS', marks: newMarks };
21
-
22
- const state = marks(initialState, action);
23
- expect(state).toEqual(newMarks);
24
- });
25
-
26
- it('replaces existing marks', () => {
27
- const initialState = [{ id: 1, type: 'point' }];
28
- const newMarks = [{ id: 2, type: 'line' }];
29
- const action = { type: 'CHANGE_MARKS', marks: newMarks };
30
-
31
- const state = marks(initialState, action);
32
- expect(state).toEqual(newMarks);
33
- expect(state.length).toBe(1);
34
- expect(state[0].id).toBe(2);
35
- });
36
-
37
- it('handles empty marks array', () => {
38
- const initialState = [{ id: 1, type: 'point' }];
39
- const action = { type: 'CHANGE_MARKS', marks: [] };
40
-
41
- const state = marks(initialState, action);
42
- expect(state).toEqual([]);
43
- });
44
-
45
- it('handles multiple marks', () => {
46
- const initialState = [];
47
- const newMarks = [
48
- { id: 1, type: 'point', x: 1, y: 2 },
49
- { id: 2, type: 'line', from: { x: 0, y: 0 }, to: { x: 5, y: 5 } },
50
- { id: 3, type: 'circle', center: { x: 3, y: 3 }, radius: 2 },
51
- ];
52
- const action = { type: 'CHANGE_MARKS', marks: newMarks };
53
-
54
- const state = marks(initialState, action);
55
- expect(state).toEqual(newMarks);
56
- expect(state.length).toBe(3);
57
- });
58
-
59
- it('throws error when marks is not an array', () => {
60
- const initialState = [];
61
- const action = { type: 'CHANGE_MARKS', marks: 'not an array' };
62
-
63
- expect(() => marks(initialState, action)).toThrow('marks must be an array');
64
- });
65
-
66
- it('throws error when marks is null', () => {
67
- const initialState = [];
68
- const action = { type: 'CHANGE_MARKS', marks: null };
69
-
70
- expect(() => marks(initialState, action)).toThrow('marks must be an array');
71
- });
72
-
73
- it('throws error when marks is undefined', () => {
74
- const initialState = [];
75
- const action = { type: 'CHANGE_MARKS', marks: undefined };
76
-
77
- expect(() => marks(initialState, action)).toThrow('marks must be an array');
78
- });
79
-
80
- it('throws error when marks is an object', () => {
81
- const initialState = [];
82
- const action = { type: 'CHANGE_MARKS', marks: { id: 1 } };
83
-
84
- expect(() => marks(initialState, action)).toThrow('marks must be an array');
85
- });
86
-
87
- it('throws error when marks is a number', () => {
88
- const initialState = [];
89
- const action = { type: 'CHANGE_MARKS', marks: 123 };
90
-
91
- expect(() => marks(initialState, action)).toThrow('marks must be an array');
92
- });
93
-
94
- it('preserves mark properties', () => {
95
- const initialState = [];
96
- const newMarks = [
97
- {
98
- id: 1,
99
- type: 'point',
100
- x: 10,
101
- y: 20,
102
- label: 'A',
103
- correctness: { value: 'correct' },
104
- editable: true,
105
- interactive: true,
106
- },
107
- ];
108
- const action = { type: 'CHANGE_MARKS', marks: newMarks };
109
-
110
- const state = marks(initialState, action);
111
- expect(state[0]).toEqual(newMarks[0]);
112
- expect(state[0].correctness).toBeDefined();
113
- expect(state[0].editable).toBe(true);
114
- });
115
- });
116
-
117
- describe('unknown actions', () => {
118
- it('returns current state for unknown action', () => {
119
- const initialState = [{ id: 1, type: 'point' }];
120
- const action = { type: 'UNKNOWN_ACTION' };
121
-
122
- const state = marks(initialState, action);
123
- expect(state).toBe(initialState);
124
- });
125
-
126
- it('returns current state for ADD_MARK action', () => {
127
- const initialState = [{ id: 1, type: 'point' }];
128
- const action = { type: 'ADD_MARK' };
129
-
130
- const state = marks(initialState, action);
131
- expect(state).toBe(initialState);
132
- });
133
-
134
- it('does not modify state for unknown actions', () => {
135
- const initialState = [{ id: 1, type: 'point' }];
136
- const action = { type: 'SOME_OTHER_ACTION', data: 'test' };
137
-
138
- const state = marks(initialState, action);
139
- expect(state).toEqual(initialState);
140
- });
141
- });
142
-
143
- describe('immutability', () => {
144
- it('does not mutate original state', () => {
145
- const initialState = [{ id: 1, type: 'point' }];
146
- const originalState = [...initialState];
147
- const newMarks = [{ id: 2, type: 'line' }];
148
- const action = { type: 'CHANGE_MARKS', marks: newMarks };
149
-
150
- marks(initialState, action);
151
- expect(initialState).toEqual(originalState);
152
- });
153
-
154
- it('returns new array reference for CHANGE_MARKS', () => {
155
- const initialState = [{ id: 1, type: 'point' }];
156
- const newMarks = [{ id: 1, type: 'point' }];
157
- const action = { type: 'CHANGE_MARKS', marks: newMarks };
158
-
159
- const state = marks(initialState, action);
160
- expect(state).not.toBe(initialState);
161
- expect(state).toBe(newMarks);
162
- });
163
-
164
- it('returns same reference for unknown actions', () => {
165
- const initialState = [{ id: 1, type: 'point' }];
166
- const action = { type: 'UNKNOWN_ACTION' };
167
-
168
- const state = marks(initialState, action);
169
- expect(state).toBe(initialState);
170
- });
171
- });
172
- });