@fluentui/react-charts 9.0.2 → 9.0.4

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 (229) hide show
  1. package/CHANGELOG.md +64 -7
  2. package/dist/index.d.ts +829 -94
  3. package/lib/AreaChart.js +1 -0
  4. package/lib/AreaChart.js.map +1 -0
  5. package/lib/HeatMapChart.js +1 -0
  6. package/lib/HeatMapChart.js.map +1 -0
  7. package/lib/HorizontalBarChartWithAxis.js +1 -0
  8. package/lib/HorizontalBarChartWithAxis.js.map +1 -0
  9. package/lib/SankeyChart.js +1 -0
  10. package/lib/SankeyChart.js.map +1 -0
  11. package/lib/VerticalStackedBarChart.js +1 -0
  12. package/lib/VerticalStackedBarChart.js.map +1 -0
  13. package/lib/components/AreaChart/AreaChart.js +775 -0
  14. package/lib/components/AreaChart/AreaChart.js.map +1 -0
  15. package/lib/components/AreaChart/AreaChart.types.js +4 -0
  16. package/lib/components/AreaChart/AreaChart.types.js.map +1 -0
  17. package/lib/components/AreaChart/index.js +3 -0
  18. package/lib/components/AreaChart/index.js.map +1 -0
  19. package/lib/components/AreaChart/useAreaChartStyles.styles.js +55 -0
  20. package/lib/components/AreaChart/useAreaChartStyles.styles.js.map +1 -0
  21. package/lib/components/CommonComponents/CartesianChart.js +30 -14
  22. package/lib/components/CommonComponents/CartesianChart.js.map +1 -1
  23. package/lib/components/CommonComponents/CartesianChart.types.js.map +1 -1
  24. package/lib/components/CommonComponents/ChartPopover.js +2 -2
  25. package/lib/components/CommonComponents/ChartPopover.js.map +1 -1
  26. package/lib/components/CommonComponents/useCartesianChartStyles.styles.js +7 -123
  27. package/lib/components/CommonComponents/useCartesianChartStyles.styles.js.map +1 -1
  28. package/lib/components/CommonComponents/useChartPopoverStyles.styles.js +11 -22
  29. package/lib/components/CommonComponents/useChartPopoverStyles.styles.js.map +1 -1
  30. package/lib/components/DeclarativeChart/DeclarativeChart.js +112 -65
  31. package/lib/components/DeclarativeChart/DeclarativeChart.js.map +1 -1
  32. package/lib/components/DeclarativeChart/PlotlySchemaAdapter.js +570 -159
  33. package/lib/components/DeclarativeChart/PlotlySchemaAdapter.js.map +1 -1
  34. package/lib/components/DonutChart/Arc/Arc.js +1 -1
  35. package/lib/components/DonutChart/Arc/Arc.js.map +1 -1
  36. package/lib/components/DonutChart/DonutChart.js +1 -1
  37. package/lib/components/DonutChart/DonutChart.js.map +1 -1
  38. package/lib/components/DonutChart/Pie/usePieStyles.styles.js +2 -6
  39. package/lib/components/DonutChart/Pie/usePieStyles.styles.js.map +1 -1
  40. package/lib/components/GaugeChart/GaugeChart.js +4 -1
  41. package/lib/components/GaugeChart/GaugeChart.js.map +1 -1
  42. package/lib/components/GaugeChart/GaugeChart.types.js.map +1 -1
  43. package/lib/components/GaugeChart/useGaugeChartStyles.styles.js +13 -9
  44. package/lib/components/GaugeChart/useGaugeChartStyles.styles.js.map +1 -1
  45. package/lib/components/GroupedVerticalBarChart/GroupedVerticalBarChart.js +9 -0
  46. package/lib/components/GroupedVerticalBarChart/GroupedVerticalBarChart.js.map +1 -1
  47. package/lib/components/GroupedVerticalBarChart/useGroupedVerticalBarChartStyles.styles.js +0 -9
  48. package/lib/components/GroupedVerticalBarChart/useGroupedVerticalBarChartStyles.styles.js.map +1 -1
  49. package/lib/components/HeatMapChart/HeatMapChart.js +588 -0
  50. package/lib/components/HeatMapChart/HeatMapChart.js.map +1 -0
  51. package/lib/components/HeatMapChart/HeatMapChart.types.js +4 -0
  52. package/lib/components/HeatMapChart/HeatMapChart.types.js.map +1 -0
  53. package/lib/components/HeatMapChart/index.js +3 -0
  54. package/lib/components/HeatMapChart/index.js.map +1 -0
  55. package/lib/components/HeatMapChart/useHeatMapChartStyles.styles.js +37 -0
  56. package/lib/components/HeatMapChart/useHeatMapChartStyles.styles.js.map +1 -0
  57. package/lib/components/HorizontalBarChart/useHorizontalBarChartStyles.styles.js +2 -9
  58. package/lib/components/HorizontalBarChart/useHorizontalBarChartStyles.styles.js.map +1 -1
  59. package/lib/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.js +571 -0
  60. package/lib/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.js.map +1 -0
  61. package/lib/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.types.js +4 -0
  62. package/lib/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.types.js.map +1 -0
  63. package/lib/components/HorizontalBarChartWithAxis/index.js +3 -0
  64. package/lib/components/HorizontalBarChartWithAxis/index.js.map +1 -0
  65. package/lib/components/HorizontalBarChartWithAxis/useHorizontalBarChartWithAxisStyles.styles.js +67 -0
  66. package/lib/components/HorizontalBarChartWithAxis/useHorizontalBarChartWithAxisStyles.styles.js.map +1 -0
  67. package/lib/components/Legends/Legends.js +38 -37
  68. package/lib/components/Legends/Legends.js.map +1 -1
  69. package/lib/components/Legends/useLegendsStyles.styles.js +2 -3
  70. package/lib/components/Legends/useLegendsStyles.styles.js.map +1 -1
  71. package/lib/components/LineChart/LineChart.js +43 -35
  72. package/lib/components/LineChart/LineChart.js.map +1 -1
  73. package/lib/components/LineChart/useLineChartStyles.styles.js +1 -10
  74. package/lib/components/LineChart/useLineChartStyles.styles.js.map +1 -1
  75. package/lib/components/SankeyChart/SankeyChart.js +1023 -0
  76. package/lib/components/SankeyChart/SankeyChart.js.map +1 -0
  77. package/lib/components/SankeyChart/SankeyChart.types.js +3 -0
  78. package/lib/components/SankeyChart/SankeyChart.types.js.map +1 -0
  79. package/lib/components/SankeyChart/index.js +3 -0
  80. package/lib/components/SankeyChart/index.js.map +1 -0
  81. package/lib/components/SankeyChart/useSankeyChartStyles.styles.js +109 -0
  82. package/lib/components/SankeyChart/useSankeyChartStyles.styles.js.map +1 -0
  83. package/lib/components/ScatterChart/ScatterChart.js +46 -59
  84. package/lib/components/ScatterChart/ScatterChart.js.map +1 -1
  85. package/lib/components/ScatterChart/useScatterChartStyles.styles.js +1 -10
  86. package/lib/components/ScatterChart/useScatterChartStyles.styles.js.map +1 -1
  87. package/lib/components/VerticalBarChart/VerticalBarChart.js +165 -88
  88. package/lib/components/VerticalBarChart/VerticalBarChart.js.map +1 -1
  89. package/lib/components/VerticalBarChart/VerticalBarChart.types.js.map +1 -1
  90. package/lib/components/VerticalBarChart/useVerticalBarChartStyles.styles.js +3 -11
  91. package/lib/components/VerticalBarChart/useVerticalBarChartStyles.styles.js.map +1 -1
  92. package/lib/components/VerticalStackedBarChart/VerticalStackedBarChart.js +904 -0
  93. package/lib/components/VerticalStackedBarChart/VerticalStackedBarChart.js.map +1 -0
  94. package/lib/components/VerticalStackedBarChart/VerticalStackedBarChart.types.js +1 -0
  95. package/lib/components/VerticalStackedBarChart/VerticalStackedBarChart.types.js.map +1 -0
  96. package/lib/components/VerticalStackedBarChart/index.js +3 -0
  97. package/lib/components/VerticalStackedBarChart/index.js.map +1 -0
  98. package/lib/components/VerticalStackedBarChart/useVerticalStackedBarChartStyles.styles.js +65 -0
  99. package/lib/components/VerticalStackedBarChart/useVerticalStackedBarChartStyles.styles.js.map +1 -0
  100. package/lib/index.js +5 -0
  101. package/lib/index.js.map +1 -1
  102. package/lib/types/DataPoint.js +1 -3
  103. package/lib/types/DataPoint.js.map +1 -1
  104. package/lib/utilities/SVGTooltipText.js +49 -4
  105. package/lib/utilities/SVGTooltipText.js.map +1 -1
  106. package/lib/utilities/colors.js +20 -0
  107. package/lib/utilities/colors.js.map +1 -1
  108. package/lib/utilities/string.js +32 -0
  109. package/lib/utilities/string.js.map +1 -0
  110. package/lib/utilities/test-data.js +53 -0
  111. package/lib/utilities/test-data.js.map +1 -1
  112. package/lib/utilities/utilities.js +90 -18
  113. package/lib/utilities/utilities.js.map +1 -1
  114. package/lib-commonjs/AreaChart.js +6 -0
  115. package/lib-commonjs/AreaChart.js.map +1 -0
  116. package/lib-commonjs/HeatMapChart.js +6 -0
  117. package/lib-commonjs/HeatMapChart.js.map +1 -0
  118. package/lib-commonjs/HorizontalBarChartWithAxis.js +6 -0
  119. package/lib-commonjs/HorizontalBarChartWithAxis.js.map +1 -0
  120. package/lib-commonjs/SankeyChart.js +6 -0
  121. package/lib-commonjs/SankeyChart.js.map +1 -0
  122. package/lib-commonjs/VerticalStackedBarChart.js +6 -0
  123. package/lib-commonjs/VerticalStackedBarChart.js.map +1 -0
  124. package/lib-commonjs/components/AreaChart/AreaChart.js +781 -0
  125. package/lib-commonjs/components/AreaChart/AreaChart.js.map +1 -0
  126. package/lib-commonjs/components/AreaChart/AreaChart.types.js +7 -0
  127. package/lib-commonjs/components/AreaChart/AreaChart.types.js.map +1 -0
  128. package/lib-commonjs/components/AreaChart/index.js +8 -0
  129. package/lib-commonjs/components/AreaChart/index.js.map +1 -0
  130. package/lib-commonjs/components/AreaChart/useAreaChartStyles.styles.js +95 -0
  131. package/lib-commonjs/components/AreaChart/useAreaChartStyles.styles.js.map +1 -0
  132. package/lib-commonjs/components/CommonComponents/CartesianChart.js +29 -14
  133. package/lib-commonjs/components/CommonComponents/CartesianChart.js.map +1 -1
  134. package/lib-commonjs/components/CommonComponents/CartesianChart.types.js.map +1 -1
  135. package/lib-commonjs/components/CommonComponents/ChartPopover.js +2 -2
  136. package/lib-commonjs/components/CommonComponents/ChartPopover.js.map +1 -1
  137. package/lib-commonjs/components/CommonComponents/useCartesianChartStyles.styles.js +8 -198
  138. package/lib-commonjs/components/CommonComponents/useCartesianChartStyles.styles.js.map +1 -1
  139. package/lib-commonjs/components/CommonComponents/useChartPopoverStyles.styles.js +12 -37
  140. package/lib-commonjs/components/CommonComponents/useChartPopoverStyles.styles.js.map +1 -1
  141. package/lib-commonjs/components/DeclarativeChart/DeclarativeChart.js +120 -73
  142. package/lib-commonjs/components/DeclarativeChart/DeclarativeChart.js.map +1 -1
  143. package/lib-commonjs/components/DeclarativeChart/PlotlySchemaAdapter.js +592 -178
  144. package/lib-commonjs/components/DeclarativeChart/PlotlySchemaAdapter.js.map +1 -1
  145. package/lib-commonjs/components/DonutChart/Arc/Arc.js +1 -1
  146. package/lib-commonjs/components/DonutChart/Arc/Arc.js.map +1 -1
  147. package/lib-commonjs/components/DonutChart/DonutChart.js +1 -1
  148. package/lib-commonjs/components/DonutChart/DonutChart.js.map +1 -1
  149. package/lib-commonjs/components/DonutChart/Pie/usePieStyles.styles.js +3 -10
  150. package/lib-commonjs/components/DonutChart/Pie/usePieStyles.styles.js.map +1 -1
  151. package/lib-commonjs/components/GaugeChart/GaugeChart.js +4 -1
  152. package/lib-commonjs/components/GaugeChart/GaugeChart.js.map +1 -1
  153. package/lib-commonjs/components/GaugeChart/GaugeChart.types.js.map +1 -1
  154. package/lib-commonjs/components/GaugeChart/useGaugeChartStyles.styles.js +14 -8
  155. package/lib-commonjs/components/GaugeChart/useGaugeChartStyles.styles.js.map +1 -1
  156. package/lib-commonjs/components/GroupedVerticalBarChart/GroupedVerticalBarChart.js +9 -0
  157. package/lib-commonjs/components/GroupedVerticalBarChart/GroupedVerticalBarChart.js.map +1 -1
  158. package/lib-commonjs/components/GroupedVerticalBarChart/useGroupedVerticalBarChartStyles.styles.js +0 -9
  159. package/lib-commonjs/components/GroupedVerticalBarChart/useGroupedVerticalBarChartStyles.styles.js.map +1 -1
  160. package/lib-commonjs/components/HeatMapChart/HeatMapChart.js +599 -0
  161. package/lib-commonjs/components/HeatMapChart/HeatMapChart.js.map +1 -0
  162. package/lib-commonjs/components/HeatMapChart/HeatMapChart.types.js +7 -0
  163. package/lib-commonjs/components/HeatMapChart/HeatMapChart.types.js.map +1 -0
  164. package/lib-commonjs/components/HeatMapChart/index.js +8 -0
  165. package/lib-commonjs/components/HeatMapChart/index.js.map +1 -0
  166. package/lib-commonjs/components/HeatMapChart/useHeatMapChartStyles.styles.js +59 -0
  167. package/lib-commonjs/components/HeatMapChart/useHeatMapChartStyles.styles.js.map +1 -0
  168. package/lib-commonjs/components/HorizontalBarChart/useHorizontalBarChartStyles.styles.js +2 -16
  169. package/lib-commonjs/components/HorizontalBarChart/useHorizontalBarChartStyles.styles.js.map +1 -1
  170. package/lib-commonjs/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.js +580 -0
  171. package/lib-commonjs/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.js.map +1 -0
  172. package/lib-commonjs/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.types.js +7 -0
  173. package/lib-commonjs/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.types.js.map +1 -0
  174. package/lib-commonjs/components/HorizontalBarChartWithAxis/index.js +8 -0
  175. package/lib-commonjs/components/HorizontalBarChartWithAxis/index.js.map +1 -0
  176. package/lib-commonjs/components/HorizontalBarChartWithAxis/useHorizontalBarChartWithAxisStyles.styles.js +107 -0
  177. package/lib-commonjs/components/HorizontalBarChartWithAxis/useHorizontalBarChartWithAxisStyles.styles.js.map +1 -0
  178. package/lib-commonjs/components/Legends/Legends.js +37 -37
  179. package/lib-commonjs/components/Legends/Legends.js.map +1 -1
  180. package/lib-commonjs/components/Legends/useLegendsStyles.styles.js +2 -2
  181. package/lib-commonjs/components/Legends/useLegendsStyles.styles.js.map +1 -1
  182. package/lib-commonjs/components/LineChart/LineChart.js +41 -33
  183. package/lib-commonjs/components/LineChart/LineChart.js.map +1 -1
  184. package/lib-commonjs/components/LineChart/useLineChartStyles.styles.js +1 -10
  185. package/lib-commonjs/components/LineChart/useLineChartStyles.styles.js.map +1 -1
  186. package/lib-commonjs/components/SankeyChart/SankeyChart.js +1039 -0
  187. package/lib-commonjs/components/SankeyChart/SankeyChart.js.map +1 -0
  188. package/lib-commonjs/components/SankeyChart/SankeyChart.types.js +6 -0
  189. package/lib-commonjs/components/SankeyChart/SankeyChart.types.js.map +1 -0
  190. package/lib-commonjs/components/SankeyChart/index.js +8 -0
  191. package/lib-commonjs/components/SankeyChart/index.js.map +1 -0
  192. package/lib-commonjs/components/SankeyChart/useSankeyChartStyles.styles.js +179 -0
  193. package/lib-commonjs/components/SankeyChart/useSankeyChartStyles.styles.js.map +1 -0
  194. package/lib-commonjs/components/ScatterChart/ScatterChart.js +45 -58
  195. package/lib-commonjs/components/ScatterChart/ScatterChart.js.map +1 -1
  196. package/lib-commonjs/components/ScatterChart/useScatterChartStyles.styles.js +1 -10
  197. package/lib-commonjs/components/ScatterChart/useScatterChartStyles.styles.js.map +1 -1
  198. package/lib-commonjs/components/VerticalBarChart/VerticalBarChart.js +164 -87
  199. package/lib-commonjs/components/VerticalBarChart/VerticalBarChart.js.map +1 -1
  200. package/lib-commonjs/components/VerticalBarChart/VerticalBarChart.types.js.map +1 -1
  201. package/lib-commonjs/components/VerticalBarChart/useVerticalBarChartStyles.styles.js +4 -11
  202. package/lib-commonjs/components/VerticalBarChart/useVerticalBarChartStyles.styles.js.map +1 -1
  203. package/lib-commonjs/components/VerticalStackedBarChart/VerticalStackedBarChart.js +915 -0
  204. package/lib-commonjs/components/VerticalStackedBarChart/VerticalStackedBarChart.js.map +1 -0
  205. package/lib-commonjs/components/VerticalStackedBarChart/VerticalStackedBarChart.types.js +6 -0
  206. package/lib-commonjs/components/VerticalStackedBarChart/VerticalStackedBarChart.types.js.map +1 -0
  207. package/lib-commonjs/components/VerticalStackedBarChart/index.js +8 -0
  208. package/lib-commonjs/components/VerticalStackedBarChart/index.js.map +1 -0
  209. package/lib-commonjs/components/VerticalStackedBarChart/useVerticalStackedBarChartStyles.styles.js +113 -0
  210. package/lib-commonjs/components/VerticalStackedBarChart/useVerticalStackedBarChartStyles.styles.js.map +1 -0
  211. package/lib-commonjs/index.js +5 -0
  212. package/lib-commonjs/index.js.map +1 -1
  213. package/lib-commonjs/types/DataPoint.js +1 -3
  214. package/lib-commonjs/types/DataPoint.js.map +1 -1
  215. package/lib-commonjs/utilities/SVGTooltipText.js +49 -4
  216. package/lib-commonjs/utilities/SVGTooltipText.js.map +1 -1
  217. package/lib-commonjs/utilities/colors.js +23 -0
  218. package/lib-commonjs/utilities/colors.js.map +1 -1
  219. package/lib-commonjs/utilities/string.js +29 -0
  220. package/lib-commonjs/utilities/string.js.map +1 -0
  221. package/lib-commonjs/utilities/test-data.js +59 -0
  222. package/lib-commonjs/utilities/test-data.js.map +1 -1
  223. package/lib-commonjs/utilities/utilities.js +94 -17
  224. package/lib-commonjs/utilities/utilities.js.map +1 -1
  225. package/package.json +11 -8
  226. package/lib/components/DeclarativeChart/PlotlySchema.js +0 -7
  227. package/lib/components/DeclarativeChart/PlotlySchema.js.map +0 -1
  228. package/lib-commonjs/components/DeclarativeChart/PlotlySchema.js +0 -10
  229. package/lib-commonjs/components/DeclarativeChart/PlotlySchema.js.map +0 -1
