stream-charts 1.2.1 → 2.0.0

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 (463) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +809 -1022
  3. package/changes.md +36 -0
  4. package/dist/app/charts/Chart.d.ts +35 -139
  5. package/dist/app/charts/Chart.d.ts.map +1 -0
  6. package/dist/app/charts/Chart.js +74 -65
  7. package/dist/app/charts/Chart.js.map +1 -1
  8. package/dist/app/charts/axes/AxesState.d.ts +26 -18
  9. package/dist/app/charts/axes/AxesState.d.ts.map +1 -0
  10. package/dist/app/charts/axes/AxesState.js +26 -24
  11. package/dist/app/charts/axes/AxesState.js.map +1 -1
  12. package/dist/app/charts/axes/AxisInterval.d.ts +44 -26
  13. package/dist/app/charts/axes/AxisInterval.d.ts.map +1 -0
  14. package/dist/app/charts/axes/AxisInterval.js +48 -29
  15. package/dist/app/charts/axes/AxisInterval.js.map +1 -1
  16. package/dist/app/charts/axes/BaseAxisRange.d.ts +46 -22
  17. package/dist/app/charts/axes/BaseAxisRange.d.ts.map +1 -0
  18. package/dist/app/charts/axes/BaseAxisRange.js +17 -12
  19. package/dist/app/charts/axes/BaseAxisRange.js.map +1 -1
  20. package/dist/app/charts/axes/ContinuousAxis.d.ts +47 -6
  21. package/dist/app/charts/axes/ContinuousAxis.d.ts.map +1 -0
  22. package/dist/app/charts/axes/ContinuousAxis.js +160 -27
  23. package/dist/app/charts/axes/ContinuousAxis.js.map +1 -1
  24. package/dist/app/charts/axes/ContinuousAxisRange.d.ts +29 -10
  25. package/dist/app/charts/axes/ContinuousAxisRange.d.ts.map +1 -0
  26. package/dist/app/charts/axes/ContinuousAxisRange.js +29 -11
  27. package/dist/app/charts/axes/ContinuousAxisRange.js.map +1 -1
  28. package/dist/app/charts/axes/EmptyAxis.d.ts +5 -2
  29. package/dist/app/charts/axes/EmptyAxis.d.ts.map +1 -0
  30. package/dist/app/charts/axes/EmptyAxis.js +30 -9
  31. package/dist/app/charts/axes/EmptyAxis.js.map +1 -1
  32. package/dist/app/charts/axes/OrdinalAxis.d.ts +5 -3
  33. package/dist/app/charts/axes/OrdinalAxis.d.ts.map +1 -0
  34. package/dist/app/charts/axes/OrdinalAxis.js +39 -16
  35. package/dist/app/charts/axes/OrdinalAxis.js.map +1 -1
  36. package/dist/app/charts/axes/OrdinalAxisRange.d.ts +76 -13
  37. package/dist/app/charts/axes/OrdinalAxisRange.d.ts.map +1 -0
  38. package/dist/app/charts/axes/OrdinalAxisRange.js +95 -16
  39. package/dist/app/charts/axes/OrdinalAxisRange.js.map +1 -1
  40. package/dist/app/charts/axes/autoScale.d.ts +111 -0
  41. package/dist/app/charts/axes/autoScale.d.ts.map +1 -0
  42. package/dist/app/charts/axes/autoScale.js +188 -0
  43. package/dist/app/charts/axes/autoScale.js.map +1 -0
  44. package/dist/app/charts/axes/axes.d.ts +273 -150
  45. package/dist/app/charts/axes/axes.d.ts.map +1 -0
  46. package/dist/app/charts/axes/axes.js +808 -583
  47. package/dist/app/charts/axes/axes.js.map +1 -1
  48. package/dist/app/charts/d3types.d.ts +40 -11
  49. package/dist/app/charts/d3types.d.ts.map +1 -0
  50. package/dist/app/charts/d3types.js +3 -0
  51. package/dist/app/charts/d3types.js.map +1 -1
  52. package/dist/app/charts/datasources/StreamingDataSource.d.ts +149 -0
  53. package/dist/app/charts/datasources/StreamingDataSource.d.ts.map +1 -0
  54. package/dist/app/charts/datasources/StreamingDataSource.js +110 -0
  55. package/dist/app/charts/datasources/StreamingDataSource.js.map +1 -0
  56. package/dist/app/charts/datasources/iteratesDataSource.d.ts +73 -0
  57. package/dist/app/charts/datasources/iteratesDataSource.d.ts.map +1 -0
  58. package/dist/app/charts/datasources/iteratesDataSource.js +87 -0
  59. package/dist/app/charts/datasources/iteratesDataSource.js.map +1 -0
  60. package/dist/app/charts/datasources/ordinalDataSource.d.ts +75 -0
  61. package/dist/app/charts/datasources/ordinalDataSource.d.ts.map +1 -0
  62. package/dist/app/charts/datasources/ordinalDataSource.js +135 -0
  63. package/dist/app/charts/datasources/ordinalDataSource.js.map +1 -0
  64. package/dist/app/charts/datasources/outlierDataSource.d.ts +53 -0
  65. package/dist/app/charts/datasources/outlierDataSource.d.ts.map +1 -0
  66. package/dist/app/charts/datasources/outlierDataSource.js +57 -0
  67. package/dist/app/charts/datasources/outlierDataSource.js.map +1 -0
  68. package/dist/app/charts/datasources/timeSeriesDataSource.d.ts +77 -0
  69. package/dist/app/charts/datasources/timeSeriesDataSource.d.ts.map +1 -0
  70. package/dist/app/charts/datasources/timeSeriesDataSource.js +85 -0
  71. package/dist/app/charts/datasources/timeSeriesDataSource.js.map +1 -0
  72. package/dist/app/charts/filters/regexFilter.d.ts +31 -4
  73. package/dist/app/charts/filters/regexFilter.d.ts.map +1 -0
  74. package/dist/app/charts/filters/regexFilter.js +38 -4
  75. package/dist/app/charts/filters/regexFilter.js.map +1 -1
  76. package/dist/app/charts/hooks/AxesProvider.d.ts +21 -0
  77. package/dist/app/charts/hooks/AxesProvider.d.ts.map +1 -0
  78. package/dist/app/charts/hooks/AxesProvider.js +213 -0
  79. package/dist/app/charts/hooks/AxesProvider.js.map +1 -0
  80. package/dist/app/charts/hooks/CanvasSurfaceProvider.d.ts +25 -0
  81. package/dist/app/charts/hooks/CanvasSurfaceProvider.d.ts.map +1 -0
  82. package/dist/app/charts/hooks/CanvasSurfaceProvider.js +76 -0
  83. package/dist/app/charts/hooks/CanvasSurfaceProvider.js.map +1 -0
  84. package/dist/app/charts/hooks/ChartProvider.d.ts +40 -0
  85. package/dist/app/charts/hooks/ChartProvider.d.ts.map +1 -0
  86. package/dist/app/charts/hooks/ChartProvider.js +33 -0
  87. package/dist/app/charts/hooks/ChartProvider.js.map +1 -0
  88. package/dist/app/charts/hooks/InteractionProvider.d.ts +23 -0
  89. package/dist/app/charts/hooks/InteractionProvider.d.ts.map +1 -0
  90. package/dist/app/charts/hooks/InteractionProvider.js +60 -0
  91. package/dist/app/charts/hooks/InteractionProvider.js.map +1 -0
  92. package/dist/app/charts/hooks/PlotDimensionsProvider.d.ts +16 -0
  93. package/dist/app/charts/hooks/PlotDimensionsProvider.d.ts.map +1 -0
  94. package/dist/app/charts/hooks/PlotDimensionsProvider.js +76 -0
  95. package/dist/app/charts/hooks/PlotDimensionsProvider.js.map +1 -0
  96. package/dist/app/charts/hooks/defaultAxesValues.d.ts +11 -0
  97. package/dist/app/charts/hooks/defaultAxesValues.d.ts.map +1 -0
  98. package/dist/app/charts/hooks/defaultAxesValues.js +36 -0
  99. package/dist/app/charts/hooks/defaultAxesValues.js.map +1 -0
  100. package/dist/app/charts/hooks/defaultMouseValues.d.ts +9 -0
  101. package/dist/app/charts/hooks/defaultMouseValues.d.ts.map +1 -0
  102. package/dist/app/charts/hooks/defaultMouseValues.js +23 -0
  103. package/dist/app/charts/hooks/defaultMouseValues.js.map +1 -0
  104. package/dist/app/charts/hooks/defaultPlotDimensions.d.ts +13 -0
  105. package/dist/app/charts/hooks/defaultPlotDimensions.d.ts.map +1 -0
  106. package/dist/app/charts/hooks/defaultPlotDimensions.js +23 -0
  107. package/dist/app/charts/hooks/defaultPlotDimensions.js.map +1 -0
  108. package/dist/app/charts/hooks/defaultTooltipValues.d.ts +9 -0
  109. package/dist/app/charts/hooks/defaultTooltipValues.d.ts.map +1 -0
  110. package/dist/app/charts/hooks/defaultTooltipValues.js +21 -0
  111. package/dist/app/charts/hooks/defaultTooltipValues.js.map +1 -0
  112. package/dist/app/charts/hooks/defaultUseChartValues.d.ts +14 -0
  113. package/dist/app/charts/hooks/defaultUseChartValues.d.ts.map +1 -0
  114. package/dist/app/charts/hooks/defaultUseChartValues.js +30 -0
  115. package/dist/app/charts/hooks/defaultUseChartValues.js.map +1 -0
  116. package/dist/app/charts/hooks/useAxes.d.ts +49 -36
  117. package/dist/app/charts/hooks/useAxes.d.ts.map +1 -0
  118. package/dist/app/charts/hooks/useAxes.js +16 -176
  119. package/dist/app/charts/hooks/useAxes.js.map +1 -1
  120. package/dist/app/charts/hooks/useCanvasSurface.d.ts +25 -0
  121. package/dist/app/charts/hooks/useCanvasSurface.d.ts.map +1 -0
  122. package/dist/app/charts/hooks/useCanvasSurface.js +18 -0
  123. package/dist/app/charts/hooks/useCanvasSurface.js.map +1 -0
  124. package/dist/app/charts/hooks/useChart.d.ts +30 -44
  125. package/dist/app/charts/hooks/useChart.d.ts.map +1 -0
  126. package/dist/app/charts/hooks/useChart.js +26 -48
  127. package/dist/app/charts/hooks/useChart.js.map +1 -1
  128. package/dist/app/charts/hooks/useDataSource.d.ts +68 -0
  129. package/dist/app/charts/hooks/useDataSource.d.ts.map +1 -0
  130. package/dist/app/charts/hooks/useDataSource.js +63 -0
  131. package/dist/app/charts/hooks/useDataSource.js.map +1 -0
  132. package/dist/app/charts/hooks/useHoveredSeries.d.ts +25 -0
  133. package/dist/app/charts/hooks/useHoveredSeries.d.ts.map +1 -0
  134. package/dist/app/charts/hooks/useHoveredSeries.js +15 -0
  135. package/dist/app/charts/hooks/useHoveredSeries.js.map +1 -0
  136. package/dist/app/charts/hooks/useMouse.d.ts +46 -22
  137. package/dist/app/charts/hooks/useMouse.d.ts.map +1 -0
  138. package/dist/app/charts/hooks/useMouse.js +12 -56
  139. package/dist/app/charts/hooks/useMouse.js.map +1 -1
  140. package/dist/app/charts/hooks/usePlotDimensions.d.ts +25 -13
  141. package/dist/app/charts/hooks/usePlotDimensions.d.ts.map +1 -0
  142. package/dist/app/charts/hooks/usePlotDimensions.js +6 -62
  143. package/dist/app/charts/hooks/usePlotDimensions.js.map +1 -1
  144. package/dist/app/charts/hooks/useTooltip.d.ts +24 -26
  145. package/dist/app/charts/hooks/useTooltip.d.ts.map +1 -0
  146. package/dist/app/charts/hooks/useTooltip.js +12 -42
  147. package/dist/app/charts/hooks/useTooltip.js.map +1 -1
  148. package/dist/app/charts/index.d.ts +66 -0
  149. package/dist/app/charts/index.d.ts.map +1 -0
  150. package/dist/app/charts/index.js +87 -0
  151. package/dist/app/charts/index.js.map +1 -0
  152. package/dist/app/charts/legends/Legend.d.ts +33 -12
  153. package/dist/app/charts/legends/Legend.d.ts.map +1 -0
  154. package/dist/app/charts/legends/Legend.js +138 -379
  155. package/dist/app/charts/legends/Legend.js.map +1 -1
  156. package/dist/app/charts/legends/constants.d.ts +19 -0
  157. package/dist/app/charts/legends/constants.d.ts.map +1 -0
  158. package/dist/app/charts/legends/constants.js +34 -0
  159. package/dist/app/charts/legends/constants.js.map +1 -0
  160. package/dist/app/charts/observables/ChartData.d.ts +1 -0
  161. package/dist/app/charts/observables/ChartData.d.ts.map +1 -0
  162. package/dist/app/charts/observables/iterates.d.ts +13 -7
  163. package/dist/app/charts/observables/iterates.d.ts.map +1 -0
  164. package/dist/app/charts/observables/iterates.js +42 -9
  165. package/dist/app/charts/observables/iterates.js.map +1 -1
  166. package/dist/app/charts/observables/ordinals.d.ts +70 -12
  167. package/dist/app/charts/observables/ordinals.d.ts.map +1 -0
  168. package/dist/app/charts/observables/ordinals.js +127 -48
  169. package/dist/app/charts/observables/ordinals.js.map +1 -1
  170. package/dist/app/charts/observables/outliers.d.ts +18 -0
  171. package/dist/app/charts/observables/outliers.d.ts.map +1 -0
  172. package/dist/app/charts/observables/outliers.js +2 -0
  173. package/dist/app/charts/observables/outliers.js.map +1 -0
  174. package/dist/app/charts/plots/BarPlot.d.ts +87 -13
  175. package/dist/app/charts/plots/BarPlot.d.ts.map +1 -0
  176. package/dist/app/charts/plots/BarPlot.js +603 -356
  177. package/dist/app/charts/plots/BarPlot.js.map +1 -1
  178. package/dist/app/charts/plots/OutlierPlot.d.ts +123 -0
  179. package/dist/app/charts/plots/OutlierPlot.d.ts.map +1 -0
  180. package/dist/app/charts/plots/OutlierPlot.js +430 -0
  181. package/dist/app/charts/plots/OutlierPlot.js.map +1 -0
  182. package/dist/app/charts/plots/PoincarePlot.d.ts +92 -14
  183. package/dist/app/charts/plots/PoincarePlot.d.ts.map +1 -0
  184. package/dist/app/charts/plots/PoincarePlot.js +523 -364
  185. package/dist/app/charts/plots/PoincarePlot.js.map +1 -1
  186. package/dist/app/charts/plots/RasterPlot.d.ts +31 -10
  187. package/dist/app/charts/plots/RasterPlot.d.ts.map +1 -0
  188. package/dist/app/charts/plots/RasterPlot.js +198 -306
  189. package/dist/app/charts/plots/RasterPlot.js.map +1 -1
  190. package/dist/app/charts/plots/ScatterPlot.d.ts +77 -21
  191. package/dist/app/charts/plots/ScatterPlot.d.ts.map +1 -0
  192. package/dist/app/charts/plots/ScatterPlot.js +359 -302
  193. package/dist/app/charts/plots/ScatterPlot.js.map +1 -1
  194. package/dist/app/charts/plots/autoScaleYAxes.d.ts +43 -0
  195. package/dist/app/charts/plots/autoScaleYAxes.d.ts.map +1 -0
  196. package/dist/app/charts/plots/autoScaleYAxes.js +71 -0
  197. package/dist/app/charts/plots/autoScaleYAxes.js.map +1 -0
  198. package/dist/app/charts/plots/colorizedLine.d.ts +61 -0
  199. package/dist/app/charts/plots/colorizedLine.d.ts.map +1 -0
  200. package/dist/app/charts/plots/colorizedLine.js +157 -0
  201. package/dist/app/charts/plots/colorizedLine.js.map +1 -0
  202. package/dist/app/charts/plots/constants.d.ts +7 -0
  203. package/dist/app/charts/plots/constants.d.ts.map +1 -0
  204. package/dist/app/charts/plots/constants.js +11 -0
  205. package/dist/app/charts/plots/constants.js.map +1 -0
  206. package/dist/app/charts/plots/hitTesting.d.ts +88 -0
  207. package/dist/app/charts/plots/hitTesting.d.ts.map +1 -0
  208. package/dist/app/charts/plots/hitTesting.js +136 -0
  209. package/dist/app/charts/plots/hitTesting.js.map +1 -0
  210. package/dist/app/charts/plots/plot.d.ts +52 -16
  211. package/dist/app/charts/plots/plot.d.ts.map +1 -0
  212. package/dist/app/charts/plots/plot.js +108 -35
  213. package/dist/app/charts/plots/plot.js.map +1 -1
  214. package/dist/app/charts/plots/useCanvasZoomPan.d.ts +119 -0
  215. package/dist/app/charts/plots/useCanvasZoomPan.d.ts.map +1 -0
  216. package/dist/app/charts/plots/useCanvasZoomPan.js +113 -0
  217. package/dist/app/charts/plots/useCanvasZoomPan.js.map +1 -0
  218. package/dist/app/charts/plots/useStreamingTimeAxes.d.ts +103 -0
  219. package/dist/app/charts/plots/useStreamingTimeAxes.d.ts.map +1 -0
  220. package/dist/app/charts/plots/useStreamingTimeAxes.js +257 -0
  221. package/dist/app/charts/plots/useStreamingTimeAxes.js.map +1 -0
  222. package/dist/app/charts/series/baseSeries.d.ts +60 -8
  223. package/dist/app/charts/series/baseSeries.d.ts.map +1 -0
  224. package/dist/app/charts/series/baseSeries.js +53 -8
  225. package/dist/app/charts/series/baseSeries.js.map +1 -1
  226. package/dist/app/charts/series/iterateSeries.d.ts +9 -8
  227. package/dist/app/charts/series/iterateSeries.d.ts.map +1 -0
  228. package/dist/app/charts/series/iterateSeries.js +7 -7
  229. package/dist/app/charts/series/iterateSeries.js.map +1 -1
  230. package/dist/app/charts/series/ordinalSeries.d.ts +27 -13
  231. package/dist/app/charts/series/ordinalSeries.d.ts.map +1 -0
  232. package/dist/app/charts/series/ordinalSeries.js +29 -15
  233. package/dist/app/charts/series/ordinalSeries.js.map +1 -1
  234. package/dist/app/charts/series/outlierSeries.d.ts +142 -0
  235. package/dist/app/charts/series/outlierSeries.d.ts.map +1 -0
  236. package/dist/app/charts/series/outlierSeries.js +82 -0
  237. package/dist/app/charts/series/outlierSeries.js.map +1 -0
  238. package/dist/app/charts/series/timeSeries.d.ts +13 -9
  239. package/dist/app/charts/series/timeSeries.d.ts.map +1 -0
  240. package/dist/app/charts/series/timeSeries.js +6 -3
  241. package/dist/app/charts/series/timeSeries.js.map +1 -1
  242. package/dist/app/charts/series/timeSeriesChartData.d.ts +18 -10
  243. package/dist/app/charts/series/timeSeriesChartData.d.ts.map +1 -0
  244. package/dist/app/charts/series/timeSeriesChartData.js +28 -14
  245. package/dist/app/charts/series/timeSeriesChartData.js.map +1 -1
  246. package/dist/app/charts/styling/barPlotStyle.d.ts +46 -2
  247. package/dist/app/charts/styling/barPlotStyle.d.ts.map +1 -0
  248. package/dist/app/charts/styling/barPlotStyle.js +37 -3
  249. package/dist/app/charts/styling/barPlotStyle.js.map +1 -1
  250. package/dist/app/charts/styling/canvasStyle.d.ts +53 -0
  251. package/dist/app/charts/styling/canvasStyle.d.ts.map +1 -0
  252. package/dist/app/charts/styling/canvasStyle.js +71 -0
  253. package/dist/app/charts/styling/canvasStyle.js.map +1 -0
  254. package/dist/app/charts/styling/margins.d.ts +21 -2
  255. package/dist/app/charts/styling/margins.d.ts.map +1 -0
  256. package/dist/app/charts/styling/margins.js +25 -4
  257. package/dist/app/charts/styling/margins.js.map +1 -1
  258. package/dist/app/charts/styling/svgStyle.d.ts +10 -56
  259. package/dist/app/charts/styling/svgStyle.d.ts.map +1 -0
  260. package/dist/app/charts/styling/svgStyle.js +3 -78
  261. package/dist/app/charts/styling/svgStyle.js.map +1 -1
  262. package/dist/app/charts/subscriptions/viewDrivers.d.ts +124 -0
  263. package/dist/app/charts/subscriptions/viewDrivers.d.ts.map +1 -0
  264. package/dist/app/charts/subscriptions/viewDrivers.js +338 -0
  265. package/dist/app/charts/subscriptions/viewDrivers.js.map +1 -0
  266. package/dist/app/charts/tooltips/BarPlotTooltipContent.d.ts +12 -78
  267. package/dist/app/charts/tooltips/BarPlotTooltipContent.d.ts.map +1 -0
  268. package/dist/app/charts/tooltips/BarPlotTooltipContent.js +65 -257
  269. package/dist/app/charts/tooltips/BarPlotTooltipContent.js.map +1 -1
  270. package/dist/app/charts/tooltips/DefaultOutlierTooltipContent.d.ts +9 -0
  271. package/dist/app/charts/tooltips/DefaultOutlierTooltipContent.d.ts.map +1 -0
  272. package/dist/app/charts/tooltips/DefaultOutlierTooltipContent.js +16 -0
  273. package/dist/app/charts/tooltips/DefaultOutlierTooltipContent.js.map +1 -0
  274. package/dist/app/charts/tooltips/OutlierPlotTooltipContent.d.ts +30 -0
  275. package/dist/app/charts/tooltips/OutlierPlotTooltipContent.d.ts.map +1 -0
  276. package/dist/app/charts/tooltips/OutlierPlotTooltipContent.js +26 -0
  277. package/dist/app/charts/tooltips/OutlierPlotTooltipContent.js.map +1 -0
  278. package/dist/app/charts/tooltips/PoincarePlotTooltipContent.d.ts +22 -72
  279. package/dist/app/charts/tooltips/PoincarePlotTooltipContent.d.ts.map +1 -0
  280. package/dist/app/charts/tooltips/PoincarePlotTooltipContent.js +104 -171
  281. package/dist/app/charts/tooltips/PoincarePlotTooltipContent.js.map +1 -1
  282. package/dist/app/charts/tooltips/RasterPlotTooltipContent.d.ts +32 -8
  283. package/dist/app/charts/tooltips/RasterPlotTooltipContent.d.ts.map +1 -0
  284. package/dist/app/charts/tooltips/RasterPlotTooltipContent.js +62 -115
  285. package/dist/app/charts/tooltips/RasterPlotTooltipContent.js.map +1 -1
  286. package/dist/app/charts/tooltips/ScatterPlotTooltipContent.d.ts +39 -12
  287. package/dist/app/charts/tooltips/ScatterPlotTooltipContent.d.ts.map +1 -0
  288. package/dist/app/charts/tooltips/ScatterPlotTooltipContent.js +162 -134
  289. package/dist/app/charts/tooltips/ScatterPlotTooltipContent.js.map +1 -1
  290. package/dist/app/charts/tooltips/Tooltip.d.ts +27 -32
  291. package/dist/app/charts/tooltips/Tooltip.d.ts.map +1 -0
  292. package/dist/app/charts/tooltips/Tooltip.js +37 -81
  293. package/dist/app/charts/tooltips/Tooltip.js.map +1 -1
  294. package/dist/app/charts/tooltips/TooltipContent.d.ts +81 -0
  295. package/dist/app/charts/tooltips/TooltipContent.d.ts.map +1 -0
  296. package/dist/app/charts/tooltips/TooltipContent.js +99 -0
  297. package/dist/app/charts/tooltips/TooltipContent.js.map +1 -0
  298. package/dist/app/charts/tooltips/tooltipUtils.d.ts +186 -36
  299. package/dist/app/charts/tooltips/tooltipUtils.d.ts.map +1 -0
  300. package/dist/app/charts/tooltips/tooltipUtils.js +277 -48
  301. package/dist/app/charts/tooltips/tooltipUtils.js.map +1 -1
  302. package/dist/app/charts/tooltips/useOutlierTooltip.d.ts +59 -0
  303. package/dist/app/charts/tooltips/useOutlierTooltip.d.ts.map +1 -0
  304. package/dist/app/charts/tooltips/useOutlierTooltip.js +16 -0
  305. package/dist/app/charts/tooltips/useOutlierTooltip.js.map +1 -0
  306. package/dist/app/charts/tooltips/useTooltipPlacement.d.ts +51 -0
  307. package/dist/app/charts/tooltips/useTooltipPlacement.d.ts.map +1 -0
  308. package/dist/app/charts/tooltips/useTooltipPlacement.js +52 -0
  309. package/dist/app/charts/tooltips/useTooltipPlacement.js.map +1 -0
  310. package/dist/app/charts/tooltips/useTooltipStyle.d.ts +11 -0
  311. package/dist/app/charts/tooltips/useTooltipStyle.d.ts.map +1 -0
  312. package/dist/app/charts/tooltips/useTooltipStyle.js +14 -0
  313. package/dist/app/charts/tooltips/useTooltipStyle.js.map +1 -0
  314. package/dist/app/charts/trackers/Tracker.d.ts +22 -6
  315. package/dist/app/charts/trackers/Tracker.d.ts.map +1 -0
  316. package/dist/app/charts/trackers/Tracker.js +36 -22
  317. package/dist/app/charts/trackers/Tracker.js.map +1 -1
  318. package/dist/app/charts/trackers/trackerUtils.d.ts +40 -18
  319. package/dist/app/charts/trackers/trackerUtils.d.ts.map +1 -0
  320. package/dist/app/charts/trackers/trackerUtils.js +213 -300
  321. package/dist/app/charts/trackers/trackerUtils.js.map +1 -1
  322. package/dist/app/charts/utils.d.ts +72 -33
  323. package/dist/app/charts/utils.d.ts.map +1 -0
  324. package/dist/app/charts/utils.js +87 -42
  325. package/dist/app/charts/utils.js.map +1 -1
  326. package/dist/index.d.ts +2 -45
  327. package/dist/index.d.ts.map +1 -0
  328. package/dist/index.js +2 -72
  329. package/dist/index.js.map +1 -1
  330. package/package.json +87 -46
  331. package/src/app/charts/Chart.tsx +132 -168
  332. package/src/app/charts/axes/AxesState.ts +27 -29
  333. package/src/app/charts/axes/AxisInterval.ts +57 -32
  334. package/src/app/charts/axes/BaseAxisRange.ts +47 -27
  335. package/src/app/charts/axes/ContinuousAxis.tsx +235 -39
  336. package/src/app/charts/axes/ContinuousAxisRange.ts +29 -11
  337. package/src/app/charts/axes/EmptyAxis.tsx +52 -17
  338. package/src/app/charts/axes/OrdinalAxis.tsx +54 -28
  339. package/src/app/charts/axes/OrdinalAxisRange.ts +96 -16
  340. package/src/app/charts/axes/autoScale.ts +244 -0
  341. package/src/app/charts/axes/axes.ts +954 -735
  342. package/src/app/charts/d3types.ts +42 -13
  343. package/src/app/charts/datasources/StreamingDataSource.ts +214 -0
  344. package/src/app/charts/datasources/iteratesDataSource.ts +122 -0
  345. package/src/app/charts/datasources/ordinalDataSource.ts +205 -0
  346. package/src/app/charts/datasources/outlierDataSource.ts +90 -0
  347. package/src/app/charts/datasources/timeSeriesDataSource.ts +133 -0
  348. package/src/app/charts/filters/regexFilter.ts +45 -5
  349. package/src/app/charts/hooks/AxesProvider.tsx +301 -0
  350. package/src/app/charts/hooks/CanvasSurfaceProvider.tsx +117 -0
  351. package/src/app/charts/hooks/ChartProvider.tsx +79 -0
  352. package/src/app/charts/hooks/InteractionProvider.tsx +88 -0
  353. package/src/app/charts/hooks/PlotDimensionsProvider.tsx +109 -0
  354. package/src/app/charts/hooks/defaultAxesValues.ts +40 -0
  355. package/src/app/charts/hooks/defaultMouseValues.ts +24 -0
  356. package/src/app/charts/hooks/defaultPlotDimensions.ts +27 -0
  357. package/src/app/charts/hooks/defaultTooltipValues.tsx +23 -0
  358. package/src/app/charts/hooks/defaultUseChartValues.tsx +36 -0
  359. package/src/app/charts/hooks/useAxes.tsx +60 -228
  360. package/src/app/charts/hooks/useCanvasSurface.tsx +35 -0
  361. package/src/app/charts/hooks/useChart.tsx +47 -106
  362. package/src/app/charts/hooks/useDataSource.tsx +106 -0
  363. package/src/app/charts/hooks/useHoveredSeries.tsx +33 -0
  364. package/src/app/charts/hooks/useMouse.tsx +58 -82
  365. package/src/app/charts/hooks/usePlotDimensions.tsx +25 -89
  366. package/src/app/charts/hooks/useTooltip.tsx +32 -63
  367. package/src/app/charts/index.ts +213 -0
  368. package/src/app/charts/legends/Legend.tsx +198 -479
  369. package/src/app/charts/legends/constants.ts +37 -0
  370. package/src/app/charts/observables/iterates.ts +32 -12
  371. package/src/app/charts/observables/ordinals.ts +141 -67
  372. package/src/app/charts/observables/outliers.ts +20 -0
  373. package/src/app/charts/plots/BarPlot.tsx +784 -666
  374. package/src/app/charts/plots/OutlierPlot.tsx +685 -0
  375. package/src/app/charts/plots/PoincarePlot.tsx +707 -489
  376. package/src/app/charts/plots/RasterPlot.tsx +253 -445
  377. package/src/app/charts/plots/ScatterPlot.tsx +480 -463
  378. package/src/app/charts/plots/autoScaleYAxes.ts +102 -0
  379. package/src/app/charts/plots/colorizedLine.ts +185 -0
  380. package/src/app/charts/plots/constants.ts +16 -0
  381. package/src/app/charts/plots/hitTesting.ts +198 -0
  382. package/src/app/charts/plots/plot.ts +138 -44
  383. package/src/app/charts/plots/useCanvasZoomPan.ts +240 -0
  384. package/src/app/charts/plots/useStreamingTimeAxes.ts +384 -0
  385. package/src/app/charts/series/baseSeries.ts +81 -14
  386. package/src/app/charts/series/iterateSeries.ts +8 -8
  387. package/src/app/charts/series/ordinalSeries.ts +35 -20
  388. package/src/app/charts/series/outlierSeries.ts +188 -0
  389. package/src/app/charts/series/timeSeries.ts +14 -12
  390. package/src/app/charts/series/timeSeriesChartData.ts +31 -17
  391. package/src/app/charts/styling/barPlotStyle.ts +48 -5
  392. package/src/app/charts/styling/canvasStyle.ts +86 -0
  393. package/src/app/charts/styling/margins.ts +28 -4
  394. package/src/app/charts/styling/svgStyle.ts +10 -91
  395. package/src/app/charts/subscriptions/viewDrivers.ts +447 -0
  396. package/src/app/charts/tooltips/BarPlotTooltipContent.tsx +156 -380
  397. package/src/app/charts/tooltips/DefaultOutlierTooltipContent.tsx +40 -0
  398. package/src/app/charts/tooltips/OutlierPlotTooltipContent.tsx +67 -0
  399. package/src/app/charts/tooltips/PoincarePlotTooltipContent.tsx +229 -292
  400. package/src/app/charts/tooltips/RasterPlotTooltipContent.tsx +164 -217
  401. package/src/app/charts/tooltips/ScatterPlotTooltipContent.tsx +373 -236
  402. package/src/app/charts/tooltips/Tooltip.tsx +58 -124
  403. package/src/app/charts/tooltips/TooltipContent.tsx +177 -0
  404. package/src/app/charts/tooltips/tooltipUtils.ts +359 -61
  405. package/src/app/charts/tooltips/useOutlierTooltip.tsx +68 -0
  406. package/src/app/charts/tooltips/useTooltipPlacement.ts +86 -0
  407. package/src/app/charts/tooltips/useTooltipStyle.ts +15 -0
  408. package/src/app/charts/trackers/Tracker.tsx +68 -33
  409. package/src/app/charts/trackers/trackerUtils.ts +263 -376
  410. package/src/app/charts/utils.ts +90 -48
  411. package/src/index.ts +2 -322
  412. package/dist/app/charts/axes/AxesState.test.d.ts +0 -1
  413. package/dist/app/charts/axes/AxesState.test.js +0 -30
  414. package/dist/app/charts/axes/AxesState.test.js.map +0 -1
  415. package/dist/app/charts/axes/AxisInterval.test.d.ts +0 -1
  416. package/dist/app/charts/axes/AxisInterval.test.js +0 -120
  417. package/dist/app/charts/axes/AxisInterval.test.js.map +0 -1
  418. package/dist/app/charts/axes/ContinuousAxisRange.test.d.ts +0 -1
  419. package/dist/app/charts/axes/ContinuousAxisRange.test.js +0 -47
  420. package/dist/app/charts/axes/ContinuousAxisRange.test.js.map +0 -1
  421. package/dist/app/charts/axes/OrdinalAxisRange.test.d.ts +0 -1
  422. package/dist/app/charts/axes/OrdinalAxisRange.test.js +0 -48
  423. package/dist/app/charts/axes/OrdinalAxisRange.test.js.map +0 -1
  424. package/dist/app/charts/filters/regexFilter.test.d.ts +0 -1
  425. package/dist/app/charts/filters/regexFilter.test.js +0 -11
  426. package/dist/app/charts/filters/regexFilter.test.js.map +0 -1
  427. package/dist/app/charts/hooks/useDataObservable.d.ts +0 -72
  428. package/dist/app/charts/hooks/useDataObservable.js +0 -74
  429. package/dist/app/charts/hooks/useDataObservable.js.map +0 -1
  430. package/dist/app/charts/hooks/useInitialData.d.ts +0 -36
  431. package/dist/app/charts/hooks/useInitialData.js +0 -28
  432. package/dist/app/charts/hooks/useInitialData.js.map +0 -1
  433. package/dist/app/charts/observables/iterates.test.d.ts +0 -1
  434. package/dist/app/charts/observables/iterates.test.js +0 -180
  435. package/dist/app/charts/observables/iterates.test.js.map +0 -1
  436. package/dist/app/charts/observables/ordinals.test.d.ts +0 -1
  437. package/dist/app/charts/observables/ordinals.test.js +0 -102
  438. package/dist/app/charts/observables/ordinals.test.js.map +0 -1
  439. package/dist/app/charts/series/datumSeries.test.d.ts +0 -1
  440. package/dist/app/charts/series/datumSeries.test.js +0 -50
  441. package/dist/app/charts/series/datumSeries.test.js.map +0 -1
  442. package/dist/app/charts/styling/margins.test.d.ts +0 -1
  443. package/dist/app/charts/styling/margins.test.js +0 -19
  444. package/dist/app/charts/styling/margins.test.js.map +0 -1
  445. package/dist/app/charts/subscriptions/subscription.test.d.ts +0 -1
  446. package/dist/app/charts/subscriptions/subscription.test.js +0 -395
  447. package/dist/app/charts/subscriptions/subscription.test.js.map +0 -1
  448. package/dist/app/charts/subscriptions/subscriptions.d.ts +0 -100
  449. package/dist/app/charts/subscriptions/subscriptions.js +0 -449
  450. package/dist/app/charts/subscriptions/subscriptions.js.map +0 -1
  451. package/src/app/charts/axes/AxesState.test.ts +0 -34
  452. package/src/app/charts/axes/AxisInterval.test.ts +0 -143
  453. package/src/app/charts/axes/ContinuousAxisRange.test.ts +0 -55
  454. package/src/app/charts/axes/OrdinalAxisRange.test.ts +0 -55
  455. package/src/app/charts/filters/regexFilter.test.ts +0 -13
  456. package/src/app/charts/hooks/useDataObservable.tsx +0 -170
  457. package/src/app/charts/hooks/useInitialData.tsx +0 -64
  458. package/src/app/charts/observables/iterates.test.ts +0 -201
  459. package/src/app/charts/observables/ordinals.test.ts +0 -135
  460. package/src/app/charts/series/datumSeries.test.ts +0 -60
  461. package/src/app/charts/styling/margins.test.ts +0 -22
  462. package/src/app/charts/subscriptions/subscription.test.ts +0 -499
  463. package/src/app/charts/subscriptions/subscriptions.ts +0 -635
