@mui/x-charts-pro 8.14.0 → 8.14.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.
Files changed (50) hide show
  1. package/CHANGELOG.md +95 -0
  2. package/ChartDataProviderPro/ChartDataProviderPro.js +1 -1
  3. package/SankeyChart/SankeyChart.d.ts +1 -1
  4. package/SankeyChart/SankeyChart.js +30 -0
  5. package/SankeyChart/SankeyChart.plugins.d.ts +3 -2
  6. package/SankeyChart/SankeyChart.plugins.js +2 -1
  7. package/SankeyChart/SankeyLinkElement.d.ts +1 -1
  8. package/SankeyChart/SankeyLinkElement.js +15 -2
  9. package/SankeyChart/SankeyNodeElement.d.ts +1 -1
  10. package/SankeyChart/SankeyNodeElement.js +16 -1
  11. package/SankeyChart/SankeyPlot.js +13 -1
  12. package/SankeyChart/plugins/index.d.ts +3 -0
  13. package/SankeyChart/plugins/index.js +49 -0
  14. package/SankeyChart/plugins/useSankeyHighlight.d.ts +7 -0
  15. package/SankeyChart/plugins/useSankeyHighlight.js +76 -0
  16. package/SankeyChart/plugins/useSankeyHighlight.selectors.d.ts +68 -0
  17. package/SankeyChart/plugins/useSankeyHighlight.selectors.js +126 -0
  18. package/SankeyChart/plugins/useSankeyHighlight.types.d.ts +55 -0
  19. package/SankeyChart/plugins/useSankeyHighlight.types.js +5 -0
  20. package/SankeyChart/sankey.highlight.types.d.ts +42 -0
  21. package/SankeyChart/sankey.highlight.types.js +6 -0
  22. package/SankeyChart/sankey.types.d.ts +3 -2
  23. package/SankeyChart/sankeyClasses.d.ts +1 -1
  24. package/SankeyChart/useSankeyChartProps.js +5 -5
  25. package/esm/ChartDataProviderPro/ChartDataProviderPro.js +1 -1
  26. package/esm/SankeyChart/SankeyChart.d.ts +1 -1
  27. package/esm/SankeyChart/SankeyChart.js +30 -0
  28. package/esm/SankeyChart/SankeyChart.plugins.d.ts +3 -2
  29. package/esm/SankeyChart/SankeyChart.plugins.js +3 -4
  30. package/esm/SankeyChart/SankeyLinkElement.d.ts +1 -1
  31. package/esm/SankeyChart/SankeyLinkElement.js +16 -3
  32. package/esm/SankeyChart/SankeyNodeElement.d.ts +1 -1
  33. package/esm/SankeyChart/SankeyNodeElement.js +17 -2
  34. package/esm/SankeyChart/SankeyPlot.js +15 -3
  35. package/esm/SankeyChart/plugins/index.d.ts +3 -0
  36. package/esm/SankeyChart/plugins/index.js +3 -0
  37. package/esm/SankeyChart/plugins/useSankeyHighlight.d.ts +7 -0
  38. package/esm/SankeyChart/plugins/useSankeyHighlight.js +68 -0
  39. package/esm/SankeyChart/plugins/useSankeyHighlight.selectors.d.ts +68 -0
  40. package/esm/SankeyChart/plugins/useSankeyHighlight.selectors.js +120 -0
  41. package/esm/SankeyChart/plugins/useSankeyHighlight.types.d.ts +55 -0
  42. package/esm/SankeyChart/plugins/useSankeyHighlight.types.js +1 -0
  43. package/esm/SankeyChart/sankey.highlight.types.d.ts +42 -0
  44. package/esm/SankeyChart/sankey.highlight.types.js +3 -0
  45. package/esm/SankeyChart/sankey.types.d.ts +3 -2
  46. package/esm/SankeyChart/sankeyClasses.d.ts +1 -1
  47. package/esm/SankeyChart/useSankeyChartProps.js +5 -5
  48. package/esm/index.js +1 -1
  49. package/index.js +1 -1
  50. package/package.json +5 -5
