@mui/x-charts-pro 8.10.1 → 8.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/BarChartPro/BarChartPro.js +0 -36
- package/CHANGELOG.md +221 -8
- package/ChartDataProviderPro/ChartDataProviderPro.js +1 -1
- package/FunnelChart/curves/bump.js +0 -2
- package/FunnelChart/curves/linear.js +0 -2
- package/FunnelChart/curves/pyramid.js +0 -2
- package/FunnelChart/curves/step-pyramid.js +0 -2
- package/FunnelChart/curves/step.js +0 -2
- package/Heatmap/Heatmap.js +0 -4
- package/LineChartPro/LineChartPro.js +0 -36
- package/PieChartPro/PieChartPro.js +2 -2
- package/SankeyChart/SankeyChart.d.ts +32 -0
- package/SankeyChart/SankeyChart.js +161 -0
- package/SankeyChart/SankeyChart.plugins.d.ts +3 -0
- package/SankeyChart/SankeyChart.plugins.js +11 -0
- package/SankeyChart/SankeyLinkElement.d.ts +27 -0
- package/SankeyChart/SankeyLinkElement.js +53 -0
- package/SankeyChart/SankeyLinkLabel.d.ts +12 -0
- package/SankeyChart/SankeyLinkLabel.js +58 -0
- package/SankeyChart/SankeyNodeElement.d.ts +27 -0
- package/SankeyChart/SankeyNodeElement.js +76 -0
- package/SankeyChart/SankeyPlot.d.ts +29 -0
- package/SankeyChart/SankeyPlot.js +100 -0
- package/SankeyChart/SankeyTooltip/SankeyTooltip.classes.d.ts +2 -0
- package/SankeyChart/SankeyTooltip/SankeyTooltip.classes.js +27 -0
- package/SankeyChart/SankeyTooltip/SankeyTooltip.d.ts +7 -0
- package/SankeyChart/SankeyTooltip/SankeyTooltip.js +208 -0
- package/SankeyChart/SankeyTooltip/SankeyTooltip.types.d.ts +10 -0
- package/SankeyChart/SankeyTooltip/SankeyTooltip.types.js +5 -0
- package/SankeyChart/SankeyTooltip/SankeyTooltipContent.d.ts +7 -0
- package/SankeyChart/SankeyTooltip/SankeyTooltipContent.js +66 -0
- package/SankeyChart/SankeyTooltip/index.d.ts +3 -0
- package/SankeyChart/SankeyTooltip/index.js +27 -0
- package/SankeyChart/calculateSankeyLayout.d.ts +13 -0
- package/SankeyChart/calculateSankeyLayout.js +141 -0
- package/SankeyChart/index.d.ts +9 -0
- package/SankeyChart/index.js +70 -0
- package/SankeyChart/sankey.types.d.ts +225 -0
- package/SankeyChart/sankey.types.js +6 -0
- package/SankeyChart/sankeyClasses.d.ts +15 -0
- package/SankeyChart/sankeyClasses.js +28 -0
- package/SankeyChart/sankeySlots.types.d.ts +24 -0
- package/SankeyChart/sankeySlots.types.js +5 -0
- package/SankeyChart/seriesConfig/getSeriesWithDefaultValues.d.ts +2 -0
- package/SankeyChart/seriesConfig/getSeriesWithDefaultValues.js +55 -0
- package/SankeyChart/seriesConfig/index.d.ts +2 -0
- package/SankeyChart/seriesConfig/index.js +19 -0
- package/SankeyChart/seriesConfig/tooltipGetter.d.ts +2 -0
- package/SankeyChart/seriesConfig/tooltipGetter.js +46 -0
- package/SankeyChart/useSankeyChartProps.d.ts +22 -0
- package/SankeyChart/useSankeyChartProps.js +77 -0
- package/SankeyChart/utils.d.ts +3 -0
- package/SankeyChart/utils.js +21 -0
- package/ScatterChartPro/ScatterChartPro.js +1 -37
- package/esm/BarChartPro/BarChartPro.js +0 -36
- package/esm/ChartDataProviderPro/ChartDataProviderPro.js +1 -1
- package/esm/FunnelChart/curves/bump.js +0 -2
- package/esm/FunnelChart/curves/linear.js +0 -2
- package/esm/FunnelChart/curves/pyramid.js +0 -2
- package/esm/FunnelChart/curves/step-pyramid.js +0 -2
- package/esm/FunnelChart/curves/step.js +0 -2
- package/esm/Heatmap/Heatmap.js +0 -4
- package/esm/LineChartPro/LineChartPro.js +0 -36
- package/esm/PieChartPro/PieChartPro.js +2 -2
- package/esm/SankeyChart/SankeyChart.d.ts +32 -0
- package/esm/SankeyChart/SankeyChart.js +155 -0
- package/esm/SankeyChart/SankeyChart.plugins.d.ts +3 -0
- package/esm/SankeyChart/SankeyChart.plugins.js +9 -0
- package/esm/SankeyChart/SankeyLinkElement.d.ts +27 -0
- package/esm/SankeyChart/SankeyLinkElement.js +46 -0
- package/esm/SankeyChart/SankeyLinkLabel.d.ts +12 -0
- package/esm/SankeyChart/SankeyLinkLabel.js +52 -0
- package/esm/SankeyChart/SankeyNodeElement.d.ts +27 -0
- package/esm/SankeyChart/SankeyNodeElement.js +69 -0
- package/esm/SankeyChart/SankeyPlot.d.ts +29 -0
- package/esm/SankeyChart/SankeyPlot.js +94 -0
- package/esm/SankeyChart/SankeyTooltip/SankeyTooltip.classes.d.ts +2 -0
- package/esm/SankeyChart/SankeyTooltip/SankeyTooltip.classes.js +19 -0
- package/esm/SankeyChart/SankeyTooltip/SankeyTooltip.d.ts +7 -0
- package/esm/SankeyChart/SankeyTooltip/SankeyTooltip.js +202 -0
- package/esm/SankeyChart/SankeyTooltip/SankeyTooltip.types.d.ts +10 -0
- package/esm/SankeyChart/SankeyTooltip/SankeyTooltip.types.js +1 -0
- package/esm/SankeyChart/SankeyTooltip/SankeyTooltipContent.d.ts +7 -0
- package/esm/SankeyChart/SankeyTooltip/SankeyTooltipContent.js +59 -0
- package/esm/SankeyChart/SankeyTooltip/index.d.ts +3 -0
- package/esm/SankeyChart/SankeyTooltip/index.js +3 -0
- package/esm/SankeyChart/calculateSankeyLayout.d.ts +13 -0
- package/esm/SankeyChart/calculateSankeyLayout.js +135 -0
- package/esm/SankeyChart/index.d.ts +9 -0
- package/esm/SankeyChart/index.js +6 -0
- package/esm/SankeyChart/sankey.types.d.ts +225 -0
- package/esm/SankeyChart/sankey.types.js +3 -0
- package/esm/SankeyChart/sankeyClasses.d.ts +15 -0
- package/esm/SankeyChart/sankeyClasses.js +19 -0
- package/esm/SankeyChart/sankeySlots.types.d.ts +24 -0
- package/esm/SankeyChart/sankeySlots.types.js +1 -0
- package/esm/SankeyChart/seriesConfig/getSeriesWithDefaultValues.d.ts +2 -0
- package/esm/SankeyChart/seriesConfig/getSeriesWithDefaultValues.js +47 -0
- package/esm/SankeyChart/seriesConfig/index.d.ts +2 -0
- package/esm/SankeyChart/seriesConfig/index.js +14 -0
- package/esm/SankeyChart/seriesConfig/tooltipGetter.d.ts +2 -0
- package/esm/SankeyChart/seriesConfig/tooltipGetter.js +39 -0
- package/esm/SankeyChart/useSankeyChartProps.d.ts +22 -0
- package/esm/SankeyChart/useSankeyChartProps.js +70 -0
- package/esm/SankeyChart/utils.d.ts +3 -0
- package/esm/SankeyChart/utils.js +14 -0
- package/esm/ScatterChartPro/ScatterChartPro.js +1 -37
- package/esm/hooks/useSankeySeries.d.ts +33 -0
- package/esm/hooks/useSankeySeries.js +42 -0
- package/esm/index.d.ts +1 -0
- package/esm/index.js +2 -1
- package/esm/internals/plugins/allPlugins.d.ts +2 -2
- package/esm/typeOverloads/modules.d.ts +11 -0
- package/hooks/useSankeySeries.d.ts +33 -0
- package/hooks/useSankeySeries.js +48 -0
- package/index.d.ts +1 -0
- package/index.js +13 -1
- package/internals/plugins/allPlugins.d.ts +2 -2
- package/package.json +6 -6
- package/typeOverloads/modules.d.ts +11 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ChartDrawingArea } from '@mui/x-charts/hooks';
|
|
2
|
+
import type { Theme } from '@mui/material/styles';
|
|
3
|
+
import type { SankeySeriesType, SankeyLayout, SankeyLayoutLink, DefaultizedSankeySeriesType } from "./sankey.types.js";
|
|
4
|
+
/**
|
|
5
|
+
* Calculates the layout for a Sankey diagram using d3-sankey
|
|
6
|
+
*
|
|
7
|
+
* @param data The Sankey data (nodes and links)
|
|
8
|
+
* @param drawingArea The drawing area dimensions
|
|
9
|
+
* @param options Layout configuration options
|
|
10
|
+
* @returns The calculated layout
|
|
11
|
+
*/
|
|
12
|
+
export declare function calculateSankeyLayout(data: DefaultizedSankeySeriesType['data'], drawingArea: ChartDrawingArea, theme: Theme, series?: Pick<SankeySeriesType, 'nodeOptions' | 'linkOptions' | 'iterations'>): SankeyLayout;
|
|
13
|
+
export declare function improvedNaiveSankeyLinkPathHorizontal(link: SankeyLayoutLink, curveCorrection?: number): string;
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
'use client';
|
|
3
|
+
|
|
4
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.calculateSankeyLayout = calculateSankeyLayout;
|
|
9
|
+
exports.improvedNaiveSankeyLinkPathHorizontal = improvedNaiveSankeyLinkPathHorizontal;
|
|
10
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
11
|
+
var _d3Sankey = require("@mui/x-charts-vendor/d3-sankey");
|
|
12
|
+
var _d3Path = require("@mui/x-charts-vendor/d3-path");
|
|
13
|
+
var _utils = require("./utils");
|
|
14
|
+
/**
|
|
15
|
+
* Calculates the layout for a Sankey diagram using d3-sankey
|
|
16
|
+
*
|
|
17
|
+
* @param data The Sankey data (nodes and links)
|
|
18
|
+
* @param drawingArea The drawing area dimensions
|
|
19
|
+
* @param options Layout configuration options
|
|
20
|
+
* @returns The calculated layout
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
function calculateSankeyLayout(data, drawingArea, theme, series = {}) {
|
|
24
|
+
const {
|
|
25
|
+
iterations = 6,
|
|
26
|
+
nodeOptions,
|
|
27
|
+
linkOptions
|
|
28
|
+
} = series;
|
|
29
|
+
const {
|
|
30
|
+
width: nodeWidth = 15,
|
|
31
|
+
padding: nodePadding = 10,
|
|
32
|
+
align: nodeAlign = 'justify',
|
|
33
|
+
sort: nodeSort = null
|
|
34
|
+
} = nodeOptions ?? {};
|
|
35
|
+
const {
|
|
36
|
+
color: linkColor = (theme.vars || theme).palette.text.primary,
|
|
37
|
+
sort: linkSort = null,
|
|
38
|
+
curveCorrection = 10
|
|
39
|
+
} = linkOptions ?? {};
|
|
40
|
+
const {
|
|
41
|
+
width,
|
|
42
|
+
height,
|
|
43
|
+
left,
|
|
44
|
+
top,
|
|
45
|
+
bottom,
|
|
46
|
+
right
|
|
47
|
+
} = drawingArea;
|
|
48
|
+
if (!data || !data.links) {
|
|
49
|
+
return {
|
|
50
|
+
nodes: [],
|
|
51
|
+
links: []
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Prepare the data structure expected by d3-sankey
|
|
56
|
+
const graph = {
|
|
57
|
+
nodes: data.nodes.values().toArray().map(v => (0, _extends2.default)({}, v)),
|
|
58
|
+
links: data.links.map(v => (0, _extends2.default)({}, v))
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
// Create the sankey layout generator
|
|
62
|
+
let sankeyGenerator = (0, _d3Sankey.sankey)().nodeWidth(nodeWidth).nodePadding(nodePadding).nodeAlign((0, _utils.getNodeAlignFunction)(nodeAlign)).extent([[left, top], [width + right, height + bottom]]).nodeId(d => d.id).iterations(iterations);
|
|
63
|
+
if (nodeSort) {
|
|
64
|
+
sankeyGenerator = sankeyGenerator.nodeSort(nodeSort);
|
|
65
|
+
}
|
|
66
|
+
if (linkSort) {
|
|
67
|
+
sankeyGenerator = sankeyGenerator.linkSort(linkSort);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Generate the layout
|
|
71
|
+
let result;
|
|
72
|
+
try {
|
|
73
|
+
result = sankeyGenerator(graph);
|
|
74
|
+
} catch (error) {
|
|
75
|
+
// There are two errors that can occur:
|
|
76
|
+
// 1. If the data contains circular references, d3-sankey will throw an error.
|
|
77
|
+
// 2. If there are missing source/target nodes, d3-sankey will throw an error.
|
|
78
|
+
// We handle the second case by building a map of nodes ourselves, so they are always present.
|
|
79
|
+
if (error instanceof Error && error.message === 'circular link') {
|
|
80
|
+
throw new Error('MUI X Charts: Sankey diagram contains circular references.');
|
|
81
|
+
}
|
|
82
|
+
throw error;
|
|
83
|
+
}
|
|
84
|
+
const {
|
|
85
|
+
nodes,
|
|
86
|
+
links
|
|
87
|
+
} = result;
|
|
88
|
+
|
|
89
|
+
// Convert d3-sankey links to our format
|
|
90
|
+
const layoutLinks = links.map(link => {
|
|
91
|
+
// Get the original link data
|
|
92
|
+
const originalLink = data.links.find(l => {
|
|
93
|
+
return l.source === link.source.id && l.target === link.target.id;
|
|
94
|
+
});
|
|
95
|
+
return (0, _extends2.default)({}, originalLink, link, {
|
|
96
|
+
color: originalLink?.color ?? linkColor,
|
|
97
|
+
path: improvedNaiveSankeyLinkPathHorizontal(link, curveCorrection)
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
const layoutNodes = nodes.map(node => {
|
|
101
|
+
const originalNode = data.nodes.get(node.id) || {};
|
|
102
|
+
return (0, _extends2.default)({}, originalNode, node);
|
|
103
|
+
});
|
|
104
|
+
return {
|
|
105
|
+
nodes: layoutNodes,
|
|
106
|
+
links: layoutLinks
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
function improvedNaiveSankeyLinkPathHorizontal(link, curveCorrection) {
|
|
110
|
+
const sx = link.source.x1;
|
|
111
|
+
const tx = link.target.x0;
|
|
112
|
+
// Weirdly this seems to work for any chart or node width change
|
|
113
|
+
// But needs to be changed when the sankey height changes.
|
|
114
|
+
const correction = curveCorrection ?? 5;
|
|
115
|
+
const y0 = link.y0;
|
|
116
|
+
const y1 = link.y1;
|
|
117
|
+
const w = link.width;
|
|
118
|
+
const halfW = w / 2;
|
|
119
|
+
const sy0 = y0 - halfW;
|
|
120
|
+
const sy1 = y0 + halfW;
|
|
121
|
+
const ty0 = y1 - halfW;
|
|
122
|
+
const ty1 = y1 + halfW;
|
|
123
|
+
const halfX = (tx - sx) / 2;
|
|
124
|
+
const p = (0, _d3Path.path)();
|
|
125
|
+
p.moveTo(sx, sy0);
|
|
126
|
+
const isDecreasing = y0 > y1;
|
|
127
|
+
const direction = isDecreasing ? -1 : 1;
|
|
128
|
+
let cpx1 = sx + halfX + correction * direction;
|
|
129
|
+
let cpy1 = sy0;
|
|
130
|
+
let cpx2 = sx + halfX + correction * direction;
|
|
131
|
+
let cpy2 = ty0;
|
|
132
|
+
p.bezierCurveTo(cpx1, cpy1, cpx2, cpy2, tx, ty0);
|
|
133
|
+
p.lineTo(tx, ty1);
|
|
134
|
+
cpx1 = sx + halfX - correction * direction;
|
|
135
|
+
cpy1 = ty1;
|
|
136
|
+
cpx2 = sx + halfX - correction * direction;
|
|
137
|
+
cpy2 = sy1;
|
|
138
|
+
p.bezierCurveTo(cpx1, cpy1, cpx2, cpy2, sx, sy1);
|
|
139
|
+
p.lineTo(sx, sy0);
|
|
140
|
+
return p.toString();
|
|
141
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { SankeyChart as Unstable_SankeyChart } from "./SankeyChart.js";
|
|
2
|
+
export type { SankeyChartProps, SankeySeries } from "./SankeyChart.js";
|
|
3
|
+
export { SankeyPlot } from "./SankeyPlot.js";
|
|
4
|
+
export type { SankeyPlotProps } from "./SankeyPlot.js";
|
|
5
|
+
export * from "./sankey.types.js";
|
|
6
|
+
export * from "./sankeySlots.types.js";
|
|
7
|
+
export { type SankeyPlotClasses, sankeyPlotClasses } from "./sankeyClasses.js";
|
|
8
|
+
export { SankeyTooltip, SankeyTooltipContent } from "./SankeyTooltip/index.js";
|
|
9
|
+
export type { SankeyTooltipProps } from "./SankeyTooltip/index.js";
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _exportNames = {
|
|
7
|
+
Unstable_SankeyChart: true,
|
|
8
|
+
SankeyPlot: true,
|
|
9
|
+
sankeyPlotClasses: true,
|
|
10
|
+
SankeyTooltip: true,
|
|
11
|
+
SankeyTooltipContent: true
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "SankeyPlot", {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: function () {
|
|
16
|
+
return _SankeyPlot.SankeyPlot;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports, "SankeyTooltip", {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
get: function () {
|
|
22
|
+
return _SankeyTooltip.SankeyTooltip;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
Object.defineProperty(exports, "SankeyTooltipContent", {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
get: function () {
|
|
28
|
+
return _SankeyTooltip.SankeyTooltipContent;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
Object.defineProperty(exports, "Unstable_SankeyChart", {
|
|
32
|
+
enumerable: true,
|
|
33
|
+
get: function () {
|
|
34
|
+
return _SankeyChart.SankeyChart;
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
Object.defineProperty(exports, "sankeyPlotClasses", {
|
|
38
|
+
enumerable: true,
|
|
39
|
+
get: function () {
|
|
40
|
+
return _sankeyClasses.sankeyPlotClasses;
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
var _SankeyChart = require("./SankeyChart");
|
|
44
|
+
var _SankeyPlot = require("./SankeyPlot");
|
|
45
|
+
var _sankey = require("./sankey.types");
|
|
46
|
+
Object.keys(_sankey).forEach(function (key) {
|
|
47
|
+
if (key === "default" || key === "__esModule") return;
|
|
48
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
49
|
+
if (key in exports && exports[key] === _sankey[key]) return;
|
|
50
|
+
Object.defineProperty(exports, key, {
|
|
51
|
+
enumerable: true,
|
|
52
|
+
get: function () {
|
|
53
|
+
return _sankey[key];
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
var _sankeySlots = require("./sankeySlots.types");
|
|
58
|
+
Object.keys(_sankeySlots).forEach(function (key) {
|
|
59
|
+
if (key === "default" || key === "__esModule") return;
|
|
60
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
61
|
+
if (key in exports && exports[key] === _sankeySlots[key]) return;
|
|
62
|
+
Object.defineProperty(exports, key, {
|
|
63
|
+
enumerable: true,
|
|
64
|
+
get: function () {
|
|
65
|
+
return _sankeySlots[key];
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
var _sankeyClasses = require("./sankeyClasses");
|
|
70
|
+
var _SankeyTooltip = require("./SankeyTooltip");
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import type { HighlightScope, SeriesId } from '@mui/x-charts/internals';
|
|
2
|
+
import type { DefaultizedProps, MakeRequired } from '@mui/x-internals/types';
|
|
3
|
+
import type { SankeyLink as D3SankeyLink, SankeyNode as D3SankeyNode } from '@mui/x-charts-vendor/d3-sankey';
|
|
4
|
+
export type SankeyNodeId = string | number;
|
|
5
|
+
export interface SankeyNode {
|
|
6
|
+
/**
|
|
7
|
+
* Unique identifier for the node
|
|
8
|
+
*/
|
|
9
|
+
id: SankeyNodeId;
|
|
10
|
+
/**
|
|
11
|
+
* The node label to display
|
|
12
|
+
*/
|
|
13
|
+
label?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Optional custom data for the node
|
|
16
|
+
*/
|
|
17
|
+
data?: any;
|
|
18
|
+
/**
|
|
19
|
+
* Optional color override for the node
|
|
20
|
+
*/
|
|
21
|
+
color?: string;
|
|
22
|
+
}
|
|
23
|
+
export interface SankeyLink {
|
|
24
|
+
/**
|
|
25
|
+
* Source node ID
|
|
26
|
+
*/
|
|
27
|
+
source: SankeyNodeId;
|
|
28
|
+
/**
|
|
29
|
+
* Target node ID
|
|
30
|
+
*/
|
|
31
|
+
target: SankeyNodeId;
|
|
32
|
+
/**
|
|
33
|
+
* The value/weight of the link (affects width)
|
|
34
|
+
*/
|
|
35
|
+
value: number;
|
|
36
|
+
/**
|
|
37
|
+
* Optional custom data for the link
|
|
38
|
+
*/
|
|
39
|
+
data?: any;
|
|
40
|
+
/**
|
|
41
|
+
* Optional color override for the link
|
|
42
|
+
*/
|
|
43
|
+
color?: string;
|
|
44
|
+
}
|
|
45
|
+
export type SankeyNodeOptions = {
|
|
46
|
+
/**
|
|
47
|
+
* Default color for nodes without specified colors
|
|
48
|
+
*/
|
|
49
|
+
color?: string;
|
|
50
|
+
/**
|
|
51
|
+
* Width of the nodes in pixels
|
|
52
|
+
*/
|
|
53
|
+
width?: number;
|
|
54
|
+
/**
|
|
55
|
+
* Padding between nodes in pixels
|
|
56
|
+
*/
|
|
57
|
+
padding?: number;
|
|
58
|
+
/**
|
|
59
|
+
* Node alignment strategy
|
|
60
|
+
* - 'justify': Nodes are evenly distributed across the width.
|
|
61
|
+
* - 'left': Nodes are aligned to the left.
|
|
62
|
+
* - 'right': Nodes are aligned to the right.
|
|
63
|
+
* - 'center': Nodes are centered.
|
|
64
|
+
* @default 'justify'
|
|
65
|
+
*/
|
|
66
|
+
align?: 'justify' | 'left' | 'right' | 'center';
|
|
67
|
+
/**
|
|
68
|
+
* Whether to show node labels
|
|
69
|
+
*/
|
|
70
|
+
showLabels?: boolean;
|
|
71
|
+
/**
|
|
72
|
+
* Custom sort function for nodes
|
|
73
|
+
* @param {SankeyLayoutNode} a - First node to compare
|
|
74
|
+
* @param {SankeyLayoutNode} b - Second node to compare
|
|
75
|
+
* @returns {number} Comparison result
|
|
76
|
+
*/
|
|
77
|
+
sort?: (a: SankeyLayoutNode, b: SankeyLayoutNode) => number | null;
|
|
78
|
+
};
|
|
79
|
+
export type SankeyLinkOptions = {
|
|
80
|
+
/**
|
|
81
|
+
* Default color for links without specified colors
|
|
82
|
+
*/
|
|
83
|
+
color?: string;
|
|
84
|
+
/**
|
|
85
|
+
* Opacity of the links (0-1)
|
|
86
|
+
*/
|
|
87
|
+
opacity?: number;
|
|
88
|
+
/**
|
|
89
|
+
* Whether to show link values
|
|
90
|
+
*/
|
|
91
|
+
showValues?: boolean;
|
|
92
|
+
/**
|
|
93
|
+
* Custom sort function for links
|
|
94
|
+
* @param {SankeyLayoutLink} a - First link to compare
|
|
95
|
+
* @param {SankeyLayoutLink} b - Second link to compare
|
|
96
|
+
* @returns {number} Comparison result
|
|
97
|
+
*/
|
|
98
|
+
sort?: (a: SankeyLayoutLink, b: SankeyLayoutLink) => number | null;
|
|
99
|
+
/**
|
|
100
|
+
* Applies the given number to the X dimension of the control points of the link's curve function.
|
|
101
|
+
* This can create better looking links between nodes, but is dependent on the graph layout.
|
|
102
|
+
* It is specially impacted by the chart height.
|
|
103
|
+
* @default 10
|
|
104
|
+
*/
|
|
105
|
+
curveCorrection?: number;
|
|
106
|
+
};
|
|
107
|
+
export interface SankeyData {
|
|
108
|
+
/**
|
|
109
|
+
* An array of node configs for the Sankey diagram
|
|
110
|
+
*
|
|
111
|
+
* This is optional, but can be used to provide custom labels or styles for nodes.
|
|
112
|
+
*/
|
|
113
|
+
nodes?: readonly SankeyNode[];
|
|
114
|
+
/**
|
|
115
|
+
* Array of links between nodes.
|
|
116
|
+
*
|
|
117
|
+
* The node ids will be used as the labels. If you want to provide custom labels, use the `nodes` property.
|
|
118
|
+
*
|
|
119
|
+
* Each link should have a `source`, `target`, and `value` property.
|
|
120
|
+
*/
|
|
121
|
+
links: readonly SankeyLink[];
|
|
122
|
+
}
|
|
123
|
+
export interface SankeySeriesType {
|
|
124
|
+
/**
|
|
125
|
+
* Unique identifier for the series
|
|
126
|
+
*/
|
|
127
|
+
id?: SeriesId;
|
|
128
|
+
/**
|
|
129
|
+
* Type identifier for Sankey series
|
|
130
|
+
*/
|
|
131
|
+
type: 'sankey';
|
|
132
|
+
/**
|
|
133
|
+
* The data for the Sankey diagram
|
|
134
|
+
*/
|
|
135
|
+
data: SankeyData;
|
|
136
|
+
/**
|
|
137
|
+
* Optional configuration for the nodes style, layout, and behavior
|
|
138
|
+
*/
|
|
139
|
+
nodeOptions?: SankeyNodeOptions;
|
|
140
|
+
/**
|
|
141
|
+
* Optional configuration for the links style, layout, and behavior
|
|
142
|
+
*/
|
|
143
|
+
linkOptions?: SankeyLinkOptions;
|
|
144
|
+
/**
|
|
145
|
+
* Number of iterations for the layout algorithm
|
|
146
|
+
* @default 6
|
|
147
|
+
*/
|
|
148
|
+
iterations?: number;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Represents the calculated positions and dimensions for a node in the Sankey diagram
|
|
152
|
+
*/
|
|
153
|
+
export interface SankeyLayoutNode extends D3SankeyNode<MakeRequired<SankeyNode, 'label' | 'color'>, SankeyLayoutLink> {
|
|
154
|
+
targetLinks: SankeyLayoutLink[];
|
|
155
|
+
sourceLinks: SankeyLayoutLink[];
|
|
156
|
+
value: number;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Represents the calculated positions and paths for a link in the Sankey diagram
|
|
160
|
+
*/
|
|
161
|
+
export interface SankeyLayoutLink extends D3SankeyLink<SankeyLayoutNode, Omit<MakeRequired<SankeyLink, 'color'>, 'source' | 'target'>> {
|
|
162
|
+
path?: string | null;
|
|
163
|
+
source: SankeyLayoutNode;
|
|
164
|
+
target: SankeyLayoutNode;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Calculated layout for the Sankey diagram
|
|
168
|
+
*/
|
|
169
|
+
export interface SankeyLayout {
|
|
170
|
+
nodes: readonly SankeyLayoutNode[];
|
|
171
|
+
links: readonly SankeyLayoutLink[];
|
|
172
|
+
}
|
|
173
|
+
export interface DefaultizedSankeySeriesType extends DefaultizedProps<Omit<SankeySeriesType, 'data'>, 'id'> {
|
|
174
|
+
data: {
|
|
175
|
+
nodes: Map<SankeyNodeId, SankeyNode>;
|
|
176
|
+
links: readonly SankeyLink[];
|
|
177
|
+
};
|
|
178
|
+
highlightScope?: HighlightScope;
|
|
179
|
+
}
|
|
180
|
+
type SankeyNodeIdentifierBase = {
|
|
181
|
+
type: 'sankey';
|
|
182
|
+
/**
|
|
183
|
+
* Unique identifier for the series
|
|
184
|
+
*/
|
|
185
|
+
seriesId: SeriesId;
|
|
186
|
+
};
|
|
187
|
+
export type SankeyNodeIdentifier = SankeyNodeIdentifierBase & {
|
|
188
|
+
/**
|
|
189
|
+
* Subtype to differentiate between node and link
|
|
190
|
+
*/
|
|
191
|
+
subType: 'node';
|
|
192
|
+
/**
|
|
193
|
+
* The id of the node
|
|
194
|
+
*/
|
|
195
|
+
nodeId: SankeyNodeId;
|
|
196
|
+
};
|
|
197
|
+
export type SankeyNodeIdentifierWithData = SankeyNodeIdentifier & {
|
|
198
|
+
/**
|
|
199
|
+
* The node object with all the calculated properties
|
|
200
|
+
*/
|
|
201
|
+
node: SankeyLayoutNode;
|
|
202
|
+
};
|
|
203
|
+
export type SankeyLinkIdentifier = SankeyNodeIdentifierBase & {
|
|
204
|
+
/**
|
|
205
|
+
* Subtype to differentiate between node and link
|
|
206
|
+
*/
|
|
207
|
+
subType: 'link';
|
|
208
|
+
/**
|
|
209
|
+
* The id of the source node
|
|
210
|
+
*/
|
|
211
|
+
sourceId: SankeyNodeId;
|
|
212
|
+
/**
|
|
213
|
+
* The id of the target node
|
|
214
|
+
*/
|
|
215
|
+
targetId: SankeyNodeId;
|
|
216
|
+
};
|
|
217
|
+
export type SankeyLinkIdentifierWithData = SankeyLinkIdentifier & {
|
|
218
|
+
/**
|
|
219
|
+
* The link object with all the calculated properties
|
|
220
|
+
*/
|
|
221
|
+
link: SankeyLayoutLink;
|
|
222
|
+
};
|
|
223
|
+
export type SankeyItemIdentifier = SankeyNodeIdentifier | SankeyLinkIdentifier;
|
|
224
|
+
export type SankeyItemIdentifierWithData = SankeyNodeIdentifierWithData | SankeyLinkIdentifierWithData;
|
|
225
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface SankeyPlotClasses {
|
|
2
|
+
/** Styles applied to the root element. */
|
|
3
|
+
root: string;
|
|
4
|
+
/** Styles applied to the nodes container. */
|
|
5
|
+
nodes: string;
|
|
6
|
+
/** Styles applied to the links container. */
|
|
7
|
+
links: string;
|
|
8
|
+
/** Styles applied to the link label container. */
|
|
9
|
+
linkLabels: string;
|
|
10
|
+
}
|
|
11
|
+
export declare function getSankeyPlotUtilityClass(slot: string): string;
|
|
12
|
+
export declare const sankeyPlotClasses: SankeyPlotClasses;
|
|
13
|
+
export declare const useUtilityClasses: (ownerState: {
|
|
14
|
+
classes?: Partial<SankeyPlotClasses>;
|
|
15
|
+
}) => Record<"root" | "nodes" | "links" | "linkLabels", string>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.getSankeyPlotUtilityClass = getSankeyPlotUtilityClass;
|
|
8
|
+
exports.useUtilityClasses = exports.sankeyPlotClasses = void 0;
|
|
9
|
+
var _composeClasses = _interopRequireDefault(require("@mui/utils/composeClasses"));
|
|
10
|
+
var _generateUtilityClass = _interopRequireDefault(require("@mui/utils/generateUtilityClass"));
|
|
11
|
+
var _generateUtilityClasses = _interopRequireDefault(require("@mui/utils/generateUtilityClasses"));
|
|
12
|
+
function getSankeyPlotUtilityClass(slot) {
|
|
13
|
+
return (0, _generateUtilityClass.default)('MuiSankeyChart', slot);
|
|
14
|
+
}
|
|
15
|
+
const sankeyPlotClasses = exports.sankeyPlotClasses = (0, _generateUtilityClasses.default)('MuiSankeyChart', ['root', 'nodes', 'links', 'linkLabels']);
|
|
16
|
+
const useUtilityClasses = ownerState => {
|
|
17
|
+
const {
|
|
18
|
+
classes
|
|
19
|
+
} = ownerState;
|
|
20
|
+
const slots = {
|
|
21
|
+
root: ['root'],
|
|
22
|
+
nodes: ['nodes'],
|
|
23
|
+
links: ['links'],
|
|
24
|
+
linkLabels: ['linkLabels']
|
|
25
|
+
};
|
|
26
|
+
return (0, _composeClasses.default)(slots, getSankeyPlotUtilityClass, classes);
|
|
27
|
+
};
|
|
28
|
+
exports.useUtilityClasses = useUtilityClasses;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ChartsOverlaySlotProps, ChartsOverlaySlots } from '@mui/x-charts/ChartsOverlay';
|
|
2
|
+
import { ChartsTooltipProps, ChartsTooltipSlotProps, ChartsTooltipSlots } from '@mui/x-charts/ChartsTooltip';
|
|
3
|
+
import { ChartsSlotProps, ChartsSlots } from '@mui/x-charts/internals';
|
|
4
|
+
import { ChartsToolbarSlotProps, ChartsToolbarSlots } from '@mui/x-charts/Toolbar';
|
|
5
|
+
export interface SankeyChartSlots extends ChartsTooltipSlots, ChartsOverlaySlots, ChartsToolbarSlots, Partial<ChartsSlots> {}
|
|
6
|
+
export interface SankeyChartSlotProps extends Omit<ChartsTooltipSlotProps, 'tooltip'>, ChartsOverlaySlotProps, ChartsToolbarSlotProps, Partial<ChartsSlotProps> {
|
|
7
|
+
/**
|
|
8
|
+
* Slot props for the tooltip component.
|
|
9
|
+
* @default {}
|
|
10
|
+
*/
|
|
11
|
+
tooltip?: Partial<ChartsTooltipProps<'item' | 'none'>>;
|
|
12
|
+
}
|
|
13
|
+
export interface SankeyChartSlotExtension {
|
|
14
|
+
/**
|
|
15
|
+
* Overridable component slots.
|
|
16
|
+
* @default {}
|
|
17
|
+
*/
|
|
18
|
+
slots?: SankeyChartSlots;
|
|
19
|
+
/**
|
|
20
|
+
* The props used for each component slot.
|
|
21
|
+
* @default {}
|
|
22
|
+
*/
|
|
23
|
+
slotProps?: SankeyChartSlotProps;
|
|
24
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.getSeriesWithDefaultValues = void 0;
|
|
8
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
9
|
+
const getSeriesWithDefaultValues = (seriesData, seriesIndex, colors) => {
|
|
10
|
+
const nodeMap = new Map();
|
|
11
|
+
const nodeColor = seriesData.nodeOptions?.color;
|
|
12
|
+
const data = seriesData.data;
|
|
13
|
+
let colorIndex = -1;
|
|
14
|
+
if (data.nodes) {
|
|
15
|
+
data.nodes.forEach(node => {
|
|
16
|
+
const id = node.id || node.label || '';
|
|
17
|
+
const label = node.label || `${id}`;
|
|
18
|
+
colorIndex += 1;
|
|
19
|
+
nodeMap.set(id, (0, _extends2.default)({}, node, {
|
|
20
|
+
id,
|
|
21
|
+
label,
|
|
22
|
+
color: node.color ?? nodeColor ?? colors?.[colorIndex % colors.length]
|
|
23
|
+
}));
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
data.links.forEach(v => {
|
|
27
|
+
if (!nodeMap.has(v.source)) {
|
|
28
|
+
colorIndex += 1;
|
|
29
|
+
const source = {
|
|
30
|
+
id: v.source,
|
|
31
|
+
label: `${v.source}`,
|
|
32
|
+
color: nodeColor ?? colors?.[colorIndex % colors.length]
|
|
33
|
+
};
|
|
34
|
+
nodeMap.set(source.id, source);
|
|
35
|
+
}
|
|
36
|
+
if (!nodeMap.has(v.target)) {
|
|
37
|
+
colorIndex += 1;
|
|
38
|
+
const target = {
|
|
39
|
+
id: v.target,
|
|
40
|
+
label: `${v.target}`,
|
|
41
|
+
color: nodeColor ?? colors?.[colorIndex % colors.length]
|
|
42
|
+
};
|
|
43
|
+
nodeMap.set(target.id, target);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
return (0, _extends2.default)({
|
|
47
|
+
id: seriesData.id ?? `auto-generated-id-${seriesIndex}`
|
|
48
|
+
}, seriesData, {
|
|
49
|
+
data: {
|
|
50
|
+
links: data.links,
|
|
51
|
+
nodes: nodeMap
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
exports.getSeriesWithDefaultValues = getSeriesWithDefaultValues;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.seriesConfig = void 0;
|
|
7
|
+
var _getSeriesWithDefaultValues = require("./getSeriesWithDefaultValues");
|
|
8
|
+
var _tooltipGetter = require("./tooltipGetter");
|
|
9
|
+
// Simple passthrough functions for sankey chart
|
|
10
|
+
const seriesProcessor = series => series;
|
|
11
|
+
const colorProcessor = series => series;
|
|
12
|
+
const legendGetter = () => [];
|
|
13
|
+
const seriesConfig = exports.seriesConfig = {
|
|
14
|
+
seriesProcessor,
|
|
15
|
+
colorProcessor,
|
|
16
|
+
legendGetter,
|
|
17
|
+
tooltipGetter: _tooltipGetter.tooltipGetter,
|
|
18
|
+
getSeriesWithDefaultValues: _getSeriesWithDefaultValues.getSeriesWithDefaultValues
|
|
19
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.tooltipGetter = void 0;
|
|
7
|
+
const tooltipGetter = params => {
|
|
8
|
+
const {
|
|
9
|
+
identifier
|
|
10
|
+
} = params;
|
|
11
|
+
if (!identifier) {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
const {
|
|
15
|
+
subType
|
|
16
|
+
} = identifier;
|
|
17
|
+
if (subType === 'node') {
|
|
18
|
+
const node = identifier.node;
|
|
19
|
+
return {
|
|
20
|
+
identifier,
|
|
21
|
+
color: node.color,
|
|
22
|
+
label: `${node.label}:`,
|
|
23
|
+
value: node.value,
|
|
24
|
+
formattedValue: `${node.value}`,
|
|
25
|
+
markType: 'square'
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
if (subType === 'link') {
|
|
29
|
+
const link = identifier.link;
|
|
30
|
+
if (!link) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
const sourceLabel = link.source.label;
|
|
34
|
+
const targetLabel = link.target.label;
|
|
35
|
+
return {
|
|
36
|
+
identifier,
|
|
37
|
+
color: link.color,
|
|
38
|
+
label: `${sourceLabel} → ${targetLabel}:`,
|
|
39
|
+
value: link.value,
|
|
40
|
+
formattedValue: `${link.value}`,
|
|
41
|
+
markType: 'line'
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
return null;
|
|
45
|
+
};
|
|
46
|
+
exports.tooltipGetter = tooltipGetter;
|