@mui/x-charts-pro 8.13.1 → 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 (70) hide show
  1. package/BarChartPro/BarChartPro.js +49 -37
  2. package/CHANGELOG.md +204 -1
  3. package/ChartDataProviderPro/ChartDataProviderPro.js +1 -1
  4. package/FunnelChart/funnelAxisPlugin/computeAxisValue.js +38 -36
  5. package/Heatmap/Heatmap.js +0 -4
  6. package/LineChartPro/LineChartPro.js +49 -37
  7. package/SankeyChart/SankeyChart.d.ts +1 -1
  8. package/SankeyChart/SankeyChart.js +30 -0
  9. package/SankeyChart/SankeyChart.plugins.d.ts +3 -2
  10. package/SankeyChart/SankeyChart.plugins.js +2 -1
  11. package/SankeyChart/SankeyLinkElement.d.ts +1 -1
  12. package/SankeyChart/SankeyLinkElement.js +15 -2
  13. package/SankeyChart/SankeyNodeElement.d.ts +1 -1
  14. package/SankeyChart/SankeyNodeElement.js +16 -1
  15. package/SankeyChart/SankeyPlot.js +13 -1
  16. package/SankeyChart/plugins/index.d.ts +3 -0
  17. package/SankeyChart/plugins/index.js +49 -0
  18. package/SankeyChart/plugins/useSankeyHighlight.d.ts +7 -0
  19. package/SankeyChart/plugins/useSankeyHighlight.js +76 -0
  20. package/SankeyChart/plugins/useSankeyHighlight.selectors.d.ts +68 -0
  21. package/SankeyChart/plugins/useSankeyHighlight.selectors.js +126 -0
  22. package/SankeyChart/plugins/useSankeyHighlight.types.d.ts +55 -0
  23. package/SankeyChart/plugins/useSankeyHighlight.types.js +5 -0
  24. package/SankeyChart/sankey.highlight.types.d.ts +42 -0
  25. package/SankeyChart/sankey.highlight.types.js +6 -0
  26. package/SankeyChart/sankey.types.d.ts +3 -2
  27. package/SankeyChart/sankeyClasses.d.ts +1 -1
  28. package/SankeyChart/useSankeyChartProps.js +5 -5
  29. package/ScatterChartPro/ScatterChartPro.js +49 -37
  30. package/esm/BarChartPro/BarChartPro.js +49 -37
  31. package/esm/ChartDataProviderPro/ChartDataProviderPro.js +1 -1
  32. package/esm/FunnelChart/funnelAxisPlugin/computeAxisValue.js +39 -37
  33. package/esm/Heatmap/Heatmap.js +0 -4
  34. package/esm/LineChartPro/LineChartPro.js +49 -37
  35. package/esm/SankeyChart/SankeyChart.d.ts +1 -1
  36. package/esm/SankeyChart/SankeyChart.js +30 -0
  37. package/esm/SankeyChart/SankeyChart.plugins.d.ts +3 -2
  38. package/esm/SankeyChart/SankeyChart.plugins.js +3 -4
  39. package/esm/SankeyChart/SankeyLinkElement.d.ts +1 -1
  40. package/esm/SankeyChart/SankeyLinkElement.js +16 -3
  41. package/esm/SankeyChart/SankeyNodeElement.d.ts +1 -1
  42. package/esm/SankeyChart/SankeyNodeElement.js +17 -2
  43. package/esm/SankeyChart/SankeyPlot.js +15 -3
  44. package/esm/SankeyChart/plugins/index.d.ts +3 -0
  45. package/esm/SankeyChart/plugins/index.js +3 -0
  46. package/esm/SankeyChart/plugins/useSankeyHighlight.d.ts +7 -0
  47. package/esm/SankeyChart/plugins/useSankeyHighlight.js +68 -0
  48. package/esm/SankeyChart/plugins/useSankeyHighlight.selectors.d.ts +68 -0
  49. package/esm/SankeyChart/plugins/useSankeyHighlight.selectors.js +120 -0
  50. package/esm/SankeyChart/plugins/useSankeyHighlight.types.d.ts +55 -0
  51. package/esm/SankeyChart/plugins/useSankeyHighlight.types.js +1 -0
  52. package/esm/SankeyChart/sankey.highlight.types.d.ts +42 -0
  53. package/esm/SankeyChart/sankey.highlight.types.js +3 -0
  54. package/esm/SankeyChart/sankey.types.d.ts +3 -2
  55. package/esm/SankeyChart/sankeyClasses.d.ts +1 -1
  56. package/esm/SankeyChart/useSankeyChartProps.js +5 -5
  57. package/esm/ScatterChartPro/ScatterChartPro.js +49 -37
  58. package/esm/index.js +1 -1
  59. package/esm/internals/plugins/useChartProZoom/ZoomInteractionConfig.selectors.d.ts +2 -6
  60. package/esm/internals/plugins/useChartProZoom/ZoomInteractionConfig.types.d.ts +5 -1
  61. package/esm/internals/plugins/useChartProZoom/gestureHooks/usePanOnPressAndDrag.d.ts +8 -0
  62. package/esm/internals/plugins/useChartProZoom/gestureHooks/usePanOnPressAndDrag.js +73 -0
  63. package/esm/internals/plugins/useChartProZoom/useChartProZoom.js +2 -0
  64. package/index.js +1 -1
  65. package/internals/plugins/useChartProZoom/ZoomInteractionConfig.selectors.d.ts +2 -6
  66. package/internals/plugins/useChartProZoom/ZoomInteractionConfig.types.d.ts +5 -1
  67. package/internals/plugins/useChartProZoom/gestureHooks/usePanOnPressAndDrag.d.ts +8 -0
  68. package/internals/plugins/useChartProZoom/gestureHooks/usePanOnPressAndDrag.js +80 -0
  69. package/internals/plugins/useChartProZoom/useChartProZoom.js +2 -0
  70. package/package.json +7 -7
