@mui/x-charts 8.0.0-alpha.10 → 8.0.0-alpha.11

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 (108) hide show
  1. package/BarChart/BarChart.d.ts +1 -2
  2. package/BarChart/BarChart.js +2 -4
  3. package/BarChart/BarChart.plugins.d.ts +12 -0
  4. package/BarChart/BarChart.plugins.js +5 -0
  5. package/BarChart/useBarChartProps.d.ts +2 -3
  6. package/BarChart/useBarChartProps.js +5 -8
  7. package/CHANGELOG.md +107 -2
  8. package/ChartContainer/ChartContainer.d.ts +2 -2
  9. package/ChartContainer/ChartContainer.js +8 -1
  10. package/ChartContainer/useChartContainerProps.d.ts +4 -3
  11. package/ChartContainer/useChartContainerProps.js +11 -7
  12. package/ChartDataProvider/ChartDataProvider.js +4 -1
  13. package/ChartsSurface/ChartsSurface.d.ts +0 -6
  14. package/ChartsSurface/ChartsSurface.js +1 -10
  15. package/ChartsTooltip/ChartsTooltipContainer.js +2 -2
  16. package/Gauge/Gauge.js +0 -6
  17. package/Gauge/GaugeContainer.js +0 -6
  18. package/LineChart/LineChart.d.ts +1 -2
  19. package/LineChart/LineChart.js +2 -4
  20. package/LineChart/LineChart.plugins.d.ts +12 -0
  21. package/LineChart/LineChart.plugins.js +5 -0
  22. package/LineChart/useLineChartProps.d.ts +2 -3
  23. package/LineChart/useLineChartProps.js +5 -8
  24. package/PieChart/PieChart.d.ts +3 -1
  25. package/PieChart/PieChart.js +8 -115
  26. package/PieChart/PieChart.plugins.d.ts +5 -0
  27. package/PieChart/PieChart.plugins.js +3 -0
  28. package/ScatterChart/ScatterChart.js +8 -1
  29. package/ScatterChart/ScatterChart.plugins.d.ts +12 -0
  30. package/ScatterChart/ScatterChart.plugins.js +5 -0
  31. package/ScatterChart/useScatterChartProps.d.ts +2 -1
  32. package/ScatterChart/useScatterChartProps.js +3 -1
  33. package/SparkLineChart/SparkLineChart.d.ts +12 -0
  34. package/SparkLineChart/SparkLineChart.js +24 -4
  35. package/colorPalettes/colorPalettes.d.ts +2 -0
  36. package/context/ChartProvider/ChartProvider.types.d.ts +2 -1
  37. package/hooks/useAxisEvents.d.ts +0 -1
  38. package/hooks/useAxisEvents.js +0 -165
  39. package/index.d.ts +0 -1
  40. package/index.js +1 -2
  41. package/internals/plugins/allPlugins.d.ts +1 -1
  42. package/internals/plugins/corePlugins/useChartSeries/useChartSeries.types.d.ts +5 -2
  43. package/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisValue.d.ts +9 -0
  44. package/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisValue.js +59 -0
  45. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxis.d.ts +1 -2
  46. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxis.js +142 -5
  47. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxis.types.d.ts +19 -2
  48. package/models/axis.d.ts +17 -0
  49. package/models/axis.js +5 -1
  50. package/models/index.d.ts +1 -1
  51. package/modern/BarChart/BarChart.js +2 -4
  52. package/modern/BarChart/BarChart.plugins.js +5 -0
  53. package/modern/BarChart/useBarChartProps.js +5 -8
  54. package/modern/ChartContainer/ChartContainer.js +8 -1
  55. package/modern/ChartContainer/useChartContainerProps.js +11 -7
  56. package/modern/ChartDataProvider/ChartDataProvider.js +4 -1
  57. package/modern/ChartsSurface/ChartsSurface.js +1 -10
  58. package/modern/ChartsTooltip/ChartsTooltipContainer.js +2 -2
  59. package/modern/Gauge/Gauge.js +0 -6
  60. package/modern/Gauge/GaugeContainer.js +0 -6
  61. package/modern/LineChart/LineChart.js +2 -4
  62. package/modern/LineChart/LineChart.plugins.js +5 -0
  63. package/modern/LineChart/useLineChartProps.js +5 -8
  64. package/modern/PieChart/PieChart.js +8 -115
  65. package/modern/PieChart/PieChart.plugins.js +3 -0
  66. package/modern/ScatterChart/ScatterChart.js +8 -1
  67. package/modern/ScatterChart/ScatterChart.plugins.js +5 -0
  68. package/modern/ScatterChart/useScatterChartProps.js +3 -1
  69. package/modern/SparkLineChart/SparkLineChart.js +24 -4
  70. package/modern/hooks/useAxisEvents.js +0 -165
  71. package/modern/index.js +1 -2
  72. package/modern/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisValue.js +59 -0
  73. package/modern/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxis.js +142 -5
  74. package/modern/models/axis.js +5 -1
  75. package/node/BarChart/BarChart.js +2 -4
  76. package/node/BarChart/BarChart.plugins.js +11 -0
  77. package/node/BarChart/useBarChartProps.js +5 -8
  78. package/node/ChartContainer/ChartContainer.js +8 -1
  79. package/node/ChartContainer/useChartContainerProps.js +11 -7
  80. package/node/ChartDataProvider/ChartDataProvider.js +4 -1
  81. package/node/ChartsSurface/ChartsSurface.js +1 -10
  82. package/node/ChartsTooltip/ChartsTooltipContainer.js +2 -2
  83. package/node/Gauge/Gauge.js +0 -6
  84. package/node/Gauge/GaugeContainer.js +0 -6
  85. package/node/LineChart/LineChart.js +2 -4
  86. package/node/LineChart/LineChart.plugins.js +11 -0
  87. package/node/LineChart/useLineChartProps.js +5 -8
  88. package/node/PieChart/PieChart.js +8 -115
  89. package/node/PieChart/PieChart.plugins.js +9 -0
  90. package/node/ScatterChart/ScatterChart.js +8 -1
  91. package/node/ScatterChart/ScatterChart.plugins.js +11 -0
  92. package/node/ScatterChart/useScatterChartProps.js +3 -1
  93. package/node/SparkLineChart/SparkLineChart.js +24 -4
  94. package/node/hooks/useAxisEvents.js +1 -173
  95. package/node/index.js +1 -12
  96. package/node/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisValue.js +65 -0
  97. package/node/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxis.js +141 -4
  98. package/node/models/axis.js +5 -1
  99. package/package.json +2 -2
  100. package/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.d.ts +0 -20
  101. package/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +0 -82
  102. package/ChartsOnAxisClickHandler/index.d.ts +0 -1
  103. package/ChartsOnAxisClickHandler/index.js +0 -1
  104. package/ChartsOnAxisClickHandler/package.json +0 -6
  105. package/modern/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +0 -82
  106. package/modern/ChartsOnAxisClickHandler/index.js +0 -1
  107. package/node/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +0 -88
  108. package/node/ChartsOnAxisClickHandler/index.js +0 -16
