@mui/x-charts 7.5.1 → 7.6.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 (133) hide show
  1. package/BarChart/BarChart.js +18 -1
  2. package/BarChart/BarElement.d.ts +0 -3
  3. package/BarChart/BarElement.js +7 -18
  4. package/BarChart/BarLabel/BarLabelItem.js +5 -16
  5. package/BarChart/BarLabel/BarLabelPlot.js +0 -4
  6. package/BarChart/BarPlot.js +4 -30
  7. package/BarChart/checkScaleErrors.d.ts +11 -0
  8. package/BarChart/checkScaleErrors.js +33 -0
  9. package/BarChart/types.d.ts +0 -2
  10. package/CHANGELOG.md +112 -1
  11. package/ChartContainer/ChartContainer.d.ts +3 -2
  12. package/ChartContainer/ChartContainer.js +19 -2
  13. package/ChartsVoronoiHandler/ChartsVoronoiHandler.js +13 -1
  14. package/LineChart/AreaElement.d.ts +0 -2
  15. package/LineChart/AreaElement.js +7 -17
  16. package/LineChart/AreaPlot.js +0 -2
  17. package/LineChart/LineChart.js +18 -1
  18. package/LineChart/LineElement.d.ts +0 -2
  19. package/LineChart/LineElement.js +7 -17
  20. package/LineChart/LinePlot.js +0 -2
  21. package/LineChart/MarkElement.d.ts +0 -2
  22. package/LineChart/MarkElement.js +10 -17
  23. package/LineChart/MarkPlot.js +0 -1
  24. package/PieChart/PieArc.d.ts +4 -1
  25. package/PieChart/PieArc.js +7 -3
  26. package/PieChart/PieArcLabelPlot.d.ts +1 -1
  27. package/PieChart/PieArcLabelPlot.js +1 -7
  28. package/PieChart/PieArcPlot.d.ts +1 -1
  29. package/PieChart/PieArcPlot.js +5 -7
  30. package/PieChart/PieChart.js +18 -1
  31. package/PieChart/PiePlot.js +2 -6
  32. package/PieChart/dataTransform/useTransformData.d.ts +1 -1
  33. package/PieChart/dataTransform/useTransformData.js +10 -25
  34. package/ResponsiveChartContainer/ResponsiveChartContainer.js +13 -0
  35. package/ScatterChart/Scatter.js +14 -10
  36. package/ScatterChart/ScatterChart.js +18 -1
  37. package/SparkLineChart/SparkLineChart.js +13 -0
  38. package/context/HighlightedProvider/HighlightedContext.d.ts +65 -0
  39. package/context/HighlightedProvider/HighlightedContext.js +36 -0
  40. package/context/HighlightedProvider/HighlightedProvider.d.ts +20 -0
  41. package/context/HighlightedProvider/HighlightedProvider.js +97 -0
  42. package/context/HighlightedProvider/createIsFaded.d.ts +2 -0
  43. package/context/HighlightedProvider/createIsFaded.js +19 -0
  44. package/context/HighlightedProvider/createIsHighlighted.d.ts +2 -0
  45. package/context/HighlightedProvider/createIsHighlighted.js +19 -0
  46. package/context/HighlightedProvider/index.d.ts +4 -0
  47. package/context/HighlightedProvider/index.js +49 -0
  48. package/context/HighlightedProvider/useHighlighted.d.ts +9 -0
  49. package/context/HighlightedProvider/useHighlighted.js +24 -0
  50. package/context/HighlightedProvider/useItemHighlighted.d.ts +21 -0
  51. package/context/HighlightedProvider/useItemHighlighted.js +37 -0
  52. package/context/index.d.ts +1 -1
  53. package/context/index.js +15 -0
  54. package/esm/BarChart/BarChart.js +18 -1
  55. package/esm/BarChart/BarElement.js +8 -19
  56. package/esm/BarChart/BarLabel/BarLabelItem.js +5 -16
  57. package/esm/BarChart/BarLabel/BarLabelPlot.js +0 -4
  58. package/esm/BarChart/BarPlot.js +4 -30
  59. package/esm/BarChart/checkScaleErrors.js +27 -0
  60. package/esm/ChartContainer/ChartContainer.js +19 -2
  61. package/esm/ChartsVoronoiHandler/ChartsVoronoiHandler.js +13 -1
  62. package/esm/LineChart/AreaElement.js +8 -18
  63. package/esm/LineChart/AreaPlot.js +0 -2
  64. package/esm/LineChart/LineChart.js +18 -1
  65. package/esm/LineChart/LineElement.js +8 -18
  66. package/esm/LineChart/LinePlot.js +0 -2
  67. package/esm/LineChart/MarkElement.js +11 -18
  68. package/esm/LineChart/MarkPlot.js +0 -1
  69. package/esm/PieChart/PieArc.js +7 -3
  70. package/esm/PieChart/PieArcLabelPlot.js +1 -7
  71. package/esm/PieChart/PieArcPlot.js +5 -7
  72. package/esm/PieChart/PieChart.js +18 -1
  73. package/esm/PieChart/PiePlot.js +2 -6
  74. package/esm/PieChart/dataTransform/useTransformData.js +10 -25
  75. package/esm/ResponsiveChartContainer/ResponsiveChartContainer.js +13 -0
  76. package/esm/ScatterChart/Scatter.js +15 -11
  77. package/esm/ScatterChart/ScatterChart.js +18 -1
  78. package/esm/SparkLineChart/SparkLineChart.js +13 -0
  79. package/esm/context/HighlightedProvider/HighlightedContext.js +29 -0
  80. package/esm/context/HighlightedProvider/HighlightedProvider.js +89 -0
  81. package/esm/context/HighlightedProvider/createIsFaded.js +12 -0
  82. package/esm/context/HighlightedProvider/createIsHighlighted.js +12 -0
  83. package/esm/context/HighlightedProvider/index.js +4 -0
  84. package/esm/context/HighlightedProvider/useHighlighted.js +17 -0
  85. package/esm/context/HighlightedProvider/useItemHighlighted.js +29 -0
  86. package/esm/context/index.js +1 -0
  87. package/esm/hooks/useInteractionItemProps.js +9 -41
  88. package/hooks/useInteractionItemProps.d.ts +1 -4
  89. package/hooks/useInteractionItemProps.js +11 -45
  90. package/index.js +1 -1
  91. package/internals/colorScale.d.ts +1 -1
  92. package/internals/defaultizeColor.d.ts +13 -13
  93. package/models/seriesType/common.d.ts +4 -1
  94. package/modern/BarChart/BarChart.js +18 -1
  95. package/modern/BarChart/BarElement.js +8 -19
  96. package/modern/BarChart/BarLabel/BarLabelItem.js +5 -16
  97. package/modern/BarChart/BarLabel/BarLabelPlot.js +0 -4
  98. package/modern/BarChart/BarPlot.js +4 -30
  99. package/modern/BarChart/checkScaleErrors.js +27 -0
  100. package/modern/ChartContainer/ChartContainer.js +19 -2
  101. package/modern/ChartsVoronoiHandler/ChartsVoronoiHandler.js +13 -1
  102. package/modern/LineChart/AreaElement.js +8 -18
  103. package/modern/LineChart/AreaPlot.js +0 -2
  104. package/modern/LineChart/LineChart.js +18 -1
  105. package/modern/LineChart/LineElement.js +8 -18
  106. package/modern/LineChart/LinePlot.js +0 -2
  107. package/modern/LineChart/MarkElement.js +11 -18
  108. package/modern/LineChart/MarkPlot.js +0 -1
  109. package/modern/PieChart/PieArc.js +7 -3
  110. package/modern/PieChart/PieArcLabelPlot.js +1 -7
  111. package/modern/PieChart/PieArcPlot.js +5 -7
  112. package/modern/PieChart/PieChart.js +18 -1
  113. package/modern/PieChart/PiePlot.js +2 -6
  114. package/modern/PieChart/dataTransform/useTransformData.js +10 -25
  115. package/modern/ResponsiveChartContainer/ResponsiveChartContainer.js +13 -0
  116. package/modern/ScatterChart/Scatter.js +15 -11
  117. package/modern/ScatterChart/ScatterChart.js +18 -1
  118. package/modern/SparkLineChart/SparkLineChart.js +13 -0
  119. package/modern/context/HighlightedProvider/HighlightedContext.js +29 -0
  120. package/modern/context/HighlightedProvider/HighlightedProvider.js +89 -0
  121. package/modern/context/HighlightedProvider/createIsFaded.js +12 -0
  122. package/modern/context/HighlightedProvider/createIsHighlighted.js +12 -0
  123. package/modern/context/HighlightedProvider/index.js +4 -0
  124. package/modern/context/HighlightedProvider/useHighlighted.js +17 -0
  125. package/modern/context/HighlightedProvider/useItemHighlighted.js +29 -0
  126. package/modern/context/index.js +1 -0
  127. package/modern/hooks/useInteractionItemProps.js +9 -41
  128. package/modern/index.js +1 -1
  129. package/package.json +3 -3
  130. package/context/HighlightProvider.d.ts +0 -45
  131. package/context/HighlightProvider.js +0 -60
  132. package/esm/context/HighlightProvider.js +0 -51
  133. package/modern/context/HighlightProvider.js +0 -51