@@ -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
+ };
@@ -0,0 +1,68 @@
1
+ import type { SankeyLayoutLink, SankeyLayoutNode } from "../sankey.types.js";
2
+ import type { SankeyLinkFade, SankeyLinkHighlight, SankeyNodeFade, SankeyNodeHighlight } from "../sankey.highlight.types.js";
3
+ /**
4
+ * Get the node highlight configuration from the Sankey series.
5
+ * Defaults to 'nodes' if not specified.
6
+ */
7
+ export declare const selectorNodeHighlightConfig: import("reselect").Selector<import("@mui/x-charts/internals/plugins/corePlugins/useChartId/useChartId.types").UseChartIdState & import("@mui/x-charts/internals/plugins/corePlugins/useChartExperimentalFeature/useChartExperimentalFeature.types").UseChartExperimentalFeaturesState & import("@mui/x-charts/internals/plugins/corePlugins/useChartDimensions/useChartDimensions.types").UseChartDimensionsState & import("@mui/x-charts/internals/plugins/corePlugins/useChartSeries/useChartSeries.types").UseChartSeriesState<keyof import("@mui/x-charts/internals").ChartsSeriesConfig> & import("@mui/x-charts/internals/plugins/corePlugins/useChartAnimation/useChartAnimation.types").UseChartAnimationState & import("@mui/x-charts/internals").UseChartInteractionListenerState & Partial<{}> & {
8
+ cacheKey: import("@mui/x-charts/internals").ChartStateCacheKey;
9
+ } & {
10
+ cacheKey: import("@mui/x-charts/internals").ChartStateCacheKey;
11
+ }, SankeyNodeHighlight, any[]>;
12
+ /**
13
+ * Get the node fade configuration from the Sankey series.
14
+ * Defaults to 'none' if not specified.
15
+ */
16
+ export declare const selectorNodeFadeConfig: import("reselect").Selector<import("@mui/x-charts/internals/plugins/corePlugins/useChartId/useChartId.types").UseChartIdState & import("@mui/x-charts/internals/plugins/corePlugins/useChartExperimentalFeature/useChartExperimentalFeature.types").UseChartExperimentalFeaturesState & import("@mui/x-charts/internals/plugins/corePlugins/useChartDimensions/useChartDimensions.types").UseChartDimensionsState & import("@mui/x-charts/internals/plugins/corePlugins/useChartSeries/useChartSeries.types").UseChartSeriesState<keyof import("@mui/x-charts/internals").ChartsSeriesConfig> & import("@mui/x-charts/internals/plugins/corePlugins/useChartAnimation/useChartAnimation.types").UseChartAnimationState & import("@mui/x-charts/internals").UseChartInteractionListenerState & Partial<{}> & {
17
+ cacheKey: import("@mui/x-charts/internals").ChartStateCacheKey;
18
+ } & {
19
+ cacheKey: import("@mui/x-charts/internals").ChartStateCacheKey;
20
+ }, SankeyNodeFade, any[]>;
21
+ /**
22
+ * Get the link highlight configuration from the Sankey series.
23
+ * Defaults to 'links' if not specified.
24
+ */
25
+ export declare const selectorLinkHighlightConfig: import("reselect").Selector<import("@mui/x-charts/internals/plugins/corePlugins/useChartId/useChartId.types").UseChartIdState & import("@mui/x-charts/internals/plugins/corePlugins/useChartExperimentalFeature/useChartExperimentalFeature.types").UseChartExperimentalFeaturesState & import("@mui/x-charts/internals/plugins/corePlugins/useChartDimensions/useChartDimensions.types").UseChartDimensionsState & import("@mui/x-charts/internals/plugins/corePlugins/useChartSeries/useChartSeries.types").UseChartSeriesState<keyof import("@mui/x-charts/internals").ChartsSeriesConfig> & import("@mui/x-charts/internals/plugins/corePlugins/useChartAnimation/useChartAnimation.types").UseChartAnimationState & import("@mui/x-charts/internals").UseChartInteractionListenerState & Partial<{}> & {
26
+ cacheKey: import("@mui/x-charts/internals").ChartStateCacheKey;
27
+ } & {
28
+ cacheKey: import("@mui/x-charts/internals").ChartStateCacheKey;
29
+ }, SankeyLinkHighlight, any[]>;
30
+ /**
31
+ * Get the link fade configuration from the Sankey series.
32
+ * Defaults to 'none' if not specified.
33
+ */
34
+ export declare const selectorLinkFadeConfig: import("reselect").Selector<import("@mui/x-charts/internals/plugins/corePlugins/useChartId/useChartId.types").UseChartIdState & import("@mui/x-charts/internals/plugins/corePlugins/useChartExperimentalFeature/useChartExperimentalFeature.types").UseChartExperimentalFeaturesState & import("@mui/x-charts/internals/plugins/corePlugins/useChartDimensions/useChartDimensions.types").UseChartDimensionsState & import("@mui/x-charts/internals/plugins/corePlugins/useChartSeries/useChartSeries.types").UseChartSeriesState<keyof import("@mui/x-charts/internals").ChartsSeriesConfig> & import("@mui/x-charts/internals/plugins/corePlugins/useChartAnimation/useChartAnimation.types").UseChartAnimationState & import("@mui/x-charts/internals").UseChartInteractionListenerState & Partial<{}> & {
35
+ cacheKey: import("@mui/x-charts/internals").ChartStateCacheKey;
36
+ } & {
37
+ cacheKey: import("@mui/x-charts/internals").ChartStateCacheKey;
38
+ }, SankeyLinkFade, any[]>;
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
+ export declare const selectorSankeyHighlightedItem: import("reselect").Selector<import("./useSankeyHighlight.types.js").UseSankeyHighlightState & {
45
+ cacheKey: import("@mui/x-charts/internals").ChartStateCacheKey;
46
+ }, import("../index.js").SankeyItemIdentifier | null, []>;
47
+ /**
48
+ * Determines if a specific node should be highlighted.
49
+ * A node is highlighted if:
50
+ * - It's the highlighted node (unless highlight mode is 'none')
51
+ * - It's connected to a highlighted link (based on linkOptions.highlight)
52
+ */
53
+ export declare const selectorIsNodeHighlighted: import("reselect").Selector<any, boolean, [node: SankeyLayoutNode]>;
54
+ /**
55
+ * Selector that determines if a specific link should be highlighted.
56
+ * A link is highlighted if:
57
+ * - It's the highlighted link (unless highlight mode is 'none')
58
+ * - It's connected to a highlighted node (based on nodeOptions.highlight)
59
+ */
60
+ export declare const selectorIsLinkHighlighted: import("reselect").Selector<any, boolean, [link: SankeyLayoutLink]>;
61
+ /**
62
+ * Selector that determines if an item should be faded.
63
+ * An item is faded if:
64
+ * - There's a highlighted item
65
+ * - This item is not highlighted
66
+ * - The fade mode is 'global' for the highlighted element type
67
+ */
68
+ export declare const selectorIsSankeyItemFaded: import("reselect").Selector<any, boolean, [isHighlighted: any]>;
@@ -0,0 +1,120 @@
1
+ import { createSelector } from '@mui/x-charts/internals';
2
+ const selectorSankeyHighlight = state => state.highlight;
3
+ const selectSeries = state => state.series;
4
+ const selectorSankeySeries = createSelector([selectSeries], series => series.processedSeries.sankey?.series[series.processedSeries.sankey?.seriesOrder[0]] || null);
5
+ const DEFAULT_NODE_HIGHLIGHT = 'links';
6
+ const DEFAULT_LINK_HIGHLIGHT = 'links';
7
+ const DEFAULT_FADE = 'none';
8
+
9
+ /**
10
+ * Get the node highlight configuration from the Sankey series.
11
+ * Defaults to 'nodes' if not specified.
12
+ */
13
+ export const selectorNodeHighlightConfig = createSelector([selectorSankeySeries], series => series?.nodeOptions?.highlight ?? DEFAULT_NODE_HIGHLIGHT);
14
+
15
+ /**
16
+ * Get the node fade configuration from the Sankey series.
17
+ * Defaults to 'none' if not specified.
18
+ */
19
+ export const selectorNodeFadeConfig = createSelector([selectorSankeySeries], series => series?.nodeOptions?.fade ?? DEFAULT_FADE);
20
+
21
+ /**
22
+ * Get the link highlight configuration from the Sankey series.
23
+ * Defaults to 'links' if not specified.
24
+ */
25
+ export const selectorLinkHighlightConfig = createSelector([selectorSankeySeries], series => series?.linkOptions?.highlight ?? DEFAULT_LINK_HIGHLIGHT);
26
+
27
+ /**
28
+ * Get the link fade configuration from the Sankey series.
29
+ * Defaults to 'none' if not specified.
30
+ */
31
+ export const selectorLinkFadeConfig = createSelector([selectorSankeySeries], series => series?.linkOptions?.fade ?? DEFAULT_FADE);
32
+
33
+ /**
34
+ * Get the currently highlighted item in the Sankey chart.
35
+ * @param {UseSankeyHighlightSignature['state']} state The state of the chart.
36
+ * @returns {SankeyItemIdentifier | null} The highlighted item identifier or null.
37
+ */
38
+ export const selectorSankeyHighlightedItem = createSelector([selectorSankeyHighlight], highlight => highlight.item);
39
+
40
+ /**
41
+ * Determines if a specific node should be highlighted.
42
+ * A node is highlighted if:
43
+ * - It's the highlighted node (unless highlight mode is 'none')
44
+ * - It's connected to a highlighted link (based on linkOptions.highlight)
45
+ */
46
+ export const selectorIsNodeHighlighted = createSelector([selectorSankeyHighlightedItem, selectorNodeHighlightConfig, selectorLinkHighlightConfig, (_, node) => node.id], (highlightedItem, nodeHighlight, linkHighlight, nodeId) => {
47
+ if (!highlightedItem) {
48
+ return false;
49
+ }
50
+ if (highlightedItem.subType === 'node' && highlightedItem.nodeId === nodeId) {
51
+ return nodeHighlight !== 'none';
52
+ }
53
+ if (highlightedItem.subType === 'link') {
54
+ if (!linkHighlight || linkHighlight === 'none' || linkHighlight === 'links') {
55
+ return false;
56
+ }
57
+ const {
58
+ sourceId,
59
+ targetId
60
+ } = highlightedItem;
61
+ switch (linkHighlight) {
62
+ case 'nodes':
63
+ return nodeId === sourceId || nodeId === targetId;
64
+ case 'source':
65
+ return nodeId === sourceId;
66
+ case 'target':
67
+ return nodeId === targetId;
68
+ default:
69
+ return false;
70
+ }
71
+ }
72
+ return false;
73
+ });
74
+
75
+ /**
76
+ * Selector that determines if a specific link should be highlighted.
77
+ * A link is highlighted if:
78
+ * - It's the highlighted link (unless highlight mode is 'none')
79
+ * - It's connected to a highlighted node (based on nodeOptions.highlight)
80
+ */
81
+ export const selectorIsLinkHighlighted = createSelector([selectorSankeyHighlightedItem, selectorNodeHighlightConfig, selectorLinkHighlightConfig, (_, link) => link], (highlightedItem, nodeHighlight, linkHighlight, link) => {
82
+ if (!highlightedItem) {
83
+ return false;
84
+ }
85
+ if (highlightedItem.subType === 'link' && highlightedItem.sourceId === link.source.id && highlightedItem.targetId === link.target.id) {
86
+ return linkHighlight !== 'none';
87
+ }
88
+ if (highlightedItem.subType === 'node') {
89
+ if (!nodeHighlight || nodeHighlight === 'none' || nodeHighlight === 'nodes') {
90
+ return false;
91
+ }
92
+ const highlightedNodeId = highlightedItem.nodeId;
93
+ switch (nodeHighlight) {
94
+ case 'links':
95
+ return link.source.id === highlightedNodeId || link.target.id === highlightedNodeId;
96
+ case 'incoming':
97
+ return link.target.id === highlightedNodeId;
98
+ case 'outgoing':
99
+ return link.source.id === highlightedNodeId;
100
+ default:
101
+ return false;
102
+ }
103
+ }
104
+ return false;
105
+ });
106
+
107
+ /**
108
+ * Selector that determines if an item should be faded.
109
+ * An item is faded if:
110
+ * - There's a highlighted item
111
+ * - This item is not highlighted
112
+ * - The fade mode is 'global' for the highlighted element type
113
+ */
114
+ export const selectorIsSankeyItemFaded = createSelector([selectorSankeyHighlightedItem, selectorNodeFadeConfig, selectorLinkFadeConfig, (_, isHighlighted) => isHighlighted], (highlightedItem, nodeFade, linkFade, isHighlighted) => {
115
+ if (!highlightedItem || isHighlighted) {
116
+ return false;
117
+ }
118
+ const fadeMode = highlightedItem.subType === 'node' ? nodeFade : linkFade;
119
+ return fadeMode === 'global';
120
+ });
@@ -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,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,3 @@
1
+ 'use client';
2
+
3
+ export {};
@@ -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>;
@@ -1,6 +1,6 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
- const _excluded = ["series", "width", "height", "margin", "colors", "sx", "children", "slots", "slotProps", "loading", "className", "apiRef", "onNodeClick", "onLinkClick"];
3
+ const _excluded = ["series", "width", "height", "margin", "colors", "sx", "children", "slots", "slotProps", "loading", "highlightedItem", "onHighlightChange", "className", "apiRef", "onNodeClick", "onLinkClick"];
4
4
  import { DEFAULT_MARGINS } from '@mui/x-charts/constants';
5
5
  import { defaultizeMargin } from '@mui/x-charts/internals';
6
6
  import { SANKEY_CHART_PLUGINS } from "./SankeyChart.plugins.js";
@@ -24,8 +24,8 @@ export const useSankeyChartProps = props => {
24
24
  slots,
25
25
  slotProps,
26
26
  loading,
27
- // highlightedItem,
28
- // onHighlightChange,
27
+ highlightedItem,
28
+ onHighlightChange,
29
29
  className,
30
30
  apiRef,
31
31
  onNodeClick,
@@ -42,8 +42,8 @@ export const useSankeyChartProps = props => {
42
42
  margin,
43
43
  colors,
44
44
  sx,
45
- // highlightedItem,
46
- // onHighlightChange,
45
+ highlightedItem,
46
+ onHighlightChange,
47
47
  className,
48
48
  apiRef,
49
49
  plugins: SANKEY_CHART_PLUGINS