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
@@ -0,0 +1,1046 @@
1
+ import { ContinuousAxisRange } from "./ContinuousAxisRange";
2
+ import * as d3 from "d3";
3
+ import { noop } from "../utils";
4
+ import { OrdinalAxisRange } from "./OrdinalAxisRange";
5
+ import { AxisInterval } from "./AxisInterval";
6
+ /**
7
+ * Factory function to create a default AxisTickStyle with the default font,
8
+ * no rotation, and no auto-rotation.
9
+ */
10
+ export function defaultAxisTickStyle() {
11
+ return {
12
+ font: defaultAxesFont(),
13
+ rotation: 0,
14
+ useAutoRotation: false
15
+ };
16
+ }
17
+ /**
18
+ * Factory function to create a default AxesFont with the default font size, color,
19
+ * family, and weight.
20
+ */
21
+ export function defaultAxesFont() {
22
+ return {
23
+ size: 12,
24
+ color: '#d2933f',
25
+ weight: 300,
26
+ family: 'sans-serif'
27
+ };
28
+ }
29
+ /**
30
+ * Factory function to create a default SeriesLineStyle with the default color, line width,
31
+ * highlight color, and highlight width.
32
+ */
33
+ export function defaultLineStyle() {
34
+ return {
35
+ color: '#008aad',
36
+ lineWidth: 1,
37
+ highlightColor: '#008aad',
38
+ highlightWidth: 3,
39
+ };
40
+ }
41
+ /**
42
+ * Enumerates the possible locations of an axis.
43
+ */
44
+ export var AxisLocation;
45
+ (function (AxisLocation) {
46
+ // y-axes
47
+ AxisLocation[AxisLocation["Left"] = 0] = "Left";
48
+ AxisLocation[AxisLocation["Right"] = 1] = "Right";
49
+ // x-axes
50
+ AxisLocation[AxisLocation["Bottom"] = 2] = "Bottom";
51
+ AxisLocation[AxisLocation["Top"] = 3] = "Top";
52
+ })(AxisLocation || (AxisLocation = {}));
53
+ /*
54
+ axis clip path definition
55
+ */
56
+ /**
57
+ * Adds a clip area for the chart to the specified SVG element. The clip-area is given
58
+ * an `id` of `clip-series-<chart_id>`, which because the chart ID should be unique, makes
59
+ * this unique as well
60
+ * @param chartId The ID of the chart to which the clip area is to be added
61
+ * @param axisId The ID of the axis to which the clip area is to be added
62
+ * @param svg The SVG element to which the clip area is to be added
63
+ * @param location The location of the axis
64
+ * @param plotDimensions The dimensions of the plot
65
+ * @param margin The margins around the plot
66
+ * @return The ID of the clip-path
67
+ */
68
+ export function setClipPath(chartId, axisId, svg, location, plotDimensions, margin) {
69
+ const clipPathId = `chart-clip-path-${chartId}-${axisId}`;
70
+ // calculate the width and height of the clip-area for the axis
71
+ const width = location === AxisLocation.Left ? margin.right :
72
+ location === AxisLocation.Right ? margin.left :
73
+ plotDimensions.width;
74
+ const height = location === AxisLocation.Top ? margin.top + 1 :
75
+ location === AxisLocation.Bottom ? margin.bottom - 1 :
76
+ plotDimensions.height;
77
+ // remove the old clipping region and add a new one with the updated plot dimensions
78
+ svg.select(`#${clipPathId}-defs`).remove();
79
+ svg
80
+ .append('defs')
81
+ .attr('id', `${clipPathId}-defs`)
82
+ .append("clipPath")
83
+ .attr("id", clipPathId)
84
+ .append("rect")
85
+ .attr("x", 0)
86
+ .attr("y", location === AxisLocation.Bottom ? -1 : -margin.top)
87
+ .attr("width", width)
88
+ .attr("height", height);
89
+ return clipPathId;
90
+ }
91
+ /*
92
+ category axes
93
+ */
94
+ /**
95
+ * Adds a category axis to the specified location. When the location is top or bottom,
96
+ * the category axis represents the x-axis. When the location is left or right, then the
97
+ * category axis represents the y-axis.
98
+ * @param chartId The unique ID of the chart to which this axis belongs
99
+ * @param axisId A unique ID for the axis
100
+ * @param svg The SVG selection (d3)
101
+ * @param location The location of the axis
102
+ * @param categories An array holding the category names
103
+ * @param axisLabel The axis label
104
+ * @param axesLabelFont The font for the axis label
105
+ * @param axisTickStyle Styling information for the ticks (e.g. font, rotation, etc)
106
+ * @param plotDimensions The dimensions of the plot
107
+ * @param margin The plot margin
108
+ * @param setAxisRangeFor Lambda that sets the axis range for the specified axis
109
+ * @param setOriginalAxisRangeFor Lambda that sets the original axis range for the specified axis
110
+ * @return A category axis
111
+ */
112
+ export function addOrdinalStringAxis(chartId, axisId, svg, location, categories, axisLabel, axesLabelFont, axisTickStyle, plotDimensions, margin, setAxisRangeFor, setOriginalAxisRangeFor) {
113
+ switch (location) {
114
+ case AxisLocation.Top:
115
+ case AxisLocation.Bottom:
116
+ return addOrdinalStringXAxis(chartId, axisId, svg, location, categories, axisLabel, axesLabelFont, axisTickStyle, plotDimensions, margin, setAxisRangeFor, setOriginalAxisRangeFor);
117
+ case AxisLocation.Left:
118
+ case AxisLocation.Right:
119
+ return addOrdinalStringYAxis(chartId, axisId, svg, location, categories, axisLabel, axesLabelFont, axisTickStyle, plotDimensions, margin, setAxisRangeFor, setOriginalAxisRangeFor);
120
+ }
121
+ }
122
+ /**
123
+ * Adds a category axis representing the x-axis.
124
+ * @param chartId The unique ID of the chart to which this axis belongs
125
+ * @param axisId A unique ID for the axis
126
+ * @param svg The SVG selection (d3)
127
+ * @param location The location of the axis
128
+ * @param categories An array holding the category names
129
+ * @param axisLabel The axis label
130
+ * @param axesLabelFont The font for the axis label
131
+ * @param axisTickStyle Styling information for the ticks (e.g. font, rotation, etc)
132
+ * @param plotDimensions The dimensions of the plot
133
+ * @param margin The plot margin
134
+ * @param setAxisRangeFor Lambda that sets the axis range for the specified axis
135
+ * @param setOriginalAxisRangeFor Lambda that sets the original axis range for the specified axis
136
+ * @return A category axis
137
+ */
138
+ function addOrdinalStringXAxis(chartId, axisId, svg, location, categories, axisLabel, axesLabelFont, axisTickStyle, plotDimensions, margin, setAxisRangeFor, setOriginalAxisRangeFor) {
139
+ const scale = d3.scaleBand()
140
+ .domain(categories)
141
+ .range([0, plotDimensions.width]);
142
+ const categorySize = scale.bandwidth();
143
+ // create and add the axes
144
+ const generator = location === AxisLocation.Bottom ? d3.axisBottom(scale) : d3.axisTop(scale);
145
+ const clipPathId = setClipPath(chartId, axisId, svg, location, plotDimensions, margin);
146
+ const selection = svg
147
+ .append('g')
148
+ .attr('id', `x-axis-selection-${chartId}-${axisId}`)
149
+ .attr("clip-path", `url(#${clipPathId})`)
150
+ .classed('x-axis', true)
151
+ .attr('transform', `translate(${margin.left}, ${yTranslation(location, plotDimensions, margin)})`)
152
+ .call(generator);
153
+ // rotate the tick-labels by the specified amount (in degrees)
154
+ let maxTickLabelHeight = 0;
155
+ const { font, rotation } = axisTickStyle;
156
+ selection
157
+ .selectAll("text")
158
+ .style("text-anchor", "end")
159
+ .each(function () {
160
+ const degrees = location === AxisLocation.Bottom ? -rotation : rotation;
161
+ const radians = degrees * Math.PI / 180;
162
+ const { width, height, x, y } = this.getBBox();
163
+ const xOrigin = x + width;
164
+ const yOrigin = location === AxisLocation.Bottom ? y + height / 2 : y + height / 2;
165
+ d3.select(this)
166
+ .attr("transform", () => `translate(${width * Math.cos(radians) / 2}, 0) rotate(${degrees}, ${xOrigin}, ${yOrigin})`);
167
+ const newHeight = Math.abs(width * Math.sin(radians));
168
+ if (newHeight > maxTickLabelHeight) {
169
+ maxTickLabelHeight = newHeight;
170
+ }
171
+ });
172
+ svg
173
+ .append('text')
174
+ .attr('id', labelIdFor(chartId, location))
175
+ .style('text-anchor', 'middle')
176
+ // when the axis is at the top, want the label to hang from the top (y=0) of the plot
177
+ .attr('dominant-baseline', location === AxisLocation.Top ? "hanging" : "baseline")
178
+ .attr('font-size', font.size)
179
+ .attr('fill', font.color)
180
+ .attr('font-family', font.family)
181
+ .attr('font-weight', font.weight)
182
+ .text(axisLabel);
183
+ const axis = { axisId, selection, location, scale, generator, categorySize, update: () => categorySize };
184
+ return Object.assign(Object.assign({}, axis), { update: (range, originalRange, plotDimensions, margin) => {
185
+ const categorySize = updateOrdinalStringXAxis(chartId, axis, svg, location, categories, range, axesLabelFont, plotDimensions, margin);
186
+ setAxisRangeFor(axisId, range);
187
+ setOriginalAxisRangeFor(axisId, originalRange);
188
+ return categorySize;
189
+ } });
190
+ }
191
+ /**
192
+ * Adds a category axis representing the y-axis.
193
+ * @param chartId The unique ID of the chart to which this axis belongs
194
+ * @param axisId A unique ID for the axis
195
+ * @param svg The SVG selection (d3)
196
+ * @param location The location of the axis
197
+ * @param categories An array holding the category names
198
+ * @param axisLabel The axis label
199
+ * @param axesLabelFont The font for the axis label
200
+ * @param axisTickStyle Styling information for the ticks (e.g. font, rotation, etc)
201
+ * @param plotDimensions The dimensions of the plot
202
+ * @param margin The plot margin
203
+ * @param setAxisRangeFor Lambda that sets the axis range for the specified axis
204
+ * @param setOriginalAxisRangeFor Lambda that sets the original axis range for the specified axis
205
+ * @return A category axis
206
+ */
207
+ function addOrdinalStringYAxis(chartId, axisId, svg, location, categories, axisLabel, axesLabelFont, axisTickStyle, plotDimensions, margin, setAxisRangeFor, setOriginalAxisRangeFor) {
208
+ const scale = d3.scaleBand()
209
+ .domain(categories)
210
+ .range([0, plotDimensions.height]);
211
+ const categorySize = scale.bandwidth();
212
+ // create and add the axes
213
+ const generator = location === AxisLocation.Left ? d3.axisLeft(scale) : d3.axisRight(scale);
214
+ const selection = svg
215
+ .append('g')
216
+ .attr('id', `y-axis-selection-${chartId}`)
217
+ .attr('class', 'y-axis')
218
+ .attr('transform', `translate(${xTranslation(location, plotDimensions, margin)}, ${margin.top})`)
219
+ .call(generator);
220
+ // rotate the tick-labels by the specified amount (in degrees)
221
+ const { font, rotation } = axisTickStyle;
222
+ selection
223
+ .selectAll("text")
224
+ .style("text-anchor", "end")
225
+ .each(function () {
226
+ const degrees = location === AxisLocation.Left ? -rotation : rotation;
227
+ const { width, height, x, y } = this.getBBox();
228
+ const xTranslation = location === AxisLocation.Left ? 0 : width;
229
+ const xOrigin = x + width;
230
+ const yOrigin = location === AxisLocation.Left ? y + height / 2 : y + height / 2;
231
+ d3.select(this)
232
+ .attr("transform", () => `translate(${xTranslation}, 0) rotate(${degrees}, ${xOrigin}, ${yOrigin})`);
233
+ });
234
+ svg
235
+ .append('text')
236
+ .attr('id', labelIdFor(chartId, location))
237
+ .attr('text-anchor', 'middle')
238
+ .attr('font-size', font.size)
239
+ .attr('fill', font.color)
240
+ .attr('font-family', font.family)
241
+ .attr('font-weight', font.weight)
242
+ .attr('transform', `translate(${ordinalLabelXTranslation(location, plotDimensions, margin, axesLabelFont)}, ${ordinalLabelYTranslation(location, plotDimensions, margin)}) rotate(-90)`)
243
+ .text(axisLabel);
244
+ const axis = { axisId, selection, location, scale, generator, categorySize, update: () => categorySize };
245
+ return Object.assign(Object.assign({}, axis), { update: (range, originalRange, plotDimensions, margin) => {
246
+ const categorySize = updateOrdinalStringYAxis(chartId, axis, svg, location, categories, range, axesLabelFont, plotDimensions, margin);
247
+ setAxisRangeFor(axisId, range);
248
+ setOriginalAxisRangeFor(axisId, originalRange);
249
+ return categorySize;
250
+ } });
251
+ }
252
+ /**
253
+ * Updates the category axis representing the x-axis, calculates and returns the
254
+ * number of pixels for each category on the x-axis.
255
+ * @param chartId The unique ID of the chart to which this axis belongs
256
+ * @param axis The category axis to be updated
257
+ * @param svg The SVG selection (d3)
258
+ * @param location The location of the axis
259
+ * @param names An array holding the category names
260
+ * @param axesLabelFont The font for the axis label
261
+ * @param plotDimensions The dimensions of the plot
262
+ * @param margin The plot margin
263
+ * @param range The range of the axis (e.g., start and end) in pixels
264
+ * @param axesLabelFont The font for the axis label
265
+ * @param plotDimensions The dimensions of the plot
266
+ * @param margin The plot margin
267
+ * adjust the axis label location when needed
268
+ * @return The number of pixels for each category
269
+ */
270
+ function updateOrdinalStringXAxis(chartId, axis, svg, location, names, // domain (categories)
271
+ range, // range (pixels)
272
+ axesLabelFont, plotDimensions, margin) {
273
+ const updatedRange = AxisInterval.from(Math.min(range.start, 0), Math.max(range.end, plotDimensions.width));
274
+ axis.scale = axis.scale
275
+ .domain(names)
276
+ .range(updatedRange.asTuple());
277
+ axis.categorySize = axis.scale.bandwidth();
278
+ const clipPathId = setClipPath(chartId, axis.axisId, svg, location, plotDimensions, margin);
279
+ axis.selection = axis.selection
280
+ .attr('transform', `translate(${margin.left}, ${yTranslation(location, plotDimensions, margin)})`)
281
+ .attr("clip-path", `url(#${clipPathId})`)
282
+ .call(axis.generator);
283
+ const xLabelTranslation = ordinalLabelXTranslation(location, plotDimensions, margin, axesLabelFont);
284
+ const yLabelTranslation = ordinalLabelYTranslation(location, plotDimensions, margin);
285
+ svg
286
+ .select(`#${labelIdFor(chartId, location)}`)
287
+ .attr('transform', `translate(${xLabelTranslation}, ${yLabelTranslation})`);
288
+ return axis.categorySize;
289
+ }
290
+ /**
291
+ * Updates the category axis representing the y-axis, calculates and returns the
292
+ * number of pixels for each category on the y-axis.
293
+ * @param chartId The unique ID of the chart to which this axis belongs
294
+ * @param axis The category axis to be updated
295
+ * @param svg The SVG selection (d3)
296
+ * @param location The location of the axis
297
+ * @param names An array holding the category names
298
+ * @param range The range of the axis (e.g. start and end)
299
+ * @param axesLabelFont The font for the axis label
300
+ * @param plotDimensions The dimensions of the plot
301
+ * @param margin The plot margin
302
+ * @param axesLabelFont The font for the axis label
303
+ * @param plotDimensions The dimensions of the plot
304
+ * @param margin The plot margin
305
+ * @return The number of pixels for each category
306
+ */
307
+ function updateOrdinalStringYAxis(chartId, axis, svg, location, names, // domain
308
+ range, // range
309
+ axesLabelFont, plotDimensions, margin) {
310
+ const updatedRange = AxisInterval.from(Math.min(range.start, 0), Math.max(range.end, plotDimensions.height));
311
+ axis.scale = axis.scale
312
+ .domain(names)
313
+ .range(updatedRange.asTuple());
314
+ axis.categorySize = axis.scale.bandwidth();
315
+ axis.selection = axis.selection
316
+ .attr('transform', `translate(${xTranslation(location, plotDimensions, margin)}, ${margin.top})`)
317
+ .call(axis.generator);
318
+ svg
319
+ .select(`#${labelIdFor(chartId, location)}`)
320
+ .attr('transform', `translate(${ordinalLabelXTranslation(location, plotDimensions, margin, axesLabelFont)}, ${ordinalLabelYTranslation(location, plotDimensions, margin)}) rotate(-90)`);
321
+ return axis.categorySize;
322
+ }
323
+ /**
324
+ * Calculates the number of pixels by which to translate the label in the x-direction for the axis.
325
+ * The calculation uses the dimensions and margins of the plot, the location of the
326
+ * axis, and the font for the label.
327
+ * @param location The axis location (i.e. top, bottom, left, right)
328
+ * @param plotDimensions The dimensions of the plot
329
+ * @param margin The margins for the plot
330
+ * @param axesLabelFont The font for the axis label
331
+ * @return The number of pixels to translate the label in the x-direction
332
+ */
333
+ function ordinalLabelXTranslation(location, plotDimensions, margin, axesLabelFont) {
334
+ switch (location) {
335
+ case AxisLocation.Left:
336
+ case AxisLocation.Right:
337
+ return location === AxisLocation.Left ?
338
+ axesLabelFont.size :
339
+ margin.left + plotDimensions.width + margin.right - axesLabelFont.size;
340
+ case AxisLocation.Top:
341
+ case AxisLocation.Bottom:
342
+ return (plotDimensions.width + margin.left + margin.right) / 2;
343
+ }
344
+ }
345
+ /**
346
+ * Calculates the number of pixels by which to translate the label in the y-direction the axis.
347
+ * The calculation uses the dimensions and margins of the plot, the location of the
348
+ * axis, and the font for the label.
349
+ * @param location The axis location (i.e. top, bottom, left, right)
350
+ * @param plotDimensions The dimensions of the plot
351
+ * @param margin The margins for the plot
352
+ * @return The number of pixels to translate the label for the y-direction
353
+ */
354
+ function ordinalLabelYTranslation(location, plotDimensions, margin) {
355
+ switch (location) {
356
+ case AxisLocation.Left:
357
+ case AxisLocation.Right:
358
+ return (margin.top + margin.bottom + plotDimensions.height) / 2;
359
+ case AxisLocation.Top:
360
+ return 0;
361
+ case AxisLocation.Bottom:
362
+ return margin.top + margin.bottom + plotDimensions.height;
363
+ }
364
+ }
365
+ /*
366
+ continuous numeric axes
367
+ */
368
+ /**
369
+ * Adds a new x-axis to the SVG element at the specified location
370
+ * @param chartId The ID of the chart
371
+ * @param axisId The ID of the axis
372
+ * @param svg The SVG selection to which to add the axis
373
+ * @param plotDimensions The dimensions of the plot
374
+ * @param location The location of the axis
375
+ * @param scaleGenerator The higher-order function that returns the axis d3 "scale" function
376
+ * @param domain The axis range (start, end)
377
+ * @param axesLabelFont The font for the axis labels
378
+ * @param margin The plot margins for the border of main SVG group
379
+ * @param axisLabel The label for the axis
380
+ * @param setAxisRangeFor A callback used to set the axis range
381
+ * @return A {@link ContinuousNumericAxis} based on the arguments to this function
382
+ */
383
+ export function addContinuousNumericXAxis(chartId, axisId, svg, plotDimensions, location, scaleGenerator, domain, axesLabelFont, margin, axisLabel, setAxisRangeFor) {
384
+ const scale = scaleGenerator.domain(domain).range([0, plotDimensions.width]);
385
+ const selection = svg
386
+ .append('g')
387
+ .attr('transform', `translate(${margin.left}, ${yTranslation(location, plotDimensions, margin)})`);
388
+ svg
389
+ .append('text')
390
+ .attr('id', labelIdFor(chartId, location))
391
+ .style('text-anchor', 'middle')
392
+ // when the axis is at the top, want the label to hang from the top (y=0) of the plot
393
+ .style('dominant-baseline', location === AxisLocation.Top ? "hanging" : "baseline")
394
+ .style('font-size', axesLabelFont.size)
395
+ .style('fill', axesLabelFont.color)
396
+ .style('font-family', axesLabelFont.family)
397
+ .style('font-weight', axesLabelFont.weight)
398
+ .attr('transform', `translate(${margin.left + plotDimensions.width / 2}, ${continuousLabelYTranslation(location, plotDimensions, margin)})`)
399
+ .text(axisLabel);
400
+ const axis = {
401
+ axisId,
402
+ location,
403
+ selection,
404
+ scale,
405
+ generator: location === AxisLocation.Bottom ? d3.axisBottom(scale) : d3.axisTop(scale),
406
+ update: noop
407
+ };
408
+ return Object.assign(Object.assign({}, axis), { update: (domain, plotDimensions, margin) => {
409
+ updateLinearXAxis(domain, axisLabel, chartId, svg, axis, plotDimensions, margin, location);
410
+ setAxisRangeFor(axisId, domain);
411
+ } });
412
+ }
413
+ /**
414
+ * Updates the x-axis with the new domain and axis label
415
+ * @param domain The new (start, end) range of the axis
416
+ * @param label The new label for the axis
417
+ * @param chartId The ID of the chart
418
+ * @param svg The SVG selection of which the axis is a child node
419
+ * @param axis The x-axis
420
+ * @param plotDimensions The dimensions of the plot
421
+ * @param margin The plot margins for the border of main SVG group
422
+ * @param location The location of the axis (i.e. top, bottom, left, right)
423
+ */
424
+ function updateLinearXAxis(domain, label, chartId, svg, axis, plotDimensions, margin, location) {
425
+ axis.scale.domain(domain.asTuple()).range([0, plotDimensions.width]);
426
+ axis.selection
427
+ .attr('transform', `translate(${margin.left}, ${yTranslation(location, plotDimensions, margin)})`)
428
+ .call(axis.generator);
429
+ svg
430
+ .select(`#${labelIdFor(chartId, location)}`)
431
+ .attr('transform', `translate(${margin.left + plotDimensions.width / 2}, ${continuousLabelYTranslation(location, plotDimensions, margin)})`)
432
+ .text(label);
433
+ }
434
+ /**
435
+ * The number of pixels to translate the x-axis label to the right
436
+ * @param location The location of the x-axis
437
+ * @param plotDimensions The dimensions of the plot
438
+ * @param margin The plot margins for the border of main SVG group
439
+ * @return The number of pixels to translate the x-axis label to the right
440
+ */
441
+ function continuousLabelYTranslation(location, plotDimensions, margin) {
442
+ return location === AxisLocation.Bottom ? plotDimensions.height + margin.top + margin.bottom : 0;
443
+ }
444
+ /**
445
+ * Adds a new y-axis to the SVG element at the specified location
446
+ * @param chartId The ID of the chart
447
+ * @param axisId The ID of the axis
448
+ * @param svg The SVG selection to which to add the axis
449
+ * @param plotDimensions The dimensions of the plot
450
+ * @param location The location of the axis
451
+ * @param scaleGenerator The higher-order function that returns the axis d3 "scale" function
452
+ * @param domain The axis range (start, end)
453
+ * @param axesLabelFont The font for the axis labels
454
+ * @param margin The plot margins for the border of main SVG group
455
+ * @param axisLabel The label for the axis
456
+ * @param setAxisRangeFor A callback used to set the axis range
457
+ * @return A {@link ContinuousNumericAxis} based on the arguments to this function
458
+ */
459
+ export function addContinuousNumericYAxis(chartId, axisId, svg, plotDimensions, location, scaleGenerator, domain, axesLabelFont, margin, axisLabel, setAxisRangeFor) {
460
+ const scale = scaleGenerator
461
+ .domain(domain)
462
+ .range([Math.max(margin.bottom, plotDimensions.height), 0]);
463
+ const selection = svg
464
+ .append('g')
465
+ .attr('class', 'y-axis')
466
+ .attr('transform', `translate(${xTranslation(location, plotDimensions, margin)}, ${margin.top})`);
467
+ svg
468
+ .append('text')
469
+ .attr('id', labelIdFor(chartId, location))
470
+ .attr('text-anchor', 'start')
471
+ .attr('font-size', axesLabelFont.size)
472
+ .attr('fill', axesLabelFont.color)
473
+ .attr('font-family', axesLabelFont.family)
474
+ .attr('font-weight', axesLabelFont.weight)
475
+ .attr('transform', `translate(${continuousLabelXTranslation(location, plotDimensions, margin, axesLabelFont)}, ${margin.top + plotDimensions.height / 2}) rotate(-90)`)
476
+ .text(axisLabel);
477
+ const axis = {
478
+ axisId,
479
+ location,
480
+ selection,
481
+ scale,
482
+ generator: location === AxisLocation.Left ? d3.axisLeft(scale) : d3.axisRight(scale),
483
+ update: noop
484
+ };
485
+ return Object.assign(Object.assign({}, axis), { update: (domain, plotDimensions, margin) => {
486
+ updateLinearYAxis(domain, axisLabel, chartId, svg, axis, plotDimensions, margin, axesLabelFont, location);
487
+ setAxisRangeFor(axisId, domain);
488
+ } });
489
+ }
490
+ /**
491
+ * Updates the y-axis with the new domain and axis label
492
+ * @param domain The new (start, end) range of the axis
493
+ * @param label The new label for the axis
494
+ * @param chartId The ID of the chart
495
+ * @param svg The SVG selection of which the axis is a child node
496
+ * @param axis The y-axis
497
+ * @param plotDimensions The dimensions of the plot
498
+ * @param margin The plot margins for the border of main SVG group
499
+ * @param axesLabelFont The font for the axis label
500
+ * @param location The location of the axis (i.e. top, bottom, left, right)
501
+ */
502
+ function updateLinearYAxis(domain, label, chartId, svg, axis, plotDimensions, margin, axesLabelFont, location) {
503
+ axis.scale.domain(domain.asTuple()).range([Math.max(margin.bottom, plotDimensions.height), 0]);
504
+ axis.selection
505
+ .attr('transform', `translate(${xTranslation(location, plotDimensions, margin)}, ${margin.top})`)
506
+ .call(axis.generator);
507
+ svg
508
+ .select(`#${labelIdFor(chartId, location)}`)
509
+ .attr('transform', `translate(${continuousLabelXTranslation(location, plotDimensions, margin, axesLabelFont)}, ${margin.top + plotDimensions.height / 2}) rotate(-90)`)
510
+ .text(label);
511
+ }
512
+ /**
513
+ * The number of pixels to translate the y-axis label down
514
+ * @param location The location of the y-axis
515
+ * @param plotDimensions The dimensions of the plot
516
+ * @param margin The plot margins for the border of main SVG group
517
+ * @param axesLabelFont The font for the axis label
518
+ * @return The number of pixels to translate the y-axis label down
519
+ */
520
+ function continuousLabelXTranslation(location, plotDimensions, margin, axesLabelFont) {
521
+ return location === AxisLocation.Left ?
522
+ axesLabelFont.size :
523
+ margin.left + plotDimensions.width + margin.right - axesLabelFont.size;
524
+ }
525
+ /*
526
+ common axis functions
527
+ */
528
+ /**
529
+ * Calculates the number of pixels by which to translate the x-axis.
530
+ * @param location The axis location (i.e. top, bottom, left, right)
531
+ * @param plotDimensions The dimensions of the plot
532
+ * @param margin The margins for the plot
533
+ * @return The number of pixels to translate the x-axis
534
+ */
535
+ function xTranslation(location, plotDimensions, margin) {
536
+ return location === AxisLocation.Left ? margin.left : margin.left + plotDimensions.width;
537
+ }
538
+ /**
539
+ * The number of pixels to translate the x-axis to the right
540
+ * @param location The location of the x-axis
541
+ * @param plotDimensions The dimensions of the plot
542
+ * @param margin The plot margins for the border of main SVG group
543
+ * @return The number of pixels to translate the y-axis to the down
544
+ */
545
+ function yTranslation(location, plotDimensions, margin) {
546
+ return location === AxisLocation.Bottom ?
547
+ plotDimensions.height + margin.top :
548
+ margin.top;
549
+ }
550
+ /**
551
+ * Calculates a unique ID for the axis based on the location and chart ID
552
+ * @param chartId The unique ID of the chart
553
+ * @param location The axis location (i.e. top, bottom, left, right)
554
+ * @return A unique ID for the axis
555
+ */
556
+ export function labelIdFor(chartId, location) {
557
+ switch (location) {
558
+ case AxisLocation.Left:
559
+ case AxisLocation.Right:
560
+ return `stream-chart-y-axis-${location}-label-${chartId}`;
561
+ case AxisLocation.Top:
562
+ case AxisLocation.Bottom:
563
+ return `stream-chart-x-axis-${location}-label-${chartId}`;
564
+ }
565
+ }
566
+ // /**
567
+ // * todo this can be generalized to any continuous numeric axis, replace x with value
568
+ // * Called when the user uses the scroll wheel (or scroll gesture) to zoom in or out. Zooms in/out
569
+ // * at the location of the mouse when the scroll wheel or gesture was applied.
570
+ // * @param transform The d3 zoom transformation information
571
+ // * @param x The x-position of the mouse when the scroll wheel or gesture is used
572
+ // * @param axis The axis being zoomed
573
+ // * @param range The current range for the axis being zoomed
574
+ // * @return The updated range and the new zoom factor
575
+ // */
576
+ // // export function calculateZoomFor<AR extends BaseAxisRange>(
577
+ // export function calculateZoomFor(
578
+ // transform: ZoomTransform,
579
+ // x: number,
580
+ // axis: ContinuousNumericAxis,
581
+ // range: ContinuousAxisRange,
582
+ // ): ZoomResult<ContinuousAxisRange> {
583
+ // const time = axis.generator.scale<ScaleLinear<number, number>>().invert(x);
584
+ // return {
585
+ // range: range.scale(transform.k, time),
586
+ // zoomFactor: transform.k
587
+ // } as ZoomResult<ContinuousAxisRange>
588
+ // }
589
+ /**
590
+ * Called when the user uses the scroll wheel (or scroll gesture) to zoom in or out. Zooms in/out
591
+ * at the location of the mouse when the scroll wheel or gesture was applied, while ensure that
592
+ * the range (start, end) is contained within the constraint (min, max).
593
+ * @param transform The d3 zoom transformation information
594
+ * @param x The x-position of the mouse when the scroll wheel or gesture is used
595
+ * @param axis The axis being zoomed
596
+ * @param range The current range for the axis being zoomed
597
+ * @param constraint The minimum and maximum value the scaled range can have
598
+ * @return The updated range and the new zoom factor
599
+ */
600
+ export function calculateConstrainedZoomFor(transform, x, axis, range, constraint) {
601
+ const domainValue = axis.generator.scale().invert(x);
602
+ return {
603
+ range: range.constrainedScale(transform.k, domainValue, constraint),
604
+ zoomFactor: transform.k
605
+ };
606
+ }
607
+ /**
608
+ * Calculates the zoom for an ordinal axis.
609
+ * @param transform The d3 zoom transformation information
610
+ * @param x The x-position of the mouse when the scroll wheel or gesture is used
611
+ * @param range The current range for the axis being zoomed
612
+ * @param constraint The minimum and maximum value the scaled range can have
613
+ * @return A ZoomResult holding the updated range and the new zoom factor
614
+ */
615
+ export function calculateOrdinalConstrainedZoomFor(transform, x, range, constraint) {
616
+ const updatedRange = range.constrainedScale(transform.k, x, constraint);
617
+ const k = range.original.equals(updatedRange.original) ? 1 : transform.k;
618
+ return {
619
+ range: updatedRange,
620
+ zoomFactor: k
621
+ };
622
+ }
623
+ /*
624
+ panning
625
+ */
626
+ /**
627
+ * Adjusts the range and updates the plot when the plot is dragged to the left or right
628
+ * @param delta The amount that the plot is dragged
629
+ * @param axis The axis being zoomed
630
+ * @param range The current range for the axis being zoomed
631
+ * @param [constrainToOriginalRange=false] When set to `true` then the pan requires that the axis
632
+ * range remains a subset of the origin axis range; when `false` the pan allows and range
633
+ * @return The updated range
634
+ */
635
+ export function calculatePanFor(delta, axis, range, constrainToOriginalRange = false) {
636
+ const scale = axis.generator.scale();
637
+ const value = scale(range.current.start);
638
+ if (value !== undefined) {
639
+ const deltaValue = scale.invert(value + delta) - range.current.start;
640
+ const constraint = constrainToOriginalRange ?
641
+ range.original.asTuple() :
642
+ [-Infinity, Infinity];
643
+ return range.translate(-deltaValue, constraint);
644
+ }
645
+ return range;
646
+ }
647
+ export function calculateOrdinalPanFor(delta, range, plotDimensions, constrainToOriginalRange = false) {
648
+ const constraint = constrainToOriginalRange ?
649
+ range.original.asTuple() :
650
+ [-Infinity, Infinity];
651
+ // only allow panning if the plot dimensions (i.e. [0, width]) is in the current axis range
652
+ // todo deal with the fact that this could be a pan of the y-axis
653
+ if (range.current.start + delta > 0 || range.current.end + delta < plotDimensions.width) {
654
+ return range;
655
+ }
656
+ return range.translate(delta, constraint);
657
+ }
658
+ /*
659
+
660
+ */
661
+ /**
662
+ * Accepts the series, the assignment of the series to axes, and the current x-axes state, and
663
+ * returns an array of the distinct axis IDs that cover all the series in the plot.
664
+ *
665
+ * @param series The array of series
666
+ * @param axisAssignments A map association a series name with its axis assignments
667
+ * @param axesState The current axis state
668
+ * @return an array of the distinct axes that cover all the series in the plot
669
+ */
670
+ export function axesForSeriesGen(series, axisAssignments, axesState) {
671
+ return series.map(srs => srs.name)
672
+ // grab the x-axis assigned to the series, or use the default x-axis if not
673
+ // assignment has been made
674
+ .map(name => { var _a; return ((_a = axisAssignments.get(name)) === null || _a === void 0 ? void 0 : _a.xAxis) || axesState.axisDefaultId().getOrElse(""); })
675
+ // de-dup the array of axis IDs so that we don't end up applying the pan or zoom
676
+ // transformation more than once
677
+ .reduce((accum, axisId) => {
678
+ if (!accum.find(id => id === axisId)) {
679
+ accum.push(axisId);
680
+ }
681
+ return accum;
682
+ }, []);
683
+ }
684
+ /**
685
+ * Pans the axis range by the specified amount.
686
+ * @param delta The pan amount in the axis specified for the series
687
+ * @param axesForSeries The names of the axes of a dimension (x or y)
688
+ * @param axesState The state for the axes of a dimension
689
+ * @param ranges The current ranges for the axes of a dimension
690
+ * @param setAxisRange Function for setting the new time-range for a specific axis
691
+ * @param plotDimensions The current plot dimensions (width, height)
692
+ * @param margin The plot margin
693
+ * @param [constrainToOriginalRange=true] Optional argument, that when set to `true`, constrains the
694
+ * axis range to remain in the origin axis range; when `false` the axis range is unconstrained
695
+ */
696
+ function panAxes(delta, axesForSeries, axesState, ranges, setAxisRange, plotDimensions, margin, constrainToOriginalRange = true) {
697
+ axesForSeries.forEach(axisId => {
698
+ axesState.axisFor(axisId).ifPresent((axis) => {
699
+ const currentRange = ranges.get(axisId);
700
+ if (currentRange) {
701
+ // calculate the change in the axis-range based on the pixel change from the drag event
702
+ const range = calculatePanFor(delta, axis, currentRange, constrainToOriginalRange);
703
+ // update the time-range for the axis
704
+ ranges.set(axisId, range);
705
+ setAxisRange(axisId, range.current);
706
+ // update the axis' time-range
707
+ axis.update(range.current.copy(), plotDimensions, margin);
708
+ }
709
+ });
710
+ });
711
+ }
712
+ /**
713
+ * Pans the axis range by the specified amount.
714
+ * @param delta The pan amount in the axis specified for the series
715
+ * @param axesForSeries The names of the axes of a dimension (x or y)
716
+ * @param axesState The state for the axes of a dimension
717
+ * @param ranges The current ranges for the axes of a dimension
718
+ * @param setAxisRange Function for setting the new time-range for a specific axis
719
+ * @param plotDimensions The current plot dimensions (width, height)
720
+ * @param margin The plot margin
721
+ * @param [constrainToOriginalRange=false] Optional argument, that when set to `true`, constrains the
722
+ * axis range to remain in the origin axis range; when `false` the axis range is unconstrained
723
+ */
724
+ function ordinalPanAxes(delta, axesForSeries, axesState, ranges, setAxisRange, plotDimensions, margin, constrainToOriginalRange = false) {
725
+ axesForSeries.forEach(axisId => {
726
+ axesState.axisFor(axisId).ifPresent(axis => {
727
+ const currentRange = ranges.get(axisId);
728
+ if (currentRange && axis) {
729
+ // calculate the change in the axis-range based on the pixel change from the drag event
730
+ const range = calculateOrdinalPanFor(delta, currentRange, plotDimensions, constrainToOriginalRange);
731
+ // update the time-range for the axis
732
+ ranges.set(axisId, range);
733
+ setAxisRange(axisId, range.current);
734
+ // update the axis' time-range
735
+ axis.update(range.current, range.original, plotDimensions, margin);
736
+ }
737
+ });
738
+ });
739
+ }
740
+ /**
741
+ * Higher-order function that generates a handler for pan events, given the distinct series IDs that cover all
742
+ * the axes in the chart, the margin, axis-range update function, and the current state of the x-axes. This
743
+ * function returns a handler function. And this handler function adjusts the time-range when the plot is dragged
744
+ * to the left or right. After calling the handler function, the plot needs to be updated as well, and this is
745
+ * left for the caller.
746
+ *
747
+ * Please note that the function generated by this function has side effects -- it updates the axes ranges.
748
+ *
749
+ * @param axesForSeries The distinct axes that cover all the series
750
+ * @param margin The plot margin
751
+ * @param setAxisRangeFor Function for setting the new axis-range for a specific axis
752
+ * @param axesState The current state of the x-axes or y-axes
753
+ * @param [constrainToOriginalRange=false] Optional argument, that when set to `true`, constrains the
754
+ * axis range to remain in the origin axis range; when `false` the axis range is unconstrained
755
+ * @return A handler function for pan events
756
+ */
757
+ export function panHandler(axesForSeries, margin, setAxisRangeFor, axesState, constrainToOriginalRange = false) {
758
+ /**
759
+ * Adjusts the time-range and updates the plot when the plot is dragged to the left or right
760
+ * @param deltaX The amount that the plot is dragged
761
+ * @param plotDimensions The dimensions of the plot
762
+ * @param series An array of series names
763
+ * @param ranges A map holding the axis ID and its associated time range
764
+ */
765
+ return (delta, plotDimensions, ranges) => {
766
+ // return (delta: number, plotDimensions: Dimensions, series: Array<string>, ranges: Map<string, ContinuousAxisRange>) => {
767
+ // run through the axis IDs, adjust their domain, and update the time-range set for that axis
768
+ panAxes(delta, axesForSeries, axesState, ranges, setAxisRangeFor, plotDimensions, margin, constrainToOriginalRange);
769
+ // hey, don't forget to update the plot with the new time-ranges in the code calling this... :)
770
+ };
771
+ }
772
+ /**
773
+ * Higher-order function that generates a handler for pan events, given the distinct series IDs that cover all
774
+ * the axes in the chart, the margin, axis-range update function, and the current state of the x-axes. This
775
+ * function returns a handler function. And this handler function adjusts the time-range when the plot is dragged
776
+ * to the left or right. After calling the handler function, the plot needs to be updated as well, and this is
777
+ * left for the caller.
778
+ *
779
+ * Please note that the function generated by this function has side effects -- it updates the axes ranges.
780
+ *
781
+ * @param axesForSeries The distinct axes that cover all the series
782
+ * @param margin The plot margin
783
+ * @param setAxisRangeFor Function for setting the new axis-range for a specific axis
784
+ * @param axesState The current state of the x-axes or y-axes
785
+ * @param [constrainToOriginalRange=false] Optional argument, that when set to `true`, constrains the
786
+ * axis range to remain in the origin axis range; when `false` the axis range is unconstrained
787
+ * @return A handler function for pan events
788
+ */
789
+ export function ordinalPanHandler(axesForSeries, margin, setAxisRangeFor, axesState, constrainToOriginalRange = false) {
790
+ /**
791
+ * Adjusts the time-range and updates the plot when the plot is dragged to the left or right
792
+ * @param deltaX The amount that the plot is dragged
793
+ * @param plotDimensions The dimensions of the plot
794
+ * @param series An array of series names
795
+ * @param ranges A map holding the axis ID and its associated time range
796
+ */
797
+ return (delta, plotDimensions, series, ranges) => {
798
+ // run through the axis IDs, adjust their domain, and update the time-range set for that axis
799
+ ordinalPanAxes(delta, axesForSeries, axesState, ranges, setAxisRangeFor, plotDimensions, margin, constrainToOriginalRange);
800
+ // hey, don't forget to update the plot with the new ranges in the code calling this... :)
801
+ };
802
+ }
803
+ /**
804
+ * Higher-order function that generates a handler for pan events, given the distinct series IDs that cover all
805
+ * the axes in the chart, the margin, time-range update function, and the current state of the x-axes. This
806
+ * function returns a handler function. And this handler function adjusts the time-range when the plot is dragged
807
+ * to the left or right. After calling the handler function, the plot needs to be updated as well, and this is
808
+ * left for the caller.
809
+ *
810
+ * Please note that the function generated by this function has side effects -- it updates the axes ranges.
811
+ *
812
+ * @param xAxesForSeries The distinct x-axes that cover all the series
813
+ * @param yAxesForSeries The distinct y-axes that cover all the series
814
+ * @param margin The plot margin
815
+ * @param setAxisRange Function for setting the new time-range for a specific axis
816
+ * @param xAxesState The current state of the x-axes
817
+ * @param yAxesState The current state of the y-axes
818
+ * @param [constrainToOriginalRange=true] Optional argument, that when set to `true`, constrains the
819
+ * axis range to remain in the origin axis range; when `false` the axis range is unconstrained
820
+ * @return A handler function for pan events
821
+ */
822
+ export function panHandler2D(xAxesForSeries, yAxesForSeries, margin, setAxisRange, xAxesState, yAxesState, constrainToOriginalRange = true) {
823
+ /**
824
+ * Adjusts the time-range and updates the plot when the plot is dragged to the left or right
825
+ * @param deltaX The amount that the plot is dragged
826
+ * @param plotDimensions The dimensions of the plot
827
+ * @param series An array of series names
828
+ * @param ranges A map holding the axis ID and its associated time range
829
+ */
830
+ return (deltaX, deltaY, plotDimensions, series, xRanges, yRanges) => {
831
+ // run through the x- and y-axes and update them by delta, within the original bounds
832
+ panAxes(deltaX, xAxesForSeries, xAxesState, xRanges, setAxisRange, plotDimensions, margin, constrainToOriginalRange);
833
+ panAxes(deltaY, yAxesForSeries, yAxesState, yRanges, setAxisRange, plotDimensions, margin, constrainToOriginalRange);
834
+ // hey, don't forget to update the plot with the new time-ranges in the code calling this... :)
835
+ };
836
+ }
837
+ /**
838
+ * Calculates the zoom for the specified axis and updates the axis and the axis ranges
839
+ * @param value The x- or y-coordinate of the mouse
840
+ * @param axisId
841
+ * @param margin The plot margin
842
+ * @param setRangeFor Function for setting the new time-range for a specific axis * @param scaleExtent The smallest and largest scale factors allowed
843
+ * @param axesState
844
+ * @param ranges A map associating axis IDs with axis ranges
845
+ * @param scaleExtent The smallest and largest scale factors allowed
846
+ * @param transform The d3 zoom transformation information
847
+ * @param plotDimensions The dimensions of the plot
848
+ */
849
+ function calcZoomAndUpdate(value, axisId, margin, setRangeFor, axesState, ranges, scaleExtent, transform, plotDimensions) {
850
+ const [, zoomMax] = scaleExtent;
851
+ axesState.axisFor(axisId).ifPresent(axis => {
852
+ const range = ranges.get(axisId);
853
+ if (range && axis) {
854
+ // calculate the constraint for the zoom
855
+ const constraint = isFinite(zoomMax) ?
856
+ [range.original.start * zoomMax, range.original.end * zoomMax] :
857
+ [0, Infinity];
858
+ const zoom = calculateConstrainedZoomFor(transform, value, axis, range, constraint);
859
+ // update the axis range
860
+ ranges.set(axisId, zoom.range);
861
+ setRangeFor(axisId, zoom.range.current);
862
+ // update the axis' range
863
+ axis.update(zoom.range.current, plotDimensions, margin);
864
+ }
865
+ });
866
+ }
867
+ function calcOrdinalZoomAndUpdate(value, axisId, margin, setRangeFor, setOriginalRangeFor, axesState, ranges, scaleExtent, transform, plotDimensions) {
868
+ const [, zoomMax] = scaleExtent;
869
+ axesState.axisFor(axisId).ifPresent(axis => {
870
+ const range = ranges.get(axisId);
871
+ if (range && axis) {
872
+ // calculate the constraint for the zoom
873
+ // const [originalStart, originalEnd] = range.original
874
+ const constraint = isFinite(zoomMax) ?
875
+ [range.original.start * zoomMax, range.original.end * zoomMax] :
876
+ [range.original.start, range.original.end];
877
+ const zoom = calculateOrdinalConstrainedZoomFor(transform, value, range, constraint);
878
+ // update the axis range
879
+ ranges.set(axisId, zoom.range);
880
+ setRangeFor(axisId, zoom.range.current);
881
+ const origRange = AxisInterval.from(0, plotDimensions.width);
882
+ setOriginalRangeFor(axisId, origRange);
883
+ // update the axis' range
884
+ axis.update(zoom.range.current, origRange, plotDimensions, margin);
885
+ }
886
+ });
887
+ }
888
+ /**
889
+ * Higher-order function that generates a handler for zoom events, given the distinct series IDs that cover all
890
+ * the axes in the chart, the margin, range update function, and the current state of the x- or y-axes. This
891
+ * function returns a handler function. And this handler function adjusts the range when the plot is zoomed.
892
+ * After calling the handler function, the plot needs to be updated as well, and this is left for the caller.
893
+ *
894
+ * Please note that the function generated by this function has side effects -- it updates the axes ranges.
895
+ *
896
+ * @param axesForSeries The distinct axes that cover all the series
897
+ * @param margin The plot margin
898
+ * @param setRangeFor Function for setting the new time-range for a specific axis
899
+ * @param axesState The current state of the x- or y-axes
900
+ * @param scaleExtent The minimum and maximum allowed scale factors
901
+ * @return A handler function for pan events
902
+ */
903
+ export function continuousAxisZoomHandler(axesForSeries, margin, setRangeFor, axesState, scaleExtent = [0, Infinity]) {
904
+ /**
905
+ * Called when the user uses the scroll wheel (or scroll gesture) to zoom in or out. Zooms in/out
906
+ * at the location of the mouse when the scroll wheel or gesture was applied.
907
+ * @param transform The d3 zoom transformation information
908
+ * @param x The x-position of the mouse when the scroll wheel or gesture is used
909
+ * @param plotDimensions The dimensions of the plot
910
+ * @param ranges A map holding the axis ID and its associated time-range
911
+ */
912
+ return (transform, x, plotDimensions, ranges) => {
913
+ // run through the axis IDs, adjust their domain, and update the time-range set for that axis
914
+ axesForSeries.forEach(axisId => calcZoomAndUpdate(x, axisId, margin, setRangeFor, axesState, ranges, scaleExtent, transform, plotDimensions));
915
+ // hey, don't forget to update the plot with the new time-ranges in the code calling this... :)
916
+ };
917
+ }
918
+ /**
919
+ * Higher-order function that generates a handler for zoom events, given the distinct series IDs that cover all
920
+ * the axes in the chart, the margin, range update function, and the current state of the x- or y-axes. This
921
+ * function returns a handler function. And this handler function adjusts the range when the plot is zoomed.
922
+ * After calling the handler function, the plot needs to be updated as well, and this is left for the caller.
923
+ *
924
+ * Please note that the function generated by this function has side effects -- it updates the axes ranges.
925
+ *
926
+ * @param axesForSeries The distinct axes that cover all the series
927
+ * @param margin The plot margin
928
+ * @param setRangeFor Function for setting the new time-range for a specific axis
929
+ * @param setOriginalRangeFor Function for setting the new original range for a specific axis
930
+ * @param axesState The current state of the x- or y-axes
931
+ * @param scaleExtent The minimum and maximum allowed scale factors
932
+ * @return A handler function for pan events
933
+ */
934
+ export function ordinalAxisZoomHandler(axesForSeries, margin, setRangeFor, setOriginalRangeFor, axesState, scaleExtent = [0, Infinity]) {
935
+ /**
936
+ * Called when the user uses the scroll wheel (or scroll gesture) to zoom in or out. Zooms in/out
937
+ * at the location of the mouse when the scroll wheel or gesture was applied.
938
+ * @param transform The d3 zoom transformation information
939
+ * @param x The x-position of the mouse when the scroll wheel or gesture is used
940
+ * @param plotDimensions The dimensions of the plot
941
+ * @param ranges A map holding the axis ID and its associated time-range
942
+ */
943
+ return (transform, x, plotDimensions, ranges) => {
944
+ // run through the axis IDs, adjust their domain, and update the time-range set for that axis
945
+ axesForSeries.forEach(axisId => calcOrdinalZoomAndUpdate(x, axisId, margin, setRangeFor, setOriginalRangeFor, axesState, ranges, scaleExtent, transform, plotDimensions));
946
+ // hey, don't forget to update the plot with the new time-ranges in the code calling this... :)
947
+ };
948
+ }
949
+ /**
950
+ * Higher-order function that generates a handler for zoom events, given the distinct series IDs that cover all
951
+ * the axes in the chart, the margin, range update function, and the current state of the x- or y-axes. This
952
+ * function returns a handler function. And this handler function adjusts the time-range when the plot is zoomed.
953
+ * After calling the handler function, the plot needs to be updated as well, and this is left for the caller.
954
+ *
955
+ * Please note that the function generated by this function has side effects -- it updates the axes ranges.
956
+ *
957
+ * @param xAxesForSeries The distinct x-axes that cover all the series
958
+ * @param yAxesForSeries The distinct y-axes that cover all the series
959
+ * @param margin The plot margin
960
+ * @param setRangeFor Function for setting the new time-range for a specific axis
961
+ * @param xAxesState The current state of the x-axes
962
+ * @param yAxesState The current state of the y-axes
963
+ * @param scaleExtent The smallest and largest scale factors allowed
964
+ * @return A handler function for pan events
965
+ */
966
+ export function axesZoomHandler(xAxesForSeries, yAxesForSeries, margin, setRangeFor, xAxesState, yAxesState, scaleExtent) {
967
+ /**
968
+ * Called when the user uses the scroll wheel (or scroll gesture) to zoom in or out. Zooms in/out
969
+ * at the location of the mouse when the scroll wheel or gesture was applied.
970
+ * @param transform The d3 zoom transformation information
971
+ * @param mousePosistion The position of the mouse when the scroll wheel or gesture is used
972
+ * @param plotDimensions The dimensions of the plot
973
+ * @param ranges A map holding the axis ID and its associated time-range
974
+ */
975
+ return (transform, mousePosition, plotDimensions, xRanges, yRanges) => {
976
+ // run through the axis IDs, adjust their domain, and update the time-range set for that axis
977
+ const [x, y] = mousePosition;
978
+ xAxesForSeries.forEach(id => calcZoomAndUpdate(x, id, margin, setRangeFor, xAxesState, xRanges, scaleExtent, transform, plotDimensions));
979
+ yAxesForSeries.forEach(id => calcZoomAndUpdate(y, id, margin, setRangeFor, yAxesState, yRanges, scaleExtent, transform, plotDimensions));
980
+ // hey, don't forget to update the plot with the new time-ranges in the code calling this... :)
981
+ };
982
+ }
983
+ /**
984
+ * Calculates the axis-ranges for each of the continuous numeric axes in the map
985
+ * @param axes The map containing the axes and their associated IDs
986
+ * @return a map associating the axis IDs to their continuous axis-range
987
+ */
988
+ export function continuousAxisRanges(axes) {
989
+ return continuousRange(axes);
990
+ }
991
+ /**
992
+ * Calculates the axis-ranges for each of the ordinal axes in the map
993
+ * @param axes The map containing the axes and their associated IDs
994
+ * @param originalRange The original range of the axis
995
+ * @return a map associating the axis IDs to their ordinal axis-range
996
+ */
997
+ export function ordinalAxisRanges(axes, originalRange) {
998
+ return ordinalRange(axes, originalRange);
999
+ }
1000
+ /**
1001
+ * Calculates the axis interval (start, end) for each of the axis
1002
+ * @param axes The axes representing the time
1003
+ * @return A map associating each axis with a (start, end) interval
1004
+ */
1005
+ export function continuousAxisIntervals(axes) {
1006
+ return new Map(Array.from(axes.entries())
1007
+ .map(([id, axis]) => {
1008
+ const [start, end] = axis.scale.domain();
1009
+ return [id, AxisInterval.from(start, end)];
1010
+ }));
1011
+ }
1012
+ /**
1013
+ * Calculates the axis interval (start, end) for each of the axis
1014
+ * @param axes The axes representing the time
1015
+ * @return A map associating each axis with a (start, end) interval
1016
+ */
1017
+ export function ordinalAxisIntervals(axes) {
1018
+ return new Map(Array.from(axes.entries())
1019
+ .map(([id, axis]) => {
1020
+ const [start, end] = axis.scale.range();
1021
+ return [id, { interval: AxisInterval.from(start, end), categories: axis.scale.domain() }];
1022
+ }));
1023
+ }
1024
+ /**
1025
+ * Returns the bounds on the specified continuous numeric axes
1026
+ * @param axes A map associating an axis ID with a {@link ContinuousNumericAxis}
1027
+ * @return A map associating each specified axis ID with the interval covered (bounds) by the axis
1028
+ */
1029
+ export function continuousRange(axes) {
1030
+ return new Map(Array.from(axes.entries())
1031
+ .map(([id, axis]) => {
1032
+ const [start, end] = axis.scale.domain();
1033
+ return [id, ContinuousAxisRange.from(start, end)];
1034
+ }));
1035
+ }
1036
+ /**
1037
+ * Returns the bounds on the specified continuous numeric axes
1038
+ * @param axes A map associating an axis ID with a {@link OrdinalStringAxis}
1039
+ * @param originalRange The original range of the axis
1040
+ * @return A map associating each specified axis ID with the interval covered (bounds) by the axis
1041
+ */
1042
+ export function ordinalRange(axes, originalRange) {
1043
+ return new Map(Array.from(axes.entries())
1044
+ .map(([id, _]) => [id, OrdinalAxisRange.from(originalRange.start, originalRange.end)]));
1045
+ }
1046
+ //# sourceMappingURL=axes.js.map