@mui/x-charts 7.5.1 → 7.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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 +87 -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
@@ -66,7 +66,9 @@ const LineChart = exports.LineChart = /*#__PURE__*/React.forwardRef(function Lin
66
66
  slots,
67
67
  slotProps,
68
68
  skipAnimation,
69
- loading
69
+ loading,
70
+ highlightedItem,
71
+ onHighlightChange
70
72
  } = props;
71
73
  const id = (0, _useId.default)();
72
74
  const clipPathId = `${id}-clip-path`;
@@ -91,6 +93,8 @@ const LineChart = exports.LineChart = /*#__PURE__*/React.forwardRef(function Lin
91
93
  dataset: dataset,
92
94
  sx: sx,
93
95
  disableAxisListener: tooltip?.trigger !== 'axis' && axisHighlight?.x === 'none' && axisHighlight?.y === 'none' && !onAxisClick,
96
+ highlightedItem: highlightedItem,
97
+ onHighlightChange: onHighlightChange,
94
98
  children: [onAxisClick && /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsOnAxisClickHandler.ChartsOnAxisClickHandler, {
95
99
  onAxisClick: onAxisClick
96
100
  }), grid && /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsGrid.ChartsGrid, {
@@ -192,6 +196,13 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
192
196
  * The height of the chart in px. If not defined, it takes the height of the parent element.
193
197
  */
194
198
  height: _propTypes.default.number,
199
+ /**
200
+ * The item currently highlighted. Turns highlighting into a controlled prop.
201
+ */
202
+ highlightedItem: _propTypes.default.shape({
203
+ dataIndex: _propTypes.default.number,
204
+ seriesId: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string])
205
+ }),
195
206
  /**
196
207
  * Indicate which axis to display the left of the charts.
197
208
  * Can be a string (the id of the axis) or an object `ChartsYAxisProps`.
@@ -240,6 +251,12 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
240
251
  * @param {null | AxisData} data The data about the clicked axis and items associated with it.
241
252
  */
242
253
  onAxisClick: _propTypes.default.func,
254
+ /**
255
+ * The callback fired when the highlighted item changes.
256
+ *
257
+ * @param {HighlightItemData | null} highlightedItem The newly highlighted item.
258
+ */
259
+ onHighlightChange: _propTypes.default.func,
243
260
  /**
244
261
  * Callback fired when a line element is clicked.
245
262
  */
@@ -1,5 +1,4 @@
1
1
  import * as React from 'react';
2
- import { HighlightScope } from '../context/HighlightProvider';
3
2
  import { AnimatedLineProps } from './AnimatedLine';
4
3
  import { SeriesId } from '../models/seriesType/common';
