@fluentui/react-charts 1.2.0 → 9.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (364) hide show
  1. package/CHANGELOG.md +177 -15
  2. package/LICENSE +11 -17
  3. package/README.md +174 -23
  4. package/dist/index.d.ts +2143 -0
  5. package/lib/CartesianChart.js +1 -0
  6. package/lib/CartesianChart.js.map +1 -0
  7. package/lib/DeclarativeChart.js +1 -0
  8. package/lib/DeclarativeChart.js.map +1 -0
  9. package/lib/DonutChart.js +1 -0
  10. package/lib/DonutChart.js.map +1 -0
  11. package/lib/HorizontalBarChart.js +1 -0
  12. package/lib/HorizontalBarChart.js.map +1 -0
  13. package/lib/Legends.js +1 -0
  14. package/lib/Legends.js.map +1 -0
  15. package/lib/LineChart.js +1 -0
  16. package/lib/LineChart.js.map +1 -0
  17. package/lib/Popover.js +1 -0
  18. package/lib/Popover.js.map +1 -0
  19. package/lib/ResponsiveContainer.js +1 -0
  20. package/lib/ResponsiveContainer.js.map +1 -0
  21. package/lib/Sparkline.js +1 -0
  22. package/lib/Sparkline.js.map +1 -0
  23. package/lib/VerticalBarChart.js +1 -0
  24. package/lib/VerticalBarChart.js.map +1 -0
  25. package/lib/components/CommonComponents/CartesianChart.js +462 -0
  26. package/lib/components/CommonComponents/CartesianChart.js.map +1 -0
  27. package/lib/components/CommonComponents/CartesianChart.types.js +1 -0
  28. package/lib/components/CommonComponents/CartesianChart.types.js.map +1 -0
  29. package/lib/components/CommonComponents/ChartPopover.js +187 -0
  30. package/lib/components/CommonComponents/ChartPopover.js.map +1 -0
  31. package/lib/components/CommonComponents/ChartPopover.types.js +1 -0
  32. package/lib/components/CommonComponents/ChartPopover.types.js.map +1 -0
  33. package/lib/components/CommonComponents/index.js +4 -0
  34. package/lib/components/CommonComponents/index.js.map +1 -0
  35. package/lib/components/CommonComponents/useCartesianChartStyles.styles.js +229 -0
  36. package/lib/components/CommonComponents/useCartesianChartStyles.styles.js.map +1 -0
  37. package/lib/components/CommonComponents/useChartPopoverStyles.styles.js +178 -0
  38. package/lib/components/CommonComponents/useChartPopoverStyles.styles.js.map +1 -0
  39. package/lib/components/DeclarativeChart/DeclarativeChart.js +150 -0
  40. package/lib/components/DeclarativeChart/DeclarativeChart.js.map +1 -0
  41. package/lib/components/DeclarativeChart/PlotlySchema.js +7 -0
  42. package/lib/components/DeclarativeChart/PlotlySchema.js.map +1 -0
  43. package/lib/components/DeclarativeChart/PlotlySchemaAdapter.js +400 -0
  44. package/lib/components/DeclarativeChart/PlotlySchemaAdapter.js.map +1 -0
  45. package/lib/components/DeclarativeChart/imageExporter.js +221 -0
  46. package/lib/components/DeclarativeChart/imageExporter.js.map +1 -0
  47. package/lib/components/DeclarativeChart/index.js +1 -0
  48. package/lib/components/DeclarativeChart/index.js.map +1 -0
  49. package/lib/components/DonutChart/Arc/Arc.js +110 -0
  50. package/lib/components/DonutChart/Arc/Arc.js.map +1 -0
  51. package/lib/components/DonutChart/Arc/Arc.types.js +1 -0
  52. package/lib/components/DonutChart/Arc/Arc.types.js.map +1 -0
  53. package/lib/components/DonutChart/Arc/index.js +2 -0
  54. package/lib/components/DonutChart/Arc/index.js.map +1 -0
  55. package/lib/components/DonutChart/Arc/useArcStyles.styles.js +54 -0
  56. package/lib/components/DonutChart/Arc/useArcStyles.styles.js.map +1 -0
  57. package/lib/components/DonutChart/DonutChart.js +291 -0
  58. package/lib/components/DonutChart/DonutChart.js.map +1 -0
  59. package/lib/components/DonutChart/DonutChart.types.js +1 -0
  60. package/lib/components/DonutChart/DonutChart.types.js.map +1 -0
  61. package/lib/components/DonutChart/Pie/Pie.js +72 -0
  62. package/lib/components/DonutChart/Pie/Pie.js.map +1 -0
  63. package/lib/components/DonutChart/Pie/Pie.types.js +1 -0
  64. package/lib/components/DonutChart/Pie/Pie.types.js.map +1 -0
  65. package/lib/components/DonutChart/Pie/index.js +2 -0
  66. package/lib/components/DonutChart/Pie/index.js.map +1 -0
  67. package/lib/components/DonutChart/Pie/usePieStyles.styles.js +44 -0
  68. package/lib/components/DonutChart/Pie/usePieStyles.styles.js.map +1 -0
  69. package/lib/components/DonutChart/index.js +3 -0
  70. package/lib/components/DonutChart/index.js.map +1 -0
  71. package/lib/components/DonutChart/useDonutChartStyles.styles.js +58 -0
  72. package/lib/components/DonutChart/useDonutChartStyles.styles.js.map +1 -0
  73. package/lib/components/HorizontalBarChart/HorizontalBarChart.js +402 -0
  74. package/lib/components/HorizontalBarChart/HorizontalBarChart.js.map +1 -0
  75. package/lib/components/HorizontalBarChart/HorizontalBarChart.types.js +6 -0
  76. package/lib/components/HorizontalBarChart/HorizontalBarChart.types.js.map +1 -0
  77. package/lib/components/HorizontalBarChart/index.js +3 -0
  78. package/lib/components/HorizontalBarChart/index.js.map +1 -0
  79. package/lib/components/HorizontalBarChart/useHorizontalBarChartStyles.styles.js +163 -0
  80. package/lib/components/HorizontalBarChart/useHorizontalBarChartStyles.styles.js.map +1 -0
  81. package/lib/components/Legends/Legends.js +302 -0
  82. package/lib/components/Legends/Legends.js.map +1 -0
  83. package/lib/components/Legends/Legends.types.js +1 -0
  84. package/lib/components/Legends/Legends.types.js.map +1 -0
  85. package/lib/components/Legends/OverflowMenu.js +25 -0
  86. package/lib/components/Legends/OverflowMenu.js.map +1 -0
  87. package/lib/components/Legends/index.js +3 -0
  88. package/lib/components/Legends/index.js.map +1 -0
  89. package/lib/components/Legends/shape.js +35 -0
  90. package/lib/components/Legends/shape.js.map +1 -0
  91. package/lib/components/Legends/useLegendsStyles.styles.js +147 -0
  92. package/lib/components/Legends/useLegendsStyles.styles.js.map +1 -0
  93. package/lib/components/LineChart/LineChart.js +1026 -0
  94. package/lib/components/LineChart/LineChart.js.map +1 -0
  95. package/lib/components/LineChart/LineChart.types.js +3 -0
  96. package/lib/components/LineChart/LineChart.types.js.map +1 -0
  97. package/lib/components/LineChart/eventAnnotation/EventAnnotation.js +119 -0
  98. package/lib/components/LineChart/eventAnnotation/EventAnnotation.js.map +1 -0
  99. package/lib/components/LineChart/eventAnnotation/LabelLink.js +57 -0
  100. package/lib/components/LineChart/eventAnnotation/LabelLink.js.map +1 -0
  101. package/lib/components/LineChart/eventAnnotation/Textbox.js +40 -0
  102. package/lib/components/LineChart/eventAnnotation/Textbox.js.map +1 -0
  103. package/lib/components/LineChart/index.js +4 -0
  104. package/lib/components/LineChart/index.js.map +1 -0
  105. package/lib/components/LineChart/useLineChartStyles.styles.js +65 -0
  106. package/lib/components/LineChart/useLineChartStyles.styles.js.map +1 -0
  107. package/lib/components/ResponsiveContainer/ResponsiveContainer.js +65 -0
  108. package/lib/components/ResponsiveContainer/ResponsiveContainer.js.map +1 -0
  109. package/lib/components/ResponsiveContainer/ResponsiveContainer.types.js +1 -0
  110. package/lib/components/ResponsiveContainer/ResponsiveContainer.types.js.map +1 -0
  111. package/lib/components/ResponsiveContainer/index.js +1 -0
  112. package/lib/components/ResponsiveContainer/index.js.map +1 -0
  113. package/lib/components/ResponsiveContainer/useResponsiveContainerStyles.styles.js +23 -0
  114. package/lib/components/ResponsiveContainer/useResponsiveContainerStyles.styles.js.map +1 -0
  115. package/lib/components/Sparkline/Sparkline.js +119 -0
  116. package/lib/components/Sparkline/Sparkline.js.map +1 -0
  117. package/lib/components/Sparkline/Sparkline.types.js +4 -0
  118. package/lib/components/Sparkline/Sparkline.types.js.map +1 -0
  119. package/lib/components/Sparkline/index.js +3 -0
  120. package/lib/components/Sparkline/index.js.map +1 -0
  121. package/lib/components/Sparkline/useSparklineStyles.styles.js +49 -0
  122. package/lib/components/Sparkline/useSparklineStyles.styles.js.map +1 -0
  123. package/lib/components/VerticalBarChart/VerticalBarChart.js +849 -0
  124. package/lib/components/VerticalBarChart/VerticalBarChart.js.map +1 -0
  125. package/lib/components/VerticalBarChart/VerticalBarChart.types.js +4 -0
  126. package/lib/components/VerticalBarChart/VerticalBarChart.types.js.map +1 -0
  127. package/lib/components/VerticalBarChart/index.js +3 -0
  128. package/lib/components/VerticalBarChart/index.js.map +1 -0
  129. package/lib/components/VerticalBarChart/useVerticalBarChartStyles.styles.js +74 -0
  130. package/lib/components/VerticalBarChart/useVerticalBarChartStyles.styles.js.map +1 -0
  131. package/lib/index.js +12 -8
  132. package/lib/index.js.map +1 -1
  133. package/lib/types/DataPoint.js +3 -0
  134. package/lib/types/DataPoint.js.map +1 -0
  135. package/lib/types/EventAnnotation.js +1 -0
  136. package/lib/types/EventAnnotation.js.map +1 -0
  137. package/lib/types/LegendDataItem.js +1 -0
  138. package/lib/types/LegendDataItem.js.map +1 -0
  139. package/lib/types/index.js +2 -2
  140. package/lib/types/index.js.map +1 -1
  141. package/lib/utilities/FocusableTooltipText.js +65 -0
  142. package/lib/utilities/FocusableTooltipText.js.map +1 -0
  143. package/lib/utilities/KeyCodes.js +8 -0
  144. package/lib/utilities/KeyCodes.js.map +1 -0
  145. package/lib/utilities/SVGTooltipText.js +138 -0
  146. package/lib/utilities/SVGTooltipText.js.map +1 -0
  147. package/lib/utilities/async-utils.js +380 -0
  148. package/lib/utilities/async-utils.js.map +1 -0
  149. package/lib/utilities/colors.js +249 -0
  150. package/lib/utilities/colors.js.map +1 -0
  151. package/lib/utilities/getWindow.js +25 -0
  152. package/lib/utilities/getWindow.js.map +1 -0
  153. package/lib/utilities/index.js +3 -0
  154. package/lib/utilities/index.js.map +1 -0
  155. package/lib/utilities/locale-util.js +15 -0
  156. package/lib/utilities/locale-util.js.map +1 -0
  157. package/lib/utilities/overflow-utils.js +27 -0
  158. package/lib/utilities/overflow-utils.js.map +1 -0
  159. package/lib/utilities/test-data.js +276 -0
  160. package/lib/utilities/test-data.js.map +1 -0
  161. package/lib/utilities/utilities.js +1215 -0
  162. package/lib/utilities/utilities.js.map +1 -0
  163. package/lib/utilities/vbc-utils.js +27 -0
  164. package/lib/utilities/vbc-utils.js.map +1 -0
  165. package/lib-commonjs/CartesianChart.js +6 -0
  166. package/lib-commonjs/CartesianChart.js.map +1 -0
  167. package/lib-commonjs/DeclarativeChart.js +6 -0
  168. package/lib-commonjs/DeclarativeChart.js.map +1 -0
  169. package/lib-commonjs/DonutChart.js +6 -0
  170. package/lib-commonjs/DonutChart.js.map +1 -0
  171. package/lib-commonjs/HorizontalBarChart.js +6 -0
  172. package/lib-commonjs/HorizontalBarChart.js.map +1 -0
  173. package/lib-commonjs/Legends.js +6 -0
  174. package/lib-commonjs/Legends.js.map +1 -0
  175. package/lib-commonjs/LineChart.js +6 -0
  176. package/lib-commonjs/LineChart.js.map +1 -0
  177. package/lib-commonjs/Popover.js +6 -0
  178. package/lib-commonjs/Popover.js.map +1 -0
  179. package/lib-commonjs/ResponsiveContainer.js +6 -0
  180. package/lib-commonjs/ResponsiveContainer.js.map +1 -0
  181. package/lib-commonjs/Sparkline.js +6 -0
  182. package/lib-commonjs/Sparkline.js.map +1 -0
  183. package/lib-commonjs/VerticalBarChart.js +6 -0
  184. package/lib-commonjs/VerticalBarChart.js.map +1 -0
  185. package/lib-commonjs/components/CommonComponents/CartesianChart.js +469 -0
  186. package/lib-commonjs/components/CommonComponents/CartesianChart.js.map +1 -0
  187. package/lib-commonjs/components/CommonComponents/CartesianChart.types.js +6 -0
  188. package/lib-commonjs/components/CommonComponents/CartesianChart.types.js.map +1 -0
  189. package/lib-commonjs/components/CommonComponents/ChartPopover.js +197 -0
  190. package/lib-commonjs/components/CommonComponents/ChartPopover.js.map +1 -0
  191. package/lib-commonjs/components/CommonComponents/ChartPopover.types.js +4 -0
  192. package/lib-commonjs/components/CommonComponents/ChartPopover.types.js.map +1 -0
  193. package/lib-commonjs/components/CommonComponents/index.js +9 -0
  194. package/lib-commonjs/components/CommonComponents/index.js.map +1 -0
  195. package/lib-commonjs/components/CommonComponents/useCartesianChartStyles.styles.js +356 -0
  196. package/lib-commonjs/components/CommonComponents/useCartesianChartStyles.styles.js.map +1 -0
  197. package/lib-commonjs/components/CommonComponents/useChartPopoverStyles.styles.js +261 -0
  198. package/lib-commonjs/components/CommonComponents/useChartPopoverStyles.styles.js.map +1 -0
  199. package/lib-commonjs/components/DeclarativeChart/DeclarativeChart.js +158 -0
  200. package/lib-commonjs/components/DeclarativeChart/DeclarativeChart.js.map +1 -0
  201. package/lib-commonjs/components/DeclarativeChart/PlotlySchema.js +10 -0
  202. package/lib-commonjs/components/DeclarativeChart/PlotlySchema.js.map +1 -0
  203. package/lib-commonjs/components/DeclarativeChart/PlotlySchemaAdapter.js +445 -0
  204. package/lib-commonjs/components/DeclarativeChart/PlotlySchemaAdapter.js.map +1 -0
  205. package/lib-commonjs/components/DeclarativeChart/imageExporter.js +231 -0
  206. package/lib-commonjs/components/DeclarativeChart/imageExporter.js.map +1 -0
  207. package/lib-commonjs/components/DeclarativeChart/index.js +6 -0
  208. package/lib-commonjs/components/DeclarativeChart/index.js.map +1 -0
  209. package/lib-commonjs/components/DonutChart/Arc/Arc.js +117 -0
  210. package/lib-commonjs/components/DonutChart/Arc/Arc.js.map +1 -0
  211. package/lib-commonjs/components/DonutChart/Arc/Arc.types.js +4 -0
  212. package/lib-commonjs/components/DonutChart/Arc/Arc.types.js.map +1 -0
  213. package/lib-commonjs/components/DonutChart/Arc/index.js +7 -0
  214. package/lib-commonjs/components/DonutChart/Arc/index.js.map +1 -0
  215. package/lib-commonjs/components/DonutChart/Arc/useArcStyles.styles.js +83 -0
  216. package/lib-commonjs/components/DonutChart/Arc/useArcStyles.styles.js.map +1 -0
  217. package/lib-commonjs/components/DonutChart/DonutChart.js +298 -0
  218. package/lib-commonjs/components/DonutChart/DonutChart.js.map +1 -0
  219. package/lib-commonjs/components/DonutChart/DonutChart.types.js +6 -0
  220. package/lib-commonjs/components/DonutChart/DonutChart.types.js.map +1 -0
  221. package/lib-commonjs/components/DonutChart/Pie/Pie.js +79 -0
  222. package/lib-commonjs/components/DonutChart/Pie/Pie.js.map +1 -0
  223. package/lib-commonjs/components/DonutChart/Pie/Pie.types.js +4 -0
  224. package/lib-commonjs/components/DonutChart/Pie/Pie.types.js.map +1 -0
  225. package/lib-commonjs/components/DonutChart/Pie/index.js +7 -0
  226. package/lib-commonjs/components/DonutChart/Pie/index.js.map +1 -0
  227. package/lib-commonjs/components/DonutChart/Pie/usePieStyles.styles.js +61 -0
  228. package/lib-commonjs/components/DonutChart/Pie/usePieStyles.styles.js.map +1 -0
  229. package/lib-commonjs/components/DonutChart/index.js +8 -0
  230. package/lib-commonjs/components/DonutChart/index.js.map +1 -0
  231. package/lib-commonjs/components/DonutChart/useDonutChartStyles.styles.js +82 -0
  232. package/lib-commonjs/components/DonutChart/useDonutChartStyles.styles.js.map +1 -0
  233. package/lib-commonjs/components/HorizontalBarChart/HorizontalBarChart.js +408 -0
  234. package/lib-commonjs/components/HorizontalBarChart/HorizontalBarChart.js.map +1 -0
  235. package/lib-commonjs/components/HorizontalBarChart/HorizontalBarChart.types.js +17 -0
  236. package/lib-commonjs/components/HorizontalBarChart/HorizontalBarChart.types.js.map +1 -0
  237. package/lib-commonjs/components/HorizontalBarChart/index.js +8 -0
  238. package/lib-commonjs/components/HorizontalBarChart/index.js.map +1 -0
  239. package/lib-commonjs/components/HorizontalBarChart/useHorizontalBarChartStyles.styles.js +251 -0
  240. package/lib-commonjs/components/HorizontalBarChart/useHorizontalBarChartStyles.styles.js.map +1 -0
  241. package/lib-commonjs/components/Legends/Legends.js +313 -0
  242. package/lib-commonjs/components/Legends/Legends.js.map +1 -0
  243. package/lib-commonjs/components/Legends/Legends.types.js +6 -0
  244. package/lib-commonjs/components/Legends/Legends.types.js.map +1 -0
  245. package/lib-commonjs/components/Legends/OverflowMenu.js +36 -0
  246. package/lib-commonjs/components/Legends/OverflowMenu.js.map +1 -0
  247. package/lib-commonjs/components/Legends/index.js +8 -0
  248. package/lib-commonjs/components/Legends/index.js.map +1 -0
  249. package/lib-commonjs/components/Legends/shape.js +46 -0
  250. package/lib-commonjs/components/Legends/shape.js.map +1 -0
  251. package/lib-commonjs/components/Legends/useLegendsStyles.styles.js +304 -0
  252. package/lib-commonjs/components/Legends/useLegendsStyles.styles.js.map +1 -0
  253. package/lib-commonjs/components/LineChart/LineChart.js +1032 -0
  254. package/lib-commonjs/components/LineChart/LineChart.js.map +1 -0
  255. package/lib-commonjs/components/LineChart/LineChart.types.js +6 -0
  256. package/lib-commonjs/components/LineChart/LineChart.types.js.map +1 -0
  257. package/lib-commonjs/components/LineChart/eventAnnotation/EventAnnotation.js +129 -0
  258. package/lib-commonjs/components/LineChart/eventAnnotation/EventAnnotation.js.map +1 -0
  259. package/lib-commonjs/components/LineChart/eventAnnotation/LabelLink.js +68 -0
  260. package/lib-commonjs/components/LineChart/eventAnnotation/LabelLink.js.map +1 -0
  261. package/lib-commonjs/components/LineChart/eventAnnotation/Textbox.js +51 -0
  262. package/lib-commonjs/components/LineChart/eventAnnotation/Textbox.js.map +1 -0
  263. package/lib-commonjs/components/LineChart/index.js +9 -0
  264. package/lib-commonjs/components/LineChart/index.js.map +1 -0
  265. package/lib-commonjs/components/LineChart/useLineChartStyles.styles.js +96 -0
  266. package/lib-commonjs/components/LineChart/useLineChartStyles.styles.js.map +1 -0
  267. package/lib-commonjs/components/ResponsiveContainer/ResponsiveContainer.js +76 -0
  268. package/lib-commonjs/components/ResponsiveContainer/ResponsiveContainer.js.map +1 -0
  269. package/lib-commonjs/components/ResponsiveContainer/ResponsiveContainer.types.js +6 -0
  270. package/lib-commonjs/components/ResponsiveContainer/ResponsiveContainer.types.js.map +1 -0
  271. package/lib-commonjs/components/ResponsiveContainer/index.js +6 -0
  272. package/lib-commonjs/components/ResponsiveContainer/index.js.map +1 -0
  273. package/lib-commonjs/components/ResponsiveContainer/useResponsiveContainerStyles.styles.js +47 -0
  274. package/lib-commonjs/components/ResponsiveContainer/useResponsiveContainerStyles.styles.js.map +1 -0
  275. package/lib-commonjs/components/Sparkline/Sparkline.js +125 -0
  276. package/lib-commonjs/components/Sparkline/Sparkline.js.map +1 -0
  277. package/lib-commonjs/components/Sparkline/Sparkline.types.js +7 -0
  278. package/lib-commonjs/components/Sparkline/Sparkline.types.js.map +1 -0
  279. package/lib-commonjs/components/Sparkline/index.js +8 -0
  280. package/lib-commonjs/components/Sparkline/index.js.map +1 -0
  281. package/lib-commonjs/components/Sparkline/useSparklineStyles.styles.js +77 -0
  282. package/lib-commonjs/components/Sparkline/useSparklineStyles.styles.js.map +1 -0
  283. package/lib-commonjs/components/VerticalBarChart/VerticalBarChart.js +851 -0
  284. package/lib-commonjs/components/VerticalBarChart/VerticalBarChart.js.map +1 -0
  285. package/lib-commonjs/components/VerticalBarChart/VerticalBarChart.types.js +7 -0
  286. package/lib-commonjs/components/VerticalBarChart/VerticalBarChart.types.js.map +1 -0
  287. package/lib-commonjs/components/VerticalBarChart/index.js +8 -0
  288. package/lib-commonjs/components/VerticalBarChart/index.js.map +1 -0
  289. package/lib-commonjs/components/VerticalBarChart/useVerticalBarChartStyles.styles.js +117 -0
  290. package/lib-commonjs/components/VerticalBarChart/useVerticalBarChartStyles.styles.js.map +1 -0
  291. package/lib-commonjs/index.js +17 -0
  292. package/lib-commonjs/index.js.map +1 -0
  293. package/lib-commonjs/types/DataPoint.js +6 -0
  294. package/lib-commonjs/types/DataPoint.js.map +1 -0
  295. package/lib-commonjs/types/EventAnnotation.js +6 -0
  296. package/lib-commonjs/types/EventAnnotation.js.map +1 -0
  297. package/lib-commonjs/types/LegendDataItem.js +4 -0
  298. package/lib-commonjs/types/LegendDataItem.js.map +1 -0
  299. package/lib-commonjs/types/index.js +7 -0
  300. package/lib-commonjs/types/index.js.map +1 -0
  301. package/lib-commonjs/utilities/FocusableTooltipText.js +75 -0
  302. package/lib-commonjs/utilities/FocusableTooltipText.js.map +1 -0
  303. package/lib-commonjs/utilities/KeyCodes.js +18 -0
  304. package/lib-commonjs/utilities/KeyCodes.js.map +1 -0
  305. package/lib-commonjs/utilities/SVGTooltipText.js +148 -0
  306. package/lib-commonjs/utilities/SVGTooltipText.js.map +1 -0
  307. package/lib-commonjs/utilities/async-utils.js +382 -0
  308. package/lib-commonjs/utilities/async-utils.js.map +1 -0
  309. package/lib-commonjs/utilities/colors.js +270 -0
  310. package/lib-commonjs/utilities/colors.js.map +1 -0
  311. package/lib-commonjs/utilities/getWindow.js +28 -0
  312. package/lib-commonjs/utilities/getWindow.js.map +1 -0
  313. package/lib-commonjs/utilities/index.js +8 -0
  314. package/lib-commonjs/utilities/index.js.map +1 -0
  315. package/lib-commonjs/utilities/locale-util.js +25 -0
  316. package/lib-commonjs/utilities/locale-util.js.map +1 -0
  317. package/lib-commonjs/utilities/overflow-utils.js +36 -0
  318. package/lib-commonjs/utilities/overflow-utils.js.map +1 -0
  319. package/lib-commonjs/utilities/test-data.js +324 -0
  320. package/lib-commonjs/utilities/test-data.js.map +1 -0
  321. package/lib-commonjs/utilities/utilities.js +1184 -0
  322. package/lib-commonjs/utilities/utilities.js.map +1 -0
  323. package/lib-commonjs/utilities/vbc-utils.js +45 -0
  324. package/lib-commonjs/utilities/vbc-utils.js.map +1 -0
  325. package/package.json +80 -72
  326. package/CHANGELOG.json +0 -65
  327. package/lib/chart/chart-legend.d.ts +0 -6
  328. package/lib/chart/chart-legend.js +0 -445
  329. package/lib/chart/chart-legend.js.map +0 -1
  330. package/lib/chart/chart-render.d.ts +0 -3
  331. package/lib/chart/chart-render.js +0 -50
  332. package/lib/chart/chart-render.js.map +0 -1
  333. package/lib/chart/chart.d.ts +0 -3
  334. package/lib/chart/chart.js +0 -10
  335. package/lib/chart/chart.js.map +0 -1
  336. package/lib/chart/index.d.ts +0 -1
  337. package/lib/chart/index.js +0 -2
  338. package/lib/chart/index.js.map +0 -1
  339. package/lib/index.d.ts +0 -7
  340. package/lib/lib/builder.d.ts +0 -89
  341. package/lib/lib/builder.js +0 -379
  342. package/lib/lib/builder.js.map +0 -1
  343. package/lib/lib/datasets.d.ts +0 -123
  344. package/lib/lib/datasets.js +0 -285
  345. package/lib/lib/datasets.js.map +0 -1
  346. package/lib/lib/patterns.d.ts +0 -43
  347. package/lib/lib/patterns.js +0 -433
  348. package/lib/lib/patterns.js.map +0 -1
  349. package/lib/lib/plugins.d.ts +0 -11
  350. package/lib/lib/plugins.js +0 -403
  351. package/lib/lib/plugins.js.map +0 -1
  352. package/lib/lib/settings.d.ts +0 -12
  353. package/lib/lib/settings.js +0 -368
  354. package/lib/lib/settings.js.map +0 -1
  355. package/lib/lib/storybook.d.ts +0 -11
  356. package/lib/lib/storybook.js +0 -13
  357. package/lib/lib/storybook.js.map +0 -1
  358. package/lib/lib/utils.d.ts +0 -34
  359. package/lib/lib/utils.js +0 -253
  360. package/lib/lib/utils.js.map +0 -1
  361. package/lib/types/index.d.ts +0 -1
  362. package/lib/types/types.d.ts +0 -101
  363. package/lib/types/types.js +0 -41
  364. package/lib/types/types.js.map +0 -1
