@pie-lib/charting 7.0.4-next.30 → 7.0.4-next.34

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.18.1/node_modules/lodash/_Hash.js +0 -21
  219. package/dist/node_modules/.bun/lodash@4.18.1/node_modules/lodash/_ListCache.js +0 -21
  220. package/dist/node_modules/.bun/lodash@4.18.1/node_modules/lodash/_Map.js +0 -10
  221. package/dist/node_modules/.bun/lodash@4.18.1/node_modules/lodash/_MapCache.js +0 -21
  222. package/dist/node_modules/.bun/lodash@4.18.1/node_modules/lodash/_Symbol.js +0 -9
  223. package/dist/node_modules/.bun/lodash@4.18.1/node_modules/lodash/_assocIndexOf.js +0 -14
  224. package/dist/node_modules/.bun/lodash@4.18.1/node_modules/lodash/_baseGetTag.js +0 -15
  225. package/dist/node_modules/.bun/lodash@4.18.1/node_modules/lodash/_baseIsNative.js +0 -16
  226. package/dist/node_modules/.bun/lodash@4.18.1/node_modules/lodash/_coreJsData.js +0 -9
  227. package/dist/node_modules/.bun/lodash@4.18.1/node_modules/lodash/_freeGlobal.js +0 -8
  228. package/dist/node_modules/.bun/lodash@4.18.1/node_modules/lodash/_getMapData.js +0 -14
  229. package/dist/node_modules/.bun/lodash@4.18.1/node_modules/lodash/_getNative.js +0 -15
  230. package/dist/node_modules/.bun/lodash@4.18.1/node_modules/lodash/_getRawTag.js +0 -19
  231. package/dist/node_modules/.bun/lodash@4.18.1/node_modules/lodash/_getValue.js +0 -11
  232. package/dist/node_modules/.bun/lodash@4.18.1/node_modules/lodash/_hashClear.js +0 -13
  233. package/dist/node_modules/.bun/lodash@4.18.1/node_modules/lodash/_hashDelete.js +0 -12
  234. package/dist/node_modules/.bun/lodash@4.18.1/node_modules/lodash/_hashGet.js +0 -18
  235. package/dist/node_modules/.bun/lodash@4.18.1/node_modules/lodash/_hashHas.js +0 -14
  236. package/dist/node_modules/.bun/lodash@4.18.1/node_modules/lodash/_hashSet.js +0 -14
  237. package/dist/node_modules/.bun/lodash@4.18.1/node_modules/lodash/_isKeyable.js +0 -12
  238. package/dist/node_modules/.bun/lodash@4.18.1/node_modules/lodash/_isMasked.js +0 -16
  239. package/dist/node_modules/.bun/lodash@4.18.1/node_modules/lodash/_listCacheClear.js +0 -11
  240. package/dist/node_modules/.bun/lodash@4.18.1/node_modules/lodash/_listCacheDelete.js +0 -14
  241. package/dist/node_modules/.bun/lodash@4.18.1/node_modules/lodash/_listCacheGet.js +0 -14
  242. package/dist/node_modules/.bun/lodash@4.18.1/node_modules/lodash/_listCacheHas.js +0 -13
  243. package/dist/node_modules/.bun/lodash@4.18.1/node_modules/lodash/_listCacheSet.js +0 -14
  244. package/dist/node_modules/.bun/lodash@4.18.1/node_modules/lodash/_mapCacheClear.js +0 -19
  245. package/dist/node_modules/.bun/lodash@4.18.1/node_modules/lodash/_mapCacheDelete.js +0 -14
  246. package/dist/node_modules/.bun/lodash@4.18.1/node_modules/lodash/_mapCacheGet.js +0 -13
  247. package/dist/node_modules/.bun/lodash@4.18.1/node_modules/lodash/_mapCacheHas.js +0 -13
  248. package/dist/node_modules/.bun/lodash@4.18.1/node_modules/lodash/_mapCacheSet.js +0 -14
  249. package/dist/node_modules/.bun/lodash@4.18.1/node_modules/lodash/_nativeCreate.js +0 -9
  250. package/dist/node_modules/.bun/lodash@4.18.1/node_modules/lodash/_objectToString.js +0 -12
  251. package/dist/node_modules/.bun/lodash@4.18.1/node_modules/lodash/_root.js +0 -10
  252. package/dist/node_modules/.bun/lodash@4.18.1/node_modules/lodash/_toSource.js +0 -20
  253. package/dist/node_modules/.bun/lodash@4.18.1/node_modules/lodash/eq.js +0 -11
  254. package/dist/node_modules/.bun/lodash@4.18.1/node_modules/lodash/isFunction.js +0 -16
  255. package/dist/node_modules/.bun/lodash@4.18.1/node_modules/lodash/isObject.js +0 -12
  256. package/dist/node_modules/.bun/lodash@4.18.1/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,30 @@
