stream-charts 1.0.0 → 1.1.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 (271) hide show
  1. package/README.md +758 -345
  2. package/changes.md +10 -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} +17 -11
  146. package/dist/src/app/charts/{tooltipUtils.js → tooltips/tooltipUtils.js} +52 -25
  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,19 +1,9 @@
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 { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
13
2
  import { cloneElement, useEffect, useMemo } from "react";
14
3
  import { defaultTooltipStyle, removeTooltip } from "./tooltipUtils";
15
4
  import * as d3 from "d3";
16
- import { useChart } from "./hooks/useChart";
5
+ import { useChart } from "../hooks/useChart";
6
+ import { usePlotDimensions } from "../hooks/usePlotDimensions";
17
7
  /**
18
8
  * Tooltip component triggered by mouse-over-series events. When mounted, the tooltip component
19
9
  * registers a mouse-over handler with the {@link useChart} hook using the
@@ -49,22 +39,27 @@ import { useChart } from "./hooks/useChart";
49
39
  * @constructor
50
40
  */
51
41
  export function Tooltip(props) {
52
- var _a = useChart(), chartId = _a.chartId, container = _a.container, margin = _a.margin, plotDimensions = _a.plotDimensions, registerMouseOverHandler = _a.registerMouseOverHandler, unregisterMouseOverHandler = _a.unregisterMouseOverHandler, tooltipContentProvider = _a.tooltipContentProvider, registerMouseLeaveHandler = _a.registerMouseLeaveHandler, unregisterMouseLeaveHandler = _a.unregisterMouseLeaveHandler;
53
- var visible = props.visible, style = props.style, children = props.children;
54
- var tooltipStyle = useMemo(function () { return (__assign(__assign({}, defaultTooltipStyle), style)); }, [style]);
55
- useEffect(function () {
56
- var handlerId = "tooltip-" + chartId;
42
+ const { chartId, container, tooltip, mouse } = useChart();
43
+ const { tooltipContentProvider, setVisibilityState, } = tooltip;
44
+ const { margin, plotDimensions } = usePlotDimensions();
45
+ const { visible, style, children } = props;
46
+ const { registerMouseOverHandler, unregisterMouseOverHandler, registerMouseLeaveHandler, unregisterMouseLeaveHandler } = mouse;
47
+ const tooltipStyle = useMemo(() => (Object.assign(Object.assign({}, defaultTooltipStyle), style)), [style]);
48
+ // let the tooltip context know whether the tooltip is visible
49
+ setVisibilityState(visible);
50
+ useEffect(() => {
51
+ const handlerId = `tooltip-${chartId}`;
57
52
  if (visible && container) {
58
- var contentProvider_1 = tooltipContentProvider();
59
- if (contentProvider_1) {
53
+ const contentProvider = tooltipContentProvider();
54
+ if (contentProvider) {
60
55
  // register this tooltip's mouse-over event handler with the useCharts hook
61
56
  // so that the plots can call it when mouse-enter events are triggered (for
62
57
  // example, a mouse-over a time-series in the plot).
63
- registerMouseOverHandler(handlerId, (function (seriesName, time, series, mouseCoords) {
58
+ registerMouseOverHandler(handlerId, ((seriesName, time, tooltipData, mouseCoords, providerId) => {
64
59
  // create the rounded rectangle for the tooltip's background
65
- var rect = d3.select(container)
60
+ const rect = d3.select(container)
66
61
  .append('rect')
67
- .attr('id', "r" + time + "-" + seriesName + "-" + chartId)
62
+ .attr('id', `r${time}-${seriesName}-${chartId}`)
68
63
  .attr('class', 'tooltip')
69
64
  .attr('rx', tooltipStyle.borderRadius)
70
65
  .attr('fill', tooltipStyle.backgroundColor)
@@ -72,17 +67,17 @@ export function Tooltip(props) {
72
67
  .attr('stroke', tooltipStyle.borderColor)
73
68
  .attr('stroke-width', tooltipStyle.borderWidth);
74
69
  // call the callback to add the content
75
- var _a = contentProvider_1(seriesName, time, series, mouseCoords), x = _a.x, y = _a.y, contentWidth = _a.contentWidth, contentHeight = _a.contentHeight;
70
+ const { x, y, contentWidth, contentHeight } = contentProvider(seriesName, time, tooltipData, mouseCoords, providerId);
76
71
  // set the position, width, and height of the tooltip rect based on the text height and width and the padding
77
- rect.attr('x', function () { return x; })
78
- .attr('y', function () { return y; })
72
+ rect.attr('x', () => x)
73
+ .attr('y', () => y)
79
74
  .attr('width', contentWidth + tooltipStyle.paddingLeft + tooltipStyle.paddingRight)
80
75
  .attr('height', contentHeight + tooltipStyle.paddingTop + tooltipStyle.paddingBottom);
81
76
  }));
82
- registerMouseLeaveHandler(handlerId, function () { return removeTooltip(); });
77
+ registerMouseLeaveHandler(handlerId, () => removeTooltip());
83
78
  }
84
79
  }
85
- return function () {
80
+ return () => {
86
81
  unregisterMouseOverHandler(handlerId);
87
82
  unregisterMouseLeaveHandler(handlerId);
88
83
  };
@@ -92,6 +87,6 @@ export function Tooltip(props) {
92
87
  unregisterMouseOverHandler, visible, registerMouseLeaveHandler,
93
88
  unregisterMouseLeaveHandler
94
89
  ]);
95
- return _jsx(_Fragment, { children: cloneElement(children, props) }, void 0);
90
+ return _jsx(_Fragment, { children: cloneElement(children, props) });
96
91
  }
97
92
  //# sourceMappingURL=Tooltip.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Tooltip.js","sourceRoot":"","sources":["../../../../../src/app/charts/tooltips/Tooltip.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAC,YAAY,EAAE,SAAS,EAAE,OAAO,EAAM,MAAM,OAAO,CAAC;AAC5D,OAAO,EAAC,mBAAmB,EAAE,aAAa,EAAe,MAAM,gBAAgB,CAAC;AAChF,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,EAAC,QAAQ,EAAC,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAC,iBAAiB,EAAC,MAAM,4BAA4B,CAAC;AAW7D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,MAAM,UAAU,OAAO,CAA6E,KAAY;IAC5G,MAAM,EACF,OAAO,EACP,SAAS,EACT,OAAO,EACP,KAAK,EACR,GAAG,QAAQ,EAAmB,CAAA;IAE/B,MAAM,EACF,sBAAsB,EACtB,kBAAkB,GACrB,GAAG,OAAO,CAAA;IAEX,MAAM,EAAC,MAAM,EAAE,cAAc,EAAC,GAAG,iBAAiB,EAAE,CAAA;IAEpD,MAAM,EACF,OAAO,EACP,KAAK,EACL,QAAQ,EACX,GAAG,KAAK,CAAA;IAET,MAAM,EACF,wBAAwB,EACxB,0BAA0B,EAC1B,yBAAyB,EACzB,2BAA2B,EAC9B,GAAG,KAAK,CAAA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,6GAA6G;oBAC7G,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC;yBAClB,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC;yBAClB,IAAI,CAAC,OAAO,EAAE,YAAY,GAAG,YAAY,CAAC,WAAW,GAAG,YAAY,CAAC,YAAY,CAAC;yBAClF,IAAI,CAAC,QAAQ,EAAE,aAAa,GAAG,YAAY,CAAC,UAAU,GAAG,YAAY,CAAC,aAAa,CAAC,CAAA;gBAE7F,CAAC,CACJ,CACJ,CAAA;gBAED,yBAAyB,CAAC,SAAS,EAAE,GAAG,EAAE,CAAC,aAAa,EAAE,CAAC,CAAA;YAC/D,CAAC;QACL,CAAC;QACD,OAAO,GAAG,EAAE;YACR,0BAA0B,CAAC,SAAS,CAAC,CAAA;YACrC,2BAA2B,CAAC,SAAS,CAAC,CAAA;QAC1C,CAAC,CAAA;IACL,CAAC,EACD;QACI,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,cAAc;QAC1C,wBAAwB,EAAE,sBAAsB,EAAE,YAAY;QAC9D,0BAA0B,EAAE,OAAO,EAAE,yBAAyB;QAC9D,2BAA2B;KAC9B,CACJ,CAAA;IAED,OAAO,4BAAG,YAAY,CAAC,QAAQ,EAAE,KAAK,CAAC,GAAI,CAAA;AAC/C,CAAC"}
@@ -1,6 +1,6 @@
1
- import { TimeSeries } from "./plot";
2
- import { Dimensions, Margin } from "./margins";
3
- import { CategoryAxis } from "./axes";
1
+ import { Series } from "../plots/plot";
2
+ import { Dimensions, Margin } from "../styling/margins";
3
+ import { OrdinalStringAxis } from "../axes/axes";
4
4
  /**
5
5
  * Properties for rendering the tooltip. This is the style for the container
6
6
  * of the content.
@@ -32,6 +32,7 @@ export interface TooltipStyle {
32
32
  backgroundColor: string;
33
33
  backgroundOpacity: number;
34
34
  borderColor: string;
35
+ borderOpacity: number;
35
36
  borderWidth: number;
36
37
  borderRadius: number;
37
38
  paddingLeft: number;
@@ -51,7 +52,7 @@ export interface TooltipDimensions {
51
52
  */
52
53
  export declare function removeTooltip(): void;
53
54
  /**
54
- * Calculates the x-coordinate of the lower left-hand side of the tooltip rectangle (obviously without
55
+ * Calculates the x-coordinate of the upper left-hand side of the tooltip rectangle (obviously without
55
56
  * "rounded corners"). Adjusts the x-coordinate so that tooltip is visible on the edges of the plot.
56
57
  * @param x The current x-coordinate of the mouse
57
58
  * @param textWidth The width of the tooltip text
@@ -62,9 +63,9 @@ export declare function removeTooltip(): void;
62
63
  */
63
64
  export declare function tooltipX(x: number, textWidth: number, plotDimensions: Dimensions, tooltipStyle: TooltipStyle, margin: Margin): number;
64
65
  /**
65
- * Calculates the y-coordinate of the lower-left-hand corner of the tooltip rectangle. Adjusts the y-coordinate
66
+ * Calculates the y-coordinate of the upper-left-hand corner of the tooltip rectangle. Adjusts the y-coordinate
66
67
  * so that the tooltip is visible on the upper edge of the plot
67
- * @param y The y-coordinate of the series
68
+ * @param y The y-coordinate of the mouse
68
69
  * @param textHeight The height of the header and neuron ID text
69
70
  * @param plotDimensions The dimensions of the plot
70
71
  * @param tooltipStyle The tooltip style information
@@ -73,23 +74,28 @@ export declare function tooltipX(x: number, textWidth: number, plotDimensions: D
73
74
  */
74
75
  export declare function tooltipY(y: number, textHeight: number, plotDimensions: Dimensions, tooltipStyle: TooltipStyle, margin: Margin): number;
75
76
  /**
76
- * Calculates the y-coordinate of the lower-left-hand corner of the tooltip rectangle. Adjusts the y-coordinate
77
- * so that the tooltip is visible on the upper edge of the plot
77
+ * Calculates the y-coordinate for the upper-left-hand the tooltip rectangle. Adjusts the y-coordinate so
78
+ * that the tooltip is visible on the upper and lower edges of the plot
78
79
  * @param seriesName The name of the series
79
80
  * @param textHeight The height of the header and neuron ID text
80
81
  * @param axis The category axis for determining the y-value of the tooltip
81
82
  * @param tooltipStyle The tooltip style
82
83
  * @param margin The plot margin
83
84
  * @param categoryHeight The height (in pixels) of the category
85
+ * @param plotDimensions The dimensions of the plot
84
86
  * @return The y-coordinate of the lower-left-hand corner of the tooltip rectangle
85
87
  */
86
- export declare function categoryTooltipY(seriesName: string, textHeight: number, axis: CategoryAxis, tooltipStyle: TooltipStyle, margin: Margin, categoryHeight: number): number;
88
+ export declare function categoryTooltipY(seriesName: string, textHeight: number, axis: OrdinalStringAxis, tooltipStyle: TooltipStyle, margin: Margin, categoryHeight: number, plotDimensions: Dimensions): number;
87
89
  /**
88
90
  * Returns the (time, value) point that comes just before the mouse and just after the mouse
89
91
  * @param data The time-series data
90
- * @param time The time represented by the mouse's x-coordinate
92
+ * @param value The time represented by the mouse's x-coordinate
93
+ * @param xFrom A function that extracts the x-value from the datum
94
+ * @param emptyDatum A function that returns an empty datum
95
+ * @template D The type of the datum in the data-series
91
96
  * @return {[[number, number], [number, number]]} the (time, value) point that comes just before
92
97
  * the mouse and just after the mouse. If the mouse is after the last point, then the "after" point
93
98
  * is `[NaN, NaN]`. If the mouse is before the first point, then the "before" point is `[NaN, NaN]`.
94
99
  */
95
- export declare function boundingPoints(data: TimeSeries, time: number): [[number, number], [number, number]];
100
+ export declare function boundingPoints<D>(data: Series<D>, value: number, xFrom: (value: D) => number, emptyDatum: () => D): [D, D];
101
+ export declare function findPointAndNeighbors<D>(data: Series<D>, value: number, tolerance: number, xFrom: (value: D) => number, emptyDatum: () => D): [D, D, D, number];
@@ -1,13 +1,16 @@
1
1
  import * as d3 from "d3";
2
- export var defaultTooltipStyle = {
2
+ export const defaultTooltipStyle = {
3
3
  visible: false,
4
4
  fontSize: 12,
5
- fontColor: '#d2933f',
5
+ fontColor: 'rgba(10,31,58,0.99)',
6
+ // fontColor: '#d2933f',
7
+ // fontColor: '#202020',
6
8
  fontFamily: 'sans-serif',
7
9
  fontWeight: 250,
8
10
  backgroundColor: '#202020',
9
11
  backgroundOpacity: 0.8,
10
12
  borderColor: '#d2933f',
13
+ borderOpacity: 1,
11
14
  borderWidth: 1,
12
15
  borderRadius: 5,
13
16
  paddingLeft: 10,
@@ -22,7 +25,7 @@ export function removeTooltip() {
22
25
  d3.selectAll('.tooltip').remove();
23
26
  }
24
27
  /**
25
- * Calculates the x-coordinate of the lower left-hand side of the tooltip rectangle (obviously without
28
+ * Calculates the x-coordinate of the upper left-hand side of the tooltip rectangle (obviously without
26
29
  * "rounded corners"). Adjusts the x-coordinate so that tooltip is visible on the edges of the plot.
27
30
  * @param x The current x-coordinate of the mouse
28
31
  * @param textWidth The width of the tooltip text
@@ -32,15 +35,15 @@ export function removeTooltip() {
32
35
  * @return The x-coordinate of the lower left-hand side of the tooltip rectangle
33
36
  */
34
37
  export function tooltipX(x, textWidth, plotDimensions, tooltipStyle, margin) {
35
- if (x + textWidth + tooltipStyle.paddingLeft + 10 > plotDimensions.width + margin.left) {
38
+ if (x > plotDimensions.width + margin.left - (textWidth + tooltipStyle.paddingLeft + tooltipStyle.paddingRight)) {
36
39
  return x - textWidth - margin.right + tooltipStyle.paddingRight + tooltipStyle.paddingLeft;
37
40
  }
38
41
  return x + tooltipStyle.paddingLeft;
39
42
  }
40
43
  /**
41
- * Calculates the y-coordinate of the lower-left-hand corner of the tooltip rectangle. Adjusts the y-coordinate
44
+ * Calculates the y-coordinate of the upper-left-hand corner of the tooltip rectangle. Adjusts the y-coordinate
42
45
  * so that the tooltip is visible on the upper edge of the plot
43
- * @param y The y-coordinate of the series
46
+ * @param y The y-coordinate of the mouse
44
47
  * @param textHeight The height of the header and neuron ID text
45
48
  * @param plotDimensions The dimensions of the plot
46
49
  * @param tooltipStyle The tooltip style information
@@ -48,22 +51,33 @@ export function tooltipX(x, textWidth, plotDimensions, tooltipStyle, margin) {
48
51
  * @return The y-coordinate of the lower-left-hand corner of the tooltip rectangle
49
52
  */
50
53
  export function tooltipY(y, textHeight, plotDimensions, tooltipStyle, margin) {
51
- return Math.min(y + margin.top - textHeight, plotDimensions.height - margin.top + tooltipStyle.paddingTop + tooltipStyle.paddingBottom);
54
+ if (y > plotDimensions.height + margin.top - (textHeight + tooltipStyle.paddingTop + tooltipStyle.paddingBottom)) {
55
+ return plotDimensions.height + margin.top - (textHeight + tooltipStyle.paddingTop + tooltipStyle.paddingBottom);
56
+ }
57
+ return y + tooltipStyle.paddingTop;
52
58
  }
53
59
  /**
54
- * Calculates the y-coordinate of the lower-left-hand corner of the tooltip rectangle. Adjusts the y-coordinate
55
- * so that the tooltip is visible on the upper edge of the plot
60
+ * Calculates the y-coordinate for the upper-left-hand the tooltip rectangle. Adjusts the y-coordinate so
61
+ * that the tooltip is visible on the upper and lower edges of the plot
56
62
  * @param seriesName The name of the series
57
63
  * @param textHeight The height of the header and neuron ID text
58
64
  * @param axis The category axis for determining the y-value of the tooltip
59
65
  * @param tooltipStyle The tooltip style
60
66
  * @param margin The plot margin
61
67
  * @param categoryHeight The height (in pixels) of the category
68
+ * @param plotDimensions The dimensions of the plot
62
69
  * @return The y-coordinate of the lower-left-hand corner of the tooltip rectangle
63
70
  */
64
- export function categoryTooltipY(seriesName, textHeight, axis, tooltipStyle, margin, categoryHeight) {
65
- var y = (axis.scale(seriesName) || 0) + margin.top - tooltipStyle.paddingBottom;
66
- return y > 0 ? y : y + tooltipStyle.paddingBottom + textHeight + tooltipStyle.paddingTop + categoryHeight;
71
+ export function categoryTooltipY(seriesName, textHeight, axis, tooltipStyle, margin, categoryHeight, plotDimensions) {
72
+ const y = axis.scale(seriesName) || 0;
73
+ const halfHeight = (tooltipStyle.paddingBottom + textHeight + tooltipStyle.paddingTop) / 2;
74
+ if (y < halfHeight) {
75
+ return margin.top;
76
+ }
77
+ if (y > plotDimensions.height + margin.top - halfHeight) {
78
+ return plotDimensions.height + margin.top - textHeight;
79
+ }
80
+ return y + margin.top - halfHeight + categoryHeight / 2;
67
81
  }
68
82
  /**
69
83
  * Returns the index of the data point whose time is the upper boundary on the specified
@@ -72,38 +86,51 @@ export function categoryTooltipY(seriesName, textHeight, axis, tooltipStyle, mar
72
86
  * the specified array, then returns -1.
73
87
  * @param data The array of points from which to select the
74
88
  * boundary.
75
- * @param time The time for which to find the bounding points
89
+ * @param value The time for which to find the bounding points
90
+ * @param xFrom A function that extracts the x-value from the datum
91
+ * @template D The type of the datum in the data-series
76
92
  * @return The index of the upper boundary.
77
93
  */
78
- function boundingPointsIndex(data, time) {
79
- var length = data.length;
80
- if (time > data[length - 1][0]) {
94
+ function boundingPointsIndex(data, value, xFrom) {
95
+ const length = data.length;
96
+ if (value > xFrom(data[length - 1])) {
81
97
  return length;
82
98
  }
83
- if (time < data[0][0]) {
99
+ if (value < xFrom(data[0])) {
84
100
  return 0;
85
101
  }
86
- return data.findIndex(function (value, index, array) {
87
- var lowerIndex = Math.max(0, index - 1);
88
- return array[lowerIndex][0] <= time && time <= array[index][0];
102
+ return data.findIndex((_, index, array) => {
103
+ const lowerIndex = Math.max(0, index - 1);
104
+ return xFrom(array[lowerIndex]) <= value && value <= xFrom(array[index]);
89
105
  });
90
106
  }
91
107
  /**
92
108
  * Returns the (time, value) point that comes just before the mouse and just after the mouse
93
109
  * @param data The time-series data
94
- * @param time The time represented by the mouse's x-coordinate
110
+ * @param value The time represented by the mouse's x-coordinate
111
+ * @param xFrom A function that extracts the x-value from the datum
112
+ * @param emptyDatum A function that returns an empty datum
113
+ * @template D The type of the datum in the data-series
95
114
  * @return {[[number, number], [number, number]]} the (time, value) point that comes just before
96
115
  * the mouse and just after the mouse. If the mouse is after the last point, then the "after" point
97
116
  * is `[NaN, NaN]`. If the mouse is before the first point, then the "before" point is `[NaN, NaN]`.
98
117
  */
99
- export function boundingPoints(data, time) {
100
- var upperIndex = boundingPointsIndex(data, time);
118
+ export function boundingPoints(data, value, xFrom, emptyDatum) {
119
+ const upperIndex = boundingPointsIndex(data, value, xFrom);
101
120
  if (upperIndex <= 0) {
102
- return [[NaN, NaN], data[0]];
121
+ return [emptyDatum(), data[0]];
103
122
  }
104
123
  if (upperIndex >= data.length) {
105
- return [data[data.length - 1], [NaN, NaN]];
124
+ return [data[data.length - 1], emptyDatum()];
106
125
  }
107
126
  return [data[upperIndex - 1], data[upperIndex]];
108
127
  }
128
+ export function findPointAndNeighbors(data, value, tolerance, xFrom, emptyDatum) {
129
+ // find the index of the point
130
+ const index = data.findIndex((_, index, array) => Math.abs(xFrom(array[index]) - value) <= tolerance);
131
+ const point = index > -1 ? data[index] : emptyDatum();
132
+ const lower = (index > 0) ? data[index - 1] : emptyDatum();
133
+ const upper = (index < data.length - 1) ? data[index + 1] : emptyDatum();
134
+ return [lower, point, upper, index];
135
+ }
109
136
  //# sourceMappingURL=tooltipUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tooltipUtils.js","sourceRoot":"","sources":["../../../../../src/app/charts/tooltips/tooltipUtils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AAiDzB,MAAM,CAAC,MAAM,mBAAmB,GAAiB;IAC7C,OAAO,EAAE,KAAK;IAEd,QAAQ,EAAE,EAAE;IACZ,SAAS,EAAE,qBAAqB;IAChC,wBAAwB;IACxB,wBAAwB;IACxB,UAAU,EAAE,YAAY;IACxB,UAAU,EAAE,GAAG;IAEf,eAAe,EAAE,SAAS;IAC1B,iBAAiB,EAAE,GAAG;IAEtB,WAAW,EAAE,SAAS;IACtB,aAAa,EAAE,CAAC;IAChB,WAAW,EAAE,CAAC;IACd,YAAY,EAAE,CAAC;IAEf,WAAW,EAAE,EAAE;IACf,YAAY,EAAE,EAAE;IAChB,UAAU,EAAE,CAAC;IACb,aAAa,EAAE,EAAE;CACpB,CAAC;AASF;;GAEG;AACH,MAAM,UAAU,aAAa;IACzB,EAAE,CAAC,SAAS,CAAwB,UAAU,CAAC,CAAC,MAAM,EAAE,CAAA;AAC5D,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,QAAQ,CAAC,CAAS,EAAE,SAAiB,EAAE,cAA0B,EAAE,YAA0B,EAAE,MAAc;IACzH,IAAI,CAAC,GAAG,cAAc,CAAC,KAAK,GAAG,MAAM,CAAC,IAAI,GAAG,CAAC,SAAS,GAAG,YAAY,CA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AO,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,CAAA;IAChD,CAAC;IACD,OAAO,CAAC,IAAI,CAAC,UAAU,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC,CAAA;AACnD,CAAC;AAED,MAAM,UAAU,qBAAqB,CACjC,IAAe,EACf,KAAa,EACb,SAAiB,EACjB,KAA2B,EAC3B,UAAmB;IAEnB,8BAA8B;IAC9B,MAAM,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,GAAG,KAAK,CAAC,IAAI,SAAS,CAAC,CAAA;IACrG,MAAM,KAAK,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,UAAU,EAAE,CAAA;IACrD,MAAM,KAAK,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,GAAC,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,EAAE,CAAA;IACxD,MAAM,KAAK,GAAG,CAAC,KAAK,GAAG,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,GAAC,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,EAAE,CAAA;IACtE,OAAO,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,CAAA;AACvC,CAAC"}
@@ -1,24 +1,25 @@
1
1
  import { TrackerLabelFont, TrackerStyle } from "./trackerUtils";
2
- import { AxisLocation } from "./axes";
2
+ import { AxisLocation } from "../axes/axes";
3
3
  export interface TrackerAxisInfo {
4
4
  x: number;
5
5
  axisLocation: AxisLocation;
6
6
  }
7
- export declare type TrackerAxisUpdate = Map<string, TrackerAxisInfo>;
7
+ export type TrackerAxisUpdate = Map<string, TrackerAxisInfo>;
8
8
  export declare enum TrackerLabelLocation {
9
9
  Nowhere = 0,
10
- WithMouse = 1,
11
- ByAxes = 2
10
+ ByAxis = 1
12
11
  }
13
12
  interface Props {
14
13
  visible: boolean;
14
+ trackerAxis?: AxisLocation;
15
15
  labelLocation?: TrackerLabelLocation;
16
+ labelFormatter?: (value: number) => string;
16
17
  style?: Partial<TrackerStyle>;
17
18
  font?: Partial<TrackerLabelFont>;
18
19
  onTrackerUpdate?: (update: TrackerAxisUpdate) => void;
19
20
  }
20
21
  /**
21
- * A tracker line that displays or reports the time at the mouse location. The tracker
22
+ * A tracker line that displays or reports the x or y coordinates at the mouse location. The tracker
22
23
  * handles single axes and dual axes.
23
24
  * @param props The tracker control properties
24
25
  * @return null component
@@ -0,0 +1,60 @@
1
+ import { noop } from "../utils";
2
+ import { useChart } from "../hooks/useChart";
3
+ import { defaultTrackerLabelFont, defaultTrackerStyle, removeTrackerControl, trackerControlInstance } from "./trackerUtils";
4
+ import * as d3 from "d3";
5
+ import { useEffect, useMemo, useRef } from "react";
6
+ import { AxisLocation } from "../axes/axes";
7
+ import { usePlotDimensions } from "../hooks/usePlotDimensions";
8
+ export var TrackerLabelLocation;
9
+ (function (TrackerLabelLocation) {
10
+ TrackerLabelLocation[TrackerLabelLocation["Nowhere"] = 0] = "Nowhere";
11
+ TrackerLabelLocation[TrackerLabelLocation["ByAxis"] = 1] = "ByAxis";
12
+ })(TrackerLabelLocation || (TrackerLabelLocation = {}));
13
+ /**
14
+ * A tracker line that displays or reports the x or y coordinates at the mouse location. The tracker
15
+ * handles single axes and dual axes.
16
+ * @param props The tracker control properties
17
+ * @return null component
18
+ * @constructor
19
+ */
20
+ export function Tracker(props) {
21
+ const { visible, trackerAxis = AxisLocation.Bottom, labelLocation = TrackerLabelLocation.ByAxis, labelFormatter, style, font, onTrackerUpdate = noop } = props;
22
+ const { chartId, container, axes, backgroundColor } = useChart();
23
+ const { xAxesState, yAxesState } = axes;
24
+ const axisState = (trackerAxis === AxisLocation.Bottom || trackerAxis === AxisLocation.Top) ?
25
+ xAxesState :
26
+ yAxesState;
27
+ const { plotDimensions, margin } = usePlotDimensions();
28
+ const trackerStyle = useMemo(() => (Object.assign(Object.assign({}, defaultTrackerStyle), style)), [style]);
29
+ const trackerFont = useMemo(() => (Object.assign(Object.assign({}, defaultTrackerLabelFont), font)), [font]);
30
+ const trackerRef = useRef(undefined);
31
+ const axisRef = useRef(new Map());
32
+ useEffect(() => {
33
+ const axes = new Map();
34
+ axisState.axes.forEach((axis, id) => axes.set(id, axis));
35
+ axisRef.current = axes;
36
+ }, [axisState]);
37
+ // when the container, tracker-control function, or visibility change, then we need to update the
38
+ // tracker control
39
+ useEffect(() => {
40
+ if (container) {
41
+ const svg = d3.select(container);
42
+ if (visible && container) {
43
+ const trackerLabels = new Map(Array.from(axisRef.current.values()).map(axis => {
44
+ const formatter = labelFormatter !== null && labelFormatter !== void 0 ? labelFormatter : ((value) => labelLocation === TrackerLabelLocation.Nowhere ?
45
+ "" :
46
+ `${d3.format(",.0f")(value)}`);
47
+ return [axis, formatter];
48
+ }));
49
+ trackerRef.current = trackerControlInstance(chartId, container, svg, plotDimensions, margin, trackerStyle, trackerFont, trackerLabels, labelLocation, onTrackerUpdate, trackerAxis, backgroundColor);
50
+ }
51
+ // if the tracker was defined and is now no longer defined (i.e., props changed, then remove the tracker)
52
+ else if (!visible && trackerRef.current !== undefined) {
53
+ removeTrackerControl(svg, trackerAxis);
54
+ trackerRef.current = undefined;
55
+ }
56
+ }
57
+ }, [backgroundColor, chartId, container, labelFormatter, labelLocation, margin, onTrackerUpdate, plotDimensions, trackerAxis, trackerFont, trackerStyle, visible]);
58
+ return null;
59
+ }
60
+ //# sourceMappingURL=Tracker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Tracker.js","sourceRoot":"","sources":["../../../../../src/app/charts/trackers/Tracker.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OAAO,CAAC,IAAI,EAAE,SAAS,CAAC,CAAA;gBAC5B,CAAC,CAAC,CACL,CAAA;gBAED,UAAU,CAAC,OAAO,GAAG,sBAAsB,CACvC,OAAO,EACP,SAAS,EACT,GAAG,EACH,cAAc,EACd,MAAM,EACN,YAAY,EACZ,WAAW,EACX,aAAa,EACb,aAAa,EACb,eAAe,EACf,WAAW,EACX,eAAe,CAClB,CAAA;YACL,CAAC;YACD,yGAAyG;iBACpG,IAAI,CAAC,OAAO,IAAI,UAAU,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;gBACpD,oBAAoB,CAAC,GAAG,EAAE,WAAW,CAAC,CAAA;gBACtC,UAAU,CAAC,OAAO,GAAG,SAAS,CAAA;YAClC,CAAC;QACL,CAAC;IACL,CAAC,EACD,CAAC,eAAe,EAAE,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,EAAE,eAAe,EAAE,cAAc,EAAE,WAAW,EAAE,WAAW,EAAE,YAAY,EAAE,OAAO,CAAC,CACjK,CAAA;IAED,OAAO,IAAI,CAAA;AACf,CAAC"}
@@ -1,6 +1,6 @@
1
- import { SvgSelection, TrackerSelection } from "./d3types";
2
- import { Dimensions, Margin } from "./margins";
3
- import { ContinuousNumericAxis } from "./axes";
1
+ import { SvgSelection, TrackerSelection } from "../d3types";
2
+ import { Dimensions, Margin } from "../styling/margins";
3
+ import { AxisLocation, ContinuousNumericAxis } from "../axes/axes";
4
4
  import { TrackerAxisUpdate, TrackerLabelLocation } from "./Tracker";
5
5
  export interface TrackerLabelFont {
6
6
  size: number;
@@ -16,7 +16,8 @@ export interface TrackerStyle {
16
16
  }
17
17
  export declare const defaultTrackerStyle: TrackerStyle;
18
18
  /**
19
- * Creates or returns the existing SVG elements for displaying a tracker line
19
+ * Creates or returns the existing SVG elements for displaying a tracker line that is either
20
+ * vertical (for x-axes) or horizontal (for y-axes).
20
21
  * @param chartId The ID of the chart
21
22
  * @param container The SVG container
22
23
  * @param svg The SVG selection
@@ -26,12 +27,16 @@ export declare const defaultTrackerStyle: TrackerStyle;
26
27
  * @param labelFont The font used for the axis labels
27
28
  * @param label A function that returns the tracker label string for a given x-value
28
29
  * @param labelStyle The location style for the tracker (i.e. on the axes, next to the mouse, none shown)
29
- * @param onTrackerUpdate A callback function the accepts the current tracker's axis information
30
+ * @param onTrackerUpdate A callback function that accepts the current tracker's axis information
31
+ * @param [axisLocation = AxisLocation.Bottom] The optional location of the axis for which the tracker is to
32
+ * be shown. Default is bottom.
33
+ * @param backgroundColor The background color of the tracker label
30
34
  * @return The tracker selection
31
35
  */
32
- export declare function trackerControlInstance(chartId: number, container: SVGSVGElement, svg: SvgSelection, plotDimensions: Dimensions, margin: Margin, style: TrackerStyle, labelFont: TrackerLabelFont, label: Map<ContinuousNumericAxis, (x: number) => string>, labelStyle: TrackerLabelLocation, onTrackerUpdate: (update: TrackerAxisUpdate) => void): TrackerSelection;
36
+ export declare function trackerControlInstance(chartId: number, container: SVGSVGElement, svg: SvgSelection, plotDimensions: Dimensions, margin: Margin, style: TrackerStyle, labelFont: TrackerLabelFont, label: Map<ContinuousNumericAxis, (x: number) => string>, labelStyle: TrackerLabelLocation, onTrackerUpdate: (update: TrackerAxisUpdate) => void, axisLocation: AxisLocation | undefined, backgroundColor: string): TrackerSelection;
33
37
  /**
34
38
  * Removes the tracker control from the chart
35
- * @param svg The svg selection holding the tracker contol
39
+ * @param svg The svg selection holding the tracker control
40
+ * @param axisLocation The location of the axis for which the tracker is to be removed.
36
41
  */
37
- export declare function removeTrackerControl(svg: SvgSelection): void;
42
+ export declare function removeTrackerControl(svg: SvgSelection, axisLocation: AxisLocation): void;