@@ -2,10 +2,11 @@
2
2
 
3
3
  import _extends from "@babel/runtime/helpers/esm/extends";
4
4
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
5
- const _excluded = ["xAxis", "yAxis", "series", "width", "height", "margin", "colors", "dataset", "sx", "onAxisClick", "onAreaClick", "onLineClick", "onMarkClick", "axisHighlight", "disableLineItemHighlight", "hideLegend", "grid", "topAxis", "leftAxis", "rightAxis", "bottomAxis", "children", "slots", "slotProps", "skipAnimation", "loading", "highlightedItem", "onHighlightChange", "className"];
5
+ const _excluded = ["xAxis", "yAxis", "series", "width", "height", "margin", "colors", "dataset", "sx", "onAreaClick", "onLineClick", "onMarkClick", "axisHighlight", "disableLineItemHighlight", "hideLegend", "grid", "topAxis", "leftAxis", "rightAxis", "bottomAxis", "children", "slots", "slotProps", "skipAnimation", "loading", "highlightedItem", "onHighlightChange", "className"];
6
6
  import useId from '@mui/utils/useId';
7
7
  import { DEFAULT_X_AXIS_KEY } from "../constants/index.js";
8
8
  import { calculateMargins } from "../internals/calculateMargins.js";
9
+ import { LINE_CHART_PLUGINS } from "./LineChart.plugins.js";
9
10
 