1
+ export const scaleMock = () => {
2
+ const fn = jest.fn((n) => n);
3
+ fn.invert = jest.fn((n) => n);
4
+ return fn;
5
+ };
6
+
7
+ export const graphProps = (dmin = 0, dmax = 1, rmin = 0, rmax = 1) => ({
8
+ scale: {
9
+ x: scaleMock(),
10
+ y: scaleMock(),
11
+ },
12
+ snap: {
13
+ x: jest.fn((n) => n),
14
+ y: jest.fn((n) => n),
15
+ },
16
+ domain: {
17
+ min: dmin,
18
+ max: dmax,
19
+ step: 1,
20
+ },
21
+ range: {
22
+ min: rmin,
23
+ max: rmax,
24
+ step: 1,
25
+ },
26
+ size: {
27
+ width: 400,
28
+ height: 400,
29
+ },
30
+ });
@@ -0,0 +1,114 @@
1
+ import React from 'react';
2
+ import classNames from 'classnames';
3
+ import PropTypes from 'prop-types';
4
+ import { styled } from '@mui/material/styles';
5
+
6
+ import { gridDraggable, types, utils } from '@pie-lib/plot';
7
+ import { color } from '@pie-lib/render-ui';
8
+ import { disabled } from '../../common/styles';
9
+
10
+ const StyledDragHandle = styled('g')(({ theme }) => ({
11
+ color: 'black',
12
+ '& .handle': {
13
+ transition: 'fill 200ms linear, height 200ms linear',
14
+ '&.non-interactive': disabled('fill'),
15
+ },
16
+ '& .transparentHandle': {
17
+ height: '20px',
18
+ fill: 'transparent',
19
+ stroke: 'transparent',
20
+ },
21
+ '& .line': {
22
+ stroke: color.defaults.TEXT,
23
+ transition: 'fill 200ms linear, height 200ms linear',
24
+ '&.non-interactive': disabled('stroke'),
25
+ },
26
+ '& .disabledPoint': {
27
+ fill: color.defaults.BLACK + ' !important',
28
+ stroke: color.defaults.BLACK + ' !important',
29
+ },
30
+ '& .correctIcon': {
31
+ backgroundColor: color.correct(),
32
+ },
33
+ '& .incorrectIcon': {
34
+ backgroundColor: color.incorrectWithIcon(),
35
+ },
36
+ '& .correctnessIcon': {
37
+ borderRadius: theme.spacing(2),
38
+ color: color.defaults.WHITE,
39
+ fontSize: '16px',
40
+ width: '16px',
41
+ height: '16px',
42
+ padding: '2px',
43
+ border: `1px solid ${color.defaults.WHITE}`,
44
+ stroke: 'initial',
45
+ boxSizing: 'unset', // to override the default border-box in IBX
46
+ },
47
+ '& .smallIcon': {
48
+ fontSize: '10px',
49
+ width: '10px',
50
+ height: '10px',
51
+ },
52
+ }));
53
+
54
+ class RawDragHandle extends React.Component {
55
+ static propTypes = {
56
+ x: PropTypes.number.isRequired,
57
+ y: PropTypes.number.isRequired,
58
+ width: PropTypes.number,
59
+ graphProps: types.GraphPropsType.isRequired,
60
+ className: PropTypes.string,
61
+ interactive: PropTypes.bool,
62
+ CustomDraggableComponent: PropTypes.func,
63
+ correctness: PropTypes.shape({
64
+ value: PropTypes.string,
65
+ label: PropTypes.string,
66
+ }),
67
+ };
68
+
69
+ render() {
70
+ const { x, y, graphProps, className, interactive, CustomDraggableComponent, correctness, ...rest } = this.props;
71
+ const { scale } = graphProps;
72
+
73
+ if (!CustomDraggableComponent) {
74
+ return null;
75
+ }
76
+
77
+ return (
78
+ <StyledDragHandle>
79
+ <CustomDraggableComponent
80
+ scale={scale}
81
+ x={x}
82
+ y={y}
83
+ className={classNames(className, !interactive && 'non-interactive')}
84
+ correctness={correctness}
85
+ interactive={interactive}
86
+ {...rest}
87
+ />
88
+ </StyledDragHandle>
89
+ );
90
+ }
91
+ }
92
+
93
+ export const DragHandle = RawDragHandle;
94
+
95
+ const DraggableHandle = gridDraggable({
96
+ axis: 'y',
97
+ fromDelta: (props, delta) => {
98
+ //TODO: should be in grid-draggable, if axis is y delta.x should always be 0.
99
+ delta.x = 0;
100
+ const newPoint = utils.point(props).add(utils.point(delta));
101
+
102
+ return newPoint.y;
103
+ },
104
+ bounds: (props, { domain, range }) => {
105
+ const area = { left: 0, top: props.y, bottom: props.y, right: 0 };
106
+
107
+ return utils.bounds(area, domain, range);
108
+ },
109
+ anchorPoint: (props) => {
110
+ return { x: props.x, y: props.y };
111
+ },
112
+ })(DragHandle);
113
+
114
+ export default DraggableHandle;
@@ -0,0 +1,171 @@
1
+ import React from 'react';
2
+ import { Group } from '@visx/group';
3
+ import { LinePath } from '@visx/shape';
4
+ import PropTypes from 'prop-types';
5
+ import { types } from '@pie-lib/plot';
6
+ import DraggableHandle, { DragHandle } from './drag-handle';
7
+ import { styled } from '@mui/material/styles';
8
+ import { isEqual } from 'lodash-es';
9
+ import { color } from '@pie-lib/render-ui';
10
+
11
+ const getData = (data, domain) => {
12
+ const { max } = domain || {};
13
+ const length = data.length;
14
+
15
+ if (!max || !length) {
16
+ return [];
17
+ }
18
+
19
+ return data.map((el, i) => ({
20
+ ...el,
21
+ x: length > 1 ? i * (max / (length - 1)) : 0.5,
22
+ y: el.value,
23
+ }));
24
+ };
25
+
26
+ const StyledLinePath = styled(LinePath)(() => ({
27
+ fill: 'transparent',
28
+ stroke: color.defaults.TERTIARY,
29
+ strokeWidth: 3,
30
+ transition: 'stroke 200ms ease-in, stroke-width 200ms ease-in',
31
+ }));
32
+
33
+ export class RawLine extends React.Component {
34
+ static propTypes = {
35
+ onChange: PropTypes.func,
36
+ value: PropTypes.number,
37
+ label: PropTypes.string,
38
+ xBand: PropTypes.func,
39
+ index: PropTypes.number.isRequired,
40
+ graphProps: types.GraphPropsType.isRequired,
41
+ defineChart: PropTypes.bool,
42
+ data: PropTypes.arrayOf(
43
+ PropTypes.shape({
44
+ label: PropTypes.string,
45
+ value: PropTypes.number,
46
+ }),
47
+ ),
48
+ CustomDraggableComponent: PropTypes.func,
49
+ correctData: PropTypes.array,
50
+ };
51
+
52
+ static defaultProps = {
53
+ index: 0,
54
+ };
55
+
56
+ constructor(props) {
57
+ super(props);
58
+ this.state = {
59
+ dragValue: undefined,
60
+ line: getData(props.data, props.graphProps.domain),
61
+ };
62
+ }
63
+
64
+ UNSAFE_componentWillReceiveProps(nextProps) {
65
+ if (!isEqual(this.props.data, nextProps.data)) {
66
+ this.setState({
67
+ line: getData(nextProps.data, nextProps.graphProps.domain),
68
+ });
69
+ }
70
+ }
71
+
72
+ setDragValue = (line) => this.setState({ line });
73
+
74
+ dragStop = (index) => {
75
+ const { onChange } = this.props;
76
+ this.setState({ dragging: false }, () => {
77
+ onChange(index, this.state.line[index]);
78
+ });
79
+ };
80
+
81
+ dragValue = (index, existing, next) => {
82
+ const newLine = [...this.state.line];
83
+ newLine[index].dragValue = next;
84
+ this.setDragValue(newLine);
85
+ };
86
+
87
+ render() {
88
+ const { graphProps, data, CustomDraggableComponent, defineChart, correctData } = this.props;
89
+ const { line: lineState, dragging } = this.state;
90
+ const { scale } = graphProps;
91
+ const lineToUse = dragging ? lineState : getData(data, graphProps.domain);
92
+
93
+ return (
94
+ <React.Fragment>
95
+ <StyledLinePath
96
+ data={lineToUse}
97
+ x={(d) => scale.x(d.x)}
98
+ y={(d) => scale.y(d.dragValue !== undefined ? d.dragValue : d.y)}
99
+ className="line"
100
+ />
101
+ {lineToUse &&
102
+ lineToUse.map((point, i) => {
103
+ const r = 6;
104
+ const enableDraggable = defineChart || point.interactive;
105
+ const Component = enableDraggable ? DraggableHandle : DragHandle;
106
+
107
+ return (
108
+ <Component
109
+ key={`point-${point.x}-${i}`}
110
+ x={point.x}
111
+ y={point.dragValue !== undefined ? point.dragValue : point.y}
112
+ interactive={enableDraggable}
113
+ r={r}
114
+ onDragStart={() => this.setState({ dragging: true })}
115
+ onDrag={(v) => this.dragValue(i, point.dragValue !== undefined ? point.dragValue : point.y, v)}
116
+ onDragStop={() => this.dragStop(i)}
117
+ graphProps={graphProps}
118
+ CustomDraggableComponent={CustomDraggableComponent}
119
+ correctness={point.correctness}
120
+ correctData={correctData}
121
+ label={point.label}
122
+ />
123
+ );
124
+ })}
125
+ </React.Fragment>
126
+ );
127
+ }
128
+ }
129
+
130
+ const StyledLine = styled(RawLine)(() => ({
131
+ '& .line': {
132
+ fill: 'transparent',
133
+ stroke: color.defaults.TERTIARY,
134
+ strokeWidth: 3,
135
+ transition: 'stroke 200ms ease-in, stroke-width 200ms ease-in',
136
+ },
137
+ }));
138
+
139
+ export class Line extends React.Component {
140
+ static propTypes = {
141
+ data: PropTypes.array,
142
+ onChange: PropTypes.func,
143
+ xBand: PropTypes.func,
144
+ graphProps: types.GraphPropsType.isRequired,
145
+ CustomDraggableComponent: PropTypes.func,
146
+ defineChart: PropTypes.bool,
147
+ correctData: PropTypes.array,
148
+ };
149
+
150
+ changeLine = (index, category) => {
151
+ const { onChange } = this.props;
152
+ const newLine = [...this.props.data];
153
+ const { dragValue, value } = category;
154
+
155
+ newLine[index].value = dragValue >= 0 ? dragValue : value;
156
+
157
+ onChange(newLine);
158
+ };
159
+
160
+ render() {
161
+ const props = this.props;
162
+
163
+ return (
164
+ <Group>
165
+ <StyledLine {...props} onChange={this.changeLine} />
166
+ </Group>
167
+ );
168
+ }
169
+ }
170
+
171
+ export default Line;
@@ -0,0 +1,144 @@
1
+ import React, { useState } from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import { LinePath } from '@visx/shape';
4
+ import { Group } from '@visx/group';
5
+ import { styled } from '@mui/material/styles';
6
+
7
+ import { color } from '@pie-lib/render-ui';
8
+ import { dataToXBand } from '../utils';
9
+ import { types } from '@pie-lib/plot';
10
+ import RawLine from './common/line';
11
+ import { CorrectnessIndicator, SmallCorrectPointIndicator } from '../common/correctness-indicators';
12
+
13
+ const StyledLinePath = styled(LinePath)(() => ({
14
+ stroke: color.defaults.TEXT,
15
+ transition: 'fill 200ms linear, height 200ms linear',
16
+ '&.non-interactive': {
17
+ stroke: color.disabled?.() || '#ccc',
18
+ },
19
+ }));
20
+
21
+ const StyledGroup = styled(Group)(({ correctness, interactive }) => ({
22
+ stroke: color.defaults.TEXT,
23
+ transition: 'fill 200ms linear, height 200ms linear',
24
+ ...(correctness &&
25
+ !interactive && {
26
+ fill: `${color.defaults.BLACK} !important`,
27
+ stroke: `${color.defaults.BLACK} !important`,
28
+ }),
29
+ '&.non-interactive': {
30
+ stroke: color.disabled?.() || '#ccc',
31
+ },
32
+ }));
33
+
34
+ const StyledTransparentHandle = styled('circle')(() => ({
35
+ height: '20px',
36
+ fill: 'transparent',
37
+ stroke: 'transparent',
38
+ }));
39
+
40
+ const DraggableComponent = (props) => {
41
+ const { className, scale, x, y, r, correctness, interactive, correctData, label, ...rest } = props;
42
+ const [hover, setHover] = useState(false);
43
+
44
+ const squareSize = r * 4;
45
+ const squareHalf = squareSize / 2;
46
+ const cx = scale.x(x);
47
+ const cy = scale.y(y);
48
+
49
+ return (
50
+ <StyledGroup className={className} correctness={correctness} interactive={interactive}>
51
+ <StyledLinePath
52
+ data={[
53
+ { x: scale.x(x) - r, y: scale.y(y) + r },
54
+ { x: scale.x(x) + r, y: scale.y(y) - r },
55
+ ]}
56
+ key={`point-${x}-${y}-1`}
57
+ x={(d) => d.x}
58
+ y={(d) => d.y}
59
+ strokeWidth={5}
60
+ style={{ pointerEvents: 'none' }}
61
+ />
62
+ <StyledLinePath
63
+ data={[
64
+ { x: scale.x(x) - r, y: scale.y(y) - r },
65
+ { x: scale.x(x) + r, y: scale.y(y) + r },
66
+ ]}
67
+ key={`point-${x}-${y}-2`}
68
+ x={(d) => d.x}
69
+ y={(d) => d.y}
70
+ strokeWidth={5}
71
+ style={{ pointerEvents: 'none' }}
72
+ />
73
+ {hover && (
74
+ <rect
75
+ x={cx - squareHalf}
76
+ y={cy - squareHalf}
77
+ width={squareSize}
78
+ height={squareSize}
79
+ stroke={color.defaults.BORDER_GRAY}
80
+ fill="none"
81
+ strokeWidth={2}
82
+ pointerEvents="none"
83
+ />
84
+ )}
85
+ <StyledTransparentHandle
86
+ cx={cx}
87
+ cy={cy}
88
+ r={r * 2}
89
+ onMouseEnter={() => setHover(true)}
90
+ onMouseLeave={() => setHover(false)}
91
+ {...rest}
92
+ />
93
+ {/* show correctness indicators */}
94
+ <CorrectnessIndicator scale={scale} x={x} y={y} r={r} correctness={correctness} interactive={interactive} />
95
+ {/* show correct point if answer was incorrect */}
96
+ <SmallCorrectPointIndicator
97
+ scale={scale}
98
+ x={x}
99
+ r={r}
100
+ correctness={correctness}
101
+ correctData={correctData}
102
+ label={label}
103
+ />
104
+ </StyledGroup>
105
+ );
106
+ };
107
+
108
+ DraggableComponent.propTypes = {
109
+ scale: PropTypes.object,
110
+ x: PropTypes.number,
111
+ y: PropTypes.number,
112
+ r: PropTypes.number,
113
+ className: PropTypes.string,
114
+ correctness: PropTypes.shape({
115
+ value: PropTypes.string,
116
+ label: PropTypes.string,
117
+ }),
118
+ interactive: PropTypes.bool,
119
+ correctData: PropTypes.array,
120
+ label: PropTypes.string,
121
+ };
122
+
123
+ export class LineCross extends React.Component {
124
+ static propTypes = {
125
+ data: PropTypes.array,
126
+ onChange: PropTypes.func,
127
+ graphProps: types.GraphPropsType.isRequired,
128
+ };
129
+
130
+ render() {
131
+ const props = this.props;
132
+ const { data, graphProps } = props;
133
+ const { scale = {}, size = {} } = graphProps || {};
134
+ const xBand = dataToXBand(scale.x, data, size.width, 'lineCross');
135
+
136
+ return <RawLine {...props} xBand={xBand} CustomDraggableComponent={DraggableComponent} />;
137
+ }
138
+ }
139
+
140
+ export default () => ({
141
+ type: 'lineCross',
142
+ Component: LineCross,
143
+ name: 'Line Cross',
144
+ });
@@ -0,0 +1,111 @@
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
+ });