@@ -0,0 +1,126 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.selectorSankeyHighlightedItem = exports.selectorNodeHighlightConfig = exports.selectorNodeFadeConfig = exports.selectorLinkHighlightConfig = exports.selectorLinkFadeConfig = exports.selectorIsSankeyItemFaded = exports.selectorIsNodeHighlighted = exports.selectorIsLinkHighlighted = void 0;
7
+ var _internals = require("@mui/x-charts/internals");
8
+ const selectorSankeyHighlight = state => state.highlight;
9
+ const selectSeries = state => state.series;
10
+ const selectorSankeySeries = (0, _internals.createSelector)([selectSeries], series => series.processedSeries.sankey?.series[series.processedSeries.sankey?.seriesOrder[0]] || null);
11
+ const DEFAULT_NODE_HIGHLIGHT = 'links';
12
+ const DEFAULT_LINK_HIGHLIGHT = 'links';
13
+ const DEFAULT_FADE = 'none';
14
+
15
+ /**
16
+ * Get the node highlight configuration from the Sankey series.
17
+ * Defaults to 'nodes' if not specified.
18
+ */
19
+ const selectorNodeHighlightConfig = exports.selectorNodeHighlightConfig = (0, _internals.createSelector)([selectorSankeySeries], series => series?.nodeOptions?.highlight ?? DEFAULT_NODE_HIGHLIGHT);
20
+
21
+ /**
22
+ * Get the node fade configuration from the Sankey series.
23
+ * Defaults to 'none' if not specified.
24
+ */
25
+ const selectorNodeFadeConfig = exports.selectorNodeFadeConfig = (0, _internals.createSelector)([selectorSankeySeries], series => series?.nodeOptions?.fade ?? DEFAULT_FADE);
26
+
27
+ /**
28
+ * Get the link highlight configuration from the Sankey series.
29
+ * Defaults to 'links' if not specified.
30
+ */
31
+ const selectorLinkHighlightConfig = exports.selectorLinkHighlightConfig = (0, _internals.createSelector)([selectorSankeySeries], series => series?.linkOptions?.highlight ?? DEFAULT_LINK_HIGHLIGHT);
32
+
33
+ /**
34
+ * Get the link fade configuration from the Sankey series.
35
+ * Defaults to 'none' if not specified.
36
+ */
37
+ const selectorLinkFadeConfig = exports.selectorLinkFadeConfig = (0, _internals.createSelector)([selectorSankeySeries], series => series?.linkOptions?.fade ?? DEFAULT_FADE);
38
+
39
+ /**
40
+ * Get the currently highlighted item in the Sankey chart.
41
+ * @param {UseSankeyHighlightSignature['state']} state The state of the chart.
42
+ * @returns {SankeyItemIdentifier | null} The highlighted item identifier or null.
43
+ */
44
+ const selectorSankeyHighlightedItem = exports.selectorSankeyHighlightedItem = (0, _internals.createSelector)([selectorSankeyHighlight], highlight => highlight.item);
45
+
46
+ /**
47
+ * Determines if a specific node should be highlighted.
48
+ * A node is highlighted if:
49
+ * - It's the highlighted node (unless highlight mode is 'none')
50
+ * - It's connected to a highlighted link (based on linkOptions.highlight)
51
+ */
52
+ const selectorIsNodeHighlighted = exports.selectorIsNodeHighlighted = (0, _internals.createSelector)([selectorSankeyHighlightedItem, selectorNodeHighlightConfig, selectorLinkHighlightConfig, (_, node) => node.id], (highlightedItem, nodeHighlight, linkHighlight, nodeId) => {
53
+ if (!highlightedItem) {
54
+ return false;
55
+ }
56
+ if (highlightedItem.subType === 'node' && highlightedItem.nodeId === nodeId) {
57
+ return nodeHighlight !== 'none';
58
+ }
59
+ if (highlightedItem.subType === 'link') {
60
+ if (!linkHighlight || linkHighlight === 'none' || linkHighlight === 'links') {
61
+ return false;
62
+ }
63
+ const {
64
+ sourceId,
65
+ targetId
66
+ } = highlightedItem;
67
+ switch (linkHighlight) {
68
+ case 'nodes':
69
+ return nodeId === sourceId || nodeId === targetId;
70
+ case 'source':
71
+ return nodeId === sourceId;
72
+ case 'target':
73
+ return nodeId === targetId;
74
+ default:
75
+ return false;
76
+ }
77
+ }
78
+ return false;
79
+ });
80
+
81
+ /**
82
+ * Selector that determines if a specific link should be highlighted.
83
+ * A link is highlighted if:
84
+ * - It's the highlighted link (unless highlight mode is 'none')
85
+ * - It's connected to a highlighted node (based on nodeOptions.highlight)
86
+ */
87
+ const selectorIsLinkHighlighted = exports.selectorIsLinkHighlighted = (0, _internals.createSelector)([selectorSankeyHighlightedItem, selectorNodeHighlightConfig, selectorLinkHighlightConfig, (_, link) => link], (highlightedItem, nodeHighlight, linkHighlight, link) => {
88
+ if (!highlightedItem) {
89
+ return false;
90
+ }
91
+ if (highlightedItem.subType === 'link' && highlightedItem.sourceId === link.source.id && highlightedItem.targetId === link.target.id) {
92
+ return linkHighlight !== 'none';
93
+ }
94
+ if (highlightedItem.subType === 'node') {
95
+ if (!nodeHighlight || nodeHighlight === 'none' || nodeHighlight === 'nodes') {
96
+ return false;
97
+ }
98
+ const highlightedNodeId = highlightedItem.nodeId;
99
+ switch (nodeHighlight) {
100
+ case 'links':
101
+ return link.source.id === highlightedNodeId || link.target.id === highlightedNodeId;
102
+ case 'incoming':
103
+ return link.target.id === highlightedNodeId;
104
+ case 'outgoing':
105
+ return link.source.id === highlightedNodeId;
106
+ default:
107
+ return false;
108
+ }
109
+ }
110
+ return false;
111
+ });
112
+
113
+ /**
114
+ * Selector that determines if an item should be faded.
115
+ * An item is faded if:
116
+ * - There's a highlighted item
117
+ * - This item is not highlighted
118
+ * - The fade mode is 'global' for the highlighted element type
119
+ */
120
+ const selectorIsSankeyItemFaded = exports.selectorIsSankeyItemFaded = (0, _internals.createSelector)([selectorSankeyHighlightedItem, selectorNodeFadeConfig, selectorLinkFadeConfig, (_, isHighlighted) => isHighlighted], (highlightedItem, nodeFade, linkFade, isHighlighted) => {
121
+ if (!highlightedItem || isHighlighted) {
122
+ return false;
123
+ }
124
+ const fadeMode = highlightedItem.subType === 'node' ? nodeFade : linkFade;
125
+ return fadeMode === 'global';
126
+ });
@@ -0,0 +1,55 @@
1
+ import { DefaultizedProps } from '@mui/x-internals/types';
2
+ import { ChartPluginSignature } from '@mui/x-charts/internals';
3
+ import { SankeyItemIdentifier } from "../sankey.types.js";
4
+ /**
5
+ * The data of the highlighted item in a Sankey chart.
6
+ * Can be either a node or a link.
7
+ *
8
+ * @example
9
+ * // Highlight a node
10
+ * { type: 'sankey', seriesId: 'series-1', subType: 'node', nodeId: 'A' }
11
+ *
12
+ * // Highlight a link
13
+ * { type: 'sankey', seriesId: 'series-1', subType: 'link', sourceId: 'A', targetId: 'B' }
14
+ *
15
+ * // Clear the highlight
16
+ * null
17
+ */
18
+ export type SankeyHighlightItemData = SankeyItemIdentifier;
19
+ export interface UseSankeyHighlightInstance {
20
+ /**
21
+ * Remove all highlight.
22
+ */
23
+ clearHighlight: () => void;
24
+ /**
25
+ * Set the highlighted item.
26
+ * @param {SankeyHighlightItemData} item The item to highlight.
27
+ */
28
+ setHighlight: (item: SankeyHighlightItemData) => void;
29
+ }
30
+ export interface UseSankeyHighlightParameters {
31
+ /**
32
+ * The highlighted item.
33
+ * Used when the highlight is controlled.
34
+ */
35
+ highlightedItem?: SankeyHighlightItemData | null;
36
+ /**
37
+ * The callback fired when the highlighted item changes.
38
+ *
39
+ * @param {SankeyHighlightItemData | null} highlightedItem The newly highlighted item.
40
+ */
41
+ onHighlightChange?: (highlightedItem: SankeyHighlightItemData | null) => void;
42
+ }
43
+ export type UseSankeyHighlightDefaultizedParameters = DefaultizedProps<UseSankeyHighlightParameters, 'highlightedItem'>;
44
+ export interface UseSankeyHighlightState {
45
+ highlight: {
46
+ item: SankeyHighlightItemData | null;
47
+ };
48
+ }
49
+ export type UseSankeyHighlightSignature = ChartPluginSignature<{
50
+ instance: UseSankeyHighlightInstance;
51
+ state: UseSankeyHighlightState;
52
+ params: UseSankeyHighlightParameters;
53
+ defaultizedParams: UseSankeyHighlightDefaultizedParameters;
54
+ modelNames: 'highlightedItem';
55
+ }>;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -0,0 +1,42 @@
1
+ export type SankeyNodeHighlight = 'nodes' | 'links' | 'incoming' | 'outgoing' | 'none';
2
+ export type SankeyNodeFade = 'global' | 'none';
3
+ export type SankeyLinkHighlight = 'links' | 'nodes' | 'source' | 'target' | 'none';
4
+ export type SankeyLinkFade = 'global' | 'none';
5
+ export type SankeyNodeHighlightScope = {
6
+ /**
7
+ * Highlight mode for nodes
8
+ * - 'nodes': Highlight hovered node
9
+ * - 'links': Highlight links connected to hovered node
10
+ * - 'incoming': Highlight incoming links to hovered node
11
+ * - 'outgoing': Highlight outgoing links from hovered node
12
+ * - 'none': No highlighting
13
+ * @default 'links'
14
+ */
15
+ highlight?: SankeyNodeHighlight;
16
+ /**
17
+ * Fade mode for nodes
18
+ * - 'global': Fade all non-highlighted items
19
+ * - 'none': No fading
20
+ * @default 'none'
21
+ */
22
+ fade?: SankeyNodeFade;
23
+ };
24
+ export type SankeyLinkHighlightScope = {
25
+ /**
26
+ * Highlight mode for links
27
+ * - 'links': Highlight hovered link
28
+ * - 'nodes': Highlight nodes connected to hovered link
29
+ * - 'source': Highlight source node of hovered link
30
+ * - 'target': Highlight target node of hovered link
31
+ * - 'none': No highlighting
32
+ * @default 'links'
33
+ */
34
+ highlight?: SankeyLinkHighlight;
35
+ /**
36
+ * Fade mode for links
37
+ * - 'global': Fade all non-highlighted items
38
+ * - 'none': No fading
39
+ * @default 'none'
40
+ */
41
+ fade?: SankeyLinkFade;
42
+ };
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ 'use client';
3
+
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
@@ -1,6 +1,7 @@
1
1
  import type { HighlightScope, SeriesId } from '@mui/x-charts/internals';