10
11
  /**
11
12
  * A helper function that extracts LineChartProps from the input props
@@ -25,7 +26,6 @@ export const useLineChartProps = props => {
25
26
  colors,
26
27
  dataset,
27
28
  sx,
28
- onAxisClick,
29
29
  onAreaClick,
30
30
  onLineClick,
31
31
  onMarkClick,
@@ -74,13 +74,11 @@ export const useLineChartProps = props => {
74
74
  yAxis,
75
75
  highlightedItem,
76
76
  onHighlightChange,
77
- disableAxisListener: slotProps?.tooltip?.trigger !== 'axis' && axisHighlight?.x === 'none' && axisHighlight?.y === 'none' && !onAxisClick,
77
+ disableAxisListener: slotProps?.tooltip?.trigger !== 'axis' && axisHighlight?.x === 'none' && axisHighlight?.y === 'none',
78
78
  className,
79
- skipAnimation
79
+ skipAnimation,
80
+ plugins: LINE_CHART_PLUGINS
80
81
  });
81
- const axisClickHandlerProps = {
82
- onAxisClick
83
- };
84
82
  const gridProps = {
85
83
  vertical: grid?.vertical,
86
84
  horizontal: grid?.horizontal
@@ -139,7 +137,6 @@ export const useLineChartProps = props => {
139
137
  return {
140
138
  chartsWrapperProps,
141
139
  chartContainerProps,
142
- axisClickHandlerProps,
143
140
  gridProps,
144
141
  clipPathProps,
145
142
  clipPathGroupProps,
@@ -7,11 +7,13 @@ import { ChartsLegendSlotProps, ChartsLegendSlots } from '../ChartsLegend';
7
7
  import { PiePlotProps, PiePlotSlotProps, PiePlotSlots } from './PiePlot';
8
8
  import { PieValueType } from '../models/seriesType/pie';
9
9
  import { ChartsOverlayProps, ChartsOverlaySlotProps, ChartsOverlaySlots } from '../ChartsOverlay';
10
+ import { UseChartInteractionSignature } from '../internals/plugins/featurePlugins/useChartInteraction';
11
+ import { UseChartHighlightSignature } from '../internals/plugins/featurePlugins/useChartHighlight';
10
12
  export interface PieChartSlots extends PiePlotSlots, ChartsLegendSlots, ChartsOverlaySlots, ChartsTooltipSlots {
11
13
  }
12
14
  export interface PieChartSlotProps extends PiePlotSlotProps, ChartsLegendSlotProps, ChartsOverlaySlotProps, ChartsTooltipSlotProps {
13
15
  }
14
- export interface PieChartProps extends Omit<ChartContainerProps, 'series' | 'leftAxis' | 'bottomAxis' | 'plugins' | 'zAxis'>, Omit<ChartsOverlayProps, 'slots' | 'slotProps'>, Pick<PiePlotProps, 'skipAnimation'> {
16
+ export interface PieChartProps extends Omit<ChartContainerProps<'pie', [UseChartInteractionSignature, UseChartHighlightSignature]>, 'series'>, Omit<ChartsOverlayProps, 'slots' | 'slotProps'>, Pick<PiePlotProps, 'skipAnimation'> {
15
17
  /**
16
18
  * The series to display in the pie chart.
17
19
  * An array of [[PieSeriesType]] objects.
@@ -2,7 +2,7 @@
2
2
 
3
3
  import _extends from "@babel/runtime/helpers/esm/extends";
4
4
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
5
- const _excluded = ["xAxis", "yAxis", "series", "width", "height", "margin", "colors", "sx", "skipAnimation", "hideLegend", "children", "slots", "slotProps", "onItemClick", "loading", "highlightedItem", "onHighlightChange", "className"];
5
+ const _excluded = ["series", "width", "height", "margin", "colors", "sx", "skipAnimation", "hideLegend", "children", "slots", "slotProps", "onItemClick", "loading", "highlightedItem", "onHighlightChange", "className"];
6
6
  import * as React from 'react';
7
7
  import PropTypes from 'prop-types';
8
8
  import { useThemeProps } from '@mui/material/styles';
@@ -14,7 +14,10 @@ import { ChartsSurface } from "../ChartsSurface/index.js";
14
14
  import { ChartDataProvider } from "../ChartDataProvider/index.js";
15
15
  import { useChartContainerProps } from "../ChartContainer/useChartContainerProps.js";
16
16
  import { ChartsWrapper } from "../internals/components/ChartsWrapper/index.js";
17
+ import { useChartInteraction } from "../internals/plugins/featurePlugins/useChartInteraction/index.js";
18
+ import { useChartHighlight } from "../internals/plugins/featurePlugins/useChartHighlight/index.js";
17
19
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
20
+ const PIE_CHART_PLUGGINS = [useChartInteraction, useChartHighlight];
18
21
  const defaultMargin = {
19
22
  top: 5,
20
23
  bottom: 5,
@@ -68,11 +71,11 @@ const PieChart = /*#__PURE__*/React.forwardRef(function PieChart(inProps, ref) {
68
71
  height,
69
72
  margin,
70
73
  colors,
71
- disableAxisListener: true,
72
74
  highlightedItem,
73
75
  onHighlightChange,
74
76
  className,
75
- skipAnimation
77
+ skipAnimation,
78
+ plugins: PIE_CHART_PLUGGINS
76
79
  }), ref);
77
80
  const Tooltip = slots?.tooltip ?? ChartsTooltip;
78
81
  return /*#__PURE__*/_jsx(ChartDataProvider, _extends({}, chartDataProviderProps, {
@@ -112,7 +115,7 @@ process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
112
115
  className: PropTypes.string,
113
116
  /**
114
117
  * Color palette used to colorize multiple series.
115
- * @default blueberryTwilightPalette
118
+ * @default rainbowSurgePalette
116
119
  */
117
120
  colors: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string), PropTypes.func]),
118
121
  /**
@@ -120,12 +123,6 @@ process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
120
123
  */
121
124
  dataset: PropTypes.arrayOf(PropTypes.object),
122
125
  desc: PropTypes.string,
123
- /**
124
- * If `true`, the charts will not listen to the mouse move event.
125
- * It might break interactive features, but will improve performance.
126
- * @default false
127
- */
128
- disableAxisListener: PropTypes.bool,
129
126
  /**
130
127
  * The height of the chart in px. If not defined, it takes the height of the parent element.
131
128
  */
@@ -199,110 +196,6 @@ process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
199
196
  /**
200
197
  * The width of the chart in px. If not defined, it takes the width of the parent element.
201
198
  */
