@pie-lib/charting 7.1.0-beta.9 → 8.0.0-next.20261002100925

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 (202) hide show
  1. package/dist/_virtual/_rolldown/runtime.js +20 -0
  2. package/dist/actions-button.d.ts +26 -0
  3. package/dist/actions-button.js +84 -0
  4. package/dist/autosize-input.d.ts +10 -0
  5. package/dist/autosize-input.js +66 -0
  6. package/dist/axes.d.ts +84 -0
  7. package/dist/axes.js +376 -0
  8. package/dist/bars/bar.d.ts +47 -0
  9. package/dist/bars/bar.js +27 -0
  10. package/dist/bars/common/bars.d.ts +98 -0
  11. package/dist/bars/common/bars.js +174 -0
  12. package/dist/bars/common/correct-check-icon.d.ts +18 -0
  13. package/dist/bars/common/correct-check-icon.js +50 -0
  14. package/dist/bars/histogram.d.ts +47 -0
  15. package/dist/bars/histogram.js +28 -0
  16. package/dist/chart-setup.d.ts +29 -0
  17. package/dist/chart-setup.js +231 -0
  18. package/dist/chart-type.d.ts +32 -0
  19. package/dist/chart-type.js +68 -0
  20. package/dist/chart-types.d.ts +41 -0
  21. package/dist/chart-types.js +17 -0
  22. package/dist/chart.d.ts +88 -0
  23. package/dist/chart.js +250 -0
  24. package/dist/common/correctness-indicators.d.ts +70 -0
  25. package/dist/common/correctness-indicators.js +106 -0
  26. package/dist/common/drag-handle.d.ts +129 -0
  27. package/dist/common/drag-handle.js +120 -0
  28. package/dist/common/drag-icon.d.ts +23 -0
  29. package/dist/common/drag-icon.js +45 -0
  30. package/dist/common/styles.d.ts +23 -0
  31. package/dist/common/styles.js +17 -0
  32. package/dist/grid.d.ts +45 -0
  33. package/dist/grid.js +56 -0
  34. package/dist/index.d.ts +14 -0
  35. package/dist/index.js +6 -0
  36. package/dist/key-legend.d.ts +19 -0
  37. package/dist/key-legend.js +46 -0
  38. package/dist/line/common/drag-handle.d.ts +120 -0
  39. package/dist/line/common/drag-handle.js +92 -0
  40. package/dist/line/common/line.d.ts +96 -0
  41. package/dist/line/common/line.js +114 -0
  42. package/dist/line/line-cross.d.ts +47 -0
  43. package/dist/line/line-cross.js +133 -0
  44. package/dist/line/line-dot.d.ts +47 -0
  45. package/dist/line/line-dot.js +101 -0
  46. package/dist/mark-label.d.ts +55 -0
  47. package/dist/mark-label.js +143 -0
  48. package/dist/node_modules/.bun/@visx_axis@4.0.0_d84c32d47042070f/node_modules/@visx/axis/esm/axis/Axis.js +67 -0
  49. package/dist/node_modules/.bun/@visx_axis@4.0.0_d84c32d47042070f/node_modules/@visx/axis/esm/axis/AxisBottom.js +29 -0
  50. package/dist/node_modules/.bun/@visx_axis@4.0.0_d84c32d47042070f/node_modules/@visx/axis/esm/axis/AxisLeft.js +30 -0
  51. package/dist/node_modules/.bun/@visx_axis@4.0.0_d84c32d47042070f/node_modules/@visx/axis/esm/axis/AxisRenderer.js +66 -0
  52. package/dist/node_modules/.bun/@visx_axis@4.0.0_d84c32d47042070f/node_modules/@visx/axis/esm/axis/Ticks.js +39 -0
  53. package/dist/node_modules/.bun/@visx_axis@4.0.0_d84c32d47042070f/node_modules/@visx/axis/esm/constants/orientation.js +9 -0
  54. package/dist/node_modules/.bun/@visx_axis@4.0.0_d84c32d47042070f/node_modules/@visx/axis/esm/utils/createPoint.js +14 -0
  55. package/dist/node_modules/.bun/@visx_axis@4.0.0_d84c32d47042070f/node_modules/@visx/axis/esm/utils/getAxisRangePaddingConfig.js +13 -0
  56. package/dist/node_modules/.bun/@visx_axis@4.0.0_d84c32d47042070f/node_modules/@visx/axis/esm/utils/getLabelTransform.js +16 -0
  57. package/dist/node_modules/.bun/@visx_axis@4.0.0_d84c32d47042070f/node_modules/@visx/axis/esm/utils/getTickFormatter.js +8 -0
  58. package/dist/node_modules/.bun/@visx_axis@4.0.0_d84c32d47042070f/node_modules/@visx/axis/esm/utils/getTickPosition.js +14 -0
  59. package/dist/node_modules/.bun/@visx_grid@4.0.0_d84c32d47042070f/node_modules/@visx/grid/esm/grids/GridColumns.js +46 -0
  60. package/dist/node_modules/.bun/@visx_grid@4.0.0_d84c32d47042070f/node_modules/@visx/grid/esm/grids/GridRows.js +46 -0
  61. package/dist/node_modules/.bun/@visx_grid@4.0.0_d84c32d47042070f/node_modules/@visx/grid/esm/utils/getScaleBandwidth.js +6 -0
  62. package/dist/node_modules/.bun/@visx_group@4.0.0_d84c32d47042070f/node_modules/@visx/group/esm/Group.js +17 -0
  63. package/dist/node_modules/.bun/@visx_point@4.0.0/node_modules/@visx/point/esm/Point.js +20 -0
  64. package/dist/node_modules/.bun/@visx_scale@4.0.0/node_modules/@visx/scale/esm/operators/align.js +6 -0
  65. package/dist/node_modules/.bun/@visx_scale@4.0.0/node_modules/@visx/scale/esm/operators/base.js +6 -0
  66. package/dist/node_modules/.bun/@visx_scale@4.0.0/node_modules/@visx/scale/esm/operators/clamp.js +6 -0
  67. package/dist/node_modules/.bun/@visx_scale@4.0.0/node_modules/@visx/scale/esm/operators/constant.js +6 -0
  68. package/dist/node_modules/.bun/@visx_scale@4.0.0/node_modules/@visx/scale/esm/operators/domain.js +6 -0
  69. package/dist/node_modules/.bun/@visx_scale@4.0.0/node_modules/@visx/scale/esm/operators/exponent.js +6 -0
  70. package/dist/node_modules/.bun/@visx_scale@4.0.0/node_modules/@visx/scale/esm/operators/interpolate.js +10 -0
  71. package/dist/node_modules/.bun/@visx_scale@4.0.0/node_modules/@visx/scale/esm/operators/nice.js +37 -0
  72. package/dist/node_modules/.bun/@visx_scale@4.0.0/node_modules/@visx/scale/esm/operators/padding.js +6 -0
  73. package/dist/node_modules/.bun/@visx_scale@4.0.0/node_modules/@visx/scale/esm/operators/range.js +6 -0
  74. package/dist/node_modules/.bun/@visx_scale@4.0.0/node_modules/@visx/scale/esm/operators/reverse.js +9 -0
  75. package/dist/node_modules/.bun/@visx_scale@4.0.0/node_modules/@visx/scale/esm/operators/round.js +7 -0
  76. package/dist/node_modules/.bun/@visx_scale@4.0.0/node_modules/@visx/scale/esm/operators/scaleOperator.js +56 -0
  77. package/dist/node_modules/.bun/@visx_scale@4.0.0/node_modules/@visx/scale/esm/operators/unknown.js +6 -0
  78. package/dist/node_modules/.bun/@visx_scale@4.0.0/node_modules/@visx/scale/esm/operators/zero.js +9 -0
  79. package/dist/node_modules/.bun/@visx_scale@4.0.0/node_modules/@visx/scale/esm/scales/band.js +9 -0
  80. package/dist/node_modules/.bun/@visx_scale@4.0.0/node_modules/@visx/scale/esm/scales/point.js +9 -0
  81. package/dist/node_modules/.bun/@visx_scale@4.0.0/node_modules/@visx/scale/esm/utils/coerceNumber.js +10 -0
  82. package/dist/node_modules/.bun/@visx_scale@4.0.0/node_modules/@visx/scale/esm/utils/createColorInterpolator.js +29 -0
  83. package/dist/node_modules/.bun/@visx_scale@4.0.0/node_modules/@visx/scale/esm/utils/getTicks.js +7 -0
  84. package/dist/node_modules/.bun/@visx_scale@4.0.0/node_modules/@visx/scale/esm/utils/isUtcScale.js +7 -0
  85. package/dist/node_modules/.bun/@visx_scale@4.0.0/node_modules/@visx/scale/esm/utils/toString.js +6 -0
  86. package/dist/node_modules/.bun/@visx_shape@4.0.0_d84c32d47042070f/node_modules/@visx/shape/esm/shapes/Bar.js +15 -0
  87. package/dist/node_modules/.bun/@visx_shape@4.0.0_d84c32d47042070f/node_modules/@visx/shape/esm/shapes/Circle.js +15 -0
  88. package/dist/node_modules/.bun/@visx_shape@4.0.0_d84c32d47042070f/node_modules/@visx/shape/esm/shapes/Line.js +27 -0
  89. package/dist/node_modules/.bun/@visx_shape@4.0.0_d84c32d47042070f/node_modules/@visx/shape/esm/shapes/LinePath.js +24 -0
  90. package/dist/node_modules/.bun/@visx_shape@4.0.0_d84c32d47042070f/node_modules/@visx/shape/esm/util/D3ShapeFactories.js +9 -0
  91. package/dist/node_modules/.bun/@visx_shape@4.0.0_d84c32d47042070f/node_modules/@visx/shape/esm/util/setNumberOrNumberAccessor.js +6 -0
  92. package/dist/node_modules/.bun/@visx_text@4.0.0_d84c32d47042070f/node_modules/@visx/text/esm/Text.js +27 -0
  93. package/dist/node_modules/.bun/@visx_text@4.0.0_d84c32d47042070f/node_modules/@visx/text/esm/hooks/useText.js +68 -0
  94. package/dist/node_modules/.bun/@visx_text@4.0.0_d84c32d47042070f/node_modules/@visx/text/esm/util/getStringWidth.js +19 -0
  95. package/dist/node_modules/.bun/@visx_text@4.0.0_d84c32d47042070f/node_modules/@visx/text/esm/util/memoize.js +13 -0
  96. package/dist/node_modules/.bun/@visx_vendor@4.0.0/node_modules/@visx/vendor/esm/d3-interpolate.js +8 -0
  97. package/dist/node_modules/.bun/@visx_vendor@4.0.0/node_modules/@visx/vendor/esm/d3-scale.js +8 -0
  98. package/dist/node_modules/.bun/@visx_vendor@4.0.0/node_modules/@visx/vendor/esm/d3-shape.js +8 -0
  99. package/dist/node_modules/.bun/@visx_vendor@4.0.0/node_modules/@visx/vendor/esm/d3-time.js +8 -0
  100. package/dist/node_modules/.bun/balanced-match@0.4.2/node_modules/balanced-match/index.js +32 -0
  101. package/dist/node_modules/.bun/balanced-match@1.0.2/node_modules/balanced-match/index.js +33 -0
  102. package/dist/node_modules/.bun/classnames@2.5.1/node_modules/classnames/index.js +32 -0
  103. package/dist/node_modules/.bun/clsx@2.1.1/node_modules/clsx/dist/clsx.js +16 -0
  104. package/dist/node_modules/.bun/math-expression-evaluator@1.4.0/node_modules/math-expression-evaluator/src/formula_evaluator.js +37 -0
  105. package/dist/node_modules/.bun/math-expression-evaluator@1.4.0/node_modules/math-expression-evaluator/src/lexer.js +509 -0
  106. package/dist/node_modules/.bun/math-expression-evaluator@1.4.0/node_modules/math-expression-evaluator/src/math_function.js +108 -0
  107. package/dist/node_modules/.bun/math-expression-evaluator@1.4.0/node_modules/math-expression-evaluator/src/postfix.js +31 -0
  108. package/dist/node_modules/.bun/math-expression-evaluator@1.4.0/node_modules/math-expression-evaluator/src/postfix_evaluator.js +45 -0
  109. package/dist/node_modules/.bun/reduce-css-calc@1.3.0/node_modules/reduce-css-calc/index.js +49 -0
  110. package/dist/node_modules/.bun/reduce-function-call@1.0.3/node_modules/reduce-function-call/index.js +34 -0
  111. package/dist/plot/common/plot.d.ts +103 -0
  112. package/dist/plot/common/plot.js +227 -0
  113. package/dist/plot/dot.d.ts +47 -0
  114. package/dist/plot/dot.js +62 -0
  115. package/dist/plot/line.d.ts +47 -0
  116. package/dist/plot/line.js +84 -0
  117. package/dist/utils.d.ts +39 -0
  118. package/dist/utils.js +101 -0
  119. package/package.json +45 -36
  120. package/CHANGELOG.json +0 -17
  121. package/CHANGELOG.md +0 -1116
  122. package/lib/actions-button.js +0 -145
  123. package/lib/actions-button.js.map +0 -1
  124. package/lib/axes.js +0 -643
  125. package/lib/axes.js.map +0 -1
  126. package/lib/bars/bar.js +0 -58
  127. package/lib/bars/bar.js.map +0 -1
  128. package/lib/bars/common/bars.js +0 -277
  129. package/lib/bars/common/bars.js.map +0 -1
  130. package/lib/bars/common/correct-check-icon.js +0 -54
  131. package/lib/bars/common/correct-check-icon.js.map +0 -1
  132. package/lib/bars/histogram.js +0 -59
  133. package/lib/bars/histogram.js.map +0 -1
  134. package/lib/chart-setup.js +0 -382
  135. package/lib/chart-setup.js.map +0 -1
  136. package/lib/chart-type.js +0 -80
  137. package/lib/chart-type.js.map +0 -1
  138. package/lib/chart-types.js +0 -22
  139. package/lib/chart-types.js.map +0 -1
  140. package/lib/chart.js +0 -384
  141. package/lib/chart.js.map +0 -1
  142. package/lib/common/correctness-indicators.js +0 -156
  143. package/lib/common/correctness-indicators.js.map +0 -1
  144. package/lib/common/drag-handle.js +0 -160
  145. package/lib/common/drag-handle.js.map +0 -1
  146. package/lib/common/drag-icon.js +0 -52
  147. package/lib/common/drag-icon.js.map +0 -1
  148. package/lib/common/styles.js +0 -22
  149. package/lib/common/styles.js.map +0 -1
  150. package/lib/grid.js +0 -112
  151. package/lib/grid.js.map +0 -1
  152. package/lib/index.js +0 -42
  153. package/lib/index.js.map +0 -1
  154. package/lib/key-legend.js +0 -87
  155. package/lib/key-legend.js.map +0 -1
  156. package/lib/line/common/drag-handle.js +0 -146
  157. package/lib/line/common/drag-handle.js.map +0 -1
  158. package/lib/line/common/line.js +0 -214
  159. package/lib/line/common/line.js.map +0 -1
  160. package/lib/line/line-cross.js +0 -214
  161. package/lib/line/line-cross.js.map +0 -1
  162. package/lib/line/line-dot.js +0 -158
  163. package/lib/line/line-dot.js.map +0 -1
  164. package/lib/mark-label.js +0 -237
  165. package/lib/mark-label.js.map +0 -1
  166. package/lib/plot/common/plot.js +0 -349
  167. package/lib/plot/common/plot.js.map +0 -1
  168. package/lib/plot/dot.js +0 -110
  169. package/lib/plot/dot.js.map +0 -1
  170. package/lib/plot/line.js +0 -140
  171. package/lib/plot/line.js.map +0 -1
  172. package/lib/tool-menu.js +0 -106
  173. package/lib/tool-menu.js.map +0 -1
  174. package/lib/utils.js +0 -189
  175. package/lib/utils.js.map +0 -1
  176. package/src/actions-button.jsx +0 -115
  177. package/src/axes.jsx +0 -594
  178. package/src/bars/bar.js +0 -28
  179. package/src/bars/common/bars.jsx +0 -249
  180. package/src/bars/common/correct-check-icon.jsx +0 -25
  181. package/src/bars/histogram.js +0 -28
  182. package/src/chart-setup.jsx +0 -356
  183. package/src/chart-type.js +0 -59
  184. package/src/chart-types.js +0 -8
  185. package/src/chart.jsx +0 -357
  186. package/src/common/correctness-indicators.jsx +0 -128
  187. package/src/common/drag-handle.jsx +0 -125
  188. package/src/common/drag-icon.jsx +0 -36
  189. package/src/common/styles.js +0 -19
  190. package/src/grid.jsx +0 -80
  191. package/src/index.js +0 -7
  192. package/src/key-legend.jsx +0 -77
  193. package/src/line/common/drag-handle.jsx +0 -114
  194. package/src/line/common/line.jsx +0 -171
  195. package/src/line/line-cross.js +0 -144
  196. package/src/line/line-dot.js +0 -111
  197. package/src/mark-label.jsx +0 -238
  198. package/src/plot/common/plot.jsx +0 -358
  199. package/src/plot/dot.js +0 -74
  200. package/src/plot/line.js +0 -98
  201. package/src/tool-menu.jsx +0 -85
  202. package/src/utils.js +0 -201
