@pie-lib/graphing-solution-set 4.1.0-beta.9 → 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 (229) 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/axis/arrow.jsx +0 -57
  192. package/src/axis/axes.jsx +0 -284
  193. package/src/axis/index.js +0 -3
  194. package/src/bg.jsx +0 -96
  195. package/src/container/actions.js +0 -8
  196. package/src/container/index.jsx +0 -93
  197. package/src/container/marks.js +0 -14
  198. package/src/container/middleware.js +0 -7
  199. package/src/container/reducer.js +0 -5
  200. package/src/coordinates-label.jsx +0 -62
  201. package/src/graph-with-controls.jsx +0 -242
  202. package/src/graph.jsx +0 -333
  203. package/src/grid-setup.jsx +0 -432
  204. package/src/grid.jsx +0 -133
  205. package/src/index.js +0 -7
  206. package/src/labels.jsx +0 -173
  207. package/src/mark-label.jsx +0 -125
  208. package/src/toggle-bar.jsx +0 -221
  209. package/src/tool-menu.jsx +0 -235
  210. package/src/tools/index.js +0 -8
  211. package/src/tools/line/component.jsx +0 -77
  212. package/src/tools/line/index.js +0 -4
  213. package/src/tools/polygon/component.jsx +0 -324
  214. package/src/tools/polygon/index.js +0 -52
  215. package/src/tools/polygon/line.jsx +0 -80
  216. package/src/tools/polygon/polygon.jsx +0 -93
  217. package/src/tools/shared/arrow-head.jsx +0 -46
  218. package/src/tools/shared/line/index.jsx +0 -471
  219. package/src/tools/shared/line/line-path.jsx +0 -85
  220. package/src/tools/shared/line/with-root-edge.jsx +0 -97
  221. package/src/tools/shared/point/arrow-point.jsx +0 -60
  222. package/src/tools/shared/point/arrow.jsx +0 -40
  223. package/src/tools/shared/point/base-point.jsx +0 -113
  224. package/src/tools/shared/point/index.jsx +0 -58
  225. package/src/tools/shared/styles.js +0 -20
  226. package/src/tools/shared/types.js +0 -8
  227. package/src/undo-redo.jsx +0 -37
  228. package/src/use-debounce.js +0 -13
  229. package/src/utils.js +0 -230