@@ -1,9 +1,36 @@
1
- import { Result } from "result-fn";
1
+ import { type Result } from "result-fn";
2
2
  /**
3
- * Wraps the creation of the regex in a try/catch and returns the regex, wrapped in an option,
3
+ * Checks whether a regex is reasonably safe from catastrophic (exponential-time) backtracking --
4
+ * e.g. `/(a+)+$/`, the classic case that freezes on a long non-matching input. Every plot
5
+ * component tests a compiled `seriesFilter` regex against every series name on every redraw
6
+ * frame (not just once), so an unvetted pattern from a free-text filter field can hang the whole
7
+ * render loop, not just one call. Delegates to the `safe-regex` package, which walks the regex's
8
+ * actual parsed structure (via `regexp-tree`) rather than pattern-matching its source string, so
9
+ * it catches more than a hand-rolled "look for nested quantifiers" check would.
10
+ * @param pattern The regex (or its string source) to check
11
+ * @return `true` if the pattern is reasonably safe to run against arbitrary input; `false` if it
12
+ * risks catastrophic backtracking
13
+ */
14
+ export declare function isSafeRegex(pattern: RegExp | string): boolean;
15
+ /**
16
+ * Wraps the creation of the regex in a try/catch and returns the regex, wrapped in a `Result`,
4
17
  * when it is valid. This can be used, for example, in a text field where the user types a regex.
18
+ * Also rejects a pattern that compiles fine but risks catastrophic backtracking (see
19
+ * {@link isSafeRegex}) -- a syntax error and an exponential-time pattern are both "can't use this"
20
+ * outcomes from the caller's point of view, so both are reported the same way.
5
21
  * @param regexString The string representation of the regex
6
- * @return The regular expression (`RegExp`) wrapped in an option. If the regexp
7
- * is invalid, then the option is none.
22
+ * @return The regular expression (`RegExp`) wrapped in a successful `Result`. If the regex is
23
+ * invalid, or is unsafe, then a failed `Result` holding a message that says why.
8
24
  */