@@ -1,111 +0,0 @@
1
- import React from 'react';
2
- import PropTypes from 'prop-types';
3
- import { styled } from '@mui/material/styles';
4
-
5
- import { types } from '@pie-lib/plot';
6
- import { color } from '@pie-lib/render-ui';
7
- import { dataToXBand } from '../utils';
8
- import RawLine from './common/line';
9
- import { CorrectnessIndicator, SmallCorrectPointIndicator } from '../common/correctness-indicators';
10
-
11
- const StyledHandle = styled('circle')(() => ({}));
12
-
13
- const StyledTransparentHandle = styled('circle')(() => ({
14
- height: '20px',
15
- fill: 'transparent', // keep it invisible
16
- stroke: 'none',
17
- pointerEvents: 'auto', // allow drag events
18
- }));
19
-
20
- const DraggableComponent = ({ scale, x, y, r, correctness, interactive, correctData, label, ...rest }) => {
21
- const [isHovered, setIsHovered] = React.useState(false);
22
- const allowRolloverEvent = !correctness && interactive;
23
-
24
- return (
25
- <g
26
- onMouseEnter={() => setIsHovered(true)}
27
- onMouseLeave={() => setIsHovered(false)}
28
- onTouchStart={() => setIsHovered(true)}
29
- onTouchEnd={() => setIsHovered(false)}
30
- >
31
- <StyledTransparentHandle
32
- cx={scale.x(x)}
33
- cy={scale.y(y)}
34
- r={r * 3}
35
- onMouseEnter={() => setIsHovered(true)}
36
- onMouseLeave={() => setIsHovered(false)}
37
- {...rest}
38
- />
39
- <StyledHandle
40
- cx={scale.x(x)}
41
- cy={scale.y(y)}
42
- r={r}
43
- correctness={correctness}
44
- interactive={interactive}
45
- {...rest}
46
- />
47
- {/* show correctness indicators */}
48
- <CorrectnessIndicator scale={scale} x={x} y={y} r={r} correctness={correctness} interactive={interactive} />
49
-
50
- {/* show correct point if answer was incorrect */}
51
- <SmallCorrectPointIndicator
52
- scale={scale}
53
- x={x}
54
- r={r}
55
- correctness={correctness}
56
- correctData={correctData}
57
- label={label}
58
- />
59
-
60
- {/* show rollover rectangle */}
61
- {isHovered && allowRolloverEvent && (
62
- <rect
63
- x={scale.x(x) - r * 2}
64
- y={scale.y(y) - r * 2}
65
- width={r * 4}
66
- height={r * 4}
67
- stroke={color.defaults.BORDER_GRAY}
68
- strokeWidth="1"
69
- fill="none"
70
- />
71
- )}
72
- </g>
73
- );
74
- };
75
-
76
- DraggableComponent.propTypes = {
77
- scale: PropTypes.object,
78
- x: PropTypes.number,
79
- y: PropTypes.number,
80
- r: PropTypes.number,
81
- correctness: PropTypes.shape({
82
- value: PropTypes.string,
83
- label: PropTypes.string,
84
- }),
85
- interactive: PropTypes.bool,
86
- correctData: PropTypes.array,
87
- label: PropTypes.string,
88
- };
89
-
90
- export class LineDot extends React.Component {
91
- static propTypes = {
92
- data: PropTypes.array,
93
- onChange: PropTypes.func,
94
- graphProps: types.GraphPropsType.isRequired,
95
- };
96
-
97
- render() {
98
- const props = this.props;
99
- const { data, graphProps } = props;
100
- const { scale = {}, size = {} } = graphProps || {};
101
- const xBand = dataToXBand(scale.x, data, size.width, 'lineDot');
102
-
103
- return <RawLine {...props} xBand={xBand} CustomDraggableComponent={DraggableComponent} />;
104
- }
105
- }
106
-
107
- export default () => ({
108
- type: 'lineDot',
109
- Component: LineDot,
110
- name: 'Line Dot',
111
- });
@@ -1,238 +0,0 @@
1
- import React, { useCallback, useEffect, useRef, useState } from 'react';
2
- import classNames from 'classnames';
3
- import { styled } from '@mui/material/styles';
4
- import AutosizeInput from 'react-input-autosize';
5
- import PropTypes from 'prop-types';
6
-
7
- import { types } from '@pie-lib/plot';
8
- import { correct, disabled, incorrect } from './common/styles';
9
- import { color } from '@pie-lib/render-ui';
10
- import { renderMath } from '@pie-lib/math-rendering';
11
-
12
- const StyledContainer = styled('div')({
13
- display: 'flex',
14
- flexDirection: 'column',
15
- alignItems: 'center',
16
- });
17
-
18
- // eslint-disable-next-line no-unused-vars
19
- const StyledInput = styled('input')(({ theme }) => ({
20
- float: 'right',
21
- fontFamily: theme.typography.fontFamily,
22
- fontSize: theme.typography.fontSize,
23
- border: 'none',
24
- '&.correct': correct('color'),
25
- '&.incorrect': incorrect('color'),
26
- '&.disabledMarkLabel': {
27
- backgroundColor: 'transparent !important',
28
- },
29
- '&.error': { border: `2px solid ${theme.palette.error.main}` },
30
- }));
31
-
32
- const StyledMathInput = styled('div')(({ theme }) => ({
33
- pointerEvents: 'auto',
34
- textAlign: 'center',
35
- fontSize: theme.typography.fontSize + 2,
36
- fontFamily: theme.typography.fontFamily,
37
- color: color.primaryDark(),
38
- paddingTop: theme.typography.fontSize / 2,
39
- '&.disabledMarkLabel': {
40
- ...disabled('color'),
41
- backgroundColor: 'transparent !important',
42
- },
43
- '&.error': {
44
- border: `2px solid ${theme.palette.error.main}`,
45
- },
46
- '&.correct': {
47
- ...correct('color'),
48
- },
49
- '&.incorrect': {
50
- ...incorrect('color'),
51
- },
52
- }));
53
-
54
- function isFractionFormat(label) {
55
- const trimmedLabel = label?.trim() || '';
56
- const fracRegex = new RegExp(/^[1-9]*[0-9]*\s?[1-9][0-9]*\/[1-9][0-9]*$/);
57
- return fracRegex.test(trimmedLabel);
58
- }
59
-
60
- function getLabelMathFormat(label) {
61
- const trimmedLabel = label?.trim() || '';
62
- let fraction;
63
- let mixedNr = '';
64
- let improperFraction = trimmedLabel.split(' ');
65
- if (improperFraction[1] && improperFraction[1].includes('/')) {
66
- fraction = improperFraction[1].split('/') || '';
67
- } else {
68
- fraction = trimmedLabel?.split('/') || '';
69
- }
70
-
71
- let formattedLLabel;
72
- if (isFractionFormat(label)) {
73
- if (improperFraction[0] && improperFraction[1]) {
74
- mixedNr = improperFraction[0];
75
- }
76
- formattedLLabel = `\\(${mixedNr}\\frac{${fraction[0]}}{${fraction[1]}}\\)`;
77
- return formattedLLabel;
78
- }
79
- return undefined;
80
- }
81
-
82
- export const MarkLabel = (props) => {
83
- // eslint-disable-next-line no-unused-vars
84
- const [input, setInput] = useState(null);
85
- const _ref = useCallback((node) => setInput(node), null);
86
-
87
- const {
88
- mark = {},
89
- disabled,
90
- inputRef: externalInputRef,
91
- barWidth,
92
- rotate,
93
- correctness,
94
- autoFocus,
95
- error,
96
- isHiddenLabel,
97
- limitCharacters,
98
- correctnessIndicator,
99
- } = props;
100
-
101
- const [label, setLabel] = useState(mark.label);
102
- const [mathLabel, setMathLabel] = useState(getLabelMathFormat(mark.label));
103
- const [isEditing, setIsEditing] = useState(false);
104
- const rootRef = useRef(null);
105
-
106
- const onChange = (e) => {
107
- if (limitCharacters && e.target.value && e.target.value.length > 20) {
108
- return;
109
- }
110
-
111
- setLabel(e.target.value);
112
- };
113
-
114
- const isMathRendering = () => {
115
- return isEditing === false && mathLabel !== undefined;
116
- };
117
-
118
- const onChangeProp = (e) => {
119
- setMathLabel(getLabelMathFormat(mark.label));
120
- setIsEditing(false);
121
- props.onChange(e.target.value);
122
- };
123
- let extraStyle = {};
124
-
125
- if (rotate) {
126
- extraStyle = {
127
- width: 'unset',
128
- textAlign: 'left',
129
- };
130
- }
131
-
132
- // useState only sets the value once, to synch props to state need useEffect
133
- useEffect(() => {
134
- setLabel(mark.label);
135
- }, [mark.label]);
136
-
137
- useEffect(() => {
138
- const el = rootRef.current;
139
-
140
- if (el && mathLabel) {
141
- el.innerHTML = mathLabel;
142
- renderMath(el);
143
- }
144
- }, [label, mathLabel]);
145
-
146
- return (
147
- <StyledContainer>
148
- {correctnessIndicator}
149
- {isMathRendering() ? (
150
- <StyledMathInput
151
- ref={(r) => {
152
- rootRef.current = r;
153
- if (typeof externalInputRef === 'function') {
154
- externalInputRef(r);
155
- }
156
- }}
157
- className={classNames({
158
- disabledMarkLabel: disabled,
159
- error: error,
160
- correct: mark.editable && correctness?.label === 'correct',
161
- incorrect: mark.editable && correctness?.label === 'incorrect',
162
- })}
163
- onClick={() => setIsEditing(true)}
164
- style={{
165
- minWidth: barWidth,
166
- position: 'fixed',
167
- transformOrigin: 'left',
168
- transform: `rotate(${rotate}deg)`,
169
- visibility: isHiddenLabel ? 'hidden' : 'unset',
170
- marginTop: correctnessIndicator ? '24px' : '0',
171
- }}
172
- ></StyledMathInput>
173
- ) : (
174
- <AutosizeInput
175
- inputRef={(r) => {
176
- _ref(r);
177
- if (typeof externalInputRef === 'function') {
178
- externalInputRef(r);
179
- }
180
- }}
181
- name="mark-label-input"
182
- autoFocus={isEditing || autoFocus}
183
- disabled={disabled}
184
- inputClassName={classNames(
185
- correctness && mark.editable ? correctness.label : null,
186
- disabled && 'disabledMarkLabel',
187
- error && 'error',
188
- )}
189
- inputStyle={{
190
- minWidth: barWidth,
191
- textAlign: 'center',
192
- background: 'transparent',
193
- boxSizing: 'border-box',
194
- paddingLeft: 0,
195
- paddingRight: 0,
196
- border: 'none',
197
- ...extraStyle,
198
- }}
199
- value={label}
200
- style={{
201
- position: 'fixed',
202
- pointerEvents: 'auto',
203
- top: 0,
204
- left: 0,
205
- minWidth: barWidth,
206
- transformOrigin: 'left',
207
- transform: `rotate(${rotate}deg)`,
208
- visibility: isHiddenLabel ? 'hidden' : 'unset',
209
- marginTop: correctnessIndicator ? '24px' : '0',
210
- }}
211
- onChange={onChange}
212
- onBlur={onChangeProp}
213
- />
214
- )}
215
- </StyledContainer>
216
- );
217
- };
218
-
219
- MarkLabel.propTypes = {
220
- autoFocus: PropTypes.bool,
221
- disabled: PropTypes.bool,
222
- error: PropTypes.any,
223
- onChange: PropTypes.func,
224
- graphProps: types.GraphPropsType,
225
- inputRef: PropTypes.func,
226
- mark: PropTypes.object,
227
- barWidth: PropTypes.number,
228
- rotate: PropTypes.number,
229
- correctness: PropTypes.shape({
230
- value: PropTypes.string,
231
- label: PropTypes.string,
232
- }),
233
- isHiddenLabel: PropTypes.bool,
234
- limitCharacters: PropTypes.bool,
235
- correctnessIndicator: PropTypes.node,
236
- };
237
-
238
- export default MarkLabel;
@@ -1,358 +0,0 @@
1
- import React from 'react';
2
- import PropTypes from 'prop-types';
3
- import Check from '@mui/icons-material/Check';
4
- import { styled } from '@mui/material/styles';
5
- import { Group } from '@visx/group';
6
- import debug from 'debug';
7
-
8
- import { types } from '@pie-lib/plot';
9
- import DraggableHandle, { DragHandle } from '../../common/drag-handle';
10
- import { color } from '@pie-lib/render-ui';
11
- import { bandKey } from '../../utils';
12
- import { correct, incorrect } from '../../common/styles';
13
-
14
- const log = debug('pie-lib:chart:bars');
15
- const ICON_SIZE = 16; // 10px icon + 2px padding on all sides + 1px border
16
-
17
- export class RawPlot extends React.Component {
18
- static propTypes = {
19
- onChangeCategory: PropTypes.func,
20
- value: PropTypes.number,
21
- label: PropTypes.string,
22
- xBand: PropTypes.func,
23
- index: PropTypes.number.isRequired,
24
- graphProps: types.GraphPropsType.isRequired,
25
- CustomBarElement: PropTypes.func,
26
- interactive: PropTypes.bool,
27
- correctness: PropTypes.shape({
28
- value: PropTypes.string,
29
- label: PropTypes.string,
30
- }),
31
- defineChart: PropTypes.bool,
32
- correctData: PropTypes.arrayOf(
33
- PropTypes.shape({
34
- value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
35
- label: PropTypes.string,
36
- }),
37
- ),
38
- className: PropTypes.string,
39
- };
40
-
41
- constructor(props) {
42
- super(props);
43
- this.state = {
44
- dragValue: undefined,
45
- isHovered: false,
46
- };
47
- }
48
-
49
- handleMouseEnter = () => {
50
- this.setState({ isHovered: true });
51
- };
52
-
53
- handleMouseLeave = () => {
54
- this.setState({ isHovered: false });
55
- };
56
-
57
- setDragValue = (dragValue) => this.setState({ dragValue });
58
-
59
- dragStop = () => {
60
- const { label, onChangeCategory } = this.props;
61
- const { dragValue } = this.state;
62
- log('[dragStop]', dragValue);
63
-
64
- if (dragValue !== undefined) {
65
- onChangeCategory({ label, value: dragValue });
66
- }
67
-
68
- this.setDragValue(undefined);
69
- };
70
-
71
- dragValue = (existing, next) => {
72
- log('[dragValue] next:', next);
73
-
74
- this.setDragValue(next);
75
- };
76
-
77
- renderCorrectnessIcon = (barX, barWidth, correctVal, correctness, scale, pointHeight, pointDiameter) => {
78
- let iconY;
79
-
80
- if (correctVal === 0) {
81
- // if correct value is 0, position icon on the horizontal axis
82
- iconY = scale.y(0) - ICON_SIZE / 2;
83
- } else {
84
- const shapeIndex = correctVal - 1; // the index of the shape representing the correct value
85
- const shapeCenterY = scale.y(shapeIndex) - (pointHeight - pointDiameter) / 2 - pointDiameter / 2;
86
- iconY = shapeCenterY - ICON_SIZE / 2; // center the icon
87
- }
88
-
89
- return (
90
- <foreignObject x={barX + barWidth / 2 - ICON_SIZE / 2} y={iconY} width={ICON_SIZE} height={ICON_SIZE}>
91
- <Check className="correctnessIcon correctIcon smallIcon" title={correctness.label} />
92
- </foreignObject>
93
- );
94
- };
95
-
96
- render() {
97
- const {
98
- graphProps,
99
- value,
100
- label,
101
- xBand,
102
- index,
103
- CustomBarElement,
104
- interactive,
105
- correctness,
106
- defineChart,
107
- correctData,
108
- className,
109
- } = this.props;
110
-
111
- const { scale, range, size } = graphProps;
112
- const { max } = range || {};
113
- const { dragValue, isHovered } = this.state;
114
-
115
- const v = Number.isFinite(dragValue) ? dragValue : value;
116
- const barWidth = xBand.bandwidth();
117
- const barHeight = scale.y(range.max - v);
118
- const barX = xBand(bandKey({ label }, index));
119
-
120
- log('label:', label, 'barX:', barX, 'v: ', v, 'barHeight:', barHeight, 'barWidth: ', barWidth);
121
-
122
- const values = [];
123
-
124
- for (let i = 0; i < v; i++) {
125
- values.push(i);
126
- }
127
-
128
- const pointHeight = size.height / max;
129
- const pointDiameter = (pointHeight > barWidth ? barWidth : pointHeight) * 0.8;
130
- const Component = interactive ? DraggableHandle : DragHandle;
131
- const allowRolloverEvent = interactive && !correctness;
132
-
133
- return (
134
- <React.Fragment>
135
- <g
136
- className={className}
137
- onMouseEnter={this.handleMouseEnter}
138
- onMouseLeave={this.handleMouseLeave}
139
- onTouchStart={this.handleMouseEnter}
140
- onTouchEnd={this.handleMouseLeave}
141
- >
142
- {isHovered && allowRolloverEvent && (
143
- <rect
144
- x={barX}
145
- y={scale.y(v)}
146
- width={barWidth}
147
- height={values?.length ? pointHeight * values.length : 0}
148
- stroke={color.defaults.BORDER_GRAY}
149
- strokeWidth={'4px'}
150
- fill={'transparent'}
151
- />
152
- )}
153
- {values.map((index) =>
154
- CustomBarElement({
155
- index,
156
- pointDiameter,
157
- barX,
158
- barWidth,
159
- pointHeight,
160
- label,
161
- value,
162
- scale,
163
- }),
164
- )}
165
- {correctness &&
166
- correctness.value === 'incorrect' &&
167
- (() => {
168
- const correctVal = parseFloat(correctData[index] && correctData[index].value);
169
- if (isNaN(correctVal)) return null;
170
- const selectedVal = v;
171
-
172
- // special case: if correct value is 0, only show the icon on the axis
173
- if (correctVal === 0) {
174
- return this.renderCorrectnessIcon(
175
- barX,
176
- barWidth,
177
- correctVal,
178
- correctness,
179
- scale,
180
- pointHeight,
181
- pointDiameter,
182
- );
183
- }
184
-
185
- if (selectedVal > correctVal) {
186
- // selected is higher than correct: overlay the correct last segment
187
- const overlayValues = [];
188
- for (let i = 0; i < correctVal; i++) {
189
- overlayValues.push(i);
190
- }
191
- const lastIndexOfOverlay = overlayValues.length - 1;
192
- const lastOverlayValue = overlayValues[lastIndexOfOverlay];
193
- const barX = xBand(bandKey({ label }, index));
194
- const barWidth = xBand.bandwidth();
195
- const pointHeight = size.height / max;
196
- const pointDiameter = (pointHeight > barWidth ? barWidth : pointHeight) * 0.8;
197
- return (
198
- <>
199
- <CustomBarElement
200
- index={lastOverlayValue}
201
- pointDiameter={pointDiameter + 10} // increase point diameter for dotted line
202
- barX={barX}
203
- barWidth={barWidth}
204
- pointHeight={pointHeight}
205
- label={label}
206
- value={value}
207
- scale={scale}
208
- dottedOverline={true}
209
- />
210
- {this.renderCorrectnessIcon(
211
- barX,
212
- barWidth,
213
- correctVal,
214
- correctness,
215
- scale,
216
- pointHeight,
217
- pointDiameter,
218
- )}
219
- </>
220
- );
221
- }
222
- // selected is lower than correct, render missing segment below the correct bar
223
- const valuesToRender = [];
224
- for (let i = selectedVal; i < correctVal; i++) {
225
- valuesToRender.push(i);
226
- }
227
- return (
228
- <>
229
- {valuesToRender.map((idx) =>
230
- CustomBarElement({
231
- index: idx,
232
- pointDiameter,
233
- barX,
234
- barWidth,
235
- pointHeight,
236
- label,
237
- value,
238
- scale,
239
- dottedOverline: true,
240
- }),
241
- )}
242
- {this.renderCorrectnessIcon(
243
- barX,
244
- barWidth,
245
- correctVal,
246
- correctness,
247
- scale,
248
- pointHeight,
249
- pointDiameter,
250
- )}
251
- </>
252
- );
253
- })()}
254
- <Component
255
- x={barX}
256
- y={v}
257
- interactive={interactive}
258
- width={barWidth}
259
- onDrag={(v) => this.dragValue(value, v)}
260
- onDragStop={this.dragStop}
261
- graphProps={graphProps}
262
- correctness={correctness}
263
- isHovered={isHovered}
264
- defineChart={defineChart}
265
- color={color.primaryDark()}
266
- isPlot
267
- />
268
- </g>
269
- </React.Fragment>
270
- );
271
- }
272
- }
273
-
274
- const Bar = styled(RawPlot)(({ theme }) => ({
275
- '& .dot': {
276
- fill: color.visualElementsColors.PLOT_FILL_COLOR,
277
- '&.correct': correct('stroke'),
278
- '&.incorrect': incorrect('stroke'),
279
- },
280
- '& .dotColor': {
281
- fill: color.visualElementsColors.PLOT_FILL_COLOR,
282
- '&.correct': correct('fill'),
283
- '&.incorrect': incorrect('fill'),
284
- },
285
- '& .line': {
286
- stroke: color.visualElementsColors.PLOT_FILL_COLOR,
287
- '&.correct': correct('stroke'),
288
- '&.incorrect': incorrect('stroke'),
289
- },
290
- '& .correctIcon': {
291
- backgroundColor: color.correct(),
292
- },
293
- '& .incorrectIcon': {
294
- backgroundColor: color.incorrectWithIcon(),
295
- },
296
- '& .correctnessIcon': {
297
- borderRadius: theme.spacing(2),
298
- color: color.defaults.WHITE,
299
- fontSize: '16px',
300
- width: '16px',
301
- height: '16px',
302
- padding: '2px',
303
- border: `1px solid ${color.defaults.WHITE}`,
304
- stroke: 'initial',
305
- boxSizing: 'unset', // to override the default border-box in IBX
306
- display: 'block',
307
- },
308
- '& .smallIcon': {
309
- fontSize: '10px',
310
- width: '10px',
311
- height: '10px',
312
- },
313
- }));
314
-
315
- export class Plot extends React.Component {
316
- static propTypes = {
317
- data: PropTypes.array,
318
- onChangeCategory: PropTypes.func,
319
- xBand: PropTypes.func,
320
- graphProps: types.GraphPropsType.isRequired,
321
- defineChart: PropTypes.bool,
322
- CustomBarElement: PropTypes.func,
323
- correctData: PropTypes.arrayOf(
324
- PropTypes.shape({
325
- value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
326
- label: PropTypes.string,
327
- }),
328
- ),
329
- className: PropTypes.string,
330
- };
331
-
332
- render() {
333
- const { data, graphProps, xBand, CustomBarElement, onChangeCategory, defineChart, correctData } = this.props;
334
-
335
- return (
336
- <Group>
337
- {(data || []).map((d, index) => (
338
- <Bar
339
- value={d.value}
340
- label={d.label}
341
- interactive={defineChart || d.interactive}
342
- defineChart={defineChart}
343
- xBand={xBand}
344
- index={index}
345
- key={`bar-${d.label}-${d.value}-${index}`}
346
- onChangeCategory={(category) => onChangeCategory(index, category)}
347
- graphProps={graphProps}
348
- CustomBarElement={CustomBarElement}
349
- correctness={d.correctness}
350
- correctData={correctData}
351
- />
352
- ))}
353
- </Group>
354
- );
355
- }
356
- }
357
-
358
- export default Plot;