stream-charts 1.0.1 → 1.1.1

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 (271) hide show
  1. package/README.md +757 -342
  2. package/changes.md +11 -0
  3. package/dist/src/app/charts/Chart.d.ts +116 -87
  4. package/dist/src/app/charts/Chart.js +96 -101
  5. package/dist/src/app/charts/Chart.js.map +1 -1
  6. package/dist/src/app/charts/axes/AxesState.d.ts +64 -0
  7. package/dist/src/app/charts/axes/AxesState.js +97 -0
  8. package/dist/src/app/charts/axes/AxesState.js.map +1 -0
  9. package/dist/src/app/charts/axes/AxesState.test.js +30 -0
  10. package/dist/src/app/charts/axes/AxesState.test.js.map +1 -0
  11. package/dist/src/app/charts/axes/AxisInterval.d.ts +92 -0
  12. package/dist/src/app/charts/axes/AxisInterval.js +126 -0
  13. package/dist/src/app/charts/axes/AxisInterval.js.map +1 -0
  14. package/dist/src/app/charts/axes/AxisInterval.test.js +120 -0
  15. package/dist/src/app/charts/axes/AxisInterval.test.js.map +1 -0
  16. package/dist/src/app/charts/axes/BaseAxisRange.d.ts +83 -0
  17. package/dist/src/app/charts/axes/BaseAxisRange.js +58 -0
  18. package/dist/src/app/charts/axes/BaseAxisRange.js.map +1 -0
  19. package/dist/src/app/charts/axes/ContinuousAxis.d.ts +22 -0
  20. package/dist/src/app/charts/axes/ContinuousAxis.js +96 -0
  21. package/dist/src/app/charts/axes/ContinuousAxis.js.map +1 -0
  22. package/dist/src/app/charts/axes/ContinuousAxisRange.d.ts +59 -0
  23. package/dist/src/app/charts/axes/ContinuousAxisRange.js +84 -0
  24. package/dist/src/app/charts/axes/ContinuousAxisRange.js.map +1 -0
  25. package/dist/src/app/charts/axes/ContinuousAxisRange.test.js +47 -0
  26. package/dist/src/app/charts/axes/ContinuousAxisRange.test.js.map +1 -0
  27. package/dist/src/app/charts/axes/OrdinalAxis.d.ts +23 -0
  28. package/dist/src/app/charts/axes/OrdinalAxis.js +124 -0
  29. package/dist/src/app/charts/axes/OrdinalAxis.js.map +1 -0
  30. package/dist/src/app/charts/axes/OrdinalAxisRange.d.ts +69 -0
  31. package/dist/src/app/charts/axes/OrdinalAxisRange.js +100 -0
  32. package/dist/src/app/charts/axes/OrdinalAxisRange.js.map +1 -0
  33. package/dist/src/app/charts/axes/OrdinalAxisRange.test.js +48 -0
  34. package/dist/src/app/charts/axes/OrdinalAxisRange.test.js.map +1 -0
  35. package/dist/src/app/charts/axes/axes.d.ts +391 -0
  36. package/dist/src/app/charts/axes/axes.js +1046 -0
  37. package/dist/src/app/charts/axes/axes.js.map +1 -0
  38. package/dist/src/app/charts/d3types.d.ts +10 -10
  39. package/dist/src/app/charts/filters/regexFilter.d.ts +9 -0
  40. package/dist/src/app/charts/filters/regexFilter.js +18 -0
  41. package/dist/src/app/charts/filters/regexFilter.js.map +1 -0
  42. package/dist/src/app/charts/filters/regexFilter.test.d.ts +1 -0
  43. package/dist/src/app/charts/filters/regexFilter.test.js +11 -0
  44. package/dist/src/app/charts/filters/regexFilter.test.js.map +1 -0
  45. package/dist/src/app/charts/hooks/useAxes.d.ts +144 -0
  46. package/dist/src/app/charts/hooks/useAxes.js +187 -0
  47. package/dist/src/app/charts/hooks/useAxes.js.map +1 -0
  48. package/dist/src/app/charts/hooks/useChart.d.ts +30 -201
  49. package/dist/src/app/charts/hooks/useChart.js +33 -134
  50. package/dist/src/app/charts/hooks/useChart.js.map +1 -1
  51. package/dist/src/app/charts/hooks/useDataObservable.d.ts +74 -0
  52. package/dist/src/app/charts/hooks/useDataObservable.js +76 -0
  53. package/dist/src/app/charts/hooks/useDataObservable.js.map +1 -0
  54. package/dist/src/app/charts/hooks/useInitialData.d.ts +38 -0
  55. package/dist/src/app/charts/hooks/useInitialData.js +29 -0
  56. package/dist/src/app/charts/hooks/useInitialData.js.map +1 -0
  57. package/dist/src/app/charts/hooks/useMouse.d.ts +53 -0
  58. package/dist/src/app/charts/hooks/useMouse.js +65 -0
  59. package/dist/src/app/charts/hooks/useMouse.js.map +1 -0
  60. package/dist/src/app/charts/hooks/usePlotDimensions.d.ts +34 -0
  61. package/dist/src/app/charts/hooks/usePlotDimensions.js +73 -0
  62. package/dist/src/app/charts/hooks/usePlotDimensions.js.map +1 -0
  63. package/dist/src/app/charts/hooks/useTooltip.d.ts +64 -0
  64. package/dist/src/app/charts/hooks/useTooltip.js +52 -0
  65. package/dist/src/app/charts/hooks/useTooltip.js.map +1 -0
  66. package/dist/src/app/charts/observables/ChartData.d.ts +23 -0
  67. package/dist/src/app/charts/observables/ChartData.js +20 -0
  68. package/dist/src/app/charts/observables/ChartData.js.map +1 -0
  69. package/dist/src/app/charts/observables/iterates.d.ts +52 -0
  70. package/dist/src/app/charts/observables/iterates.js +121 -0
  71. package/dist/src/app/charts/observables/iterates.js.map +1 -0
  72. package/dist/src/app/charts/observables/iterates.test.d.ts +1 -0
  73. package/dist/src/app/charts/observables/iterates.test.js +180 -0
  74. package/dist/src/app/charts/observables/iterates.test.js.map +1 -0
  75. package/dist/src/app/charts/observables/ordinals.d.ts +75 -0
  76. package/dist/src/app/charts/observables/ordinals.js +141 -0
  77. package/dist/src/app/charts/observables/ordinals.js.map +1 -0
  78. package/dist/src/app/charts/observables/ordinals.test.d.ts +1 -0
  79. package/dist/src/app/charts/observables/ordinals.test.js +102 -0
  80. package/dist/src/app/charts/observables/ordinals.test.js.map +1 -0
  81. package/dist/src/app/charts/plots/BarPlot.d.ts +81 -0
  82. package/dist/src/app/charts/plots/BarPlot.js +557 -0
  83. package/dist/src/app/charts/plots/BarPlot.js.map +1 -0
  84. package/dist/src/app/charts/plots/PoincarePlot.d.ts +78 -0
  85. package/dist/src/app/charts/plots/PoincarePlot.js +504 -0
  86. package/dist/src/app/charts/plots/PoincarePlot.js.map +1 -0
  87. package/dist/src/app/charts/{RasterPlot.d.ts → plots/RasterPlot.d.ts} +1 -1
  88. package/dist/src/app/charts/{RasterPlot.js → plots/RasterPlot.js} +152 -133
  89. package/dist/src/app/charts/plots/RasterPlot.js.map +1 -0
  90. package/dist/src/app/charts/{ScatterPlot.d.ts → plots/ScatterPlot.d.ts} +10 -8
  91. package/dist/src/app/charts/plots/ScatterPlot.js +379 -0
  92. package/dist/src/app/charts/plots/ScatterPlot.js.map +1 -0
  93. package/dist/src/app/charts/{plot.d.ts → plots/plot.d.ts} +12 -14
  94. package/dist/src/app/charts/{plot.js → plots/plot.js} +19 -17
  95. package/dist/src/app/charts/plots/plot.js.map +1 -0
  96. package/dist/src/app/charts/series/baseSeries.d.ts +38 -0
  97. package/dist/src/app/charts/series/baseSeries.js +36 -0
  98. package/dist/src/app/charts/series/baseSeries.js.map +1 -0
  99. package/dist/src/app/charts/series/datumSeries.test.d.ts +1 -0
  100. package/dist/src/app/charts/series/datumSeries.test.js +50 -0
  101. package/dist/src/app/charts/series/datumSeries.test.js.map +1 -0
  102. package/dist/src/app/charts/series/iterateSeries.d.ts +42 -0
  103. package/dist/src/app/charts/series/iterateSeries.js +34 -0
  104. package/dist/src/app/charts/series/iterateSeries.js.map +1 -0
  105. package/dist/src/app/charts/series/ordinalSeries.d.ts +54 -0
  106. package/dist/src/app/charts/series/ordinalSeries.js +98 -0
  107. package/dist/src/app/charts/series/ordinalSeries.js.map +1 -0
  108. package/dist/src/app/charts/series/timeSeries.d.ts +30 -0
  109. package/dist/src/app/charts/series/timeSeries.js +19 -0
  110. package/dist/src/app/charts/series/timeSeries.js.map +1 -0
  111. package/dist/src/app/charts/{chartData.d.ts → series/timeSeriesChartData.d.ts} +11 -6
  112. package/dist/src/app/charts/series/timeSeriesChartData.js +32 -0
  113. package/dist/src/app/charts/series/timeSeriesChartData.js.map +1 -0
  114. package/dist/src/app/charts/styling/barPlotStyle.d.ts +41 -0
  115. package/dist/src/app/charts/styling/barPlotStyle.js +84 -0
  116. package/dist/src/app/charts/styling/barPlotStyle.js.map +1 -0
  117. package/dist/src/app/charts/{margins.d.ts → styling/margins.d.ts} +7 -5
  118. package/dist/src/app/charts/{margins.js → styling/margins.js} +19 -9
  119. package/dist/src/app/charts/styling/margins.js.map +1 -0
  120. package/dist/src/app/charts/styling/margins.test.d.ts +1 -0
  121. package/dist/src/app/charts/styling/margins.test.js +19 -0
  122. package/dist/src/app/charts/styling/margins.test.js.map +1 -0
  123. package/dist/src/app/charts/styling/svgStyle.d.ts +76 -0
  124. package/dist/src/app/charts/styling/svgStyle.js +84 -0
  125. package/dist/src/app/charts/styling/svgStyle.js.map +1 -0
  126. package/dist/src/app/charts/subscriptions/subscription.test.d.ts +1 -0
  127. package/dist/src/app/charts/subscriptions/subscription.test.js +395 -0
  128. package/dist/src/app/charts/subscriptions/subscription.test.js.map +1 -0
  129. package/dist/src/app/charts/subscriptions/subscriptions.d.ts +100 -0
  130. package/dist/src/app/charts/subscriptions/subscriptions.js +449 -0
  131. package/dist/src/app/charts/subscriptions/subscriptions.js.map +1 -0
  132. package/dist/src/app/charts/tooltips/BarPlotTooltipContent.d.ts +90 -0
  133. package/dist/src/app/charts/tooltips/BarPlotTooltipContent.js +302 -0
  134. package/dist/src/app/charts/tooltips/BarPlotTooltipContent.js.map +1 -0
  135. package/dist/src/app/charts/tooltips/PoincarePlotTooltipContent.d.ts +100 -0
  136. package/dist/src/app/charts/tooltips/PoincarePlotTooltipContent.js +190 -0
  137. package/dist/src/app/charts/tooltips/PoincarePlotTooltipContent.js.map +1 -0
  138. package/dist/src/app/charts/{RasterPlotTooltipContent.js → tooltips/RasterPlotTooltipContent.js} +40 -44
  139. package/dist/src/app/charts/tooltips/RasterPlotTooltipContent.js.map +1 -0
  140. package/dist/src/app/charts/tooltips/ScatterPlotTooltipContent.js +154 -0
  141. package/dist/src/app/charts/tooltips/ScatterPlotTooltipContent.js.map +1 -0
  142. package/dist/src/app/charts/{Tooltip.d.ts → tooltips/Tooltip.d.ts} +4 -2
  143. package/dist/src/app/charts/{Tooltip.js → tooltips/Tooltip.js} +23 -28
  144. package/dist/src/app/charts/tooltips/Tooltip.js.map +1 -0
  145. package/dist/src/app/charts/{tooltipUtils.d.ts → tooltips/tooltipUtils.d.ts} +11 -6
  146. package/dist/src/app/charts/{tooltipUtils.js → tooltips/tooltipUtils.js} +33 -17
  147. package/dist/src/app/charts/tooltips/tooltipUtils.js.map +1 -0
  148. package/dist/src/app/charts/{Tracker.d.ts → trackers/Tracker.d.ts} +6 -5
  149. package/dist/src/app/charts/trackers/Tracker.js +60 -0
  150. package/dist/src/app/charts/trackers/Tracker.js.map +1 -0
  151. package/dist/src/app/charts/{trackerUtils.d.ts → trackers/trackerUtils.d.ts} +13 -8
  152. package/dist/src/app/charts/trackers/trackerUtils.js +359 -0
  153. package/dist/src/app/charts/trackers/trackerUtils.js.map +1 -0
  154. package/dist/src/app/charts/utils.d.ts +22 -32
  155. package/dist/src/app/charts/utils.js +36 -37
  156. package/dist/src/app/charts/utils.js.map +1 -1
  157. package/dist/src/index.d.ts +48 -15
  158. package/dist/src/index.js +71 -15
  159. package/dist/src/index.js.map +1 -1
  160. package/package.json +30 -20
  161. package/src/app/charts/Chart.tsx +334 -0
  162. package/src/app/charts/axes/AxesState.test.ts +34 -0
  163. package/src/app/charts/axes/AxesState.ts +112 -0
  164. package/src/app/charts/axes/AxisInterval.test.ts +143 -0
  165. package/src/app/charts/axes/AxisInterval.ts +139 -0
  166. package/src/app/charts/axes/BaseAxisRange.ts +113 -0
  167. package/src/app/charts/axes/ContinuousAxis.tsx +192 -0
  168. package/src/app/charts/axes/ContinuousAxisRange.test.ts +55 -0
  169. package/src/app/charts/axes/ContinuousAxisRange.ts +96 -0
  170. package/src/app/charts/axes/OrdinalAxis.tsx +223 -0
  171. package/src/app/charts/axes/OrdinalAxisRange.test.ts +55 -0
  172. package/src/app/charts/axes/OrdinalAxisRange.ts +112 -0
  173. package/src/app/charts/axes/axes.ts +1569 -0
  174. package/src/app/charts/d3types.ts +16 -0
  175. package/src/app/charts/filters/regexFilter.test.ts +13 -0
  176. package/src/app/charts/filters/regexFilter.ts +17 -0
  177. package/src/app/charts/hooks/useAxes.tsx +341 -0
  178. package/src/app/charts/hooks/useChart.tsx +159 -0
  179. package/src/app/charts/hooks/useDataObservable.tsx +175 -0
  180. package/src/app/charts/hooks/useInitialData.tsx +65 -0
  181. package/src/app/charts/hooks/useMouse.tsx +125 -0
  182. package/src/app/charts/hooks/usePlotDimensions.tsx +120 -0
  183. package/src/app/charts/hooks/useTooltip.tsx +112 -0
  184. package/src/app/charts/observables/ChartData.ts +31 -0
  185. package/src/app/charts/observables/iterates.test.ts +201 -0
  186. package/src/app/charts/observables/iterates.ts +203 -0
  187. package/src/app/charts/observables/ordinals.test.ts +135 -0
  188. package/src/app/charts/observables/ordinals.ts +248 -0
  189. package/src/app/charts/plots/BarPlot.tsx +1088 -0
  190. package/src/app/charts/plots/PoincarePlot.tsx +832 -0
  191. package/src/app/charts/plots/RasterPlot.tsx +676 -0
  192. package/src/app/charts/plots/ScatterPlot.tsx +653 -0
  193. package/src/app/charts/plots/plot.ts +75 -0
  194. package/src/app/charts/series/baseSeries.ts +52 -0
  195. package/src/app/charts/series/datumSeries.test.ts +60 -0
  196. package/src/app/charts/series/iterateSeries.ts +56 -0
  197. package/src/app/charts/series/ordinalSeries.ts +164 -0
  198. package/src/app/charts/series/timeSeries.ts +40 -0
  199. package/src/app/charts/series/timeSeriesChartData.ts +68 -0
  200. package/src/app/charts/styling/barPlotStyle.ts +126 -0
  201. package/src/app/charts/styling/margins.test.ts +22 -0
  202. package/src/app/charts/styling/margins.ts +58 -0
  203. package/src/app/charts/styling/svgStyle.ts +118 -0
  204. package/src/app/charts/subscriptions/subscription.test.ts +499 -0
  205. package/src/app/charts/subscriptions/subscriptions.ts +635 -0
  206. package/src/app/charts/tooltips/BarPlotTooltipContent.tsx +440 -0
  207. package/src/app/charts/tooltips/PoincarePlotTooltipContent.tsx +352 -0
  208. package/src/app/charts/tooltips/RasterPlotTooltipContent.tsx +274 -0
  209. package/src/app/charts/tooltips/ScatterPlotTooltipContent.tsx +319 -0
  210. package/src/app/charts/tooltips/Tooltip.tsx +148 -0
  211. package/src/app/charts/tooltips/tooltipUtils.ts +216 -0
  212. package/src/app/charts/trackers/Tracker.tsx +129 -0
  213. package/src/app/charts/trackers/trackerUtils.ts +494 -0
  214. package/src/app/charts/utils.ts +109 -0
  215. package/dist/src/app/charts/CategoryAxis.d.ts +0 -20
  216. package/dist/src/app/charts/CategoryAxis.js +0 -112
  217. package/dist/src/app/charts/CategoryAxis.js.map +0 -1
  218. package/dist/src/app/charts/ContinuousAxis.d.ts +0 -16
  219. package/dist/src/app/charts/ContinuousAxis.js +0 -186
  220. package/dist/src/app/charts/ContinuousAxis.js.map +0 -1
  221. package/dist/src/app/charts/RasterPlot.js.map +0 -1
  222. package/dist/src/app/charts/RasterPlotTooltipContent.js.map +0 -1
  223. package/dist/src/app/charts/ScatterPlot.js +0 -351
  224. package/dist/src/app/charts/ScatterPlot.js.map +0 -1
  225. package/dist/src/app/charts/ScatterPlotTooltipContent.js +0 -163
  226. package/dist/src/app/charts/ScatterPlotTooltipContent.js.map +0 -1
  227. package/dist/src/app/charts/Tooltip.js.map +0 -1
  228. package/dist/src/app/charts/Tracker.js +0 -65
  229. package/dist/src/app/charts/Tracker.js.map +0 -1
  230. package/dist/src/app/charts/axes.d.ts +0 -132
  231. package/dist/src/app/charts/axes.js +0 -265
  232. package/dist/src/app/charts/axes.js.map +0 -1
  233. package/dist/src/app/charts/chartData.js +0 -32
  234. package/dist/src/app/charts/chartData.js.map +0 -1
  235. package/dist/src/app/charts/continuousAxisRangeFor.d.ts +0 -20
  236. package/dist/src/app/charts/continuousAxisRangeFor.js +0 -68
  237. package/dist/src/app/charts/continuousAxisRangeFor.js.map +0 -1
  238. package/dist/src/app/charts/datumSeries.d.ts +0 -59
  239. package/dist/src/app/charts/datumSeries.js +0 -55
  240. package/dist/src/app/charts/datumSeries.js.map +0 -1
  241. package/dist/src/app/charts/datumSeries.test.js +0 -50
  242. package/dist/src/app/charts/datumSeries.test.js.map +0 -1
  243. package/dist/src/app/charts/hooks/AxesState.d.ts +0 -37
  244. package/dist/src/app/charts/hooks/AxesState.js +0 -44
  245. package/dist/src/app/charts/hooks/AxesState.js.map +0 -1
  246. package/dist/src/app/charts/margins.js.map +0 -1
  247. package/dist/src/app/charts/margins.test.js +0 -14
  248. package/dist/src/app/charts/margins.test.js.map +0 -1
  249. package/dist/src/app/charts/plot.js.map +0 -1
  250. package/dist/src/app/charts/regexFilter.d.ts +0 -9
  251. package/dist/src/app/charts/regexFilter.js +0 -17
  252. package/dist/src/app/charts/regexFilter.js.map +0 -1
  253. package/dist/src/app/charts/regexFilter.test.js +0 -11
  254. package/dist/src/app/charts/regexFilter.test.js.map +0 -1
  255. package/dist/src/app/charts/subscriptions.d.ts +0 -43
  256. package/dist/src/app/charts/subscriptions.js +0 -213
  257. package/dist/src/app/charts/subscriptions.js.map +0 -1
  258. package/dist/src/app/charts/svgStyle.d.ts +0 -27
  259. package/dist/src/app/charts/svgStyle.js +0 -32
  260. package/dist/src/app/charts/svgStyle.js.map +0 -1
  261. package/dist/src/app/charts/timeRange.test.js +0 -54
  262. package/dist/src/app/charts/timeRange.test.js.map +0 -1
  263. package/dist/src/app/charts/tooltipUtils.js.map +0 -1
  264. package/dist/src/app/charts/trackerUtils.js +0 -130
  265. package/dist/src/app/charts/trackerUtils.js.map +0 -1
  266. /package/dist/src/app/charts/{datumSeries.test.d.ts → axes/AxesState.test.d.ts} +0 -0
  267. /package/dist/src/app/charts/{margins.test.d.ts → axes/AxisInterval.test.d.ts} +0 -0
  268. /package/dist/src/app/charts/{regexFilter.test.d.ts → axes/ContinuousAxisRange.test.d.ts} +0 -0
  269. /package/dist/src/app/charts/{timeRange.test.d.ts → axes/OrdinalAxisRange.test.d.ts} +0 -0
  270. /package/dist/src/app/charts/{RasterPlotTooltipContent.d.ts → tooltips/RasterPlotTooltipContent.d.ts} +0 -0
  271. /package/dist/src/app/charts/{ScatterPlotTooltipContent.d.ts → tooltips/ScatterPlotTooltipContent.d.ts} +0 -0
