@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.
Files changed (120) hide show
  1. package/BarChartPro/BarChartPro.js +0 -36
  2. package/CHANGELOG.md +221 -8
  3. package/ChartDataProviderPro/ChartDataProviderPro.js +1 -1
  4. package/FunnelChart/curves/bump.js +0 -2
  5. package/FunnelChart/curves/linear.js +0 -2
  6. package/FunnelChart/curves/pyramid.js +0 -2
  7. package/FunnelChart/curves/step-pyramid.js +0 -2
  8. package/FunnelChart/curves/step.js +0 -2
  9. package/Heatmap/Heatmap.js +0 -4
  10. package/LineChartPro/LineChartPro.js +0 -36
  11. package/PieChartPro/PieChartPro.js +2 -2
  12. package/SankeyChart/SankeyChart.d.ts +32 -0
  13. package/SankeyChart/SankeyChart.js +161 -0
  14. package/SankeyChart/SankeyChart.plugins.d.ts +3 -0
  15. package/SankeyChart/SankeyChart.plugins.js +11 -0
  16. package/SankeyChart/SankeyLinkElement.d.ts +27 -0
  17. package/SankeyChart/SankeyLinkElement.js +53 -0
  18. package/SankeyChart/SankeyLinkLabel.d.ts +12 -0
  19. package/SankeyChart/SankeyLinkLabel.js +58 -0
  20. package/SankeyChart/SankeyNodeElement.d.ts +27 -0
  21. package/SankeyChart/SankeyNodeElement.js +76 -0
  22. package/SankeyChart/SankeyPlot.d.ts +29 -0
  23. package/SankeyChart/SankeyPlot.js +100 -0
  24. package/SankeyChart/SankeyTooltip/SankeyTooltip.classes.d.ts +2 -0
  25. package/SankeyChart/SankeyTooltip/SankeyTooltip.classes.js +27 -0
  26. package/SankeyChart/SankeyTooltip/SankeyTooltip.d.ts +7 -0
  27. package/SankeyChart/SankeyTooltip/SankeyTooltip.js +208 -0
  28. package/SankeyChart/SankeyTooltip/SankeyTooltip.types.d.ts +10 -0
  29. package/SankeyChart/SankeyTooltip/SankeyTooltip.types.js +5 -0
  30. package/SankeyChart/SankeyTooltip/SankeyTooltipContent.d.ts +7 -0
  31. package/SankeyChart/SankeyTooltip/SankeyTooltipContent.js +66 -0
  32. package/SankeyChart/SankeyTooltip/index.d.ts +3 -0
  33. package/SankeyChart/SankeyTooltip/index.js +27 -0
  34. package/SankeyChart/calculateSankeyLayout.d.ts +13 -0
  35. package/SankeyChart/calculateSankeyLayout.js +141 -0
  36. package/SankeyChart/index.d.ts +9 -0
  37. package/SankeyChart/index.js +70 -0
  38. package/SankeyChart/sankey.types.d.ts +225 -0
  39. package/SankeyChart/sankey.types.js +6 -0
  40. package/SankeyChart/sankeyClasses.d.ts +15 -0
  41. package/SankeyChart/sankeyClasses.js +28 -0
  42. package/SankeyChart/sankeySlots.types.d.ts +24 -0
  43. package/SankeyChart/sankeySlots.types.js +5 -0
  44. package/SankeyChart/seriesConfig/getSeriesWithDefaultValues.d.ts +2 -0
  45. package/SankeyChart/seriesConfig/getSeriesWithDefaultValues.js +55 -0
  46. package/SankeyChart/seriesConfig/index.d.ts +2 -0
  47. package/SankeyChart/seriesConfig/index.js +19 -0
  48. package/SankeyChart/seriesConfig/tooltipGetter.d.ts +2 -0
  49. package/SankeyChart/seriesConfig/tooltipGetter.js +46 -0
  50. package/SankeyChart/useSankeyChartProps.d.ts +22 -0
  51. package/SankeyChart/useSankeyChartProps.js +77 -0
  52. package/SankeyChart/utils.d.ts +3 -0
  53. package/SankeyChart/utils.js +21 -0
  54. package/ScatterChartPro/ScatterChartPro.js +1 -37
  55. package/esm/BarChartPro/BarChartPro.js +0 -36
  56. package/esm/ChartDataProviderPro/ChartDataProviderPro.js +1 -1
  57. package/esm/FunnelChart/curves/bump.js +0 -2
  58. package/esm/FunnelChart/curves/linear.js +0 -2
  59. package/esm/FunnelChart/curves/pyramid.js +0 -2
  60. package/esm/FunnelChart/curves/step-pyramid.js +0 -2
  61. package/esm/FunnelChart/curves/step.js +0 -2
  62. package/esm/Heatmap/Heatmap.js +0 -4
  63. package/esm/LineChartPro/LineChartPro.js +0 -36
  64. package/esm/PieChartPro/PieChartPro.js +2 -2
  65. package/esm/SankeyChart/SankeyChart.d.ts +32 -0
  66. package/esm/SankeyChart/SankeyChart.js +155 -0
  67. package/esm/SankeyChart/SankeyChart.plugins.d.ts +3 -0
  68. package/esm/SankeyChart/SankeyChart.plugins.js +9 -0
  69. package/esm/SankeyChart/SankeyLinkElement.d.ts +27 -0
  70. package/esm/SankeyChart/SankeyLinkElement.js +46 -0
  71. package/esm/SankeyChart/SankeyLinkLabel.d.ts +12 -0
  72. package/esm/SankeyChart/SankeyLinkLabel.js +52 -0
  73. package/esm/SankeyChart/SankeyNodeElement.d.ts +27 -0
  74. package/esm/SankeyChart/SankeyNodeElement.js +69 -0
  75. package/esm/SankeyChart/SankeyPlot.d.ts +29 -0
  76. package/esm/SankeyChart/SankeyPlot.js +94 -0
  77. package/esm/SankeyChart/SankeyTooltip/SankeyTooltip.classes.d.ts +2 -0
  78. package/esm/SankeyChart/SankeyTooltip/SankeyTooltip.classes.js +19 -0
  79. package/esm/SankeyChart/SankeyTooltip/SankeyTooltip.d.ts +7 -0
  80. package/esm/SankeyChart/SankeyTooltip/SankeyTooltip.js +202 -0
  81. package/esm/SankeyChart/SankeyTooltip/SankeyTooltip.types.d.ts +10 -0
  82. package/esm/SankeyChart/SankeyTooltip/SankeyTooltip.types.js +1 -0
  83. package/esm/SankeyChart/SankeyTooltip/SankeyTooltipContent.d.ts +7 -0
  84. package/esm/SankeyChart/SankeyTooltip/SankeyTooltipContent.js +59 -0
  85. package/esm/SankeyChart/SankeyTooltip/index.d.ts +3 -0
  86. package/esm/SankeyChart/SankeyTooltip/index.js +3 -0
  87. package/esm/SankeyChart/calculateSankeyLayout.d.ts +13 -0
  88. package/esm/SankeyChart/calculateSankeyLayout.js +135 -0
  89. package/esm/SankeyChart/index.d.ts +9 -0
  90. package/esm/SankeyChart/index.js +6 -0
  91. package/esm/SankeyChart/sankey.types.d.ts +225 -0
  92. package/esm/SankeyChart/sankey.types.js +3 -0
  93. package/esm/SankeyChart/sankeyClasses.d.ts +15 -0
  94. package/esm/SankeyChart/sankeyClasses.js +19 -0
  95. package/esm/SankeyChart/sankeySlots.types.d.ts +24 -0
  96. package/esm/SankeyChart/sankeySlots.types.js +1 -0
  97. package/esm/SankeyChart/seriesConfig/getSeriesWithDefaultValues.d.ts +2 -0
  98. package/esm/SankeyChart/seriesConfig/getSeriesWithDefaultValues.js +47 -0
  99. package/esm/SankeyChart/seriesConfig/index.d.ts +2 -0
  100. package/esm/SankeyChart/seriesConfig/index.js +14 -0
  101. package/esm/SankeyChart/seriesConfig/tooltipGetter.d.ts +2 -0
  102. package/esm/SankeyChart/seriesConfig/tooltipGetter.js +39 -0
  103. package/esm/SankeyChart/useSankeyChartProps.d.ts +22 -0
  104. package/esm/SankeyChart/useSankeyChartProps.js +70 -0
  105. package/esm/SankeyChart/utils.d.ts +3 -0
  106. package/esm/SankeyChart/utils.js +14 -0
  107. package/esm/ScatterChartPro/ScatterChartPro.js +1 -37
  108. package/esm/hooks/useSankeySeries.d.ts +33 -0
  109. package/esm/hooks/useSankeySeries.js +42 -0
  110. package/esm/index.d.ts +1 -0
  111. package/esm/index.js +2 -1
  112. package/esm/internals/plugins/allPlugins.d.ts +2 -2
  113. package/esm/typeOverloads/modules.d.ts +11 -0
  114. package/hooks/useSankeySeries.d.ts +33 -0
  115. package/hooks/useSankeySeries.js +48 -0
  116. package/index.d.ts +1 -0
  117. package/index.js +13 -1
  118. package/internals/plugins/allPlugins.d.ts +2 -2
  119. package/package.json +6 -6
  120. package/typeOverloads/modules.d.ts +11 -0