2
2
  import type { DefaultizedProps, MakeRequired } from '@mui/x-internals/types';
3
3
  import type { SankeyLink as D3SankeyLink, SankeyNode as D3SankeyNode } from '@mui/x-charts-vendor/d3-sankey';
4
+ import type { SankeyLinkHighlightScope, SankeyNodeHighlightScope } from "./sankey.highlight.types.js";
4
5
  export type SankeyNodeId = string | number;
5
6
  export interface SankeyNode {
6
7
  /**
@@ -79,7 +80,7 @@ export type SankeyNodeOptions = {
79
80
  * @returns {number} Comparison result
80
81
  */
81
82
  sort?: (a: SankeyLayoutNode, b: SankeyLayoutNode) => number | null;
82
- };
83
+ } & SankeyNodeHighlightScope;
83
84
  export type SankeyLinkOptions = {
84
85
  /**
85
86
  * Default color for links without specified colors.
@@ -111,7 +112,7 @@ export type SankeyLinkOptions = {
111
112
  * @default 10
112
113
  */
113
114
  curveCorrection?: number;
114
- };
115
+ } & SankeyLinkHighlightScope;
115
116
  export interface SankeyData {
116
117
  /**
117
118
  * An array of node configs for the Sankey diagram
@@ -12,4 +12,4 @@ export declare function getSankeyPlotUtilityClass(slot: string): string;
12
12
  export declare const sankeyPlotClasses: SankeyPlotClasses;
13
13
  export declare const useUtilityClasses: (ownerState: {
14
14
  classes?: Partial<SankeyPlotClasses>;
15
- }) => Record<"root" | "nodes" | "links" | "linkLabels", string>;
15
+ }) => Record<"nodes" | "links" | "root" | "linkLabels", string>;
@@ -10,7 +10,7 @@ var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runt
10
10
  var _constants = require("@mui/x-charts/constants");
11
11
  var _internals = require("@mui/x-charts/internals");
12
12
  var _SankeyChart = require("./SankeyChart.plugins");
13
- const _excluded = ["series", "width", "height", "margin", "colors", "sx", "children", "slots", "slotProps", "loading", "className", "apiRef", "onNodeClick", "onLinkClick"];
13
+ const _excluded = ["series", "width", "height", "margin", "colors", "sx", "children", "slots", "slotProps", "loading", "highlightedItem", "onHighlightChange", "className", "apiRef", "onNodeClick", "onLinkClick"];
14
14
  /**
15
15
  * A helper function that extracts SankeyChartProps from the input props
16
16
  * and returns an object with props for the children components of SankeyChart.
@@ -30,8 +30,8 @@ const useSankeyChartProps = props => {
30
30
  slots,
31
31
  slotProps,
32
32
  loading,
33
- // highlightedItem,
34
- // onHighlightChange,
33
+ highlightedItem,
34
+ onHighlightChange,
35
35
  className,
36
36
  apiRef,
37
37
  onNodeClick,
@@ -48,8 +48,8 @@ const useSankeyChartProps = props => {
48
48
  margin,
49
49
  colors,
50
50
  sx,
51
- // highlightedItem,
52
- // onHighlightChange,
51
+ highlightedItem,
52
+ onHighlightChange,
53
53
  className,
54
54
  apiRef,
55
55
  plugins: _SankeyChart.SANKEY_CHART_PLUGINS
@@ -11,7 +11,7 @@ import { defaultSlotsMaterial } from "../internals/material/index.js";
11
11
  import { DEFAULT_PLUGINS } from "../internals/plugins/allPlugins.js";
12
12
  import { useChartDataProviderProProps } from "./useChartDataProviderProProps.js";
13
13
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
14
- const releaseInfo = "MTc1OTk2ODAwMDAwMA==";
14
+ const releaseInfo = "MTc2MDU3MjgwMDAwMA==";
15
15
  const packageIdentifier = 'x-charts-pro';
16
16
  /**
17
17
  * Orchestrates the data providers for the chart components and hooks.
@@ -7,7 +7,7 @@ import { type SankeyChartPluginSignatures } from "./SankeyChart.plugins.js";
7
7
  import type { SankeySeriesType } from "./sankey.types.js";
8
8
  import type { SankeyChartSlotExtension } from "./sankeySlots.types.js";
9
9
  export type SankeySeries = MakeOptional<SankeySeriesType, 'type'>;
10
- export interface SankeyChartProps extends Omit<ChartContainerProProps<'sankey', SankeyChartPluginSignatures>, 'plugins' | 'series' | 'slotProps' | 'slots' | 'dataset' | 'hideLegend' | 'skipAnimation' | 'highlightedItem' | 'onHighlightChange'>, Omit<SankeyPlotProps, 'data'>, Omit<ChartsOverlayProps, 'slots' | 'slotProps'>, SankeyChartSlotExtension {
10
+ export interface SankeyChartProps extends Omit<ChartContainerProProps<'sankey', SankeyChartPluginSignatures>, 'plugins' | 'series' | 'slotProps' | 'slots' | 'dataset' | 'hideLegend' | 'skipAnimation'>, Omit<SankeyPlotProps, 'data'>, Omit<ChartsOverlayProps, 'slots' | 'slotProps'>, SankeyChartSlotExtension {
11
11
  /**
12
12
  * The series to display in the Sankey chart.
13
13
  * A single object is expected.
@@ -94,6 +94,30 @@ process.env.NODE_ENV !== "production" ? SankeyChart.propTypes = {
94
94
  * The height of the chart in px. If not defined, it takes the height of the parent element.
95
95
  */
96
96
  height: PropTypes.number,
97
+ /**
98
+ * The highlighted item.
99
+ * Used when the highlight is controlled.
100
+ */
101
+ highlightedItem: PropTypes.oneOfType([PropTypes.shape({
102
+ nodeId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
103
+ seriesId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
104
+ subType: PropTypes.oneOf([
105
+ /**
106
+ * Subtype to differentiate between node and link
107
+ */
108
+ 'node']).isRequired,
109
+ type: PropTypes.oneOf(['sankey']).isRequired
110
+ }), PropTypes.shape({
111
+ seriesId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
112
+ sourceId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
113
+ subType: PropTypes.oneOf([
114
+ /**
115
+ * Subtype to differentiate between node and link
116
+ */
117
+ 'link']).isRequired,
118
+ targetId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
119
+ type: PropTypes.oneOf(['sankey']).isRequired
120
+ })]),
97
121
  /**
98
122
  * This prop is used to help implement the accessibility logic.
99
123
  * If you don't provide this prop. It falls back to a randomly generated id.
@@ -120,6 +144,12 @@ process.env.NODE_ENV !== "production" ? SankeyChart.propTypes = {
120
144
  right: PropTypes.number,
121
145
  top: PropTypes.number
122
146
  })]),
147
+ /**
148
+ * The callback fired when the highlighted item changes.
149
+ *
150
+ * @param {SankeyHighlightItemData | null} highlightedItem The newly highlighted item.
151
+ */
152
+ onHighlightChange: PropTypes.func,
123
153
  /**
124
154
  * Callback fired when a sankey item is clicked.
125
155
  * @param {React.MouseEvent<SVGElement, MouseEvent>} event The event source of the callback.
@@ -1,4 +1,5 @@
1
- import { ConvertSignaturesIntoPlugins, UseChartHighlightSignature, UseChartInteractionSignature } from '@mui/x-charts/internals';
1
+ import { ConvertSignaturesIntoPlugins, UseChartInteractionSignature } from '@mui/x-charts/internals';
2
2
  import { UseChartProExportSignature } from "../internals/plugins/useChartProExport/index.js";
3
- export type SankeyChartPluginSignatures = [UseChartInteractionSignature, UseChartHighlightSignature, UseChartProExportSignature];
3
+ import { type UseSankeyHighlightSignature } from "./plugins/index.js";
4
+ export type SankeyChartPluginSignatures = [UseChartInteractionSignature, UseSankeyHighlightSignature, UseChartProExportSignature];
4
5
  export declare const SANKEY_CHART_PLUGINS: ConvertSignaturesIntoPlugins<SankeyChartPluginSignatures>;
@@ -1,5 +1,4 @@
1
- import { useChartHighlight
2
- // useChartHighlight,
3
- , useChartInteraction } from '@mui/x-charts/internals';
1
+ import { useChartInteraction } from '@mui/x-charts/internals';
4
2
  import { useChartProExport } from "../internals/plugins/useChartProExport/index.js";
5
- export const SANKEY_CHART_PLUGINS = [useChartInteraction, useChartHighlight, useChartProExport];
3
+ import { useSankeyHighlight } from "./plugins/index.js";
4
+ export const SANKEY_CHART_PLUGINS = [useChartInteraction, useSankeyHighlight, useChartProExport];
@@ -1,6 +1,6 @@
1
1
  import * as React from 'react';
2
2
  import type { SeriesId } from '@mui/x-charts/internals';
3
- import { SankeyLayoutLink, type SankeyLinkIdentifierWithData } from "./sankey.types.js";
3
+ import type { SankeyLayoutLink, SankeyLinkIdentifierWithData } from "./sankey.types.js";
4
4
  export interface SankeyLinkElementProps {
5
5
  /**
6
6
  * The series ID to which the link belongs
@@ -3,7 +3,9 @@
3
3
  import _extends from "@babel/runtime/helpers/esm/extends";
4
4
  import * as React from 'react';
5
5
  import useEventCallback from '@mui/utils/useEventCallback';
6
- import { useInteractionItemProps } from '@mui/x-charts/internals';
6
+ import { useInteractionItemProps, useStore, useSelector } from '@mui/x-charts/internals';
7
+ import { selectorIsLinkHighlighted } from "./plugins/index.js";
8
+ import { selectorIsSankeyItemFaded } from "./plugins/useSankeyHighlight.selectors.js";
7
9
  import { jsx as _jsx } from "react/jsx-runtime";
8
10
  /**
9
11
  * @ignore - internal component.
@@ -15,6 +17,7 @@ export const SankeyLinkElement = /*#__PURE__*/React.forwardRef(function SankeyLi
15
17
  onClick,
16
18
  seriesId
17
19
  } = props;
20
+ const store = useStore();
18
21
  const identifier = {
19
22
  type: 'sankey',
20
23
  seriesId,
@@ -23,6 +26,8 @@ export const SankeyLinkElement = /*#__PURE__*/React.forwardRef(function SankeyLi
23
26
  sourceId: link.source.id,
24
27
  link
25
28
  };
29
+ const isHighlighted = useSelector(store, selectorIsLinkHighlighted, [link]);
30
+ const isFaded = useSelector(store, selectorIsSankeyItemFaded, [isHighlighted]);
26
31
 
27
32
  // Add interaction props for tooltips
28
33
  const interactionProps = useInteractionItemProps(identifier);
@@ -30,15 +35,23 @@ export const SankeyLinkElement = /*#__PURE__*/React.forwardRef(function SankeyLi
30
35
  onClick?.(event, identifier);
31
36
  });
32
37
  if (!link.path) {
33
- return null; // No path defined, nothing to render
38
+ return null;
39
+ }
40
+ let finalOpacity = opacity;
41
+ if (isFaded) {
42
+ finalOpacity = opacity * 0.3;
43
+ } else if (isHighlighted) {
44
+ finalOpacity = Math.min(opacity * 1.2, 1);
34
45
  }
35
46
  return /*#__PURE__*/_jsx("path", _extends({
36
47
  ref: ref,
37
48
  d: link.path,
38
49
  fill: link.color,
39
- opacity: opacity,
50
+ opacity: finalOpacity,
40
51
  "data-link-source": link.source.id,
41
52
  "data-link-target": link.target.id,
53
+ "data-highlighted": isHighlighted || undefined,
54
+ "data-faded": isFaded || undefined,
42
55
  onClick: onClick ? handleClick : undefined,
43
56
  cursor: onClick ? 'pointer' : 'default'
44
57
  }, interactionProps));
@@ -1,6 +1,6 @@
1
1
  import * as React from 'react';
2
2
  import type { SeriesId } from '@mui/x-charts/internals';
3
- import { SankeyLayoutNode, type SankeyNodeIdentifierWithData } from "./sankey.types.js";
3
+ import type { SankeyLayoutNode, SankeyNodeIdentifierWithData } from "./sankey.types.js";
4
4
  export interface SankeyNodeElementProps {
5
5
  /**
6
6
  * The series ID to which the node belongs
@@ -3,8 +3,10 @@
3
3
  import _extends from "@babel/runtime/helpers/esm/extends";
4
4
  import * as React from 'react';
5
5
  import useEventCallback from '@mui/utils/useEventCallback';
6
- import { useInteractionItemProps } from '@mui/x-charts/internals';
6
+ import { useInteractionItemProps, useStore, useSelector } from '@mui/x-charts/internals';
7
7
  import { useTheme } from '@mui/material/styles';
8
+ import { selectorIsNodeHighlighted } from "./plugins/index.js";
9
+ import { selectorIsSankeyItemFaded } from "./plugins/useSankeyHighlight.selectors.js";
8
10
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
9
11
  /**
10
12
  * @ignore - internal component.
@@ -17,6 +19,7 @@ export const SankeyNodeElement = /*#__PURE__*/React.forwardRef(function SankeyNo
17
19
  seriesId
18
20
  } = props;
19
21
  const theme = useTheme();
22
+ const store = useStore();
20
23
  const x0 = node.x0 ?? 0;
21
24
  const y0 = node.y0 ?? 0;
22
25
  const x1 = node.x1 ?? 0;
@@ -36,12 +39,20 @@ export const SankeyNodeElement = /*#__PURE__*/React.forwardRef(function SankeyNo
36
39
  nodeId: node.id,
37
40
  node
38
41
  };
42
+ const isHighlighted = useSelector(store, selectorIsNodeHighlighted, [node]);
43
+ const isFaded = useSelector(store, selectorIsSankeyItemFaded, [isHighlighted]);
39
44
 
40
45
  // Add interaction props for tooltips
41
46
  const interactionProps = useInteractionItemProps(identifier);
42
47
  const handleClick = useEventCallback(event => {
43
48
  onClick?.(event, identifier);
44
49
  });
50
+ let opacity = 1;
51
+ if (isFaded) {
52
+ opacity = 0.3;
53
+ } else if (isHighlighted) {
54
+ opacity = 1;
55
+ }
45
56
  return /*#__PURE__*/_jsxs("g", {
46
57
  ref: ref,
47
58
  "data-node": node.id,
@@ -51,9 +62,12 @@ export const SankeyNodeElement = /*#__PURE__*/React.forwardRef(function SankeyNo
51
62
  width: nodeWidth,
52
63
  height: nodeHeight,
53
64
  fill: node.color,
65
+ opacity: opacity,
54
66
  onClick: onClick ? handleClick : undefined,
55
67
  cursor: onClick ? 'pointer' : 'default',
56
- stroke: "none"
68
+ stroke: "none",
69
+ "data-highlighted": isHighlighted || undefined,
70
+ "data-faded": isFaded || undefined
57
71
  }, interactionProps)), showLabel && node.label && /*#__PURE__*/_jsx("text", {
58
72
  x: labelX,
59
73
  y: (y0 + y1) / 2,
@@ -62,6 +76,7 @@ export const SankeyNodeElement = /*#__PURE__*/React.forwardRef(function SankeyNo
62
76
  fontSize: theme.typography.caption.fontSize,
63
77
  fontFamily: theme.typography.fontFamily,
64
78
  pointerEvents: "none",
79
+ opacity: opacity,
65
80
  children: node.label
66
81
  })]
67
82
  });