@@ -1,27 +1,26 @@
1
- /// <reference types="react" />
2
- import { Dimensions, Margin } from "../margins";
1
+ import { JSX } from "react";
3
2
  import { GSelection } from "../d3types";
4
- import { Observable, Subscription } from "rxjs";
5
- import { ChartData } from "../chartData";
6
- import { Datum, Series } from "../datumSeries";
7
- import { BaseAxis, SeriesLineStyle } from "../axes";
8
- import { ContinuousAxisRange } from "../continuousAxisRangeFor";
9
- import { AxesAssignment, TimeSeries } from "../plot";
10
- import { TooltipDimensions } from "../tooltipUtils";
11
- import { AxesState } from "./AxesState";
12
- export declare const defaultMargin: Margin;
3
+ import { BaseAxis, SeriesLineStyle, SeriesStyle } from "../axes/axes";
4
+ import { UseAxesValues } from "./useAxes";
5
+ import { UseMouseValues } from "./useMouse";
6
+ import { UseTooltipValues } from "./useTooltip";
7
+ import { SvgStyle } from "../styling/svgStyle";
8
+ import { BaseAxisRange } from "../axes/BaseAxisRange";
9
+ export type NoTooltipMetadata = {};
13
10
  /**
14
11
  * The values exposed through the {@link useChart} react hook
12
+ * @param chartId The unique ID for the chart
13
+ * @param mainG The root <g> element for the chart
14
+ * @param container The SVG element which is the container for this chart
15
+ * @template D The type of the series' datum
16
+ * @template S The type of the series style
17
+ * @template TM The type of the tooltip's metadata (data about the series data)
15
18
  */
