@mui/x-charts 7.0.0-beta.0 → 7.0.0-beta.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 (185) hide show
  1. package/BarChart/BarChart.d.ts +2 -1
  2. package/BarChart/BarChart.js +23 -4
  3. package/BarChart/BarElement.d.ts +1 -1
  4. package/BarChart/BarElement.js +6 -3
  5. package/BarChart/BarPlot.d.ts +8 -1
  6. package/BarChart/BarPlot.js +19 -5
  7. package/BarChart/formatter.js +1 -1
  8. package/CHANGELOG.md +247 -0
  9. package/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.d.ts +20 -0
  10. package/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +83 -0
  11. package/ChartsOnAxisClickHandler/index.d.ts +1 -0
  12. package/ChartsOnAxisClickHandler/index.js +16 -0
  13. package/ChartsOnAxisClickHandler/package.json +6 -0
  14. package/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
  15. package/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
  16. package/ChartsTooltip/ChartsAxisTooltipContent.js +6 -5
  17. package/ChartsTooltip/DefaultChartsAxisTooltipContent.js +6 -4
  18. package/ChartsTooltip/utils.d.ts +3 -1
  19. package/ChartsTooltip/utils.js +8 -0
  20. package/ChartsVoronoiHandler/ChartsVoronoiHandler.d.ts +7 -0
  21. package/ChartsVoronoiHandler/ChartsVoronoiHandler.js +92 -44
  22. package/LineChart/AnimatedArea.d.ts +1361 -0
  23. package/LineChart/AnimatedArea.js +111 -0
  24. package/LineChart/AnimatedLine.d.ts +1361 -0
  25. package/LineChart/AnimatedLine.js +113 -0
  26. package/LineChart/AreaElement.d.ts +17 -17
  27. package/LineChart/AreaElement.js +17 -34
  28. package/LineChart/AreaPlot.d.ts +12 -7
  29. package/LineChart/AreaPlot.js +91 -58
  30. package/LineChart/LineChart.d.ts +13 -4
  31. package/LineChart/LineChart.js +35 -6
  32. package/LineChart/LineElement.d.ts +17 -17
  33. package/LineChart/LineElement.js +16 -36
  34. package/LineChart/LineHighlightElement.js +3 -2
  35. package/LineChart/LinePlot.d.ts +12 -7
  36. package/LineChart/LinePlot.js +89 -56
  37. package/LineChart/MarkElement.d.ts +5 -2
  38. package/LineChart/MarkElement.js +26 -13
  39. package/LineChart/MarkPlot.d.ts +8 -1
  40. package/LineChart/MarkPlot.js +80 -51
  41. package/LineChart/formatter.js +1 -1
  42. package/LineChart/index.d.ts +2 -0
  43. package/LineChart/index.js +22 -0
  44. package/PieChart/PieArcLabelPlot.d.ts +1 -1
  45. package/PieChart/PieArcLabelPlot.js +1 -1
  46. package/PieChart/PieArcPlot.d.ts +2 -2
  47. package/PieChart/PieArcPlot.js +6 -6
  48. package/PieChart/PieChart.d.ts +1 -1
  49. package/PieChart/PieChart.js +4 -4
  50. package/PieChart/PiePlot.d.ts +1 -1
  51. package/PieChart/PiePlot.js +4 -4
  52. package/ScatterChart/Scatter.d.ts +7 -1
  53. package/ScatterChart/Scatter.js +17 -3
  54. package/ScatterChart/ScatterChart.d.ts +8 -2
  55. package/ScatterChart/ScatterChart.js +11 -2
  56. package/ScatterChart/ScatterPlot.d.ts +1 -1
  57. package/ScatterChart/ScatterPlot.js +10 -2
  58. package/SparkLineChart/SparkLineChart.js +2 -0
  59. package/context/DrawingProvider.d.ts +6 -1
  60. package/context/DrawingProvider.js +9 -2
  61. package/context/InteractionProvider.d.ts +3 -3
  62. package/esm/BarChart/BarChart.js +23 -4
  63. package/esm/BarChart/BarElement.js +6 -3
  64. package/esm/BarChart/BarPlot.js +19 -5
  65. package/esm/BarChart/formatter.js +1 -1
  66. package/esm/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +77 -0
  67. package/esm/ChartsOnAxisClickHandler/index.js +1 -0
  68. package/esm/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
  69. package/esm/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
  70. package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +6 -5
  71. package/esm/ChartsTooltip/DefaultChartsAxisTooltipContent.js +7 -4
  72. package/esm/ChartsTooltip/utils.js +6 -0
  73. package/esm/ChartsVoronoiHandler/ChartsVoronoiHandler.js +92 -44
  74. package/esm/LineChart/AnimatedArea.js +103 -0
  75. package/esm/LineChart/AnimatedLine.js +105 -0
  76. package/esm/LineChart/AreaElement.js +16 -33
  77. package/esm/LineChart/AreaPlot.js +92 -59
  78. package/esm/LineChart/LineChart.js +35 -6
  79. package/esm/LineChart/LineElement.js +16 -35
  80. package/esm/LineChart/LineHighlightElement.js +3 -2
  81. package/esm/LineChart/LinePlot.js +90 -57
  82. package/esm/LineChart/MarkElement.js +26 -13
  83. package/esm/LineChart/MarkPlot.js +80 -51
  84. package/esm/LineChart/formatter.js +1 -1
  85. package/esm/LineChart/index.js +2 -0
  86. package/esm/PieChart/PieArcLabelPlot.js +1 -1
  87. package/esm/PieChart/PieArcPlot.js +6 -6
  88. package/esm/PieChart/PieChart.js +4 -4
  89. package/esm/PieChart/PiePlot.js +4 -4
  90. package/esm/ScatterChart/Scatter.js +17 -3
  91. package/esm/ScatterChart/ScatterChart.js +11 -2
  92. package/esm/ScatterChart/ScatterPlot.js +10 -2
  93. package/esm/SparkLineChart/SparkLineChart.js +2 -0
  94. package/esm/context/DrawingProvider.js +9 -2
  95. package/esm/hooks/useDrawingArea.js +7 -3
  96. package/esm/index.js +1 -0
  97. package/esm/internals/geometry.js +1 -1
  98. package/esm/internals/useAnimatedPath.js +29 -0
  99. package/esm/internals/utils.js +7 -0
  100. package/hooks/useDrawingArea.d.ts +2 -0
  101. package/hooks/useDrawingArea.js +7 -3
  102. package/index.d.ts +1 -0
  103. package/index.js +12 -1
  104. package/internals/geometry.js +1 -1
  105. package/internals/useAnimatedPath.d.ts +1 -0
  106. package/internals/useAnimatedPath.js +38 -0
  107. package/internals/utils.d.ts +4 -0
  108. package/internals/utils.js +8 -0
  109. package/legacy/BarChart/BarChart.js +23 -4
  110. package/legacy/BarChart/BarElement.js +5 -2
  111. package/legacy/BarChart/BarPlot.js +18 -4
  112. package/legacy/BarChart/formatter.js +1 -1
  113. package/legacy/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +75 -0
  114. package/legacy/ChartsOnAxisClickHandler/index.js +1 -0
  115. package/legacy/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
  116. package/legacy/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
  117. package/legacy/ChartsTooltip/ChartsAxisTooltipContent.js +6 -7
  118. package/legacy/ChartsTooltip/DefaultChartsAxisTooltipContent.js +7 -4
  119. package/legacy/ChartsTooltip/utils.js +6 -0
  120. package/legacy/ChartsVoronoiHandler/ChartsVoronoiHandler.js +88 -44
  121. package/legacy/LineChart/AnimatedArea.js +102 -0
  122. package/legacy/LineChart/AnimatedLine.js +104 -0
  123. package/legacy/LineChart/AreaElement.js +15 -35
  124. package/legacy/LineChart/AreaPlot.js +102 -66
  125. package/legacy/LineChart/LineChart.js +35 -6
  126. package/legacy/LineChart/LineElement.js +15 -37
  127. package/legacy/LineChart/LineHighlightElement.js +3 -2
  128. package/legacy/LineChart/LinePlot.js +97 -63
  129. package/legacy/LineChart/MarkElement.js +29 -12
  130. package/legacy/LineChart/MarkPlot.js +83 -53
  131. package/legacy/LineChart/formatter.js +1 -1
  132. package/legacy/LineChart/index.js +2 -0
  133. package/legacy/PieChart/PieArcLabelPlot.js +1 -1
  134. package/legacy/PieChart/PieArcPlot.js +6 -6
  135. package/legacy/PieChart/PieChart.js +4 -4
  136. package/legacy/PieChart/PiePlot.js +4 -4
  137. package/legacy/ScatterChart/Scatter.js +19 -3
  138. package/legacy/ScatterChart/ScatterChart.js +11 -2
  139. package/legacy/ScatterChart/ScatterPlot.js +10 -2
  140. package/legacy/SparkLineChart/SparkLineChart.js +2 -0
  141. package/legacy/context/DrawingProvider.js +11 -2
  142. package/legacy/hooks/useDrawingArea.js +7 -3
  143. package/legacy/index.js +2 -1
  144. package/legacy/internals/geometry.js +1 -1
  145. package/legacy/internals/useAnimatedPath.js +32 -0
  146. package/legacy/internals/utils.js +7 -0
  147. package/modern/BarChart/BarChart.js +23 -4
  148. package/modern/BarChart/BarElement.js +6 -3
  149. package/modern/BarChart/BarPlot.js +19 -5
  150. package/modern/BarChart/formatter.js +1 -1
  151. package/modern/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +75 -0
  152. package/modern/ChartsOnAxisClickHandler/index.js +1 -0
  153. package/modern/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
  154. package/modern/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
  155. package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +6 -5
  156. package/modern/ChartsTooltip/DefaultChartsAxisTooltipContent.js +6 -4
  157. package/modern/ChartsTooltip/utils.js +6 -0
  158. package/modern/ChartsVoronoiHandler/ChartsVoronoiHandler.js +92 -44
  159. package/modern/LineChart/AnimatedArea.js +103 -0
  160. package/modern/LineChart/AnimatedLine.js +105 -0
  161. package/modern/LineChart/AreaElement.js +16 -33
  162. package/modern/LineChart/AreaPlot.js +91 -58
  163. package/modern/LineChart/LineChart.js +35 -6
  164. package/modern/LineChart/LineElement.js +16 -35
  165. package/modern/LineChart/LineHighlightElement.js +3 -2
  166. package/modern/LineChart/LinePlot.js +89 -56
  167. package/modern/LineChart/MarkElement.js +26 -13
  168. package/modern/LineChart/MarkPlot.js +80 -51
  169. package/modern/LineChart/formatter.js +1 -1
  170. package/modern/LineChart/index.js +2 -0
  171. package/modern/PieChart/PieArcLabelPlot.js +1 -1
  172. package/modern/PieChart/PieArcPlot.js +6 -6
  173. package/modern/PieChart/PieChart.js +4 -4
  174. package/modern/PieChart/PiePlot.js +4 -4
  175. package/modern/ScatterChart/Scatter.js +17 -3
  176. package/modern/ScatterChart/ScatterChart.js +11 -2
  177. package/modern/ScatterChart/ScatterPlot.js +10 -2
  178. package/modern/SparkLineChart/SparkLineChart.js +2 -0
  179. package/modern/context/DrawingProvider.js +9 -2
  180. package/modern/hooks/useDrawingArea.js +7 -3
  181. package/modern/index.js +2 -1
  182. package/modern/internals/geometry.js +1 -1
  183. package/modern/internals/useAnimatedPath.js +29 -0
  184. package/modern/internals/utils.js +7 -0
  185. package/package.json +6 -5