@@ -0,0 +1,1023 @@
1
+ import * as React from 'react';
2
+ import { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';
3
+ import { tokens } from '@fluentui/react-theme';
4
+ import { useId } from '@fluentui/react-utilities';
5
+ import { sum as d3Sum } from 'd3-array';
6
+ import { sankey as d3Sankey, sankeyJustify, sankeyRight } from 'd3-sankey';
7
+ import { select, selectAll } from 'd3-selection';
8
+ import { area as d3Area, curveBumpX as d3CurveBasis } from 'd3-shape';
9
+ import { useSankeyChartStyles } from './useSankeyChartStyles.styles';
10
+ import { ChartPopover } from '../CommonComponents/index';
11
+ import { useArrowNavigationGroup } from '@fluentui/react-tabster';
12
+ import { format } from '../../utilities/string';
13
+ const PADDING_PERCENTAGE = 0.3;
14
+ const NON_SELECTED_NODE_AND_STREAM_COLOR = '#757575';
15
+ const DEFAULT_NODE_COLORS = [
16
+ {
17
+ fillColor: '#00758F',
18
+ borderColor: '#002E39'
19
+ },
20
+ {
21
+ fillColor: '#77004D',
22
+ borderColor: '#43002C'
23
+ },
24
+ {
25
+ fillColor: '#4F6BED',
26
+ borderColor: '#3B52B4'
27
+ },
28
+ {
29
+ fillColor: '#937600',
30
+ borderColor: '#6D5700'
31
+ },
32
+ {
33
+ fillColor: '#286EA8',
34
+ borderColor: '#00457E'
35
+ },
36
+ {
37
+ fillColor: '#A43FB1',
38
+ borderColor: '#7C158A'
39
+ },
40
+ {
41
+ fillColor: '#CC3595',
42
+ borderColor: '#7F215D'
43
+ },
44
+ {
45
+ fillColor: '#0E7878',
46
+ borderColor: '#004E4E'
47
+ },
48
+ {
49
+ fillColor: '#8764B8',
50
+ borderColor: '#4B3867'
51
+ },
52
+ {
53
+ fillColor: '#9C663F',
54
+ borderColor: '#6D4123'
55
+ }
56
+ ];
57
+ const MIN_HEIGHT_FOR_DOUBLINE_TYPE = 36;
58
+ const MIN_HEIGHT_FOR_TYPE = 24;
59
+ const REST_STREAM_OPACITY = 1;
60
+ const NON_SELECTED_OPACITY = 1;
61
+ const SELECTED_STREAM_OPACITY = 0.3;
62
+ const NON_SELECTED_STREAM_BORDER_OPACITY = 0.5;
63
+ const DEFAULT_TEXT_COLOR = '#323130';
64
+ const NON_SELECTED_TEXT_COLOR = '#FFFFFF';
65
+ const NODE_WIDTH = 124;
66
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
67
+ function getSelectedNodes(selectedLinks) {
68
+ const nodes = [];
69
+ selectedLinks.forEach((link)=>{
70
+ nodes.push(link.target);
71
+ if (nodes.indexOf(link.source) === -1) {
72
+ nodes.push(link.source);
73
+ }
74
+ });
75
+ return nodes;
76
+ }
77
+ function getSelectedLinks(singleNode) {
78
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, no-array-constructor
79
+ const q = new Array();
80
+ const finalLinks = new Set();
81
+ singleNode.sourceLinks.forEach((link)=>{
82
+ q.push(link);
83
+ finalLinks.add(link);
84
+ });
85
+ while(q.length > 0){
86
+ const poppedLink = q.shift();
87
+ const node = poppedLink.target;
88
+ if (node && node.sourceLinks) {
89
+ node.sourceLinks.forEach((link)=>{
90
+ finalLinks.add(link);
91
+ q.push(link);
92
+ });
93
+ }
94
+ }
95
+ if (singleNode.targetLinks) {
96
+ singleNode.targetLinks.forEach((link)=>{
97
+ q.push(link);
98
+ finalLinks.add(link);
99
+ });
100
+ }
101
+ while(q.length > 0){
102
+ const poppedLink = q.shift();
103
+ const node = poppedLink.source;
104
+ if (node && node.targetLinks) {
105
+ node.targetLinks.forEach((link)=>{
106
+ finalLinks.add(link);
107
+ q.push(link);
108
+ });
109
+ }
110
+ }
111
+ return finalLinks;
112
+ }
113
+ function getSelectedLinksforStreamHover(singleLink) {
114
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, no-array-constructor
115
+ const q = new Array();
116
+ const finalLinks = new Set();
117
+ const finalNodes = new Set();
118
+ q.push(singleLink.source);
119
+ finalLinks.add(singleLink);
120
+ while(q.length > 0){
121
+ const poppedNode = q.shift();
122
+ finalNodes.add(poppedNode);
123
+ if (poppedNode.targetLinks && poppedNode.targetLinks.length > 0) {
124
+ poppedNode.targetLinks.forEach((link)=>{
125
+ q.push(link.source);
126
+ finalLinks.add(link);
127
+ });
128
+ }
129
+ }
130
+ q.push(singleLink.target);
131
+ while(q.length > 0){
132
+ const poppedNode = q.shift();
133
+ finalNodes.add(poppedNode);
134
+ if (poppedNode.sourceLinks && poppedNode.sourceLinks.length > 0) {
135
+ poppedNode.sourceLinks.forEach((link)=>{
136
+ q.push(link.target);
137
+ finalLinks.add(link);
138
+ });
139
+ }
140
+ }
141
+ return {
142
+ selectedLinks: finalLinks,
143
+ selectedNodes: finalNodes
144
+ };
145
+ }
146
+ /**
147
+ * This is used to group nodes by column index.
148
+ */ // This is exported for unit tests.
149
+ export function groupNodesByColumn(graph) {
150
+ const nodesInColumn = {};
151
+ graph.nodes.forEach((node)=>{
152
+ const columnId = node.layer;
153
+ if (nodesInColumn[columnId]) {
154
+ nodesInColumn[columnId].push(node);
155
+ } else {
156
+ nodesInColumn[columnId] = [
157
+ node
158
+ ];
159
+ }
160
+ });
161
+ return nodesInColumn;
162
+ }
163
+ /**
164
+ * This is used to normalize the nodes value whose value is less than 1% of the total column value.
165
+ */ function adjustOnePercentHeightNodes(nodesInColumn, computedNodes, originalLinks) {
166
+ const totalColumnValue = Object.values(nodesInColumn).map((column)=>{
167
+ return d3Sum(column, (node)=>node.value);
168
+ });
169
+ totalColumnValue.forEach((columnValue, index)=>{
170
+ let totalPercentage = 0;
171
+ const onePercent = 0.01 * columnValue;
172
+ const columnNodes = nodesInColumn[index];
173
+ columnNodes.forEach((node)=>{
174
+ const value = computedNodes[node.nodeId];
175
+ const nodePercentage = value / columnValue * 100;
176
+ node.actualValue = value;
177
+ //if the value is less than 1% then we are making it as 1% of total .
178
+ if (nodePercentage < 1) {
179
+ node.value = onePercent;
180
+ totalPercentage = totalPercentage + 1;
181
+ } else {
182
+ totalPercentage = totalPercentage + nodePercentage;
183
+ }
184
+ });
185
+ //since we have adjusted the value to be 1% but we need to keep the sum of the percentage value under 100.
186
+ const scalingRatio = totalPercentage !== 0 ? totalPercentage / 100 : 1;
187
+ if (scalingRatio > 1) {
188
+ // Loop through each node in that column and scale that node--and its incoming and outgoing links--by the
189
+ // scaling ratio. We need the sankey diagram to re-layout the nodes and links after we do this.
190
+ columnNodes.forEach((node)=>{
191
+ const normalized = node.value = node.value / scalingRatio;
192
+ // Which Original Value? and Which Normalized Value is needed, here? The Node? The Link? Both?
193
+ changeColumnValue(node, computedNodes[node.nodeId], normalized, originalLinks);
194
+ });
195
+ }
196
+ });
197
+ }
198
+ /**
199
+ * This is used for normalizing each link's value to reflect the normalized node value.
200
+ */ function changeColumnValue(node, originalNodeValue, normalizedNodeValue, linkValues) {
201
+ // For each link in the source and target, compute the proportion that this link contributes to the total
202
+ // then adjust the link's value to reflect its proportion of the normalized node value.
203
+ const updateLinkValue = (link)=>{
204
+ const value = linkValue(linkValues, link);
205
+ link.unnormalizedValue = value;
206
+ const linkRatio = value / originalNodeValue;
207
+ link.value = Math.max(normalizedNodeValue * linkRatio, link.value);
208
+ };
209
+ node.sourceLinks.forEach(updateLinkValue);
210
+ node.targetLinks.forEach(updateLinkValue);
211
+ }
212
+ /**
213
+ * This is used for calculating the node non normalized value based on link non normalized value.
214
+ * The links have the original weights. Computed nodes have the total weight of all incoming and outgoing links.
215
+ */ function populateNodeActualValue(data, computedNodes, originalLinks) {
216
+ data.links.forEach((link)=>{
217
+ if (!link.unnormalizedValue) {
218
+ link.unnormalizedValue = linkValue(originalLinks, link);
219
+ }
220
+ });
221
+ data.nodes.forEach((node)=>{
222
+ node.actualValue = computedNodes[node.nodeId];
223
+ });
224
+ }
225
+ /**
226
+ * This is used to introduce dynamic padding for cases where the number of nodes in a column is huge
227
+ * so that we maintain a node to space ratio for such columns as if we fail to do so the
228
+ * chart is devoid of nodes and only shows links.
229
+ */ // This is exported for unit tests
230
+ export function adjustPadding(sankey, height, nodesInColumn) {
231
+ let padding = sankey.nodePadding();
232
+ const minPadding = PADDING_PERCENTAGE * height;
233
+ Object.values(nodesInColumn).forEach((column)=>{
234
+ const totalPaddingInColumn = height - d3Sum(column, (node)=>node.y1 - node.y0);
235
+ if (minPadding < totalPaddingInColumn) {
236
+ // Here we are calculating the min of default and calculated padding, we will not increase the padding
237
+ // in any scenario.
238
+ padding = Math.min(padding, minPadding / (column.length - 1));
239
+ }
240
+ });
241
+ sankey.nodePadding(padding);
242
+ }
243
+ function idFromNumberOrSNode(node) {
244
+ if (typeof node === 'number') {
245
+ return node;
246
+ }
247
+ return node.nodeId;
248
+ }
249
+ /**
250
+ * Duplicates the supplied chart data so that we do not alter the original.
251
+ * @param data The data to duplicate.
252
+ * @returns The duplicated data.
253
+ */ function duplicateData(data) {
254
+ return {
255
+ nodes: data.nodes.map((node)=>({
256
+ ...node
257
+ })),
258
+ links: data.links.map((link)=>({
259
+ ...link
260
+ }))
261
+ };
262
+ }
263
+ function valuesOfNodes(nodes) {
264
+ const result = {};
265
+ nodes.forEach((node)=>{
266
+ result[node.nodeId] = node.value;
267
+ });
268
+ return result;
269
+ }
270
+ function valuesOfLinks(links) {
271
+ const result = {};
272
+ links.forEach((link)=>{
273
+ const sourceId = idFromNumberOrSNode(link.source);
274
+ let sourceToTarget = result[sourceId];
275
+ if (!sourceToTarget) {
276
+ sourceToTarget = {};
277
+ result[sourceId] = sourceToTarget;
278
+ }
279
+ sourceToTarget[idFromNumberOrSNode(link.target)] = link.value;
280
+ });
281
+ return result;
282
+ }
283
+ function linkValue(originalLinks, link) {
284
+ return originalLinks[idFromNumberOrSNode(link.source)][idFromNumberOrSNode(link.target)];
285
+ }
286
+ // This is exported for unit tests.
287
+ export function preRenderLayout(margins, containerWidth, containerHeight, isRtl) {
288
+ const { left, right, top, bottom } = margins;
289
+ const width = containerWidth - right;
290
+ const height = containerHeight - bottom > 0 ? containerHeight - bottom : 0;
291
+ const sankey = d3Sankey().nodeWidth(NODE_WIDTH).extent([
292
+ [
293
+ left,
294
+ top
295
+ ],
296
+ [
297
+ width - 1,
298
+ height - 6
299
+ ]
300
+ ]).nodeAlign(isRtl ? sankeyRight : sankeyJustify);
301
+ return {
302
+ sankey,
303
+ height,
304
+ width
305
+ };
306
+ }
307
+ const elipsis = '...';
308
+ /**
309
+ * This is used to assign node fillcolors and borderColor cyclically when the user doesnt
310
+ * provide color to individual node.
311
+ */ function assignNodeColors(nodes, colorsForNodes, borderColorsForNodes) {
312
+ let colors;
313
+ let borders;
314
+ if (colorsForNodes && borderColorsForNodes) {
315
+ colors = colorsForNodes;
316
+ borders = borderColorsForNodes;
317
+ } else {
318
+ colors = DEFAULT_NODE_COLORS.map((color)=>color.fillColor);
319
+ borders = DEFAULT_NODE_COLORS.map((color)=>color.borderColor);
320
+ }
321
+ let currentIndex = 0;
322
+ nodes.forEach((node)=>{
323
+ if (!node.color && !node.borderColor) {
324
+ node.color = colors[currentIndex];
325
+ node.borderColor = borders[currentIndex];
326
+ } else if (node.color && !node.borderColor) {
327
+ node.borderColor = '#757575';
328
+ } else if (node.borderColor && !node.color) {
329
+ node.color = '#F5F5F5';
330
+ }
331
+ currentIndex = (currentIndex + 1) % colors.length;
332
+ });
333
+ }
334
+ /**
335
+ * Takes in the display name for the node and potentially returns a trimmed version of the name.
336
+ * @param tspan the `tspan` element to use for text visual length measurement
337
+ * @param text is the text which we will potentially truncate
338
+ * @param rectangleWidth is the width of the rectangle which will contain the text
339
+ * @param padding is the space we need to leave between the rect lines and other text
340
+ * @returns the name to show on the node which might be the truncated `text` if the `text` is too long
341
+ */ function truncateText(tspan, text, rectangleWidth, padding) {
342
+ // NOTE: This method is the most-expensive in terms of rerendering components.
343
+ const textLengthForNodeName = rectangleWidth - padding; // This can likely be computed once and passed in.
344
+ // The following `select` statement injects a `tempText` element into the DOM. This injection
345
+ // (and subsequent removal) is causing a layout recalculation. This is a performance issue.
346
+ // Note that this code will always inject a `tempText` element, but doesn't always remove it. This is a bug.
347
+ if (fitsWithinNode(tspan, text, textLengthForNodeName)) {
348
+ return text;
349
+ }
350
+ // Computing the size of elipsis is performed with each node. This should be computed once and used everywhere.
351
+ // TODO: Compute the size of the elipsis once and use it everywhere.
352
+ const elipsisLength = computeElipsisLength(tspan);
353
+ let line = '';
354
+ // Calculate how much of the original text to show.
355
+ // TODO: The folllowing is O(n). We could use a binary search to make this faster: O(log(n)).
356
+ for(let i = 0; i < text.length; i++){
357
+ line += text[i];
358
+ tspan.text(line);
359
+ const currentNode = tspan.node();
360
+ if (currentNode !== null) {
361
+ const w = currentNode.getComputedTextLength();
362
+ if (w >= textLengthForNodeName - elipsisLength) {
363
+ line = line.slice(0, -1);
364
+ line += elipsis;
365
+ break;
366
+ }
367
+ }
368
+ }
369
+ tspan.text(null);
370
+ return line;
371
+ }
372
+ function fitsWithinNode(tspan, text, textLengthForNodeName) {
373
+ const measurement = measureText(tspan, text);
374
+ if (measurement === undefined) {
375
+ return false;
376
+ }
377
+ return measurement <= textLengthForNodeName;
378
+ }
379
+ function measureText(tspan, text) {
380
+ try {
381
+ var _tspan_node;
382
+ tspan.text(text);
383
+ return (_tspan_node = tspan.node()) === null || _tspan_node === void 0 ? void 0 : _tspan_node.getComputedTextLength();
384
+ } finally{
385
+ tspan.text(null);
386
+ }
387
+ }
388
+ function computeElipsisLength(tspan) {
389
+ const measurement = measureText(tspan, elipsis);
390
+ return measurement === undefined ? 0 : measurement;
391
+ }
392
+ function computeLinkAttributes(links, linkFrom, linkAriaLabel, linkId) {
393
+ const result = {};
394
+ links.forEach((link, index)=>{
395
+ const sourceId = idFromNumberOrSNode(link.source);
396
+ let sourceToTarget = result[sourceId];
397
+ if (!sourceToTarget) {
398
+ sourceToTarget = {};
399
+ result[sourceId] = sourceToTarget;
400
+ }
401
+ sourceToTarget[idFromNumberOrSNode(link.target)] = {
402
+ reactId: `${linkId}-${index}`,
403
+ from: linkFrom(link.source),
404
+ aria: linkAriaLabel(link)
405
+ };
406
+ });
407
+ return result;
408
+ }
409
+ const linkToDataPoints = (d)=>{
410
+ const halfWidth = d.width * 0.5;
411
+ const y0 = d.y0;
412
+ const y1 = d.y1;
413
+ return [
414
+ {
415
+ x: d.source.x1,
416
+ y0: y0 + halfWidth,
417
+ y1: y0 - halfWidth
418
+ },
419
+ {
420
+ x: d.target.x0,
421
+ y0: y1 + halfWidth,
422
+ y1: y1 - halfWidth
423
+ }
424
+ ];
425
+ };
426
+ const linkArea = d3Area().x((p)=>p.x).y0((p)=>p.y0).y1((p)=>p.y1).curve(d3CurveBasis);
427
+ function nodeTextColor(state, singleNode) {
428
+ return !(!state.selectedState || state.selectedNodes.has(singleNode.index) && state.selectedNode || !state.selectedNode) ? DEFAULT_TEXT_COLOR : NON_SELECTED_TEXT_COLOR;
429
+ }
430
+ export const SankeyChart = /*#__PURE__*/ React.forwardRef((props, forwardedRef)=>{
431
+ const classes = useSankeyChartStyles(props);
432
+ const chartContainer = React.useRef(null);
433
+ const _reqID = React.useRef();
434
+ const _linkId = useId('link');
435
+ const _chartId = useId('sankeyChart');
436
+ const _emptyChartId = useId('_SankeyChart_empty');
437
+ const _labelTooltipId = useId('tooltip');
438
+ const _margins = React.useRef({
439
+ top: 36,
440
+ right: 48,
441
+ bottom: 32,
442
+ left: 48
443
+ });
444
+ const { targetDocument, dir } = useFluent();
445
+ const _window = targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.defaultView;
446
+ const _isRtl = dir === 'rtl';
447
+ const _numColumns = React.useRef(0);
448
+ const _nodeBarId = useId('nodeBar');
449
+ const _nodeGElementId = useId('nodeGElement');
450
+ const _arrowNavigationAttributes = useArrowNavigationGroup({
451
+ axis: 'vertical'
452
+ });
453
+ const _tooltip = React.useRef(null);
454
+ const [containerHeight, setContainerHeight] = React.useState(468);
455
+ const [containerWidth, setContainerWidth] = React.useState(912);
456
+ const [selectedState, setSelectedState] = React.useState(false);
457
+ const [selectedLinks, setSelectedLinks] = React.useState(new Set());
458
+ const [selectedNodes, setSelectedNodes] = React.useState(new Set());
459
+ const [isCalloutVisible, setCalloutVisible] = React.useState(false);
460
+ const [selectedNode, setSelectedNode] = React.useState();
461
+ const [color, setColor] = React.useState();
462
+ const [xCalloutValue, setXCalloutValue] = React.useState();
463
+ const [yCalloutValue, setYCalloutValue] = React.useState();
464
+ const [descriptionMessage, setDescriptionMessage] = React.useState();
465
+ const [clickPosition, setClickPosition] = React.useState({
466
+ x: 0,
467
+ y: 0
468
+ });
469
+ React.useImperativeHandle(props.componentRef, ()=>({
470
+ chartContainer: chartContainer.current
471
+ }), []);
472
+ const _fitParentContainer = React.useCallback(()=>{
473
+ _reqID.current = _window === null || _window === void 0 ? void 0 : _window.requestAnimationFrame(()=>{
474
+ // NOTE: Calls to this method trigger a re-render.
475
+ const container = props.parentRef ? props.parentRef : chartContainer.current;
476
+ if (container) {
477
+ const currentContainerWidth = props.enableReflow ? Math.max(container.getBoundingClientRect().width, _calculateChartMinWidth()) : container.getBoundingClientRect().width;
478
+ const currentContainerHeight = container.getBoundingClientRect().height;
479
+ setContainerWidth(currentContainerWidth);
480
+ setContainerHeight(currentContainerHeight);
481
+ }
482
+ });
483
+ }, [
484
+ _window,
485
+ props.enableReflow,
486
+ props.parentRef
487
+ ]);
488
+ React.useEffect(()=>{
489
+ _fitParentContainer();
490
+ return ()=>{
491
+ if (typeof _reqID.current === 'number') {
492
+ _window === null || _window === void 0 ? void 0 : _window.cancelAnimationFrame(_reqID.current);
493
+ }
494
+ };
495
+ }, [
496
+ _fitParentContainer,
497
+ _window,
498
+ props.shouldResize
499
+ ]);
500
+ const _formatNumber = React.useCallback((value)=>{
501
+ return props.formatNumberOptions ? value.toLocaleString(props.culture, props.formatNumberOptions) : value.toString();
502
+ }, [
503
+ props.formatNumberOptions,
504
+ props.culture
505
+ ]);
506
+ const _computeNodeAttributes = React.useCallback((nodes, nodeAriaLabel)=>{
507
+ const result = {};
508
+ const weightSpan = select('.nodeName').append('text').attr('class', 'tempText').append('tspan').text(null);
509
+ const nameSpan = select('.nodeName').append('text').attr('class', 'tempText').attr('font-size', '10').append('tspan').text(null);
510
+ nodes.forEach((singleNode, index)=>{
511
+ const height = Math.max(singleNode.y1 - singleNode.y0, 0);
512
+ let padding = 8;
513
+ let textLengthForNodeWeight = 0;
514
+ const nodeValue = singleNode.actualValue;
515
+ // If the nodeWeight is in the same line as node description an extra padding
516
+ // of 6 px is required between node description and node weight.
517
+ if (height < MIN_HEIGHT_FOR_DOUBLINE_TYPE) {
518
+ padding = padding + 6;
519
+ // The following `select` statement injects a `tempText` element into the DOM. This injection
520
+ // (and subsequent removal) is causing a layout recalculation. This is a performance issue.
521
+ const measurement = measureText(weightSpan, _formatNumber(nodeValue));
522
+ if (measurement !== undefined) {
523
+ textLengthForNodeWeight = measurement;
524
+ padding = padding + textLengthForNodeWeight;
525
+ }
526
+ }
527
+ // Since the total width of the node is 124 and we are giving margin of 8px from the left .
528
+ // So the actual value on which it will be truncated is 124-8=116.
529
+ const truncatedname = truncateText(nameSpan, singleNode.name, NODE_WIDTH - 8, padding);
530
+ const isTruncated = truncatedname.slice(-3) === elipsis;
531
+ result[singleNode.nodeId] = {
532
+ reactId: `${_nodeBarId}-${index}`,
533
+ gElementId: `${_nodeGElementId}-${index}`,
534
+ name: truncatedname,
535
+ aria: nodeAriaLabel(singleNode, nodeValue),
536
+ trimmed: isTruncated,
537
+ height,
538
+ weightOffset: textLengthForNodeWeight
539
+ };
540
+ });
541
+ selectAll('.tempText').remove();
542
+ return result;
543
+ }, [
544
+ _formatNumber,
545
+ _nodeBarId,
546
+ _nodeGElementId
547
+ ]);
548
+ const _linkCalloutAttributes = (singleLink, from)=>{
549
+ setCalloutVisible(true);
550
+ setColor(singleLink.source.color);
551
+ setXCalloutValue(singleLink.target.name);
552
+ setYCalloutValue(_formatNumber(singleLink.unnormalizedValue));
553
+ setDescriptionMessage(from);
554
+ };
555
+ const _isChartEmpty = React.useCallback(()=>{
556
+ var _props_data;
557
+ const sankeyChartData = (_props_data = props.data) === null || _props_data === void 0 ? void 0 : _props_data.SankeyChartData;
558
+ return !(sankeyChartData && sankeyChartData.nodes.length > 0 && sankeyChartData.links.length > 0);
559
+ }, [
560
+ props.data
561
+ ]);
562
+ const _normalizeSankeyData = React.useCallback((data, _containerWidth, _containerHeight, colorsForNodes, borderColorsForNodes)=>{
563
+ if (_isChartEmpty()) {
564
+ return {
565
+ width: 0,
566
+ height: 0,
567
+ nodes: [],
568
+ links: []
569
+ };
570
+ }
571
+ const { sankey, height, width } = preRenderLayout(_margins.current, _containerWidth, _containerHeight, _isRtl);
572
+ // Clone the data before mutating it (via the SankeyLayoutGenerator) so that we don't mutate the original data.
573
+ const transformed = duplicateData(data);
574
+ sankey(transformed);
575
+ // NOTE: After the prior line, `transformed` is now a more-complex object than the incoming `ISankeyChartData`.
576
+ // `transformed` should be cast to a more-specific type. This is a breaking change because we would be eliminating
577
+ // fields from `ISankeyChartData` and putting those fields on a now-local type. But doing so makes it clearer what
578
+ // the caller needs to supply and why. For example, the `actualValue` and `layer` fields of `ISNodeExtra` should
579
+ // both be moved. Similarly for `unnormalizedValue` in `ISLinkExtra`.
580
+ // `SankeyNodeMinimal` and `SankeyLinkMinimal` are both the types after `sankey(transformed)`, but have almost no
581
+ // bearing on the data before `sankey(transformed)` (which is basically nodes with ids and names along with links
582
+ // with source index, target index, and value).
583
+ const nodesInColumn = groupNodesByColumn(transformed);
584
+ _numColumns.current = Object.keys(nodesInColumn).length;
585
+ // Keep track of the original values of the links and their acccumulated values in the nodes
586
+ // Setting these in external objects so they cannot be mutated by other code.
587
+ // The IDs of nodes can be numbers or strings. But, the IDs of links are always the index into the "nodes" array.
588
+ // After the sankey layout is computed, the each link's `source` and `target` will have the ID of the node in the
589
+ // type originally specified in the Nodes array. Consequently, we get the values of those links after the sankey
590
+ // transformation.
591
+ const nodeValues = valuesOfNodes(transformed.nodes);
592
+ const linkValues = valuesOfLinks(transformed.links);
593
+ adjustOnePercentHeightNodes(nodesInColumn, nodeValues, linkValues);
594
+ adjustPadding(sankey, height - 6, nodesInColumn);
595
+ // `sankey` is called a second time, probably to re-layout the nodes with the one-percent adjusted weights.
596
+ // NOTE: The second call to `sankey` is required to allow links to be hoverable.
597
+ // Without the second call, the links are not hoverable.
598
+ sankey(transformed);
599
+ populateNodeActualValue(transformed, nodeValues, linkValues);
600
+ assignNodeColors(transformed.nodes, colorsForNodes, borderColorsForNodes);
601
+ return {
602
+ width,
603
+ height,
604
+ nodes: transformed.nodes,
605
+ links: transformed.links
606
+ };
607
+ }, [
608
+ _isChartEmpty,
609
+ _isRtl
610
+ ]);
611
+ const _createLinks = (dataLinks, linkAttributes)=>{
612
+ if (dataLinks) {
613
+ const linkId = _linkId;
614
+ return dataLinks.map((singleLink, index)=>{
615
+ const onMouseOut = ()=>{
616
+ _onStreamLeave(singleLink);
617
+ };
618
+ const { reactId, from, aria } = linkValue(linkAttributes, singleLink);
619
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
620
+ const dataPoints = linkToDataPoints(singleLink);
621
+ const key = `${linkId}-${index}`;
622
+ const gradientId = `gradient-${key}`;
623
+ const gradientUrl = `url(#${gradientId})`;
624
+ const source = singleLink.source;
625
+ const target = singleLink.target;
626
+ // TODO: localize the aria-label string
627
+ return /*#__PURE__*/ React.createElement("g", {
628
+ key: key
629
+ }, /*#__PURE__*/ React.createElement("defs", null, /*#__PURE__*/ React.createElement("linearGradient", {
630
+ id: gradientId,
631
+ x1: "0%",
632
+ y1: "0%",
633
+ x2: "100%",
634
+ y2: "0%"
635
+ }, /*#__PURE__*/ React.createElement("stop", {
636
+ offset: "0",
637
+ stopColor: source.color
638
+ }), /*#__PURE__*/ React.createElement("stop", {
639
+ offset: "100%",
640
+ stopColor: target.color
641
+ }))), /*#__PURE__*/ React.createElement("path", {
642
+ d: linkArea(dataPoints),
643
+ id: reactId,
644
+ fill: _fillStreamColors(singleLink, gradientUrl),
645
+ stroke: _fillStreamBorder(singleLink, gradientUrl),
646
+ strokeWidth: "2",
647
+ strokeOpacity: _getOpacityStreamBorder(singleLink),
648
+ onMouseOver: (event)=>_onStreamHover(event, singleLink, from),
649
+ onMouseOut: onMouseOut,
650
+ onFocus: (event)=>_onFocusLink(event, singleLink, from),
651
+ onBlur: _onBlur,
652
+ fillOpacity: _getOpacityStream(singleLink),
653
+ tabIndex: 0,
654
+ "aria-label": aria,
655
+ role: "img"
656
+ }));
657
+ });
658
+ }
659
+ return [];
660
+ };
661
+ const _createNodes = (dataNodes, nodeAttributes)=>{
662
+ if (dataNodes) {
663
+ const textAnchor = _isRtl ? 'end' : 'start';
664
+ return dataNodes.map((singleNode, index)=>{
665
+ const onMouseOut = ()=>{
666
+ _onLeave(singleNode);
667
+ };
668
+ const { reactId: nodeId, gElementId, height, trimmed: isTruncated, name: truncatedName, weightOffset: textLengthForNodeWeight, aria } = nodeAttributes[singleNode.nodeId];
669
+ const tooTall = height > MIN_HEIGHT_FOR_DOUBLINE_TYPE;
670
+ const { name, actualValue, x0, x1, y0 } = singleNode;
671
+ const textColor = nodeTextColor({
672
+ selectedState,
673
+ selectedNodes,
674
+ selectedNode
675
+ }, singleNode);
676
+ return /*#__PURE__*/ React.createElement("g", {
677
+ key: index,
678
+ id: gElementId
679
+ }, /*#__PURE__*/ React.createElement("rect", {
680
+ x: x0,
681
+ y: y0,
682
+ height: height,
683
+ width: x1 - x0,
684
+ fill: _fillNodeColors(singleNode),
685
+ id: nodeId,
686
+ onMouseOver: (e)=>_onHover(singleNode, e),
687
+ onMouseOut: onMouseOut,
688
+ onFocus: _onCloseCallout,
689
+ stroke: _fillNodeBorder(singleNode),
690
+ strokeWidth: "2",
691
+ opacity: "1",
692
+ tabIndex: 0,
693
+ "aria-label": aria,
694
+ role: "img"
695
+ }), height > MIN_HEIGHT_FOR_TYPE && /*#__PURE__*/ React.createElement("g", {
696
+ className: classes.nodeTextContainer
697
+ }, /*#__PURE__*/ React.createElement("g", {
698
+ className: "nodeName"
699
+ }, /*#__PURE__*/ React.createElement("text", {
700
+ id: `${nodeId}-name`,
701
+ x: x0,
702
+ y: y0,
703
+ dy: '1.2em',
704
+ dx: '0.4em',
705
+ textAnchor: textAnchor,
706
+ fontWeight: "regular",
707
+ "aria-hidden": "true",
708
+ fill: textColor,
709
+ fontSize: 10,
710
+ onMouseOver: (e)=>_showTooltip(name, isTruncated, e),
711
+ onMouseOut: ()=>_hideTooltip()
712
+ }, truncatedName)), /*#__PURE__*/ React.createElement("text", {
713
+ x: tooTall ? x0 : x1 - textLengthForNodeWeight - 8,
714
+ y: y0,
715
+ dy: tooTall ? '2em' : '1em',
716
+ dx: tooTall ? '0.4em' : '0em',
717
+ textAnchor: textAnchor,
718
+ fontWeight: "bold",
719
+ "aria-hidden": "true",
720
+ fill: textColor,
721
+ fontSize: 14
722
+ }, actualValue ? _formatNumber(actualValue) : actualValue)));
723
+ });
724
+ }
725
+ };
726
+ const _onLeave = (singleNode)=>{
727
+ if (selectedState) {
728
+ setSelectedState(false);
729
+ setSelectedNodes(new Set());
730
+ setSelectedLinks(new Set());
731
+ setSelectedNode(undefined);
732
+ }
733
+ };
734
+ const _onHover = (singleNode, mouseEvent)=>{
735
+ mouseEvent.persist();
736
+ _onCloseCallout();
737
+ if (!selectedState) {
738
+ const _selectedLinks = getSelectedLinks(singleNode);
739
+ const _selectedNodes = getSelectedNodes(_selectedLinks);
740
+ _selectedNodes.push(singleNode);
741
+ setSelectedState(true);
742
+ setSelectedNodes(new Set(Array.from(_selectedNodes).map((node)=>node.index)));
743
+ setSelectedLinks(new Set(Array.from(_selectedLinks).map((link)=>link.index)));
744
+ setSelectedNode(singleNode);
745
+ updatePosition(mouseEvent.clientX, mouseEvent.clientY);
746
+ setCalloutVisible(singleNode.y1 - singleNode.y0 < MIN_HEIGHT_FOR_TYPE);
747
+ setColor(singleNode.color);
748
+ setXCalloutValue(singleNode.name);
749
+ setYCalloutValue(_formatNumber(singleNode.actualValue));
750
+ }
751
+ };
752
+ const _onStreamHover = (mouseEvent, singleLink, from)=>{
753
+ mouseEvent.persist();
754
+ _onCloseCallout();
755
+ if (!selectedState) {
756
+ const { selectedLinks: _selectedLinks, selectedNodes: _selectedNodes } = getSelectedLinksforStreamHover(singleLink);
757
+ setSelectedState(true);
758
+ setSelectedNodes(new Set(Array.from(_selectedNodes).map((node)=>node.index)));
759
+ setSelectedLinks(new Set(Array.from(_selectedLinks).map((link)=>link.index)));
760
+ updatePosition(mouseEvent.clientX, mouseEvent.clientY);
761
+ _linkCalloutAttributes(singleLink, from);
762
+ }
763
+ };
764
+ const _onStreamLeave = (singleLink)=>{
765
+ if (selectedState) {
766
+ setSelectedState(false);
767
+ setSelectedNodes(new Set());
768
+ setSelectedLinks(new Set());
769
+ }
770
+ };
771
+ const _onFocusLink = (focusEvent, singleLink, from)=>{
772
+ // There is a big difference in how "Tab" and the "Arrow keys" are handled in this diagram.
773
+ // In particular, I would expect the "Down" key to be like "Tab", but it jumps a little wildly. I'm not sure
774
+ // if this behavior is an accessiblity violation, but it we might want to investigate it.
775
+ focusEvent.persist();
776
+ _onCloseCallout();
777
+ const boundingRect = focusEvent.currentTarget.getBoundingClientRect();
778
+ const clientX = boundingRect.left + boundingRect.width / 2;
779
+ const clientY = boundingRect.top + boundingRect.height / 2;
780
+ updatePosition(clientX, clientY);
781
+ _linkCalloutAttributes(singleLink, from);
782
+ };
783
+ const _onCloseCallout = ()=>{
784
+ setCalloutVisible(false);
785
+ updatePosition(0, 0);
786
+ setDescriptionMessage('');
787
+ };
788
+ const _onBlur = ()=>{
789
+ /**/ };
790
+ const _fillNodeColors = (singleNode)=>{
791
+ if (!selectedState) {
792
+ return singleNode.color;
793
+ } else {
794
+ if (selectedNode && selectedNodes.has(singleNode.index)) {
795
+ return selectedNode.color;
796
+ } else if (!selectedNode) {
797
+ return singleNode.color;
798
+ }
799
+ }
800
+ };
801
+ const _fillStreamColors = (singleLink, gradientUrl)=>{
802
+ if (selectedState && selectedLinks.has(singleLink.index)) {
803
+ return selectedNode ? selectedNode.color : gradientUrl;
804
+ }
805
+ };
806
+ const _fillStreamBorder = (singleLink, gradientUrl)=>{
807
+ if (!selectedState) {
808
+ return NON_SELECTED_NODE_AND_STREAM_COLOR;
809
+ } else {
810
+ if (selectedLinks.has(singleLink.index)) {
811
+ return selectedNode ? selectedNode.borderColor : gradientUrl;
812
+ }
813
+ return NON_SELECTED_NODE_AND_STREAM_COLOR;
814
+ }
815
+ };
816
+ const _fillNodeBorder = (singleNode)=>{
817
+ if (!selectedState) {
818
+ return singleNode.borderColor;
819
+ } else {
820
+ if (selectedNodes.has(singleNode.index)) {
821
+ return selectedNode ? selectedNode.borderColor : singleNode.borderColor;
822
+ }
823
+ return singleNode.borderColor;
824
+ }
825
+ };
826
+ const _getOpacityStream = (singleLink)=>{
827
+ if (selectedState) {
828
+ if (!selectedLinks.has(singleLink.index)) {
829
+ return NON_SELECTED_OPACITY;
830
+ } else if (!selectedNode) {
831
+ return SELECTED_STREAM_OPACITY;
832
+ }
833
+ }
834
+ return REST_STREAM_OPACITY;
835
+ };
836
+ const _getOpacityStreamBorder = (singleLink)=>{
837
+ if (selectedState && !selectedLinks.has(singleLink.index) && !selectedNode) {
838
+ return NON_SELECTED_STREAM_BORDER_OPACITY;
839
+ }
840
+ return NON_SELECTED_OPACITY;
841
+ };
842
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
843
+ const _showTooltip = (text, checkTrcuncated, evt)=>{
844
+ if (_tooltip.current && checkTrcuncated) {
845
+ //Fixing tooltip position by attaching it to the element rather than page
846
+ select(_tooltip.current).style('opacity', 0.9).style('color', tokens.colorNeutralForeground1).style('left', evt.pageX + 'px').style('top', evt.pageY - 28 + 'px').html(text);
847
+ }
848
+ };
849
+ const _hideTooltip = ()=>{
850
+ if (_tooltip.current) {
851
+ select(_tooltip.current).style('opacity', 0);
852
+ }
853
+ };
854
+ const _calculateChartMinWidth = ()=>{
855
+ return _margins.current.left + _margins.current.right + // total width of all node columns
856
+ _numColumns.current * NODE_WIDTH + // minimum total width of all column gaps
857
+ (_numColumns.current - 1) * (NODE_WIDTH / 2);
858
+ };
859
+ const updatePosition = (newX, newY)=>{
860
+ const threshold = 1; // Set a threshold for movement
861
+ const { x, y } = clickPosition;
862
+ // Calculate the distance moved
863
+ const distance = Math.sqrt(Math.pow(newX - x, 2) + Math.pow(newY - y, 2));
864
+ // Update the position only if the distance moved is greater than the threshold
865
+ if (distance > threshold) {
866
+ setClickPosition({
867
+ x: newX,
868
+ y: newY
869
+ });
870
+ }
871
+ };
872
+ // Prepare the localization utilities
873
+ const _strings = React.useMemo(()=>{
874
+ var _props_strings;
875
+ const fromString = ((_props_strings = props.strings) === null || _props_strings === void 0 ? void 0 : _props_strings.linkFrom) || 'From {0}';
876
+ // NOTE: The `node` parameter is the sankey-generated node on the link, and not the original `node` supplied
877
+ // by the caller.
878
+ return {
879
+ linkFrom: (node)=>format(fromString, node.name)
880
+ };
881
+ }, [
882
+ props.strings
883
+ ]);
884
+ const _accessibility = React.useMemo(()=>{
885
+ var _props_accessibility, _props_accessibility1, _props_accessibility2;
886
+ const linkString = ((_props_accessibility = props.accessibility) === null || _props_accessibility === void 0 ? void 0 : _props_accessibility.linkAriaLabel) || 'link from {0} to {1} with weight {2}';
887
+ const nodeString = ((_props_accessibility1 = props.accessibility) === null || _props_accessibility1 === void 0 ? void 0 : _props_accessibility1.nodeAriaLabel) || 'node {0} with weight {1}';
888
+ return {
889
+ emptyAriaLabel: ((_props_accessibility2 = props.accessibility) === null || _props_accessibility2 === void 0 ? void 0 : _props_accessibility2.emptyAriaLabel) || 'Graph has no data to display',
890
+ linkAriaLabel: (link)=>format(linkString, link.source.name, link.target.name, link.unnormalizedValue ? _formatNumber(link.unnormalizedValue) : link.unnormalizedValue),
891
+ nodeAriaLabel: (node, weight)=>format(nodeString, node.name, _formatNumber(weight))
892
+ };
893
+ }, [
894
+ _formatNumber,
895
+ props.accessibility
896
+ ]);
897
+ // Compute the position of each node and link
898
+ const { nodes, links, width, height } = React.useMemo(()=>_normalizeSankeyData(props.data.SankeyChartData, containerWidth, containerHeight, props.colorsForNodes, props.borderColorsForNodes), [
899
+ _normalizeSankeyData,
900
+ containerHeight,
901
+ containerWidth,
902
+ props.borderColorsForNodes,
903
+ props.colorsForNodes,
904
+ props.data
905
+ ]);
906
+ // Pre-compute some important attributes about nodes, specifically text
907
+ const nodeAttributes = React.useMemo(()=>_computeNodeAttributes(nodes, _accessibility.nodeAriaLabel), [
908
+ _accessibility,
909
+ _computeNodeAttributes,
910
+ nodes
911
+ ]);
912
+ const linkAttributes = React.useMemo(()=>computeLinkAttributes(links, _strings.linkFrom, _accessibility.linkAriaLabel, _linkId), [
913
+ _accessibility,
914
+ _linkId,
915
+ _strings,
916
+ links
917
+ ]);
918
+ if (!_isChartEmpty()) {
919
+ // In FocusZone, the focus order is determined by the rendering order of the elements. We need to find
920
+ // a rendering order such that the focus moves through the nodes and links in a logical sequence.
921
+ // Rendering the nodes and links layer by layer in a vertical order seems to be the most effective solution
922
+ // with FocusZone. Although this focus order may not be entirely logical, it ensures that the focus moves
923
+ // sequentially and prevents links (especially skip layer links) from being rendered over the nodes.
924
+ const nodeLinkDomOrderArray = [];
925
+ nodes.sort((a, b)=>{
926
+ if (a.x0 !== b.x0) {
927
+ return a.x0 - b.x0;
928
+ }
929
+ return a.y0 - b.y0;
930
+ });
931
+ nodes.forEach((item, index)=>{
932
+ nodeLinkDomOrderArray.push({
933
+ layer: item.layer,
934
+ type: 'node',
935
+ index
936
+ });
937
+ });
938
+ links.sort((a, b)=>{
939
+ const asx0 = a.source.x0;
940
+ const bsx0 = b.source.x0;
941
+ if (asx0 !== bsx0) {
942
+ return asx0 - bsx0;
943
+ }
944
+ return a.y0 - b.y0;
945
+ });
946
+ links.forEach((item, index)=>{
947
+ nodeLinkDomOrderArray.push({
948
+ layer: item.source.layer,
949
+ type: 'link',
950
+ index
951
+ });
952
+ });
953
+ nodeLinkDomOrderArray.sort((a, b)=>{
954
+ if (a.layer !== b.layer) {
955
+ return a.layer - b.layer;
956
+ }
957
+ if (a.type > b.type) {
958
+ return -1;
959
+ }
960
+ if (a.type < b.type) {
961
+ return 1;
962
+ }
963
+ return 0;
964
+ });
965
+ // Build the nodes and links as rendered in the UX.
966
+ const nodeData = _createNodes(nodes, nodeAttributes);
967
+ const linkData = _createLinks(links, linkAttributes);
968
+ const calloutProps = {
969
+ isPopoverOpen: isCalloutVisible,
970
+ clickPosition,
971
+ color,
972
+ XValue: xCalloutValue,
973
+ YValue: yCalloutValue,
974
+ descriptionMessage,
975
+ ...props.calloutProps
976
+ };
977
+ return /*#__PURE__*/ React.createElement("div", {
978
+ className: classes.root,
979
+ ref: chartContainer,
980
+ onMouseLeave: _onCloseCallout
981
+ }, /*#__PURE__*/ React.createElement("div", {
982
+ className: classes.chartWrapper,
983
+ ..._arrowNavigationAttributes
984
+ }, /*#__PURE__*/ React.createElement("svg", {
985
+ width: width,
986
+ height: height,
987
+ id: _chartId
988
+ }, nodeLinkDomOrderArray.map((item)=>{
989
+ if (item.type === 'node') {
990
+ return /*#__PURE__*/ React.createElement("g", {
991
+ key: nodes[item.index].nodeId,
992
+ className: classes.nodes
993
+ }, nodeData[item.index]);
994
+ } else {
995
+ return /*#__PURE__*/ React.createElement("g", {
996
+ key: `${links[item.index].source.nodeId}-${links[item.index].target.nodeId}`,
997
+ className: classes.links,
998
+ stroke: props.pathColor ? props.pathColor : tokens.colorStrokeFocus2,
999
+ strokeOpacity: 1
1000
+ }, linkData[item.index]);
1001
+ }
1002
+ }))), calloutProps.isPopoverOpen && /*#__PURE__*/ React.createElement(ChartPopover, calloutProps), /*#__PURE__*/ React.createElement("div", {
1003
+ id: _labelTooltipId,
1004
+ className: classes.toolTip,
1005
+ style: {
1006
+ opacity: 0
1007
+ },
1008
+ ref: _tooltip
1009
+ }));
1010
+ }
1011
+ return /*#__PURE__*/ React.createElement("div", {
1012
+ id: _emptyChartId,
1013
+ role: 'alert',
1014
+ style: {
1015
+ opacity: '0'
1016
+ },
1017
+ "aria-label": _accessibility.emptyAriaLabel
1018
+ });
1019
+ });
1020
+ SankeyChart.displayName = 'SankeyChart';
1021
+ SankeyChart.defaultProps = {
1022
+ enableReflow: true
1023
+ };