@@ -0,0 +1,32 @@
1
+ import * as React from 'react';
2
+ import { type ChartsOverlayProps } from '@mui/x-charts/ChartsOverlay';
3
+ import type { MakeOptional } from '@mui/x-internals/types';
4
+ import { ChartContainerProProps } from "../ChartContainerPro/index.js";
5
+ import { type SankeyPlotProps } from "./SankeyPlot.js";
6
+ import { type SankeyChartPluginsSignatures } from "./SankeyChart.plugins.js";
7
+ import type { SankeySeriesType } from "./sankey.types.js";
8
+ import type { SankeyChartSlotExtension } from "./sankeySlots.types.js";
9
+ export type SankeySeries = MakeOptional<SankeySeriesType, 'type'>;
10
+ export interface SankeyChartProps extends Omit<ChartContainerProProps<'sankey', SankeyChartPluginsSignatures>, 'plugins' | 'series' | 'slotProps' | 'slots' | 'dataset' | 'hideLegend' | 'skipAnimation' | 'highlightedItem' | 'onHighlightChange'>, Omit<SankeyPlotProps, 'data'>, Omit<ChartsOverlayProps, 'slots' | 'slotProps'>, SankeyChartSlotExtension {
11
+ /**
12
+ * The series to display in the Sankey chart.
13
+ * A single object is expected.
14
+ */
15
+ series: SankeySeries;
16
+ }
17
+ /**
18
+ * Sankey Chart component
19
+ *
20
+ * Displays a Sankey diagram, visualizing flows between nodes where the width
21
+ * of the links is proportional to the flow quantity.
22
+ *
23
+ * Demos:
24
+ *
25
+ * - [Sankey Chart](https://mui.com/x/react-charts/sankey/)
26
+ *
27
+ * API:
28
+ *
29
+ * - [SankeyChart API](https://mui.com/x/api/charts/sankey-chart/)
30
+ */
31
+ declare const SankeyChart: React.ForwardRefExoticComponent<SankeyChartProps & React.RefAttributes<SVGSVGElement>>;
32
+ export { SankeyChart };
@@ -0,0 +1,155 @@
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 { useThemeProps } from '@mui/material/styles';
7
+ import { ChartsSurface } from '@mui/x-charts/ChartsSurface';
8
+ import { ChartsOverlay } from '@mui/x-charts/ChartsOverlay';
9
+ import { ChartsWrapper } from '@mui/x-charts/ChartsWrapper';
10
+ import { ChartDataProviderPro } from "../ChartDataProviderPro/index.js";
11
+ import { useChartContainerProProps } from "../ChartContainerPro/useChartContainerProProps.js";
12
+ import { SankeyPlot } from "./SankeyPlot.js";
13
+ import { useSankeyChartProps } from "./useSankeyChartProps.js";
14
+ import { SANKEY_CHART_PLUGINS } from "./SankeyChart.plugins.js";
15
+ import { seriesConfig as sankeySeriesConfig } from "./seriesConfig/index.js";
16
+ import { SankeyTooltip } from "./SankeyTooltip/index.js";
17
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
18
+ const seriesConfig = {
19
+ sankey: sankeySeriesConfig
20
+ };
21
+ /**
22
+ * Sankey Chart component
23
+ *
24
+ * Displays a Sankey diagram, visualizing flows between nodes where the width
25
+ * of the links is proportional to the flow quantity.
26
+ *
27
+ * Demos:
28
+ *
29
+ * - [Sankey Chart](https://mui.com/x/react-charts/sankey/)
30
+ *
31
+ * API:
32
+ *
33
+ * - [SankeyChart API](https://mui.com/x/api/charts/sankey-chart/)
34
+ */
35
+ const SankeyChart = /*#__PURE__*/React.forwardRef(function SankeyChart(props, ref) {
36
+ const themedProps = useThemeProps({
37
+ props,
38
+ name: 'MuiSankeyChart'
39
+ });
40
+ const {
41
+ chartContainerProps,
42
+ sankeyPlotProps,
43
+ overlayProps,
44
+ chartsWrapperProps,
45
+ children
46
+ } = useSankeyChartProps(themedProps);
47
+ const {
48
+ chartDataProviderProProps,
49
+ chartsSurfaceProps
50
+ } = useChartContainerProProps(chartContainerProps, ref);
51
+ const Tooltip = themedProps.slots?.tooltip ?? SankeyTooltip;
52
+ return /*#__PURE__*/_jsx(ChartDataProviderPro, _extends({}, chartDataProviderProProps, {
53
+ seriesConfig: seriesConfig,
54
+ plugins: SANKEY_CHART_PLUGINS,
55
+ children: /*#__PURE__*/_jsxs(ChartsWrapper, _extends({}, chartsWrapperProps, {
56
+ children: [/*#__PURE__*/_jsxs(ChartsSurface, _extends({}, chartsSurfaceProps, {
57
+ children: [/*#__PURE__*/_jsx(SankeyPlot, _extends({}, sankeyPlotProps)), /*#__PURE__*/_jsx(ChartsOverlay, _extends({}, overlayProps)), children]
58
+ })), !themedProps.loading && /*#__PURE__*/_jsx(Tooltip, _extends({
59
+ trigger: "item"
60
+ }, themedProps.slotProps?.tooltip))]
61
+ }))
62
+ }));
63
+ });
64
+ if (process.env.NODE_ENV !== "production") SankeyChart.displayName = "SankeyChart";
65
+ process.env.NODE_ENV !== "production" ? SankeyChart.propTypes = {
66
+ // ----------------------------- Warning --------------------------------
67
+ // | These PropTypes are generated from the TypeScript type definitions |
68
+ // | To update them edit the TypeScript types and run "pnpm proptypes" |
69
+ // ----------------------------------------------------------------------
70
+ apiRef: PropTypes.shape({
71
+ current: PropTypes.object
72
+ }),
73
+ /**
74
+ * Classes applied to the various elements.
75
+ */
76
+ classes: PropTypes.object,
77
+ className: PropTypes.string,
78
+ /**
79
+ * Color palette used to colorize multiple series.
80
+ * @default rainbowSurgePalette
81
+ */
82
+ colors: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string), PropTypes.func]),
83
+ desc: PropTypes.string,
84
+ /**
85
+ * Options to enable features planned for the next major.
86
+ */
87
+ experimentalFeatures: PropTypes.shape({
88
+ preferStrictDomainInLineCharts: PropTypes.bool
89
+ }),
90
+ /**
91
+ * The height of the chart in px. If not defined, it takes the height of the parent element.
92
+ */
93
+ height: PropTypes.number,
94
+ /**
95
+ * This prop is used to help implement the accessibility logic.
96
+ * If you don't provide this prop. It falls back to a randomly generated id.
97
+ */
98
+ id: PropTypes.string,
99
+ /**
100
+ * If `true`, a loading overlay is displayed.
101
+ * @default false
102
+ */
103
+ loading: PropTypes.bool,
104
+ /**
105
+ * Localized text for chart components.
106
+ */
107
+ localeText: PropTypes.object,
108
+ /**
109
+ * The margin between the SVG and the drawing area.
110
+ * It's used for leaving some space for extra information such as the x- and y-axis or legend.
111
+ *
112
+ * Accepts a `number` to be used on all sides or an object with the optional properties: `top`, `bottom`, `left`, and `right`.
113
+ */
114
+ margin: PropTypes.oneOfType([PropTypes.number, PropTypes.shape({
115
+ bottom: PropTypes.number,
116
+ left: PropTypes.number,
117
+ right: PropTypes.number,
118
+ top: PropTypes.number
119
+ })]),
120
+ /**
121
+ * Callback fired when a sankey item is clicked.
122
+ * @param {React.MouseEvent<SVGElement, MouseEvent>} event The event source of the callback.
123
+ * @param {SankeyLinkIdentifierWithData} link The sankey link identifier.
124
+ */
125
+ onLinkClick: PropTypes.func,
126
+ /**
127
+ * Callback fired when a sankey item is clicked.
128
+ * @param {React.MouseEvent<SVGElement, MouseEvent>} event The event source of the callback.
129
+ * @param {SankeyNodeIdentifierWithData} node The sankey node identifier.
130
+ */
131
+ onNodeClick: PropTypes.func,
132
+ /**
133
+ * The series to display in the Sankey chart.
134
+ * A single object is expected.
135
+ */
136
+ series: PropTypes.object.isRequired,
137
+ /**
138
+ * The props used for each component slot.
139
+ * @default {}
140
+ */
141
+ slotProps: PropTypes.object,
142
+ /**
143
+ * Overridable component slots.
144
+ * @default {}
145
+ */
146
+ slots: PropTypes.object,
147
+ sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
148
+ theme: PropTypes.oneOf(['dark', 'light']),
149
+ title: PropTypes.string,
150
+ /**
151
+ * The width of the chart in px. If not defined, it takes the width of the parent element.
152
+ */
153
+ width: PropTypes.number
154
+ } : void 0;
155
+ export { SankeyChart };
@@ -0,0 +1,3 @@
1
+ import { ConvertSignaturesIntoPlugins, UseChartHighlightSignature, UseChartInteractionSignature } from '@mui/x-charts/internals';
2
+ export type SankeyChartPluginsSignatures = [UseChartInteractionSignature, UseChartHighlightSignature];
3
+ export declare const SANKEY_CHART_PLUGINS: ConvertSignaturesIntoPlugins<SankeyChartPluginsSignatures>;
@@ -0,0 +1,9 @@
1
+ import { useChartHighlight
2
+ // useChartHighlight,
3
+ , useChartInteraction } from '@mui/x-charts/internals';
4
+ import // useChartProExport,
5
+ // UseChartProExportSignature,
6
+ "../internals/plugins/useChartProExport/index.js";
7
+ export const SANKEY_CHART_PLUGINS = [useChartInteraction, useChartHighlight
8
+ // useChartProExport,
9
+ ];
@@ -0,0 +1,27 @@
1
+ import * as React from 'react';
2
+ import type { SeriesId } from '@mui/x-charts/internals';
3
+ import { SankeyLayoutLink, type SankeyLinkIdentifierWithData } from "./sankey.types.js";
4
+ export interface SankeyLinkElementProps {
5
+ /**
6
+ * The series ID to which the link belongs
7
+ */
8
+ seriesId: SeriesId;
9
+ /**
10
+ * The link data
11
+ */
12
+ link: SankeyLayoutLink;
13
+ /**
14
+ * Opacity to apply to the link
15
+ */
16
+ opacity?: number;
17
+ /**
18
+ * Callback fired when a sankey item is clicked.
19
+ * @param {React.MouseEvent<SVGElement, MouseEvent>} event The event source of the callback.
20
+ * @param {SankeyLinkIdentifierWithData} link The sankey link identifier.
21
+ */
22
+ onClick?: (event: React.MouseEvent<SVGElement, MouseEvent>, link: SankeyLinkIdentifierWithData) => void;
23
+ }
24
+ /**
25
+ * @ignore - internal component.
26
+ */
27
+ export declare const SankeyLinkElement: React.ForwardRefExoticComponent<SankeyLinkElementProps & React.RefAttributes<SVGPathElement>>;
@@ -0,0 +1,46 @@
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 { jsx as _jsx } from "react/jsx-runtime";
8
+ /**
9
+ * @ignore - internal component.
10
+ */
11
+ export const SankeyLinkElement = /*#__PURE__*/React.forwardRef(function SankeyLinkElement(props, ref) {
12
+ const {
13
+ link,
14
+ opacity = 0.4,
15
+ onClick,
16
+ seriesId
17
+ } = props;
18
+ const identifier = {
19
+ type: 'sankey',
20
+ seriesId,
21
+ subType: 'link',
22
+ targetId: link.target.id,
23
+ sourceId: link.source.id,
24
+ link
25
+ };
26
+
27
+ // Add interaction props for tooltips
28
+ const interactionProps = useInteractionItemProps(identifier);
29
+ const handleClick = useEventCallback(event => {
30
+ onClick?.(event, identifier);
31
+ });
32
+ if (!link.path) {
33
+ return null; // No path defined, nothing to render
34
+ }
35
+ return /*#__PURE__*/_jsx("path", _extends({
36
+ ref: ref,
37
+ d: link.path,
38
+ fill: link.color,
39
+ opacity: opacity,
40
+ "data-link-source": link.source.id,
41
+ "data-link-target": link.target.id,
42
+ onClick: onClick ? handleClick : undefined,
43
+ cursor: onClick ? 'pointer' : 'default'
44
+ }, interactionProps));
45
+ });
46
+ if (process.env.NODE_ENV !== "production") SankeyLinkElement.displayName = "SankeyLinkElement";
@@ -0,0 +1,12 @@
1
+ import * as React from 'react';
2
+ import { SankeyLayoutLink } from "./sankey.types.js";
3
+ export interface SankeyLinkLabelProps {
4
+ /**
5
+ * The link data
6
+ */
7
+ link: SankeyLayoutLink;
8
+ }
9
+ /**
10
+ * @ignore - internal component.
11
+ */
12
+ export declare const SankeyLinkLabel: React.ForwardRefExoticComponent<SankeyLinkLabelProps & React.RefAttributes<SVGTextElement>>;
@@ -0,0 +1,52 @@
1
+ 'use client';
2
+
3
+ import * as React from 'react';
4
+ import { useTheme } from '@mui/material/styles';
5
+ import { jsx as _jsx } from "react/jsx-runtime";
6
+ const getLinkMidpoint = link => {
7
+ if (link.y0 === undefined || link.y1 === undefined) {
8
+ return {
9
+ x: 0,
10
+ y: 0
11
+ };
12
+ }
13
+
14
+ // For Sankey links, we can calculate the midpoint using the source and target positions
15
+ const sourceX = link.source.x1 || 0;
16
+ const sourceY = (link.y0 + link.y1) / 2;
17
+ const targetX = link.target.x0 || 0;
18
+ const targetY = (link.y0 + link.y1) / 2;
19
+ return {
20
+ x: (sourceX + targetX) / 2,
21
+ y: (sourceY + targetY) / 2
22
+ };
23
+ };
24
+
25
+ /**
26
+ * @ignore - internal component.
27
+ */
28
+ export const SankeyLinkLabel = /*#__PURE__*/React.forwardRef(function SankeyLinkLabel(props, ref) {
29
+ const {
30
+ link
31
+ } = props;
32
+ const theme = useTheme();
33
+ if (!link.path || link.y0 === undefined || link.y1 === undefined) {
34
+ return null; // No path defined or invalid coordinates, nothing to render
35
+ }
36
+ const midpoint = getLinkMidpoint(link);
37
+ return /*#__PURE__*/_jsx("text", {
38
+ ref: ref,
39
+ x: midpoint.x,
40
+ y: midpoint.y,
41
+ textAnchor: "middle",
42
+ dominantBaseline: "middle",
43
+ fontSize: theme.typography.caption.fontSize,
44
+ fill: (theme.vars || theme).palette.text.primary,
45
+ "data-link-source": link.source.id,
46
+ "data-link-target": link.target.id,
47
+ fontFamily: theme.typography.fontFamily,
48
+ pointerEvents: "none",
49
+ children: link.value
50
+ });
51
+ });
52
+ if (process.env.NODE_ENV !== "production") SankeyLinkLabel.displayName = "SankeyLinkLabel";
@@ -0,0 +1,27 @@
1
+ import * as React from 'react';
2
+ import type { SeriesId } from '@mui/x-charts/internals';
3
+ import { SankeyLayoutNode, type SankeyNodeIdentifierWithData } from "./sankey.types.js";
4
+ export interface SankeyNodeElementProps {
5
+ /**
6
+ * The series ID to which the node belongs
7
+ */
8
+ seriesId: SeriesId;
9
+ /**
10
+ * The node data
11
+ */
12
+ node: SankeyLayoutNode;
13
+ /**
14
+ * Whether to show the node label
15
+ */
16
+ showLabel?: boolean;
17
+ /**
18
+ * Callback fired when a sankey item is clicked.
19
+ * @param {React.MouseEvent<SVGElement, MouseEvent>} event The event source of the callback.
20
+ * @param {SankeyNodeIdentifierWithData} node The sankey node identifier.
21
+ */
22
+ onClick?: (event: React.MouseEvent<SVGElement, MouseEvent>, node: SankeyNodeIdentifierWithData) => void;
23
+ }
24
+ /**
25
+ * @ignore - internal component.
26
+ */
27
+ export declare const SankeyNodeElement: React.ForwardRefExoticComponent<SankeyNodeElementProps & React.RefAttributes<SVGGElement>>;
@@ -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,2 @@
1
+ import type { SankeyTooltipProps } from "./SankeyTooltip.types.js";
2
+ export declare const useUtilityClasses: (props: Pick<SankeyTooltipProps, "classes">) => Record<"mark" | "table" | "cell" | "row" | "root" | "paper" | "markContainer" | "labelCell" | "valueCell", string>;
@@ -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,7 @@
1
+ import * as React from 'react';
2
+ import { SankeyTooltipProps } from "./SankeyTooltip.types.js";
3
+ declare function SankeyTooltip(props: SankeyTooltipProps): React.JSX.Element;
4
+ declare namespace SankeyTooltip {
5
+ var propTypes: any;
6
+ }
7
+ export { SankeyTooltip };