5
4
  export interface LineElementClasses {
@@ -33,7 +32,6 @@ export interface LineElementSlotProps {
33
32
  }
34
33
  export interface LineElementProps extends Omit<LineElementOwnerState, 'isFaded' | 'isHighlighted'>, Pick<AnimatedLineProps, 'skipAnimation'>, Omit<React.SVGProps<SVGPathElement>, 'ref' | 'color' | 'id'> {
35
34
  d: string;
36
- highlightScope?: Partial<HighlightScope>;
37
35
  /**
38
36
  * The props used for each component slot.
39
37
  * @default {}
@@ -15,11 +15,11 @@ var _composeClasses = _interopRequireDefault(require("@mui/utils/composeClasses"
15
15
  var _utils = require("@mui/base/utils");
16
16
  var _generateUtilityClass = _interopRequireDefault(require("@mui/utils/generateUtilityClass"));
17
17
  var _generateUtilityClasses = _interopRequireDefault(require("@mui/utils/generateUtilityClasses"));
18
- var _InteractionProvider = require("../context/InteractionProvider");
19
18
  var _useInteractionItemProps = require("../hooks/useInteractionItemProps");
20
19
  var _AnimatedLine = require("./AnimatedLine");
20
+ var _context = require("../context");
21
21
  var _jsxRuntime = require("react/jsx-runtime");
22
- const _excluded = ["id", "classes", "color", "gradientId", "highlightScope", "slots", "slotProps", "onClick"];
22
+ const _excluded = ["id", "classes", "color", "gradientId", "slots", "slotProps", "onClick"];
23
23
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
24
24
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
25
25
  function getLineElementUtilityClass(slot) {
@@ -54,24 +54,18 @@ function LineElement(props) {
54
54
  classes: innerClasses,
55
55
  color,
56
56
  gradientId,
57
- highlightScope,
58
57
  slots,
59
58
  slotProps,
60
59
  onClick
61
60
  } = props,
62
61
  other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
63
- const getInteractionItemProps = (0, _useInteractionItemProps.useInteractionItemProps)(highlightScope);
62
+ const getInteractionItemProps = (0, _useInteractionItemProps.useInteractionItemProps)();
64
63
  const {
65
- item
66
- } = React.useContext(_InteractionProvider.InteractionContext);
67
- const isHighlighted = (0, _useInteractionItemProps.getIsHighlighted)(item, {
68
- type: 'line',
69
- seriesId: id
70
- }, highlightScope);
71
- const isFaded = !isHighlighted && (0, _useInteractionItemProps.getIsFaded)(item, {
72
- type: 'line',
64
+ isFaded,
65
+ isHighlighted
66
+ } = (0, _context.useItemHighlighted)({
73
67
  seriesId: id
74
- }, highlightScope);
68
+ });
75
69
  const ownerState = {
76
70
  id,
77
71
  classes: innerClasses,
@@ -106,10 +100,6 @@ process.env.NODE_ENV !== "production" ? LineElement.propTypes = {
106
100
  color: _propTypes.default.string.isRequired,
107
101
  d: _propTypes.default.string.isRequired,
108
102
  gradientId: _propTypes.default.string,
109
- highlightScope: _propTypes.default.shape({
110
- faded: _propTypes.default.oneOf(['global', 'none', 'series']),
111
- highlighted: _propTypes.default.oneOf(['item', 'none', 'series'])
112
- }),
113
103
  id: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]).isRequired,
114
104
  /**
115
105
  * If `true`, animations are skipped.
@@ -103,7 +103,6 @@ function LinePlot(props) {
103
103
  d,
104
104
  seriesId,
105
105
  color,
106
- highlightScope,
107
106
  gradientUsed
108
107
  }) => {
109
108
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_LineElement.LineElement, {
@@ -111,7 +110,6 @@ function LinePlot(props) {
111
110
  d: d,
112
111
  color: color,
113
112
  gradientId: gradientUsed && getGradientId(...gradientUsed),
114
- highlightScope: highlightScope,
115
113
  skipAnimation: skipAnimation,
116
114
  slots: slots,
117
115
  slotProps: slotProps,
@@ -1,5 +1,4 @@
1
1
  import * as React from 'react';
2
- import { HighlightScope } from '../context/HighlightProvider';
3
2
  import { SeriesId } from '../models/seriesType/common';
4
3
  export interface MarkElementClasses {
5
4
  /** Styles applied to the root element. */
@@ -33,7 +32,6 @@ export type MarkElementProps = Omit<MarkElementOwnerState, 'isFaded' | 'isHighli
33
32
  * The index to the element in the series' data array.
34
33
  */
35
34
  dataIndex: number;
36
- highlightScope?: Partial<HighlightScope>;
37
35
  };
38
36
  /**
39
37
  * Demos:
@@ -20,8 +20,9 @@ var _web = require("@react-spring/web");
20
20
  var _utils = require("../internals/utils");
21
21
  var _InteractionProvider = require("../context/InteractionProvider");
22
22
  var _useInteractionItemProps = require("../hooks/useInteractionItemProps");
23
+ var _context = require("../context");
23
24
  var _jsxRuntime = require("react/jsx-runtime");
24
- const _excluded = ["x", "y", "id", "classes", "color", "shape", "dataIndex", "highlightScope", "onClick", "skipAnimation"];
25
+ const _excluded = ["x", "y", "id", "classes", "color", "shape", "dataIndex", "onClick", "skipAnimation"];
25
26
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
26
27
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
27
28
  function getMarkElementUtilityClass(slot) {
@@ -71,24 +72,20 @@ function MarkElement(props) {
71
72
  color,
72
73
  shape,
73
74
  dataIndex,
74
- highlightScope,
75
75
  onClick,
76
76
  skipAnimation
77
77
  } = props,
78
78
  other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
79
- const getInteractionItemProps = (0, _useInteractionItemProps.useInteractionItemProps)(highlightScope);
79
+ const getInteractionItemProps = (0, _useInteractionItemProps.useInteractionItemProps)();
80
+ const {
81
+ isFaded,
82
+ isHighlighted
83
+ } = (0, _context.useItemHighlighted)({
84
+ seriesId: id
85
+ });
80
86
  const {
81
- item,
82
87
  axis
83
88
  } = React.useContext(_InteractionProvider.InteractionContext);
84
- const isHighlighted = axis.x?.index === dataIndex || (0, _useInteractionItemProps.getIsHighlighted)(item, {
85
- type: 'line',
86
- seriesId: id
87
- }, highlightScope);
88
- const isFaded = !isHighlighted && (0, _useInteractionItemProps.getIsFaded)(item, {
89
- type: 'line',
90
- seriesId: id
91
- }, highlightScope);
92
89
  const position = (0, _web.useSpring)({
93
90
  x,
94
91
  y,
@@ -97,7 +94,7 @@ function MarkElement(props) {
97
94
  const ownerState = {
98
95
  id,
99
96
  classes: innerClasses,
100
- isHighlighted,
97
+ isHighlighted: axis.x?.index === dataIndex || isHighlighted,
101
98
  isFaded,
102
99
  color
103
100
  };
@@ -128,10 +125,6 @@ process.env.NODE_ENV !== "production" ? MarkElement.propTypes = {
128
125
  * The index to the element in the series' data array.
129
126
  */
130
127
  dataIndex: _propTypes.default.number.isRequired,
131
- highlightScope: _propTypes.default.shape({
132
- faded: _propTypes.default.oneOf(['global', 'none', 'series']),
133
- highlighted: _propTypes.default.oneOf(['item', 'none', 'series'])
134
- }),
135
128
  id: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]).isRequired,