9
25
  export declare function regexFilter(regexString: string): Result<RegExp, string>;
26
+ /**
27
+ * Builds a regex that matches `text` literally, for callers (e.g. a series-name filter input)
28
+ * who want to search for plain text without regex metacharacters (`.`, `*`, `+`, `(`, etc.) in it
29
+ * being given unintended regex semantics. Escapes those metacharacters before handing the result
30
+ * to {@link regexFilter}, so it shares the same `Result`-wrapped, never-throws contract.
31
+ * @param text The literal text to match
32
+ * @return The regular expression (`RegExp`) matching `text` literally, wrapped in a `Result` (see
33
+ * {@link regexFilter})
34
+ */
35
+ export declare function literalFilter(text: string): Result<RegExp, string>;
36
+ //# sourceMappingURL=regexFilter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"regexFilter.d.ts","sourceRoot":"","sources":["../../../../src/app/charts/filters/regexFilter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,MAAM,EAAgB,MAAM,WAAW,CAAC;AAGpE;;;;;;;;;;;GAWG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAE7D;AAED;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAcvE;AAED;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAElE"}
@@ -1,18 +1,52 @@
1
1
  import { failureResult, successResult } from "result-fn";
2
+ import safeRegex from "safe-regex";
2
3
  /**
3
- * Wraps the creation of the regex in a try/catch and returns the regex, wrapped in an option,
4
+ * Checks whether a regex is reasonably safe from catastrophic (exponential-time) backtracking --
5
+ * e.g. `/(a+)+$/`, the classic case that freezes on a long non-matching input. Every plot
6
+ * component tests a compiled `seriesFilter` regex against every series name on every redraw
7
+ * frame (not just once), so an unvetted pattern from a free-text filter field can hang the whole
8
+ * render loop, not just one call. Delegates to the `safe-regex` package, which walks the regex's
9
+ * actual parsed structure (via `regexp-tree`) rather than pattern-matching its source string, so
10
+ * it catches more than a hand-rolled "look for nested quantifiers" check would.
11
+ * @param pattern The regex (or its string source) to check
12
+ * @return `true` if the pattern is reasonably safe to run against arbitrary input; `false` if it
13
+ * risks catastrophic backtracking
14
+ */
15
+ export function isSafeRegex(pattern) {
16
+ return safeRegex(pattern);
17
+ }
18
+ /**
19
+ * Wraps the creation of the regex in a try/catch and returns the regex, wrapped in a `Result`,
4
20
  * when it is valid. This can be used, for example, in a text field where the user types a regex.
21
+ * Also rejects a pattern that compiles fine but risks catastrophic backtracking (see
22
+ * {@link isSafeRegex}) -- a syntax error and an exponential-time pattern are both "can't use this"
23
+ * outcomes from the caller's point of view, so both are reported the same way.
5
24
  * @param regexString The string representation of the regex
6
- * @return The regular expression (`RegExp`) wrapped in an option. If the regexp
7
- * is invalid, then the option is none.
25
+ * @return The regular expression (`RegExp`) wrapped in a successful `Result`. If the regex is
26
+ * invalid, or is unsafe, then a failed `Result` holding a message that says why.
8
27
  */