@@ -1,15 +1,15 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
- const _excluded = ["id", "classes", "color", "gradientId", "highlightScope", "slots", "slotProps", "onClick"];
3
+ const _excluded = ["id", "classes", "color", "gradientId", "slots", "slotProps", "onClick"];
4
4
  import * as React from 'react';
5
5
  import PropTypes from 'prop-types';
6
6
  import composeClasses from '@mui/utils/composeClasses';
7
7
  import { useSlotProps } from '@mui/base/utils';
8
8
  import generateUtilityClass from '@mui/utils/generateUtilityClass';
9
9
  import generateUtilityClasses from '@mui/utils/generateUtilityClasses';
10
- import { InteractionContext } from '../context/InteractionProvider';
11
- import { getIsFaded, getIsHighlighted, useInteractionItemProps } from '../hooks/useInteractionItemProps';
10
+ import { useInteractionItemProps } from '../hooks/useInteractionItemProps';
12
11
  import { AnimatedLine } from './AnimatedLine';
12
+ import { useItemHighlighted } from '../context';
13
13
  import { jsx as _jsx } from "react/jsx-runtime";
14
14
  export function getLineElementUtilityClass(slot) {
15
15
  return generateUtilityClass('MuiLineElement', slot);
@@ -43,24 +43,18 @@ function LineElement(props) {
43
43
  classes: innerClasses,
44
44
  color,
45
45
  gradientId,
46
- highlightScope,
47
46
  slots,
48
47
  slotProps,
49
48
  onClick
50
49
  } = props,
51
50
  other = _objectWithoutPropertiesLoose(props, _excluded);
52
- const getInteractionItemProps = useInteractionItemProps(highlightScope);
51
+ const getInteractionItemProps = useInteractionItemProps();
53
52
  const {
54
- item
55
- } = React.useContext(InteractionContext);
56
- const isHighlighted = getIsHighlighted(item, {
57
- type: 'line',
58
- seriesId: id
59
- }, highlightScope);
60
- const isFaded = !isHighlighted && getIsFaded(item, {
61
- type: 'line',
53
+ isFaded,
54
+ isHighlighted
55
+ } = useItemHighlighted({
62
56
  seriesId: id
63
- }, highlightScope);
57
+ });
64
58
  const ownerState = {
65
59
  id,
66
60
  classes: innerClasses,
@@ -95,10 +89,6 @@ process.env.NODE_ENV !== "production" ? LineElement.propTypes = {
95
89
  color: PropTypes.string.isRequired,
96
90
  d: PropTypes.string.isRequired,
97
91
  gradientId: PropTypes.string,
98
- highlightScope: PropTypes.shape({
99
- faded: PropTypes.oneOf(['global', 'none', 'series']),
100
- highlighted: PropTypes.oneOf(['item', 'none', 'series'])
101
- }),
102
92
  id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
103
93
  /**
104
94
  * If `true`, animations are skipped.
@@ -94,7 +94,6 @@ function LinePlot(props) {
94
94
  d,
95
95
  seriesId,
96
96
  color,
97
- highlightScope,
98
97
  gradientUsed
99
98
  }) => {
100
99
  return /*#__PURE__*/_jsx(LineElement, {
@@ -102,7 +101,6 @@ function LinePlot(props) {
102
101
  d: d,
103
102
  color: color,
104
103
  gradientId: gradientUsed && getGradientId(...gradientUsed),
105
- highlightScope: highlightScope,
106
104
  skipAnimation: skipAnimation,
107
105
  slots: slots,
108
106
  slotProps: slotProps,
@@ -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 = ["x", "y", "id", "classes", "color", "shape", "dataIndex", "highlightScope", "onClick", "skipAnimation"];
3
+ const _excluded = ["x", "y", "id", "classes", "color", "shape", "dataIndex", "onClick", "skipAnimation"];
4
4
  import * as React from 'react';
5
5
  import PropTypes from 'prop-types';
6
6
  import composeClasses from '@mui/utils/composeClasses';
@@ -11,7 +11,8 @@ import { symbol as d3Symbol, symbolsFill as d3SymbolsFill } from 'd3-shape';
11
11
  import { animated, to, useSpring } from '@react-spring/web';
12
12
  import { getSymbol } from '../internals/utils';
13
13
  import { InteractionContext } from '../context/InteractionProvider';
14
- import { getIsFaded, getIsHighlighted, useInteractionItemProps } from '../hooks/useInteractionItemProps';
14
+ import { useInteractionItemProps } from '../hooks/useInteractionItemProps';
15
+ import { useItemHighlighted } from '../context';
15
16
  import { jsx as _jsx } from "react/jsx-runtime";
16
17
  export function getMarkElementUtilityClass(slot) {
17
18
  return generateUtilityClass('MuiMarkElement', slot);
@@ -60,24 +61,20 @@ function MarkElement(props) {
60
61
  color,
61
62
  shape,
62
63
  dataIndex,
63
- highlightScope,
64
64
  onClick,
65
65
  skipAnimation
66
66
  } = props,
67
67
  other = _objectWithoutPropertiesLoose(props, _excluded);
68
- const getInteractionItemProps = useInteractionItemProps(highlightScope);
68
+ const getInteractionItemProps = useInteractionItemProps();
69
+ const {
70
+ isFaded,
71
+ isHighlighted
72
+ } = useItemHighlighted({
73
+ seriesId: id
74
+ });
69
75
  const {
70
- item,
71
76
  axis
72
77
  } = React.useContext(InteractionContext);
73
- const isHighlighted = axis.x?.index === dataIndex || getIsHighlighted(item, {
74
- type: 'line',
75
- seriesId: id
76
- }, highlightScope);
77
- const isFaded = !isHighlighted && getIsFaded(item, {
78
- type: 'line',
79
- seriesId: id
80
- }, highlightScope);
81
78
  const position = useSpring({
82
79
  x,
83
80
  y,
@@ -86,7 +83,7 @@ function MarkElement(props) {
86
83
  const ownerState = {
87
84
  id,
88
85
  classes: innerClasses,
89
- isHighlighted,
86
+ isHighlighted: axis.x?.index === dataIndex || isHighlighted,
90
87
  isFaded,
91
88
  color
92
89
  };
@@ -117,10 +114,6 @@ process.env.NODE_ENV !== "production" ? MarkElement.propTypes = {
117
114
  * The index to the element in the series' data array.
118
115
  */
119
116
  dataIndex: PropTypes.number.isRequired,
120
- highlightScope: PropTypes.shape({
121
- faded: PropTypes.oneOf(['global', 'none', 'series']),
122
- highlighted: PropTypes.oneOf(['item', 'none', 'series'])
123
- }),
124
117
  id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
125
118
  /**
126
119
  * The shape of the marker.
@@ -139,7 +139,6 @@ function MarkPlot(props) {
139
139
  x: x,
140
140
  y: y // Don't know why TS doesn't get from the filter that y can't be null
141
141
  ,
142
- highlightScope: series[seriesId].highlightScope,
143
142
  skipAnimation: skipAnimation,
144
143
  onClick: onItemClick && (event => onItemClick(event, {
145
144
  type: 'line',
@@ -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 = ["classes", "color", "cornerRadius", "dataIndex", "endAngle", "highlightScope", "id", "innerRadius", "isFaded", "isHighlighted", "onClick", "outerRadius", "paddingAngle", "startAngle"];
3
+ const _excluded = ["classes", "color", "cornerRadius", "dataIndex", "endAngle", "id", "innerRadius", "isFaded", "isHighlighted", "onClick", "outerRadius", "paddingAngle", "startAngle", "highlightScope"];
4
4
  import * as React from 'react';
5
5
  import PropTypes from 'prop-types';
6
6
  import { arc as d3Arc } from 'd3-shape';
@@ -45,7 +45,6 @@ function PieArc(props) {
45
45
  cornerRadius,
46
46
  dataIndex,
47
47
  endAngle,
48
- highlightScope,
49
48
  id,
50
49
  innerRadius,
51
50
  isFaded,
@@ -65,7 +64,7 @@ function PieArc(props) {
65
64
  isHighlighted
66
65
  };
67
66
  const classes = useUtilityClasses(ownerState);
68
- const getInteractionItemProps = useInteractionItemProps(highlightScope);
67
+ const getInteractionItemProps = useInteractionItemProps();
69
68
  return /*#__PURE__*/_jsx(PieArcRoot, _extends({
70
69
  d: to([startAngle, endAngle, paddingAngle, innerRadius, outerRadius, cornerRadius], (sA, eA, pA, iR, oR, cR) => d3Arc().cornerRadius(cR)({
71
70
  padAngle: pA,
@@ -91,8 +90,13 @@ process.env.NODE_ENV !== "production" ? PieArc.propTypes = {
91
90
  // ----------------------------------------------------------------------
92
91
  classes: PropTypes.object,
93
92
  dataIndex: PropTypes.number.isRequired,
93
+ /**
94
+ * @deprecated Use the `isFaded` or `isHighlighted` props instead.
95
+ */
94
96
  highlightScope: PropTypes.shape({
97
+ fade: PropTypes.oneOf(['global', 'none', 'series']),
95
98
  faded: PropTypes.oneOf(['global', 'none', 'series']),
99
+ highlight: PropTypes.oneOf(['item', 'none', 'series']),
96
100
  highlighted: PropTypes.oneOf(['item', 'none', 'series'])
97
101
  }),
98
102
  id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
@@ -1,6 +1,6 @@
1
1
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
2
2
  import _extends from "@babel/runtime/helpers/esm/extends";
3
- const _excluded = ["arcLabel", "arcLabelMinAngle", "arcLabelRadius", "cornerRadius", "data", "faded", "highlighted", "highlightScope", "id", "innerRadius", "outerRadius", "paddingAngle", "skipAnimation", "slotProps", "slots"],
3
+ const _excluded = ["arcLabel", "arcLabelMinAngle", "arcLabelRadius", "cornerRadius", "data", "faded", "highlighted", "id", "innerRadius", "outerRadius", "paddingAngle", "skipAnimation", "slotProps", "slots"],
4
4
  _excluded2 = ["startAngle", "endAngle", "paddingAngle", "innerRadius", "outerRadius", "arcLabelRadius", "cornerRadius"];
5
5
  import * as React from 'react';
6
6
  import PropTypes from 'prop-types';
@@ -43,7 +43,6 @@ function PieArcLabelPlot(props) {
43
43
  additionalRadius: -5
44
44
  },
45
45
  highlighted,
46
- highlightScope,
47
46
  id,
48
47
  innerRadius,
49
48
  outerRadius,
@@ -60,7 +59,6 @@ function PieArcLabelPlot(props) {
60
59
  cornerRadius,
61
60
  paddingAngle,
62
61
  id,
63
- highlightScope,
64
62
  highlighted,
65
63
  faded,
66
64
  data
@@ -162,10 +160,6 @@ process.env.NODE_ENV !== "production" ? PieArcLabelPlot.propTypes = {
162
160
  outerRadius: PropTypes.number,
163
161
  paddingAngle: PropTypes.number
164
162
  }),
165
- highlightScope: PropTypes.shape({
166
- faded: PropTypes.oneOf(['global', 'none', 'series']),
167
- highlighted: PropTypes.oneOf(['item', 'none', 'series'])
168
- }),
169
163
  id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
170
164
  /**
171
165
  * The radius between circle center and the beginning of the arc.
@@ -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 = ["slots", "slotProps", "innerRadius", "outerRadius", "cornerRadius", "paddingAngle", "id", "highlightScope", "highlighted", "faded", "data", "onItemClick", "skipAnimation"],
3
+ const _excluded = ["slots", "slotProps", "innerRadius", "outerRadius", "cornerRadius", "paddingAngle", "id", "highlighted", "faded", "data", "onItemClick", "skipAnimation"],
4
4
  _excluded2 = ["startAngle", "endAngle", "paddingAngle", "innerRadius", "arcLabelRadius", "outerRadius", "cornerRadius"];
5
5
  import * as React from 'react';
6
6
  import PropTypes from 'prop-types';
@@ -8,6 +8,7 @@ import { useTransition } from '@react-spring/web';
8
8
  import { PieArc } from './PieArc';
9
9
  import { defaultTransitionConfig } from './dataTransform/transition';
10
10
  import { useTransformData } from './dataTransform/useTransformData';
11
+ import { useHighlighted } from '../context';
11
12
  import { jsx as _jsx } from "react/jsx-runtime";
12
13
  function PieArcPlot(props) {
13
14
  const {
@@ -18,7 +19,6 @@ function PieArcPlot(props) {
18
19
  cornerRadius = 0,
19
20
  paddingAngle = 0,
20
21
  id,
21
- highlightScope,
22
22
  highlighted,
23
23
  faded = {
24
24
  additionalRadius: -5
@@ -34,7 +34,6 @@ function PieArcPlot(props) {
34
34
  cornerRadius,
35
35
  paddingAngle,
36
36
  id,
37
- highlightScope,
38
37
  highlighted,
39
38
  faded,
40
39
  data
@@ -42,6 +41,9 @@ function PieArcPlot(props) {
42
41
  const transition = useTransition(transformedData, _extends({}, defaultTransitionConfig, {
43
42
  immediate: skipAnimation
44
43
  }));
44
+ const {
45
+ highlightScope
46
+ } = useHighlighted();
45
47
  if (data.length === 0) {
46
48
  return null;
47
49
  }
@@ -133,10 +135,6 @@ process.env.NODE_ENV !== "production" ? PieArcPlot.propTypes = {
133
135
  outerRadius: PropTypes.number,
134
136
  paddingAngle: PropTypes.number
135
137
  }),
136
- highlightScope: PropTypes.shape({
137
- faded: PropTypes.oneOf(['global', 'none', 'series']),
138
- highlighted: PropTypes.oneOf(['item', 'none', 'series'])
139
- }),
140
138
  id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
141
139
  /**
142
140
  * The radius between circle center and the beginning of the arc.
@@ -61,7 +61,9 @@ function PieChart(props) {
61
61
  slots,
62
62
  slotProps,
63
63
  onItemClick,
64
- loading
64
+ loading,
65
+ highlightedItem,
66
+ onHighlightChange
65
67
  } = props;
66
68
  const isRTL = useIsRTL();
67
69
  const margin = _extends({}, isRTL ? defaultRTLMargin : defaultMargin, marginProps);
@@ -88,6 +90,8 @@ function PieChart(props) {
88
90
  colors: colors,
89
91
  sx: sx,
90
92
  disableAxisListener: tooltip?.trigger !== 'axis' && axisHighlight?.x === 'none' && axisHighlight?.y === 'none',
93
+ highlightedItem: highlightedItem,
94
+ onHighlightChange: onHighlightChange,
91
95
  children: [/*#__PURE__*/_jsx(ChartsAxis, {
92
96
  topAxis: topAxis,
93
97
  leftAxis: leftAxis,
@@ -155,6 +159,13 @@ process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
155
159
  * The height of the chart in px. If not defined, it takes the height of the parent element.
156
160
  */
157
161
  height: PropTypes.number,
162
+ /**
163
+ * The item currently highlighted. Turns highlighting into a controlled prop.
164
+ */
165
+ highlightedItem: PropTypes.shape({
166
+ dataIndex: PropTypes.number,
167
+ seriesId: PropTypes.oneOfType([PropTypes.number, PropTypes.string])
168
+ }),
158
169
  /**
159
170
  * Indicate which axis to display the left of the charts.
160
171
  * Can be a string (the id of the axis) or an object `ChartsYAxisProps`.
@@ -194,6 +205,12 @@ process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
194
205
  right: PropTypes.number,
195
206
  top: PropTypes.number
196
207
  }),
208
+ /**
209
+ * The callback fired when the highlighted item changes.
210
+ *
211
+ * @param {HighlightItemData | null} highlightedItem The newly highlighted item.
212
+ */
213
+ onHighlightChange: PropTypes.func,
197
214
  /**
198
215
  * Callback fired when a pie arc is clicked.
199
216
  */
@@ -49,8 +49,7 @@ function PiePlot(props) {
49
49
  cx: cxParam,
50
50
  cy: cyParam,
51
51
  highlighted,
52
- faded,
53
- highlightScope
52
+ faded
54
53
  } = series[seriesId];
55
54
  const {
56
55
  cx,
@@ -75,7 +74,6 @@ function PiePlot(props) {
75
74
  id: seriesId,
76
75
  data: data,
77
76
  skipAnimation: skipAnimation,
78
- highlightScope: highlightScope,
79
77
  highlighted: highlighted,
80
78
  faded: faded,
81
79
  onItemClick: onItemClick,
@@ -94,8 +92,7 @@ function PiePlot(props) {
94
92
  arcLabelMinAngle,
95
93
  data,
96
94
  cx: cxParam,
97
- cy: cyParam,
98
- highlightScope
95
+ cy: cyParam
99
96
  } = series[seriesId];
100
97
  const {
101
98
  cx,
@@ -124,7 +121,6 @@ function PiePlot(props) {
124
121
  skipAnimation: skipAnimation,
125
122
  arcLabel: arcLabel,
126
123
  arcLabelMinAngle: arcLabelMinAngle,
127
- highlightScope: highlightScope,
128
124
  slots: slots,
129
125
  slotProps: slotProps
130
126
  })
@@ -1,11 +1,9 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import * as React from 'react';
3
- import { InteractionContext } from '../../context/InteractionProvider';
4
- import { getIsHighlighted, getIsFaded } from '../../hooks/useInteractionItemProps';
3
+ import { useHighlighted } from '../../context';
5
4
  export function useTransformData(series) {
6
5
  const {
7
6
  id: seriesId,
8
- highlightScope,
9
7
  data,
10
8
  faded,
11
9
  highlighted,
@@ -16,29 +14,16 @@ export function useTransformData(series) {
16
14
  cornerRadius: baseCornerRadius = 0
17
15
  } = series;
18
16
  const {
19
- item: highlightedItem
20
- } = React.useContext(InteractionContext);
21
- const getHighlightStatus = React.useCallback(dataIndex => {
22
- const isHighlighted = getIsHighlighted(highlightedItem, {
23
- type: 'pie',
24
- seriesId,
25
- dataIndex
26
- }, highlightScope);
27
- const isFaded = !isHighlighted && getIsFaded(highlightedItem, {
28
- type: 'pie',
17
+ isFaded: isItemFaded,
18
+ isHighlighted: isItemHighlighted
19
+ } = useHighlighted();
20
+ const dataWithHighlight = React.useMemo(() => data.map((item, itemIndex) => {
21
+ const currentItem = {
29
22
  seriesId,
30
- dataIndex
31
- }, highlightScope);
32
- return {
33
- isHighlighted,
34
- isFaded
23
+ dataIndex: itemIndex
35
24
  };
36
- }, [highlightScope, highlightedItem, seriesId]);
37
- const dataWithHighlight = React.useMemo(() => data.map((item, itemIndex) => {
38
- const {
39
- isHighlighted,
40
- isFaded
41
- } = getHighlightStatus(itemIndex);
25
+ const isHighlighted = isItemHighlighted(currentItem);
26
+ const isFaded = !isHighlighted && isItemFaded(currentItem);
42
27
  const attributesOverride = _extends({
43
28
  additionalRadius: 0
44
29
  }, isFaded && faded || isHighlighted && highlighted || {});
@@ -56,6 +41,6 @@ export function useTransformData(series) {
56
41
  cornerRadius,
57
42
  arcLabelRadius
58
43
  });
59
- }), [baseCornerRadius, baseInnerRadius, baseOuterRadius, basePaddingAngle, baseArcLabelRadius, data, faded, getHighlightStatus, highlighted]);
44
+ }), [baseCornerRadius, baseInnerRadius, baseOuterRadius, basePaddingAngle, baseArcLabelRadius, data, faded, highlighted, isItemFaded, isItemHighlighted, seriesId]);
60
45
  return dataWithHighlight;
61
46
  }
@@ -74,6 +74,13 @@ process.env.NODE_ENV !== "production" ? ResponsiveChartContainer.propTypes = {
74
74
  * The height of the chart in px. If not defined, it takes the height of the parent element.
75
75
  */
76
76
  height: PropTypes.number,
77
+ /**
78
+ * The item currently highlighted. Turns highlighting into a controlled prop.
79
+ */
80
+ highlightedItem: PropTypes.shape({
81
+ dataIndex: PropTypes.number,
82
+ seriesId: PropTypes.oneOfType([PropTypes.number, PropTypes.string])
83
+ }),
77
84
  /**
78
85
  * The margin between the SVG and the drawing area.
79
86
  * It's used for leaving some space for extra information such as the x- and y-axis or legend.
@@ -86,6 +93,12 @@ process.env.NODE_ENV !== "production" ? ResponsiveChartContainer.propTypes = {
86
93
  right: PropTypes.number,
87
94
  top: PropTypes.number
88
95
  }),
96
+ /**
97
+ * The callback fired when the highlighted item changes.
98
+ *
99
+ * @param {HighlightItemData | null} highlightedItem The newly highlighted item.
100
+ */
101
+ onHighlightChange: PropTypes.func,
89
102
  /**
90
103
  * The array of series to display.
91
104
  * Each type of series has its own specificity.
@@ -2,8 +2,9 @@ import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import * as React from 'react';
3
3
  import PropTypes from 'prop-types';
4
4
  import { getValueToPositionMapper } from '../hooks/useScale';
5
- import { getIsFaded, getIsHighlighted, useInteractionItemProps } from '../hooks/useInteractionItemProps';
5
+ import { useInteractionItemProps } from '../hooks/useInteractionItemProps';
6
6
  import { InteractionContext } from '../context/InteractionProvider';
7
+ import { useHighlighted } from '../context';
7
8
  import { jsx as _jsx } from "react/jsx-runtime";
8
9
  /**
9
10
  * Demos:
@@ -25,16 +26,15 @@ function Scatter(props) {
25
26
  markerSize,
26
27
  onItemClick
27
28
  } = props;
28
- const highlightScope = React.useMemo(() => _extends({
29
- highlighted: 'item',
30
- faded: 'global'
31
- }, series.highlightScope), [series.highlightScope]);
32
29
  const {
33
- item,
34
30
  useVoronoiInteraction
35
31
  } = React.useContext(InteractionContext);
36
32
  const skipInteractionHandlers = useVoronoiInteraction || series.disableHover;
37
- const getInteractionItemProps = useInteractionItemProps(highlightScope, skipInteractionHandlers);
33
+ const getInteractionItemProps = useInteractionItemProps(skipInteractionHandlers);
34
+ const {
35
+ isFaded,
36
+ isHighlighted
37
+ } = useHighlighted();
38
38
  const cleanData = React.useMemo(() => {
39
39
  const getXPosition = getValueToPositionMapper(xScale);
40
40
  const getYPosition = getValueToPositionMapper(yScale);
@@ -56,12 +56,16 @@ function Scatter(props) {
56
56
  dataIndex: i
57
57
  };
58
58
  if (isInRange) {
59
- const isHighlighted = getIsHighlighted(item, pointCtx, highlightScope);
59
+ const currentItem = {
60
+ seriesId: pointCtx.seriesId,
61
+ dataIndex: pointCtx.dataIndex
62
+ };
63
+ const isItemHighlighted = isHighlighted(currentItem);
60
64
  temp.push({
61
65
  x,
62
66
  y,
63
- isHighlighted,
64
- isFaded: !isHighlighted && getIsFaded(item, pointCtx, highlightScope),
67
+ isHighlighted: isItemHighlighted,
68
+ isFaded: !isItemHighlighted && isFaded(currentItem),
65
69
  interactionProps: getInteractionItemProps(pointCtx),
66
70
  id: scatterPoint.id,
67
71
  dataIndex: i,
@@ -70,7 +74,7 @@ function Scatter(props) {
70
74
  }
71
75
  }
72
76
  return temp;
73
- }, [xScale, yScale, series.data, series.id, item, highlightScope, getInteractionItemProps, color, colorGetter]);
77
+ }, [xScale, yScale, series.data, series.id, getInteractionItemProps, color, colorGetter, isFaded, isHighlighted]);
74
78
  return /*#__PURE__*/_jsx("g", {
75
79
  children: cleanData.map(dataPoint => /*#__PURE__*/_jsx("circle", _extends({
76
80
  cx: 0,
@@ -47,7 +47,9 @@ const ScatterChart = /*#__PURE__*/React.forwardRef(function ScatterChart(props,
47
47
  children,
48
48
  slots,
49
49
  slotProps,
50
- loading
50
+ loading,
51
+ highlightedItem,
52
+ onHighlightChange
51
53
  } = props;
52
54
  return /*#__PURE__*/_jsx(ResponsiveChartContainer, {
53
55
  ref: ref,
@@ -61,6 +63,8 @@ const ScatterChart = /*#__PURE__*/React.forwardRef(function ScatterChart(props,
61
63
  xAxis: xAxis,
62
64
  yAxis: yAxis,
63
65
  sx: sx,
66
+ highlightedItem: highlightedItem,
67
+ onHighlightChange: onHighlightChange,
64
68
  children: /*#__PURE__*/_jsxs(ZAxisContextProvider, {
65
69
  zAxis: zAxis,
66
70
  children: [!disableVoronoi && /*#__PURE__*/_jsx(ChartsVoronoiHandler, {
@@ -150,6 +154,13 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
150
154
  * The height of the chart in px. If not defined, it takes the height of the parent element.
151
155
  */
152
156
  height: PropTypes.number,
157
+ /**
158
+ * The item currently highlighted. Turns highlighting into a controlled prop.
159
+ */
160
+ highlightedItem: PropTypes.shape({
161
+ dataIndex: PropTypes.number,
162
+ seriesId: PropTypes.oneOfType([PropTypes.number, PropTypes.string])
163
+ }),
153
164
  /**
154
165
  * Indicate which axis to display the left of the charts.
155
166
  * Can be a string (the id of the axis) or an object `ChartsYAxisProps`.
@@ -187,6 +198,12 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
187
198
  right: PropTypes.number,
188
199
  top: PropTypes.number
189
200
  }),
201
+ /**
202
+ * The callback fired when the highlighted item changes.
203
+ *
204
+ * @param {HighlightItemData | null} highlightedItem The newly highlighted item.
205
+ */
206
+ onHighlightChange: PropTypes.func,
190
207
  /**
191
208
  * Callback fired when clicking on a scatter item.
192
209
  * @param {MouseEvent} event The mouse event recorded on the `<svg/>` element if using Voronoi cells. Or the Mouse event from the scatter element, when `disableVoronoi=true`.
@@ -147,6 +147,13 @@ process.env.NODE_ENV !== "production" ? SparkLineChart.propTypes = {
147
147
  * The height of the chart in px. If not defined, it takes the height of the parent element.
148
148
  */
149
149
  height: PropTypes.number,
150
+ /**
151
+ * The item currently highlighted. Turns highlighting into a controlled prop.
152
+ */
153
+ highlightedItem: PropTypes.shape({
154
+ dataIndex: PropTypes.number,
155
+ seriesId: PropTypes.oneOfType([PropTypes.number, PropTypes.string])
156
+ }),
150
157
  /**
151
158
  * The margin between the SVG and the drawing area.
152
159
  * It's used for leaving some space for extra information such as the x- and y-axis or legend.
@@ -164,6 +171,12 @@ process.env.NODE_ENV !== "production" ? SparkLineChart.propTypes = {
164
171
  right: PropTypes.number,
165
172
  top: PropTypes.number
166
173
  }),
174
+ /**
175
+ * The callback fired when the highlighted item changes.
176
+ *
177
+ * @param {HighlightItemData | null} highlightedItem The newly highlighted item.
178
+ */
179
+ onHighlightChange: PropTypes.func,
167
180
  /**
168
181
  * Type of plot used.
169
182
  * @default 'line'
@@ -0,0 +1,29 @@
1
+ import * as React from 'react';
2
+
3
+ /**
4
+ * The data of the highlighted item.
5
+ * To highlight an item, you need to provide the series id and the item id.
6
+ * If targeting the whole series, you can omit the item id.
7
+ * To clear the highlight, set the value to an empty object.
8
+ *
9
+ * @example
10
+ * // Highlight the item with the series id 'london' and the item id 0.
11
+ * { seriesId: 'london', dataIndex: 0 }
12
+ *
13
+ * // Highlight the whole series with the series id 'london'.
14
+ * { seriesId: 'london' }
15
+ *
16
+ * // Clear the highlight.
17
+ * {}
18
+ */
19
+
20
+ export const HighlightedContext = /*#__PURE__*/React.createContext({
21
+ highlightedItem: null,
22
+ setHighlighted: () => {},
23
+ clearHighlighted: () => {},
24
+ isHighlighted: () => false,
25
+ isFaded: () => false
26
+ });
27
+ if (process.env.NODE_ENV !== 'production') {
28
+ HighlightedContext.displayName = 'HighlightedContext';
29
+ }