@@ -0,0 +1,1215 @@
1
+ import { axisRight as d3AxisRight, axisBottom as d3AxisBottom, axisLeft as d3AxisLeft } from 'd3-axis';
2
+ import { max as d3Max, min as d3Min } from 'd3-array';
3
+ import { scaleLinear as d3ScaleLinear, scaleBand as d3ScaleBand, scaleUtc as d3ScaleUtc, scaleTime as d3ScaleTime } from 'd3-scale';
4
+ import { select as d3Select, selectAll as d3SelectAll } from 'd3-selection';
5
+ import { format as d3Format } from 'd3-format';
6
+ import { timeFormat as d3TimeFormat, timeFormatLocale as d3TimeFormatLocale, utcFormat as d3UtcFormat } from 'd3-time-format';
7
+ import { timeSecond as d3TimeSecond, timeMinute as d3TimeMinute, timeHour as d3TimeHour, timeDay as d3TimeDay, timeMonth as d3TimeMonth, timeWeek as d3TimeWeek, timeYear as d3TimeYear, utcSecond as d3UtcSecond, utcMinute as d3UtcMinute, utcHour as d3UtcHour, utcDay as d3UtcDay, utcMonth as d3UtcMonth, utcWeek as d3UtcWeek, utcYear as d3UtcYear } from 'd3-time';
8
+ import { formatPrefix as d3FormatPrefix } from 'd3-format';
9
+ import { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';
10
+ export var ChartTypes;
11
+ (function(ChartTypes) {
12
+ ChartTypes[ChartTypes["AreaChart"] = 0] = "AreaChart";
13
+ ChartTypes[ChartTypes["LineChart"] = 1] = "LineChart";
14
+ ChartTypes[ChartTypes["VerticalBarChart"] = 2] = "VerticalBarChart";
15
+ ChartTypes[ChartTypes["VerticalStackedBarChart"] = 3] = "VerticalStackedBarChart";
16
+ ChartTypes[ChartTypes["GroupedVerticalBarChart"] = 4] = "GroupedVerticalBarChart";
17
+ ChartTypes[ChartTypes["HeatMapChart"] = 5] = "HeatMapChart";
18
+ ChartTypes[ChartTypes["HorizontalBarChartWithAxis"] = 6] = "HorizontalBarChartWithAxis";
19
+ })(ChartTypes || (ChartTypes = {}));
20
+ export var XAxisTypes;
21
+ (function(XAxisTypes) {
22
+ XAxisTypes[XAxisTypes["NumericAxis"] = 0] = "NumericAxis";
23
+ XAxisTypes[XAxisTypes["DateAxis"] = 1] = "DateAxis";
24
+ XAxisTypes[XAxisTypes["StringAxis"] = 2] = "StringAxis";
25
+ })(XAxisTypes || (XAxisTypes = {}));
26
+ export var YAxisType;
27
+ (function(YAxisType) {
28
+ YAxisType[YAxisType["NumericAxis"] = 0] = "NumericAxis";
29
+ YAxisType[YAxisType["DateAxis"] = 1] = "DateAxis";
30
+ YAxisType[YAxisType["StringAxis"] = 2] = "StringAxis";
31
+ })(YAxisType || (YAxisType = {}));
32
+ /**
33
+ * Create Numeric X axis
34
+ * @export
35
+ * @param {IXAxisParams} xAxisParams
36
+ */ export function createNumericXAxis(xAxisParams, tickParams, chartType, culture) {
37
+ const { domainNRangeValues, showRoundOffXTickValues = false, xAxistickSize = 6, tickPadding = 10, xAxisCount, xAxisElement, hideTickOverlap } = xAxisParams;
38
+ const xAxisScale = d3ScaleLinear().domain([
39
+ domainNRangeValues.dStartValue,
40
+ domainNRangeValues.dEndValue
41
+ ]).range([
42
+ domainNRangeValues.rStartValue,
43
+ domainNRangeValues.rEndValue
44
+ ]);
45
+ showRoundOffXTickValues && xAxisScale.nice();
46
+ let tickCount = xAxisCount !== null && xAxisCount !== void 0 ? xAxisCount : 6;
47
+ const tickFormat = (domainValue, _index)=>{
48
+ if (tickParams.tickFormat) {
49
+ return d3Format(tickParams.tickFormat)(domainValue);
50
+ }
51
+ const xAxisValue = typeof domainValue === 'number' ? domainValue : domainValue.valueOf();
52
+ return convertToLocaleString(xAxisValue, culture);
53
+ };
54
+ if (hideTickOverlap && typeof xAxisCount === 'undefined') {
55
+ const longestLabelWidth = calculateLongestLabelWidth(xAxisScale.ticks().map(tickFormat), '.fui-cart__xAxis text') + 20;
56
+ const [start, end] = xAxisScale.range();
57
+ tickCount = Math.max(1, Math.floor(Math.abs(end - start) / longestLabelWidth));
58
+ }
59
+ const xAxis = d3AxisBottom(xAxisScale).tickSize(xAxistickSize).tickPadding(tickPadding).ticks(tickCount).tickFormat(tickFormat);
60
+ if (chartType === 6) {
61
+ xAxis.tickSizeInner(-(xAxisParams.containerHeight - xAxisParams.margins.top));
62
+ }
63
+ if (tickParams.tickValues) {
64
+ xAxis.tickValues(tickParams.tickValues);
65
+ }
66
+ if (xAxisElement) {
67
+ d3Select(xAxisElement).call(xAxis).selectAll('text').attr('aria-hidden', 'true');
68
+ }
69
+ var _tickParams_tickValues;
70
+ const tickValues = ((_tickParams_tickValues = tickParams.tickValues) !== null && _tickParams_tickValues !== void 0 ? _tickParams_tickValues : xAxisScale.ticks(tickCount)).map(xAxis.tickFormat());
71
+ return {
72
+ xScale: xAxisScale,
73
+ tickValues
74
+ };
75
+ }
76
+ function multiFormat(date, locale, useUTC) {
77
+ const timeFormat = locale ? useUTC ? locale.utcFormat : locale.format : useUTC ? d3UtcFormat : d3TimeFormat;
78
+ const formatMillisecond = timeFormat('.%L');
79
+ const formatSecond = timeFormat(':%S');
80
+ const formatMinute = timeFormat('%I:%M');
81
+ const formatHour = timeFormat('%I %p');
82
+ const formatDay = timeFormat('%a %d');
83
+ const formatWeek = timeFormat('%b %d');
84
+ const formatMonth = timeFormat('%B');
85
+ const formatYear = timeFormat('%Y');
86
+ const timeSecond = useUTC ? d3UtcSecond : d3TimeSecond;
87
+ const timeMinute = useUTC ? d3UtcMinute : d3TimeMinute;
88
+ const timeHour = useUTC ? d3UtcHour : d3TimeHour;
89
+ const timeDay = useUTC ? d3UtcDay : d3TimeDay;
90
+ const timeMonth = useUTC ? d3UtcMonth : d3TimeMonth;
91
+ const timeWeek = useUTC ? d3UtcWeek : d3TimeWeek;
92
+ const timeYear = useUTC ? d3UtcYear : d3TimeYear;
93
+ return (timeSecond(date) < date ? formatMillisecond : timeMinute(date) < date ? formatSecond : timeHour(date) < date ? formatMinute : timeDay(date) < date ? formatHour : timeMonth(date) < date ? timeWeek(date) < date ? formatDay : formatWeek : timeYear(date) < date ? formatMonth : formatYear)(date);
94
+ }
95
+ /**
96
+ * Creating Date x axis of the Chart
97
+ * @export
98
+ * @param {IXAxisParams} xAxisParams
99
+ * @param {ITickParams} tickParams
100
+ */ export function createDateXAxis(xAxisParams, tickParams, culture, options, timeFormatLocale, customDateTimeFormatter, useUTC) {
101
+ const { domainNRangeValues, xAxisElement, tickPadding = 6, xAxistickSize = 6, xAxisCount, hideTickOverlap } = xAxisParams;
102
+ const xAxisScale = useUTC ? d3ScaleUtc() : d3ScaleTime();
103
+ xAxisScale.domain([
104
+ domainNRangeValues.dStartValue,
105
+ domainNRangeValues.dEndValue
106
+ ]).range([
107
+ domainNRangeValues.rStartValue,
108
+ domainNRangeValues.rEndValue
109
+ ]);
110
+ let tickCount = xAxisCount !== null && xAxisCount !== void 0 ? xAxisCount : 6;
111
+ const tickFormat = (domainValue, _index)=>{
112
+ if (customDateTimeFormatter) {
113
+ return customDateTimeFormatter(domainValue);
114
+ }
115
+ if (culture && options) {
116
+ return domainValue.toLocaleString(culture, options);
117
+ }
118
+ if (timeFormatLocale) {
119
+ const locale = d3TimeFormatLocale(timeFormatLocale);
120
+ return multiFormat(domainValue, locale, useUTC);
121
+ }
122
+ if (culture === undefined && tickParams.tickFormat) {
123
+ if (useUTC) {
124
+ return d3UtcFormat(tickParams.tickFormat)(domainValue);
125
+ } else {
126
+ return d3TimeFormat(tickParams.tickFormat)(domainValue);
127
+ }
128
+ }
129
+ return multiFormat(domainValue, undefined, useUTC);
130
+ };
131
+ if (hideTickOverlap && typeof xAxisCount === 'undefined') {
132
+ const longestLabelWidth = calculateLongestLabelWidth(xAxisScale.ticks().map(tickFormat), '.fui-cart__xAxis text') + 40;
133
+ const [start, end] = xAxisScale.range();
134
+ tickCount = Math.max(1, Math.floor(Math.abs(end - start) / longestLabelWidth));
135
+ }
136
+ const xAxis = d3AxisBottom(xAxisScale).tickSize(xAxistickSize).tickPadding(tickPadding).ticks(tickCount).tickFormat(tickFormat);
137
+ tickParams.tickValues ? xAxis.tickValues(tickParams.tickValues) : '';
138
+ if (xAxisElement) {
139
+ d3Select(xAxisElement).call(xAxis).selectAll('text').attr('aria-hidden', 'true');
140
+ }
141
+ var _tickParams_tickValues;
142
+ const tickValues = ((_tickParams_tickValues = tickParams.tickValues) !== null && _tickParams_tickValues !== void 0 ? _tickParams_tickValues : xAxisScale.ticks(tickCount)).map(xAxis.tickFormat());
143
+ return {
144
+ xScale: xAxisScale,
145
+ tickValues
146
+ };
147
+ }
148
+ /**
149
+ * Create String X axis
150
+ * Currently using for only Vetical stacked bar chart and grouped vertical bar chart
151
+ * @export
152
+ * @param {IXAxisParams} xAxisParams
153
+ * @param {ITickParams} tickParams
154
+ * @param {string[]} dataset
155
+ * @returns
156
+ */ export function createStringXAxis(xAxisParams, tickParams, dataset, culture) {
157
+ const { domainNRangeValues, xAxistickSize = 6, tickPadding = 10, xAxisPadding = 0.1, xAxisInnerPadding, xAxisOuterPadding, containerWidth, hideTickOverlap } = xAxisParams;
158
+ const xAxisScale = d3ScaleBand().domain(dataset).range([
159
+ domainNRangeValues.rStartValue,
160
+ domainNRangeValues.rEndValue
161
+ ]).paddingInner(typeof xAxisInnerPadding !== 'undefined' ? xAxisInnerPadding : xAxisPadding).paddingOuter(typeof xAxisOuterPadding !== 'undefined' ? xAxisOuterPadding : xAxisPadding);
162
+ var _tickParams_tickValues;
163
+ let tickValues = (_tickParams_tickValues = tickParams.tickValues) !== null && _tickParams_tickValues !== void 0 ? _tickParams_tickValues : dataset;
164
+ const tickFormat = (domainValue, _index)=>{
165
+ return convertToLocaleString(domainValue, culture);
166
+ };
167
+ if (hideTickOverlap) {
168
+ let nonOverlappingTickValues = [];
169
+ const tickSizes = tickValues.map((value, index)=>calculateLongestLabelWidth([
170
+ tickFormat(value, index)
171
+ ], '.fui-cart__xAxis text'));
172
+ // for LTR
173
+ let start = 0;
174
+ let end = containerWidth;
175
+ let sign = 1;
176
+ const range = xAxisScale.range();
177
+ if (range[1] - range[0] < 0) {
178
+ // for RTL
179
+ start = containerWidth;
180
+ end = 0;
181
+ sign = -1;
182
+ }
183
+ for(let i = tickValues.length - 1; i >= 0; i--){
184
+ const tickPosition = xAxisScale(tickValues[i]);
185
+ if (sign * (tickPosition - sign * tickSizes[i] / 2 - start) >= 0 && sign * (tickPosition + sign * tickSizes[i] / 2 - end) <= 0) {
186
+ nonOverlappingTickValues.push(tickValues[i]);
187
+ end = tickPosition - sign * (tickSizes[i] / 2 + 10);
188
+ }
189
+ }
190
+ nonOverlappingTickValues = nonOverlappingTickValues.reverse();
191
+ tickValues = nonOverlappingTickValues;
192
+ }
193
+ const xAxis = d3AxisBottom(xAxisScale).tickSize(xAxistickSize).tickPadding(tickPadding).tickValues(tickValues).tickFormat(tickFormat);
194
+ if (xAxisParams.xAxisElement) {
195
+ d3Select(xAxisParams.xAxisElement).call(xAxis).selectAll('text').attr('aria-hidden', 'true');
196
+ }
197
+ return {
198
+ xScale: xAxisScale,
199
+ tickValues: tickValues.map(xAxis.tickFormat())
200
+ };
201
+ }
202
+ export function useRtl() {
203
+ const { dir } = useFluent(); // "dir" returns "ltr" or "rtl"
204
+ return dir === 'rtl';
205
+ }
206
+ /**
207
+ * This method used for creating data points for the y axis.
208
+ * @export
209
+ * @param {number} maxVal
210
+ * @param {number} minVal
211
+ * @param {number} splitInto
212
+ * @param {boolean} isIntegralDataset
213
+ * @returns {number[]}
214
+ */ export function prepareDatapoints(maxVal, minVal, splitInto, isIntegralDataset) {
215
+ const val = isIntegralDataset ? Math.ceil((maxVal - minVal) / splitInto) : (maxVal - minVal) / splitInto >= 1 ? Math.ceil((maxVal - minVal) / splitInto) : (maxVal - minVal) / splitInto;
216
+ const dataPointsArray = [
217
+ minVal,
218
+ minVal + val
219
+ ];
220
+ while(dataPointsArray[dataPointsArray.length - 1] < maxVal){
221
+ dataPointsArray.push(dataPointsArray[dataPointsArray.length - 1] + val);
222
+ }
223
+ return dataPointsArray;
224
+ }
225
+ /**
226
+ * Creating Numeric Y axis of the chart
227
+ * @export
228
+ * @param {IYAxisParams} yAxisParams
229
+ * @param {boolean} isRtl
230
+ */ export function createYAxis(yAxisParams, isRtl, axisData, chartType, barWidth, isIntegralDataset, useSecondaryYScale = false) {
231
+ switch(chartType){
232
+ case 6:
233
+ return createYAxisForHorizontalBarChartWithAxis(yAxisParams, isRtl, axisData, barWidth);
234
+ default:
235
+ return createYAxisForOtherCharts(yAxisParams, isRtl, axisData, isIntegralDataset, useSecondaryYScale);
236
+ }
237
+ }
238
+ export function createYAxisForHorizontalBarChartWithAxis(yAxisParams, isRtl, axisData, barWidth) {
239
+ const { yMinMaxValues = {
240
+ startValue: 0,
241
+ endValue: 0
242
+ }, yAxisElement = null, yMaxValue = 0, yMinValue = 0, containerHeight, margins, tickPadding = 12, maxOfYVal = 0, yAxisTickFormat, yAxisTickCount = 4 } = yAxisParams;
243
+ // maxOfYVal coming from only area chart and Grouped vertical bar chart(Calculation done at base file)
244
+ const tempVal = maxOfYVal || yMinMaxValues.endValue;
245
+ const finalYmax = tempVal > yMaxValue ? tempVal : yMaxValue;
246
+ const finalYmin = yMinMaxValues.startValue < yMinValue ? 0 : yMinValue;
247
+ const yAxisScale = d3ScaleLinear().domain([
248
+ finalYmin,
249
+ finalYmax
250
+ ]).range([
251
+ containerHeight - margins.bottom,
252
+ margins.top
253
+ ]);
254
+ const axis = isRtl ? d3AxisRight(yAxisScale) : d3AxisLeft(yAxisScale);
255
+ const yAxis = axis.tickPadding(tickPadding).ticks(yAxisTickCount);
256
+ yAxisTickFormat ? yAxis.tickFormat(yAxisTickFormat) : yAxis.tickFormat(d3Format('.2~s'));
257
+ yAxisElement ? d3Select(yAxisElement).call((g)=>yAxis).selectAll('text').attr('aria-hidden', 'true') : '';
258
+ return yAxisScale;
259
+ }
260
+ export function createYAxisForOtherCharts(yAxisParams, isRtl, axisData, isIntegralDataset, useSecondaryYScale = false) {
261
+ const { yMinMaxValues = {
262
+ startValue: 0,
263
+ endValue: 0
264
+ }, yAxisElement = null, yMaxValue = 0, yMinValue = 0, containerHeight, containerWidth, margins, tickPadding = 12, maxOfYVal = 0, yAxisTickFormat, yAxisTickCount = 4, eventAnnotationProps, eventLabelHeight } = yAxisParams;
265
+ // maxOfYVal coming from only area chart and Grouped vertical bar chart(Calculation done at base file)
266
+ const tempVal = maxOfYVal || yMinMaxValues.endValue;
267
+ const finalYmax = tempVal > yMaxValue ? tempVal : yMaxValue;
268
+ const finalYmin = yMinMaxValues.startValue < yMinValue ? 0 : yMinValue;
269
+ const domainValues = prepareDatapoints(finalYmax, finalYmin, yAxisTickCount, isIntegralDataset);
270
+ const yAxisScale = d3ScaleLinear().domain([
271
+ finalYmin,
272
+ domainValues[domainValues.length - 1]
273
+ ]).range([
274
+ containerHeight - margins.bottom,
275
+ margins.top + (eventAnnotationProps ? eventLabelHeight : 0)
276
+ ]);
277
+ const axis = !isRtl && useSecondaryYScale || isRtl && !useSecondaryYScale ? d3AxisRight(yAxisScale) : d3AxisLeft(yAxisScale);
278
+ const yAxis = axis.tickPadding(tickPadding).tickValues(domainValues).tickSizeInner(-(containerWidth - margins.left - margins.right));
279
+ yAxisTickFormat ? yAxis.tickFormat(yAxisTickFormat) : yAxis.tickFormat(d3Format('.2~s'));
280
+ yAxisElement ? d3Select(yAxisElement).call(yAxis).selectAll('text').attr('aria-hidden', 'true') : '';
281
+ axisData.yAxisDomainValues = domainValues;
282
+ return yAxisScale;
283
+ }
284
+ export const createStringYAxis = (yAxisParams, dataPoints, isRtl, chartType, barWidth, culture)=>{
285
+ switch(chartType){
286
+ case 6:
287
+ return createStringYAxisForHorizontalBarChartWithAxis(yAxisParams, dataPoints, isRtl, barWidth, culture);
288
+ default:
289
+ return createStringYAxisForOtherCharts(yAxisParams, dataPoints, isRtl);
290
+ }
291
+ };
292
+ /**
293
+ * Creating String Y axis of the chart for Horizontal Bar Chart With Axis
294
+ * @param yAxisParams
295
+ * @param dataPoints
296
+ * @param isRtl
297
+ */ export const createStringYAxisForHorizontalBarChartWithAxis = (yAxisParams, dataPoints, isRtl, barWidth, culture)=>{
298
+ const { containerHeight, tickPadding = 12, margins, yAxisTickFormat, yAxisElement } = yAxisParams;
299
+ const yAxisScale = d3ScaleBand().domain(dataPoints).range([
300
+ containerHeight - margins.bottom - barWidth / 2,
301
+ margins.top + barWidth / 2
302
+ ]);
303
+ const axis = isRtl ? d3AxisRight(yAxisScale) : d3AxisLeft(yAxisScale);
304
+ const yAxis = axis.tickPadding(tickPadding).ticks(dataPoints);
305
+ if (yAxisTickFormat) {
306
+ yAxis.tickFormat(yAxisTickFormat);
307
+ }
308
+ yAxisElement ? d3Select(yAxisElement).call((g)=>yAxis).selectAll('text') : '';
309
+ return yAxisScale;
310
+ };
311
+ /**
312
+ * Creating String Y axis of the chart for other chart except Horizontal Bar Chart With Axis
313
+ * @param yAxisParams
314
+ * @param dataPoints
315
+ * @param isRtl
316
+ */ export const createStringYAxisForOtherCharts = (yAxisParams, dataPoints, isRtl)=>{
317
+ const { containerHeight, tickPadding = 12, margins, yAxisTickFormat, yAxisElement, yAxisPadding = 0 } = yAxisParams;
318
+ const yAxisScale = d3ScaleBand().domain(dataPoints).range([
319
+ containerHeight - margins.bottom,
320
+ margins.top
321
+ ]).padding(yAxisPadding);
322
+ const axis = isRtl ? d3AxisRight(yAxisScale) : d3AxisLeft(yAxisScale);
323
+ const yAxis = axis.tickPadding(tickPadding).tickValues(dataPoints).tickSize(0);
324
+ if (yAxisTickFormat) {
325
+ yAxis.tickFormat(yAxisTickFormat);
326
+ }
327
+ yAxisElement ? d3Select(yAxisElement).call((g)=>yAxis).selectAll('text') : '';
328
+ return yAxisScale;
329
+ };
330
+ /**
331
+ * For area chart and line chart, while displaying stackCallout, Need to form a callout data object.
332
+ * This methos creates an object for those 2 charts.
333
+ * @param values
334
+ */ export function calloutData(values) {
335
+ let combinedResult = [];
336
+ values.forEach((line)=>{
337
+ const elements = line.data.filter((point)=>!point.hideCallout).map((point)=>{
338
+ return {
339
+ ...point,
340
+ legend: line.legend,
341
+ color: line.color,
342
+ index: line.index
343
+ };
344
+ });
345
+ combinedResult = combinedResult.concat(elements);
346
+ });
347
+ const xValToDataPoints = {};
348
+ combinedResult.forEach((ele)=>{
349
+ const xValue = ele.x instanceof Date ? ele.x.getTime() : ele.x;
350
+ if (xValue in xValToDataPoints) {
351
+ xValToDataPoints[xValue].push({
352
+ legend: ele.legend,
353
+ y: ele.y,
354
+ color: ele.color,
355
+ xAxisCalloutData: ele.xAxisCalloutData,
356
+ yAxisCalloutData: ele.yAxisCalloutData,
357
+ callOutAccessibilityData: ele.callOutAccessibilityData,
358
+ index: ele.index
359
+ });
360
+ } else {
361
+ xValToDataPoints[xValue] = [
362
+ {
363
+ legend: ele.legend,
364
+ y: ele.y,
365
+ color: ele.color,
366
+ xAxisCalloutData: ele.xAxisCalloutData,
367
+ yAxisCalloutData: ele.yAxisCalloutData,
368
+ callOutAccessibilityData: ele.callOutAccessibilityData,
369
+ index: ele.index
370
+ }
371
+ ];
372
+ }
373
+ });
374
+ const result = Object.keys(xValToDataPoints).map((xValue)=>{
375
+ return {
376
+ x: Number(xValue),
377
+ values: xValToDataPoints[xValue]
378
+ };
379
+ });
380
+ return result;
381
+ }
382
+ export function getUnique(arr, comp) {
383
+ const unique = arr// eslint-disable-next-line @typescript-eslint/no-explicit-any
384
+ .map((e)=>e[comp])// store the keys of the unique objects
385
+ .map((e, i, final)=>final.indexOf(e) === i && i)// eliminate the dead keys & store unique objects
386
+ .filter((e)=>arr[e]).map((e)=>arr[e]);
387
+ return unique;
388
+ }
389
+ /**
390
+ * This function takes two paramerter
391
+ * 1. an array of strings
392
+ * 2. a string value
393
+ * if the value is not present in the given array then it will return the new
394
+ * array by appending the value to the present arrray.
395
+ *
396
+ * if the value is already present in the given array then it will return the new
397
+ * array by deleteing the value from the the array
398
+ * @param array
399
+ * @param value
400
+ */ export function silceOrAppendToArray(array, value) {
401
+ const pos = array.indexOf(value);
402
+ if (pos === -1) {
403
+ return [
404
+ ...array,
405
+ value
406
+ ];
407
+ } else {
408
+ return array.slice(0, pos).concat(array.slice(pos + 1));
409
+ }
410
+ }
411
+ /**
412
+ * This method used for wrapping of x axis labels (tick values).
413
+ * It breaks down given text value by space separated and calculates the total height needed to display all the words.
414
+ * That value = removal value. This value needs to be remove from total svg height, svg will shrink and
415
+ * total text will be displayed.
416
+ * @export
417
+ * @param {IWrapLabelProps} wrapLabelProps
418
+ * @returns
419
+ */ export function createWrapOfXLabels(wrapLabelProps) {
420
+ const { node, xAxis, noOfCharsToTruncate, showXAxisLablesTooltip } = wrapLabelProps;
421
+ if (node === null) {
422
+ return;
423
+ }
424
+ const axisNode = d3Select(node).call((g)=>xAxis);
425
+ let removeVal = 0;
426
+ const width = 10;
427
+ const arr = [];
428
+ axisNode.selectAll('.tick text').each(function() {
429
+ const text = d3Select(this);
430
+ const totalWord = text.text();
431
+ const truncatedWord = `${text.text().slice(0, noOfCharsToTruncate)}...`;
432
+ const totalWordLength = text.text().length;
433
+ const words = text.text().split(/\s+/).reverse();
434
+ arr.push(words.length);
435
+ let word = '';
436
+ let line = [];
437
+ let lineNumber = 0;
438
+ const lineHeight = 1.1; // ems
439
+ const y = text.attr('y');
440
+ const dy = parseFloat(text.attr('dy'));
441
+ let tspan = text.text(null).append('tspan').attr('x', 0).attr('y', y).attr('id', 'BaseSpan').attr('dy', dy + 'em').attr('data-', totalWord);
442
+ if (showXAxisLablesTooltip && totalWordLength > noOfCharsToTruncate) {
443
+ tspan = text.append('tspan').attr('id', 'showDots').attr('x', 0).attr('y', y).attr('dy', ++lineNumber * lineHeight + dy + 'em').text(truncatedWord);
444
+ } else if (showXAxisLablesTooltip && totalWordLength <= noOfCharsToTruncate) {
445
+ tspan = text.append('tspan').attr('id', 'LessLength').attr('x', 0).attr('y', y).attr('dy', ++lineNumber * lineHeight + dy + 'em').text(totalWord);
446
+ } else {
447
+ while(word = words.pop()){
448
+ line.push(word);
449
+ tspan.text(line.join(' '));
450
+ if (tspan.node().getComputedTextLength() > width && line.length > 1) {
451
+ line.pop();
452
+ tspan.text(line.join(' '));
453
+ line = [
454
+ word
455
+ ];
456
+ tspan = text.append('tspan').attr('id', 'WordBreakId').attr('x', 0).attr('y', y).attr('dy', ++lineNumber * lineHeight + dy + 'em').text(word);
457
+ }
458
+ }
459
+ const maxDigit = Math.max(...arr);
460
+ let maxHeight = 12; // intial value to render corretly first time
461
+ axisNode.selectAll('text').each(()=>{
462
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
463
+ const outerHTMLElement = document.getElementById('WordBreakId');
464
+ const BoxCordinates = outerHTMLElement && outerHTMLElement.getBoundingClientRect();
465
+ const boxHeight = BoxCordinates && BoxCordinates.height;
466
+ if (boxHeight > maxHeight) {
467
+ maxHeight = boxHeight;
468
+ }
469
+ });
470
+ // If we take directly maxDigit * maxheight, then it will show more height between x axis tick values and bottom.
471
+ // To avoid this, reducing maxDigit value by removing some digit based on legth of word.
472
+ let removeDigit = 4;
473
+ if (maxDigit <= 2) {
474
+ removeDigit = 1;
475
+ } else if (maxDigit > 2 && maxDigit <= 6) {
476
+ removeDigit = 2;
477
+ } else if (maxDigit > 6 && maxDigit <= 9) {
478
+ removeDigit = 3;
479
+ }
480
+ removeVal = (maxDigit - removeDigit) * maxHeight;
481
+ }
482
+ });
483
+ return removeVal > 0 ? removeVal : 0;
484
+ }
485
+ /**
486
+ * This method used for wrapping of y axis labels (tick values).
487
+ */ // eslint-disable-next-line @typescript-eslint/no-explicit-any
488
+ export function createYAxisLabels(node, // eslint-disable-next-line @typescript-eslint/no-explicit-any
489
+ yAxis, noOfCharsToTruncate, truncateLabel, xValue, isRtl) {
490
+ if (node === null) {
491
+ return;
492
+ }
493
+ const axisNode = d3Select(node).call(yAxis);
494
+ axisNode.selectAll('.tick text').each(function() {
495
+ const text = d3Select(this);
496
+ const totalWord = text.text();
497
+ const truncatedWord = isRtl ? `...${text.text().slice(0, noOfCharsToTruncate)}` : `${text.text().slice(0, noOfCharsToTruncate)}...`;
498
+ const totalWordLength = text.text().length;
499
+ const padding = truncateLabel ? 1.5 : 1; // ems
500
+ const y = text.attr('y');
501
+ const x = text.attr('x');
502
+ const dy = parseFloat(text.attr('dy'));
503
+ const dx = 0;
504
+ text.text(null).append('tspan').attr('x', x).attr('y', y).attr('id', 'BaseSpan').attr('dy', dy + 'em').attr('data-', totalWord);
505
+ if (truncateLabel && totalWordLength > noOfCharsToTruncate) {
506
+ text.append('tspan').attr('id', 'showDots').attr('x', isRtl ? 0 : x).attr('y', y).attr('dy', dy).attr('dx', padding + dx + 'em').text(truncatedWord);
507
+ } else {
508
+ text.attr('text-align', 'start').append('tspan').attr('id', 'LessLength').attr('x', isRtl ? 0 : x).attr('y', y).attr('dx', padding + dx + 'em').text(totalWord);
509
+ }
510
+ });
511
+ }
512
+ export const wrapContent = (content, id, maxWidth)=>{
513
+ const textElement = d3Select(`#${id}`);
514
+ textElement.text(content);
515
+ if (!textElement.node()) {
516
+ return false;
517
+ }
518
+ let isOverflowing = false;
519
+ let textLength = textElement.node().getComputedTextLength();
520
+ while(textLength > maxWidth && content.length > 0){
521
+ content = content.slice(0, -1);
522
+ textElement.text(content + '...');
523
+ isOverflowing = true;
524
+ textLength = textElement.node().getComputedTextLength();
525
+ }
526
+ return isOverflowing;
527
+ };
528
+ /**
529
+ * Calculates the width of the longest axis label in pixels
530
+ */ export const calculateLongestLabelWidth = (labels, query = 'none')=>{
531
+ let maxLabelWidth = 0;
532
+ const canvas = document.createElement('canvas');
533
+ const ctx = canvas.getContext('2d');
534
+ if (ctx) {
535
+ const axisText = document.querySelector(query);
536
+ if (axisText) {
537
+ const styles = window.getComputedStyle(axisText, null);
538
+ const fontWeight = styles.getPropertyValue('font-weight');
539
+ const fontSize = styles.getPropertyValue('font-size');
540
+ const fontFamily = styles.getPropertyValue('font-family');
541
+ ctx.font = `${fontWeight} ${fontSize} ${fontFamily}`;
542
+ } else {
543
+ ctx.font = '600 10px "Segoe UI"';
544
+ }
545
+ labels.forEach((label)=>{
546
+ maxLabelWidth = Math.max(ctx.measureText(label.toString()).width, maxLabelWidth);
547
+ });
548
+ }
549
+ return maxLabelWidth;
550
+ };
551
+ /**
552
+ * This method displays a tooltip to the x axis lables(tick values)
553
+ * when prop 'showXAxisLablesTooltip' enables to the respected chart.
554
+ * On hover of the truncated word(at x axis labels tick), a tooltip will be appeared.
555
+ */ // eslint-disable-next-line @typescript-eslint/no-explicit-any
556
+ export function tooltipOfXAxislabels(xAxistooltipProps) {
557
+ const { tooltipCls, xAxis, id } = xAxistooltipProps;
558
+ if (xAxis === null) {
559
+ return null;
560
+ }
561
+ const div = d3Select('body').append('div').attr('id', id).attr('class', tooltipCls).style('opacity', 0);
562
+ const aa = xAxis.selectAll('#BaseSpan')._groups[0];
563
+ const baseSpanLength = aa && Object.keys(aa).length;
564
+ const originalDataArray = [];
565
+ for(let i = 0; i < baseSpanLength; i++){
566
+ const originalData = aa[i].dataset && Object.values(aa[i].dataset)[0];
567
+ originalDataArray.push(originalData);
568
+ }
569
+ const tickObject = xAxis.selectAll('.tick')._groups[0];
570
+ const tickObjectLength = tickObject && Object.keys(tickObject).length;
571
+ for(let i = 0; i < tickObjectLength; i++){
572
+ const d1 = tickObject[i];
573
+ d3Select(d1)// eslint-disable-next-line @typescript-eslint/no-explicit-any
574
+ .on('mouseover', (event, d)=>{
575
+ div.style('opacity', 0.9);
576
+ div.html(originalDataArray[i]).style('left', event.pageX + 'px').style('top', event.pageY - 28 + 'px');
577
+ }).on('mouseout', (d)=>{
578
+ div.style('opacity', 0);
579
+ });
580
+ }
581
+ }
582
+ /**
583
+ * Find the axis type of line chart and area chart from given data
584
+ * @param points
585
+ */ export function getXAxisType(points) {
586
+ let isXAxisDateType = false;
587
+ if (points && points.length > 0) {
588
+ points.forEach((chartData)=>{
589
+ if (chartData.data.length > 0) {
590
+ isXAxisDateType = chartData.data[0].x instanceof Date;
591
+ return;
592
+ }
593
+ });
594
+ }
595
+ return isXAxisDateType;
596
+ }
597
+ /**
598
+ * Calculates Domain and range values for Numeric X axis.
599
+ * This method calculates Area cart and line chart.
600
+ * @export
601
+ * @param {LineChartPoints[]} points
602
+ * @param {IMargins} margins
603
+ * @param {number} width
604
+ * @param {boolean} isRTL
605
+ * @returns {IDomainNRange}
606
+ */ export function domainRangeOfNumericForAreaChart(points, margins, width, isRTL) {
607
+ const xMin = d3Min(points, (point)=>{
608
+ return d3Min(point.data, (item)=>item.x);
609
+ });
610
+ const xMax = d3Max(points, (point)=>{
611
+ return d3Max(point.data, (item)=>{
612
+ return item.x;
613
+ });
614
+ });
615
+ const rStartValue = margins.left;
616
+ const rEndValue = width - margins.right;
617
+ return isRTL ? {
618
+ dStartValue: xMax,
619
+ dEndValue: xMin,
620
+ rStartValue,
621
+ rEndValue
622
+ } : {
623
+ dStartValue: xMin,
624
+ dEndValue: xMax,
625
+ rStartValue,
626
+ rEndValue
627
+ };
628
+ }
629
+ /**
630
+ * Calculates Domain and range values for Numeric X axis.
631
+ * This method calculates Horizontal Chart with Axis
632
+ * @export
633
+ * @param {LineChartPoints[]} points
634
+ * @param {IMargins} margins
635
+ * @param {number} width
636
+ * @param {boolean} isRTL
637
+ * @returns {IDomainNRange}
638
+ */ export function domainRangeOfNumericForHorizontalBarChartWithAxis(points, margins, containerWidth, isRTL, shiftX) {
639
+ const xMax = d3Max(points, (point)=>point.x);
640
+ const rMin = isRTL ? margins.left : margins.left + shiftX;
641
+ const rMax = isRTL ? containerWidth - margins.right - shiftX : containerWidth - margins.right;
642
+ return isRTL ? {
643
+ dStartValue: xMax,
644
+ dEndValue: 0,
645
+ rStartValue: rMin,
646
+ rEndValue: rMax
647
+ } : {
648
+ dStartValue: 0,
649
+ dEndValue: xMax,
650
+ rStartValue: rMin,
651
+ rEndValue: rMax
652
+ };
653
+ }
654
+ /**
655
+ * Calculates Range values of x Axis string axis
656
+ * For String axis, we need to give domain values (Not start and end array values)
657
+ * So sending 0 as domain values. Domain will be handled at creation of string axis
658
+ * For charts stacked bar chart, grouped vertical bar chart, HeatMapChart and Vertical bar chart
659
+ * @export
660
+ * @param {IMargins} margins
661
+ * @param {number} width
662
+ * @param {boolean} isRTL
663
+ * @returns {IDomainNRange}
664
+ */ export function domainRangeOfXStringAxis(margins, width, isRTL) {
665
+ const rMin = margins.left;
666
+ const rMax = width - margins.right;
667
+ return isRTL ? {
668
+ dStartValue: 0,
669
+ dEndValue: 0,
670
+ rStartValue: rMax,
671
+ rEndValue: rMin
672
+ } : {
673
+ dStartValue: 0,
674
+ dEndValue: 0,
675
+ rStartValue: rMin,
676
+ rEndValue: rMax
677
+ };
678
+ }
679
+ /**
680
+ * Calculate domain and range values to the Vertical stacked bar chart - For Numeric axis
681
+ * @export
682
+ * @param {DataPoint[]} points
683
+ * @param {IMargins} margins
684
+ * @param {number} width
685
+ * @param {boolean} isRTL
686
+ * @param {number} barWidth
687
+ * @returns {IDomainNRange}
688
+ */ export function domainRangeOfVSBCNumeric(points, margins, width, isRTL, barWidth) {
689
+ const xMin = d3Min(points, (point)=>point.x);
690
+ const xMax = d3Max(points, (point)=>point.x);
691
+ const rMax = margins.left;
692
+ const rMin = width - margins.right;
693
+ return isRTL ? {
694
+ dStartValue: xMax,
695
+ dEndValue: xMin,
696
+ rStartValue: rMax,
697
+ rEndValue: rMin
698
+ } : {
699
+ dStartValue: xMin,
700
+ dEndValue: xMax,
701
+ rStartValue: rMax,
702
+ rEndValue: rMin
703
+ };
704
+ }
705
+ /**
706
+ * Calculates Domain and range values for Date X axis.
707
+ * This method calculates Bar chart.
708
+ * @export
709
+ * @param {VerticalBarChartDataPoint[]} points
710
+ * @param {IMargins} margins
711
+ * @param {number} width
712
+ * @param {boolean} isRTL
713
+ * @param {Date[] | number[]} tickValues
714
+ * @returns {IDomainNRange}
715
+ */ export function domainRangeOfDateForAreaLineVerticalBarChart(points, margins, width, isRTL, tickValues = [], chartType, barWidth) {
716
+ let sDate;
717
+ let lDate;
718
+ if (chartType === 0 || chartType === 1) {
719
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
720
+ sDate = d3Min(points, (point)=>{
721
+ return d3Min(point.data, (item)=>{
722
+ return item.x;
723
+ });
724
+ });
725
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
726
+ lDate = d3Max(points, (point)=>{
727
+ return d3Max(point.data, (item)=>{
728
+ return item.x;
729
+ });
730
+ });
731
+ // Need to draw graph with given small and large date
732
+ // (Which Involves customization of date axis tick values)
733
+ // That may be Either from given graph data or from prop 'tickValues' date values.
734
+ // So, Finding smallest and largest dates
735
+ sDate = d3Min([
736
+ ...tickValues,
737
+ sDate
738
+ ]);
739
+ lDate = d3Max([
740
+ ...tickValues,
741
+ lDate
742
+ ]);
743
+ } else {
744
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
745
+ sDate = d3Min(points, (point)=>point.x);
746
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
747
+ lDate = d3Max(points, (point)=>point.x);
748
+ }
749
+ const rStartValue = margins.left;
750
+ const rEndValue = width - margins.right;
751
+ return isRTL ? {
752
+ dStartValue: lDate,
753
+ dEndValue: sDate,
754
+ rStartValue,
755
+ rEndValue
756
+ } : {
757
+ dStartValue: sDate,
758
+ dEndValue: lDate,
759
+ rStartValue,
760
+ rEndValue
761
+ };
762
+ }
763
+ /**
764
+ * Calculate domain and range values to the Vertical bar chart - For Numeric axis
765
+ * @export
766
+ * @param {DataPoint[]} points
767
+ * @param {IMargins} margins
768
+ * @param {number} containerWidth
769
+ * @param {boolean} isRTL
770
+ * @param {number} barWidth
771
+ * @returns {IDomainNRange}
772
+ */ export function domainRageOfVerticalNumeric(points, margins, containerWidth, isRTL, barWidth) {
773
+ const xMax = d3Max(points, (point)=>point.x);
774
+ const xMin = d3Min(points, (point)=>point.x);
775
+ const rMin = margins.left;
776
+ const rMax = containerWidth - margins.right;
777
+ return isRTL ? {
778
+ dStartValue: xMax,
779
+ dEndValue: xMin,
780
+ rStartValue: rMin,
781
+ rEndValue: rMax
782
+ } : {
783
+ dStartValue: xMin,
784
+ dEndValue: xMax,
785
+ rStartValue: rMin,
786
+ rEndValue: rMax
787
+ };
788
+ }
789
+ /**
790
+ * For creating X axis, need to calculate x axis domain and range values from given points.
791
+ * This may vary based on chart type and type of x axis
792
+ * So, this method will define which method need to call based on chart type and axis type.
793
+ * @export
794
+ * @param {*} points
795
+ * @param {IMargins} margins
796
+ * @param {number} width
797
+ * @param {ChartTypes} chartType
798
+ * @param {boolean} isRTL
799
+ * @param {XAxisTypes} xAxisType
800
+ * @param {number} [barWidth]
801
+ * @returns {IDomainNRange}
802
+ */ export function getDomainNRangeValues(// eslint-disable-next-line @typescript-eslint/no-explicit-any
803
+ points, margins, width, chartType, isRTL, xAxisType, barWidth, tickValues, shiftX) {
804
+ let domainNRangeValue;
805
+ if (xAxisType === 0) {
806
+ switch(chartType){
807
+ case 0:
808
+ case 1:
809
+ domainNRangeValue = domainRangeOfNumericForAreaChart(points, margins, width, isRTL);
810
+ break;
811
+ case 3:
812
+ domainNRangeValue = domainRangeOfVSBCNumeric(points, margins, width, isRTL, barWidth);
813
+ break;
814
+ case 2:
815
+ domainNRangeValue = domainRageOfVerticalNumeric(points, margins, width, isRTL, barWidth);
816
+ break;
817
+ case 6:
818
+ domainNRangeValue = domainRangeOfNumericForHorizontalBarChartWithAxis(points, margins, width, isRTL, shiftX);
819
+ break;
820
+ default:
821
+ domainNRangeValue = {
822
+ dStartValue: 0,
823
+ dEndValue: 0,
824
+ rStartValue: 0,
825
+ rEndValue: 0
826
+ };
827
+ }
828
+ } else if (xAxisType === 1) {
829
+ switch(chartType){
830
+ case 0:
831
+ case 1:
832
+ case 2:
833
+ case 3:
834
+ domainNRangeValue = domainRangeOfDateForAreaLineVerticalBarChart(points, margins, width, isRTL, tickValues, chartType, barWidth);
835
+ break;
836
+ default:
837
+ domainNRangeValue = {
838
+ dStartValue: 0,
839
+ dEndValue: 0,
840
+ rStartValue: 0,
841
+ rEndValue: 0
842
+ };
843
+ }
844
+ } else {
845
+ // String Axis type
846
+ switch(chartType){
847
+ case 3:
848
+ case 4:
849
+ case 2:
850
+ case 5:
851
+ domainNRangeValue = domainRangeOfXStringAxis(margins, width, isRTL);
852
+ break;
853
+ default:
854
+ domainNRangeValue = {
855
+ dStartValue: 0,
856
+ dEndValue: 0,
857
+ rStartValue: 0,
858
+ rEndValue: 0
859
+ };
860
+ }
861
+ }
862
+ return domainNRangeValue;
863
+ }
864
+ /**
865
+ * Calculating start and ending values of the Area chart and LineChart
866
+ * @export
867
+ * @param {LineChartPoints[]} points
868
+ * @returns {{ startValue: number; endValue: number }}
869
+ */ export function findNumericMinMaxOfY(points) {
870
+ const yMax = d3Max(points, (point)=>{
871
+ return d3Max(point.data, (item)=>item.y);
872
+ });
873
+ const yMin = d3Min(points, (point)=>{
874
+ return d3Min(point.data, (item)=>item.y);
875
+ });
876
+ return {
877
+ startValue: yMin,
878
+ endValue: yMax
879
+ };
880
+ }
881
+ /**
882
+ * Find the minimum and maximum values of the vertical stacked bar chart y axis data point. Used for create y axis.
883
+ * @export
884
+ * @param {DataPoint[]} dataset
885
+ * @returns {{ startValue: number; endValue: number }}
886
+ */ export function findVSBCNumericMinMaxOfY(dataset) {
887
+ const yMax = d3Max(dataset, (point)=>point.y);
888
+ const yMin = d3Min(dataset, (point)=>point.y);
889
+ return {
890
+ startValue: yMin,
891
+ endValue: yMax
892
+ };
893
+ }
894
+ /**
895
+ * Fins the min and max values of the vertical bar chart y axis data point.
896
+ * @export
897
+ * @param {VerticalBarChartDataPoint[]} points
898
+ * @returns {{ startValue: number; endValue: number }}
899
+ */ export function findVerticalNumericMinMaxOfY(points) {
900
+ const yMax = d3Max(points, (point)=>{
901
+ if (point.lineData !== undefined) {
902
+ if (point.y > point.lineData.y) {
903
+ return point.y;
904
+ } else {
905
+ return point.lineData.y;
906
+ }
907
+ } else {
908
+ return point.y;
909
+ }
910
+ });
911
+ const yMin = d3Min(points, (point)=>{
912
+ if (point.lineData !== undefined) {
913
+ if (point.y < point.lineData.y) {
914
+ return point.y;
915
+ } else {
916
+ return point.lineData.y;
917
+ }
918
+ } else {
919
+ return point.y;
920
+ }
921
+ });
922
+ return {
923
+ startValue: yMin,
924
+ endValue: yMax
925
+ };
926
+ }
927
+ /**
928
+ * Fins the min and max values of the vertical bar chart y axis data point.
929
+ * @export
930
+ * @param {VerticalBarChartDataPoint[]} points
931
+ * @returns {{ startValue: number; endValue: number }}
932
+ */ export function findHBCWANumericMinMaxOfY(points, yAxisType) {
933
+ if (yAxisType !== undefined && yAxisType === 0) {
934
+ const yMax = d3Max(points, (point)=>point.y);
935
+ const yMin = d3Min(points, (point)=>point.y);
936
+ return {
937
+ startValue: yMin,
938
+ endValue: yMax
939
+ };
940
+ }
941
+ return {
942
+ startValue: 0,
943
+ endValue: 0
944
+ };
945
+ }
946
+ /**
947
+ * For creating Y axis, need to calculate y axis domain values from given points. This may vary based on chart type.
948
+ * So, this method will define which method need to call based on chart type to find out min and max values(For Domain).
949
+ * For grouped vertical bar chart, Calculating yMax value in the base file and sending as MaxOfYVal to cartesian.
950
+ * @export
951
+ * @param {*} points
952
+ * @param {ChartTypes} chartType
953
+ * @returns {{ startValue: number; endValue: number }}
954
+ */ // eslint-disable-next-line @typescript-eslint/no-explicit-any
955
+ export function getMinMaxOfYAxis(// eslint-disable-next-line @typescript-eslint/no-explicit-any
956
+ points, chartType, yAxisType = 0) {
957
+ let minMaxValues;
958
+ switch(chartType){
959
+ case 0:
960
+ case 1:
961
+ minMaxValues = findNumericMinMaxOfY(points);
962
+ break;
963
+ case 3:
964
+ minMaxValues = findVSBCNumericMinMaxOfY(points);
965
+ break;
966
+ case 2:
967
+ minMaxValues = findVerticalNumericMinMaxOfY(points);
968
+ break;
969
+ case 6:
970
+ minMaxValues = findHBCWANumericMinMaxOfY(points, yAxisType);
971
+ break;
972
+ default:
973
+ minMaxValues = {
974
+ startValue: 0,
975
+ endValue: 0
976
+ };
977
+ }
978
+ return minMaxValues;
979
+ }
980
+ /**
981
+ * @param p string or number or Date
982
+ *
983
+ * This function takes the single data point of the x-aixs
984
+ * and decides what is the x-axis
985
+ */ export const getTypeOfAxis = (p, isXAxis)=>{
986
+ if (isXAxis) {
987
+ switch(typeof p){
988
+ case 'string':
989
+ return 2;
990
+ case 'number':
991
+ return 0;
992
+ default:
993
+ return 1;
994
+ }
995
+ } else {
996
+ switch(typeof p){
997
+ case 'string':
998
+ return 2;
999
+ case 'number':
1000
+ return 0;
1001
+ default:
1002
+ return 1;
1003
+ }
1004
+ }
1005
+ };
1006
+ export var Points;
1007
+ (function(Points) {
1008
+ Points[Points["circle"] = 0] = "circle";
1009
+ Points[Points["square"] = 1] = "square";
1010
+ Points[Points["triangle"] = 2] = "triangle";
1011
+ Points[Points["diamond"] = 3] = "diamond";
1012
+ Points[Points["pyramid"] = 4] = "pyramid";
1013
+ Points[Points["hexagon"] = 5] = "hexagon";
1014
+ Points[Points["pentagon"] = 6] = "pentagon";
1015
+ Points[Points["octagon"] = 7] = "octagon";
1016
+ })(Points || (Points = {}));
1017
+ export var CustomPoints;
1018
+ (function(CustomPoints) {
1019
+ CustomPoints[CustomPoints["dottedLine"] = 0] = "dottedLine";
1020
+ })(CustomPoints || (CustomPoints = {}));
1021
+ /**
1022
+ * we need to make sure that if we add any property to this, then
1023
+ * we need to also add that in enum Point and vise-versa
1024
+ */ export const pointTypes = {
1025
+ [0]: {
1026
+ widthRatio: 1
1027
+ },
1028
+ [1]: {
1029
+ widthRatio: 1
1030
+ },
1031
+ [2]: {
1032
+ widthRatio: 1
1033
+ },
1034
+ [3]: {
1035
+ widthRatio: 1
1036
+ },
1037
+ [4]: {
1038
+ widthRatio: 1
1039
+ },
1040
+ [5]: {
1041
+ widthRatio: 2
1042
+ },
1043
+ [6]: {
1044
+ widthRatio: 1.168
1045
+ },
1046
+ [7]: {
1047
+ widthRatio: 2.414
1048
+ }
1049
+ };
1050
+ /**
1051
+ * @param accessibleData accessible data
1052
+ * @param role string to define role of tag
1053
+ * @param isDataFocusable boolean
1054
+ * function returns the accessibility data object
1055
+ */ export const getAccessibleDataObject = (accessibleData, role = 'text', isDataFocusable = true)=>{
1056
+ accessibleData = accessibleData !== null && accessibleData !== void 0 ? accessibleData : {};
1057
+ return {
1058
+ role,
1059
+ 'data-is-focusable': isDataFocusable,
1060
+ 'aria-label': accessibleData.ariaLabel,
1061
+ 'aria-labelledby': accessibleData.ariaLabelledBy,
1062
+ 'aria-describedby': accessibleData.ariaDescribedBy
1063
+ };
1064
+ };
1065
+ export const convertToLocaleString = (data, culture)=>{
1066
+ if (data === undefined || data === null || Number.isNaN(data)) {
1067
+ return data;
1068
+ }
1069
+ culture = culture || undefined;
1070
+ if (typeof data === 'number') {
1071
+ return data.toLocaleString(culture);
1072
+ } else if (typeof data === 'string' && !isNaN(Number(data))) {
1073
+ const num = Number(data);
1074
+ return num.toLocaleString(culture);
1075
+ } else if (data instanceof Date) {
1076
+ return data.toLocaleDateString(culture);
1077
+ }
1078
+ return data;
1079
+ };
1080
+ export function rotateXAxisLabels(rotateLabelProps) {
1081
+ const { node, xAxis } = rotateLabelProps;
1082
+ if (node === null || xAxis === null) {
1083
+ return;
1084
+ }
1085
+ let maxHeight = 0;
1086
+ const xAxisTranslations = [];
1087
+ d3Select(node).call(xAxis).selectAll('.tick').each(function() {
1088
+ const translateValue = this.getAttribute('transform');
1089
+ if ((translateValue === null || translateValue === void 0 ? void 0 : translateValue.indexOf('rotate')) === -1) {
1090
+ const translatePair = translateValue.substring(translateValue.indexOf('(') + 1, translateValue.indexOf(')')).split(',');
1091
+ if (translatePair.length === 2) {
1092
+ xAxisTranslations.push(translatePair[0]);
1093
+ this.setAttribute('transform', `translate(${translatePair[0]},0)rotate(-45)`);
1094
+ }
1095
+ }
1096
+ const BoxCordinates = this.getBoundingClientRect();
1097
+ const boxHeight = BoxCordinates && BoxCordinates.height;
1098
+ if (boxHeight > maxHeight) {
1099
+ maxHeight = boxHeight;
1100
+ }
1101
+ });
1102
+ let idx = 0;
1103
+ d3Select(node).call(xAxis).selectAll('.tick').each(function() {
1104
+ if (xAxisTranslations.length > idx) {
1105
+ this.setAttribute('transform', `translate(${xAxisTranslations[idx]},${maxHeight / 2})rotate(-45)`); // Translate y by max height/2
1106
+ idx += 1;
1107
+ }
1108
+ });
1109
+ return Math.floor(maxHeight / 1.414); // Compute maxHeight/tanInverse(45) to get the vertical height of labels.
1110
+ }
1111
+ export function wrapTextInsideDonut(selectorClass, maxWidth) {
1112
+ let idx = 0;
1113
+ d3SelectAll(`.${selectorClass}`).each(function() {
1114
+ const text = d3Select(this);
1115
+ const words = text.text().split(/\s+/).reverse();
1116
+ let word = '';
1117
+ let line = [];
1118
+ let lineNumber = 0;
1119
+ const lineHeight = 1.1; // ems
1120
+ const y = text.attr('y');
1121
+ let tspan = text.text(null).append('tspan').attr('id', `WordBreakId-${idx}-${lineNumber}`).attr('x', 0).attr('y', y).attr('dy', lineNumber++ * lineHeight + 'em');
1122
+ while(word = words.pop()){
1123
+ line.push(word);
1124
+ tspan.text(line.join(' ') + ' ');
1125
+ if (tspan.node().getComputedTextLength() > maxWidth && line.length > 1) {
1126
+ line.pop();
1127
+ tspan.text(line.join(' ') + ' ');
1128
+ line = [
1129
+ word
1130
+ ];
1131
+ tspan = text.append('tspan').attr('id', `WordBreakId-${idx}-${lineNumber}`).attr('x', 0).attr('y', y).attr('dy', lineNumber++ * lineHeight + 'em').text(word);
1132
+ }
1133
+ }
1134
+ idx += 1;
1135
+ });
1136
+ }
1137
+ export function formatValueWithSIPrefix(value) {
1138
+ let specifier;
1139
+ if (value < 1000) {
1140
+ specifier = '.2~'; // upto 2 decimal places without insignificant trailing zeros
1141
+ } else {
1142
+ specifier = '.1'; // upto 1 decimal place
1143
+ }
1144
+ return d3FormatPrefix(specifier, value)(value);
1145
+ }
1146
+ const DEFAULT_BAR_WIDTH = 16;
1147
+ const MIN_BAR_WIDTH = 1;
1148
+ export const getBarWidth = (barWidthProp, maxBarWidthProp, adjustedValue = DEFAULT_BAR_WIDTH)=>{
1149
+ let barWidth;
1150
+ if (typeof barWidthProp === 'number') {
1151
+ barWidth = barWidthProp;
1152
+ } else if (barWidthProp === 'default' || typeof barWidthProp === 'undefined') {
1153
+ barWidth = Math.min(adjustedValue, DEFAULT_BAR_WIDTH);
1154
+ } else {
1155
+ barWidth = adjustedValue;
1156
+ }
1157
+ if (typeof maxBarWidthProp === 'number') {
1158
+ barWidth = Math.min(barWidth, maxBarWidthProp);
1159
+ }
1160
+ barWidth = Math.max(barWidth, MIN_BAR_WIDTH);
1161
+ return barWidth;
1162
+ };
1163
+ export const getScalePadding = (prop, shorthandProp, defaultValue = 0)=>{
1164
+ let padding = typeof prop === 'number' ? prop : typeof shorthandProp === 'number' ? shorthandProp : defaultValue;
1165
+ padding = Math.max(0, Math.min(padding, 1));
1166
+ return padding;
1167
+ };
1168
+ export const isScalePaddingDefined = (prop, shorthandProp)=>{
1169
+ return typeof prop === 'number' || typeof shorthandProp === 'number';
1170
+ };
1171
+ /**
1172
+ * Helper to find the index of an item within an array, using a callback to
1173
+ * determine the match.
1174
+ *
1175
+ * @public
1176
+ * @param array - Array to search.
1177
+ * @param cb - Callback which returns true on matches.
1178
+ * @param fromIndex - Optional index to start from (defaults to 0)
1179
+ */ export function findIndex(array, cb, fromIndex = 0) {
1180
+ let index = -1;
1181
+ for(let i = fromIndex; array && i < array.length; i++){
1182
+ if (cb(array[i], i)) {
1183
+ index = i;
1184
+ break;
1185
+ }
1186
+ }
1187
+ return index;
1188
+ }
1189
+ /**
1190
+ * Helper to find the first item within an array that satisfies the callback.
1191
+ * @param array - Array to search
1192
+ * @param cb - Callback which returns true on matches
1193
+ */ export function find(array, cb) {
1194
+ let index = findIndex(array, cb);
1195
+ if (index < 0) {
1196
+ return undefined;
1197
+ }
1198
+ return array[index];
1199
+ }
1200
+ export const HighContrastSelector = '@media screen and (-ms-high-contrast: active), screen and (forced-colors: active)';
1201
+ export const HighContrastSelectorWhite = // eslint-disable-next-line @fluentui/max-len
1202
+ '@media screen and (-ms-high-contrast: black-on-white), screen and (forced-colors: active) and (prefers-color-scheme: light)';
1203
+ export const HighContrastSelectorBlack = // eslint-disable-next-line @fluentui/max-len
1204
+ '@media screen and (-ms-high-contrast: white-on-black), screen and (forced-colors: active) and (prefers-color-scheme: dark)';
1205
+ export const formatDate = (date, useUTC)=>{
1206
+ const timeFormat = useUTC ? d3UtcFormat : d3TimeFormat;
1207
+ return timeFormat('%-e %b %Y, %H:%M')(date) + (useUTC ? ' GMT' : '');
1208
+ };
1209
+ const cssVarRegExp = /var\((--[a-zA-Z0-9\-]+)\)/g;
1210
+ export function resolveCSSVariables(chartContainer, styleRules) {
1211
+ const containerStyles = getComputedStyle(chartContainer);
1212
+ return styleRules.replace(cssVarRegExp, (match, group1)=>{
1213
+ return containerStyles.getPropertyValue(group1);
1214
+ });
1215
+ }