9
28
  export function regexFilter(regexString) {
10
29
  try {
11
30
  const regex = new RegExp(regexString);
31
+ if (!isSafeRegex(regex)) {
32
+ return failureResult(`Refusing to use a regex that risks catastrophic backtracking; regex_expression: ${regexString}`);
33
+ }
12
34
  return successResult(regex);
13
35
  }
14
36
  catch (error) {
15
- return failureResult(`Unable to compile the regex expression; regex_expression: ${regexString}`);
37
+ return failureResult(`Unable to compile the regex expression; regex_expression: ${regexString}; error: ${error}`);
16
38
  }
17
39
  }
40
+ /**
41
+ * Builds a regex that matches `text` literally, for callers (e.g. a series-name filter input)
42
+ * who want to search for plain text without regex metacharacters (`.`, `*`, `+`, `(`, etc.) in it
43
+ * being given unintended regex semantics. Escapes those metacharacters before handing the result
44
+ * to {@link regexFilter}, so it shares the same `Result`-wrapped, never-throws contract.
45
+ * @param text The literal text to match
46
+ * @return The regular expression (`RegExp`) matching `text` literally, wrapped in a `Result` (see
47
+ * {@link regexFilter})
48
+ */
49
+ export function literalFilter(text) {
50
+ return regexFilter(text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'));
51
+ }
18
52
  //# sourceMappingURL=regexFilter.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"regexFilter.js","sourceRoot":"","sources":["../../../../src/app/charts/filters/regexFilter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAU,aAAa,EAAC,MAAM,WAAW,CAAC;AAE/D;;;;;;GAMG;AACH,MAAM,UAAU,WAAW,CAAC,WAAmB;IAC3C,IAAI,CAAC;QACD,MAAM,KAAK,GAAG,IAAI,MAAM,CAAC,WAAW,CAAC,CAAA;QACrC,OAAO,aAAa,CAAC,KAAK,CAAC,CAAA;IAC/B,CAAC;IAAC,OAAM,KAAK,EAAE,CAAC;QACZ,OAAO,aAAa,CAAC,6DAA6D,WAAW,EAAE,CAAC,CAAA;IACpG,CAAC;AACL,CAAC"}
1
+ {"version":3,"file":"regexFilter.js","sourceRoot":"","sources":["../../../../src/app/charts/filters/regexFilter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAe,aAAa,EAAC,MAAM,WAAW,CAAC;AACpE,OAAO,SAAS,MAAM,YAAY,CAAC;AAEnC;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,WAAW,CAAC,OAAwB;IAChD,OAAO,SAAS,CAAC,OAAO,CAAC,CAAA;AAC7B,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,WAAW,CAAC,WAAmB;IAC3C,IAAI,CAAC;QACD,MAAM,KAAK,GAAG,IAAI,MAAM,CAAC,WAAW,CAAC,CAAA;QACrC,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE,CAAC;YACtB,OAAO,aAAa,CAChB,mFAAmF,WAAW,EAAE,CACnG,CAAA;QACL,CAAC;QACD,OAAO,aAAa,CAAC,KAAK,CAAC,CAAA;IAC/B,CAAC;IAAC,OAAM,KAAK,EAAE,CAAC;QACZ,OAAO,aAAa,CAChB,6DAA6D,WAAW,YAAY,KAAK,EAAE,CAC9F,CAAA;IACL,CAAC;AACL,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,aAAa,CAAC,IAAY;IACtC,OAAO,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,qBAAqB,EAAE,MAAM,CAAC,CAAC,CAAA;AACnE,CAAC"}
@@ -0,0 +1,21 @@
1
+ import { AxisInterval } from "../axes/AxisInterval";
2
+ import { type JSX } from "react";
3
+ import { BaseAxisRange } from "../axes/BaseAxisRange";
4
+ import type { BaseAxis } from "../axes/axes";
5
+ export type Props = {
6
+ /**
7
+ * Callback when axes bounds change.
8
+ * @param ranges The ranges (start, end) for each axis in the plot
9
+ */
10
+ onUpdateAxesInterval?: (ranges: Map<string, AxisInterval>) => void;
11
+ children: JSX.Element | Array<JSX.Element>;
12
+ };
13
+ /**
14
+ * The React context provider for the {@link UseAxesValues}
15
+ * @param props The properties
16
+ * @return The children wrapped in this provider
17
+ * @template AR The type of the axis range (e.g. {@link ContinuousAxisRange} or {@link OrdinalAxisRange})
18
+ * @template A The axis type
19
+ */
20
+ export default function AxesProvider<AR extends BaseAxisRange, A extends BaseAxis>(props: Props): JSX.Element;
21
+ //# sourceMappingURL=AxesProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AxesProvider.d.ts","sourceRoot":"","sources":["../../../../src/app/charts/hooks/AxesProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAC,KAAK,GAAG,EAAyC,MAAM,OAAO,CAAC;AACvE,OAAO,EAAC,aAAa,EAAC,MAAM,uBAAuB,CAAC;AACpD,OAAO,KAAK,EAAC,QAAQ,EAAC,MAAM,cAAc,CAAC;AAQ3C,MAAM,MAAM,KAAK,GAAG;IAChB;;;OAGG;IACH,oBAAoB,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC,KAAK,IAAI,CAAA;IAElE,QAAQ,EAAE,GAAG,CAAC,OAAO,GAAG,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;CAC7C,CAAA;AACD;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,YAAY,CAAC,EAAE,SAAS,aAAa,EAAE,CAAC,SAAS,QAAQ,EAAE,KAAK,EAAE,KAAK,GAAG,GAAG,CAAC,OAAO,CAiR5G"}
@@ -0,0 +1,213 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useCallback, useMemo, useRef, useState } from "react";
3
+ import { usePlotDimensions } from "./usePlotDimensions";
4
+ import { AxesState } from "../axes/AxesState";
5
+ import { Optional } from "result-fn";
6
+ import { AxesContext } from "./useAxes";
7
+ /**
8
+ * The React context provider for the {@link UseAxesValues}
9
+ * @param props The properties
10
+ * @return The children wrapped in this provider
11
+ * @template AR The type of the axis range (e.g. {@link ContinuousAxisRange} or {@link OrdinalAxisRange})
12
+ * @template A The axis type
13
+ */
14
+ export default function AxesProvider(props) {
15
+ const { onUpdateAxesInterval, children } = props;
16
+ const plotDimensions = usePlotDimensions();
17
+ const [xAxesState, setXAxesState] = useState(AxesState.empty());
18
+ const [yAxesState, setYAxesState] = useState(AxesState.empty());
19
+ const axisAssignmentsRef = useRef(new Map());
20
+ const axesBoundsUpdateHandlersRef = useRef(new Map());
21
+ const axesRangeRef = useRef(new Map());
22
+ /**
23
+ * Retrieves the x-axis and y-axis assignments for the specified series. If the series does not
24
+ * have an assignment, then we assume it is using the default x- and y-axes.
25
+ * @param seriesName The name of the series for which to retrieve the axes assignments
26
+ * @return An {@link AxesAssignment} for the specified axes.
27
+ */
28
+ const axisAssignmentsFor = useCallback((seriesName) => axisAssignmentsRef.current.get(seriesName) || {
29
+ xAxis: xAxesState.axisDefaultId().getOrElse(""),
30
+ yAxis: yAxesState.axisDefaultId().getOrElse("")
31
+ }, [xAxesState, yAxesState]);
32
+ /**
33
+ * Called when the domain/range is updated on one or more of the chart's axes (generally x-axes). Stores
34
+ * the updated ranges, and in turn, dispatches the update to all the registered domain/range update
35
+ * handlers (e.g. the axes, which redraw themselves with their new domain).
36
+ * @param updates A map holding the axis ID to the updated axis time-range (i.e., map(axis_id, axis_time_range))
37
+ */
38
+ const updateAxisRanges = useCallback((updates) => {
39
+ // update the current time-ranges reference
40
+ updates.forEach((range, id) => {
41
+ axesRangeRef.current.set(id, range);
42
+ });
43
+ // dispatch the updates to all the registered handlers
44
+ axesBoundsUpdateHandlersRef.current
45
+ .forEach((handler) => handler(updates, plotDimensions.plotDimensions));
46
+ }, [plotDimensions.plotDimensions]);
47
+ /**
48
+ * Sets the axis ranges specified in the input map (without dispatching them to the update handlers)
49
+ * @param ranges The ranges to set
50
+ */
51
+ const setAxesRanges = useCallback((ranges) => {
52
+ ranges.forEach((range, id) => {
53
+ axesRangeRef.current.set(id, range);
54
+ });
55
+ }, []);
56
+ /**
57
+ * Sets the axis range for the specified axis ID (without dispatching it to the update handlers)
58
+ * @param axisId The axis ID
59
+ * @param range The range to set
60
+ */
61
+ const setAxisRangeFor = useCallback((axisId, range) => {
62
+ axesRangeRef.current.set(axisId, range);
63
+ }, []);
64
+ /**
65
+ * Sets the axis bounds (the current range) for the specified axis ID. Note that this does not
66
+ * change the original axis interval, doesn't dispatch the change to the update handlers, and
67
+ * does nothing when the axis has no range yet.
68
+ * @param axisId The axis ID
69
+ * @param interval The interval
70
+ */
71
+ const setAxisIntervalFor = useCallback((axisId, interval) => {
72
+ Optional.ofNullable(axesRangeRef.current.get(axisId))
73
+ .map(range => range.update(interval.start, interval.end))
74
+ .ifPresent(updatedRange => axesRangeRef.current.set(axisId, updatedRange));
75
+ }, []);
76
+ /**
77
+ * Sets the original axis interval for the axis range (does nothing when the axis has no range yet)
78
+ * @param axisId The axis ID
79
+ * @param interval The interval to which to set the origin interval
80
+ */
81
+ const setOriginalAxisIntervalFor = useCallback((axisId, interval) => {
82
+ Optional.ofNullable(axesRangeRef.current.get(axisId))
83
+ .map(range => range.updateOriginal(interval.start, interval.end))
84
+ .ifPresent(updatedRange => axesRangeRef.current.set(axisId, updatedRange));
85
+ }, []);
86
+ /**
87
+ * Re-applies the specified axis' stored range: dispatches it, unchanged, to the update handlers
88
+ * (so that the axis redraws with it). Note that this does *not* restore the axis' original
89
+ * range. Does nothing when the axis has no range.
90
+ * @param axisId The ID of the axis
91
+ */
92
+ const resetAxisIntervalFor = useCallback((axisId) => {
93
+ Optional
94
+ .ofNullable(axesRangeRef.current.get(axisId))
95
+ .map(range => new Map([[axisId, range]]))
96
+ .ifPresent(updates => updateAxisRanges(updates));
97
+ }, [updateAxisRanges]);
98
+ /**
99
+ * Sets the ranges of the axes in the specified map, and dispatches them to the update handlers
100
+ * (the same as {@link updateAxisRanges}). Axes that aren't in the map are left as they are, so
101
+ * the default (empty) map changes nothing.
102
+ * @param [axesRanges=new Map()] An optional map holds bounds for specified axes. The map
103
+ * associates an axis ID with the new bounds.
104
+ */
105
+ const resetAxesRanges = useCallback((axesRanges = new Map()) => {
106
+ updateAxisRanges(axesRanges);
107
+ }, [updateAxisRanges]);
108
+ /**
109
+ * Adds a handler to deal with updates to the bounds of the axes
110
+ * @param handlerId the unique ID of the handler
111
+ * @param handler The handler function that accepts a map of updates and a plot dimension
112
+ * @return A map with all the handlers
113
+ * @throws Error when a handler with the same ID is already registered
114
+ */
115
+ const addAxesRangesUpdateHandler = useCallback((handlerId, handler) => {
116
+ if (axesBoundsUpdateHandlersRef.current.has(handlerId)) {
117
+ throw new Error(`Handler with ID already exists, please remove it before adding it; ` +
118
+ `handler_id: ${handlerId}; ` +
119
+ `existing_handler_ids: [${Array.from(axesBoundsUpdateHandlersRef.current.keys()).join(", ")}]`);
120
+ }
121
+ return axesBoundsUpdateHandlersRef.current.set(handlerId, handler);
122
+ }, []);
123
+ /**
124
+ * Removes the axis-update handler with the specified ID
125
+ * @param handlerId The ID of the handler to remove
126
+ * @return `true` when the handler was registered (and has been removed); `false` otherwise
127
+ */
128
+ const removeAxesRangesUpdateHandler = useCallback((handlerId) => axesBoundsUpdateHandlersRef.current.delete(handlerId), []);
129
+ /**
130
+ * Adds an x-axis to the x-axes state (a new state object, so dependents re-render)
131
+ * @param axis The axis to add
132
+ * @param id The ID of the axis to add
133
+ * @param [range] The initial axis range (when given, it's stored as the axis' range)
134
+ */
135
+ const addXAxis = useCallback((axis, id, range) => {
136
+ setXAxesState(xAxesState.addAxis(axis, id));
137
+ if (range !== undefined) {
138
+ axesRangeRef.current.set(id, range);
139
+ }
140
+ }, [xAxesState]);
141
+ /**
142
+ * Adds a y-axis to the y-axes state (a new state object, so dependents re-render)
143
+ * @param axis The axis to add
144
+ * @param id The ID of the axis to add
145
+ * @param [range] The initial axis range (when given, it's stored as the axis' range)
146
+ */
147
+ const addYAxis = useCallback((axis, id, range) => {
148
+ setYAxesState(yAxesState.addAxis(axis, id));
149
+ if (range !== undefined) {
150
+ axesRangeRef.current.set(id, range);
151
+ }
152
+ }, [yAxesState]);
153
+ /**
154
+ * Sets the axes assigned to each series (replacing any earlier assignments)
155
+ * @param assignments The assignment of the series to their axes
156
+ */
157
+ const setAxisAssignments = useCallback((assignments) => {
158
+ axisAssignmentsRef.current = assignments;
159
+ }, []);
160
+ /**
161
+ * @return A copy of the map of the axes' current ranges, by axis ID
162
+ */
163
+ const axesRanges = useCallback(() => new Map(axesRangeRef.current), []);
164
+ /**
165
+ * Retrieves the current axis range for the specified axis ID
166
+ * @param axisId The ID of the axis
167
+ * @return The axis' range, or an empty `Optional` when the axis has no range
168
+ */
169
+ const axisRangeFor = useCallback((axisId) => Optional.ofNullable(axesRangeRef.current.get(axisId)), []);
170
+ // the context's `value` prop is typed as `unknown` (see `AxesContext` in `useAxes.tsx`), so
171
+ // the object literal needs its own explicit type here to give the handler functions below
172
+ // their parameter types -- otherwise they'd fall back to implicit `any`.
173
+ //
174
+ // Memoized so consumers relying on this context value's identity (e.g. a `useMemo`/effect
175
+ // keyed on it) don't re-run on essentially every render of anything above this provider --
176
+ // previously a fresh object literal every render, with every method inside it also a fresh
177
+ // closure. This is the same class of bug already documented/worked around in ScatterPlot.tsx/
178
+ // RasterPlot.tsx/OutlierPlot.tsx (their own comments on `axesRanges` never being memoized
179
+ // here) -- those workarounds (refs populated imperatively instead of `useMemo([axesRanges])`)
180
+ // are left in place; they're redundant once this is memoized, but harmless, and removing them
181
+ // isn't part of this change.
182
+ const value = useMemo(() => ({
183
+ xAxesState,
184
+ yAxesState,
185
+ addXAxis,
186
+ addYAxis,
187
+ setAxisAssignments,
188
+ axisAssignmentsFor,
189
+ updateAxisRanges,
190
+ axesRanges,
191
+ axisRangeFor,
192
+ setAxesRanges,
193
+ setAxisRangeFor,
194
+ setAxisIntervalFor,
195
+ setOriginalAxisIntervalFor,
196
+ resetAxesRanges,
197
+ resetAxisIntervalFor,
198
+ onUpdateAxesInterval,
199
+ addAxesRangesUpdateHandler,
200
+ removeAxesRangesUpdateHandler,
201
+ }), [
202
+ xAxesState, yAxesState,
203
+ addXAxis, addYAxis,
204
+ setAxisAssignments, axisAssignmentsFor,
205
+ updateAxisRanges, axesRanges, axisRangeFor,
206
+ setAxesRanges, setAxisRangeFor, setAxisIntervalFor, setOriginalAxisIntervalFor,
207
+ resetAxesRanges, resetAxisIntervalFor,
208
+ onUpdateAxesInterval,
209
+ addAxesRangesUpdateHandler, removeAxesRangesUpdateHandler,
210
+ ]);
211
+ return _jsx(AxesContext.Provider, { value: value, children: children });
212
+ }
213
+ //# sourceMappingURL=AxesProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AxesProvider.js","sourceRoot":"","sources":["../../../../src/app/charts/hooks/AxesProvider.tsx"],"names":[],"mappings":";AACA,OAAO,EAAW,WAAW,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAC,MAAM,OAAO,CAAC;AAGvE,OAAO,EAAC,iBAAiB,EAAC,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAC,SAAS,EAAC,MAAM,mBAAmB,CAAC;AAG5C,OAAO,EAAC,QAAQ,EAAC,MAAM,WAAW,CAAC;AACnC,OAAO,EAAC,WAAW,EAAqB,MAAM,WAAW,CAAC;AAW1D;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,YAAY,CAA+C,KAAY;IAC3F,MAAM,EAAC,oBAAoB,EAAE,QAAQ,EAAC,GAAG,KAAK,CAAA;IAE9C,MAAM,cAAc,GAAG,iBAAiB,EAAE,CAAA;IAE1C,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,QAAQ,CAAe,SAAS,C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;IAED,4FAA4F;IAC5F,0FAA0F;IAC1F,yEAAyE;IACzE,EAAE;IACF,0FAA0F;IAC1F,2FAA2F;IAC3F,2FAA2F;IAC3F,8FAA8F;IAC9F,0FAA0F;IAC1F,8FAA8F;IAC9F,8FAA8F;IAC9F,6BAA6B;IAC7B,MAAM,KAAK,GAAyB,OAAO,CACvC,GAAG,EAAE,CAAC,CAAC;QACH,UAAU;QACV,UAAU;QACV,QAAQ;QACR,QAAQ;QACR,kBAAkB;QAClB,kBAAkB;QAClB,gBAAgB;QAChB,UAAU;QACV,YAAY;QACZ,aAAa;QACb,eAAe;QACf,kBAAkB;QAClB,0BAA0B;QAC1B,eAAe;QACf,oBAAoB;QACpB,oBAAoB;QACpB,0BAA0B;QAC1B,6BAA6B;KAChC,CAAC,EACF;QACI,UAAU,EAAE,UAAU;QACtB,QAAQ,EAAE,QAAQ;QAClB,kBAAkB,EAAE,kBAAkB;QACtC,gBAAgB,EAAE,UAAU,EAAE,YAAY;QAC1C,aAAa,EAAE,eAAe,EAAE,kBAAkB,EAAE,0BAA0B;QAC9E,eAAe,EAAE,oBAAoB;QACrC,oBAAoB;QACpB,0BAA0B,EAAE,6BAA6B;KAC5D,CACJ,CAAA;IAED,OAAO,KAAC,WAAW,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,YACpC,QAAQ,GACU,CAAA;AAC3B,CAAC"}
@@ -0,0 +1,25 @@
1
+ import { type JSX } from "react";
2
+ import { type SvgStyle } from "../styling/svgStyle";
3
+ export type Props = {
4
+ chartId: number;
5
+ color: string;
6
+ backgroundColor: string;
7
+ svgStyle?: Partial<SvgStyle>;
8
+ children: JSX.Element | Array<JSX.Element>;
9
+ };
10
+ /**
11
+ * Creates and sizes the chart's `<canvas>` element, and provides the resulting canvas element and
12
+ * drawing context (via {@link useCanvasSurface}) to descendants -- most notably {@link ChartProvider}.
13
+ *
14
+ * Must be rendered as a descendant of {@link PlotDimensionsProvider}. The canvas's size is derived
15
+ * entirely from {@link usePlotDimensions}'s `plotDimensions`/`margin` -- the single source of truth
16
+ * for the chart's dimensions -- rather than from static width/height props. This matters because
17
+ * `usePlotDimensions` also exposes `updateDimensions(...)`, an escape hatch for updating
18
+ * dimensions independent of any prop (e.g. from a `ResizeObserver`-driven descendant); sourcing
19
+ * the canvas's size from the same place those updates land keeps the canvas from ever drifting out
20
+ * of sync with what the axes/plots believe the plot dimensions to be.
21
+ * @param props The properties
22
+ * @return The children, wrapped in the canvas-surface context provider
23
+ */
24
+ export default function CanvasSurfaceProvider(props: Props): JSX.Element;
25
+ //# sourceMappingURL=CanvasSurfaceProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CanvasSurfaceProvider.d.ts","sourceRoot":"","sources":["../../../../src/app/charts/hooks/CanvasSurfaceProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,GAAG,EAAoD,MAAM,OAAO,CAAC;AAKlF,OAAO,EAAkB,KAAK,QAAQ,EAAC,MAAM,qBAAqB,CAAC;AAInE,MAAM,MAAM,KAAK,GAAG;IAChB,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,MAAM,CAAA;IACb,eAAe,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAA;IAC5B,QAAQ,EAAE,GAAG,CAAC,OAAO,GAAG,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;CAC7C,CAAA;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,OAAO,UAAU,qBAAqB,CAAC,KAAK,EAAE,KAAK,GAAG,GAAG,CAAC,OAAO,CAqFvE"}
@@ -0,0 +1,76 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
3
+ import { usePlotDimensions } from "./usePlotDimensions";
4
+ import { createCanvasContext, resizeCanvasTo } from "../plots/plot";
5
+ import { CanvasSurfaceContext } from "./useCanvasSurface";
6
+ import { initialSvgStyle } from "../styling/svgStyle";
7
+ const defaultBackground = '#202020';
8
+ /**
9
+ * Creates and sizes the chart's `<canvas>` element, and provides the resulting canvas element and
10
+ * drawing context (via {@link useCanvasSurface}) to descendants -- most notably {@link ChartProvider}.
11
+ *
12
+ * Must be rendered as a descendant of {@link PlotDimensionsProvider}. The canvas's size is derived
13
+ * entirely from {@link usePlotDimensions}'s `plotDimensions`/`margin` -- the single source of truth
14
+ * for the chart's dimensions -- rather than from static width/height props. This matters because
15
+ * `usePlotDimensions` also exposes `updateDimensions(...)`, an escape hatch for updating
16
+ * dimensions independent of any prop (e.g. from a `ResizeObserver`-driven descendant); sourcing
17
+ * the canvas's size from the same place those updates land keeps the canvas from ever drifting out
18
+ * of sync with what the axes/plots believe the plot dimensions to be.
19
+ * @param props The properties
20
+ * @return The children, wrapped in the canvas-surface context provider
21
+ */
22
+ export default function CanvasSurfaceProvider(props) {
23
+ const { chartId, color, backgroundColor, children } = props;
24
+ // the container (canvas) size is the plot area plus its margins -- i.e. the inverse of what
25
+ // plotDimensionsFrom(width, height, margin) computes -- reconstructed from usePlotDimensions'
26
+ // state rather than from props, so this stays correct even when dimensions are updated via
27
+ // updateDimensions(...) rather than a containerDimensions prop change.
28
+ const { plotDimensions, margin } = usePlotDimensions();
29
+ const width = plotDimensions.width + margin.left + margin.right;
30
+ const height = plotDimensions.height + margin.top + margin.bottom;
31
+ const svgStyle = useMemo(() => ({ ...initialSvgStyle, ...props.svgStyle }), [props.svgStyle]);
32
+ const [canvas, setCanvas] = useState(null);
33
+ const [canvasContext, setCanvasContext] = useState(null);
34
+ // captures the dimensions active at the exact moment this component first renders
35
+ const initialDimensionsRef = useRef({ width, height });
36
+ // a plain ref latch, not `canvasContext` state, guards the one-time canvas-context creation
37
+ // below
38
+ const hasCreatedCanvasContext = useRef(false);
39
+ // keep the canvas's backing store in sync with the plot dimensions, however they change
40
+ // (prop-driven container resize, or a direct updateDimensions(...) call)
41
+ useEffect(() => {
42
+ if (canvasContext) {
43
+ resizeCanvasTo(canvasContext, { width, height });
44
+ canvasContext.requestRedraw();
45
+ }
46
+ }, [canvasContext, width, height]);
47
+ const setCanvasCallback = useCallback(
48
+ /**
49
+ * Callback for setting the canvas element and updating its CSS style.
50
+ * @param canvasElement - The canvas element, or null if not available (e.g. unmounting).
51
+ */
52
+ (canvasElement) => {
53
+ if (canvasElement) {
54
+ setCanvas(canvasElement);
55
+ // create the canvas context (and do its initial sizing) exactly once, the moment
56
+ // the canvas element first attaches.
57
+ if (!hasCreatedCanvasContext.current) {
58
+ hasCreatedCanvasContext.current = true;
59
+ const cc = createCanvasContext(chartId, canvasElement, color);
60
+ resizeCanvasTo(cc, initialDimensionsRef.current);
61
+ setCanvasContext(cc);
62
+ }
63
+ // apply the style/background/color from the defaults and any style object passed
64
+ // in as properties, one property at a time, rather than overwriting the whole
65
+ // `style` attribute
66
+ Object.getOwnPropertyNames(svgStyle)
67
+ .filter(name => name !== 'width' && name !== 'height')
68
+ .forEach(name => canvasElement.style.setProperty(name, String(svgStyle[name])));
69
+ canvasElement.style.backgroundColor = backgroundColor !== defaultBackground ? backgroundColor : '';
70
+ canvasElement.style.color = color;
71
+ }
72
+ }, [backgroundColor, chartId, color, svgStyle]);
73
+ const value = useMemo(() => ({ canvas, canvasContext }), [canvas, canvasContext]);
74
+ return (_jsxs(CanvasSurfaceContext.Provider, { value: value, children: [_jsx("div", { style: { position: 'relative', width, height }, children: _jsx("canvas", { ref: setCanvasCallback }) }), children] }));
75
+ }
76
+ //# sourceMappingURL=CanvasSurfaceProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CanvasSurfaceProvider.js","sourceRoot":"","sources":["../../../../src/app/charts/hooks/CanvasSurfaceProvider.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAW,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAC,MAAM,OAAO,CAAC;AAClF,OAAO,EAAC,iBAAiB,EAAC,MAAM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K,CAAA;QACrC,CAAC;IACL,CAAC,EACD,CAAC,eAAe,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,CAAC,CAC9C,CAAA;IAED,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,EAAC,MAAM,EAAE,aAAa,EAAC,CAAC,EAAE,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC,CAAA;IAE/E,OAAO,CACH,MAAC,oBAAoB,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,aACvC,cAAK,KAAK,EAAE,EAAC,QAAQ,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,EAAC,YAC7C,iBAAQ,GAAG,EAAE,iBAAiB,GAAG,GAC/B,EACL,QAAQ,IACmB,CACnC,CAAA;AACL,CAAC"}
@@ -0,0 +1,40 @@
1
+ import type { BaseAxis, SeriesStyle } from "../axes/axes";
2
+ import { BaseAxisRange } from "../axes/BaseAxisRange";
3
+ import { type JSX } from "react";
4
+ /**
5
+ * The properties for the {@link ChartProvider}
6
+ * @template S The type of the series style
7
+ */
8
+ export interface Props<S extends SeriesStyle> {
9
+ /**
10
+ * The unique ID for the chart
11
+ */
12
+ chartId: number;
13
+ /**
14
+ * Base color
15
+ */
16
+ color: string;
17
+ /**
18
+ * The base/default background color
19
+ */
20
+ backgroundColor: string;
21
+ /**
22
+ * A `map(series_name -> series_line_style)` holding the style for each series
23
+ */
24
+ seriesStyles?: Map<string, S>;
25
+ /**
26
+ * An optional regular expression used against the series names to determine which series to show in the chart
27
+ */
28
+ seriesFilter?: RegExp;
29
+ children: JSX.Element | Array<JSX.Element>;
30
+ }
31
+ /**
32
+ * The React context provider for the {@link UseChartValues}
33
+ * @param props The properties
34
+ * @return The children wrapped in this provider
35
+ * @template S The type of the series style
36
+ * @template AR The type of the axis range
37
+ * @template A The type of the axis
38
+ */
39
+ export default function ChartProvider<S extends SeriesStyle, AR extends BaseAxisRange, A extends BaseAxis>(props: Props<S>): JSX.Element;
40
+ //# sourceMappingURL=ChartProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ChartProvider.d.ts","sourceRoot":"","sources":["../../../../src/app/charts/hooks/ChartProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,QAAQ,EAAE,WAAW,EAAC,MAAM,cAAc,CAAC;AACxD,OAAO,EAAC,aAAa,EAAC,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAC,KAAK,GAAG,EAAU,MAAM,OAAO,CAAC;AAYxC;;;GAGG;AACH,MAAM,WAAW,KAAK,CAAC,CAAC,SAAS,WAAW;IACxC;;OAEG;IACH,OAAO,EAAE,MAAM,CAAA;IACf;;OAEG;IACH,KAAK,EAAE,MAAM,CAAA;IACb;;OAEG;IACH,eAAe,EAAE,MAAM,CAAA;IACvB;;OAEG;IACH,YAAY,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,CAAA;IAC7B;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;IAErB,QAAQ,EAAE,GAAG,CAAC,OAAO,GAAG,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;CAC7C;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,CAAC,SAAS,WAAW,EAAE,EAAE,SAAS,aAAa,EAAE,CAAC,SAAS,QAAQ,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,OAAO,CA2BvI"}
@@ -0,0 +1,33 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useMemo } from "react";
3
+ import { defaultUseChartValues } from "./defaultUseChartValues";
4
+ import { useAxes } from "./useAxes";
5
+ import { useMouse } from "./useMouse";
6
+ import { useTooltip } from "./useTooltip";
7
+ import { useCanvasSurface } from "./useCanvasSurface";
8
+ import { ChartContext } from "./useChart";
9
+ // the defaults (constants, so that their identity doesn't change from one render to the next)
10
+ const DEFAULT_SERIES_FILTER = defaultUseChartValues().seriesFilter;
11
+ const NO_SERIES_STYLES = new Map();
12
+ /**
13
+ * The React context provider for the {@link UseChartValues}
14
+ * @param props The properties
15
+ * @return The children wrapped in this provider
16
+ * @template S The type of the series style
17
+ * @template AR The type of the axis range
18
+ * @template A The type of the axis
19
+ */
20
+ export default function ChartProvider(props) {
21
+ const { chartId, color, backgroundColor, seriesFilter = DEFAULT_SERIES_FILTER, seriesStyles = NO_SERIES_STYLES, } = props;
22
+ // canvas/canvasContext come from CanvasSurfaceProvider (a shared ancestor -- see Chart.tsx),
23
+ // which sizes the canvas from usePlotDimensions() rather than from props, so this always
24
+ // reflects the same dimensions the axes/plots are using.
25
+ const { canvas, canvasContext } = useCanvasSurface();
26
+ const axes = useAxes();
27
+ const mouse = useMouse();
28
+ const tooltip = useTooltip();
29
+ // (memoized, so that the chart's components only re-render when something in it changes)
30
+ const value = useMemo(() => ({ chartId, color, backgroundColor, seriesStyles, seriesFilter, canvasContext, canvas, axes, mouse, tooltip }), [chartId, color, backgroundColor, seriesStyles, seriesFilter, canvasContext, canvas, axes, mouse, tooltip]);
31
+ return _jsx(ChartContext.Provider, { value: value, children: props.children });
32
+ }
33
+ //# sourceMappingURL=ChartProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ChartProvider.js","sourceRoot":"","sources":["../../../../src/app/charts/hooks/ChartProvider.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAW,OAAO,EAAC,MAAM,OAAO,CAAC;AACxC,OAAO,EAAC,qBAAqB,EAAC,MAAM,yBAAyB,CAAC;AAC9D,OAAO,EAAC,OAAO,EAAC,MAAM,WAAW,CAAC;AAClC,OAAO,EAAC,QAAQ,EAAC,MAAM,YAAY,CAAC;AACpC,OAAO,EAAC,UAAU,EAAC,MAAM,cAAc,CAAC;AACxC,OAAO,EAAC,gBAAgB,EAAC,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAC,YAAY,EAAC,MAAM,YAAY,CAAC;AAExC,8FAA8F;AAC9F,MAAM,qBAAqB,GAAG,qBAAqB,EAAE,CAAC,YAAY,CAAA;AAClE,MAAM,gBAAgB,GAAG,IAAI,GAAG,EAAuB,CAAA;AA+BvD;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,UAAU,aAAa,CAAsE,KAAe;IACtH,MAAM,EACF,OAAO,EACP,KAAK,EACL,eAAe,EACf,YAAY,GAAG,qBAAqB,EACpC,YAAY,GAAG,gBAAkC,GACpD,GAAG,KAAK,CAAA;IAET,6FAA6F;IAC7F,yFAAyF;IACzF,yDAAyD;IACzD,MAAM,EAAC,MAAM,EAAE,aAAa,EAAC,GAAG,gBAAgB,EAAE,CAAA;IAElD,MAAM,IAAI,GAAG,OAAO,EAAS,CAAA;IAC7B,MAAM,KAAK,GAAG,QAAQ,EAAE,CAAA;IACxB,MAAM,OAAO,GAAG,UAAU,EAAE,CAAA;IAE5B,yFAAyF;IACzF,MAAM,KAAK,GAAG,OAAO,CACjB,GAAG,EAAE,CAAC,CAAC,EAAC,OAAO,EAAE,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAC,CAAC,EAClH,CAAC,OAAO,EAAE,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,CAAC,CAC7G,CAAA;IAED,OAAO,KAAC,YAAY,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,YACrC,KAAK,CAAC,QAAQ,GACK,CAAA;AAC5B,CAAC"}
@@ -0,0 +1,23 @@
1
+ import { type JSX } from "react";
2
+ type Props = {
3
+ children: JSX.Element | Array<JSX.Element>;
4
+ };
5
+ /**
6
+ * Provides the chart's interactions: the mouse-over and mouse-leave handlers (see {@link useMouse}),
7
+ * the tooltip's content provider and visibility (see {@link useTooltip}), and the hovered series
8
+ * (see {@link useHoveredSeries}).
9
+ *
10
+ * The plots hit-test the mouse, and call the mouse handlers: a mouse-over sets the hovered series,
11
+ * and then calls every registered mouse-over handler (e.g. the tooltip's); a mouse-leave clears the
12
+ * hovered series, and calls every registered mouse-leave handler.
13
+ *
14
+ * The handler registries live in refs, so the mouse and tooltip values never change identity (the
15
+ * tooltip's changes only with its visibility), and registering a handler never re-renders anything.
16
+ * @param props The children
17
+ * @return The children, wrapped in the interaction contexts
18
+ * @template D The type of the data object for the series
19
+ * @template TM The type of the metadata object for the series
20
+ */
21
+ export default function InteractionProvider<D, TM>(props: Props): JSX.Element;
22
+ export {};
23
+ //# sourceMappingURL=InteractionProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InteractionProvider.d.ts","sourceRoot":"","sources":["../../../../src/app/charts/hooks/InteractionProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,GAAG,EAA4B,MAAM,OAAO,CAAC;AAK1D,KAAK,KAAK,GAAG;IACT,QAAQ,EAAE,GAAG,CAAC,OAAO,GAAG,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;CAC7C,CAAA;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,OAAO,UAAU,mBAAmB,CAAC,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,GAAG,GAAG,CAAC,OAAO,CA8D5E"}