@pie-lib/charting 7.0.4-next.31 → 7.0.4-next.36

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 (272) hide show
  1. package/CHANGELOG.json +17 -0
  2. package/CHANGELOG.md +1116 -0
  3. package/LICENSE.md +5 -0
  4. package/lib/actions-button.js +145 -0
  5. package/lib/actions-button.js.map +1 -0
  6. package/lib/axes.js +643 -0
  7. package/lib/axes.js.map +1 -0
  8. package/lib/bars/bar.js +58 -0
  9. package/lib/bars/bar.js.map +1 -0
  10. package/lib/bars/common/bars.js +277 -0
  11. package/lib/bars/common/bars.js.map +1 -0
  12. package/lib/bars/common/correct-check-icon.js +54 -0
  13. package/lib/bars/common/correct-check-icon.js.map +1 -0
  14. package/lib/bars/histogram.js +59 -0
  15. package/lib/bars/histogram.js.map +1 -0
  16. package/lib/chart-setup.js +382 -0
  17. package/lib/chart-setup.js.map +1 -0
  18. package/lib/chart-type.js +80 -0
  19. package/lib/chart-type.js.map +1 -0
  20. package/lib/chart-types.js +22 -0
  21. package/lib/chart-types.js.map +1 -0
  22. package/lib/chart.js +384 -0
  23. package/lib/chart.js.map +1 -0
  24. package/lib/common/correctness-indicators.js +156 -0
  25. package/lib/common/correctness-indicators.js.map +1 -0
  26. package/lib/common/drag-handle.js +160 -0
  27. package/lib/common/drag-handle.js.map +1 -0
  28. package/lib/common/drag-icon.js +52 -0
  29. package/lib/common/drag-icon.js.map +1 -0
  30. package/lib/common/styles.js +22 -0
  31. package/lib/common/styles.js.map +1 -0
  32. package/lib/grid.js +112 -0
  33. package/lib/grid.js.map +1 -0
  34. package/lib/index.js +42 -0
  35. package/lib/index.js.map +1 -0
  36. package/lib/key-legend.js +87 -0
  37. package/lib/key-legend.js.map +1 -0
  38. package/lib/line/common/drag-handle.js +146 -0
  39. package/lib/line/common/drag-handle.js.map +1 -0
  40. package/lib/line/common/line.js +214 -0
  41. package/lib/line/common/line.js.map +1 -0
  42. package/lib/line/line-cross.js +214 -0
  43. package/lib/line/line-cross.js.map +1 -0
  44. package/lib/line/line-dot.js +158 -0
  45. package/lib/line/line-dot.js.map +1 -0
  46. package/lib/mark-label.js +237 -0
  47. package/lib/mark-label.js.map +1 -0
  48. package/lib/plot/common/plot.js +349 -0
  49. package/lib/plot/common/plot.js.map +1 -0
  50. package/lib/plot/dot.js +110 -0
  51. package/lib/plot/dot.js.map +1 -0
  52. package/lib/plot/line.js +140 -0
  53. package/lib/plot/line.js.map +1 -0
  54. package/lib/tool-menu.js +106 -0
  55. package/lib/tool-menu.js.map +1 -0
  56. package/lib/utils.js +189 -0
  57. package/lib/utils.js.map +1 -0
  58. package/package.json +28 -39
  59. package/src/__tests__/actions-button.test.jsx +280 -0
  60. package/src/__tests__/axes.test.jsx +667 -0
  61. package/src/__tests__/chart-setup.test.jsx +532 -0
  62. package/src/__tests__/chart-type.test.jsx +23 -0
  63. package/src/__tests__/chart.test.jsx +86 -0
  64. package/src/__tests__/grid.test.jsx +37 -0
  65. package/src/__tests__/key-legend.test.jsx +223 -0
  66. package/src/__tests__/mark-label.test.jsx +33 -0
  67. package/src/__tests__/tool-menu.test.jsx +522 -0
  68. package/src/__tests__/utils.js +36 -0
  69. package/src/__tests__/utils.test.js +100 -0
  70. package/src/actions-button.jsx +115 -0
  71. package/src/axes.jsx +594 -0
  72. package/src/bars/__tests__/bar.test.jsx +45 -0
  73. package/src/bars/__tests__/histogram.test.jsx +45 -0
  74. package/src/bars/__tests__/utils.js +30 -0
  75. package/src/bars/bar.js +28 -0
  76. package/src/bars/common/__tests__/bars.test.jsx +68 -0
  77. package/src/bars/common/__tests__/utils.js +30 -0
  78. package/src/bars/common/bars.jsx +249 -0
  79. package/src/bars/common/correct-check-icon.jsx +25 -0
  80. package/src/bars/histogram.js +28 -0
  81. package/src/chart-setup.jsx +356 -0
  82. package/src/chart-type.js +59 -0
  83. package/src/chart-types.js +8 -0
  84. package/src/chart.jsx +357 -0
  85. package/src/common/__tests__/correctness-indicators.test.jsx +720 -0
  86. package/src/common/__tests__/drag-handle.test.jsx +58 -0
  87. package/src/common/__tests__/utils.js +30 -0
  88. package/src/common/correctness-indicators.jsx +128 -0
  89. package/src/common/drag-handle.jsx +125 -0
  90. package/src/common/drag-icon.jsx +36 -0
  91. package/src/common/styles.js +19 -0
  92. package/src/grid.jsx +80 -0
  93. package/src/index.js +7 -0
  94. package/src/key-legend.jsx +77 -0
  95. package/src/line/__tests__/line-cross.test.jsx +463 -0
  96. package/src/line/__tests__/line-dot.test.jsx +41 -0
  97. package/src/line/__tests__/utils.js +36 -0
  98. package/src/line/common/__tests__/drag-handle.test.jsx +62 -0
  99. package/src/line/common/__tests__/line.test.jsx +79 -0
  100. package/src/line/common/__tests__/utils.js +30 -0
  101. package/src/line/common/drag-handle.jsx +114 -0
  102. package/src/line/common/line.jsx +171 -0
  103. package/src/line/line-cross.js +144 -0
  104. package/src/line/line-dot.js +111 -0
  105. package/src/mark-label.jsx +238 -0
  106. package/src/plot/__tests__/dot.test.jsx +344 -0
  107. package/src/plot/__tests__/line.test.jsx +375 -0
  108. package/src/plot/__tests__/utils.js +30 -0
  109. package/src/plot/common/__tests__/plot.test.jsx +69 -0
  110. package/src/plot/common/__tests__/utils.js +30 -0
  111. package/src/plot/common/plot.jsx +358 -0
  112. package/src/plot/dot.js +74 -0
  113. package/src/plot/line.js +98 -0
  114. package/src/tool-menu.jsx +85 -0
  115. package/src/utils.js +201 -0
  116. package/dist/_virtual/_rolldown/runtime.js +0 -23
  117. package/dist/actions-button.d.ts +0 -26
  118. package/dist/actions-button.js +0 -84
  119. package/dist/autosize-input.d.ts +0 -10
  120. package/dist/autosize-input.js +0 -66
  121. package/dist/axes.d.ts +0 -84
  122. package/dist/axes.js +0 -376
  123. package/dist/bars/bar.d.ts +0 -47
  124. package/dist/bars/bar.js +0 -27
  125. package/dist/bars/common/bars.d.ts +0 -98
  126. package/dist/bars/common/bars.js +0 -174
  127. package/dist/bars/common/correct-check-icon.d.ts +0 -18
  128. package/dist/bars/common/correct-check-icon.js +0 -50
  129. package/dist/bars/histogram.d.ts +0 -47
  130. package/dist/bars/histogram.js +0 -28
  131. package/dist/chart-setup.d.ts +0 -29
  132. package/dist/chart-setup.js +0 -231
  133. package/dist/chart-type.d.ts +0 -32
  134. package/dist/chart-type.js +0 -68
  135. package/dist/chart-types.d.ts +0 -41
  136. package/dist/chart-types.js +0 -17
  137. package/dist/chart.d.ts +0 -88
  138. package/dist/chart.js +0 -250
  139. package/dist/common/correctness-indicators.d.ts +0 -70
  140. package/dist/common/correctness-indicators.js +0 -106
  141. package/dist/common/drag-handle.d.ts +0 -129
  142. package/dist/common/drag-handle.js +0 -120
  143. package/dist/common/drag-icon.d.ts +0 -23
  144. package/dist/common/drag-icon.js +0 -45
  145. package/dist/common/styles.d.ts +0 -23
  146. package/dist/common/styles.js +0 -17
  147. package/dist/grid.d.ts +0 -45
  148. package/dist/grid.js +0 -56
  149. package/dist/index.d.ts +0 -14
  150. package/dist/index.js +0 -6
  151. package/dist/key-legend.d.ts +0 -19
  152. package/dist/key-legend.js +0 -46
  153. package/dist/line/common/drag-handle.d.ts +0 -120
  154. package/dist/line/common/drag-handle.js +0 -92
  155. package/dist/line/common/line.d.ts +0 -96
  156. package/dist/line/common/line.js +0 -114
  157. package/dist/line/line-cross.d.ts +0 -47
  158. package/dist/line/line-cross.js +0 -133
  159. package/dist/line/line-dot.d.ts +0 -47
  160. package/dist/line/line-dot.js +0 -101
  161. package/dist/mark-label.d.ts +0 -55
  162. package/dist/mark-label.js +0 -138
  163. package/dist/node_modules/.bun/@visx_axis@3.12.0_f4eacebf2041cd4f/node_modules/@visx/axis/esm/axis/Axis.js +0 -101
  164. package/dist/node_modules/.bun/@visx_axis@3.12.0_f4eacebf2041cd4f/node_modules/@visx/axis/esm/axis/AxisBottom.js +0 -46
  165. package/dist/node_modules/.bun/@visx_axis@3.12.0_f4eacebf2041cd4f/node_modules/@visx/axis/esm/axis/AxisLeft.js +0 -47
  166. package/dist/node_modules/.bun/@visx_axis@3.12.0_f4eacebf2041cd4f/node_modules/@visx/axis/esm/axis/AxisRenderer.js +0 -63
  167. package/dist/node_modules/.bun/@visx_axis@3.12.0_f4eacebf2041cd4f/node_modules/@visx/axis/esm/axis/Ticks.js +0 -44
  168. package/dist/node_modules/.bun/@visx_axis@3.12.0_f4eacebf2041cd4f/node_modules/@visx/axis/esm/constants/orientation.js +0 -9
  169. package/dist/node_modules/.bun/@visx_axis@3.12.0_f4eacebf2041cd4f/node_modules/@visx/axis/esm/utils/createPoint.js +0 -14
  170. package/dist/node_modules/.bun/@visx_axis@3.12.0_f4eacebf2041cd4f/node_modules/@visx/axis/esm/utils/getAxisRangePaddingConfig.js +0 -21
  171. package/dist/node_modules/.bun/@visx_axis@3.12.0_f4eacebf2041cd4f/node_modules/@visx/axis/esm/utils/getLabelTransform.js +0 -16
  172. package/dist/node_modules/.bun/@visx_axis@3.12.0_f4eacebf2041cd4f/node_modules/@visx/axis/esm/utils/getTickFormatter.js +0 -8
  173. package/dist/node_modules/.bun/@visx_axis@3.12.0_f4eacebf2041cd4f/node_modules/@visx/axis/esm/utils/getTickPosition.js +0 -15
  174. package/dist/node_modules/.bun/@visx_grid@3.12.0_f4eacebf2041cd4f/node_modules/@visx/grid/esm/grids/GridColumns.js +0 -79
  175. package/dist/node_modules/.bun/@visx_grid@3.12.0_f4eacebf2041cd4f/node_modules/@visx/grid/esm/grids/GridRows.js +0 -79
  176. package/dist/node_modules/.bun/@visx_grid@3.12.0_f4eacebf2041cd4f/node_modules/@visx/grid/esm/utils/getScaleBandwidth.js +0 -6
  177. package/dist/node_modules/.bun/@visx_group@3.12.0_f4eacebf2041cd4f/node_modules/@visx/group/esm/Group.js +0 -50
  178. package/dist/node_modules/.bun/@visx_point@3.12.0/node_modules/@visx/point/esm/Point.js +0 -18
  179. package/dist/node_modules/.bun/@visx_scale@3.12.0/node_modules/@visx/scale/esm/operators/align.js +0 -6
  180. package/dist/node_modules/.bun/@visx_scale@3.12.0/node_modules/@visx/scale/esm/operators/base.js +0 -6
  181. package/dist/node_modules/.bun/@visx_scale@3.12.0/node_modules/@visx/scale/esm/operators/clamp.js +0 -6
  182. package/dist/node_modules/.bun/@visx_scale@3.12.0/node_modules/@visx/scale/esm/operators/constant.js +0 -6
  183. package/dist/node_modules/.bun/@visx_scale@3.12.0/node_modules/@visx/scale/esm/operators/domain.js +0 -6
  184. package/dist/node_modules/.bun/@visx_scale@3.12.0/node_modules/@visx/scale/esm/operators/exponent.js +0 -6
  185. package/dist/node_modules/.bun/@visx_scale@3.12.0/node_modules/@visx/scale/esm/operators/interpolate.js +0 -10
  186. package/dist/node_modules/.bun/@visx_scale@3.12.0/node_modules/@visx/scale/esm/operators/nice.js +0 -37
  187. package/dist/node_modules/.bun/@visx_scale@3.12.0/node_modules/@visx/scale/esm/operators/padding.js +0 -6
  188. package/dist/node_modules/.bun/@visx_scale@3.12.0/node_modules/@visx/scale/esm/operators/range.js +0 -6
  189. package/dist/node_modules/.bun/@visx_scale@3.12.0/node_modules/@visx/scale/esm/operators/reverse.js +0 -9
  190. package/dist/node_modules/.bun/@visx_scale@3.12.0/node_modules/@visx/scale/esm/operators/round.js +0 -7
  191. package/dist/node_modules/.bun/@visx_scale@3.12.0/node_modules/@visx/scale/esm/operators/scaleOperator.js +0 -58
  192. package/dist/node_modules/.bun/@visx_scale@3.12.0/node_modules/@visx/scale/esm/operators/unknown.js +0 -6
  193. package/dist/node_modules/.bun/@visx_scale@3.12.0/node_modules/@visx/scale/esm/operators/zero.js +0 -9
  194. package/dist/node_modules/.bun/@visx_scale@3.12.0/node_modules/@visx/scale/esm/scales/band.js +0 -9
  195. package/dist/node_modules/.bun/@visx_scale@3.12.0/node_modules/@visx/scale/esm/scales/point.js +0 -9
  196. package/dist/node_modules/.bun/@visx_scale@3.12.0/node_modules/@visx/scale/esm/utils/coerceNumber.js +0 -10
  197. package/dist/node_modules/.bun/@visx_scale@3.12.0/node_modules/@visx/scale/esm/utils/createColorInterpolator.js +0 -29
  198. package/dist/node_modules/.bun/@visx_scale@3.12.0/node_modules/@visx/scale/esm/utils/getTicks.js +0 -9
  199. package/dist/node_modules/.bun/@visx_scale@3.12.0/node_modules/@visx/scale/esm/utils/isUtcScale.js +0 -7
  200. package/dist/node_modules/.bun/@visx_scale@3.12.0/node_modules/@visx/scale/esm/utils/toString.js +0 -6
  201. package/dist/node_modules/.bun/@visx_shape@3.12.0_f4eacebf2041cd4f/node_modules/@visx/shape/esm/shapes/Bar.js +0 -29
  202. package/dist/node_modules/.bun/@visx_shape@3.12.0_f4eacebf2041cd4f/node_modules/@visx/shape/esm/shapes/Circle.js +0 -29
  203. package/dist/node_modules/.bun/@visx_shape@3.12.0_f4eacebf2041cd4f/node_modules/@visx/shape/esm/shapes/Line.js +0 -47
  204. package/dist/node_modules/.bun/@visx_shape@3.12.0_f4eacebf2041cd4f/node_modules/@visx/shape/esm/shapes/LinePath.js +0 -50
  205. package/dist/node_modules/.bun/@visx_shape@3.12.0_f4eacebf2041cd4f/node_modules/@visx/shape/esm/util/D3ShapeFactories.js +0 -9
  206. package/dist/node_modules/.bun/@visx_shape@3.12.0_f4eacebf2041cd4f/node_modules/@visx/shape/esm/util/setNumberOrNumberAccessor.js +0 -6
  207. package/dist/node_modules/.bun/@visx_shape@3.12.0_f4eacebf2041cd4f/node_modules/@visx/shape/lib/shapes/Line.js +0 -53
  208. package/dist/node_modules/.bun/@visx_text@3.12.0_f4eacebf2041cd4f/node_modules/@visx/text/esm/Text.js +0 -57
  209. package/dist/node_modules/.bun/@visx_text@3.12.0_f4eacebf2041cd4f/node_modules/@visx/text/esm/hooks/useText.js +0 -91
  210. package/dist/node_modules/.bun/@visx_text@3.12.0_f4eacebf2041cd4f/node_modules/@visx/text/esm/util/getStringWidth.js +0 -21
  211. package/dist/node_modules/.bun/@visx_vendor@3.12.0/node_modules/@visx/vendor/esm/d3-interpolate.js +0 -8
  212. package/dist/node_modules/.bun/@visx_vendor@3.12.0/node_modules/@visx/vendor/esm/d3-scale.js +0 -8
  213. package/dist/node_modules/.bun/@visx_vendor@3.12.0/node_modules/@visx/vendor/esm/d3-time.js +0 -8
  214. package/dist/node_modules/.bun/balanced-match@0.4.2/node_modules/balanced-match/index.js +0 -32
  215. package/dist/node_modules/.bun/balanced-match@1.0.2/node_modules/balanced-match/index.js +0 -33
  216. package/dist/node_modules/.bun/classnames@2.5.1/node_modules/classnames/index.js +0 -32
  217. package/dist/node_modules/.bun/clsx@2.1.1/node_modules/clsx/dist/clsx.js +0 -16
  218. package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_Hash.js +0 -21
  219. package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_ListCache.js +0 -21
  220. package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_Map.js +0 -10
  221. package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_MapCache.js +0 -21
  222. package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_Symbol.js +0 -9
  223. package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_assocIndexOf.js +0 -14
  224. package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_baseGetTag.js +0 -15
  225. package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_baseIsNative.js +0 -16
  226. package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_coreJsData.js +0 -9
  227. package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_freeGlobal.js +0 -8
  228. package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_getMapData.js +0 -14
  229. package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_getNative.js +0 -15
  230. package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_getRawTag.js +0 -19
  231. package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_getValue.js +0 -11
  232. package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_hashClear.js +0 -13
  233. package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_hashDelete.js +0 -12
  234. package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_hashGet.js +0 -18
  235. package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_hashHas.js +0 -14
  236. package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_hashSet.js +0 -14
  237. package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_isKeyable.js +0 -12
  238. package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_isMasked.js +0 -16
  239. package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_listCacheClear.js +0 -11
  240. package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_listCacheDelete.js +0 -14
  241. package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_listCacheGet.js +0 -14
  242. package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_listCacheHas.js +0 -13
  243. package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_listCacheSet.js +0 -14
  244. package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_mapCacheClear.js +0 -19
  245. package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_mapCacheDelete.js +0 -14
  246. package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_mapCacheGet.js +0 -13
  247. package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_mapCacheHas.js +0 -13
  248. package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_mapCacheSet.js +0 -14
  249. package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_nativeCreate.js +0 -9
  250. package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_objectToString.js +0 -12
  251. package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_root.js +0 -10
  252. package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/_toSource.js +0 -20
  253. package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/eq.js +0 -11
  254. package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/isFunction.js +0 -16
  255. package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/isObject.js +0 -12
  256. package/dist/node_modules/.bun/lodash@4.17.21/node_modules/lodash/memoize.js +0 -20
  257. package/dist/node_modules/.bun/math-expression-evaluator@1.4.0/node_modules/math-expression-evaluator/src/formula_evaluator.js +0 -37
  258. package/dist/node_modules/.bun/math-expression-evaluator@1.4.0/node_modules/math-expression-evaluator/src/lexer.js +0 -509
  259. package/dist/node_modules/.bun/math-expression-evaluator@1.4.0/node_modules/math-expression-evaluator/src/math_function.js +0 -108
  260. package/dist/node_modules/.bun/math-expression-evaluator@1.4.0/node_modules/math-expression-evaluator/src/postfix.js +0 -31
  261. package/dist/node_modules/.bun/math-expression-evaluator@1.4.0/node_modules/math-expression-evaluator/src/postfix_evaluator.js +0 -45
  262. package/dist/node_modules/.bun/reduce-css-calc@1.3.0/node_modules/reduce-css-calc/index.js +0 -49
  263. package/dist/node_modules/.bun/reduce-function-call@1.0.3/node_modules/reduce-function-call/index.js +0 -34
  264. package/dist/plot/common/plot.d.ts +0 -103
  265. package/dist/plot/common/plot.js +0 -227
  266. package/dist/plot/dot.d.ts +0 -47
  267. package/dist/plot/dot.js +0 -62
  268. package/dist/plot/line.d.ts +0 -47
  269. package/dist/plot/line.js +0 -84
  270. package/dist/tool-menu.d.ts +0 -31
  271. package/dist/utils.d.ts +0 -39
  272. package/dist/utils.js +0 -101
