@mui/x-charts-pro 8.10.2 → 8.11.1
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 +214 -13
- 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/FunnelChart/labelUtils.d.ts +7 -5
- package/FunnelChart/labelUtils.js +2 -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/FunnelChart/labelUtils.d.ts +7 -5
- package/esm/FunnelChart/labelUtils.js +2 -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 +15 -15
- package/typeOverloads/modules.d.ts +11 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
import useEventCallback from '@mui/utils/useEventCallback';
|
|
6
|
+
import { useInteractionItemProps } from '@mui/x-charts/internals';
|
|
7
|
+
import { useTheme } from '@mui/material/styles';
|
|
8
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
9
|
+
/**
|
|
10
|
+
* @ignore - internal component.
|
|
11
|
+
*/
|
|
12
|
+
export const SankeyNodeElement = /*#__PURE__*/React.forwardRef(function SankeyNodeElement(props, ref) {
|
|
13
|
+
const {
|
|
14
|
+
node,
|
|
15
|
+
showLabel = true,
|
|
16
|
+
onClick,
|
|
17
|
+
seriesId
|
|
18
|
+
} = props;
|
|
19
|
+
const theme = useTheme();
|
|
20
|
+
const x0 = node.x0 ?? 0;
|
|
21
|
+
const y0 = node.y0 ?? 0;
|
|
22
|
+
const x1 = node.x1 ?? 0;
|
|
23
|
+
const y1 = node.y1 ?? 0;
|
|
24
|
+
const nodeWidth = x1 - x0;
|
|
25
|
+
const nodeHeight = y1 - y0;
|
|
26
|
+
|
|
27
|
+
// Determine label position
|
|
28
|
+
const labelX = node.depth === 0 ? x1 + 6 // Right side for first column
|
|
29
|
+
: x0 - 6; // Left side for other columns
|
|
30
|
+
|
|
31
|
+
const labelAnchor = node.depth === 0 ? 'start' : 'end';
|
|
32
|
+
const identifier = {
|
|
33
|
+
type: 'sankey',
|
|
34
|
+
seriesId,
|
|
35
|
+
subType: 'node',
|
|
36
|
+
nodeId: node.id,
|
|
37
|
+
node
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
// Add interaction props for tooltips
|
|
41
|
+
const interactionProps = useInteractionItemProps(identifier);
|
|
42
|
+
const handleClick = useEventCallback(event => {
|
|
43
|
+
onClick?.(event, identifier);
|
|
44
|
+
});
|
|
45
|
+
return /*#__PURE__*/_jsxs("g", {
|
|
46
|
+
ref: ref,
|
|
47
|
+
"data-node": node.id,
|
|
48
|
+
children: [/*#__PURE__*/_jsx("rect", _extends({
|
|
49
|
+
x: node.x0,
|
|
50
|
+
y: node.y0,
|
|
51
|
+
width: nodeWidth,
|
|
52
|
+
height: nodeHeight,
|
|
53
|
+
fill: node.color,
|
|
54
|
+
onClick: onClick ? handleClick : undefined,
|
|
55
|
+
cursor: onClick ? 'pointer' : 'default',
|
|
56
|
+
stroke: "none"
|
|
57
|
+
}, interactionProps)), showLabel && node.label && /*#__PURE__*/_jsx("text", {
|
|
58
|
+
x: labelX,
|
|
59
|
+
y: (y0 + y1) / 2,
|
|
60
|
+
textAnchor: labelAnchor,
|
|
61
|
+
fill: (theme.vars || theme).palette.text.primary,
|
|
62
|
+
fontSize: theme.typography.caption.fontSize,
|
|
63
|
+
fontFamily: theme.typography.fontFamily,
|
|
64
|
+
pointerEvents: "none",
|
|
65
|
+
children: node.label
|
|
66
|
+
})]
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
if (process.env.NODE_ENV !== "production") SankeyNodeElement.displayName = "SankeyNodeElement";
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { type SankeyLinkIdentifierWithData, type SankeyNodeIdentifierWithData } from "./sankey.types.js";
|
|
3
|
+
import { type SankeyPlotClasses } from "./sankeyClasses.js";
|
|
4
|
+
export interface SankeyPlotProps {
|
|
5
|
+
/**
|
|
6
|
+
* Classes applied to the various elements.
|
|
7
|
+
*/
|
|
8
|
+
classes?: Partial<SankeyPlotClasses>;
|
|
9
|
+
/**
|
|
10
|
+
* Callback fired when a sankey item is clicked.
|
|
11
|
+
* @param {React.MouseEvent<SVGElement, MouseEvent>} event The event source of the callback.
|
|
12
|
+
* @param {SankeyNodeIdentifierWithData} node The sankey node identifier.
|
|
13
|
+
*/
|
|
14
|
+
onNodeClick?: (event: React.MouseEvent<SVGElement, MouseEvent>, node: SankeyNodeIdentifierWithData) => void;
|
|
15
|
+
/**
|
|
16
|
+
* Callback fired when a sankey item is clicked.
|
|
17
|
+
* @param {React.MouseEvent<SVGElement, MouseEvent>} event The event source of the callback.
|
|
18
|
+
* @param {SankeyLinkIdentifierWithData} link The sankey link identifier.
|
|
19
|
+
*/
|
|
20
|
+
onLinkClick?: (event: React.MouseEvent<SVGElement, MouseEvent>, link: SankeyLinkIdentifierWithData) => void;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Renders a Sankey diagram plot.
|
|
24
|
+
*/
|
|
25
|
+
declare function SankeyPlot(props: SankeyPlotProps): React.JSX.Element | null;
|
|
26
|
+
declare namespace SankeyPlot {
|
|
27
|
+
var propTypes: any;
|
|
28
|
+
}
|
|
29
|
+
export { SankeyPlot };
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import PropTypes from 'prop-types';
|
|
5
|
+
import { useTheme } from '@mui/material/styles';
|
|
6
|
+
import { useDrawingArea } from '@mui/x-charts/hooks';
|
|
7
|
+
import { calculateSankeyLayout } from "./calculateSankeyLayout.js";
|
|
8
|
+
import { SankeyNodeElement } from "./SankeyNodeElement.js";
|
|
9
|
+
import { SankeyLinkElement } from "./SankeyLinkElement.js";
|
|
10
|
+
import { SankeyLinkLabel } from "./SankeyLinkLabel.js";
|
|
11
|
+
import { useSankeySeriesContext } from "../hooks/useSankeySeries.js";
|
|
12
|
+
import { useUtilityClasses } from "./sankeyClasses.js";
|
|
13
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
14
|
+
/**
|
|
15
|
+
* Renders a Sankey diagram plot.
|
|
16
|
+
*/
|
|
17
|
+
function SankeyPlot(props) {
|
|
18
|
+
const {
|
|
19
|
+
classes: inputClasses,
|
|
20
|
+
onLinkClick,
|
|
21
|
+
onNodeClick
|
|
22
|
+
} = props;
|
|
23
|
+
const seriesContext = useSankeySeriesContext();
|
|
24
|
+
if (!seriesContext) {
|
|
25
|
+
throw new Error(`MUI X Charts: Sankey series context is missing. Ensure the SankeyPlot is used inside a properly configured ChartDataProviderPro.`);
|
|
26
|
+
}
|
|
27
|
+
const series = seriesContext.series[seriesContext.seriesOrder?.[0]];
|
|
28
|
+
const classes = useUtilityClasses({
|
|
29
|
+
classes: inputClasses
|
|
30
|
+
});
|
|
31
|
+
const drawingArea = useDrawingArea();
|
|
32
|
+
const {
|
|
33
|
+
data,
|
|
34
|
+
linkOptions,
|
|
35
|
+
nodeOptions
|
|
36
|
+
} = series;
|
|
37
|
+
const theme = useTheme();
|
|
38
|
+
|
|
39
|
+
// Calculate layout based on data and dimensions
|
|
40
|
+
const layout = React.useMemo(() => calculateSankeyLayout(data, drawingArea, theme, series), [drawingArea, data, series, theme]);
|
|
41
|
+
|
|
42
|
+
// Early return if no data or dimensions
|
|
43
|
+
if (!data || !data.links) {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
return /*#__PURE__*/_jsxs("g", {
|
|
47
|
+
className: classes.root,
|
|
48
|
+
children: [/*#__PURE__*/_jsx("g", {
|
|
49
|
+
className: classes.links,
|
|
50
|
+
children: layout.links.map(link => /*#__PURE__*/_jsx(SankeyLinkElement, {
|
|
51
|
+
seriesId: series.id,
|
|
52
|
+
link: link,
|
|
53
|
+
opacity: linkOptions?.opacity,
|
|
54
|
+
onClick: onLinkClick
|
|
55
|
+
}, `${link.source.id}-${link.target.id}`))
|
|
56
|
+
}), /*#__PURE__*/_jsx("g", {
|
|
57
|
+
className: classes.nodes,
|
|
58
|
+
children: layout.nodes.map(node => /*#__PURE__*/_jsx(SankeyNodeElement, {
|
|
59
|
+
seriesId: series.id,
|
|
60
|
+
node: node,
|
|
61
|
+
showLabel: nodeOptions?.showLabels,
|
|
62
|
+
onClick: onNodeClick
|
|
63
|
+
}, node.id))
|
|
64
|
+
}), linkOptions?.showValues && /*#__PURE__*/_jsx("g", {
|
|
65
|
+
className: classes.linkLabels,
|
|
66
|
+
children: layout.links.map(link => /*#__PURE__*/_jsx(SankeyLinkLabel, {
|
|
67
|
+
link: link
|
|
68
|
+
}, `label-${link.source.id}-${link.target.id}`))
|
|
69
|
+
})]
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
process.env.NODE_ENV !== "production" ? SankeyPlot.propTypes = {
|
|
73
|
+
// ----------------------------- Warning --------------------------------
|
|
74
|
+
// | These PropTypes are generated from the TypeScript type definitions |
|
|
75
|
+
// | To update them edit the TypeScript types and run "pnpm proptypes" |
|
|
76
|
+
// ----------------------------------------------------------------------
|
|
77
|
+
/**
|
|
78
|
+
* Classes applied to the various elements.
|
|
79
|
+
*/
|
|
80
|
+
classes: PropTypes.object,
|
|
81
|
+
/**
|
|
82
|
+
* Callback fired when a sankey item is clicked.
|
|
83
|
+
* @param {React.MouseEvent<SVGElement, MouseEvent>} event The event source of the callback.
|
|
84
|
+
* @param {SankeyLinkIdentifierWithData} link The sankey link identifier.
|
|
85
|
+
*/
|
|
86
|
+
onLinkClick: PropTypes.func,
|
|
87
|
+
/**
|
|
88
|
+
* Callback fired when a sankey item is clicked.
|
|
89
|
+
* @param {React.MouseEvent<SVGElement, MouseEvent>} event The event source of the callback.
|
|
90
|
+
* @param {SankeyNodeIdentifierWithData} node The sankey node identifier.
|
|
91
|
+
*/
|
|
92
|
+
onNodeClick: PropTypes.func
|
|
93
|
+
} : void 0;
|
|
94
|
+
export { SankeyPlot };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import composeClasses from '@mui/utils/composeClasses';
|
|
2
|
+
import { getChartsTooltipUtilityClass } from '@mui/x-charts/ChartsTooltip';
|
|
3
|
+
export const useUtilityClasses = props => {
|
|
4
|
+
const {
|
|
5
|
+
classes
|
|
6
|
+
} = props;
|
|
7
|
+
const slots = {
|
|
8
|
+
root: ['root'],
|
|
9
|
+
paper: ['paper'],
|
|
10
|
+
table: ['table'],
|
|
11
|
+
row: ['row'],
|
|
12
|
+
cell: ['cell'],
|
|
13
|
+
mark: ['mark'],
|
|
14
|
+
markContainer: ['markContainer'],
|
|
15
|
+
labelCell: ['labelCell'],
|
|
16
|
+
valueCell: ['valueCell']
|
|
17
|
+
};
|
|
18
|
+
return composeClasses(slots, getChartsTooltipUtilityClass, classes);
|
|
19
|
+
};
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
import PropTypes from 'prop-types';
|
|
6
|
+
import { ChartsTooltipContainer } from '@mui/x-charts/ChartsTooltip';
|
|
7
|
+
import { SankeyTooltipContent } from "./SankeyTooltipContent.js";
|
|
8
|
+
import { useUtilityClasses } from "./SankeyTooltip.classes.js";
|
|
9
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
10
|
+
function SankeyTooltip(props) {
|
|
11
|
+
const classes = useUtilityClasses(props);
|
|
12
|
+
return /*#__PURE__*/_jsx(ChartsTooltipContainer, _extends({
|
|
13
|
+
trigger: "item"
|
|
14
|
+
}, props, {
|
|
15
|
+
classes: classes,
|
|
16
|
+
children: /*#__PURE__*/_jsx(SankeyTooltipContent, {
|
|
17
|
+
classes: classes
|
|
18
|
+
})
|
|
19
|
+
}));
|
|
20
|
+
}
|
|
21
|
+
process.env.NODE_ENV !== "production" ? SankeyTooltip.propTypes = {
|
|
22
|
+
// ----------------------------- Warning --------------------------------
|
|
23
|
+
// | These PropTypes are generated from the TypeScript type definitions |
|
|
24
|
+
// | To update them edit the TypeScript types and run "pnpm proptypes" |
|
|
25
|
+
// ----------------------------------------------------------------------
|
|
26
|
+
/**
|
|
27
|
+
* An HTML element, [virtualElement](https://popper.js.org/docs/v2/virtual-elements/),
|
|
28
|
+
* or a function that returns either.
|
|
29
|
+
* It's used to set the position of the popper.
|
|
30
|
+
* The return value will passed as the reference object of the Popper instance.
|
|
31
|
+
*/
|
|
32
|
+
anchorEl: PropTypes.oneOfType([(props, propName) => {
|
|
33
|
+
if (props[propName] == null) {
|
|
34
|
+
return new Error(`Prop '${propName}' is required but wasn't specified`);
|
|
35
|
+
}
|
|
36
|
+
if (typeof props[propName] !== 'object' || props[propName].nodeType !== 1) {
|
|
37
|
+
return new Error(`Expected prop '${propName}' to be of type Element`);
|
|
38
|
+
}
|
|
39
|
+
return null;
|
|
40
|
+
}, PropTypes.func, PropTypes.shape({
|
|
41
|
+
contextElement: (props, propName) => {
|
|
42
|
+
if (props[propName] == null) {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
if (typeof props[propName] !== 'object' || props[propName].nodeType !== 1) {
|
|
46
|
+
return new Error(`Expected prop '${propName}' to be of type Element`);
|
|
47
|
+
}
|
|
48
|
+
return null;
|
|
49
|
+
},
|
|
50
|
+
getBoundingClientRect: PropTypes.func.isRequired
|
|
51
|
+
})]),
|
|
52
|
+
/**
|
|
53
|
+
* Override or extend the styles applied to the component.
|
|
54
|
+
*/
|
|
55
|
+
classes: PropTypes.object,
|
|
56
|
+
/**
|
|
57
|
+
* The component used for the root node.
|
|
58
|
+
* Either a string to use a HTML element or a component.
|
|
59
|
+
*/
|
|
60
|
+
component: PropTypes.elementType,
|
|
61
|
+
/**
|
|
62
|
+
* The components used for each slot inside the Popper.
|
|
63
|
+
* Either a string to use a HTML element or a component.
|
|
64
|
+
*
|
|
65
|
+
* @deprecated use the `slots` prop instead. This prop will be removed in a future major release. [How to migrate](/material-ui/migration/migrating-from-deprecated-apis/).
|
|
66
|
+
* @default {}
|
|
67
|
+
*/
|
|
68
|
+
components: PropTypes.shape({
|
|
69
|
+
Root: PropTypes.elementType
|
|
70
|
+
}),
|
|
71
|
+
/**
|
|
72
|
+
* The props used for each slot inside the Popper.
|
|
73
|
+
*
|
|
74
|
+
* @deprecated use the `slotProps` prop instead. This prop will be removed in a future major release. [How to migrate](/material-ui/migration/migrating-from-deprecated-apis/).
|
|
75
|
+
* @default {}
|
|
76
|
+
*/
|
|
77
|
+
componentsProps: PropTypes.shape({
|
|
78
|
+
root: PropTypes.oneOfType([PropTypes.func, PropTypes.object])
|
|
79
|
+
}),
|
|
80
|
+
/**
|
|
81
|
+
* An HTML element or function that returns one.
|
|
82
|
+
* The `container` will have the portal children appended to it.
|
|
83
|
+
*
|
|
84
|
+
* You can also provide a callback, which is called in a React layout effect.
|
|
85
|
+
* This lets you set the container from a ref, and also makes server-side rendering possible.
|
|
86
|
+
*
|
|
87
|
+
* By default, it uses the body of the top-level document object,
|
|
88
|
+
* so it's simply `document.body` most of the time.
|
|
89
|
+
*/
|
|
90
|
+
container: PropTypes.oneOfType([(props, propName) => {
|
|
91
|
+
if (props[propName] == null) {
|
|
92
|
+
return new Error(`Prop '${propName}' is required but wasn't specified`);
|
|
93
|
+
}
|
|
94
|
+
if (typeof props[propName] !== 'object' || props[propName].nodeType !== 1) {
|
|
95
|
+
return new Error(`Expected prop '${propName}' to be of type Element`);
|
|
96
|
+
}
|
|
97
|
+
return null;
|
|
98
|
+
}, PropTypes.func]),
|
|
99
|
+
/**
|
|
100
|
+
* The `children` will be under the DOM hierarchy of the parent component.
|
|
101
|
+
* @default false
|
|
102
|
+
*/
|
|
103
|
+
disablePortal: PropTypes.bool,
|
|
104
|
+
/**
|
|
105
|
+
* Always keep the children in the DOM.
|
|
106
|
+
* This prop can be useful in SEO situation or
|
|
107
|
+
* when you want to maximize the responsiveness of the Popper.
|
|
108
|
+
* @default false
|
|
109
|
+
*/
|
|
110
|
+
keepMounted: PropTypes.bool,
|
|
111
|
+
/**
|
|
112
|
+
* Popper.js is based on a "plugin-like" architecture,
|
|
113
|
+
* most of its features are fully encapsulated "modifiers".
|
|
114
|
+
*
|
|
115
|
+
* A modifier is a function that is called each time Popper.js needs to
|
|
116
|
+
* compute the position of the popper.
|
|
117
|
+
* For this reason, modifiers should be very performant to avoid bottlenecks.
|
|
118
|
+
* To learn how to create a modifier, [read the modifiers documentation](https://popper.js.org/docs/v2/modifiers/).
|
|
119
|
+
*/
|
|
120
|
+
modifiers: PropTypes.arrayOf(PropTypes.shape({
|
|
121
|
+
data: PropTypes.object,
|
|
122
|
+
effect: PropTypes.func,
|
|
123
|
+
enabled: PropTypes.bool,
|
|
124
|
+
fn: PropTypes.func,
|
|
125
|
+
name: PropTypes.any,
|
|
126
|
+
options: PropTypes.object,
|
|
127
|
+
phase: PropTypes.oneOf(['afterMain', 'afterRead', 'afterWrite', 'beforeMain', 'beforeRead', 'beforeWrite', 'main', 'read', 'write']),
|
|
128
|
+
requires: PropTypes.arrayOf(PropTypes.string),
|
|
129
|
+
requiresIfExists: PropTypes.arrayOf(PropTypes.string)
|
|
130
|
+
})),
|
|
131
|
+
/**
|
|
132
|
+
* If `true`, the component is shown.
|
|
133
|
+
*/
|
|
134
|
+
open: PropTypes.bool,
|
|
135
|
+
/**
|
|
136
|
+
* Popper placement.
|
|
137
|
+
* @default 'bottom'
|
|
138
|
+
*/
|
|
139
|
+
placement: PropTypes.oneOf(['auto-end', 'auto-start', 'auto', 'bottom-end', 'bottom-start', 'bottom', 'left-end', 'left-start', 'left', 'right-end', 'right-start', 'right', 'top-end', 'top-start', 'top']),
|
|
140
|
+
/**
|
|
141
|
+
* Options provided to the [`Popper.js`](https://popper.js.org/docs/v2/constructors/#options) instance.
|
|
142
|
+
* @default {}
|
|
143
|
+
*/
|
|
144
|
+
popperOptions: PropTypes.shape({
|
|
145
|
+
modifiers: PropTypes.array,
|
|
146
|
+
onFirstUpdate: PropTypes.func,
|
|
147
|
+
placement: PropTypes.oneOf(['auto-end', 'auto-start', 'auto', 'bottom-end', 'bottom-start', 'bottom', 'left-end', 'left-start', 'left', 'right-end', 'right-start', 'right', 'top-end', 'top-start', 'top']),
|
|
148
|
+
strategy: PropTypes.oneOf(['absolute', 'fixed'])
|
|
149
|
+
}),
|
|
150
|
+
/**
|
|
151
|
+
* A ref that points to the used popper instance.
|
|
152
|
+
*/
|
|
153
|
+
popperRef: PropTypes.oneOfType([PropTypes.func, PropTypes.shape({
|
|
154
|
+
current: PropTypes.shape({
|
|
155
|
+
destroy: PropTypes.func.isRequired,
|
|
156
|
+
forceUpdate: PropTypes.func.isRequired,
|
|
157
|
+
setOptions: PropTypes.func.isRequired,
|
|
158
|
+
state: PropTypes.shape({
|
|
159
|
+
attributes: PropTypes.object.isRequired,
|
|
160
|
+
elements: PropTypes.object.isRequired,
|
|
161
|
+
modifiersData: PropTypes.object.isRequired,
|
|
162
|
+
options: PropTypes.object.isRequired,
|
|
163
|
+
orderedModifiers: PropTypes.arrayOf(PropTypes.object).isRequired,
|
|
164
|
+
placement: PropTypes.oneOf(['auto-end', 'auto-start', 'auto', 'bottom-end', 'bottom-start', 'bottom', 'left-end', 'left-start', 'left', 'right-end', 'right-start', 'right', 'top-end', 'top-start', 'top']).isRequired,
|
|
165
|
+
rects: PropTypes.object.isRequired,
|
|
166
|
+
reset: PropTypes.bool.isRequired,
|
|
167
|
+
scrollParents: PropTypes.object.isRequired,
|
|
168
|
+
strategy: PropTypes.oneOf(['absolute', 'fixed']).isRequired,
|
|
169
|
+
styles: PropTypes.object.isRequired
|
|
170
|
+
}).isRequired,
|
|
171
|
+
update: PropTypes.func.isRequired
|
|
172
|
+
})
|
|
173
|
+
})]),
|
|
174
|
+
/**
|
|
175
|
+
* The props used for each slot inside the Popper.
|
|
176
|
+
* @default {}
|
|
177
|
+
*/
|
|
178
|
+
slotProps: PropTypes.object,
|
|
179
|
+
/**
|
|
180
|
+
* The components used for each slot inside the Popper.
|
|
181
|
+
* Either a string to use a HTML element or a component.
|
|
182
|
+
* @default {}
|
|
183
|
+
*/
|
|
184
|
+
slots: PropTypes.object,
|
|
185
|
+
/**
|
|
186
|
+
* The system prop that allows defining system overrides as well as additional CSS styles.
|
|
187
|
+
*/
|
|
188
|
+
sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
|
|
189
|
+
/**
|
|
190
|
+
* Help supporting a react-transition-group/Transition component.
|
|
191
|
+
* @default false
|
|
192
|
+
*/
|
|
193
|
+
transition: PropTypes.bool,
|
|
194
|
+
/**
|
|
195
|
+
* Select the kind of tooltip to display
|
|
196
|
+
* - 'item': Shows data about the item below the mouse.
|
|
197
|
+
* - 'none': Does not display tooltip
|
|
198
|
+
* @default 'item'
|
|
199
|
+
*/
|
|
200
|
+
trigger: PropTypes.oneOf(['item', 'none'])
|
|
201
|
+
} : void 0;
|
|
202
|
+
export { SankeyTooltip };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ChartsTooltipContainerProps } from '@mui/x-charts/ChartsTooltip';
|
|
2
|
+
export interface SankeyTooltipProps extends Omit<ChartsTooltipContainerProps, 'trigger' | 'children'> {
|
|
3
|
+
/**
|
|
4
|
+
* Select the kind of tooltip to display
|
|
5
|
+
* - 'item': Shows data about the item below the mouse.
|
|
6
|
+
* - 'none': Does not display tooltip
|
|
7
|
+
* @default 'item'
|
|
8
|
+
*/
|
|
9
|
+
trigger?: 'item' | 'none';
|
|
10
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { SankeyTooltipProps } from "./SankeyTooltip.types.js";
|
|
3
|
+
export interface SankeyTooltipContentProps extends Pick<SankeyTooltipProps, 'classes'> {}
|
|
4
|
+
export declare function SankeyTooltipContent(props: SankeyTooltipContentProps): React.JSX.Element | null;
|
|
5
|
+
export declare namespace SankeyTooltipContent {
|
|
6
|
+
var propTypes: any;
|
|
7
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import PropTypes from 'prop-types';
|
|
5
|
+
import clsx from 'clsx';
|
|
6
|
+
import { ChartsTooltipPaper, ChartsTooltipTable, ChartsTooltipRow, ChartsTooltipCell, useItemTooltip } from '@mui/x-charts/ChartsTooltip';
|
|
7
|
+
import { ChartsLabelMark } from '@mui/x-charts/internals';
|
|
8
|
+
import { useUtilityClasses } from "./SankeyTooltip.classes.js";
|
|
9
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
10
|
+
export function SankeyTooltipContent(props) {
|
|
11
|
+
const classes = useUtilityClasses(props);
|
|
12
|
+
const tooltipData = useItemTooltip();
|
|
13
|
+
if (!tooltipData) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
const {
|
|
17
|
+
color,
|
|
18
|
+
formattedValue,
|
|
19
|
+
markType,
|
|
20
|
+
label
|
|
21
|
+
} = tooltipData;
|
|
22
|
+
return /*#__PURE__*/_jsx(ChartsTooltipPaper, {
|
|
23
|
+
className: classes.paper,
|
|
24
|
+
children: /*#__PURE__*/_jsx(ChartsTooltipTable, {
|
|
25
|
+
className: classes.table,
|
|
26
|
+
children: /*#__PURE__*/_jsx("tbody", {
|
|
27
|
+
children: /*#__PURE__*/_jsxs(ChartsTooltipRow, {
|
|
28
|
+
className: classes.row,
|
|
29
|
+
children: [/*#__PURE__*/_jsxs(ChartsTooltipCell, {
|
|
30
|
+
className: clsx(classes.cell),
|
|
31
|
+
component: "th",
|
|
32
|
+
children: [/*#__PURE__*/_jsx("div", {
|
|
33
|
+
className: classes.markContainer,
|
|
34
|
+
children: /*#__PURE__*/_jsx(ChartsLabelMark, {
|
|
35
|
+
type: markType,
|
|
36
|
+
color: color,
|
|
37
|
+
className: classes.mark
|
|
38
|
+
})
|
|
39
|
+
}), label]
|
|
40
|
+
}), /*#__PURE__*/_jsx(ChartsTooltipCell, {
|
|
41
|
+
className: clsx(classes.valueCell, classes.cell),
|
|
42
|
+
component: "td",
|
|
43
|
+
children: formattedValue
|
|
44
|
+
})]
|
|
45
|
+
})
|
|
46
|
+
})
|
|
47
|
+
})
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
process.env.NODE_ENV !== "production" ? SankeyTooltipContent.propTypes = {
|
|
51
|
+
// ----------------------------- Warning --------------------------------
|
|
52
|
+
// | These PropTypes are generated from the TypeScript type definitions |
|
|
53
|
+
// | To update them edit the TypeScript types and run "pnpm proptypes" |
|
|
54
|
+
// ----------------------------------------------------------------------
|
|
55
|
+
/**
|
|
56
|
+
* Override or extend the styles applied to the component.
|
|
57
|
+
*/
|
|
58
|
+
classes: PropTypes.object
|
|
59
|
+
} : void 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,135 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
4
|
+
import { sankey } from '@mui/x-charts-vendor/d3-sankey';
|
|
5
|
+
import { path } from '@mui/x-charts-vendor/d3-path';
|
|
6
|
+
import { getNodeAlignFunction } from "./utils.js";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Calculates the layout for a Sankey diagram using d3-sankey
|
|
10
|
+
*
|
|
11
|
+
* @param data The Sankey data (nodes and links)
|
|
12
|
+
* @param drawingArea The drawing area dimensions
|
|
13
|
+
* @param options Layout configuration options
|
|
14
|
+
* @returns The calculated layout
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
export function calculateSankeyLayout(data, drawingArea, theme, series = {}) {
|
|
18
|
+
const {
|
|
19
|
+
iterations = 6,
|
|
20
|
+
nodeOptions,
|
|
21
|
+
linkOptions
|
|
22
|
+
} = series;
|
|
23
|
+
const {
|
|
24
|
+
width: nodeWidth = 15,
|
|
25
|
+
padding: nodePadding = 10,
|
|
26
|
+
align: nodeAlign = 'justify',
|
|
27
|
+
sort: nodeSort = null
|
|
28
|
+
} = nodeOptions ?? {};
|
|
29
|
+
const {
|
|
30
|
+
color: linkColor = (theme.vars || theme).palette.text.primary,
|
|
31
|
+
sort: linkSort = null,
|
|
32
|
+
curveCorrection = 10
|
|
33
|
+
} = linkOptions ?? {};
|
|
34
|
+
const {
|
|
35
|
+
width,
|
|
36
|
+
height,
|
|
37
|
+
left,
|
|
38
|
+
top,
|
|
39
|
+
bottom,
|
|
40
|
+
right
|
|
41
|
+
} = drawingArea;
|
|
42
|
+
if (!data || !data.links) {
|
|
43
|
+
return {
|
|
44
|
+
nodes: [],
|
|
45
|
+
links: []
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Prepare the data structure expected by d3-sankey
|
|
50
|
+
const graph = {
|
|
51
|
+
nodes: data.nodes.values().toArray().map(v => _extends({}, v)),
|
|
52
|
+
links: data.links.map(v => _extends({}, v))
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
// Create the sankey layout generator
|
|
56
|
+
let sankeyGenerator = sankey().nodeWidth(nodeWidth).nodePadding(nodePadding).nodeAlign(getNodeAlignFunction(nodeAlign)).extent([[left, top], [width + right, height + bottom]]).nodeId(d => d.id).iterations(iterations);
|
|
57
|
+
if (nodeSort) {
|
|
58
|
+
sankeyGenerator = sankeyGenerator.nodeSort(nodeSort);
|
|
59
|
+
}
|
|
60
|
+
if (linkSort) {
|
|
61
|
+
sankeyGenerator = sankeyGenerator.linkSort(linkSort);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Generate the layout
|
|
65
|
+
let result;
|
|
66
|
+
try {
|
|
67
|
+
result = sankeyGenerator(graph);
|
|
68
|
+
} catch (error) {
|
|
69
|
+
// There are two errors that can occur:
|
|
70
|
+
// 1. If the data contains circular references, d3-sankey will throw an error.
|
|
71
|
+
// 2. If there are missing source/target nodes, d3-sankey will throw an error.
|
|
72
|
+
// We handle the second case by building a map of nodes ourselves, so they are always present.
|
|
73
|
+
if (error instanceof Error && error.message === 'circular link') {
|
|
74
|
+
throw new Error('MUI X Charts: Sankey diagram contains circular references.');
|
|
75
|
+
}
|
|
76
|
+
throw error;
|
|
77
|
+
}
|
|
78
|
+
const {
|
|
79
|
+
nodes,
|
|
80
|
+
links
|
|
81
|
+
} = result;
|
|
82
|
+
|
|
83
|
+
// Convert d3-sankey links to our format
|
|
84
|
+
const layoutLinks = links.map(link => {
|
|
85
|
+
// Get the original link data
|
|
86
|
+
const originalLink = data.links.find(l => {
|
|
87
|
+
return l.source === link.source.id && l.target === link.target.id;
|
|
88
|
+
});
|
|
89
|
+
return _extends({}, originalLink, link, {
|
|
90
|
+
color: originalLink?.color ?? linkColor,
|
|
91
|
+
path: improvedNaiveSankeyLinkPathHorizontal(link, curveCorrection)
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
const layoutNodes = nodes.map(node => {
|
|
95
|
+
const originalNode = data.nodes.get(node.id) || {};
|
|
96
|
+
return _extends({}, originalNode, node);
|
|
97
|
+
});
|
|
98
|
+
return {
|
|
99
|
+
nodes: layoutNodes,
|
|
100
|
+
links: layoutLinks
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
export function improvedNaiveSankeyLinkPathHorizontal(link, curveCorrection) {
|
|
104
|
+
const sx = link.source.x1;
|
|
105
|
+
const tx = link.target.x0;
|
|
106
|
+
// Weirdly this seems to work for any chart or node width change
|
|
107
|
+
// But needs to be changed when the sankey height changes.
|
|
108
|
+
const correction = curveCorrection ?? 5;
|
|
109
|
+
const y0 = link.y0;
|
|
110
|
+
const y1 = link.y1;
|
|
111
|
+
const w = link.width;
|
|
112
|
+
const halfW = w / 2;
|
|
113
|
+
const sy0 = y0 - halfW;
|
|
114
|
+
const sy1 = y0 + halfW;
|
|
115
|
+
const ty0 = y1 - halfW;
|
|
116
|
+
const ty1 = y1 + halfW;
|
|
117
|
+
const halfX = (tx - sx) / 2;
|
|
118
|
+
const p = path();
|
|
119
|
+
p.moveTo(sx, sy0);
|
|
120
|
+
const isDecreasing = y0 > y1;
|
|
121
|
+
const direction = isDecreasing ? -1 : 1;
|
|
122
|
+
let cpx1 = sx + halfX + correction * direction;
|
|
123
|
+
let cpy1 = sy0;
|
|
124
|
+
let cpx2 = sx + halfX + correction * direction;
|
|
125
|
+
let cpy2 = ty0;
|
|
126
|
+
p.bezierCurveTo(cpx1, cpy1, cpx2, cpy2, tx, ty0);
|
|
127
|
+
p.lineTo(tx, ty1);
|
|
128
|
+
cpx1 = sx + halfX - correction * direction;
|
|
129
|
+
cpy1 = ty1;
|
|
130
|
+
cpx2 = sx + halfX - correction * direction;
|
|
131
|
+
cpy2 = sy1;
|
|
132
|
+
p.bezierCurveTo(cpx1, cpy1, cpx2, cpy2, sx, sy1);
|
|
133
|
+
p.lineTo(sx, sy0);
|
|
134
|
+
return p.toString();
|
|
135
|
+
}
|