202
- width: PropTypes.number,
203
- /**
204
- * The configuration of the x-axes.
205
- * If not provided, a default axis config is used.
206
- * An array of [[AxisConfig]] objects.
207
- */
208
- xAxis: PropTypes.arrayOf(PropTypes.shape({
209
- classes: PropTypes.object,
210
- colorMap: PropTypes.oneOfType([PropTypes.shape({
211
- colors: PropTypes.arrayOf(PropTypes.string).isRequired,
212
- type: PropTypes.oneOf(['ordinal']).isRequired,
213
- unknownColor: PropTypes.string,
214
- values: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired)
215
- }), PropTypes.shape({
216
- color: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string.isRequired), PropTypes.func]).isRequired,
217
- max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
218
- min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
219
- type: PropTypes.oneOf(['continuous']).isRequired
220
- }), PropTypes.shape({
221
- colors: PropTypes.arrayOf(PropTypes.string).isRequired,
222
- thresholds: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired).isRequired,
223
- type: PropTypes.oneOf(['piecewise']).isRequired
224
- })]),
225
- data: PropTypes.array,
226
- dataKey: PropTypes.string,
227
- disableLine: PropTypes.bool,
228
- disableTicks: PropTypes.bool,
229
- domainLimit: PropTypes.oneOfType([PropTypes.oneOf(['nice', 'strict']), PropTypes.func]),
230
- fill: PropTypes.string,
231
- hideTooltip: PropTypes.bool,
232
- id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
233
- label: PropTypes.string,
234
- labelStyle: PropTypes.object,
235
- max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
236
- min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
237
- position: PropTypes.oneOf(['bottom', 'top']),
238
- reverse: PropTypes.bool,
239
- scaleType: PropTypes.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
240
- slotProps: PropTypes.object,
241
- slots: PropTypes.object,
242
- stroke: PropTypes.string,
243
- sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
244
- tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
245
- tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
246
- tickLabelPlacement: PropTypes.oneOf(['middle', 'tick']),
247
- tickLabelStyle: PropTypes.object,
248
- tickMaxStep: PropTypes.number,
249
- tickMinStep: PropTypes.number,
250
- tickNumber: PropTypes.number,
251
- tickPlacement: PropTypes.oneOf(['end', 'extremities', 'middle', 'start']),
252
- tickSize: PropTypes.number,
253
- valueFormatter: PropTypes.func
254
- })),
255
- /**
256
- * The configuration of the y-axes.
257
- * If not provided, a default axis config is used.
258
- * An array of [[AxisConfig]] objects.
259
- */
260
- yAxis: PropTypes.arrayOf(PropTypes.shape({
261
- classes: PropTypes.object,
262
- colorMap: PropTypes.oneOfType([PropTypes.shape({
263
- colors: PropTypes.arrayOf(PropTypes.string).isRequired,
264
- type: PropTypes.oneOf(['ordinal']).isRequired,
265
- unknownColor: PropTypes.string,
266
- values: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired)
267
- }), PropTypes.shape({
268
- color: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string.isRequired), PropTypes.func]).isRequired,
269
- max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
270
- min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
271
- type: PropTypes.oneOf(['continuous']).isRequired
272
- }), PropTypes.shape({
273
- colors: PropTypes.arrayOf(PropTypes.string).isRequired,
274
- thresholds: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired).isRequired,
275
- type: PropTypes.oneOf(['piecewise']).isRequired
276
- })]),
277
- data: PropTypes.array,
278
- dataKey: PropTypes.string,
279
- disableLine: PropTypes.bool,
280
- disableTicks: PropTypes.bool,
281
- domainLimit: PropTypes.oneOfType([PropTypes.oneOf(['nice', 'strict']), PropTypes.func]),
282
- fill: PropTypes.string,
283
- hideTooltip: PropTypes.bool,
284
- id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
285
- label: PropTypes.string,
286
- labelStyle: PropTypes.object,
287
- max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
288
- min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
289
- position: PropTypes.oneOf(['left', 'right']),
290
- reverse: PropTypes.bool,
291
- scaleType: PropTypes.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
292
- slotProps: PropTypes.object,
293
- slots: PropTypes.object,
294
- stroke: PropTypes.string,
295
- sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
296
- tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
297
- tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
298
- tickLabelPlacement: PropTypes.oneOf(['middle', 'tick']),
299
- tickLabelStyle: PropTypes.object,
300
- tickMaxStep: PropTypes.number,
301
- tickMinStep: PropTypes.number,
302
- tickNumber: PropTypes.number,
303
- tickPlacement: PropTypes.oneOf(['end', 'extremities', 'middle', 'start']),
304
- tickSize: PropTypes.number,
305
- valueFormatter: PropTypes.func
306
- }))
199
+ width: PropTypes.number
307
200
  } : void 0;
308
201
  export { PieChart };
@@ -0,0 +1,5 @@
1
+ import { UseChartInteractionSignature } from '../internals/plugins/featurePlugins/useChartInteraction';
2
+ import { UseChartHighlightSignature } from '../internals/plugins/featurePlugins/useChartHighlight';
3
+ import { ConvertSignaturesIntoPlugins } from '../internals/plugins/models/helpers';
4
+ export type PieChartPluginSignatures = [UseChartInteractionSignature, UseChartHighlightSignature];
5
+ export declare const PIE_CHART_PLUGINS: ConvertSignaturesIntoPlugins<PieChartPluginSignatures>;
@@ -0,0 +1,3 @@
1
+ import { useChartInteraction } from "../internals/plugins/featurePlugins/useChartInteraction/index.js";
2
+ import { useChartHighlight } from "../internals/plugins/featurePlugins/useChartHighlight/index.js";
3
+ export const PIE_CHART_PLUGINS = [useChartInteraction, useChartHighlight];
@@ -90,7 +90,7 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
90
90
  className: PropTypes.string,