package/src/axis/axes.jsx DELETED
@@ -1,284 +0,0 @@
1
- import React from 'react';
2
- import { Axis } from '@visx/axis';
3
- import { types } from '@pie-lib/plot';
4
- import PropTypes from 'prop-types';
5
- import Arrow from './arrow';
6
- import { styled } from '@mui/material/styles';
7
- import { amountToIncreaseWidth, countWords, findLongestWord, getTickValues } from '../utils';
8
- import { color, Readable } from '@pie-lib/render-ui';
9
-
10
- export const AxisPropTypes = {
11
- includeArrows: PropTypes.object,
12
- graphProps: PropTypes.object,
13
- };
14
-
15
- const AxisDefaultProps = {
16
- includeArrows: {
17
- left: true,
18
- right: true,
19
- up: true,
20
- down: true,
21
- },
22
- };
23
-
24
- const StyledAxesGroup = styled('g')(() => ({
25
- '& .visx-axis-line': {
26
- stroke: '#8a92c0',
27
- strokeWidth: 4,
28
- },
29
- '& .visx-axis-tick': {
30
- fill: color.defaults.BLACK,
31
- '& > line': {
32
- stroke: '#8a92c0',
33
- },
34
- },
35
- }));
36
-
37
- const AxisLabelHolder = styled('div')(({ theme, centered }) => ({
38
- padding: 0,
39
- margin: 0,
40
- '* > *': {
41
- margin: 0,
42
- padding: 0,
43
- },
44
- '& p': {
45
- margin: 0,
46
- },
47
- fontSize: theme.typography.fontSize,
48
- ...(centered && { textAlign: 'center' }),
49
- }));
50
-
51
- const StyledArrow = styled(Arrow)({
52
- fill: '#8a92c0',
53
- });
54
-
55
- const tickLabelStyles = {
56
- fontFamily: 'Roboto',
57
- fontSize: '14px',
58
- cursor: 'inherit',
59
- };
60
-
61
- export const sharedValues = (
62
- firstNegativeX,
63
- firstNegativeY,
64
- distanceFromOriginToFirstNegativeX,
65
- distanceFromOriginToFirstNegativeY,
66
- deltaAllowance,
67
- dy,
68
- ) => {
69
- let result = [];
70
-
71
- if (
72
- firstNegativeX === firstNegativeY &&
73
- distanceFromOriginToFirstNegativeX - deltaAllowance < distanceFromOriginToFirstNegativeY &&
74
- distanceFromOriginToFirstNegativeY < distanceFromOriginToFirstNegativeX + deltaAllowance &&
75
- distanceFromOriginToFirstNegativeX - deltaAllowance < dy &&
76
- dy < distanceFromOriginToFirstNegativeX + deltaAllowance
77
- ) {
78
- result.push(firstNegativeX);
79
- }
80
-
81
- return result;
82
- };
83
-
84
- export const firstNegativeValue = (interval) => (interval || []).find((element) => element < 0);
85
-
86
- export class RawXAxis extends React.Component {
87
- static propTypes = {
88
- ...AxisPropTypes,
89
- graphProps: types.GraphPropsType.isRequired,
90
- };
91
- static defaultProps = AxisDefaultProps;
92
-
93
- render() {
94
- const { includeArrows, graphProps, columnTicksValues, skipValues, distanceFromOriginToFirstNegativeY, dy } =
95
- this.props;
96
- const { scale, domain, size, range } = graphProps || {};
97
-
98
- const labelProps = (label) => {
99
- const y = skipValues && skipValues[0] === label ? distanceFromOriginToFirstNegativeY + 4 : dy;
100
-
101
- return {
102
- ...tickLabelStyles,
103
- textAnchor: 'middle',
104
- y: y,
105
- dx: label === 0 ? -10 : 0,
106
- dy: label === 0 ? -7 : 0,
107
- };
108
- };
109
-
110
- const necessaryRows = countWords(domain.axisLabel);
111
- const longestWord = findLongestWord(domain.axisLabel);
112
- const necessaryWidth = amountToIncreaseWidth(longestWord) + 2;
113
-
114
- return (
115
- <StyledAxesGroup>
116
- <Axis
117
- scale={scale.x}
118
- top={scale.y(0)}
119
- left={0}
120
- label={domain.label}
121
- rangePadding={8}
122
- tickFormat={(value) => value}
123
- tickLabelProps={labelProps}
124
- tickValues={columnTicksValues}
125
- hideZero={!(domain.labelStep || range.labelStep) && domain.min <= 0}
126
- />
127
- {includeArrows && includeArrows.left && <StyledArrow direction="left" x={domain.min} y={0} scale={scale} />}
128
- {includeArrows && includeArrows.right && <StyledArrow direction="right" x={domain.max} y={0} scale={scale} />}
129
- {domain.axisLabel && (
130
- <foreignObject x={size.width + 17} y={scale.y(0) - 9} width={necessaryWidth} height={20 * necessaryRows}>
131
- <Readable false>
132
- <AxisLabelHolder dangerouslySetInnerHTML={{ __html: domain.axisLabel }} />
133
- </Readable>
134
- </foreignObject>
135
- )}
136
- </StyledAxesGroup>
137
- );
138
- }
139
- }
140
-
141
- const XAxis = RawXAxis;
142
-
143
- export class RawYAxis extends React.Component {
144
- static propTypes = {
145
- ...AxisPropTypes,
146
- graphProps: types.GraphPropsType.isRequired,
147
- };
148
- static defaultProps = AxisDefaultProps;
149
-
150
- render() {
151
- const { includeArrows, graphProps, skipValues, rowTickValues } = this.props;
152
- const { scale, range, size } = graphProps || {};
153
-
154
- const necessaryWidth = range.axisLabel ? amountToIncreaseWidth(range.axisLabel.length) : 0;
155
-
156
- const customTickFormat = (value) => (skipValues && skipValues.indexOf(value) >= 0 ? '' : value);
157
-
158
- return (
159
- <StyledAxesGroup>
160
- <Axis
161
- orientation={'left'}
162
- scale={scale.y}
163
- top={0}
164
- height={size.height}
165
- left={scale.x(0)}
166
- label={range.label}
167
- labelProps={{ 'data-pie-readable': false }}
168
- rangePadding={8}
169
- tickLength={10}
170
- tickFormat={customTickFormat}
171
- tickLabelProps={(value) => {
172
- let digits = value.toLocaleString().replace(/[.-]/g, '').length || 1;
173
-
174
- return {
175
- ...tickLabelStyles,
176
- dy: 4,
177
- dx: -10 - digits * 9,
178
- 'data-pie-readable': false,
179
- };
180
- }}
181
- hideZero={true}
182
- tickTextAnchor={'bottom'}
183
- tickValues={rowTickValues}
184
- />
185
- {includeArrows && includeArrows.down && <StyledArrow direction="down" x={0} y={range.min} scale={scale} />}
186
- {includeArrows && includeArrows.up && <StyledArrow direction="up" x={0} y={range.max} scale={scale} />}
187
- {range.axisLabel && (
188
- <foreignObject x={scale.x(0) - necessaryWidth / 2} y={-33} width={necessaryWidth} height="20">
189
- <Readable false>
190
- <AxisLabelHolder centered dangerouslySetInnerHTML={{ __html: range.axisLabel }} />
191
- </Readable>
192
- </foreignObject>
193
- )}
194
- </StyledAxesGroup>
195
- );
196
- }
197
- }
198
-
199
- const YAxis = RawYAxis;
200
-
201
- export default class Axes extends React.Component {
202
- static propTypes = {
203
- ...AxisPropTypes,
204
- graphProps: types.GraphPropsType.isRequired,
205
- };
206
- static defaultProps = AxisDefaultProps;
207
-
208
- xValues = () => {
209
- const { graphProps } = this.props;
210
- const { scale, domain } = graphProps || {};
211
-
212
- if (!domain || !scale) {
213
- return;
214
- }
215
-
216
- const ticks = getTickValues({ ...domain, step: domain.labelStep });
217
- const negative = firstNegativeValue(ticks);
218
-
219
- return {
220
- columnTicksValues: ticks,
221
- firstNegativeX: negative,
222
- distanceFromOriginToFirstNegativeX: Math.abs(scale.y(0) - scale.y(negative)),
223
- };
224
- };
225
-
226
- yValues = () => {
227
- const { graphProps } = this.props;
228
- const { scale, range } = graphProps || {};
229
-
230
- if (!range || !scale) {
231
- return;
232
- }
233
-
234
- const ticks = getTickValues({ ...range, step: range.labelStep });
235
- const negative = firstNegativeValue(ticks);
236
-
237
- return {
238
- rowTickValues: ticks,
239
- firstNegativeY: negative,
240
- distanceFromOriginToFirstNegativeY: Math.abs(scale.x(0) - scale.x(negative)),
241
- };
242
- };
243
-
244
- render() {
245
- const { graphProps } = this.props;
246
- const { domain, range } = graphProps || {};
247
- const { columnTicksValues, firstNegativeX, distanceFromOriginToFirstNegativeX } = this.xValues();
248
- const { rowTickValues, firstNegativeY, distanceFromOriginToFirstNegativeY } = this.yValues();
249
- const deltaAllowance = 6;
250
- const dy = 25;
251
-
252
- const skipValues = sharedValues(
253
- firstNegativeX,
254
- firstNegativeY,
255
- distanceFromOriginToFirstNegativeX,
256
- distanceFromOriginToFirstNegativeY,
257
- deltaAllowance,
258
- dy,
259
- );
260
-
261
- // each axis has to be displayed only if the domain & range include it
262
- return (
263
- <StyledAxesGroup>
264
- {range.min <= 0 ? (
265
- <XAxis
266
- {...this.props}
267
- skipValues={skipValues}
268
- columnTicksValues={columnTicksValues}
269
- distanceFromOriginToFirstNegativeY={distanceFromOriginToFirstNegativeY}
270
- dy={dy}
271
- />
272
- ) : null}
273
- {domain.min <= 0 ? (
274
- <YAxis
275
- {...this.props}
276
- skipValues={skipValues}
277
- rowTickValues={rowTickValues}
278
- distanceFromOriginToFirstNegativeX={distanceFromOriginToFirstNegativeX}
279
- />
280
- ) : null}
281
- </StyledAxesGroup>
282
- );
283
- }
284
- }
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,8 +0,0 @@
1
- export const addMark = () => ({
2
- type: 'ADD_MARK',
3
- });
4
-
5
- export const changeMarks = (marks) => ({
6
- type: 'CHANGE_MARKS',
7
- marks,
8
- });
@@ -1,93 +0,0 @@
1
- import { connect, Provider } from 'react-redux';
2
- import React from 'react';
3
- import { applyMiddleware, createStore } from 'redux';
4
- import reducer from './reducer';
5
- import { changeMarks } from './actions';
6
- import PropTypes from 'prop-types';
7
- import { isEqual } from 'lodash-es';
8
- import { ActionCreators } from 'redux-undo';
9
- import GraphWithControls from '../graph-with-controls';
10
- import { getLastAction, lastActionMiddleware } from './middleware';
11
-
12
- const mapStateToProps = (s) => ({
13
- marks: s.marks.present,
14
- });
15
-
16
- const mapDispatchToProps = (dispatch) => ({
17
- onChangeMarks: (m) => dispatch(changeMarks(m)),
18
- onUndo: () => dispatch(ActionCreators.undo()),
19
- onRedo: () => dispatch(ActionCreators.redo()),
20
- onReset: () => dispatch(changeMarks([])),
21
- });
22
-
23
- export const GraphContainer = connect(mapStateToProps, mapDispatchToProps)(GraphWithControls);
24
-
25
- /**
26
- * The graph component entry point with undo/redo
27
- * Redux is an implementation detail, hide it in the react component.
28
- */
29
- class Root extends React.Component {
30
- static propTypes = {
31
- onChangeMarks: PropTypes.func,
32
- marks: PropTypes.array,
33
- };
34
-
35
- constructor(props) {
36
- super(props);
37
-
38
- const r = reducer();
39
- this.store = createStore(r, { marks: props.marks }, applyMiddleware(lastActionMiddleware));
40
-
41
- this.store.subscribe(this.onStoreChange);
42
- }
43
-
44
- componentDidUpdate(prevProps) {
45
- const { marks } = this.props;
46
- const storeState = this.store.getState();
47
-
48
- if (isEqual(storeState.marks.present, marks)) {
49
- return;
50
- }
51
-
52
- if (!isEqual(prevProps.marks, marks)) {
53
- // Don't dispatch marks that have correctness (evaluate mode marks) into the undo history.
54
- // These marks are already handled in render() via the correctnessSet path and bypass the
55
- // Redux store entirely. Dispatching them would pollute the undo history and cause the graph
56
- // to show the correct answer when the user presses undo after returning to gather mode.
57
- const hasCorrectness = marks && marks.find((m) => m.correctness);
58
-
59
- if (!hasCorrectness) {
60
- this.store.dispatch(changeMarks(marks));
61
- }
62
- }
63
- }
64
-
65
- onStoreChange = () => {
66
- const { marks, onChangeMarks } = this.props;
67
- const storeState = this.store.getState();
68
- const lastAction = getLastAction();
69
- const isUndoOperation = lastAction.type.includes('UNDO') || lastAction.type.includes('REDO');
70
-
71
- if (!isEqual(storeState.marks.present, marks)) {
72
- onChangeMarks(storeState.marks.present, isUndoOperation);
73
- }
74
- };
75
-
76
- render() {
77
- // eslint-disable-next-line no-unused-vars
78
- const { onChangeMarks, marks, ...rest } = this.props;
79
- const correctnessSet = marks && marks.find((m) => m.correctness);
80
-
81
- if (correctnessSet) {
82
- return <GraphWithControls {...rest} marks={marks} disabled={correctnessSet} />;
83
- }
84
-
85
- return (
86
- <Provider store={this.store}>
87
- <GraphContainer {...rest} />
88
- </Provider>
89
- );
90
- }
91
- }
92
-
93
- export default Root;
@@ -1,14 +0,0 @@
1
- const marks = (state = [], action) => {
2
- switch (action.type) {
3
- case 'CHANGE_MARKS':
4
- if (Array.isArray(action.marks)) {
5
- return action.marks;
6
- } else {
7
- throw new Error('marks must be an array');
8
- }
9
- default:
10
- return state;
11
- }
12
- };
13
-
14
- export default marks;
@@ -1,7 +0,0 @@
1
- let lastAction = null;
2
- export const getLastAction = () => lastAction;
3
-
4
- export const lastActionMiddleware = () => (next) => (action) => {
5
- lastAction = action;
6
- return next(action);
7
- };
@@ -1,5 +0,0 @@
1
- import { combineReducers } from 'redux';
2
- import marks from './marks';
3
- import undoable from 'redux-undo';
4
-
5
- export default () => combineReducers({ marks: undoable(marks, { debug: false }) });
@@ -1,62 +0,0 @@
1
- import React from 'react';
2
- import PropTypes from 'prop-types';
3
- import { types } from '@pie-lib/plot';
4
- import { color } from '@pie-lib/render-ui';
5
- import { styled } from '@mui/material/styles';
6
- import InputBase from '@mui/material/InputBase';
7
- import { roundNumber } from './utils';
8
-
9
- const StyledInputBase = styled(InputBase)(({ theme }) => ({
10
- fontFamily: theme.typography.fontFamily,
11
- fontSize: theme.typography.fontSize,
12
- borderRadius: '8px',
13
- background: theme.palette.common.white,
14
- color: color.defaults.BLACK,
15
- '& .MuiInputBase-input': {
16
- padding: 0,
17
- },
18
- }));
19
-
20
- export const getLabelPosition = (graphProps, x, y, labelLength) => {
21
- const { scale, domain, range } = graphProps;
22
- // treat corner cases for maximum and minimum
23
- const topShift = y === range.min ? 16 : y === range.max ? 0 : 8;
24
- const leftShift = 10;
25
- const rightEdge = scale.x(x) + labelLength + leftShift;
26
-
27
- if (rightEdge >= scale.x(domain.max)) {
28
- return {
29
- left: scale.x(x) - leftShift - labelLength,
30
- top: scale.y(y) - topShift,
31
- };
32
- }
33
-
34
- return {
35
- left: scale.x(x) + leftShift,
36
- top: scale.y(y) - topShift,
37
- };
38
- };
39
-
40
- export const CoordinatesLabel = ({ x, y, graphProps }) => {
41
- const label = `(${roundNumber(x)}, ${roundNumber(y)})`;
42
- const labelLength = (label.length || 0) * 6;
43
- const labelPosition = getLabelPosition(graphProps, x, y, labelLength);
44
-
45
- const style = {
46
- position: 'absolute',
47
- pointerEvents: 'auto',
48
- width: labelLength,
49
- padding: 0,
50
- ...labelPosition,
51
- };
52
-
53
- return <StyledInputBase style={style} value={label} inputProps={{ ariaLabel: 'naked' }} />;
54
- };
55
-
56
- CoordinatesLabel.propTypes = {
57
- graphProps: types.GraphPropsType,
58
- x: PropTypes.number,
59
- y: PropTypes.number,
60
- };
61
-
62
- export default CoordinatesLabel;