136
129
  /**
137
130
  * The shape of the marker.
@@ -148,7 +148,6 @@ function MarkPlot(props) {
148
148
  x: x,
149
149
  y: y // Don't know why TS doesn't get from the filter that y can't be null
150
150
  ,
151
- highlightScope: series[seriesId].highlightScope,
152
151
  skipAnimation: skipAnimation,
153
152
  onClick: onItemClick && (event => onItemClick(event, {
154
153
  type: 'line',
@@ -1,8 +1,8 @@
1
1
  /// <reference types="@react-spring/core" />
2
2
  import * as React from 'react';
3
3
  import { SpringValue } from '@react-spring/web';
4
- import { HighlightScope } from '../context/HighlightProvider';
5
4
  import { PieItemId } from '../models';
5
+ import { HighlightScope } from '../context';
6
6
  export interface PieArcClasses {
7
7
  /** Styles applied to the root element. */
8
8
  root: string;
@@ -25,6 +25,9 @@ export declare const pieArcClasses: PieArcClasses;
25
25
  export type PieArcProps = Omit<React.SVGProps<SVGPathElement>, 'ref' | 'id'> & PieArcOwnerState & {
26
26
  cornerRadius: SpringValue<number>;
27
27
  endAngle: SpringValue<number>;
28
+ /**
29
+ * @deprecated Use the `isFaded` or `isHighlighted` props instead.
30
+ */
28
31
  highlightScope?: Partial<HighlightScope>;
29
32
  innerRadius: SpringValue<number>;
30
33
  onClick?: (event: React.MouseEvent<SVGPathElement, MouseEvent>) => void;
@@ -19,7 +19,7 @@ var _styles = require("@mui/material/styles");
19
19
  var _generateUtilityClasses = _interopRequireDefault(require("@mui/utils/generateUtilityClasses"));
20
20
  var _useInteractionItemProps = require("../hooks/useInteractionItemProps");
21
21
  var _jsxRuntime = require("react/jsx-runtime");
22
- const _excluded = ["classes", "color", "cornerRadius", "dataIndex", "endAngle", "highlightScope", "id", "innerRadius", "isFaded", "isHighlighted", "onClick", "outerRadius", "paddingAngle", "startAngle"];
22
+ const _excluded = ["classes", "color", "cornerRadius", "dataIndex", "endAngle", "id", "innerRadius", "isFaded", "isHighlighted", "onClick", "outerRadius", "paddingAngle", "startAngle", "highlightScope"];
23
23
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
24
24
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
25
25
  function getPieArcUtilityClass(slot) {
@@ -56,7 +56,6 @@ function PieArc(props) {
56
56
  cornerRadius,
57
57
  dataIndex,
58
58
  endAngle,
59
- highlightScope,
60
59
  id,
61
60
  innerRadius,
62
61
  isFaded,
@@ -76,7 +75,7 @@ function PieArc(props) {
76
75
  isHighlighted
77
76
  };
78
77
  const classes = useUtilityClasses(ownerState);
79
- const getInteractionItemProps = (0, _useInteractionItemProps.useInteractionItemProps)(highlightScope);
78
+ const getInteractionItemProps = (0, _useInteractionItemProps.useInteractionItemProps)();
80
79
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(PieArcRoot, (0, _extends2.default)({
81
80
  d: (0, _web.to)([startAngle, endAngle, paddingAngle, innerRadius, outerRadius, cornerRadius], (sA, eA, pA, iR, oR, cR) => (0, _d3Shape.arc)().cornerRadius(cR)({
82
81
  padAngle: pA,
@@ -102,8 +101,13 @@ process.env.NODE_ENV !== "production" ? PieArc.propTypes = {
102
101
  // ----------------------------------------------------------------------
103
102
  classes: _propTypes.default.object,
104
103
  dataIndex: _propTypes.default.number.isRequired,
104
+ /**
105
+ * @deprecated Use the `isFaded` or `isHighlighted` props instead.
106
+ */
105
107
  highlightScope: _propTypes.default.shape({
108
+ fade: _propTypes.default.oneOf(['global', 'none', 'series']),
106
109
  faded: _propTypes.default.oneOf(['global', 'none', 'series']),
110
+ highlight: _propTypes.default.oneOf(['item', 'none', 'series']),
107
111
  highlighted: _propTypes.default.oneOf(['item', 'none', 'series'])
108
112
  }),
109
113
  id: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]).isRequired,
@@ -7,7 +7,7 @@ export interface PieArcLabelPlotSlots {
7
7
  export interface PieArcLabelPlotSlotProps {
8
8
  pieArcLabel?: Partial<PieArcLabelProps>;
9
9
  }
10
- export interface PieArcLabelPlotProps extends Pick<DefaultizedPieSeriesType, 'data' | 'faded' | 'highlighted' | 'cornerRadius' | 'paddingAngle' | 'arcLabel' | 'arcLabelMinAngle' | 'id' | 'highlightScope'>, ComputedPieRadius {
10
+ export interface PieArcLabelPlotProps extends Pick<DefaultizedPieSeriesType, 'data' | 'faded' | 'highlighted' | 'cornerRadius' | 'paddingAngle' | 'arcLabel' | 'arcLabelMinAngle' | 'id'>, ComputedPieRadius {
11
11
  /**
12
12
  * Override the arc attributes when it is faded.
13
13
  * @default { additionalRadius: -5 }
@@ -15,7 +15,7 @@ var _useTransformData = require("./dataTransform/useTransformData");
15
15
  var _PieArcLabel = require("./PieArcLabel");
16
16
  var _getLabel = require("../internals/getLabel");
17
17
  var _jsxRuntime = require("react/jsx-runtime");
18
- const _excluded = ["arcLabel", "arcLabelMinAngle", "arcLabelRadius", "cornerRadius", "data", "faded", "highlighted", "highlightScope", "id", "innerRadius", "outerRadius", "paddingAngle", "skipAnimation", "slotProps", "slots"],
18
+ const _excluded = ["arcLabel", "arcLabelMinAngle", "arcLabelRadius", "cornerRadius", "data", "faded", "highlighted", "id", "innerRadius", "outerRadius", "paddingAngle", "skipAnimation", "slotProps", "slots"],
19
19
  _excluded2 = ["startAngle", "endAngle", "paddingAngle", "innerRadius", "outerRadius", "arcLabelRadius", "cornerRadius"];
20
20
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
21
21
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
@@ -52,7 +52,6 @@ function PieArcLabelPlot(props) {
52
52
  additionalRadius: -5
53
53
  },
54
54
  highlighted,
55
- highlightScope,
56
55
  id,
57
56
  innerRadius,
58
57
  outerRadius,
@@ -69,7 +68,6 @@ function PieArcLabelPlot(props) {
69
68
  cornerRadius,
70
69
  paddingAngle,
71
70
  id,
72
- highlightScope,
73
71
  highlighted,
74
72
  faded,
75
73
  data
@@ -171,10 +169,6 @@ process.env.NODE_ENV !== "production" ? PieArcLabelPlot.propTypes = {
171
169
  outerRadius: _propTypes.default.number,
172
170
  paddingAngle: _propTypes.default.number
173
171
  }),
174
- highlightScope: _propTypes.default.shape({
175
- faded: _propTypes.default.oneOf(['global', 'none', 'series']),
176
- highlighted: _propTypes.default.oneOf(['item', 'none', 'series'])
177
- }),
178
172
  id: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]).isRequired,
179
173
  /**
180
174
  * The radius between circle center and the beginning of the arc.
@@ -7,7 +7,7 @@ export interface PieArcPlotSlots {
7
7
  export interface PieArcPlotSlotProps {
8
8
  pieArc?: Partial<PieArcProps>;
9
9
  }
10
- export interface PieArcPlotProps extends Pick<DefaultizedPieSeriesType, 'data' | 'faded' | 'highlighted' | 'cornerRadius' | 'paddingAngle' | 'id' | 'highlightScope'>, ComputedPieRadius {
10
+ export interface PieArcPlotProps extends Pick<DefaultizedPieSeriesType, 'data' | 'faded' | 'highlighted' | 'cornerRadius' | 'paddingAngle' | 'id'>, ComputedPieRadius {
11
11
  /**
12
12
  * Override the arc attributes when it is faded.
13
13
  * @default { additionalRadius: -5 }
@@ -13,8 +13,9 @@ var _web = require("@react-spring/web");
13
13
  var _PieArc = require("./PieArc");
14
14
  var _transition = require("./dataTransform/transition");
15
15
  var _useTransformData = require("./dataTransform/useTransformData");
16
+ var _context = require("../context");
16
17
  var _jsxRuntime = require("react/jsx-runtime");
17
- const _excluded = ["slots", "slotProps", "innerRadius", "outerRadius", "cornerRadius", "paddingAngle", "id", "highlightScope", "highlighted", "faded", "data", "onItemClick", "skipAnimation"],
18
+ const _excluded = ["slots", "slotProps", "innerRadius", "outerRadius", "cornerRadius", "paddingAngle", "id", "highlighted", "faded", "data", "onItemClick", "skipAnimation"],
18
19
  _excluded2 = ["startAngle", "endAngle", "paddingAngle", "innerRadius", "arcLabelRadius", "outerRadius", "cornerRadius"];
19
20
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
20
21
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
@@ -27,7 +28,6 @@ function PieArcPlot(props) {
27
28
  cornerRadius = 0,
28
29
  paddingAngle = 0,
29
30
  id,
30
- highlightScope,
31
31
  highlighted,
32
32
  faded = {
33
33
  additionalRadius: -5
@@ -43,7 +43,6 @@ function PieArcPlot(props) {
43
43
  cornerRadius,
44
44
  paddingAngle,
45
45
  id,
46
- highlightScope,
47
46
  highlighted,
48
47
  faded,
49
48
  data
@@ -51,6 +50,9 @@ function PieArcPlot(props) {
51
50
  const transition = (0, _web.useTransition)(transformedData, (0, _extends2.default)({}, _transition.defaultTransitionConfig, {
52
51
  immediate: skipAnimation
53
52
  }));
53
+ const {
54
+ highlightScope
55
+ } = (0, _context.useHighlighted)();
54
56
  if (data.length === 0) {
55
57
  return null;
56
58
  }
@@ -142,10 +144,6 @@ process.env.NODE_ENV !== "production" ? PieArcPlot.propTypes = {
142
144
  outerRadius: _propTypes.default.number,
143
145
  paddingAngle: _propTypes.default.number
144
146
  }),
145
- highlightScope: _propTypes.default.shape({
146
- faded: _propTypes.default.oneOf(['global', 'none', 'series']),
147
- highlighted: _propTypes.default.oneOf(['item', 'none', 'series'])
148
- }),
149
147
  id: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]).isRequired,
150
148
  /**
151
149
  * The radius between circle center and the beginning of the arc.
@@ -70,7 +70,9 @@ function PieChart(props) {
70
70
  slots,
71
71
  slotProps,
72
72
  onItemClick,
73
- loading
73
+ loading,
74
+ highlightedItem,
75
+ onHighlightChange
74
76
  } = props;
75
77
  const isRTL = (0, _useIsRTL.useIsRTL)();
76
78
  const margin = (0, _extends2.default)({}, isRTL ? defaultRTLMargin : defaultMargin, marginProps);
@@ -97,6 +99,8 @@ function PieChart(props) {
97
99
  colors: colors,
98
100
  sx: sx,
99
101
  disableAxisListener: tooltip?.trigger !== 'axis' && axisHighlight?.x === 'none' && axisHighlight?.y === 'none',
102
+ highlightedItem: highlightedItem,
103
+ onHighlightChange: onHighlightChange,
100
104
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsAxis.ChartsAxis, {
101
105
  topAxis: topAxis,
102
106
  leftAxis: leftAxis,
@@ -164,6 +168,13 @@ process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
164
168
  * The height of the chart in px. If not defined, it takes the height of the parent element.
165
169
  */
166
170
  height: _propTypes.default.number,
171
+ /**
172
+ * The item currently highlighted. Turns highlighting into a controlled prop.
173
+ */
174
+ highlightedItem: _propTypes.default.shape({
175
+ dataIndex: _propTypes.default.number,
176
+ seriesId: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string])
177
+ }),
167
178
  /**
168
179
  * Indicate which axis to display the left of the charts.
169
180
  * Can be a string (the id of the axis) or an object `ChartsYAxisProps`.
@@ -203,6 +214,12 @@ process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
203
214
  right: _propTypes.default.number,
204
215
  top: _propTypes.default.number
205
216
  }),
217
+ /**
218
+ * The callback fired when the highlighted item changes.
219
+ *
220
+ * @param {HighlightItemData | null} highlightedItem The newly highlighted item.
221
+ */
222
+ onHighlightChange: _propTypes.default.func,
206
223
  /**
207
224
  * Callback fired when a pie arc is clicked.
208
225
  */
@@ -58,8 +58,7 @@ function PiePlot(props) {
58
58
  cx: cxParam,
59
59
  cy: cyParam,
60
60
  highlighted,
61
- faded,
62
- highlightScope
61
+ faded
63
62
  } = series[seriesId];
64
63
  const {
65
64
  cx,
@@ -84,7 +83,6 @@ function PiePlot(props) {
84
83
  id: seriesId,
85
84
  data: data,
86
85
  skipAnimation: skipAnimation,
87
- highlightScope: highlightScope,
88
86
  highlighted: highlighted,
89
87
  faded: faded,
90
88
  onItemClick: onItemClick,
@@ -103,8 +101,7 @@ function PiePlot(props) {
103
101
  arcLabelMinAngle,
104
102
  data,
105
103
  cx: cxParam,
106
- cy: cyParam,
107
- highlightScope
104
+ cy: cyParam
108
105
  } = series[seriesId];
109
106
  const {
110
107
  cx,
@@ -133,7 +130,6 @@ function PiePlot(props) {
133
130
  skipAnimation: skipAnimation,
134
131
  arcLabel: arcLabel,
135
132
  arcLabelMinAngle: arcLabelMinAngle,
136
- highlightScope: highlightScope,
137
133
  slots: slots,
138
134
  slotProps: slotProps
139
135
  })
@@ -12,4 +12,4 @@ export interface ValueWithHighlight extends DefaultizedPieValueType, AnimatedObj
12
12
  isFaded: boolean;
13
13
  isHighlighted: boolean;
14
14
  }
15
- export declare function useTransformData(series: Pick<DefaultizedPieSeriesType, 'cornerRadius' | 'paddingAngle' | 'id' | 'highlightScope' | 'highlighted' | 'faded' | 'data'> & ComputedPieRadius): ValueWithHighlight[];
15
+ export declare function useTransformData(series: Pick<DefaultizedPieSeriesType, 'cornerRadius' | 'paddingAngle' | 'id' | 'highlighted' | 'faded' | 'data'> & ComputedPieRadius): ValueWithHighlight[];
@@ -7,14 +7,12 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.useTransformData = useTransformData;
8
8
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
9
  var React = _interopRequireWildcard(require("react"));
10
- var _InteractionProvider = require("../../context/InteractionProvider");
11
- var _useInteractionItemProps = require("../../hooks/useInteractionItemProps");
10
+ var _context = require("../../context");
12
11
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
13
12
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
14
13
  function useTransformData(series) {
15
14
  const {
16
15
  id: seriesId,
17
- highlightScope,
18
16
  data,
19
17
  faded,
20
18
  highlighted,
@@ -25,29 +23,16 @@ function useTransformData(series) {
25
23
  cornerRadius: baseCornerRadius = 0
26
24
  } = series;
27
25
  const {
28
- item: highlightedItem
29
- } = React.useContext(_InteractionProvider.InteractionContext);
30
- const getHighlightStatus = React.useCallback(dataIndex => {
31
- const isHighlighted = (0, _useInteractionItemProps.getIsHighlighted)(highlightedItem, {
32
- type: 'pie',
33
- seriesId,
34
- dataIndex
35
- }, highlightScope);
36
- const isFaded = !isHighlighted && (0, _useInteractionItemProps.getIsFaded)(highlightedItem, {
37
- type: 'pie',
26
+ isFaded: isItemFaded,
27
+ isHighlighted: isItemHighlighted
28
+ } = (0, _context.useHighlighted)();
29
+ const dataWithHighlight = React.useMemo(() => data.map((item, itemIndex) => {
30
+ const currentItem = {
38
31
  seriesId,
39
- dataIndex
40
- }, highlightScope);
41
- return {
42
- isHighlighted,
43
- isFaded
32
+ dataIndex: itemIndex
44
33
  };
45
- }, [highlightScope, highlightedItem, seriesId]);
46
- const dataWithHighlight = React.useMemo(() => data.map((item, itemIndex) => {
47
- const {
48
- isHighlighted,
49
- isFaded
50
- } = getHighlightStatus(itemIndex);
34
+ const isHighlighted = isItemHighlighted(currentItem);
35
+ const isFaded = !isHighlighted && isItemFaded(currentItem);
51
36
  const attributesOverride = (0, _extends2.default)({
52
37
  additionalRadius: 0
53
38
  }, isFaded && faded || isHighlighted && highlighted || {});
@@ -65,6 +50,6 @@ function useTransformData(series) {
65
50
  cornerRadius,
66
51
  arcLabelRadius
67
52
  });
68
- }), [baseCornerRadius, baseInnerRadius, baseOuterRadius, basePaddingAngle, baseArcLabelRadius, data, faded, getHighlightStatus, highlighted]);
53
+ }), [baseCornerRadius, baseInnerRadius, baseOuterRadius, basePaddingAngle, baseArcLabelRadius, data, faded, highlighted, isItemFaded, isItemHighlighted, seriesId]);
69
54
  return dataWithHighlight;
70
55
  }
@@ -83,6 +83,13 @@ process.env.NODE_ENV !== "production" ? ResponsiveChartContainer.propTypes = {
83
83
  * The height of the chart in px. If not defined, it takes the height of the parent element.
84
84
  */
85
85
  height: _propTypes.default.number,
86
+ /**
87
+ * The item currently highlighted. Turns highlighting into a controlled prop.
88
+ */
89
+ highlightedItem: _propTypes.default.shape({
90
+ dataIndex: _propTypes.default.number,
91
+ seriesId: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string])
92
+ }),
86
93
  /**
87
94
  * The margin between the SVG and the drawing area.
88
95
  * It's used for leaving some space for extra information such as the x- and y-axis or legend.
@@ -95,6 +102,12 @@ process.env.NODE_ENV !== "production" ? ResponsiveChartContainer.propTypes = {
95
102
  right: _propTypes.default.number,
96
103
  top: _propTypes.default.number
97
104
  }),
105
+ /**
106
+ * The callback fired when the highlighted item changes.
107
+ *
108
+ * @param {HighlightItemData | null} highlightedItem The newly highlighted item.
109
+ */
110
+ onHighlightChange: _propTypes.default.func,
98
111
  /**
99
112
  * The array of series to display.
100
113
  * Each type of series has its own specificity.
@@ -11,6 +11,7 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
11
11
  var _useScale = require("../hooks/useScale");
12
12
  var _useInteractionItemProps = require("../hooks/useInteractionItemProps");
13
13
  var _InteractionProvider = require("../context/InteractionProvider");
14
+ var _context = require("../context");
14
15
  var _jsxRuntime = require("react/jsx-runtime");
15
16
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
16
17
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
@@ -34,16 +35,15 @@ function Scatter(props) {
34
35
  markerSize,
35
36
  onItemClick
36
37
  } = props;
37
- const highlightScope = React.useMemo(() => (0, _extends2.default)({
38
- highlighted: 'item',
39
- faded: 'global'
40
- }, series.highlightScope), [series.highlightScope]);
41
38
  const {
42
- item,
43
39
  useVoronoiInteraction
44
40
  } = React.useContext(_InteractionProvider.InteractionContext);
45
41
  const skipInteractionHandlers = useVoronoiInteraction || series.disableHover;
46
- const getInteractionItemProps = (0, _useInteractionItemProps.useInteractionItemProps)(highlightScope, skipInteractionHandlers);
42
+ const getInteractionItemProps = (0, _useInteractionItemProps.useInteractionItemProps)(skipInteractionHandlers);
43
+ const {
44
+ isFaded,
45
+ isHighlighted
46
+ } = (0, _context.useHighlighted)();
47
47
  const cleanData = React.useMemo(() => {
48
48
  const getXPosition = (0, _useScale.getValueToPositionMapper)(xScale);
49
49
  const getYPosition = (0, _useScale.getValueToPositionMapper)(yScale);
@@ -65,12 +65,16 @@ function Scatter(props) {
65
65
  dataIndex: i
66
66
  };
67
67
  if (isInRange) {
68
- const isHighlighted = (0, _useInteractionItemProps.getIsHighlighted)(item, pointCtx, highlightScope);
68
+ const currentItem = {
69
+ seriesId: pointCtx.seriesId,
70
+ dataIndex: pointCtx.dataIndex
71
+ };
72
+ const isItemHighlighted = isHighlighted(currentItem);
69
73
  temp.push({
70
74
  x,
71
75
  y,
72
- isHighlighted,
73
- isFaded: !isHighlighted && (0, _useInteractionItemProps.getIsFaded)(item, pointCtx, highlightScope),
76
+ isHighlighted: isItemHighlighted,
77
+ isFaded: !isItemHighlighted && isFaded(currentItem),
74
78
  interactionProps: getInteractionItemProps(pointCtx),
75
79
  id: scatterPoint.id,
76
80
  dataIndex: i,
@@ -79,7 +83,7 @@ function Scatter(props) {
79
83
  }
80
84
  }
81
85
  return temp;
82
- }, [xScale, yScale, series.data, series.id, item, highlightScope, getInteractionItemProps, color, colorGetter]);
86
+ }, [xScale, yScale, series.data, series.id, getInteractionItemProps, color, colorGetter, isFaded, isHighlighted]);
83
87
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("g", {
84
88
  children: cleanData.map(dataPoint => /*#__PURE__*/(0, _jsxRuntime.jsx)("circle", (0, _extends2.default)({
85
89
  cx: 0,