91
91
  /**
92
92
  * Color palette used to colorize multiple series.
93
- * @default blueberryTwilightPalette
93
+ * @default rainbowSurgePalette
94
94
  */
95
95
  colors: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string), PropTypes.func]),
96
96
  /**
@@ -159,6 +159,13 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
159
159
  right: PropTypes.number,
160
160
  top: PropTypes.number
161
161
  }),
162
+ /**
163
+ * The function called for onClick events.
164
+ * The second argument contains information about all line/bar elements at the current mouse position.
165
+ * @param {MouseEvent} event The mouse event recorded on the `<svg/>` element.
166
+ * @param {null | AxisData} data The data about the clicked axis and items associated with it.
167
+ */
168
+ onAxisClick: PropTypes.func,
162
169
  /**
163
170
  * The callback fired when the highlighted item changes.
164
171
  *
@@ -0,0 +1,12 @@
1
+ import { UseChartZAxisSignature } from '../internals/plugins/featurePlugins/useChartZAxis';
2
+ import { UseChartCartesianAxisSignature } from '../internals/plugins/featurePlugins/useChartCartesianAxis';
3
+ import { UseChartInteractionSignature } from '../internals/plugins/featurePlugins/useChartInteraction';
4
+ import { UseChartHighlightSignature } from '../internals/plugins/featurePlugins/useChartHighlight';
5
+ import { ConvertSignaturesIntoPlugins } from '../internals/plugins/models/helpers';
6
+ export type ScatterChartPluginsSignatures = [
7
+ UseChartZAxisSignature,
8
+ UseChartCartesianAxisSignature<'scatter'>,
9
+ UseChartInteractionSignature,
10
+ UseChartHighlightSignature
11
+ ];
12
+ export declare const SCATTER_CHART_PLUGINS: ConvertSignaturesIntoPlugins<ScatterChartPluginsSignatures>;
@@ -0,0 +1,5 @@
1
+ import { useChartZAxis } from "../internals/plugins/featurePlugins/useChartZAxis/index.js";
2
+ import { useChartCartesianAxis } from "../internals/plugins/featurePlugins/useChartCartesianAxis/index.js";
3
+ import { useChartInteraction } from "../internals/plugins/featurePlugins/useChartInteraction/index.js";
4
+ import { useChartHighlight } from "../internals/plugins/featurePlugins/useChartHighlight/index.js";
5
+ export const SCATTER_CHART_PLUGINS = [useChartZAxis, useChartCartesianAxis, useChartInteraction, useChartHighlight];
@@ -8,6 +8,7 @@ import { ChartContainerProps } from '../ChartContainer';
8
8
  import type { ScatterChartProps } from './ScatterChart';
9
9
  import type { ScatterPlotProps } from './ScatterPlot';
10
10
  import type { ChartsWrapperProps } from '../internals/components/ChartsWrapper';
11
+ import { ScatterChartPluginsSignatures } from './ScatterChart.plugins';
11
12
  /**
12
13
  * A helper function that extracts ScatterChartProps from the input props
13
14
  * and returns an object with props for the children components of ScatterChart.
@@ -17,7 +18,7 @@ import type { ChartsWrapperProps } from '../internals/components/ChartsWrapper';
17
18
  */
18
19
  export declare const useScatterChartProps: (props: ScatterChartProps) => {
19
20
  chartsWrapperProps: Omit<ChartsWrapperProps, "children">;
20
- chartContainerProps: Omit<ChartContainerProps<"scatter">, "plugins">;
21
+ chartContainerProps: ChartContainerProps<"scatter", ScatterChartPluginsSignatures>;
21
22
  voronoiHandlerProps: ChartsVoronoiHandlerProps;
22
23
  chartsAxisProps: ChartsAxisProps;
23
24
  gridProps: ChartsGridProps;
@@ -4,6 +4,7 @@ import _extends from "@babel/runtime/helpers/esm/extends";
4
4
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
5
5
  const _excluded = ["xAxis", "yAxis", "zAxis", "series", "axisHighlight", "voronoiMaxRadius", "disableVoronoi", "hideLegend", "width", "height", "margin", "colors", "sx", "grid", "topAxis", "leftAxis", "rightAxis", "bottomAxis", "onItemClick", "children", "slots", "slotProps", "loading", "highlightedItem", "onHighlightChange", "className"];
6
6
  import { calculateMargins } from "../internals/calculateMargins.js";
7
+ import { SCATTER_CHART_PLUGINS } from "./ScatterChart.plugins.js";
7
8
 
8
9
  /**
9
10
  * A helper function that extracts ScatterChartProps from the input props
@@ -60,7 +61,8 @@ export const useScatterChartProps = props => {
60
61
  zAxis,
61
62
  highlightedItem,
62
63
  onHighlightChange,
63
- className
64
+ className,
65
+ plugins: SCATTER_CHART_PLUGINS
64
66
  });
65
67
  const voronoiHandlerProps = {
66
68
  voronoiMaxRadius,
@@ -1,5 +1,6 @@
1
1
  import * as React from 'react';
2
2
  import { MakeOptional } from '@mui/x-internals/types';
3
+ import { ChartsColor } from '../colorPalettes';
3
4
  import { ChartContainerProps } from '../ChartContainer';
4
5
  import { ChartsTooltipSlots, ChartsTooltipSlotProps } from '../ChartsTooltip/ChartTooltip.types';
5
6
  import { ChartsAxisHighlightProps } from '../ChartsAxisHighlight';
@@ -87,6 +88,17 @@ export interface SparkLineChartProps extends Omit<ChartContainerProps, 'series'
87
88
  * @default {}
88
89
  */
89
90
  slotProps?: SparkLineChartSlotProps;
91
+ /**
92
+ * Color palette used to colorize multiple series.
93
+ * @default rainbowSurgePalette
94
+ * @deprecated use the `color` prop instead
95
+ */
96
+ colors?: ChartContainerProps['colors'];
97
+ /**
98
+ * Color used to colorize the sparkline.
99
+ * @default rainbowSurgePalette[0]
100
+ */
101
+ color?: ChartsColor;
90
102
  }