16
- interface UseChartValues {
19
+ interface UseChartValues<D, S extends SeriesStyle, TM, AR extends BaseAxisRange, A extends BaseAxis> {
17
20
  /**
18
21
  * Unique ID for the chart
19
22
  */
20
23
  chartId: number;
21
- /**
22
- * The width and height (in pixels) of this chart
23
- */
24
- plotDimensions: Dimensions;
25
24
  /**
26
25
  * The root <g> element for the chart
27
26
  */
@@ -30,221 +29,51 @@ interface UseChartValues {
30
29
  * The SVG element which is the container for this chart
31
30
  */
32
31
  container: SVGSVGElement | null;
33
- /**
34
- * The plot margins for the border of main G
35
- */
36
- margin: Margin;
37
32
  /**
38
33
  * Base color
39
34
  */
40
35
  color: string;
41
36
  /**
42
- * A `map(series_name -> series_line_style)`
43
- */
44
- seriesStyles: Map<string, SeriesLineStyle>;
45
- /**
46
- * The x-axes state holds the currently set x-axes, manipulation and accessor functions
47
- */
48
- xAxesState: AxesState;
49
- /**
50
- * Adds an x-axis to the axes and updates the internal state
51
- * @param axis The axis to add
52
- * @param id The ID of the axis to add
53
- */
54
- addXAxis: (axis: BaseAxis, id: string) => void;
55
- /**
56
- * The y-axes state holds the currently set x-axes, manipulation and accessor functions
57
- */
58
- yAxesState: AxesState;
59
- /**
60
- * Adds a y-axis to the axes and updates the internal state
61
- * @param axis The axis to add
62
- * @param id The ID of the axis to add
63
- */
64
- addYAxis: (axis: BaseAxis, id: string) => void;
65
- /**
66
- * Sets the axis assigned to each series. This should contain **all** the series used in
67
- * the chart.
68
- * @param assignments The assignment of the series to their axes
37
+ * The base/default background color. This can be overridden by the {@link Props.svgStyle} property.
69
38
  */
70
- setAxisAssignments: (assignments: Map<string, AxesAssignment>) => void;
39
+ backgroundColor: string;
71
40
  /**
72
- * Retrieves the axis assigned to the specified series
73
- * @return The axes assigned to the specified series
41
+ * Overrides for the SVG style
74
42
  */
75
- axisAssignmentsFor: (seriesName: string) => AxesAssignment;
43
+ svgStyle: Partial<SvgStyle>;
76
44
  /**
77
- * Retrieves the time range for the specified axis ID
78
- * @param axisId The ID of the axis for which to retrieve the time-range
79
- * @return The time-range as a `[t_start, t_end]` tuple if the axis ID is found, `undefined` otherwise
80
- */
81
- timeRangeFor: (axisId: string) => [start: number, end: number] | undefined;
82
- /**
83
- * Sets the time-range for the specified axis ID to the specified range
84
- * @param axisId The ID of the axis for which to set the range
85
- * @param timeRange The new time range as an `[t_start, t_end]` tuple
86
- */
87
- setTimeRangeFor: (axisId: string, timeRange: [start: number, end: number]) => void;
88
- /**
89
- * An array of time-series representing the initial data for the chart (i.e. static data
90
- * before streaming starts)
91
- */
92
- initialData: Array<Series>;
93
- /**
94
- * An observable source for chart data
95
- */
96
- seriesObservable?: Observable<ChartData>;
97
- /**
98
- * When `true` the chart will subscribe to the observable, or if already subscribed, will remain
99
- * subscribed. When `false` the chart will unsubscribe to the observable if subscribed, or will
100
- * remain unsubscribed if not already subscribed.
101
- */
102
- shouldSubscribe?: boolean;
103
- /**
104
- * The windowing time for aggregating chart-data events. Defines the update rate of the chart.
105
- * For example if chart-data events occur every 1 ms, and the windowing time is set to 10 ms,
106
- * then events will be aggregated for 10 ms, and then the chart will be updated. In this example,
107
- * the chart would be updated only once per 10 ms.
45
+ * A `map(series_name -> series_line_style)`
108
46
  */
109
- windowingTime?: number;
47
+ seriesStyles: Map<string, S>;
48
+ axes: UseAxesValues<AR, A>;
110
49
  /**
111
50
  * A regular expression uses against the series names to determine which series to show in the chart
112
51
  */
113
52
  seriesFilter: RegExp;
114
- /**
115
- * Callback function that is called when the chart subscribes to the observable
116
- * @param subscription The subscription resulting form the subscribe action
117
- */
118
- onSubscribe: (subscription: Subscription) => void;
119
- /**
120
- * Callback when the time range changes.
121
- * @param times The times (start, end) times for each axis in the plot
122
- * @return void
123
- */
124
- onUpdateTime?: (times: Map<string, [start: number, end: number]>) => void;
125
- /**
126
- * Callback function that is called when new data arrives to the chart.
127
- * @param seriesName The name of the series for which new data arrived
128
- * @param data The new data that arrived in the windowing tine
129
- * @see UseChartValues.windowingTime
130
- */
131
- onUpdateData?: (seriesName: string, data: Array<Datum>) => void;
132
- /**
133
- * Callback function that is called when the time ranges change. The time ranges could
134
- * change because of a zoom action, a pan action, or as new data is streamed in.
135
- * @param times A `map(axis_id -> time_range)` that associates the axis ID with the
136
- * current time range.
137
- */
138
- updateTimeRanges: (times: Map<string, ContinuousAxisRange>) => void;
139
- /**
140
- * Update the plot dimensions (for example, on a window resize)
141
- * @param dimensions the new dimensions of the plot
142
- */
143
- updateDimensions: (dimensions: Dimensions) => void;
144
- /**
145
- * Adds a handler for when the time is updated. The time could change because of a zoom action,
146
- * a pan action, or as new data is streamed in.
147
- * @param handlerId The unique ID of the handler to register/add
148
- * @param handler The handler function
149
- */
150
- addTimeUpdateHandler: (handlerId: string, handler: (updates: Map<string, ContinuousAxisRange>, plotDim: Dimensions) => void) => void;
151
- /**
152
- * Removes the time-update handler with the specified ID
153
- * @param handlerId The ID of the handler to remove
154
- */
155
- removeTimeUpdateHandler: (handlerId: string) => void;
156
- /**
157
- * Adds a mouse-over-series handler with the specified ID and handler function
158
- * @param handlerId The handler ID
159
- * @param handler The handler function called when a mouse-over-series event occurs
160
- * @return The handler ID
161
- */
162
- registerMouseOverHandler: (handlerId: string, handler: (seriesName: string, time: number, series: TimeSeries, mouseCoords: [x: number, y: number]) => void) => string;
163
- /**
164
- * Removes the mouse-over-series handler with the specified ID
165
- * @param handlerId The ID of the handler to remove
166
- */
167
- unregisterMouseOverHandler: (handlerId: string) => void;
168
- /**
169
- * Attempts to retrieve the mouse-over-series handler for the specified ID
170
- * @param handlerId The ID of the handler
171
- * @return The mouse-over-series handler for the ID, or `undefined` if not found
172
- */
173
- mouseOverHandlerFor: (handlerId: string) => ((seriesName: string, time: number, series: TimeSeries, mouseCoords: [x: number, y: number]) => void) | undefined;
174
- /**
175
- * Adds a mouse-leave-series handler with the specified ID and handler function
176
- * @param handlerId The handler ID
177
- * @param handler The handler function called when a mouse-leave-series event occurs
178
- * @return The handler ID
179
- */
180
- registerMouseLeaveHandler: (handlerId: string, handler: (seriesName: string) => void) => string;
181
- /**
182
- * Removes the mouse-leave-series handler with the specified ID
183
- * @param handlerId The ID of the handler to remove
184
- */
185
- unregisterMouseLeaveHandler: (handlerId: string) => void;
186
- /**
187
- * Attempts to retrieve the mouse-leave-series handler for the specified ID
188
- * @param handlerId The ID of the handler
189
- * @return The mouse-leave-series handler for the ID, or `undefined` if not found
190
- */
191
- mouseLeaveHandlerFor: (handlerId: string) => ((seriesName: string) => void) | undefined;
192
- /**
193
- * Registers the provider of the tooltip content (generally this will be registered by the plot).
194
- * When this function is called again, overwrites the previously registered provider with the
195
- * one specified. This function can be called repeatedly.
196
- * @param provider The function that provides the content when called.
197
- */
198
- registerTooltipContentProvider: (provider: (seriesName: string, time: number, series: TimeSeries, mouseCoords: [x: number, y: number]) => TooltipDimensions) => void;
199
- /**
200
- * @return The registered function that provides the tooltip content. If no function has been
201
- * registered, then returns `undefined`.
202
- */
203
- tooltipContentProvider: () => ((seriesName: string, time: number, series: TimeSeries, mouseCoords: [x: number, y: number]) => TooltipDimensions) | undefined;
53
+ mouse: UseMouseValues<D, TM>;
54
+ tooltip: UseTooltipValues<D, TM>;
204
55
  }
205
56
  interface Props {
206
57
  chartId: number;
207
58
  container: SVGSVGElement | null;
208
59
  mainG: GSelection | null;
209
- containerDimensions: Dimensions;
210
- margin: Margin;
211
60
  color: string;
61
+ backgroundColor: string;
62
+ svgStyle: Partial<SvgStyle>;
212
63
  seriesStyles?: Map<string, SeriesLineStyle>;
213
- initialData: Array<Series>;
214
64
  seriesFilter?: RegExp;
215
- seriesObservable?: Observable<ChartData>;
216
- windowingTime?: number;
217
- shouldSubscribe?: boolean;
218
- /**
219
- * Callback function that is called when the chart subscribes to the observable
220
- * @param subscription The subscription resulting form the subscribe action
221
- */
222
- onSubscribe?: (subscription: Subscription) => void;
223
- /**
224
- * Callback when the time range changes.
225
- * @param times The times (start, end) times for each axis in the plot
226
- * @return void
227
- */
228
- onUpdateTime?: (times: Map<string, [start: number, end: number]>) => void;
229
- /**
230
- * Callback function that is called when new data arrives to the chart.
231
- * @param seriesName The name of the series for which new data arrived
232
- * @param data The new data that arrived in the windowing tine
233
- * @see UseChartValues.windowingTime
234
- */
235
- onUpdateData?: (seriesName: string, data: Array<Datum>) => void;
236
65
  children: JSX.Element | Array<JSX.Element>;
237
66
  }
238
67
  /**
239
- * The react context provider for the {@link UseChartValues}
68
+ * The React context provider for the {@link UseChartValues}
240
69
  * @param props The properties
241
70
  * @return The children wrapped in this provider
242
71
  * @constructor
243
72
  */
244
73
  export default function ChartProvider(props: Props): JSX.Element;
245
74
  /**
246
- * React hook that sets up the react context for the chart values.
247
- * @return The {@link UseChartValues} held in the react context.
75
+ * React hook that sets up the React context for the chart values.
76
+ * @return The {@link UseChartValues} held in the React context.
248
77
  */
249
- export declare function useChart(): UseChartValues;
78
+ export declare function useChart<D, S extends SeriesStyle, TM, AR extends BaseAxisRange, A extends BaseAxis>(): UseChartValues<D, S, TM, AR, A>;
250
79
  export {};
@@ -1,158 +1,57 @@
1
- var __assign = (this && this.__assign) || function () {
2
- __assign = Object.assign || function(t) {
3
- for (var s, i = 1, n = arguments.length; i < n; i++) {
4
- s = arguments[i];
5
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
- t[p] = s[p];
7
- }
8
- return t;
9
- };
10
- return __assign.apply(this, arguments);
11
- };
12
1
  import { jsx as _jsx } from "react/jsx-runtime";
13
- import { createContext, useContext, useEffect, useRef, useState } from 'react';
14
- import { plotDimensionsFrom } from "../margins";
15
- import { noop } from "../utils";
16
- import { addAxisTo, createAxesState } from "./AxesState";
17
- export var defaultMargin = { top: 30, right: 20, bottom: 30, left: 50 };
18
- var defaultUseChartValues = {
2
+ import { createContext, useContext } from "react";
3
+ import { defaultAxesValues, useAxes } from "./useAxes";
4
+ import { defaultMouseValues, useMouse } from "./useMouse";
5
+ import { defaultTooltipValues, useTooltip } from "./useTooltip";
6
+ const defaultUseChartValues = {
19
7
  chartId: NaN,
20
8
  container: null,
21
9
  mainG: null,
22
- plotDimensions: { width: 0, height: 0 },
23
- margin: defaultMargin,
24
10
  color: '#d2933f',
11
+ backgroundColor: '#EEE',
12
+ svgStyle: new Map(),
25
13
  seriesStyles: new Map(),
26
14
  // axes
27
- xAxesState: createAxesState(),
28
- yAxesState: createAxesState(),
29
- addXAxis: noop,
30
- addYAxis: noop,
31
- setAxisAssignments: noop,
32
- axisAssignmentsFor: function () { return ({ xAxis: "", yAxis: "" }); },
33
- // timing
34
- timeRangeFor: function () { return [NaN, NaN]; },
35
- setTimeRangeFor: noop,
15
+ axes: defaultAxesValues(),
36
16
  // data
37
- initialData: [],
38
17
  seriesFilter: /./,
39
- windowingTime: NaN,
40
- shouldSubscribe: false,
41
- // user callbacks
42
- onSubscribe: noop,
43
- // internal event handlers
44
- updateTimeRanges: noop,
45
- updateDimensions: noop,
46
- addTimeUpdateHandler: function () { return noop; },
47
- removeTimeUpdateHandler: function () { return noop; },
48
18
  // internal chart-interaction event handlers
49
- registerMouseOverHandler: function () { return ''; },
50
- unregisterMouseOverHandler: noop,
51
- mouseOverHandlerFor: function () { return undefined; },
52
- registerMouseLeaveHandler: function () { return ''; },
53
- unregisterMouseLeaveHandler: noop,
54
- mouseLeaveHandlerFor: function () { return undefined; },
55
- registerTooltipContentProvider: noop,
56
- tooltipContentProvider: function () { return undefined; }
19
+ mouse: defaultMouseValues(),
20
+ tooltip: defaultTooltipValues()
57
21
  };
58
- var ChartContext = createContext(defaultUseChartValues);
22
+ const ChartContext = createContext(defaultUseChartValues);
59
23
  /**
60
- * The react context provider for the {@link UseChartValues}
24
+ * The React context provider for the {@link UseChartValues}
61
25
  * @param props The properties
62
26
  * @return The children wrapped in this provider
63
27
  * @constructor
64
28
  */
65
29
  export default function ChartProvider(props) {
66
- var chartId = props.chartId, container = props.container, mainG = props.mainG, containerDimensions = props.containerDimensions, margin = props.margin, color = props.color, initialData = props.initialData, _a = props.seriesFilter, seriesFilter = _a === void 0 ? defaultUseChartValues.seriesFilter : _a, _b = props.seriesStyles, seriesStyles = _b === void 0 ? new Map() : _b, seriesObservable = props.seriesObservable, _c = props.windowingTime, windowingTime = _c === void 0 ? defaultUseChartValues.windowingTime || 100 : _c, shouldSubscribe = props.shouldSubscribe, _d = props.onSubscribe, onSubscribe = _d === void 0 ? noop : _d, _e = props.onUpdateTime, onUpdateTime = _e === void 0 ? noop : _e, _f = props.onUpdateData, onUpdateData = _f === void 0 ? noop : _f;
67
- var _g = useState(defaultUseChartValues.plotDimensions), dimensions = _g[0], setDimensions = _g[1];
68
- var xAxesRef = useRef(createAxesState());
69
- var yAxesRef = useRef(createAxesState());
70
- var axisAssignmentsRef = useRef(new Map());
71
- var timeRangesRef = useRef(new Map());
72
- var timeUpdateHandlersRef = useRef(new Map());
73
- var mouseOverHandlersRef = useRef(new Map());
74
- var mouseLeaveHandlersRef = useRef(new Map());
75
- var tooltipContentProviderRef = useRef(undefined);
76
- // update the plot dimensions when the container size or margin change
77
- useEffect(function () {
78
- setDimensions(plotDimensionsFrom(containerDimensions.width, containerDimensions.height, margin));
79
- }, [containerDimensions, margin]);
80
- /**
81
- * Called when the time is updated on one or more of the chart's axes (generally x-axes). In turn,
82
- * dispatches the update to all the internal time update handlers.
83
- * @param updates A map holding the axis ID to the updated axis time-range
84
- */
85
- function updateTimeRanges(updates) {
86
- // update the current time-ranges reference
87
- updates.forEach(function (range, id) {
88
- return timeRangesRef.current.set(id, [range.start, range.end]);
89
- });
90
- // dispatch the updates to all the registered handlers
91
- timeUpdateHandlersRef.current.forEach(function (handler) { return handler(updates, dimensions); });
92
- }
93
- /**
94
- * Retrieves the x-axis and y-axis assignments for the specified series. If the axes does not have
95
- * an assignment, then is assumed to be using the default x- and y-axes.
96
- * @param seriesName The name of the series for which to retrieve the axes assignments
97
- * @return An {@link AxesAssignment} for the specified axes.
98
- */
99
- function axisAssignmentsFor(seriesName) {
100
- return axisAssignmentsRef.current.get(seriesName) || {
101
- xAxis: xAxesRef.current.axisDefaultName(),
102
- yAxis: yAxesRef.current.axisDefaultName()
103
- };
104
- }
105
- return _jsx(ChartContext.Provider, __assign({ value: {
106
- chartId: chartId,
107
- plotDimensions: dimensions,
108
- margin: margin,
109
- color: color,
110
- seriesStyles: seriesStyles,
111
- initialData: initialData,
112
- seriesFilter: seriesFilter,
113
- mainG: mainG,
114
- container: container,
115
- xAxesState: xAxesRef.current,
116
- yAxesState: yAxesRef.current,
117
- addXAxis: function (axis, id) { return xAxesRef.current = addAxisTo(xAxesRef.current, axis, id); },
118
- addYAxis: function (axis, id) { return yAxesRef.current = addAxisTo(yAxesRef.current, axis, id); },
119
- setAxisAssignments: function (assignments) { return axisAssignmentsRef.current = assignments; },
120
- axisAssignmentsFor: function (seriesName) { return axisAssignmentsFor(seriesName); },
121
- timeRangeFor: function (axisId) { return timeRangesRef.current.get(axisId); },
122
- setTimeRangeFor: (function (axisId, timeRange) { return timeRangesRef.current.set(axisId, timeRange); }),
123
- seriesObservable: seriesObservable,
124
- windowingTime: windowingTime,
125
- shouldSubscribe: shouldSubscribe,
126
- onSubscribe: onSubscribe,
127
- onUpdateTime: onUpdateTime,
128
- onUpdateData: onUpdateData,
129
- updateTimeRanges: updateTimeRanges,
130
- updateDimensions: function (dimensions) { return setDimensions(dimensions); },
131
- addTimeUpdateHandler: function (handlerId, handler) { return timeUpdateHandlersRef.current.set(handlerId, handler); },
132
- removeTimeUpdateHandler: function (handlerId) { return timeUpdateHandlersRef.current.delete(handlerId); },
133
- registerMouseOverHandler: function (handlerId, handler) {
134
- mouseOverHandlersRef.current.set(handlerId, handler);
135
- return handlerId;
136
- },
137
- unregisterMouseOverHandler: function (handlerId) { return mouseOverHandlersRef.current.delete(handlerId); },
138
- mouseOverHandlerFor: function (handlerId) { return mouseOverHandlersRef.current.get(handlerId); },
139
- registerMouseLeaveHandler: function (handlerId, handler) {
140
- mouseLeaveHandlersRef.current.set(handlerId, handler);
141
- return handlerId;
142
- },
143
- unregisterMouseLeaveHandler: function (handlerId) { return mouseLeaveHandlersRef.current.delete(handlerId); },
144
- mouseLeaveHandlerFor: function (handlerId) { return mouseLeaveHandlersRef.current.get(handlerId); },
145
- registerTooltipContentProvider: function (provider) { return tooltipContentProviderRef.current = provider; },
146
- tooltipContentProvider: function () { return tooltipContentProviderRef.current; },
147
- } }, { children: props.children }), void 0);
30
+ const { chartId, container, mainG, color, backgroundColor, seriesFilter = defaultUseChartValues.seriesFilter, svgStyle, seriesStyles = new Map(), } = props;
31
+ const axes = useAxes();
32
+ const mouse = useMouse();
33
+ const tooltip = useTooltip();
34
+ return _jsx(ChartContext.Provider, { value: {
35
+ chartId,
36
+ color,
37
+ backgroundColor,
38
+ svgStyle,
39
+ seriesStyles,
40
+ seriesFilter,
41
+ mainG,
42
+ container,
43
+ axes,
44
+ mouse,
45
+ tooltip,
46
+ }, children: props.children });
148
47
  }
149
48
  /**
150
- * React hook that sets up the react context for the chart values.
151
- * @return The {@link UseChartValues} held in the react context.
49
+ * React hook that sets up the React context for the chart values.
50
+ * @return The {@link UseChartValues} held in the React context.
152
51
  */
153
52
  export function useChart() {
154
- var context = useContext(ChartContext);
155
- var chartId = context.chartId;
53
+ const context = useContext(ChartContext);
54
+ const { chartId } = context;
156
55
  if (isNaN(chartId)) {
157
56
  throw new Error("useChart can only be used when the parent is a <ChartProvider/>");
158
57
  }
@@ -1 +1 @@
1
- {"version":3,"file":"useChart.js","sourceRoot":"","sources":["../../../../../src/app/charts/hooks/useChart.tsx"],"names":[],"mappings":";;;;;;;;;;;;AACA,OAAO,EAAC,aAAa,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAC,MAAM,OAAO,CAAC;AAC7E,OAAO,EAAqB,kBAAkB,EAAC,MAAM,YAAY,CAAC;AAKlE,OAAO,EAAC,IAAI,EAAC,MAAM,UAAU,CAAC;AAK9B,OAAO,EAAC,SAAS,EAAa,eAAe,EAAC,MAAM,aAAa,CAAC;AAElE,MAAM,CAAC,IAAM,aAAa,GAAW,EAAC,GAAG,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAC,CAAA;AAyO/E,IAAM,qBAAqB,GAAmB;IAC1C,OAAO,EAAE,GAAG;IACZ,SAAS,EAAE,IAAI;IACf,KAAK,EAAE,IAAI;IACX,cAAc,EAAE,EAAC,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAC;IACrC,MAAM,EAAE,aAAa;IACrB,KAAK,EAAE,SAAS;IAChB,YAAY,EAAE,IAAI,GAAG,EAAE;IAEvB,OAAO;IACP,UAAU,EAAE,eAAe,EAAE;IAC7B,UAAU,EAAE,eAAe,EAAE;IAC7B,QAAQ,EAAE,IAAI;IACd,QAAQ,EAAE,IAAI;IACd,kBAAkB,EAAE,I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ACpB,MAAM,OAAO,GAAG,UAAU,CAAkC,YAAY,CAAC,CAAA;IACzE,MAAM,EAAC,OAAO,EAAC,GAAG,OAAO,CAAA;IACzB,IAAI,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;QACjB,MAAM,IAAI,KAAK,CAAC,iEAAiE,CAAC,CAAA;IACtF,CAAC;IACD,OAAO,OAAO,CAAA;AAClB,CAAC"}
@@ -0,0 +1,74 @@
1
+ import { JSX } from "react";
2
+ import { Observable, Subscription } from "rxjs";
3
+ import { ChartData } from "../observables/ChartData";
4
+ /**
5
+ * The values exposed through the {@link useDataObservable} react hook
6
+ */
7
+ interface UseObservableValues<CD extends ChartData, D> {
8
+ /**
9
+ * An observable source for chart data
10
+ */
11
+ seriesObservable?: Observable<CD>;
12
+ /**
13
+ * When `true` the chart will subscribe to the observable, or if already subscribed, will remain
14
+ * subscribed. When `false` the chart will unsubscribe to the observable if subscribed, or will
15
+ * remain unsubscribed if not already subscribed.
16
+ */
17
+ shouldSubscribe?: boolean;
18
+ /**
19
+ * The windowing time for aggregating chart-data events. Defines the update rate of the chart.
20
+ * For example if chart-data events occur every 1 ms, and the windowing time is set to 10 ms,
21
+ * then events will be aggregated for 10 ms, and then the chart will be updated. In this example,
22
+ * the chart would be updated only once per 10 ms.
23
+ */
24
+ windowingTime?: number;
25
+ /**
26
+ * Callback function that is called when the chart subscribes to the observable
27
+ * @param subscription The subscription resulting form the subscribe action
28
+ */
29
+ onSubscribe: (subscription: Subscription) => void;
30
+ /**
31
+ * Callback function that is called when new data arrives to the chart.
32
+ * @param seriesName The name of the series for which new data arrived
33
+ * @param data The new data that arrived in the windowing tine
34
+ * @see UseChartValues.windowingTime
35
+ */
36
+ onUpdateData?: (seriesName: string, data: Array<D>) => void;
37
+ /**
38
+ * todo
39
+ * @param time
40
+ */
41
+ onUpdateChartTime?: (time: number) => void;
42
+ }
43
+ interface Props<CD extends ChartData, D> {
44
+ seriesObservable?: Observable<CD>;
45
+ windowingTime?: number;
46
+ shouldSubscribe?: boolean;
47
+ /**
48
+ * Callback function that is called when the chart subscribes to the observable
49
+ * @param subscription The subscription resulting form the subscribe action
50
+ */
51
+ onSubscribe?: (subscription: Subscription) => void;
52
+ /**
53
+ * Callback function that is called when new data arrives to the chart.
54
+ * @param seriesName The name of the series for which new data arrived
55
+ * @param data The new data that arrived in the windowing tine
56
+ * @see UseChartValues.windowingTime
57
+ */
58
+ onUpdateData?: (seriesName: string, data: Array<D>) => void;
59
+ onUpdateChartTime?: (time: number) => void;
60
+ children: JSX.Element | Array<JSX.Element>;
61
+ }
62
+ /**
63
+ * The react context provider for the {@link UseObservableValues}
64
+ * @param props The properties
65
+ * @return The children wrapped in this provider
66
+ * @constructor
67
+ */
68
+ export default function DataObservableProvider<CD extends ChartData, D>(props: Props<CD, D>): JSX.Element;
69
+ /**
70
+ * React hook that sets up the React context for the chart values.
71
+ * @return The {@link UseObservableValues} held in the React context.
72
+ */
73
+ export declare function useDataObservable<CD extends ChartData, D>(): UseObservableValues<CD, D>;
74
+ export {};
@@ -0,0 +1,76 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { createContext, useContext } from "react";
3
+ import { concat, from } from "rxjs";
4
+ import { useInitialData } from "./useInitialData";
5
+ // import {noop} from "../utils";
6
+ /**
7
+ * No operation function for use when a default function is needed
8
+ */
9
+ const noop = () => {
10
+ /* empty on purpose */
11
+ };
12
+ const defaultObservableValues = {
13
+ windowingTime: NaN,
14
+ shouldSubscribe: false,
15
+ // user callbacks
16
+ onSubscribe: noop,
17
+ };
18
+ const DataObservableContext = createContext(defaultObservableValues);
19
+ /**
20
+ * The react context provider for the {@link UseObservableValues}
21
+ * @param props The properties
22
+ * @return The children wrapped in this provider
23
+ * @constructor
24
+ */
25
+ export default function DataObservableProvider(props) {
26
+ const { seriesObservable, windowingTime = defaultObservableValues.windowingTime || 100, shouldSubscribe, onSubscribe = noop, onUpdateData = noop, onUpdateChartTime = noop, } = props;
27
+ // when initial data is provided, and importantly, when a function is provided that converts
28
+ // the initial data into an object of type ChartData, and when there is a defined series
29
+ // observable, then the initial data is prepended to the data observable.
30
+ const { initialData, asChartData } = useInitialData();
31
+ const observable = dataObservable(seriesObservable, initialData, asChartData);
32
+ return _jsx(DataObservableContext.Provider, { value: {
33
+ seriesObservable: observable,
34
+ windowingTime,
35
+ shouldSubscribe,
36
+ onSubscribe,
37
+ onUpdateData,
38
+ onUpdateChartTime,
39
+ }, children: props.children });
40
+ }
41
+ /**
42
+ * When initial data is provided, and importantly, when a function is provided that converts
43
+ * the initial data into an object of type ChartData, and when there is a defined series
44
+ * observable, then the initial data is prepended to the data observable. When only initial data
45
+ * is provided and a conversion function, then a creates an observable from the initial data.
46
+ * And, when only a defined series observable is specified, then that is used (this is the default,
47
+ * and backward compatible behavior).
48
+ * @param seriesObservable An optional series observable
49
+ * @param initialData An array of initial data series
50
+ * @param asChartData A function that converts the initial data series into chart data
51
+ * @return An {@link Observable} of {@link ChartData}, or an `undefined`
52
+ */
53
+ function dataObservable(seriesObservable, initialData, asChartData) {
54
+ if (seriesObservable !== undefined && initialData !== undefined && initialData.length > 0 && asChartData !== undefined) {
55
+ return concat(from([asChartData(initialData)]), seriesObservable);
56
+ }
57
+ else if (initialData !== undefined && initialData.length > 0 && asChartData !== undefined) {
58
+ return from([asChartData(initialData)]);
59
+ }
60
+ else {
61
+ return seriesObservable;
62
+ }
63
+ }
64
+ /**
65
+ * React hook that sets up the React context for the chart values.
66
+ * @return The {@link UseObservableValues} held in the React context.
67
+ */
68
+ export function useDataObservable() {
69
+ const context = useContext(DataObservableContext);
70
+ const { onSubscribe } = context;
71
+ if (onSubscribe === undefined) {
72
+ throw new Error("useDataObservable can only be used when the parent is a <DataObservableProvider/>");
73
+ }
74
+ return context;
75
+ }
76
+ //# sourceMappingURL=useDataObservable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDataObservable.js","sourceRoot":"","sources":["../../../../../src/app/charts/hooks/useDataObservable.tsx"],"names":[],"mappings":";A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