@@ -0,0 +1,115 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import { styled } from '@mui/material/styles';
4
+ import Button from '@mui/material/Button';
5
+ import Popover from '@mui/material/Popover';
6
+ import Paper from '@mui/material/Paper';
7
+
8
+ import { color } from '@pie-lib/render-ui';
9
+ import Translator from '@pie-lib/translator';
10
+
11
+ const { translator } = Translator;
12
+
13
+ const StyledActions = styled('div')(() => ({
14
+ alignSelf: 'flex-end',
15
+ }));
16
+
17
+ const StyledTrigger = styled('div')(({ theme }) => ({
18
+ cursor: 'pointer',
19
+ fontSize: theme.typography.fontSize,
20
+ color: color.tertiary(),
21
+ padding: theme.spacing(1),
22
+ }));
23
+
24
+ const StyledActionsPaper = styled(Paper)(({ theme }) => ({
25
+ padding: theme.spacing(1),
26
+ display: 'flex',
27
+ flexDirection: 'column',
28
+ gap: theme.spacing(1),
29
+ '& button': {
30
+ textTransform: 'none',
31
+ fontSize: theme.typography.fontSize,
32
+ color: color.text(),
33
+ justifyContent: 'flex-start',
34
+ },
35
+ }));
36
+
37
+ export class ActionsButton extends React.Component {
38
+ constructor(props) {
39
+ super(props);
40
+ this.state = {
41
+ actionsAnchorEl: null,
42
+ };
43
+ }
44
+
45
+ componentWillUnmount() {
46
+ this.setState({ actionsAnchorEl: null });
47
+ }
48
+
49
+ static propTypes = {
50
+ addCategory: PropTypes.func.isRequired,
51
+ deleteCategory: PropTypes.func.isRequired,
52
+ language: PropTypes.string,
53
+ categories: PropTypes.array,
54
+ };
55
+
56
+ handleActionsClick = (event) => {
57
+ this.setState({ actionsAnchorEl: event.currentTarget });
58
+ };
59
+
60
+ handleActionsClose = () => {
61
+ this.setState({ actionsAnchorEl: null });
62
+ };
63
+
64
+ handleAddCategory = () => {
65
+ const { addCategory } = this.props;
66
+ addCategory();
67
+ this.handleActionsClose();
68
+ };
69
+
70
+ handleDeleteCategory = (index) => {
71
+ const { deleteCategory } = this.props;
72
+ deleteCategory(index);
73
+ this.handleActionsClose();
74
+ };
75
+
76
+ render() {
77
+ const { categories, language } = this.props;
78
+ const { actionsAnchorEl } = this.state;
79
+
80
+ return (
81
+ <StyledActions>
82
+ <StyledTrigger role="button" tabIndex={0} onClick={this.handleActionsClick}>
83
+ Actions
84
+ </StyledTrigger>
85
+ <Popover
86
+ key={`actions-popover-${Math.random()}`}
87
+ open={Boolean(actionsAnchorEl)}
88
+ anchorEl={actionsAnchorEl}
89
+ onClose={this.handleActionsClose}
90
+ anchorOrigin={{ vertical: 'bottom', horizontal: 'left' }}
91
+ transformOrigin={{ vertical: 'top', horizontal: 'left' }}
92
+ >
93
+ <StyledActionsPaper>
94
+ <Button onClick={() => this.handleAddCategory()}>
95
+ + {translator.t('charting.add', { lng: language })}
96
+ </Button>
97
+ {categories.length > 0 &&
98
+ categories.map(
99
+ (category, index) =>
100
+ category.deletable &&
101
+ !category.correctness && (
102
+ <Button key={index} onClick={() => this.handleDeleteCategory(index)}>
103
+ {`${translator.t('charting.delete', { lng: language })} <${category.label ||
104
+ translator.t('charting.newLabel', { lng: language })}>`}
105
+ </Button>
106
+ ),
107
+ )}
108
+ </StyledActionsPaper>
109
+ </Popover>
110
+ </StyledActions>
111
+ );
112
+ }
113
+ }
114
+
115
+ export default ActionsButton;
package/src/axes.jsx ADDED
@@ -0,0 +1,594 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import { styled } from '@mui/material/styles';
4
+ import { AxisBottom, AxisLeft } from '@visx/axis';
5
+ import Checkbox from '@mui/material/Checkbox';
6
+
7
+ import { types } from '@pie-lib/plot';
8
+ import { color } from '@pie-lib/render-ui';
9
+ import { AlertDialog } from '@pie-lib/config-ui';
10
+ import { renderMath } from '@pie-lib/math-rendering';
11
+
12
+ import { TickCorrectnessIndicator } from './common/correctness-indicators';
13
+ import { bandKey, getRotateAngle, getTickValues } from './utils';
14
+ import MarkLabel from './mark-label';
15
+
16
+ // one document-level MutationObserver shared across all
17
+ // RawChartAxes instances so that no chart misses a MathJax render batch
18
+ const _mathCallbacks = new Set();
19
+ let _docObserver = null;
20
+
21
+ function registerMathCallback(cb) {
22
+ _mathCallbacks.add(cb);
23
+
24
+ if (!_docObserver && typeof document !== 'undefined') {
25
+ _docObserver = new MutationObserver(() => {
26
+ _mathCallbacks.forEach((fn) => fn());
27
+ });
28
+ _docObserver.observe(document.body, { childList: true, subtree: true });
29
+ }
30
+ }
31
+
32
+ function unregisterMathCallback(cb) {
33
+ _mathCallbacks.delete(cb);
34
+
35
+ if (_mathCallbacks.size === 0 && _docObserver) {
36
+ _docObserver.disconnect();
37
+ _docObserver = null;
38
+ }
39
+ }
40
+
41
+ const StyledErrorText = styled('text')(({ theme }) => ({
42
+ fontSize: theme.typography.fontSize - 2,
43
+ fill: theme.palette.error.main,
44
+ }));
45
+
46
+ const StyledCheckbox = styled(Checkbox)(() => ({
47
+ color: `${color.tertiary()} !important`,
48
+ }));
49
+
50
+ const StyledAxesGroup = styled('g')(({ theme }) => ({
51
+ '& .vx-axis-line': {
52
+ stroke: color.visualElementsColors.AXIS_LINE_COLOR,
53
+ strokeWidth: 2,
54
+ },
55
+ '& .vx-axis-tick': {
56
+ fill: color.visualElementsColors.AXIS_TICK_COLOR,
57
+ '& line': {
58
+ stroke: color.visualElementsColors.AXIS_TICK_COLOR,
59
+ strokeWidth: 2,
60
+ },
61
+ fontFamily: theme.typography.body1?.fontFamily,
62
+ fontSize: theme.typography.fontSize,
63
+ textAnchor: 'middle',
64
+ },
65
+ }));
66
+
67
+ const correctnessIconStyles = (theme) => ({
68
+ borderRadius: theme.spacing(2),
69
+ color: color.defaults.WHITE,
70
+ fontSize: '16px',
71
+ width: '16px',
72
+ height: '16px',
73
+ padding: '2px',
74
+ border: `1px solid ${color.defaults.WHITE}`,
75
+ boxSizing: 'unset', // to override the default border-box in IBX
76
+ });
77
+
78
+ const incorrectIconStyles = {
79
+ backgroundColor: color.incorrectWithIcon(),
80
+ };
81
+
82
+ const correctIconStyles = {
83
+ backgroundColor: color.correct(),
84
+ };
85
+
86
+ export class TickComponent extends React.Component {
87
+ static propTypes = {
88
+ defineChart: PropTypes.bool,
89
+ error: PropTypes.any,
90
+ };
91
+
92
+ constructor(props) {
93
+ super(props);
94
+ this.state = {
95
+ dialog: {
96
+ open: false,
97
+ },
98
+ };
99
+ }
100
+
101
+ componentDidUpdate(prevProps) {
102
+ if (this.props.autoFocus && !prevProps.autoFocus) {
103
+ this.props.onAutoFocusUsed();
104
+ }
105
+ }
106
+
107
+ handleAlertDialog = (open, callback) =>
108
+ this.setState(
109
+ {
110
+ dialog: { open },
111
+ },
112
+ callback,
113
+ );
114
+
115
+ changeCategory = (index, newLabel) => {
116
+ const { categories, onChangeCategory } = this.props;
117
+ const category = categories[index];
118
+
119
+ onChangeCategory(index, { ...category, label: newLabel });
120
+ };
121
+
122
+ changeInteractive = (index, value) => {
123
+ const { categories, onChangeCategory } = this.props;
124
+ const category = categories[index];
125
+
126
+ if (!value) {
127
+ this.setState({
128
+ dialog: {
129
+ open: true,
130
+ title: 'Warning',
131
+ text: 'This will remove the correct answer value that has been defined for this category.',
132
+ onConfirm: () =>
133
+ this.handleAlertDialog(false, onChangeCategory(index, { ...category, interactive: !category.interactive })),
134
+ onClose: () => this.handleAlertDialog(false),
135
+ },
136
+ });
137
+ } else {
138
+ onChangeCategory(index, { ...category, interactive: !category.interactive });
139
+ }
140
+ };
141
+
142
+ changeEditable = (index, value) => {
143
+ const { categories, onChangeCategory } = this.props;
144
+ const category = categories[index];
145
+
146
+ if (!value) {
147
+ this.setState({
148
+ dialog: {
149
+ open: true,
150
+ title: 'Warning',
151
+ text: 'This will remove the correct answer category name that has been defined for this category.',
152
+ onConfirm: () =>
153
+ this.handleAlertDialog(
154
+ false,
155
+ onChangeCategory(index, { ...category, editable: !category.editable || false }),
156
+ ),
157
+ onClose: () => this.handleAlertDialog(false),
158
+ },
159
+ });
160
+ } else {
161
+ onChangeCategory(index, { ...category, editable: !category.editable || false });
162
+ }
163
+ };
164
+
165
+ splitText = (text, maxChar) => {
166
+ let chunks = [];
167
+ while ((text || '').length > 0) {
168
+ let indexToSplit;
169
+ if (text.length > maxChar) {
170
+ indexToSplit = text.lastIndexOf(' ', maxChar);
171
+ if (indexToSplit === -1) {
172
+ indexToSplit = maxChar;
173
+ }
174
+ } else {
175
+ indexToSplit = text.length;
176
+ }
177
+ chunks.push(text.substring(0, indexToSplit));
178
+ text = text.substring(indexToSplit).trim();
179
+ }
180
+ return chunks;
181
+ };
182
+
183
+ render() {
184
+ const {
185
+ categories,
186
+ xBand,
187
+ bandWidth,
188
+ barWidth,
189
+ rotate,
190
+ top,
191
+ graphProps,
192
+ defineChart,
193
+ chartingOptions,
194
+ x,
195
+ y,
196
+ formattedValue,
197
+ changeInteractiveEnabled,
198
+ changeEditableEnabled,
199
+ error,
200
+ autoFocus,
201
+ hiddenLabelRef,
202
+ showCorrectness,
203
+ } = this.props;
204
+
205
+ if (!formattedValue) {
206
+ return null;
207
+ }
208
+
209
+ // Create classes object for TickCorrectnessIndicator compatibility
210
+ const classes = {
211
+ correctnessIcon: correctnessIconStyles,
212
+ incorrectIcon: incorrectIconStyles,
213
+ correctIcon: correctIconStyles,
214
+ };
215
+
216
+ const { dialog } = this.state;
217
+ const { changeEditable, changeInteractive } = chartingOptions || {};
218
+ const index = parseInt(formattedValue.split('-')[0], 10);
219
+ const category = categories[index];
220
+ const { editable, interactive, label, correctness } = category || {};
221
+ const barX = xBand(bandKey({ label }, index));
222
+ const longestCategory = (categories || []).reduce(
223
+ (a, b) => {
224
+ const lengthA = a && a.label ? a.label.length : 0;
225
+ const lengthB = b && b.label ? b.label.length : 0;
226
+
227
+ return lengthA > lengthB ? a : b;
228
+ },
229
+ { label: '' },
230
+ );
231
+ const distinctMessages = error ? [...new Set(Object.values(error))].join(' ') : '';
232
+
233
+ return (
234
+ <g>
235
+ <foreignObject
236
+ x={bandWidth ? barX : x - barWidth / 2}
237
+ y={18}
238
+ width={barWidth}
239
+ height={4}
240
+ style={{ pointerEvents: 'none', overflow: 'visible' }}
241
+ >
242
+ {index === 0 && (
243
+ <MarkLabel
244
+ isHiddenLabel={true}
245
+ inputRef={hiddenLabelRef}
246
+ disabled={true}
247
+ mark={longestCategory}
248
+ graphProps={graphProps}
249
+ barWidth={barWidth}
250
+ />
251
+ )}
252
+
253
+ <MarkLabel
254
+ autoFocus={defineChart && autoFocus}
255
+ inputRef={(r) => (this.input = r)}
256
+ disabled={!defineChart && !editable}
257
+ mark={category}
258
+ graphProps={graphProps}
259
+ onChange={(newLabel) => this.changeCategory(index, newLabel)}
260
+ barWidth={barWidth}
261
+ rotate={rotate}
262
+ correctness={correctness}
263
+ error={error && error[index]}
264
+ limitCharacters
265
+ correctnessIndicator={
266
+ showCorrectness &&
267
+ correctness && (
268
+ <TickCorrectnessIndicator correctness={correctness} interactive={interactive} classes={classes} />
269
+ )
270
+ }
271
+ />
272
+ </foreignObject>
273
+
274
+ {error && index === 0 && (
275
+ <StyledErrorText y={y + 23} height={6} textAnchor="start">
276
+ {distinctMessages}
277
+ </StyledErrorText>
278
+ )}
279
+
280
+ {defineChart && index === 0 && (
281
+ <svg
282
+ x={-55}
283
+ style={{
284
+ overflow: 'visible',
285
+ }}
286
+ >
287
+ {changeInteractiveEnabled && (
288
+ <text
289
+ y={y + 90 + top}
290
+ width={barWidth}
291
+ height={4}
292
+ style={{
293
+ position: 'absolute',
294
+ pointerEvents: 'none',
295
+ wordBreak: 'break-word',
296
+ maxWidth: barWidth,
297
+ display: 'inline-block',
298
+ }}
299
+ >
300
+ {this.splitText(changeInteractive?.authoringLabel, 20).map((word, index) => (
301
+ <tspan key={index} x="0" dy={`${index > 0 ? '1.2em' : '.6em'}`}>
302
+ {word}
303
+ </tspan>
304
+ ))}
305
+ </text>
306
+ )}
307
+
308
+ {changeEditableEnabled && (
309
+ <text
310
+ y={y + 145 + top}
311
+ width={barWidth}
312
+ height={4}
313
+ style={{
314
+ position: 'absolute',
315
+ pointerEvents: 'none',
316
+ wordBreak: 'break-word',
317
+ maxWidth: barWidth,
318
+ display: 'inline-block',
319
+ }}
320
+ >
321
+ {this.splitText(changeEditable?.authoringLabel, 20).map((word, index) => (
322
+ <tspan key={index} x="0" dy={`${index > 0 ? '1.2em' : '.6em'}`}>
323
+ {word}
324
+ </tspan>
325
+ ))}
326
+ </text>
327
+ )}
328
+ </svg>
329
+ )}
330
+
331
+ {defineChart && changeInteractiveEnabled && (
332
+ <foreignObject
333
+ x={x - 24}
334
+ y={y + 80 + top}
335
+ width={barWidth}
336
+ height={4}
337
+ style={{ pointerEvents: 'visible', overflow: 'visible' }}
338
+ >
339
+ <StyledCheckbox
340
+ style={{ position: 'fixed' }}
341
+ checked={interactive}
342
+ onChange={(e) => this.changeInteractive(index, e.target.checked)}
343
+ />
344
+ </foreignObject>
345
+ )}
346
+
347
+ {defineChart && changeEditableEnabled && (
348
+ <foreignObject
349
+ x={x - 24}
350
+ y={y + 130 + top}
351
+ width={barWidth}
352
+ height={4}
353
+ style={{ pointerEvents: 'visible', overflow: 'visible' }}
354
+ >
355
+ <StyledCheckbox
356
+ style={{ position: 'fixed' }}
357
+ checked={editable}
358
+ onChange={(e) => this.changeEditable(index, e.target.checked)}
359
+ />
360
+ </foreignObject>
361
+ )}
362
+
363
+ <foreignObject
364
+ x={x - 24}
365
+ y={y + 100 + top}
366
+ width={barWidth}
367
+ height={4}
368
+ style={{ pointerEvents: 'visible', overflow: 'visible' }}
369
+ >
370
+ <AlertDialog
371
+ open={dialog.open}
372
+ title={dialog.title}
373
+ text={dialog.text}
374
+ onClose={dialog.onClose}
375
+ onConfirm={dialog.onConfirm}
376
+ />
377
+ </foreignObject>
378
+ </g>
379
+ );
380
+ }
381
+ }
382
+
383
+ TickComponent.propTypes = {
384
+ categories: PropTypes.array,
385
+ xBand: PropTypes.func,
386
+ bandWidth: PropTypes.number,
387
+ barWidth: PropTypes.number,
388
+ rotate: PropTypes.number,
389
+ top: PropTypes.number,
390
+ x: PropTypes.number,
391
+ y: PropTypes.number,
392
+ graphProps: PropTypes.object,
393
+ formattedValue: PropTypes.string,
394
+ onChangeCategory: PropTypes.func,
395
+ onChange: PropTypes.func,
396
+ error: PropTypes.object,
397
+ defineChart: PropTypes.bool,
398
+ chartingOptions: PropTypes.object,
399
+ changeInteractiveEnabled: PropTypes.bool,
400
+ changeEditableEnabled: PropTypes.bool,
401
+ autoFocus: PropTypes.bool,
402
+ onAutoFocusUsed: PropTypes.func,
403
+ showCorrectness: PropTypes.bool,
404
+ hiddenLabelRef: PropTypes.oneOfType([PropTypes.func, PropTypes.shape({ current: PropTypes.instanceOf(Element) })]),
405
+ };
406
+
407
+ export class RawChartAxes extends React.Component {
408
+ static propTypes = {
409
+ bottomScale: PropTypes.func,
410
+ categories: PropTypes.array,
411
+ defineChart: PropTypes.bool,
412
+ error: PropTypes.any,
413
+ graphProps: types.GraphPropsType.isRequired,
414
+ xBand: PropTypes.func,
415
+ leftAxis: PropTypes.bool,
416
+ onChange: PropTypes.func,
417
+ onChangeCategory: PropTypes.func,
418
+ top: PropTypes.number,
419
+ theme: PropTypes.object,
420
+ chartingOptions: PropTypes.object,
421
+ changeInteractiveEnabled: PropTypes.bool,
422
+ changeEditableEnabled: PropTypes.bool,
423
+ autoFocus: PropTypes.bool,
424
+ onAutoFocusUsed: PropTypes.func,
425
+ showCorrectness: PropTypes.bool,
426
+ hiddenLabelRef: PropTypes.oneOfType([PropTypes.func, PropTypes.shape({ current: PropTypes.instanceOf(Element) })]),
427
+ };
428
+
429
+ state = { height: 0, width: 0 };
430
+
431
+ measureHiddenLabel = () => {
432
+ if (!this.hiddenLabelRef) return;
433
+
434
+ const mjx = this.hiddenLabelRef.querySelector('mjx-container');
435
+ const input = this.hiddenLabelRef.querySelector('input');
436
+ const target = mjx || input || this.hiddenLabelRef;
437
+ const rect = target.getBoundingClientRect();
438
+ const height = Math.floor(rect.height);
439
+ const width = Math.floor(rect.width);
440
+
441
+ if (height !== this.state.height || width !== this.state.width) {
442
+ this.setState({ height, width });
443
+ }
444
+ };
445
+
446
+ // called by the document-level observer on every DOM mutation.
447
+ // only re-measures once mjx-container is present in our hidden label.
448
+ _onDocMutation = () => {
449
+ if (!this.hiddenLabelRef) return;
450
+ if (this.hiddenLabelRef.querySelector('mjx-container')) {
451
+ this.measureHiddenLabel();
452
+ }
453
+ };
454
+
455
+ observeHiddenLabel = (el) => {
456
+ if (!el) return;
457
+
458
+ const containsLatex = el.querySelector('[data-latex], [data-raw]');
459
+
460
+ if (containsLatex) {
461
+ renderMath(el);
462
+ }
463
+
464
+ if (el.querySelector('mjx-container') || !containsLatex) {
465
+ this.measureHiddenLabel();
466
+ }
467
+ // always register: if mjx-container isn't there yet, the doc observer will
468
+ // call _onDocMutation when MathJax finishes rendering any element on the page.
469
+ registerMathCallback(this._onDocMutation);
470
+ };
471
+
472
+ setHiddenLabelRef = (ref) => {
473
+ if (ref && ref !== this.hiddenLabelRef) {
474
+ this.hiddenLabelRef = ref;
475
+ this.observeHiddenLabel(ref);
476
+ }
477
+ };
478
+
479
+ componentDidMount() {
480
+ if (this.hiddenLabelRef) {
481
+ this.observeHiddenLabel(this.hiddenLabelRef);
482
+ }
483
+ }
484
+
485
+ componentWillUnmount() {
486
+ unregisterMathCallback(this._onDocMutation);
487
+ if (this._updateTimer) {
488
+ clearTimeout(this._updateTimer);
489
+ }
490
+ }
491
+
492
+ componentDidUpdate(prevProps) {
493
+ if (prevProps.categories !== this.props.categories) {
494
+ if (this._updateTimer) clearTimeout(this._updateTimer);
495
+ this._updateTimer = setTimeout(() => this.measureHiddenLabel(), 50);
496
+ }
497
+ }
498
+
499
+ render() {
500
+ const {
501
+ graphProps,
502
+ xBand,
503
+ leftAxis,
504
+ onChange,
505
+ onChangeCategory,
506
+ categories = [],
507
+ top,
508
+ defineChart,
509
+ chartingOptions,
510
+ changeInteractiveEnabled,
511
+ changeEditableEnabled,
512
+ theme,
513
+ autoFocus,
514
+ onAutoFocusUsed,
515
+ error,
516
+ showCorrectness,
517
+ } = this.props;
518
+
519
+ const { scale = {}, range = {}, domain = {}, size = {} } = graphProps || {};
520
+ const { height, width } = this.state;
521
+
522
+ const bottomScale = xBand && typeof xBand.rangeRound === 'function' && xBand.rangeRound([0, size.width]);
523
+
524
+ const bandWidth = xBand && typeof xBand.bandwidth === 'function' && xBand.bandwidth();
525
+ // for chartType "line", bandWidth will be 0, so we have to calculate it
526
+ const barWidth = bandWidth || (scale.x && scale.x(domain.max) / categories.length);
527
+
528
+ const rowTickValues = getTickValues({ ...range, step: range.labelStep });
529
+ const fontSize = theme && theme.typography ? theme.typography.fontSize : 14;
530
+ // this mostly applies for labels that are not editable
531
+ const rotateBecauseOfHeight = getRotateAngle(fontSize, height);
532
+ // this applies for labels that are editable
533
+ const rotateBecauseOfWidth = width > barWidth ? 25 : 0;
534
+
535
+ const getTickLabelProps = (value) => ({
536
+ dy: 4,
537
+ dx: -10 - (value.toLocaleString().length || 1) * 5,
538
+ });
539
+
540
+ const getTickComponent = (props) => {
541
+ const properties = {
542
+ hiddenLabelRef: this.setHiddenLabelRef,
543
+ categories,
544
+ xBand,
545
+ bandWidth,
546
+ barWidth,
547
+ rotate: rotateBecauseOfHeight || rotateBecauseOfWidth,
548
+ top,
549
+ defineChart,
550
+ chartingOptions,
551
+ autoFocus,
552
+ onAutoFocusUsed,
553
+ error,
554
+ onChangeCategory,
555
+ changeInteractiveEnabled,
556
+ changeEditableEnabled,
557
+ onChange,
558
+ graphProps,
559
+ x: props.x,
560
+ y: props.y,
561
+ formattedValue: props.formattedValue,
562
+ showCorrectness,
563
+ };
564
+
565
+ return <TickComponent {...properties} />;
566
+ };
567
+
568
+ return (
569
+ <StyledAxesGroup>
570
+ {leftAxis && (
571
+ <AxisLeft
572
+ scale={scale.y}
573
+ tickLength={10}
574
+ tickFormat={(value) => value}
575
+ tickValues={rowTickValues}
576
+ tickLabelProps={getTickLabelProps}
577
+ />
578
+ )}
579
+ <AxisBottom
580
+ scale={bottomScale}
581
+ labelProps={{ y: 60 + top }}
582
+ top={scale.y && scale.y(range.min)}
583
+ textLabelProps={() => ({ textAnchor: 'middle' })}
584
+ tickFormat={(count) => count}
585
+ tickComponent={getTickComponent}
586
+ autoFocus={autoFocus}
587
+ onAutoFocusUsed={onAutoFocusUsed}
588
+ />
589
+ </StyledAxesGroup>
590
+ );
591
+ }
592
+ }
593
+
594
+ export default RawChartAxes;