@@ -59,7 +59,7 @@ function PieChart(props) {
59
59
  children,
60
60
  slots,
61
61
  slotProps,
62
- onClick
62
+ onItemClick
63
63
  } = props;
64
64
  const margin = _extends({}, defaultMargin, marginProps);
65
65
  return /*#__PURE__*/_jsxs(ResponsiveChartContainer, {
@@ -88,7 +88,7 @@ function PieChart(props) {
88
88
  }), /*#__PURE__*/_jsx(PiePlot, {
89
89
  slots: slots,
90
90
  slotProps: slotProps,
91
- onClick: onClick,
91
+ onItemClick: onItemClick,
92
92
  skipAnimation: skipAnimation
93
93
  }), /*#__PURE__*/_jsx(ChartsLegend, _extends({}, legend, {
94
94
  slots: slots,
@@ -208,7 +208,7 @@ process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
208
208
  right: PropTypes.number,
209
209
  top: PropTypes.number
210
210
  }),
211
- onClick: PropTypes.func,
211
+ onItemClick: PropTypes.func,
212
212
  /**
213
213
  * Indicate which axis to display the right of the charts.
214
214
  * Can be a string (the id of the axis) or an object `ChartsYAxisProps`.
@@ -238,7 +238,7 @@ process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
238
238
  }), PropTypes.string]),
239
239
  series: PropTypes.arrayOf(PropTypes.object).isRequired,
240
240
  /**
241
- * If `true`, animations are skiped.
241
+ * If `true`, animations are skipped.
242
242
  * @default false
243
243
  */
244
244
  skipAnimation: PropTypes.bool,
@@ -22,7 +22,7 @@ function PiePlot(props) {
22
22
  skipAnimation,
23
23
  slots,
24
24
  slotProps,
25
- onClick
25
+ onItemClick
26
26
  } = props;
27
27
  const seriesData = React.useContext(SeriesContext).pie;
28
28
  const {
@@ -70,7 +70,7 @@ function PiePlot(props) {
70
70
  highlightScope: highlightScope,
71
71
  highlighted: highlighted,
72
72
  faded: faded,
73
- onClick: onClick,
73
+ onItemClick: onItemClick,
74
74
  slots: slots,
75
75
  slotProps: slotProps
76
76
  })
@@ -124,9 +124,9 @@ process.env.NODE_ENV !== "production" ? PiePlot.propTypes = {
124
124
  * @param {PieItemIdentifier} pieItemIdentifier The pie item identifier.
125
125
  * @param {DefaultizedPieValueType} item The pie item.
126
126
  */
127
- onClick: PropTypes.func,
127
+ onItemClick: PropTypes.func,
128
128
  /**
129
- * If `true`, animations are skiped.
129
+ * If `true`, animations are skipped.
130
130
  * @default false
131
131
  */
132
132
  skipAnimation: PropTypes.bool,
@@ -21,7 +21,8 @@ function Scatter(props) {
21
21
  xScale,
22
22
  yScale,
23
23
  color,
24
- markerSize
24
+ markerSize,
25
+ onItemClick
25
26
  } = props;
26
27
  const highlightScope = React.useMemo(() => _extends({
27
28
  highlighted: 'item',
@@ -61,7 +62,8 @@ function Scatter(props) {
61
62
  isHighlighted,
62
63
  isFaded: !isHighlighted && getIsFaded(item, pointCtx, highlightScope),
63
64
  interactionProps: getInteractionItemProps(pointCtx),
64
- id: scatterPoint.id
65
+ id: scatterPoint.id,
66
+ dataIndex: i
65
67
  });
66
68
  }
67
69
  }
@@ -74,7 +76,13 @@ function Scatter(props) {
74
76
  r: (dataPoint.isHighlighted ? 1.2 : 1) * markerSize,
75
77
  transform: `translate(${dataPoint.x}, ${dataPoint.y})`,
76
78
  fill: color,
77
- opacity: dataPoint.isFaded && 0.3 || 1
79
+ opacity: dataPoint.isFaded && 0.3 || 1,
80
+ onClick: onItemClick && (event => onItemClick(event, {
81
+ type: 'scatter',
82
+ seriesId: series.id,
83
+ dataIndex: dataPoint.dataIndex
84
+ })),
85
+ cursor: onItemClick ? 'pointer' : 'unset'
78
86
  }, dataPoint.interactionProps), dataPoint.id))
