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