@fluentui/react-charts 9.0.1 → 9.0.3
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.
- package/CHANGELOG.md +58 -2
- package/dist/index.d.ts +1432 -238
- package/lib/AreaChart.js +1 -0
- package/lib/AreaChart.js.map +1 -0
- package/lib/GaugeChart.js +1 -0
- package/lib/GaugeChart.js.map +1 -0
- package/lib/GroupedVerticalBarChart.js +1 -0
- package/lib/GroupedVerticalBarChart.js.map +1 -0
- package/lib/HeatMapChart.js +1 -0
- package/lib/HeatMapChart.js.map +1 -0
- package/lib/HorizontalBarChartWithAxis.js +1 -0
- package/lib/HorizontalBarChartWithAxis.js.map +1 -0
- package/lib/SankeyChart.js +1 -0
- package/lib/SankeyChart.js.map +1 -0
- package/lib/ScatterChart.js +1 -0
- package/lib/ScatterChart.js.map +1 -0
- package/lib/VerticalStackedBarChart.js +1 -0
- package/lib/VerticalStackedBarChart.js.map +1 -0
- package/lib/components/AreaChart/AreaChart.js +775 -0
- package/lib/components/AreaChart/AreaChart.js.map +1 -0
- package/lib/components/AreaChart/AreaChart.types.js +4 -0
- package/lib/components/AreaChart/AreaChart.types.js.map +1 -0
- package/lib/components/AreaChart/index.js +3 -0
- package/lib/components/AreaChart/index.js.map +1 -0
- package/lib/components/AreaChart/useAreaChartStyles.styles.js +64 -0
- package/lib/components/AreaChart/useAreaChartStyles.styles.js.map +1 -0
- package/lib/components/CommonComponents/CartesianChart.js +30 -14
- package/lib/components/CommonComponents/CartesianChart.js.map +1 -1
- package/lib/components/CommonComponents/CartesianChart.types.js.map +1 -1
- package/lib/components/DeclarativeChart/DeclarativeChart.js +112 -65
- package/lib/components/DeclarativeChart/DeclarativeChart.js.map +1 -1
- package/lib/components/DeclarativeChart/PlotlySchemaAdapter.js +570 -159
- package/lib/components/DeclarativeChart/PlotlySchemaAdapter.js.map +1 -1
- package/lib/components/DonutChart/Arc/Arc.js +1 -1
- package/lib/components/DonutChart/Arc/Arc.js.map +1 -1
- package/lib/components/DonutChart/DonutChart.js +1 -1
- package/lib/components/DonutChart/DonutChart.js.map +1 -1
- package/lib/components/GaugeChart/GaugeChart.js +592 -0
- package/lib/components/GaugeChart/GaugeChart.js.map +1 -0
- package/lib/components/GaugeChart/GaugeChart.types.js +4 -0
- package/lib/components/GaugeChart/GaugeChart.types.js.map +1 -0
- package/lib/components/GaugeChart/index.js +3 -0
- package/lib/components/GaugeChart/index.js.map +1 -0
- package/lib/components/GaugeChart/useGaugeChartStyles.styles.js +174 -0
- package/lib/components/GaugeChart/useGaugeChartStyles.styles.js.map +1 -0
- package/lib/components/GroupedVerticalBarChart/GroupedVerticalBarChart.js +501 -0
- package/lib/components/GroupedVerticalBarChart/GroupedVerticalBarChart.js.map +1 -0
- package/lib/components/GroupedVerticalBarChart/GroupedVerticalBarChart.types.js +4 -0
- package/lib/components/GroupedVerticalBarChart/GroupedVerticalBarChart.types.js.map +1 -0
- package/lib/components/GroupedVerticalBarChart/index.js +3 -0
- package/lib/components/GroupedVerticalBarChart/index.js.map +1 -0
- package/lib/components/GroupedVerticalBarChart/useGroupedVerticalBarChartStyles.styles.js +90 -0
- package/lib/components/GroupedVerticalBarChart/useGroupedVerticalBarChartStyles.styles.js.map +1 -0
- package/lib/components/HeatMapChart/HeatMapChart.js +588 -0
- package/lib/components/HeatMapChart/HeatMapChart.js.map +1 -0
- package/lib/components/HeatMapChart/HeatMapChart.types.js +4 -0
- package/lib/components/HeatMapChart/HeatMapChart.types.js.map +1 -0
- package/lib/components/HeatMapChart/index.js +3 -0
- package/lib/components/HeatMapChart/index.js.map +1 -0
- package/lib/components/HeatMapChart/useHeatMapChartStyles.styles.js +46 -0
- package/lib/components/HeatMapChart/useHeatMapChartStyles.styles.js.map +1 -0
- package/lib/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.js +571 -0
- package/lib/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.js.map +1 -0
- package/lib/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.types.js +4 -0
- package/lib/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.types.js.map +1 -0
- package/lib/components/HorizontalBarChartWithAxis/index.js +3 -0
- package/lib/components/HorizontalBarChartWithAxis/index.js.map +1 -0
- package/lib/components/HorizontalBarChartWithAxis/useHorizontalBarChartWithAxisStyles.styles.js +76 -0
- package/lib/components/HorizontalBarChartWithAxis/useHorizontalBarChartWithAxisStyles.styles.js.map +1 -0
- package/lib/components/Legends/Legends.js +38 -37
- package/lib/components/Legends/Legends.js.map +1 -1
- package/lib/components/Legends/Legends.types.js.map +1 -1
- package/lib/components/LineChart/LineChart.js +43 -35
- package/lib/components/LineChart/LineChart.js.map +1 -1
- package/lib/components/SankeyChart/SankeyChart.js +1022 -0
- package/lib/components/SankeyChart/SankeyChart.js.map +1 -0
- package/lib/components/SankeyChart/SankeyChart.types.js +3 -0
- package/lib/components/SankeyChart/SankeyChart.types.js.map +1 -0
- package/lib/components/SankeyChart/index.js +3 -0
- package/lib/components/SankeyChart/index.js.map +1 -0
- package/lib/components/SankeyChart/useSankeyChartStyles.styles.js +109 -0
- package/lib/components/SankeyChart/useSankeyChartStyles.styles.js.map +1 -0
- package/lib/components/ScatterChart/ScatterChart.js +465 -0
- package/lib/components/ScatterChart/ScatterChart.js.map +1 -0
- package/lib/components/ScatterChart/ScatterChart.types.js +4 -0
- package/lib/components/ScatterChart/ScatterChart.types.js.map +1 -0
- package/lib/components/ScatterChart/index.js +3 -0
- package/lib/components/ScatterChart/index.js.map +1 -0
- package/lib/components/ScatterChart/useScatterChartStyles.styles.js +65 -0
- package/lib/components/ScatterChart/useScatterChartStyles.styles.js.map +1 -0
- package/lib/components/Sparkline/Sparkline.js.map +1 -1
- package/lib/components/VerticalBarChart/VerticalBarChart.js +165 -88
- package/lib/components/VerticalBarChart/VerticalBarChart.js.map +1 -1
- package/lib/components/VerticalBarChart/VerticalBarChart.types.js.map +1 -1
- package/lib/components/VerticalStackedBarChart/VerticalStackedBarChart.js +904 -0
- package/lib/components/VerticalStackedBarChart/VerticalStackedBarChart.js.map +1 -0
- package/lib/components/VerticalStackedBarChart/VerticalStackedBarChart.types.js +1 -0
- package/lib/components/VerticalStackedBarChart/VerticalStackedBarChart.types.js.map +1 -0
- package/lib/components/VerticalStackedBarChart/index.js +3 -0
- package/lib/components/VerticalStackedBarChart/index.js.map +1 -0
- package/lib/components/VerticalStackedBarChart/useVerticalStackedBarChartStyles.styles.js +73 -0
- package/lib/components/VerticalStackedBarChart/useVerticalStackedBarChartStyles.styles.js.map +1 -0
- package/lib/index.js +8 -0
- package/lib/index.js.map +1 -1
- package/lib/types/DataPoint.js +1 -3
- package/lib/types/DataPoint.js.map +1 -1
- package/lib/utilities/SVGTooltipText.js +49 -4
- package/lib/utilities/SVGTooltipText.js.map +1 -1
- package/lib/utilities/colors.js +20 -0
- package/lib/utilities/colors.js.map +1 -1
- package/lib/utilities/string.js +32 -0
- package/lib/utilities/string.js.map +1 -0
- package/lib/utilities/test-data.js +53 -0
- package/lib/utilities/test-data.js.map +1 -1
- package/lib/utilities/utilities.js +210 -20
- package/lib/utilities/utilities.js.map +1 -1
- package/lib-commonjs/AreaChart.js +6 -0
- package/lib-commonjs/AreaChart.js.map +1 -0
- package/lib-commonjs/GaugeChart.js +6 -0
- package/lib-commonjs/GaugeChart.js.map +1 -0
- package/lib-commonjs/GroupedVerticalBarChart.js +6 -0
- package/lib-commonjs/GroupedVerticalBarChart.js.map +1 -0
- package/lib-commonjs/HeatMapChart.js +6 -0
- package/lib-commonjs/HeatMapChart.js.map +1 -0
- package/lib-commonjs/HorizontalBarChartWithAxis.js +6 -0
- package/lib-commonjs/HorizontalBarChartWithAxis.js.map +1 -0
- package/lib-commonjs/SankeyChart.js +6 -0
- package/lib-commonjs/SankeyChart.js.map +1 -0
- package/lib-commonjs/ScatterChart.js +6 -0
- package/lib-commonjs/ScatterChart.js.map +1 -0
- package/lib-commonjs/VerticalStackedBarChart.js +6 -0
- package/lib-commonjs/VerticalStackedBarChart.js.map +1 -0
- package/lib-commonjs/components/AreaChart/AreaChart.js +781 -0
- package/lib-commonjs/components/AreaChart/AreaChart.js.map +1 -0
- package/lib-commonjs/components/AreaChart/AreaChart.types.js +7 -0
- package/lib-commonjs/components/AreaChart/AreaChart.types.js.map +1 -0
- package/lib-commonjs/components/AreaChart/index.js +8 -0
- package/lib-commonjs/components/AreaChart/index.js.map +1 -0
- package/lib-commonjs/components/AreaChart/useAreaChartStyles.styles.js +104 -0
- package/lib-commonjs/components/AreaChart/useAreaChartStyles.styles.js.map +1 -0
- package/lib-commonjs/components/CommonComponents/CartesianChart.js +29 -14
- package/lib-commonjs/components/CommonComponents/CartesianChart.js.map +1 -1
- package/lib-commonjs/components/CommonComponents/CartesianChart.types.js.map +1 -1
- package/lib-commonjs/components/DeclarativeChart/DeclarativeChart.js +120 -73
- package/lib-commonjs/components/DeclarativeChart/DeclarativeChart.js.map +1 -1
- package/lib-commonjs/components/DeclarativeChart/PlotlySchemaAdapter.js +592 -178
- package/lib-commonjs/components/DeclarativeChart/PlotlySchemaAdapter.js.map +1 -1
- package/lib-commonjs/components/DonutChart/Arc/Arc.js +1 -1
- package/lib-commonjs/components/DonutChart/Arc/Arc.js.map +1 -1
- package/lib-commonjs/components/DonutChart/DonutChart.js +1 -1
- package/lib-commonjs/components/DonutChart/DonutChart.js.map +1 -1
- package/lib-commonjs/components/GaugeChart/GaugeChart.js +621 -0
- package/lib-commonjs/components/GaugeChart/GaugeChart.js.map +1 -0
- package/lib-commonjs/components/GaugeChart/GaugeChart.types.js +7 -0
- package/lib-commonjs/components/GaugeChart/GaugeChart.types.js.map +1 -0
- package/lib-commonjs/components/GaugeChart/index.js +8 -0
- package/lib-commonjs/components/GaugeChart/index.js.map +1 -0
- package/lib-commonjs/components/GaugeChart/useGaugeChartStyles.styles.js +252 -0
- package/lib-commonjs/components/GaugeChart/useGaugeChartStyles.styles.js.map +1 -0
- package/lib-commonjs/components/GroupedVerticalBarChart/GroupedVerticalBarChart.js +507 -0
- package/lib-commonjs/components/GroupedVerticalBarChart/GroupedVerticalBarChart.js.map +1 -0
- package/lib-commonjs/components/GroupedVerticalBarChart/GroupedVerticalBarChart.types.js +7 -0
- package/lib-commonjs/components/GroupedVerticalBarChart/GroupedVerticalBarChart.types.js.map +1 -0
- package/lib-commonjs/components/GroupedVerticalBarChart/index.js +8 -0
- package/lib-commonjs/components/GroupedVerticalBarChart/index.js.map +1 -0
- package/lib-commonjs/components/GroupedVerticalBarChart/useGroupedVerticalBarChartStyles.styles.js +139 -0
- package/lib-commonjs/components/GroupedVerticalBarChart/useGroupedVerticalBarChartStyles.styles.js.map +1 -0
- package/lib-commonjs/components/HeatMapChart/HeatMapChart.js +599 -0
- package/lib-commonjs/components/HeatMapChart/HeatMapChart.js.map +1 -0
- package/lib-commonjs/components/HeatMapChart/HeatMapChart.types.js +7 -0
- package/lib-commonjs/components/HeatMapChart/HeatMapChart.types.js.map +1 -0
- package/lib-commonjs/components/HeatMapChart/index.js +8 -0
- package/lib-commonjs/components/HeatMapChart/index.js.map +1 -0
- package/lib-commonjs/components/HeatMapChart/useHeatMapChartStyles.styles.js +68 -0
- package/lib-commonjs/components/HeatMapChart/useHeatMapChartStyles.styles.js.map +1 -0
- package/lib-commonjs/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.js +580 -0
- package/lib-commonjs/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.js.map +1 -0
- package/lib-commonjs/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.types.js +7 -0
- package/lib-commonjs/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.types.js.map +1 -0
- package/lib-commonjs/components/HorizontalBarChartWithAxis/index.js +8 -0
- package/lib-commonjs/components/HorizontalBarChartWithAxis/index.js.map +1 -0
- package/lib-commonjs/components/HorizontalBarChartWithAxis/useHorizontalBarChartWithAxisStyles.styles.js +116 -0
- package/lib-commonjs/components/HorizontalBarChartWithAxis/useHorizontalBarChartWithAxisStyles.styles.js.map +1 -0
- package/lib-commonjs/components/Legends/Legends.js +37 -37
- package/lib-commonjs/components/Legends/Legends.js.map +1 -1
- package/lib-commonjs/components/Legends/Legends.types.js.map +1 -1
- package/lib-commonjs/components/LineChart/LineChart.js +41 -33
- package/lib-commonjs/components/LineChart/LineChart.js.map +1 -1
- package/lib-commonjs/components/SankeyChart/SankeyChart.js +1038 -0
- package/lib-commonjs/components/SankeyChart/SankeyChart.js.map +1 -0
- package/lib-commonjs/components/SankeyChart/SankeyChart.types.js +6 -0
- package/lib-commonjs/components/SankeyChart/SankeyChart.types.js.map +1 -0
- package/lib-commonjs/components/SankeyChart/index.js +8 -0
- package/lib-commonjs/components/SankeyChart/index.js.map +1 -0
- package/lib-commonjs/components/SankeyChart/useSankeyChartStyles.styles.js +179 -0
- package/lib-commonjs/components/SankeyChart/useSankeyChartStyles.styles.js.map +1 -0
- package/lib-commonjs/components/ScatterChart/ScatterChart.js +471 -0
- package/lib-commonjs/components/ScatterChart/ScatterChart.js.map +1 -0
- package/lib-commonjs/components/ScatterChart/ScatterChart.types.js +7 -0
- package/lib-commonjs/components/ScatterChart/ScatterChart.types.js.map +1 -0
- package/lib-commonjs/components/ScatterChart/index.js +8 -0
- package/lib-commonjs/components/ScatterChart/index.js.map +1 -0
- package/lib-commonjs/components/ScatterChart/useScatterChartStyles.styles.js +96 -0
- package/lib-commonjs/components/ScatterChart/useScatterChartStyles.styles.js.map +1 -0
- package/lib-commonjs/components/Sparkline/Sparkline.js.map +1 -1
- package/lib-commonjs/components/VerticalBarChart/VerticalBarChart.js +164 -87
- package/lib-commonjs/components/VerticalBarChart/VerticalBarChart.js.map +1 -1
- package/lib-commonjs/components/VerticalBarChart/VerticalBarChart.types.js.map +1 -1
- package/lib-commonjs/components/VerticalStackedBarChart/VerticalStackedBarChart.js +915 -0
- package/lib-commonjs/components/VerticalStackedBarChart/VerticalStackedBarChart.js.map +1 -0
- package/lib-commonjs/components/VerticalStackedBarChart/VerticalStackedBarChart.types.js +6 -0
- package/lib-commonjs/components/VerticalStackedBarChart/VerticalStackedBarChart.types.js.map +1 -0
- package/lib-commonjs/components/VerticalStackedBarChart/index.js +8 -0
- package/lib-commonjs/components/VerticalStackedBarChart/index.js.map +1 -0
- package/lib-commonjs/components/VerticalStackedBarChart/useVerticalStackedBarChartStyles.styles.js +120 -0
- package/lib-commonjs/components/VerticalStackedBarChart/useVerticalStackedBarChartStyles.styles.js.map +1 -0
- package/lib-commonjs/index.js +8 -0
- package/lib-commonjs/index.js.map +1 -1
- package/lib-commonjs/types/DataPoint.js +1 -3
- package/lib-commonjs/types/DataPoint.js.map +1 -1
- package/lib-commonjs/utilities/SVGTooltipText.js +49 -4
- package/lib-commonjs/utilities/SVGTooltipText.js.map +1 -1
- package/lib-commonjs/utilities/colors.js +23 -0
- package/lib-commonjs/utilities/colors.js.map +1 -1
- package/lib-commonjs/utilities/string.js +29 -0
- package/lib-commonjs/utilities/string.js.map +1 -0
- package/lib-commonjs/utilities/test-data.js +59 -0
- package/lib-commonjs/utilities/test-data.js.map +1 -1
- package/lib-commonjs/utilities/utilities.js +206 -19
- package/lib-commonjs/utilities/utilities.js.map +1 -1
- package/package.json +11 -8
- package/lib/components/DeclarativeChart/PlotlySchema.js +0 -7
- package/lib/components/DeclarativeChart/PlotlySchema.js.map +0 -1
- package/lib-commonjs/components/DeclarativeChart/PlotlySchema.js +0 -10
- package/lib-commonjs/components/DeclarativeChart/PlotlySchema.js.map +0 -1
|
@@ -0,0 +1,1038 @@
|
|
|
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(undefined, props.formatNumberOptions) : value.toString();
|
|
518
|
+
}, [
|
|
519
|
+
props.formatNumberOptions
|
|
520
|
+
]);
|
|
521
|
+
const _computeNodeAttributes = _react.useCallback((nodes, nodeAriaLabel)=>{
|
|
522
|
+
const result = {};
|
|
523
|
+
const weightSpan = (0, _d3selection.select)('.nodeName').append('text').attr('class', 'tempText').append('tspan').text(null);
|
|
524
|
+
const nameSpan = (0, _d3selection.select)('.nodeName').append('text').attr('class', 'tempText').attr('font-size', '10').append('tspan').text(null);
|
|
525
|
+
nodes.forEach((singleNode, index)=>{
|
|
526
|
+
const height = Math.max(singleNode.y1 - singleNode.y0, 0);
|
|
527
|
+
let padding = 8;
|
|
528
|
+
let textLengthForNodeWeight = 0;
|
|
529
|
+
const nodeValue = singleNode.actualValue;
|
|
530
|
+
// If the nodeWeight is in the same line as node description an extra padding
|
|
531
|
+
// of 6 px is required between node description and node weight.
|
|
532
|
+
if (height < MIN_HEIGHT_FOR_DOUBLINE_TYPE) {
|
|
533
|
+
padding = padding + 6;
|
|
534
|
+
// The following `select` statement injects a `tempText` element into the DOM. This injection
|
|
535
|
+
// (and subsequent removal) is causing a layout recalculation. This is a performance issue.
|
|
536
|
+
const measurement = measureText(weightSpan, _formatNumber(nodeValue));
|
|
537
|
+
if (measurement !== undefined) {
|
|
538
|
+
textLengthForNodeWeight = measurement;
|
|
539
|
+
padding = padding + textLengthForNodeWeight;
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
// Since the total width of the node is 124 and we are giving margin of 8px from the left .
|
|
543
|
+
// So the actual value on which it will be truncated is 124-8=116.
|
|
544
|
+
const truncatedname = truncateText(nameSpan, singleNode.name, NODE_WIDTH - 8, padding);
|
|
545
|
+
const isTruncated = truncatedname.slice(-3) === elipsis;
|
|
546
|
+
result[singleNode.nodeId] = {
|
|
547
|
+
reactId: `${_nodeBarId}-${index}`,
|
|
548
|
+
gElementId: `${_nodeGElementId}-${index}`,
|
|
549
|
+
name: truncatedname,
|
|
550
|
+
aria: nodeAriaLabel(singleNode, nodeValue),
|
|
551
|
+
trimmed: isTruncated,
|
|
552
|
+
height,
|
|
553
|
+
weightOffset: textLengthForNodeWeight
|
|
554
|
+
};
|
|
555
|
+
});
|
|
556
|
+
(0, _d3selection.selectAll)('.tempText').remove();
|
|
557
|
+
return result;
|
|
558
|
+
}, [
|
|
559
|
+
_formatNumber,
|
|
560
|
+
_nodeBarId,
|
|
561
|
+
_nodeGElementId
|
|
562
|
+
]);
|
|
563
|
+
const _linkCalloutAttributes = (singleLink, from)=>{
|
|
564
|
+
setCalloutVisible(true);
|
|
565
|
+
setColor(singleLink.source.color);
|
|
566
|
+
setXCalloutValue(singleLink.target.name);
|
|
567
|
+
setYCalloutValue(_formatNumber(singleLink.unnormalizedValue));
|
|
568
|
+
setDescriptionMessage(from);
|
|
569
|
+
};
|
|
570
|
+
const _isChartEmpty = _react.useCallback(()=>{
|
|
571
|
+
var _props_data;
|
|
572
|
+
const sankeyChartData = (_props_data = props.data) === null || _props_data === void 0 ? void 0 : _props_data.SankeyChartData;
|
|
573
|
+
return !(sankeyChartData && sankeyChartData.nodes.length > 0 && sankeyChartData.links.length > 0);
|
|
574
|
+
}, [
|
|
575
|
+
props.data
|
|
576
|
+
]);
|
|
577
|
+
const _normalizeSankeyData = _react.useCallback((data, _containerWidth, _containerHeight, colorsForNodes, borderColorsForNodes)=>{
|
|
578
|
+
if (_isChartEmpty()) {
|
|
579
|
+
return {
|
|
580
|
+
width: 0,
|
|
581
|
+
height: 0,
|
|
582
|
+
nodes: [],
|
|
583
|
+
links: []
|
|
584
|
+
};
|
|
585
|
+
}
|
|
586
|
+
const { sankey, height, width } = preRenderLayout(_margins.current, _containerWidth, _containerHeight, _isRtl);
|
|
587
|
+
// Clone the data before mutating it (via the SankeyLayoutGenerator) so that we don't mutate the original data.
|
|
588
|
+
const transformed = duplicateData(data);
|
|
589
|
+
sankey(transformed);
|
|
590
|
+
// NOTE: After the prior line, `transformed` is now a more-complex object than the incoming `ISankeyChartData`.
|
|
591
|
+
// `transformed` should be cast to a more-specific type. This is a breaking change because we would be eliminating
|
|
592
|
+
// fields from `ISankeyChartData` and putting those fields on a now-local type. But doing so makes it clearer what
|
|
593
|
+
// the caller needs to supply and why. For example, the `actualValue` and `layer` fields of `ISNodeExtra` should
|
|
594
|
+
// both be moved. Similarly for `unnormalizedValue` in `ISLinkExtra`.
|
|
595
|
+
// `SankeyNodeMinimal` and `SankeyLinkMinimal` are both the types after `sankey(transformed)`, but have almost no
|
|
596
|
+
// bearing on the data before `sankey(transformed)` (which is basically nodes with ids and names along with links
|
|
597
|
+
// with source index, target index, and value).
|
|
598
|
+
const nodesInColumn = groupNodesByColumn(transformed);
|
|
599
|
+
_numColumns.current = Object.keys(nodesInColumn).length;
|
|
600
|
+
// Keep track of the original values of the links and their acccumulated values in the nodes
|
|
601
|
+
// Setting these in external objects so they cannot be mutated by other code.
|
|
602
|
+
// The IDs of nodes can be numbers or strings. But, the IDs of links are always the index into the "nodes" array.
|
|
603
|
+
// After the sankey layout is computed, the each link's `source` and `target` will have the ID of the node in the
|
|
604
|
+
// type originally specified in the Nodes array. Consequently, we get the values of those links after the sankey
|
|
605
|
+
// transformation.
|
|
606
|
+
const nodeValues = valuesOfNodes(transformed.nodes);
|
|
607
|
+
const linkValues = valuesOfLinks(transformed.links);
|
|
608
|
+
adjustOnePercentHeightNodes(nodesInColumn, nodeValues, linkValues);
|
|
609
|
+
adjustPadding(sankey, height - 6, nodesInColumn);
|
|
610
|
+
// `sankey` is called a second time, probably to re-layout the nodes with the one-percent adjusted weights.
|
|
611
|
+
// NOTE: The second call to `sankey` is required to allow links to be hoverable.
|
|
612
|
+
// Without the second call, the links are not hoverable.
|
|
613
|
+
sankey(transformed);
|
|
614
|
+
populateNodeActualValue(transformed, nodeValues, linkValues);
|
|
615
|
+
assignNodeColors(transformed.nodes, colorsForNodes, borderColorsForNodes);
|
|
616
|
+
return {
|
|
617
|
+
width,
|
|
618
|
+
height,
|
|
619
|
+
nodes: transformed.nodes,
|
|
620
|
+
links: transformed.links
|
|
621
|
+
};
|
|
622
|
+
}, [
|
|
623
|
+
_isChartEmpty,
|
|
624
|
+
_isRtl
|
|
625
|
+
]);
|
|
626
|
+
const _createLinks = (dataLinks, linkAttributes)=>{
|
|
627
|
+
if (dataLinks) {
|
|
628
|
+
const linkId = _linkId;
|
|
629
|
+
return dataLinks.map((singleLink, index)=>{
|
|
630
|
+
const onMouseOut = ()=>{
|
|
631
|
+
_onStreamLeave(singleLink);
|
|
632
|
+
};
|
|
633
|
+
const { reactId, from, aria } = linkValue(linkAttributes, singleLink);
|
|
634
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
635
|
+
const dataPoints = linkToDataPoints(singleLink);
|
|
636
|
+
const key = `${linkId}-${index}`;
|
|
637
|
+
const gradientId = `gradient-${key}`;
|
|
638
|
+
const gradientUrl = `url(#${gradientId})`;
|
|
639
|
+
const source = singleLink.source;
|
|
640
|
+
const target = singleLink.target;
|
|
641
|
+
// TODO: localize the aria-label string
|
|
642
|
+
return /*#__PURE__*/ _react.createElement("g", {
|
|
643
|
+
key: key
|
|
644
|
+
}, /*#__PURE__*/ _react.createElement("defs", null, /*#__PURE__*/ _react.createElement("linearGradient", {
|
|
645
|
+
id: gradientId,
|
|
646
|
+
x1: "0%",
|
|
647
|
+
y1: "0%",
|
|
648
|
+
x2: "100%",
|
|
649
|
+
y2: "0%"
|
|
650
|
+
}, /*#__PURE__*/ _react.createElement("stop", {
|
|
651
|
+
offset: "0",
|
|
652
|
+
stopColor: source.color
|
|
653
|
+
}), /*#__PURE__*/ _react.createElement("stop", {
|
|
654
|
+
offset: "100%",
|
|
655
|
+
stopColor: target.color
|
|
656
|
+
}))), /*#__PURE__*/ _react.createElement("path", {
|
|
657
|
+
d: linkArea(dataPoints),
|
|
658
|
+
id: reactId,
|
|
659
|
+
fill: _fillStreamColors(singleLink, gradientUrl),
|
|
660
|
+
stroke: _fillStreamBorder(singleLink, gradientUrl),
|
|
661
|
+
strokeWidth: "2",
|
|
662
|
+
strokeOpacity: _getOpacityStreamBorder(singleLink),
|
|
663
|
+
onMouseOver: (event)=>_onStreamHover(event, singleLink, from),
|
|
664
|
+
onMouseOut: onMouseOut,
|
|
665
|
+
onFocus: (event)=>_onFocusLink(event, singleLink, from),
|
|
666
|
+
onBlur: _onBlur,
|
|
667
|
+
fillOpacity: _getOpacityStream(singleLink),
|
|
668
|
+
tabIndex: 0,
|
|
669
|
+
"aria-label": aria,
|
|
670
|
+
role: "img"
|
|
671
|
+
}));
|
|
672
|
+
});
|
|
673
|
+
}
|
|
674
|
+
return [];
|
|
675
|
+
};
|
|
676
|
+
const _createNodes = (dataNodes, nodeAttributes)=>{
|
|
677
|
+
if (dataNodes) {
|
|
678
|
+
const textAnchor = _isRtl ? 'end' : 'start';
|
|
679
|
+
return dataNodes.map((singleNode, index)=>{
|
|
680
|
+
const onMouseOut = ()=>{
|
|
681
|
+
_onLeave(singleNode);
|
|
682
|
+
};
|
|
683
|
+
const { reactId: nodeId, gElementId, height, trimmed: isTruncated, name: truncatedName, weightOffset: textLengthForNodeWeight, aria } = nodeAttributes[singleNode.nodeId];
|
|
684
|
+
const tooTall = height > MIN_HEIGHT_FOR_DOUBLINE_TYPE;
|
|
685
|
+
const { name, actualValue, x0, x1, y0 } = singleNode;
|
|
686
|
+
const textColor = nodeTextColor({
|
|
687
|
+
selectedState,
|
|
688
|
+
selectedNodes,
|
|
689
|
+
selectedNode
|
|
690
|
+
}, singleNode);
|
|
691
|
+
return /*#__PURE__*/ _react.createElement("g", {
|
|
692
|
+
key: index,
|
|
693
|
+
id: gElementId
|
|
694
|
+
}, /*#__PURE__*/ _react.createElement("rect", {
|
|
695
|
+
x: x0,
|
|
696
|
+
y: y0,
|
|
697
|
+
height: height,
|
|
698
|
+
width: x1 - x0,
|
|
699
|
+
fill: _fillNodeColors(singleNode),
|
|
700
|
+
id: nodeId,
|
|
701
|
+
onMouseOver: (e)=>_onHover(singleNode, e),
|
|
702
|
+
onMouseOut: onMouseOut,
|
|
703
|
+
onFocus: _onCloseCallout,
|
|
704
|
+
stroke: _fillNodeBorder(singleNode),
|
|
705
|
+
strokeWidth: "2",
|
|
706
|
+
opacity: "1",
|
|
707
|
+
tabIndex: 0,
|
|
708
|
+
"aria-label": aria,
|
|
709
|
+
role: "img"
|
|
710
|
+
}), height > MIN_HEIGHT_FOR_TYPE && /*#__PURE__*/ _react.createElement("g", {
|
|
711
|
+
className: classes.nodeTextContainer
|
|
712
|
+
}, /*#__PURE__*/ _react.createElement("g", {
|
|
713
|
+
className: "nodeName"
|
|
714
|
+
}, /*#__PURE__*/ _react.createElement("text", {
|
|
715
|
+
id: `${nodeId}-name`,
|
|
716
|
+
x: x0,
|
|
717
|
+
y: y0,
|
|
718
|
+
dy: '1.2em',
|
|
719
|
+
dx: '0.4em',
|
|
720
|
+
textAnchor: textAnchor,
|
|
721
|
+
fontWeight: "regular",
|
|
722
|
+
"aria-hidden": "true",
|
|
723
|
+
fill: textColor,
|
|
724
|
+
fontSize: 10,
|
|
725
|
+
onMouseOver: (e)=>_showTooltip(name, isTruncated, e),
|
|
726
|
+
onMouseOut: ()=>_hideTooltip()
|
|
727
|
+
}, truncatedName)), /*#__PURE__*/ _react.createElement("text", {
|
|
728
|
+
x: tooTall ? x0 : x1 - textLengthForNodeWeight - 8,
|
|
729
|
+
y: y0,
|
|
730
|
+
dy: tooTall ? '2em' : '1em',
|
|
731
|
+
dx: tooTall ? '0.4em' : '0em',
|
|
732
|
+
textAnchor: textAnchor,
|
|
733
|
+
fontWeight: "bold",
|
|
734
|
+
"aria-hidden": "true",
|
|
735
|
+
fill: textColor,
|
|
736
|
+
fontSize: 14
|
|
737
|
+
}, actualValue ? _formatNumber(actualValue) : actualValue)));
|
|
738
|
+
});
|
|
739
|
+
}
|
|
740
|
+
};
|
|
741
|
+
const _onLeave = (singleNode)=>{
|
|
742
|
+
if (selectedState) {
|
|
743
|
+
setSelectedState(false);
|
|
744
|
+
setSelectedNodes(new Set());
|
|
745
|
+
setSelectedLinks(new Set());
|
|
746
|
+
setSelectedNode(undefined);
|
|
747
|
+
}
|
|
748
|
+
};
|
|
749
|
+
const _onHover = (singleNode, mouseEvent)=>{
|
|
750
|
+
mouseEvent.persist();
|
|
751
|
+
_onCloseCallout();
|
|
752
|
+
if (!selectedState) {
|
|
753
|
+
const _selectedLinks = getSelectedLinks(singleNode);
|
|
754
|
+
const _selectedNodes = getSelectedNodes(_selectedLinks);
|
|
755
|
+
_selectedNodes.push(singleNode);
|
|
756
|
+
setSelectedState(true);
|
|
757
|
+
setSelectedNodes(new Set(Array.from(_selectedNodes).map((node)=>node.index)));
|
|
758
|
+
setSelectedLinks(new Set(Array.from(_selectedLinks).map((link)=>link.index)));
|
|
759
|
+
setSelectedNode(singleNode);
|
|
760
|
+
updatePosition(mouseEvent.clientX, mouseEvent.clientY);
|
|
761
|
+
setCalloutVisible(singleNode.y1 - singleNode.y0 < MIN_HEIGHT_FOR_TYPE);
|
|
762
|
+
setColor(singleNode.color);
|
|
763
|
+
setXCalloutValue(singleNode.name);
|
|
764
|
+
setYCalloutValue(_formatNumber(singleNode.actualValue));
|
|
765
|
+
}
|
|
766
|
+
};
|
|
767
|
+
const _onStreamHover = (mouseEvent, singleLink, from)=>{
|
|
768
|
+
mouseEvent.persist();
|
|
769
|
+
_onCloseCallout();
|
|
770
|
+
if (!selectedState) {
|
|
771
|
+
const { selectedLinks: _selectedLinks, selectedNodes: _selectedNodes } = getSelectedLinksforStreamHover(singleLink);
|
|
772
|
+
setSelectedState(true);
|
|
773
|
+
setSelectedNodes(new Set(Array.from(_selectedNodes).map((node)=>node.index)));
|
|
774
|
+
setSelectedLinks(new Set(Array.from(_selectedLinks).map((link)=>link.index)));
|
|
775
|
+
updatePosition(mouseEvent.clientX, mouseEvent.clientY);
|
|
776
|
+
_linkCalloutAttributes(singleLink, from);
|
|
777
|
+
}
|
|
778
|
+
};
|
|
779
|
+
const _onStreamLeave = (singleLink)=>{
|
|
780
|
+
if (selectedState) {
|
|
781
|
+
setSelectedState(false);
|
|
782
|
+
setSelectedNodes(new Set());
|
|
783
|
+
setSelectedLinks(new Set());
|
|
784
|
+
}
|
|
785
|
+
};
|
|
786
|
+
const _onFocusLink = (focusEvent, singleLink, from)=>{
|
|
787
|
+
// There is a big difference in how "Tab" and the "Arrow keys" are handled in this diagram.
|
|
788
|
+
// In particular, I would expect the "Down" key to be like "Tab", but it jumps a little wildly. I'm not sure
|
|
789
|
+
// if this behavior is an accessiblity violation, but it we might want to investigate it.
|
|
790
|
+
focusEvent.persist();
|
|
791
|
+
_onCloseCallout();
|
|
792
|
+
const boundingRect = focusEvent.currentTarget.getBoundingClientRect();
|
|
793
|
+
const clientX = boundingRect.left + boundingRect.width / 2;
|
|
794
|
+
const clientY = boundingRect.top + boundingRect.height / 2;
|
|
795
|
+
updatePosition(clientX, clientY);
|
|
796
|
+
_linkCalloutAttributes(singleLink, from);
|
|
797
|
+
};
|
|
798
|
+
const _onCloseCallout = ()=>{
|
|
799
|
+
setCalloutVisible(false);
|
|
800
|
+
updatePosition(0, 0);
|
|
801
|
+
setDescriptionMessage('');
|
|
802
|
+
};
|
|
803
|
+
const _onBlur = ()=>{
|
|
804
|
+
/**/ };
|
|
805
|
+
const _fillNodeColors = (singleNode)=>{
|
|
806
|
+
if (!selectedState) {
|
|
807
|
+
return singleNode.color;
|
|
808
|
+
} else {
|
|
809
|
+
if (selectedNode && selectedNodes.has(singleNode.index)) {
|
|
810
|
+
return selectedNode.color;
|
|
811
|
+
} else if (!selectedNode) {
|
|
812
|
+
return singleNode.color;
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
};
|
|
816
|
+
const _fillStreamColors = (singleLink, gradientUrl)=>{
|
|
817
|
+
if (selectedState && selectedLinks.has(singleLink.index)) {
|
|
818
|
+
return selectedNode ? selectedNode.color : gradientUrl;
|
|
819
|
+
}
|
|
820
|
+
};
|
|
821
|
+
const _fillStreamBorder = (singleLink, gradientUrl)=>{
|
|
822
|
+
if (!selectedState) {
|
|
823
|
+
return NON_SELECTED_NODE_AND_STREAM_COLOR;
|
|
824
|
+
} else {
|
|
825
|
+
if (selectedLinks.has(singleLink.index)) {
|
|
826
|
+
return selectedNode ? selectedNode.borderColor : gradientUrl;
|
|
827
|
+
}
|
|
828
|
+
return NON_SELECTED_NODE_AND_STREAM_COLOR;
|
|
829
|
+
}
|
|
830
|
+
};
|
|
831
|
+
const _fillNodeBorder = (singleNode)=>{
|
|
832
|
+
if (!selectedState) {
|
|
833
|
+
return singleNode.borderColor;
|
|
834
|
+
} else {
|
|
835
|
+
if (selectedNodes.has(singleNode.index)) {
|
|
836
|
+
return selectedNode ? selectedNode.borderColor : singleNode.borderColor;
|
|
837
|
+
}
|
|
838
|
+
return singleNode.borderColor;
|
|
839
|
+
}
|
|
840
|
+
};
|
|
841
|
+
const _getOpacityStream = (singleLink)=>{
|
|
842
|
+
if (selectedState) {
|
|
843
|
+
if (!selectedLinks.has(singleLink.index)) {
|
|
844
|
+
return NON_SELECTED_OPACITY;
|
|
845
|
+
} else if (!selectedNode) {
|
|
846
|
+
return SELECTED_STREAM_OPACITY;
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
return REST_STREAM_OPACITY;
|
|
850
|
+
};
|
|
851
|
+
const _getOpacityStreamBorder = (singleLink)=>{
|
|
852
|
+
if (selectedState && !selectedLinks.has(singleLink.index) && !selectedNode) {
|
|
853
|
+
return NON_SELECTED_STREAM_BORDER_OPACITY;
|
|
854
|
+
}
|
|
855
|
+
return NON_SELECTED_OPACITY;
|
|
856
|
+
};
|
|
857
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
858
|
+
const _showTooltip = (text, checkTrcuncated, evt)=>{
|
|
859
|
+
if (_tooltip.current && checkTrcuncated) {
|
|
860
|
+
//Fixing tooltip position by attaching it to the element rather than page
|
|
861
|
+
(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);
|
|
862
|
+
}
|
|
863
|
+
};
|
|
864
|
+
const _hideTooltip = ()=>{
|
|
865
|
+
if (_tooltip.current) {
|
|
866
|
+
(0, _d3selection.select)(_tooltip.current).style('opacity', 0);
|
|
867
|
+
}
|
|
868
|
+
};
|
|
869
|
+
const _calculateChartMinWidth = ()=>{
|
|
870
|
+
return _margins.current.left + _margins.current.right + // total width of all node columns
|
|
871
|
+
_numColumns.current * NODE_WIDTH + // minimum total width of all column gaps
|
|
872
|
+
(_numColumns.current - 1) * (NODE_WIDTH / 2);
|
|
873
|
+
};
|
|
874
|
+
const updatePosition = (newX, newY)=>{
|
|
875
|
+
const threshold = 1; // Set a threshold for movement
|
|
876
|
+
const { x, y } = clickPosition;
|
|
877
|
+
// Calculate the distance moved
|
|
878
|
+
const distance = Math.sqrt(Math.pow(newX - x, 2) + Math.pow(newY - y, 2));
|
|
879
|
+
// Update the position only if the distance moved is greater than the threshold
|
|
880
|
+
if (distance > threshold) {
|
|
881
|
+
setClickPosition({
|
|
882
|
+
x: newX,
|
|
883
|
+
y: newY
|
|
884
|
+
});
|
|
885
|
+
}
|
|
886
|
+
};
|
|
887
|
+
// Prepare the localization utilities
|
|
888
|
+
const _strings = _react.useMemo(()=>{
|
|
889
|
+
var _props_strings;
|
|
890
|
+
const fromString = ((_props_strings = props.strings) === null || _props_strings === void 0 ? void 0 : _props_strings.linkFrom) || 'From {0}';
|
|
891
|
+
// NOTE: The `node` parameter is the sankey-generated node on the link, and not the original `node` supplied
|
|
892
|
+
// by the caller.
|
|
893
|
+
return {
|
|
894
|
+
linkFrom: (node)=>(0, _string.format)(fromString, node.name)
|
|
895
|
+
};
|
|
896
|
+
}, [
|
|
897
|
+
props.strings
|
|
898
|
+
]);
|
|
899
|
+
const _accessibility = _react.useMemo(()=>{
|
|
900
|
+
var _props_accessibility, _props_accessibility1, _props_accessibility2;
|
|
901
|
+
const linkString = ((_props_accessibility = props.accessibility) === null || _props_accessibility === void 0 ? void 0 : _props_accessibility.linkAriaLabel) || 'link from {0} to {1} with weight {2}';
|
|
902
|
+
const nodeString = ((_props_accessibility1 = props.accessibility) === null || _props_accessibility1 === void 0 ? void 0 : _props_accessibility1.nodeAriaLabel) || 'node {0} with weight {1}';
|
|
903
|
+
return {
|
|
904
|
+
emptyAriaLabel: ((_props_accessibility2 = props.accessibility) === null || _props_accessibility2 === void 0 ? void 0 : _props_accessibility2.emptyAriaLabel) || 'Graph has no data to display',
|
|
905
|
+
linkAriaLabel: (link)=>(0, _string.format)(linkString, link.source.name, link.target.name, link.unnormalizedValue ? _formatNumber(link.unnormalizedValue) : link.unnormalizedValue),
|
|
906
|
+
nodeAriaLabel: (node, weight)=>(0, _string.format)(nodeString, node.name, _formatNumber(weight))
|
|
907
|
+
};
|
|
908
|
+
}, [
|
|
909
|
+
_formatNumber,
|
|
910
|
+
props.accessibility
|
|
911
|
+
]);
|
|
912
|
+
// Compute the position of each node and link
|
|
913
|
+
const { nodes, links, width, height } = _react.useMemo(()=>_normalizeSankeyData(props.data.SankeyChartData, containerWidth, containerHeight, props.colorsForNodes, props.borderColorsForNodes), [
|
|
914
|
+
_normalizeSankeyData,
|
|
915
|
+
containerHeight,
|
|
916
|
+
containerWidth,
|
|
917
|
+
props.borderColorsForNodes,
|
|
918
|
+
props.colorsForNodes,
|
|
919
|
+
props.data
|
|
920
|
+
]);
|
|
921
|
+
// Pre-compute some important attributes about nodes, specifically text
|
|
922
|
+
const nodeAttributes = _react.useMemo(()=>_computeNodeAttributes(nodes, _accessibility.nodeAriaLabel), [
|
|
923
|
+
_accessibility,
|
|
924
|
+
_computeNodeAttributes,
|
|
925
|
+
nodes
|
|
926
|
+
]);
|
|
927
|
+
const linkAttributes = _react.useMemo(()=>computeLinkAttributes(links, _strings.linkFrom, _accessibility.linkAriaLabel, _linkId), [
|
|
928
|
+
_accessibility,
|
|
929
|
+
_linkId,
|
|
930
|
+
_strings,
|
|
931
|
+
links
|
|
932
|
+
]);
|
|
933
|
+
if (!_isChartEmpty()) {
|
|
934
|
+
// In FocusZone, the focus order is determined by the rendering order of the elements. We need to find
|
|
935
|
+
// a rendering order such that the focus moves through the nodes and links in a logical sequence.
|
|
936
|
+
// Rendering the nodes and links layer by layer in a vertical order seems to be the most effective solution
|
|
937
|
+
// with FocusZone. Although this focus order may not be entirely logical, it ensures that the focus moves
|
|
938
|
+
// sequentially and prevents links (especially skip layer links) from being rendered over the nodes.
|
|
939
|
+
const nodeLinkDomOrderArray = [];
|
|
940
|
+
nodes.sort((a, b)=>{
|
|
941
|
+
if (a.x0 !== b.x0) {
|
|
942
|
+
return a.x0 - b.x0;
|
|
943
|
+
}
|
|
944
|
+
return a.y0 - b.y0;
|
|
945
|
+
});
|
|
946
|
+
nodes.forEach((item, index)=>{
|
|
947
|
+
nodeLinkDomOrderArray.push({
|
|
948
|
+
layer: item.layer,
|
|
949
|
+
type: 'node',
|
|
950
|
+
index
|
|
951
|
+
});
|
|
952
|
+
});
|
|
953
|
+
links.sort((a, b)=>{
|
|
954
|
+
const asx0 = a.source.x0;
|
|
955
|
+
const bsx0 = b.source.x0;
|
|
956
|
+
if (asx0 !== bsx0) {
|
|
957
|
+
return asx0 - bsx0;
|
|
958
|
+
}
|
|
959
|
+
return a.y0 - b.y0;
|
|
960
|
+
});
|
|
961
|
+
links.forEach((item, index)=>{
|
|
962
|
+
nodeLinkDomOrderArray.push({
|
|
963
|
+
layer: item.source.layer,
|
|
964
|
+
type: 'link',
|
|
965
|
+
index
|
|
966
|
+
});
|
|
967
|
+
});
|
|
968
|
+
nodeLinkDomOrderArray.sort((a, b)=>{
|
|
969
|
+
if (a.layer !== b.layer) {
|
|
970
|
+
return a.layer - b.layer;
|
|
971
|
+
}
|
|
972
|
+
if (a.type > b.type) {
|
|
973
|
+
return -1;
|
|
974
|
+
}
|
|
975
|
+
if (a.type < b.type) {
|
|
976
|
+
return 1;
|
|
977
|
+
}
|
|
978
|
+
return 0;
|
|
979
|
+
});
|
|
980
|
+
// Build the nodes and links as rendered in the UX.
|
|
981
|
+
const nodeData = _createNodes(nodes, nodeAttributes);
|
|
982
|
+
const linkData = _createLinks(links, linkAttributes);
|
|
983
|
+
const calloutProps = {
|
|
984
|
+
isPopoverOpen: isCalloutVisible,
|
|
985
|
+
clickPosition,
|
|
986
|
+
color,
|
|
987
|
+
XValue: xCalloutValue,
|
|
988
|
+
YValue: yCalloutValue,
|
|
989
|
+
descriptionMessage,
|
|
990
|
+
...props.calloutProps
|
|
991
|
+
};
|
|
992
|
+
return /*#__PURE__*/ _react.createElement("div", {
|
|
993
|
+
className: classes.root,
|
|
994
|
+
ref: chartContainer,
|
|
995
|
+
onMouseLeave: _onCloseCallout
|
|
996
|
+
}, /*#__PURE__*/ _react.createElement("div", {
|
|
997
|
+
className: classes.chartWrapper,
|
|
998
|
+
..._arrowNavigationAttributes
|
|
999
|
+
}, /*#__PURE__*/ _react.createElement("svg", {
|
|
1000
|
+
width: width,
|
|
1001
|
+
height: height,
|
|
1002
|
+
id: _chartId
|
|
1003
|
+
}, nodeLinkDomOrderArray.map((item)=>{
|
|
1004
|
+
if (item.type === 'node') {
|
|
1005
|
+
return /*#__PURE__*/ _react.createElement("g", {
|
|
1006
|
+
key: nodes[item.index].nodeId,
|
|
1007
|
+
className: classes.nodes
|
|
1008
|
+
}, nodeData[item.index]);
|
|
1009
|
+
} else {
|
|
1010
|
+
return /*#__PURE__*/ _react.createElement("g", {
|
|
1011
|
+
key: `${links[item.index].source.nodeId}-${links[item.index].target.nodeId}`,
|
|
1012
|
+
className: classes.links,
|
|
1013
|
+
stroke: props.pathColor ? props.pathColor : _reacttheme.tokens.colorStrokeFocus2,
|
|
1014
|
+
strokeOpacity: 1
|
|
1015
|
+
}, linkData[item.index]);
|
|
1016
|
+
}
|
|
1017
|
+
}))), calloutProps.isPopoverOpen && /*#__PURE__*/ _react.createElement(_index.ChartPopover, calloutProps), /*#__PURE__*/ _react.createElement("div", {
|
|
1018
|
+
id: _labelTooltipId,
|
|
1019
|
+
className: classes.toolTip,
|
|
1020
|
+
style: {
|
|
1021
|
+
opacity: 0
|
|
1022
|
+
},
|
|
1023
|
+
ref: _tooltip
|
|
1024
|
+
}));
|
|
1025
|
+
}
|
|
1026
|
+
return /*#__PURE__*/ _react.createElement("div", {
|
|
1027
|
+
id: _emptyChartId,
|
|
1028
|
+
role: 'alert',
|
|
1029
|
+
style: {
|
|
1030
|
+
opacity: '0'
|
|
1031
|
+
},
|
|
1032
|
+
"aria-label": _accessibility.emptyAriaLabel
|
|
1033
|
+
});
|
|
1034
|
+
});
|
|
1035
|
+
SankeyChart.displayName = 'SankeyChart';
|
|
1036
|
+
SankeyChart.defaultProps = {
|
|
1037
|
+
enableReflow: true
|
|
1038
|
+
};
|