@@ -2,15 +2,27 @@
2
2
 
3
3
  import * as React from 'react';
4
4
  import PropTypes from 'prop-types';
5
- import { useTheme } from '@mui/material/styles';
5
+ import { styled, useTheme } from '@mui/material/styles';
6
6
  import { useDrawingArea } from '@mui/x-charts/hooks';
7
7
  import { calculateSankeyLayout } from "./calculateSankeyLayout.js";
8
8
  import { SankeyNodeElement } from "./SankeyNodeElement.js";
9
9
  import { SankeyLinkElement } from "./SankeyLinkElement.js";
10
10
  import { SankeyLinkLabel } from "./SankeyLinkLabel.js";
11
11
  import { useSankeySeriesContext } from "../hooks/useSankeySeries.js";
12
- import { useUtilityClasses } from "./sankeyClasses.js";
12
+ import { sankeyPlotClasses, useUtilityClasses } from "./sankeyClasses.js";
13
13
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
14
+ const SankeyPlotRoot = styled('g')({
15
+ [`.${sankeyPlotClasses.links} path, .${sankeyPlotClasses.nodes} rect`]: {
16
+ transition: 'opacity 0.1s ease-out, filter 0.1s ease-out'
17
+ },
18
+ '& [data-faded=true]': {
19
+ filter: 'saturate(80%)'
20
+ },
21
+ '& [data-highlighted=true]': {
22
+ filter: 'saturate(120%)'
23
+ }
24
+ });
25
+
14
26
  /**
15
27
  * Renders a Sankey diagram plot.
16
28
  */