91
103
  /**
92
104
  * Demos:
@@ -2,7 +2,7 @@
2
2
 
3
3
  import _extends from "@babel/runtime/helpers/esm/extends";
4
4
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
5
- const _excluded = ["xAxis", "yAxis", "width", "height", "margin", "colors", "sx", "showTooltip", "showHighlight", "axisHighlight", "children", "slots", "slotProps", "data", "plotType", "valueFormatter", "area", "curve", "className"];
5
+ const _excluded = ["xAxis", "yAxis", "width", "height", "margin", "color", "colors", "sx", "showTooltip", "showHighlight", "axisHighlight", "children", "slots", "slotProps", "data", "plotType", "valueFormatter", "area", "curve", "className"];
6
6
  import * as React from 'react';
7
7
  import PropTypes from 'prop-types';
8
8
  import { BarPlot } from "../BarChart/index.js";
@@ -35,7 +35,8 @@ const SparkLineChart = /*#__PURE__*/React.forwardRef(function SparkLineChart(pro
35
35
  width,
36
36
  height,
37
37
  margin = SPARKLINE_DEFAULT_MARGIN,
38
- colors,
38
+ color,
39
+ colors: deprecatedColors,
39
40
  sx,
40
41
  showTooltip,
41
42
  showHighlight,
@@ -58,6 +59,12 @@ const SparkLineChart = /*#__PURE__*/React.forwardRef(function SparkLineChart(pro
58
59
  };
59
60
  const axisHighlight = _extends({}, defaultXHighlight, inAxisHighlight);
60
61
  const Tooltip = props.slots?.tooltip ?? ChartsTooltip;
62
+ const colors = React.useMemo(() => {
63
+ if (color == null) {
64
+ return undefined;
65
+ }
66
+ return typeof color === 'function' ? mode => [color(mode)] : [color];
67
+ }, [color]);
61
68
  return /*#__PURE__*/_jsxs(ChartContainer, _extends({}, other, {
62
69
  ref: ref,
63
70
  series: [_extends({
@@ -84,7 +91,7 @@ const SparkLineChart = /*#__PURE__*/React.forwardRef(function SparkLineChart(pro
84
91
  yAxis: [_extends({
85
92
  id: DEFAULT_Y_AXIS_KEY
86
93
  }, yAxis)],
87
- colors: colors,
94
+ colors: colors ?? deprecatedColors,
88
95
  sx: sx,
89
96
  disableAxisListener: (!showTooltip || slotProps?.tooltip?.trigger !== 'axis') && axisHighlight?.x === 'none' && axisHighlight?.y === 'none',
90
97
  children: [plotType === 'bar' && /*#__PURE__*/_jsx(BarPlot, {
@@ -127,9 +134,15 @@ process.env.NODE_ENV !== "production" ? SparkLineChart.propTypes = {
127
134
  }),
128
135
  children: PropTypes.node,
129
136
  className: PropTypes.string,
137
+ /**
138
+ * Color used to colorize the sparkline.
139
+ * @default rainbowSurgePalette[0]
140
+ */
141
+ color: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
130
142
  /**
131
143
  * Color palette used to colorize multiple series.
132
- * @default blueberryTwilightPalette
144
+ * @default rainbowSurgePalette
145
+ * @deprecated use the `color` prop instead
133
146
  */
134
147
  colors: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string), PropTypes.func]),
135
148
  /**
@@ -185,6 +198,13 @@ process.env.NODE_ENV !== "production" ? SparkLineChart.propTypes = {
185
198
  right: PropTypes.number,
186
199
  top: PropTypes.number
187
200
  }),
201
+ /**
202
+ * The function called for onClick events.
203
+ * The second argument contains information about all line/bar elements at the current mouse position.
204
+ * @param {MouseEvent} event The mouse event recorded on the `<svg/>` element.
205
+ * @param {null | AxisData} data The data about the clicked axis and items associated with it.
206
+ */
207
+ onAxisClick: PropTypes.func,
188
208
  /**
189
209
  * The callback fired when the highlighted item changes.
190
210
  *
@@ -1,5 +1,7 @@
1
1
  export type ChartsColorPaletteCallback = (mode: 'light' | 'dark') => string[];
2
2
  export type ChartsColorPalette = string[] | ChartsColorPaletteCallback;
3
+ export type ChartsColorCallback = (mode: 'light' | 'dark') => string;
4
+ export type ChartsColor = string | ChartsColorCallback;
3
5
  export declare const rainbowSurgePaletteLight: string[];
4
6
  export declare const rainbowSurgePaletteDark: string[];
5
7
  export declare const rainbowSurgePalette: ChartsColorPaletteCallback;
@@ -24,12 +24,13 @@ export type ChartContextValue<TSignatures extends readonly ChartAnyPluginSignatu
24
24
  */
25
25
  svgRef: React.RefObject<SVGSVGElement | null>;
26
26
  };
27
+ export type ChartPluginParams<TSignatures extends readonly ChartAnyPluginSignature[]> = UseChartBaseProps<TSignatures> & MergeSignaturesProperty<[...ChartCorePluginSignatures, ...TSignatures], 'params'>;
27
28
  export interface ChartProviderProps<TSeries extends ChartSeriesType = ChartSeriesType, TSignatures extends readonly ChartAnyPluginSignature[] = AllPluginSignatures<TSeries>> {
28
29
  /**
29
30
  * Array of plugins used to add features to the chart.
30
31
  */
31
32
  plugins?: ConvertSignaturesIntoPlugins<TSignatures>;
32
- pluginParams?: UseChartBaseProps<TSignatures> & MergeSignaturesProperty<[...ChartCorePluginSignatures, ...TSignatures], 'params'>;
33
+ pluginParams?: ChartPluginParams<TSignatures>;
33
34
  /**
34
35
  * The configuration helpers used to compute attributes according to the serries type.
35
36
  * @ignore Unstable props for internal usage.
@@ -1 +0,0 @@
1
- export declare const useAxisEvents: (disableAxisListener: boolean) => void;
@@ -1,165 +0,0 @@
1
- 'use client';
2
-
3
- import _extends from "@babel/runtime/helpers/esm/extends";
4
- import * as React from 'react';
5
- import { isBandScale } from "../internals/isBandScale.js";
6
- import { getSVGPoint } from "../internals/getSVGPoint.js";
7
- import { useSvgRef } from "./useSvgRef.js";
8
- import { useStore } from "../internals/store/useStore.js";
9
- import { useChartContext } from "../context/ChartProvider/index.js";
10
- import { useXAxes, useYAxes } from "./useAxis.js";
11
- function getAsANumber(value) {
12
- return value instanceof Date ? value.getTime() : value;
13
- }
14
- export const useAxisEvents = disableAxisListener => {
15
- const svgRef = useSvgRef();
16
- const {
17
- instance
18
- } = useChartContext();
19
- const {
20
- xAxis,
21
- xAxisIds
22
- } = useXAxes();
23
- const {
24
- yAxis,
25
- yAxisIds
26
- } = useYAxes();
27
- const store = useStore();
28
- const usedXAxis = xAxisIds[0];
29
- const usedYAxis = yAxisIds[0];
30
-
31
- // Use a ref to avoid rerendering on every mousemove event.
32
- const mousePosition = React.useRef({
33
- isInChart: false,
34
- x: -1,
35
- y: -1
36
- });
37
- React.useEffect(() => {
38
- const element = svgRef.current;
39
- if (element === null || disableAxisListener || !store) {
40
- return () => {};
41
- }
42
- function getNewAxisState(axisConfig, mouseValue) {
43
- const {
44
- scale,
45
- data: axisData,
46
- reverse
47
- } = axisConfig;
48
- if (!isBandScale(scale)) {
49
- const value = scale.invert(mouseValue);
50
- if (axisData === undefined) {
51
- return {
52
- value,
53
- index: -1
54
- };
55
- }
56
- const valueAsNumber = getAsANumber(value);
57
- const closestIndex = axisData?.findIndex((pointValue, index) => {
58
- const v = getAsANumber(pointValue);
59
- if (v > valueAsNumber) {
60
- if (index === 0 || Math.abs(valueAsNumber - v) <= Math.abs(valueAsNumber - getAsANumber(axisData[index - 1]))) {
61
- return true;
62
- }
63
- }
64
- if (v <= valueAsNumber) {
65
- if (index === axisData.length - 1 || Math.abs(getAsANumber(value) - v) < Math.abs(getAsANumber(value) - getAsANumber(axisData[index + 1]))) {
66
- return true;
67
- }
68
- }
69
- return false;
70
- });
71
- return {
72
- value: closestIndex !== undefined && closestIndex >= 0 ? axisData[closestIndex] : value,
73
- index: closestIndex
74
- };
75
- }
76
- const dataIndex = scale.bandwidth() === 0 ? Math.floor((mouseValue - Math.min(...scale.range()) + scale.step() / 2) / scale.step()) : Math.floor((mouseValue - Math.min(...scale.range())) / scale.step());
77
- if (dataIndex < 0 || dataIndex >= axisData.length) {
78
- return null;
79
- }
80
- if (reverse) {
81
- const reverseIndex = axisData.length - 1 - dataIndex;
82
- return {
83
- index: reverseIndex,
84
- value: axisData[reverseIndex]
85
- };
86
- }
87
- return {
88
- index: dataIndex,
89
- value: axisData[dataIndex]
90
- };
91
- }
92
- const handleOut = () => {
93
- mousePosition.current = {
94
- isInChart: false,
95
- x: -1,
96
- y: -1
97
- };
98
- store.update(prev => _extends({}, prev, {
99
- interaction: {
100
- item: null,
101
- axis: {
102
- x: null,
103
- y: null
104
- }
105
- }
106
- }));
107
- };
108
- const handleMove = event => {
109
- const target = 'targetTouches' in event ? event.targetTouches[0] : event;
110
- const svgPoint = getSVGPoint(element, target);
111
- mousePosition.current.x = svgPoint.x;
112
- mousePosition.current.y = svgPoint.y;
113
- if (!instance.isPointInside(svgPoint, {
114
- targetElement: event.target
115
- })) {
116
- if (mousePosition.current.isInChart) {
117
- store.update(prev => _extends({}, prev, {
118
- interaction: {
119
- item: null,
120
- axis: {
121
- x: null,
122
- y: null
123
- }
124
- }
125
- }));
126
- mousePosition.current.isInChart = false;
127
- }
128
- return;
129
- }
130
- mousePosition.current.isInChart = true;
131
- const newStateX = getNewAxisState(xAxis[usedXAxis], svgPoint.x);
132
- const newStateY = getNewAxisState(yAxis[usedYAxis], svgPoint.y);
133
- store.update(prev => _extends({}, prev, {
134
- interaction: _extends({}, prev.interaction, {
135
- axis: _extends({}, prev.interaction.axis, prev.interaction.axis.x?.index !== newStateX?.index || prev.interaction.axis.x?.value !== newStateX?.value ? {
136
- x: newStateX
137
- } : {}, prev.interaction.axis.y?.index !== newStateY?.index || prev.interaction.axis.y?.value !== newStateY?.value ? {
138
- y: newStateY
139
- } : {})
140
- })
141
- }));
142
- };
143
- const handleDown = event => {
144
- const target = event.currentTarget;
145
- if (!target) {
146
- return;
147
- }
148
- if (target.hasPointerCapture(event.pointerId)) {
149
- target.releasePointerCapture(event.pointerId);
150
- }
151
- };
152
- element.addEventListener('pointerdown', handleDown);
153
- element.addEventListener('pointermove', handleMove);
154
- element.addEventListener('pointerout', handleOut);
155
- element.addEventListener('pointercancel', handleOut);
156
- element.addEventListener('pointerleave', handleOut);
157
- return () => {
158
- element.removeEventListener('pointerdown', handleDown);
159
- element.removeEventListener('pointermove', handleMove);
160
- element.removeEventListener('pointerout', handleOut);
161
- element.removeEventListener('pointercancel', handleOut);
162
- element.removeEventListener('pointerleave', handleOut);
163
- };
164
- }, [svgRef, store, usedYAxis, yAxis, usedXAxis, xAxis, disableAxisListener, instance]);
165
- };
package/index.d.ts CHANGED
@@ -15,7 +15,6 @@ export * from './ChartsLabel';
15
15
  export * from './ChartsLegend';
16
16
  export * from './ChartsAxisHighlight';
17
17
  export * from './ChartsVoronoiHandler';
18
- export * from './ChartsOnAxisClickHandler';
19
18
  export * from './BarChart';
20
19
  export * from './LineChart';
21
20
  export * from './PieChart';
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-charts v8.0.0-alpha.10
2
+ * @mui/x-charts v8.0.0-alpha.11
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
@@ -22,7 +22,6 @@ export * from "./ChartsLabel/index.js";
22
22
  export * from "./ChartsLegend/index.js";
23
23
  export * from "./ChartsAxisHighlight/index.js";
24
24
  export * from "./ChartsVoronoiHandler/index.js";
25
- export * from "./ChartsOnAxisClickHandler/index.js";
26
25
  export * from "./BarChart/index.js";
27
26
  export * from "./LineChart/index.js";
28
27
  export * from "./PieChart/index.js";
@@ -11,4 +11,4 @@ export type AllPluginSignatures<TSeries extends ChartSeriesType = ChartSeriesTyp
11
11
  UseChartHighlightSignature
12
12
  ];
13
13
  export type AllPluginsType<TSeries extends ChartSeriesType = ChartSeriesType> = ConvertSignaturesIntoPlugins<AllPluginSignatures<TSeries>>;
14
- export declare const ALL_PLUGINS: (import("./models").ChartPlugin<UseChartCartesianAxisSignature<keyof import("..").ChartsSeriesConfig>> | import("./models").ChartPlugin<UseChartZAxisSignature> | import("./models").ChartPlugin<UseChartInteractionSignature> | import("./models").ChartPlugin<UseChartHighlightSignature>)[];
14
+ export declare const ALL_PLUGINS: (import("./models").ChartPlugin<UseChartInteractionSignature> | import("./models").ChartPlugin<UseChartZAxisSignature> | import("./models").ChartPlugin<UseChartCartesianAxisSignature<any>> | import("./models").ChartPlugin<UseChartHighlightSignature>)[];