79
87
  });
80
88
  }
@@ -85,6 +93,12 @@ process.env.NODE_ENV !== "production" ? Scatter.propTypes = {
85
93
  // ----------------------------------------------------------------------
86
94
  color: PropTypes.string.isRequired,
87
95
  markerSize: PropTypes.number.isRequired,
96
+ /**
97
+ * Callback fired when clicking on a scatter item.
98
+ * @param {MouseEvent} event Mouse event recorded on the `<svg/>` element.
99
+ * @param {ScatterItemIdentifier} scatterItemIdentifier The scatter item identifier.
100
+ */
101
+ onItemClick: PropTypes.func,
88
102
  series: PropTypes.object.isRequired,
89
103
  xScale: PropTypes.func.isRequired,
90
104
  yScale: PropTypes.func.isRequired
@@ -39,6 +39,7 @@ const ScatterChart = /*#__PURE__*/React.forwardRef(function ScatterChart(props,
39
39
  leftAxis,
40
40
  rightAxis,
41
41
  bottomAxis,
42
+ onItemClick,
42
43
  children,
43
44
  slots,
44
45
  slotProps
@@ -56,7 +57,8 @@ const ScatterChart = /*#__PURE__*/React.forwardRef(function ScatterChart(props,
56
57
  yAxis: yAxis,
57
58
  sx: sx,
58
59
  children: [!disableVoronoi && /*#__PURE__*/_jsx(ChartsVoronoiHandler, {
59
- voronoiMaxRadius: voronoiMaxRadius
60
+ voronoiMaxRadius: voronoiMaxRadius,
61
+ onItemClick: onItemClick
60
62
  }), /*#__PURE__*/_jsx(ChartsAxis, {
61
63
  topAxis: topAxis,
62
64
  leftAxis: leftAxis,
@@ -66,7 +68,8 @@ const ScatterChart = /*#__PURE__*/React.forwardRef(function ScatterChart(props,
66
68
  slotProps: slotProps
67
69
  }), /*#__PURE__*/_jsx(ScatterPlot, {
68
70
  slots: slots,
69
- slotProps: slotProps
71
+ slotProps: slotProps,
72
+ onItemClick: disableVoronoi ? onItemClick : undefined
70
73
  }), /*#__PURE__*/_jsx(ChartsLegend, _extends({}, legend, {
71
74
  slots: slots,
72
75
  slotProps: slotProps
@@ -195,6 +198,12 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
195
198
  right: PropTypes.number,
196
199
  top: PropTypes.number
197
200
  }),
201
+ /**
202
+ * Callback fired when clicking on a scatter item.
203
+ * @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`.
204
+ * @param {ScatterItemIdentifier} scatterItemIdentifier The scatter item identifier.
205
+ */
206
+ onItemClick: PropTypes.func,
198
207
  /**
199
208
  * Indicate which axis to display the right of the charts.
200
209
  * Can be a string (the id of the axis) or an object `ChartsYAxisProps`.
@@ -19,7 +19,8 @@ function ScatterPlot(props) {
19
19
  var _slots$scatter;
20
20
  const {
21
21
  slots,
22
- slotProps
22
+ slotProps,
23
+ onItemClick
23
24
  } = props;
24
25
  const seriesData = React.useContext(SeriesContext).scatter;
25
26
  const axisData = React.useContext(CartesianContext);
@@ -55,7 +56,8 @@ function ScatterPlot(props) {
55
56
  yScale: yScale,
56
57
  color: color,
57
58
  markerSize: markerSize != null ? markerSize : 4,
58
- series: series[seriesId]
59
+ series: series[seriesId],
60
+ onItemClick: onItemClick
59
61
  }, slotProps == null ? void 0 : slotProps.scatter), id);
60
62
  })
61
63
  });
@@ -65,6 +67,12 @@ process.env.NODE_ENV !== "production" ? ScatterPlot.propTypes = {
65
67
  // | These PropTypes are generated from the TypeScript type definitions |
66
68
  // | To update them edit the TypeScript types and run "yarn proptypes" |
67
69
  // ----------------------------------------------------------------------
70
+ /**
71
+ * Callback fired when clicking on a scatter item.
72
+ * @param {MouseEvent} event Mouse event recorded on the `<svg/>` element.
73
+ * @param {ScatterItemIdentifier} scatterItemIdentifier The scatter item identifier.
74
+ */
75
+ onItemClick: PropTypes.func,
68
76
  /**
69
77
  * The props used for each component slot.
70
78
  * @default {}
@@ -86,9 +86,11 @@ const SparkLineChart = /*#__PURE__*/React.forwardRef(function SparkLineChart(pro
86
86
  }
87
87
  }), plotType === 'line' && /*#__PURE__*/_jsxs(React.Fragment, {
88
88
  children: [/*#__PURE__*/_jsx(AreaPlot, {
89
+ skipAnimation: true,
89
90
  slots: slots,
90
91
  slotProps: slotProps
91
92
  }), /*#__PURE__*/_jsx(LinePlot, {
93
+ skipAnimation: true,
92
94
  slots: slots,
93
95
  slotProps: slotProps
94
96
  }), /*#__PURE__*/_jsx(LineHighlightPlot, {
@@ -1,5 +1,7 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
1
2
  import * as React from 'react';
2
3
  import PropTypes from 'prop-types';
4
+ import useId from '@mui/utils/useId';
3
5
  import useChartDimensions from '../hooks/useChartDimensions';
4
6
 
5
7
  /**
@@ -12,7 +14,8 @@ export const DrawingContext = /*#__PURE__*/React.createContext({
12
14
  bottom: 0,
13
15
  right: 0,
14
16
  height: 300,
15
- width: 400
17
+ width: 400,
18
+ chartId: ''
16
19
  });
17
20
  export const SVGContext = /*#__PURE__*/React.createContext({
18
21
  current: null
@@ -32,10 +35,14 @@ function DrawingProvider(props) {
32
35
  children
33
36
  } = props;
34
37
  const drawingArea = useChartDimensions(width, height, margin);
38
+ const chartId = useId();
39
+ const value = React.useMemo(() => _extends({
40
+ chartId: chartId != null ? chartId : ''
41
+ }, drawingArea), [chartId, drawingArea]);
35
42
  return /*#__PURE__*/_jsx(SVGContext.Provider, {
36
43
  value: svgRef,
37
44
  children: /*#__PURE__*/_jsx(DrawingContext.Provider, {
38
- value: drawingArea,
45
+ value: value,
39
46
  children: children
40
47
  })
41
48
  });
@@ -5,12 +5,16 @@ export function useDrawingArea() {
5
5
  left,
6
6
  top,
7
7
  width,
8
- height
8
+ height,
9
+ bottom,
10
+ right
9
11
  } = React.useContext(DrawingContext);
10
12
  return React.useMemo(() => ({
11
13
  left,
12
14
  top,
13
15
  width,
14
- height
15
- }), [height, left, top, width]);
16
+ height,
17
+ bottom,
18
+ right
19
+ }), [height, left, top, width, bottom, right]);
16
20
  }
package/esm/index.js CHANGED
@@ -13,6 +13,7 @@ export * from './ChartsTooltip';
13
13
  export * from './ChartsLegend';
14
14
  export * from './ChartsAxisHighlight';
15
15
  export * from './ChartsVoronoiHandler';
16
+ export * from './ChartsOnAxisClickHandler';
16
17
  export * from './BarChart';
17
18
  export * from './LineChart';
18
19
  export * from './PieChart';
@@ -14,7 +14,7 @@ export function getMinXTranslation(width, height, angle = 0) {
14
14
  if (process.env.NODE_ENV !== 'production') {
15
15
  if (!warnedOnce && angle > 90 && angle < -90) {
16
16
  warnedOnce = true;
17
- console.warn([`MUI X: It seems you applied an angle larger than 90° or smaller than -90° to an axis text.`, `This could cause some text overlapping.`, `If you encounter a use case where it's needed, please open an issue.`].join('\n'));
17
+ console.warn([`MUI X Charts: It seems you applied an angle larger than 90° or smaller than -90° to an axis text.`, `This could cause some text overlapping.`, `If you encounter a use case where it's needed, please open an issue.`].join('\n'));
18
18
  }
19
19
  }
20
20
  const standardAngle = Math.min(Math.abs(angle) % 180, Math.abs(Math.abs(angle) % 180 - 180) % 180); // Map from R to [0, 90]
@@ -0,0 +1,29 @@
1
+ import * as React from 'react';
2
+ import { interpolateString } from 'd3-interpolate';
3
+ import { useSpring, to } from '@react-spring/web';
4
+ function usePrevious(value) {
5
+ const ref = React.useRef(null);
6
+ React.useEffect(() => {
7
+ ref.current = value;
8
+ }, [value]);
9
+ return ref.current;
10
+ }
11
+
12
+ // Taken from Nivo
13
+ export const useAnimatedPath = (path, skipAnimation) => {
14
+ const previousPath = usePrevious(path);
15
+ const interpolator = React.useMemo(() => previousPath ? interpolateString(previousPath, path) : () => path, [previousPath, path]);
16
+ const {
17
+ value
18
+ } = useSpring({
19
+ from: {
20
+ value: 0
21
+ },
22
+ to: {
23
+ value: 1
24
+ },
25
+ reset: true,
26
+ immediate: skipAnimation
27
+ });
28
+ return to([value], interpolator);
29
+ };
@@ -42,4 +42,11 @@ export function getPercentageValue(value, refValue) {
42
42
  }
43
43
  }
44
44
  throw Error(`MUI-Charts: Received an unknown value "${value}". It should be a number, or a string with a percentage value.`);
45
+ }
46
+
47
+ /**
48
+ * Remove spaces to have viable ids
49
+ */
50
+ export function cleanId(id) {
51
+ return id.replace(' ', '_');
45
52
  }
@@ -3,4 +3,6 @@ export declare function useDrawingArea(): {
3
3
  top: number;
4
4
  width: number;
5
5
  height: number;
6
+ bottom: number;
7
+ right: number;
6
8
  };
@@ -13,12 +13,16 @@ function useDrawingArea() {
13
13
  left,
14
14
  top,
15
15
  width,
16
- height
16
+ height,
17
+ bottom,
18
+ right
17
19
  } = React.useContext(_DrawingProvider.DrawingContext);
18
20
  return React.useMemo(() => ({
19
21
  left,
20
22
  top,
21
23
  width,
22
- height
23
- }), [height, left, top, width]);
24
+ height,
25
+ bottom,
26
+ right
27
+ }), [height, left, top, width, bottom, right]);
24
28
  }
package/index.d.ts CHANGED
@@ -13,6 +13,7 @@ export * from './ChartsTooltip';
13
13
  export * from './ChartsLegend';
14
14
  export * from './ChartsAxisHighlight';
15
15
  export * from './ChartsVoronoiHandler';
16
+ export * from './ChartsOnAxisClickHandler';
16
17
  export * from './BarChart';
17
18
  export * from './LineChart';
18
19
  export * from './PieChart';
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-charts v7.0.0-beta.0
2
+ * @mui/x-charts v7.0.0-beta.1
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
@@ -175,6 +175,17 @@ Object.keys(_ChartsVoronoiHandler).forEach(function (key) {
175
175
  }
176
176
  });
177
177
  });
178
+ var _ChartsOnAxisClickHandler = require("./ChartsOnAxisClickHandler");
179
+ Object.keys(_ChartsOnAxisClickHandler).forEach(function (key) {
180
+ if (key === "default" || key === "__esModule") return;
181
+ if (key in exports && exports[key] === _ChartsOnAxisClickHandler[key]) return;
182
+ Object.defineProperty(exports, key, {
183
+ enumerable: true,
184
+ get: function () {
185
+ return _ChartsOnAxisClickHandler[key];
186
+ }
187
+ });
188
+ });
178
189
  var _BarChart = require("./BarChart");
179
190
  Object.keys(_BarChart).forEach(function (key) {
180
191
  if (key === "default" || key === "__esModule") return;
@@ -20,7 +20,7 @@ function getMinXTranslation(width, height, angle = 0) {
20
20
  if (process.env.NODE_ENV !== 'production') {
21
21
  if (!warnedOnce && angle > 90 && angle < -90) {
22
22
  warnedOnce = true;
23
- console.warn([`MUI X: It seems you applied an angle larger than 90° or smaller than -90° to an axis text.`, `This could cause some text overlapping.`, `If you encounter a use case where it's needed, please open an issue.`].join('\n'));
23
+ console.warn([`MUI X Charts: It seems you applied an angle larger than 90° or smaller than -90° to an axis text.`, `This could cause some text overlapping.`, `If you encounter a use case where it's needed, please open an issue.`].join('\n'));
24
24
  }
25
25
  }
26
26
  const standardAngle = Math.min(Math.abs(angle) % 180, Math.abs(Math.abs(angle) % 180 - 180) % 180); // Map from R to [0, 90]
@@ -0,0 +1 @@
1
+ export declare const useAnimatedPath: (path: string, skipAnimation?: boolean) => import("@react-spring/core").Interpolation<string, any>;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useAnimatedPath = void 0;
7
+ var React = _interopRequireWildcard(require("react"));
8
+ var _d3Interpolate = require("d3-interpolate");
9
+ var _web = require("@react-spring/web");
10
+ 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); }
11
+ 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 && Object.prototype.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; }
12
+ function usePrevious(value) {
13
+ const ref = React.useRef(null);
14
+ React.useEffect(() => {
15
+ ref.current = value;
16
+ }, [value]);
17
+ return ref.current;
18
+ }
19
+
20
+ // Taken from Nivo
21
+ const useAnimatedPath = (path, skipAnimation) => {
22
+ const previousPath = usePrevious(path);
23
+ const interpolator = React.useMemo(() => previousPath ? (0, _d3Interpolate.interpolateString)(previousPath, path) : () => path, [previousPath, path]);
24
+ const {
25
+ value
26
+ } = (0, _web.useSpring)({
27
+ from: {
28
+ value: 0
29
+ },
30
+ to: {
31
+ value: 1
32
+ },
33
+ reset: true,
34
+ immediate: skipAnimation
35
+ });
36
+ return (0, _web.to)([value], interpolator);
37
+ };
38
+ exports.useAnimatedPath = useAnimatedPath;
@@ -17,4 +17,8 @@ export declare function getSVGPoint(svg: SVGSVGElement, event: MouseEvent): DOMP
17
17
  * @returns The numerical value associated to the provided value.
18
18
  */
19
19
  export declare function getPercentageValue(value: number | string, refValue: number): number;
20
+ /**
21
+ * Remove spaces to have viable ids
22
+ */
23
+ export declare function cleanId(id: string): string;
20
24
  export {};
@@ -3,6 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.cleanId = cleanId;
6
7
  exports.getPercentageValue = getPercentageValue;
7
8
  exports.getSVGPoint = getSVGPoint;
8
9
  exports.getSymbol = getSymbol;
@@ -50,4 +51,11 @@ function getPercentageValue(value, refValue) {
50
51
  }
51
52
  }
52
53
  throw Error(`MUI-Charts: Received an unknown value "${value}". It should be a number, or a string with a percentage value.`);
54
+ }
55
+
56
+ /**
57
+ * Remove spaces to have viable ids
58
+ */
59
+ function cleanId(id) {
60
+ return id.replace(' ', '_');
53
61
  }
@@ -11,6 +11,7 @@ import { ChartsTooltip } from '../ChartsTooltip';
11
11
  import { ChartsLegend } from '../ChartsLegend';
12
12
  import { ChartsAxisHighlight } from '../ChartsAxisHighlight';
13
13
  import { ChartsClipPath } from '../ChartsClipPath';
14
+ import { ChartsOnAxisClickHandler } from '../ChartsOnAxisClickHandler';
14
15
  import { jsx as _jsx } from "react/jsx-runtime";
15
16
  import { jsxs as _jsxs } from "react/jsx-runtime";
16
17
  /**
@@ -43,6 +44,8 @@ var BarChart = /*#__PURE__*/React.forwardRef(function BarChart(props, ref) {
43
44
  rightAxis = props.rightAxis,
44
45
  bottomAxis = props.bottomAxis,
45
46
  skipAnimation = props.skipAnimation,
47
+ onItemClick = props.onItemClick,
48
+ onAxisClick = props.onAxisClick,
46
49
  children = props.children,
47
50
  slots = props.slots,
48
51
  slotProps = props.slotProps;
@@ -88,13 +91,16 @@ var BarChart = /*#__PURE__*/React.forwardRef(function BarChart(props, ref) {
88
91
  colors: colors,
89
92
  dataset: dataset,
90
93
  sx: sx,
91
- disableAxisListener: (tooltip == null ? void 0 : tooltip.trigger) !== 'axis' && (axisHighlight == null ? void 0 : axisHighlight.x) === 'none' && (axisHighlight == null ? void 0 : axisHighlight.y) === 'none',
92
- children: [/*#__PURE__*/_jsx("g", {
94
+ disableAxisListener: (tooltip == null ? void 0 : tooltip.trigger) !== 'axis' && (axisHighlight == null ? void 0 : axisHighlight.x) === 'none' && (axisHighlight == null ? void 0 : axisHighlight.y) === 'none' && !onAxisClick,
95
+ children: [onAxisClick && /*#__PURE__*/_jsx(ChartsOnAxisClickHandler, {
96
+ onAxisClick: onAxisClick
97
+ }), /*#__PURE__*/_jsx("g", {
93
98
  clipPath: "url(#".concat(clipPathId, ")"),
94
99
  children: /*#__PURE__*/_jsx(BarPlot, {
95
100
  slots: slots,
96
101
  slotProps: slotProps,
97
- skipAnimation: skipAnimation
102
+ skipAnimation: skipAnimation,
103
+ onItemClick: onItemClick
98
104
  })
99
105
  }), /*#__PURE__*/_jsx(ChartsAxis, {
100
106
  topAxis: topAxis,
@@ -234,6 +240,19 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
234
240
  right: PropTypes.number,
235
241
  top: PropTypes.number
236
242
  }),
243
+ /**
244
+ * The function called for onClick events.
245
+ * The second argument contains information about all line/bar elements at the current mouse position.
246
+ * @param {MouseEvent} event The mouse event recorded on the `<svg/>` element.
247
+ * @param {null | AxisData} data The data about the clicked axis and items associated with it.
248
+ */
249
+ onAxisClick: PropTypes.func,
250
+ /**
251
+ * Callback fired when a bar item is clicked.
252
+ * @param {React.MouseEvent<SVGElement, MouseEvent>} event The event source of the callback.
253
+ * @param {BarItemIdentifier} barItemIdentifier The bar item identifier.
254
+ */
255
+ onItemClick: PropTypes.func,
237
256
  /**
238
257
  * Indicate which axis to display the right of the charts.
239
258
  * Can be a string (the id of the axis) or an object `ChartsYAxisProps`.
@@ -263,7 +282,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
263
282
  }), PropTypes.string]),
264
283
  series: PropTypes.arrayOf(PropTypes.object).isRequired,
265
284
  /**
266
- * If `true`, animations are skiped.
285
+ * If `true`, animations are skipped.
267
286
  * @default false
268
287
  */
269
288
  skipAnimation: PropTypes.bool,
@@ -1,6 +1,6 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
3
- var _excluded = ["id", "dataIndex", "classes", "color", "highlightScope", "slots", "slotProps", "style"];
3
+ var _excluded = ["id", "dataIndex", "classes", "color", "highlightScope", "slots", "slotProps", "style", "onClick"];
4
4
  import * as React from 'react';
5
5
  import PropTypes from 'prop-types';
6
6
  import composeClasses from '@mui/utils/composeClasses';
@@ -51,6 +51,7 @@ function BarElement(props) {
51
51
  slots = props.slots,
52
52
  slotProps = props.slotProps,
53
53
  style = props.style,
54
+ onClick = props.onClick,
54
55
  other = _objectWithoutProperties(props, _excluded);
55
56
  var getInteractionItemProps = useInteractionItemProps(highlightScope);
56
57
  var _React$useContext = React.useContext(InteractionContext),
@@ -84,7 +85,9 @@ function BarElement(props) {
84
85
  dataIndex: dataIndex
85
86
  }), {
86
87
  style: style,
87
- className: classes.root
88
+ className: classes.root,
89
+ onClick: onClick,
90
+ cursor: onClick ? 'pointer' : 'unset'
88
91
  }),
89
92
  ownerState: ownerState
90
93
  });
@@ -1,7 +1,7 @@
1
1
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
2
2
  import _extends from "@babel/runtime/helpers/esm/extends";
3
3
  import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
4
- var _excluded = ["skipAnimation"];
4
+ var _excluded = ["skipAnimation", "onItemClick"];
5
5
  import * as React from 'react';
6
6
  import PropTypes from 'prop-types';
7
7
  import { useTransition } from '@react-spring/web';
@@ -38,7 +38,7 @@ function getBandSize(_ref) {
38
38
  offset: offset
39
39
  };
40
40
  }
41
- var useCompletedData = function useCompletedData() {
41
+ var useAggregatedData = function useAggregatedData() {
42
42
  var _React$useContext$bar;
43
43
  var seriesData = (_React$useContext$bar = React.useContext(SeriesContext).bar) != null ? _React$useContext$bar : {
44
44
  series: {},
@@ -164,8 +164,9 @@ var getInStyle = function getInStyle(_ref4) {
164
164
  * - [BarPlot API](https://mui.com/x/api/charts/bar-plot/)
165
165
  */
166
166
  function BarPlot(props) {
167
- var completedData = useCompletedData();
167
+ var completedData = useAggregatedData();
168
168
  var skipAnimation = props.skipAnimation,
169
+ onItemClick = props.onItemClick,
169
170
  other = _objectWithoutProperties(props, _excluded);
170
171
  var transition = useTransition(completedData, {
171
172
  keys: function keys(bar) {
@@ -189,6 +190,13 @@ function BarPlot(props) {
189
190
  highlightScope: highlightScope,
190
191
  color: color
191
192
  }, other, {
193
+ onClick: onItemClick && function (event) {
194
+ onItemClick(event, {
195
+ type: 'bar',
196
+ seriesId: seriesId,
197
+ dataIndex: dataIndex
198
+ });
199
+ },
192
200
  style: style
193
201
  }));
194
202
  })
@@ -200,7 +208,13 @@ process.env.NODE_ENV !== "production" ? BarPlot.propTypes = {
200
208
  // | To update them edit the TypeScript types and run "yarn proptypes" |
201
209
  // ----------------------------------------------------------------------
202
210
  /**
203
- * If `true`, animations are skiped.
211
+ * Callback fired when a bar item is clicked.
212
+ * @param {React.MouseEvent<SVGElement, MouseEvent>} event The event source of the callback.
213
+ * @param {BarItemIdentifier} barItemIdentifier The bar item identifier.
214
+ */
215
+ onItemClick: PropTypes.func,
216
+ /**
217
+ * If `true`, animations are skipped.
204
218
  * @default false
205
219
  */
206
220
  skipAnimation: PropTypes.bool,
@@ -71,7 +71,7 @@ var formatter = function formatter(params, dataset) {
71
71
  seriesOrder: seriesOrder,
72
72
  stackingGroups: stackingGroups,
73
73
  series: defaultizeValueFormatter(completedSeries, function (v) {
74
- return v === null ? '' : v.toLocaleString();
74
+ return v == null ? '' : v.toLocaleString();
75
75
  })
76
76
  };
77
77
  };