@@ -43,7 +55,7 @@ function SankeyPlot(props) {
43
55
  if (!data || !data.links) {
44
56
  return null;
45
57
  }
46
- return /*#__PURE__*/_jsxs("g", {
58
+ return /*#__PURE__*/_jsxs(SankeyPlotRoot, {
47
59
  className: classes.root,
48
60
  children: [/*#__PURE__*/_jsx("g", {
49
61
  className: classes.links,
@@ -0,0 +1,3 @@
1
+ export { useSankeyHighlight } from "./useSankeyHighlight.js";
2
+ export * from "./useSankeyHighlight.types.js";
3
+ export { selectorIsSankeyItemFaded as selectorIsFaded, selectorIsLinkHighlighted, selectorIsNodeHighlighted } from "./useSankeyHighlight.selectors.js";
@@ -0,0 +1,3 @@
1
+ export { useSankeyHighlight } from "./useSankeyHighlight.js";
2
+ export * from "./useSankeyHighlight.types.js";
3
+ export { selectorIsSankeyItemFaded as selectorIsFaded, selectorIsLinkHighlighted, selectorIsNodeHighlighted } from "./useSankeyHighlight.selectors.js";
@@ -0,0 +1,7 @@
1
+ import { ChartPlugin } from '@mui/x-charts/internals';
2
+ import type { UseSankeyHighlightSignature } from "./useSankeyHighlight.types.js";
3
+ /**
4
+ * Custom highlight plugin for Sankey charts that uses SankeyItemIdentifier
5
+ * instead of the standard HighlightItemData.
6
+ */
7
+ export declare const useSankeyHighlight: ChartPlugin<UseSankeyHighlightSignature>;
@@ -0,0 +1,68 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import { useAssertModelConsistency } from '@mui/x-internals/useAssertModelConsistency';
3
+ import useEventCallback from '@mui/utils/useEventCallback';
4
+ import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
5
+ import { fastObjectShallowCompare } from '@mui/x-internals/fastObjectShallowCompare';
6
+ /**
7
+ * Custom highlight plugin for Sankey charts that uses SankeyItemIdentifier
8
+ * instead of the standard HighlightItemData.
9
+ */
10
+ export const useSankeyHighlight = ({
11
+ store,
12
+ params
13
+ }) => {
14
+ useAssertModelConsistency({
15
+ warningPrefix: 'MUI X Charts',
16
+ componentName: 'SankeyChart',
17
+ propName: 'highlightedItem',
18
+ controlled: params.highlightedItem,
19
+ defaultValue: null
20
+ });
21
+ useEnhancedEffect(() => {
22
+ store.update(prevState => prevState.highlight.item === params.highlightedItem ? prevState : _extends({}, prevState, {
23
+ highlight: _extends({}, prevState.highlight, {
24
+ item: params.highlightedItem
25
+ })
26
+ }));
27
+ }, [store, params.highlightedItem]);
28
+ const clearHighlight = useEventCallback(() => {
29
+ params.onHighlightChange?.(null);
30
+ store.update(prev => _extends({}, prev, {
31
+ highlight: {
32
+ item: null
33
+ }
34
+ }));
35
+ });
36
+ const setHighlight = useEventCallback(newItem => {
37
+ const prevItem = store.getSnapshot().highlight.item;
38
+ if (fastObjectShallowCompare(prevItem, newItem)) {
39
+ return;
40
+ }
41
+ params.onHighlightChange?.(newItem);
42
+ store.update(prev => _extends({}, prev, {
43
+ highlight: {
44
+ item: newItem
45
+ }
46
+ }));
47
+ });
48
+ return {
49
+ instance: {
50
+ clearHighlight,
51
+ setHighlight
52
+ }
53
+ };
54
+ };
55
+ useSankeyHighlight.getDefaultizedParams = ({
56
+ params
57
+ }) => _extends({}, params, {
58
+ highlightedItem: params.highlightedItem ?? null
59
+ });
60
+ useSankeyHighlight.getInitialState = params => ({
61
+ highlight: {
62
+ item: params.highlightedItem
63
+ }
64
+ });
65
+ useSankeyHighlight.params = {
66
+ highlightedItem: true,
67
+ onHighlightChange: true
68
+ };