@mui/x-charts-pro 9.0.1 → 9.0.3

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 (68) hide show
  1. package/BarChartPro/BarChartPro.js +20 -1
  2. package/BarChartPro/BarChartPro.mjs +20 -1
  3. package/CHANGELOG.md +257 -0
  4. package/ChartsDataProviderPro/ChartsDataProviderPro.js +2 -2
  5. package/ChartsDataProviderPro/ChartsDataProviderPro.mjs +2 -2
  6. package/ChartsRadialDataProvider/index.d.mts +1 -0
  7. package/ChartsRadialDataProvider/index.d.ts +1 -0
  8. package/ChartsRadialDataProvider/index.js +16 -0
  9. package/ChartsRadialDataProvider/index.mjs +2 -0
  10. package/ChartsRadialGrid/index.d.mts +1 -0
  11. package/ChartsRadialGrid/index.d.ts +1 -0
  12. package/ChartsRadialGrid/index.js +16 -0
  13. package/ChartsRadialGrid/index.mjs +2 -0
  14. package/ChartsRadiusAxis/index.d.mts +1 -0
  15. package/ChartsRadiusAxis/index.d.ts +1 -0
  16. package/ChartsRadiusAxis/index.js +16 -0
  17. package/ChartsRadiusAxis/index.mjs +2 -0
  18. package/ChartsRotationAxis/index.d.mts +1 -0
  19. package/ChartsRotationAxis/index.d.ts +1 -0
  20. package/ChartsRotationAxis/index.js +16 -0
  21. package/ChartsRotationAxis/index.mjs +2 -0
  22. package/ChartsToolbarPro/ChartsToolbarImageExportTrigger.js +1 -0
  23. package/ChartsToolbarPro/ChartsToolbarImageExportTrigger.mjs +1 -0
  24. package/ChartsToolbarPro/ChartsToolbarPrintExportTrigger.js +1 -0
  25. package/ChartsToolbarPro/ChartsToolbarPrintExportTrigger.mjs +1 -0
  26. package/ChartsToolbarPro/ChartsToolbarPro.d.mts +30 -0
  27. package/ChartsToolbarPro/ChartsToolbarPro.d.ts +30 -0
  28. package/ChartsToolbarPro/ChartsToolbarPro.js +66 -17
  29. package/ChartsToolbarPro/ChartsToolbarPro.mjs +66 -17
  30. package/ChartsToolbarPro/ChartsToolbarRangeButtonTrigger.d.mts +41 -0
  31. package/ChartsToolbarPro/ChartsToolbarRangeButtonTrigger.d.ts +41 -0
  32. package/ChartsToolbarPro/ChartsToolbarRangeButtonTrigger.js +156 -0
  33. package/ChartsToolbarPro/ChartsToolbarRangeButtonTrigger.mjs +150 -0
  34. package/ChartsToolbarPro/ChartsToolbarZoomInTrigger.js +1 -1
  35. package/ChartsToolbarPro/ChartsToolbarZoomInTrigger.mjs +1 -1
  36. package/ChartsToolbarPro/ChartsToolbarZoomOutTrigger.js +1 -1
  37. package/ChartsToolbarPro/ChartsToolbarZoomOutTrigger.mjs +1 -1
  38. package/ChartsToolbarPro/index.d.mts +1 -0
  39. package/ChartsToolbarPro/index.d.ts +1 -0
  40. package/ChartsToolbarPro/index.js +11 -0
  41. package/ChartsToolbarPro/index.mjs +1 -0
  42. package/ChartsToolbarPro/rangeButtonValueToZoom.d.mts +66 -0
  43. package/ChartsToolbarPro/rangeButtonValueToZoom.d.ts +66 -0
  44. package/ChartsToolbarPro/rangeButtonValueToZoom.js +217 -0
  45. package/ChartsToolbarPro/rangeButtonValueToZoom.mjs +212 -0
  46. package/Heatmap/Heatmap.js +4 -1
  47. package/Heatmap/Heatmap.mjs +4 -1
  48. package/LineChartPro/LineChartPro.js +20 -1
  49. package/LineChartPro/LineChartPro.mjs +20 -1
  50. package/ScatterChartPro/ScatterChartPro.js +20 -1
  51. package/ScatterChartPro/ScatterChartPro.mjs +20 -1
  52. package/index.d.mts +4 -0
  53. package/index.d.ts +4 -0
  54. package/index.js +45 -1
  55. package/index.mjs +5 -1
  56. package/internals/plugins/useChartProZoom/gestureHooks/useZoom.utils.js +3 -3
  57. package/internals/plugins/useChartProZoom/gestureHooks/useZoom.utils.mjs +3 -3
  58. package/internals/plugins/useChartProZoom/useChartProZoom.js +13 -4
  59. package/internals/plugins/useChartProZoom/useChartProZoom.mjs +13 -4
  60. package/internals/plugins/useChartProZoom/useChartProZoom.selectors.d.mts +3 -0
  61. package/internals/plugins/useChartProZoom/useChartProZoom.selectors.d.ts +3 -0
  62. package/internals/plugins/useChartProZoom/useChartProZoom.selectors.js +4 -3
  63. package/internals/plugins/useChartProZoom/useChartProZoom.selectors.mjs +3 -2
  64. package/internals/plugins/useChartProZoom/useChartProZoom.types.d.mts +10 -0
  65. package/internals/plugins/useChartProZoom/useChartProZoom.types.d.ts +10 -0
  66. package/models/seriesType/heatmap.d.mts +9 -1
  67. package/models/seriesType/heatmap.d.ts +9 -1
  68. package/package.json +62 -6
@@ -0,0 +1 @@
1
+ export * from '@mui/x-charts/ChartsRotationAxis';
@@ -0,0 +1 @@
1
+ export * from '@mui/x-charts/ChartsRotationAxis';
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _ChartsRotationAxis = require("@mui/x-charts/ChartsRotationAxis");
7
+ Object.keys(_ChartsRotationAxis).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _ChartsRotationAxis[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _ChartsRotationAxis[key];
14
+ }
15
+ });
16
+ });
@@ -0,0 +1,2 @@
1
+ // Re-export automatically generated, to customize, simply remove this line.
2
+ export * from '@mui/x-charts/ChartsRotationAxis';
@@ -75,6 +75,7 @@ process.env.NODE_ENV !== "production" ? ChartsToolbarImageExportTrigger.propType
75
75
  * A function to customize the rendering of the component.
76
76
  */
77
77
  render: _propTypes.default.oneOfType([_propTypes.default.element, _propTypes.default.func]),
78
+ size: _propTypes.default.oneOf(['large', 'medium', 'small']),
78
79
  style: _propTypes.default.object,
79
80
  tabIndex: _propTypes.default.number
80
81
  } : void 0;
@@ -67,6 +67,7 @@ process.env.NODE_ENV !== "production" ? ChartsToolbarImageExportTrigger.propType
67
67
  * A function to customize the rendering of the component.
68
68
  */
69
69
  render: PropTypes.oneOfType([PropTypes.element, PropTypes.func]),
70
+ size: PropTypes.oneOf(['large', 'medium', 'small']),
70
71
  style: PropTypes.object,
71
72
  tabIndex: PropTypes.number
72
73
  } : void 0;
@@ -73,6 +73,7 @@ process.env.NODE_ENV !== "production" ? ChartsToolbarPrintExportTrigger.propType
73
73
  * A function to customize the rendering of the component.
74
74
  */
75
75
  render: _propTypes.default.oneOfType([_propTypes.default.element, _propTypes.default.func]),
76
+ size: _propTypes.default.oneOf(['large', 'medium', 'small']),
76
77
  style: _propTypes.default.object,
77
78
  tabIndex: _propTypes.default.number
78
79
  } : void 0;
@@ -65,6 +65,7 @@ process.env.NODE_ENV !== "production" ? ChartsToolbarPrintExportTrigger.propType
65
65
  * A function to customize the rendering of the component.
66
66
  */
67
67
  render: PropTypes.oneOfType([PropTypes.element, PropTypes.func]),
68
+ size: PropTypes.oneOf(['large', 'medium', 'small']),
68
69
  style: PropTypes.object,
69
70
  tabIndex: PropTypes.number
70
71
  } : void 0;
@@ -1,9 +1,37 @@
1
1
  import { type ChartsToolbarProps } from '@mui/x-charts/Toolbar';
2
+ import { type AxisId } from '@mui/x-charts/internals';
3
+ import { type RangeButtonValue } from "./rangeButtonValueToZoom.mjs";
2
4
  import { type ChartsToolbarPrintExportOptions } from "./ChartsToolbarPrintExportTrigger.mjs";
3
5
  import { type ChartsToolbarImageExportOptions } from "./ChartsToolbarImageExportTrigger.mjs";
6
+ export type { RangeButtonFunctionParams } from "./rangeButtonValueToZoom.mjs";
7
+ export interface RangeButtonConfig {
8
+ /**
9
+ * The label displayed on the button (e.g., "1M", "3M", "1Y").
10
+ */
11
+ label: string;
12
+ /**
13
+ * The range value.
14
+ *
15
+ * - `{ unit, step }` — A calendar interval from the end of the data (e.g., `{ unit: 'month', step: 3 }` for 3 months).
16
+ * - `[start, end]` — An absolute date range.
17
+ * - `(params) => { start, end }` — A function that receives axis context (`scaleType`, `data`, `domain`) and returns zoom percentages (0-100).
18
+ * - `null` — Resets zoom to show all data.
19
+ */
20
+ value: RangeButtonValue;
21
+ }
4
22
  export interface ChartsToolbarProProps extends ChartsToolbarProps {
5
23
  printOptions?: ChartsToolbarPrintExportOptions;
6
24
  imageExportOptions?: ChartsToolbarImageExportOptions[];
25
+ /**
26
+ * Configuration for range buttons shown in the toolbar.
27
+ * Each button zooms the chart to a predefined time range from the end of the data.
28
+ */
29
+ rangeButtons?: RangeButtonConfig[];
30
+ /**
31
+ * The axis ID to apply range buttons to.
32
+ * Defaults to the first x-axis with zoom enabled and a time scale.
33
+ */
34
+ rangeButtonsAxisId?: AxisId;
7
35
  }
8
36
  /**
9
37
  * The chart toolbar component for the pro package.
@@ -11,6 +39,8 @@ export interface ChartsToolbarProProps extends ChartsToolbarProps {
11
39
  declare function ChartsToolbarPro({
12
40
  printOptions,
13
41
  imageExportOptions: rawImageExportOptions,
42
+ rangeButtons,
43
+ rangeButtonsAxisId,
14
44
  ...other
15
45
  }: ChartsToolbarProProps): import("react/jsx-runtime").JSX.Element | null;
16
46
  declare namespace ChartsToolbarPro {
@@ -1,9 +1,37 @@
1
1
  import { type ChartsToolbarProps } from '@mui/x-charts/Toolbar';
2
+ import { type AxisId } from '@mui/x-charts/internals';
3
+ import { type RangeButtonValue } from "./rangeButtonValueToZoom.js";
2
4
  import { type ChartsToolbarPrintExportOptions } from "./ChartsToolbarPrintExportTrigger.js";
3
5
  import { type ChartsToolbarImageExportOptions } from "./ChartsToolbarImageExportTrigger.js";
6
+ export type { RangeButtonFunctionParams } from "./rangeButtonValueToZoom.js";
7
+ export interface RangeButtonConfig {
8
+ /**
9
+ * The label displayed on the button (e.g., "1M", "3M", "1Y").
10
+ */
11
+ label: string;
12
+ /**
13
+ * The range value.
14
+ *
15
+ * - `{ unit, step }` — A calendar interval from the end of the data (e.g., `{ unit: 'month', step: 3 }` for 3 months).
16
+ * - `[start, end]` — An absolute date range.
17
+ * - `(params) => { start, end }` — A function that receives axis context (`scaleType`, `data`, `domain`) and returns zoom percentages (0-100).
18
+ * - `null` — Resets zoom to show all data.
19
+ */
20
+ value: RangeButtonValue;
21
+ }
4
22
  export interface ChartsToolbarProProps extends ChartsToolbarProps {
5
23
  printOptions?: ChartsToolbarPrintExportOptions;
6
24
  imageExportOptions?: ChartsToolbarImageExportOptions[];
25
+ /**
26
+ * Configuration for range buttons shown in the toolbar.
27
+ * Each button zooms the chart to a predefined time range from the end of the data.
28
+ */
29
+ rangeButtons?: RangeButtonConfig[];
30
+ /**
31
+ * The axis ID to apply range buttons to.
32
+ * Defaults to the first x-axis with zoom enabled and a time scale.
33
+ */
34
+ rangeButtonsAxisId?: AxisId;
7
35
  }
8
36
  /**
9
37
  * The chart toolbar component for the pro package.
@@ -11,6 +39,8 @@ export interface ChartsToolbarProProps extends ChartsToolbarProps {
11
39
  declare function ChartsToolbarPro({
12
40
  printOptions,
13
41
  imageExportOptions: rawImageExportOptions,
42
+ rangeButtons,
43
+ rangeButtonsAxisId,
14
44
  ...other
15
45
  }: ChartsToolbarProProps): import("react/jsx-runtime").JSX.Element | null;
16
46
  declare namespace ChartsToolbarPro {
@@ -11,6 +11,8 @@ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")
11
11
  var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
12
12
  var React = _interopRequireWildcard(require("react"));
13
13
  var _propTypes = _interopRequireDefault(require("prop-types"));
14
+ var _styles = require("@mui/material/styles");
15
+ var _ToggleButtonGroup = _interopRequireDefault(require("@mui/material/ToggleButtonGroup"));
14
16
  var _Toolbar = require("@mui/x-charts/Toolbar");
15
17
  var _internals = require("@mui/x-charts/internals");
16
18
  var _hooks = require("@mui/x-charts/hooks");
@@ -20,13 +22,25 @@ var _ChartsMenu = require("./internals/ChartsMenu");
20
22
  var _useChartProZoom = require("../internals/plugins/useChartProZoom");
21
23
  var _ChartsToolbarZoomInTrigger = require("./ChartsToolbarZoomInTrigger");
22
24
  var _ChartsToolbarZoomOutTrigger = require("./ChartsToolbarZoomOutTrigger");
25
+ var _ChartsToolbarRangeButtonTrigger = require("./ChartsToolbarRangeButtonTrigger");
23
26
  var _ChartsToolbarPrintExportTrigger = require("./ChartsToolbarPrintExportTrigger");
24
27
  var _ChartsToolbarImageExportTrigger = require("./ChartsToolbarImageExportTrigger");
25
28
  var _jsxRuntime = require("react/jsx-runtime");
26
- const _excluded = ["printOptions", "imageExportOptions"];
29
+ const _excluded = ["printOptions", "imageExportOptions", "rangeButtons", "rangeButtonsAxisId"];
27
30
  const DEFAULT_IMAGE_EXPORT_OPTIONS = [{
28
31
  type: 'image/png'
29
32
  }];
33
+ const RangeButtonGroup = (0, _styles.styled)(_ToggleButtonGroup.default, {
34
+ name: 'MuiChartsToolbarRangeButtons',
35
+ slot: 'Root'
36
+ })({
37
+ alignSelf: 'stretch',
38
+ '& .MuiToggleButton-root': {
39
+ fontSize: '0.75rem',
40
+ minWidth: 'unset',
41
+ border: 'none'
42
+ }
43
+ });
30
44
 
31
45
  /**
32
46
  * The chart toolbar component for the pro package.
@@ -34,7 +48,9 @@ const DEFAULT_IMAGE_EXPORT_OPTIONS = [{
34
48
  function ChartsToolbarPro(_ref) {
35
49
  let {
36
50
  printOptions,
37
- imageExportOptions: rawImageExportOptions
51
+ imageExportOptions: rawImageExportOptions,
52
+ rangeButtons,
53
+ rangeButtonsAxisId
38
54
  } = _ref,
39
55
  other = (0, _objectWithoutPropertiesLoose2.default)(_ref, _excluded);
40
56
  const {
@@ -56,29 +72,46 @@ function ChartsToolbarPro(_ref) {
56
72
  const showExportMenu = !printOptions?.disableToolbarButton || imageExportOptionList.length > 0;
57
73
  const children = [];
58
74
  if (isZoomEnabled) {
75
+ if (rangeButtons && rangeButtons.length > 0) {
76
+ children.push(/*#__PURE__*/(0, _jsxRuntime.jsx)(RangeButtonGroup, {
77
+ exclusive: true,
78
+ size: "small",
79
+ children: rangeButtons.map(rangeButton => /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsToolbarRangeButtonTrigger.ChartsToolbarRangeButtonTrigger, {
80
+ value: rangeButton.value,
81
+ label: rangeButton.label,
82
+ axisId: rangeButtonsAxisId,
83
+ children: rangeButton.label
84
+ }, rangeButton.label))
85
+ }, "range-buttons"));
86
+ children.push(/*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsToolbarDivider.ChartsToolbarDivider, {}, "range-divider"));
87
+ }
59
88
  const Tooltip = slots.baseTooltip;
60
89
  const ZoomOutIcon = slots.zoomOutIcon;
61
90
  const ZoomInIcon = slots.zoomInIcon;
62
91
  children.push(/*#__PURE__*/(0, _jsxRuntime.jsx)(Tooltip, (0, _extends2.default)({}, slotProps.baseTooltip, {
63
92
  title: localeText.zoomIn,
64
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsToolbarZoomInTrigger.ChartsToolbarZoomInTrigger, {
65
- render: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Toolbar.ToolbarButton, {
66
- size: "small"
67
- }),
68
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(ZoomInIcon, (0, _extends2.default)({
69
- fontSize: "small"
70
- }, slotProps.zoomInIcon))
93
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
94
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsToolbarZoomInTrigger.ChartsToolbarZoomInTrigger, {
95
+ render: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Toolbar.ToolbarButton, {
96
+ size: "small"
97
+ }),
98
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(ZoomInIcon, (0, _extends2.default)({
99
+ fontSize: "small"
100
+ }, slotProps.zoomInIcon))
101
+ })
71
102
  })
72
103
  }), "zoom-in"));
73
104
  children.push(/*#__PURE__*/(0, _jsxRuntime.jsx)(Tooltip, (0, _extends2.default)({}, slotProps.baseTooltip, {
74
105
  title: localeText.zoomOut,
75
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsToolbarZoomOutTrigger.ChartsToolbarZoomOutTrigger, {
76
- render: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Toolbar.ToolbarButton, {
77
- size: "small"
78
- }),
79
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(ZoomOutIcon, (0, _extends2.default)({
80
- fontSize: "small"
81
- }, slotProps.zoomOutIcon))
106
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
107
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsToolbarZoomOutTrigger.ChartsToolbarZoomOutTrigger, {
108
+ render: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Toolbar.ToolbarButton, {
109
+ size: "small"
110
+ }),
111
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(ZoomOutIcon, (0, _extends2.default)({
112
+ fontSize: "small"
113
+ }, slotProps.zoomOutIcon))
114
+ })
82
115
  })
83
116
  }), "zoom-out"));
84
117
  }
@@ -165,7 +198,23 @@ process.env.NODE_ENV !== "production" ? ChartsToolbarPro.propTypes = {
165
198
  quality: _propTypes.default.number,
166
199
  type: _propTypes.default.string.isRequired
167
200
  })),
168
- printOptions: _propTypes.default.object
201
+ printOptions: _propTypes.default.object,
202
+ /**
203
+ * Configuration for range buttons shown in the toolbar.
204
+ * Each button zooms the chart to a predefined time range from the end of the data.
205
+ */
206
+ rangeButtons: _propTypes.default.arrayOf(_propTypes.default.shape({
207
+ label: _propTypes.default.string.isRequired,
208
+ value: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.instanceOf(Date).isRequired), _propTypes.default.func, _propTypes.default.shape({
209
+ step: _propTypes.default.number,
210
+ unit: _propTypes.default.oneOf(['day', 'hour', 'microsecond', 'millisecond', 'minute', 'month', 'second', 'week', 'year']).isRequired
211
+ })])
212
+ })),
213
+ /**
214
+ * The axis ID to apply range buttons to.
215
+ * Defaults to the first x-axis with zoom enabled and a time scale.
216
+ */
217
+ rangeButtonsAxisId: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string])
169
218
  } : void 0;
170
219
  function isHideMenuKey(key) {
171
220
  return key === 'Tab' || key === 'Escape';
@@ -2,9 +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 = ["printOptions", "imageExportOptions"];
5
+ const _excluded = ["printOptions", "imageExportOptions", "rangeButtons", "rangeButtonsAxisId"];
6
6
  import * as React from 'react';
7
7
  import PropTypes from 'prop-types';
8
+ import { styled } from '@mui/material/styles';
9
+ import ToggleButtonGroup from '@mui/material/ToggleButtonGroup';
8
10
  import { Toolbar, ToolbarButton } from '@mui/x-charts/Toolbar';
9
11
  import { useChartsContext, useChartsSlots } from '@mui/x-charts/internals';
10
12
  import { useChartsLocalization } from '@mui/x-charts/hooks';
@@ -14,12 +16,24 @@ import { ChartsMenu } from "./internals/ChartsMenu.mjs";
14
16
  import { selectorChartZoomIsEnabled } from "../internals/plugins/useChartProZoom/index.mjs";
15
17
  import { ChartsToolbarZoomInTrigger } from "./ChartsToolbarZoomInTrigger.mjs";
16
18
  import { ChartsToolbarZoomOutTrigger } from "./ChartsToolbarZoomOutTrigger.mjs";
19
+ import { ChartsToolbarRangeButtonTrigger } from "./ChartsToolbarRangeButtonTrigger.mjs";
17
20
  import { ChartsToolbarPrintExportTrigger } from "./ChartsToolbarPrintExportTrigger.mjs";
18
21
  import { ChartsToolbarImageExportTrigger } from "./ChartsToolbarImageExportTrigger.mjs";
19
22
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
20
23
  const DEFAULT_IMAGE_EXPORT_OPTIONS = [{
21
24
  type: 'image/png'
22
25
  }];
26
+ const RangeButtonGroup = styled(ToggleButtonGroup, {
27
+ name: 'MuiChartsToolbarRangeButtons',
28
+ slot: 'Root'
29
+ })({
30
+ alignSelf: 'stretch',
31
+ '& .MuiToggleButton-root': {
32
+ fontSize: '0.75rem',
33
+ minWidth: 'unset',
34
+ border: 'none'
35
+ }
36
+ });
23
37
 
24
38
  /**
25
39
  * The chart toolbar component for the pro package.
@@ -27,7 +41,9 @@ const DEFAULT_IMAGE_EXPORT_OPTIONS = [{
27
41
  function ChartsToolbarPro(_ref) {
28
42
  let {
29
43
  printOptions,
30
- imageExportOptions: rawImageExportOptions
44
+ imageExportOptions: rawImageExportOptions,
45
+ rangeButtons,
46
+ rangeButtonsAxisId
31
47
  } = _ref,
32
48
  other = _objectWithoutPropertiesLoose(_ref, _excluded);
33
49
  const {
@@ -49,29 +65,46 @@ function ChartsToolbarPro(_ref) {
49
65
  const showExportMenu = !printOptions?.disableToolbarButton || imageExportOptionList.length > 0;
50
66
  const children = [];
51
67
  if (isZoomEnabled) {
68
+ if (rangeButtons && rangeButtons.length > 0) {
69
+ children.push(/*#__PURE__*/_jsx(RangeButtonGroup, {
70
+ exclusive: true,
71
+ size: "small",
72
+ children: rangeButtons.map(rangeButton => /*#__PURE__*/_jsx(ChartsToolbarRangeButtonTrigger, {
73
+ value: rangeButton.value,
74
+ label: rangeButton.label,
75
+ axisId: rangeButtonsAxisId,
76
+ children: rangeButton.label
77
+ }, rangeButton.label))
78
+ }, "range-buttons"));
79
+ children.push(/*#__PURE__*/_jsx(ChartsToolbarDivider, {}, "range-divider"));
80
+ }
52
81
  const Tooltip = slots.baseTooltip;
53
82
  const ZoomOutIcon = slots.zoomOutIcon;
54
83
  const ZoomInIcon = slots.zoomInIcon;
55
84
  children.push(/*#__PURE__*/_jsx(Tooltip, _extends({}, slotProps.baseTooltip, {
56
85
  title: localeText.zoomIn,
57
- children: /*#__PURE__*/_jsx(ChartsToolbarZoomInTrigger, {
58
- render: /*#__PURE__*/_jsx(ToolbarButton, {
59
- size: "small"
60
- }),
61
- children: /*#__PURE__*/_jsx(ZoomInIcon, _extends({
62
- fontSize: "small"
63
- }, slotProps.zoomInIcon))
86
+ children: /*#__PURE__*/_jsx("span", {
87
+ children: /*#__PURE__*/_jsx(ChartsToolbarZoomInTrigger, {
88
+ render: /*#__PURE__*/_jsx(ToolbarButton, {
89
+ size: "small"
90
+ }),
91
+ children: /*#__PURE__*/_jsx(ZoomInIcon, _extends({
92
+ fontSize: "small"
93
+ }, slotProps.zoomInIcon))
94
+ })
64
95
  })
65
96
  }), "zoom-in"));
66
97
  children.push(/*#__PURE__*/_jsx(Tooltip, _extends({}, slotProps.baseTooltip, {
67
98
  title: localeText.zoomOut,
68
- children: /*#__PURE__*/_jsx(ChartsToolbarZoomOutTrigger, {
69
- render: /*#__PURE__*/_jsx(ToolbarButton, {
70
- size: "small"
71
- }),
72
- children: /*#__PURE__*/_jsx(ZoomOutIcon, _extends({
73
- fontSize: "small"
74
- }, slotProps.zoomOutIcon))
99
+ children: /*#__PURE__*/_jsx("span", {
100
+ children: /*#__PURE__*/_jsx(ChartsToolbarZoomOutTrigger, {
101
+ render: /*#__PURE__*/_jsx(ToolbarButton, {
102
+ size: "small"
103
+ }),
104
+ children: /*#__PURE__*/_jsx(ZoomOutIcon, _extends({
105
+ fontSize: "small"
106
+ }, slotProps.zoomOutIcon))
107
+ })
75
108
  })
76
109
  }), "zoom-out"));
77
110
  }
@@ -158,7 +191,23 @@ process.env.NODE_ENV !== "production" ? ChartsToolbarPro.propTypes = {
158
191
  quality: PropTypes.number,
159
192
  type: PropTypes.string.isRequired
160
193
  })),
161
- printOptions: PropTypes.object
194
+ printOptions: PropTypes.object,
195
+ /**
196
+ * Configuration for range buttons shown in the toolbar.
197
+ * Each button zooms the chart to a predefined time range from the end of the data.
198
+ */
199
+ rangeButtons: PropTypes.arrayOf(PropTypes.shape({
200
+ label: PropTypes.string.isRequired,
201
+ value: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.instanceOf(Date).isRequired), PropTypes.func, PropTypes.shape({
202
+ step: PropTypes.number,
203
+ unit: PropTypes.oneOf(['day', 'hour', 'microsecond', 'millisecond', 'minute', 'month', 'second', 'week', 'year']).isRequired
204
+ })])
205
+ })),
206
+ /**
207
+ * The axis ID to apply range buttons to.
208
+ * Defaults to the first x-axis with zoom enabled and a time scale.
209
+ */
210
+ rangeButtonsAxisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string])
162
211
  } : void 0;
163
212
  export { ChartsToolbarPro };
164
213
  function isHideMenuKey(key) {
@@ -0,0 +1,41 @@
1
+ import * as React from 'react';
2
+ import { type ChartsSlotProps, type AxisId } from '@mui/x-charts/internals';
3
+ import { type RenderProp } from '@mui/x-internals/useComponentRenderer';
4
+ import { type RangeButtonValue } from "./rangeButtonValueToZoom.mjs";
5
+ export interface ChartsToolbarRangeButtonTriggerProps {
6
+ /**
7
+ * A function to customize the rendering of the component.
8
+ */
9
+ render?: RenderProp<ChartsSlotProps['baseToggleButton']>;
10
+ /**
11
+ * The range value. Specifies how far back from the end of the data to zoom.
12
+ *
13
+ * - `{ unit, step }` — A calendar interval from the end of the data (e.g., `{ unit: 'month', step: 3 }` for 3 months).
14
+ * - `[start, end]` — An absolute date range.
15
+ * - `(params) => { start, end }` — A function that receives axis context (`scaleType`, `data`, `domain`) and returns zoom percentages (0-100).
16
+ * - `null` — Resets zoom to show all data.
17
+ */
18
+ value: RangeButtonValue;
19
+ /**
20
+ * The axis ID to apply the range to.
21
+ * Defaults to the first x-axis with zoom enabled.
22
+ */
23
+ axisId?: AxisId;
24
+ /**
25
+ * The label used to identify the button for active-state tracking.
26
+ */
27
+ label: string;
28
+ /**
29
+ * The size of the button.
30
+ * @default 'small'
31
+ */
32
+ size?: 'small' | 'medium' | 'large';
33
+ }
34
+ /**
35
+ * A button that sets the chart zoom to a predefined range.
36
+ * It renders the `baseToggleButton` slot.
37
+ */
38
+ declare const ChartsToolbarRangeButtonTrigger: React.ForwardRefExoticComponent<ChartsToolbarRangeButtonTriggerProps & {
39
+ children?: React.ReactNode | undefined;
40
+ } & React.RefAttributes<HTMLButtonElement>>;
41
+ export { ChartsToolbarRangeButtonTrigger };
@@ -0,0 +1,41 @@
1
+ import * as React from 'react';
2
+ import { type ChartsSlotProps, type AxisId } from '@mui/x-charts/internals';
3
+ import { type RenderProp } from '@mui/x-internals/useComponentRenderer';
4
+ import { type RangeButtonValue } from "./rangeButtonValueToZoom.js";
5
+ export interface ChartsToolbarRangeButtonTriggerProps {
6
+ /**
7
+ * A function to customize the rendering of the component.
8
+ */
9
+ render?: RenderProp<ChartsSlotProps['baseToggleButton']>;
10
+ /**
11
+ * The range value. Specifies how far back from the end of the data to zoom.
12
+ *
13
+ * - `{ unit, step }` — A calendar interval from the end of the data (e.g., `{ unit: 'month', step: 3 }` for 3 months).
14
+ * - `[start, end]` — An absolute date range.
15
+ * - `(params) => { start, end }` — A function that receives axis context (`scaleType`, `data`, `domain`) and returns zoom percentages (0-100).
16
+ * - `null` — Resets zoom to show all data.
17
+ */
18
+ value: RangeButtonValue;
19
+ /**
20
+ * The axis ID to apply the range to.
21
+ * Defaults to the first x-axis with zoom enabled.
22
+ */
23
+ axisId?: AxisId;
24
+ /**
25
+ * The label used to identify the button for active-state tracking.
26
+ */
27
+ label: string;
28
+ /**
29
+ * The size of the button.
30
+ * @default 'small'
31
+ */
32
+ size?: 'small' | 'medium' | 'large';
33
+ }
34
+ /**
35
+ * A button that sets the chart zoom to a predefined range.
36
+ * It renders the `baseToggleButton` slot.
37
+ */
38
+ declare const ChartsToolbarRangeButtonTrigger: React.ForwardRefExoticComponent<ChartsToolbarRangeButtonTriggerProps & {
39
+ children?: React.ReactNode | undefined;
40
+ } & React.RefAttributes<HTMLButtonElement>>;
41
+ export { ChartsToolbarRangeButtonTrigger };
@@ -0,0 +1,156 @@
1
+ "use strict";
2
+ 'use client';
3
+
4
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
5
+ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
6
+ Object.defineProperty(exports, "__esModule", {
7
+ value: true
8
+ });
9
+ exports.ChartsToolbarRangeButtonTrigger = void 0;
10
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
11
+ var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
12
+ var React = _interopRequireWildcard(require("react"));
13
+ var _propTypes = _interopRequireDefault(require("prop-types"));
14
+ var _internals = require("@mui/x-charts/internals");
15
+ var _useComponentRenderer = require("@mui/x-internals/useComponentRenderer");
16
+ var _useChartProZoom = require("../internals/plugins/useChartProZoom");
17
+ var _rangeButtonValueToZoom = require("./rangeButtonValueToZoom");
18
+ var _jsxRuntime = require("react/jsx-runtime");
19
+ const _excluded = ["render", "value", "axisId", "label", "size"];
20
+ /**
21
+ * A button that sets the chart zoom to a predefined range.
22
+ * It renders the `baseToggleButton` slot.
23
+ */
24
+ const ChartsToolbarRangeButtonTrigger = exports.ChartsToolbarRangeButtonTrigger = /*#__PURE__*/React.forwardRef(function ChartsToolbarRangeButtonTrigger(_ref, ref) {
25
+ let {
26
+ render,
27
+ value,
28
+ axisId: axisIdProp,
29
+ label,
30
+ size = 'small'
31
+ } = _ref,
32
+ other = (0, _objectWithoutPropertiesLoose2.default)(_ref, _excluded);
33
+ const {
34
+ slots,
35
+ slotProps
36
+ } = (0, _internals.useChartsSlots)();
37
+ const {
38
+ instance,
39
+ store
40
+ } = (0, _internals.useChartsContext)();
41
+ const activeRangeButtonKey = store.use(_useChartProZoom.selectorChartActiveRangeButtonKey);
42
+ const canZoomOut = store.use(_useChartProZoom.selectorChartCanZoomOut);
43
+ const zoomOptionsLookup = store.use(_internals.selectorChartZoomOptionsLookup);
44
+ const rawXAxes = store.use(_internals.selectorChartRawXAxis);
45
+ const {
46
+ domains
47
+ } = store.use(_internals.selectorChartXAxisWithDomains);
48
+
49
+ // Resolve the target axis ID: use the prop, or find the first zoomable x-axis.
50
+ const resolvedAxisId = React.useMemo(() => {
51
+ if (axisIdProp !== undefined) {
52
+ return axisIdProp;
53
+ }
54
+ if (!rawXAxes) {
55
+ return undefined;
56
+ }
57
+ return rawXAxes.find(axis => zoomOptionsLookup[axis.id] !== undefined)?.id;
58
+ }, [axisIdProp, rawXAxes, zoomOptionsLookup]);
59
+
60
+ // Determine if the resolved axis is ordinal (band/point) to use index-based domain.
61
+ const resolvedAxis = React.useMemo(() => rawXAxes?.find(axis => axis.id === resolvedAxisId), [rawXAxes, resolvedAxisId]);
62
+ const isOrdinal = resolvedAxis?.scaleType === 'band' || resolvedAxis?.scaleType === 'point';
63
+
64
+ // Get the full domain for the target axis, ignoring the current zoom.
65
+ // For ordinal axes (band/point), use index-based range since domain values are categories.
66
+ const axisDomain = React.useMemo(() => {
67
+ if (resolvedAxisId === undefined) {
68
+ return undefined;
69
+ }
70
+ const domainDef = domains[resolvedAxisId];
71
+ if (!domainDef || domainDef.domain.length < 2) {
72
+ return undefined;
73
+ }
74
+ if (isOrdinal) {
75
+ return {
76
+ min: 0,
77
+ max: domainDef.domain.length - 1
78
+ };
79
+ }
80
+ const min = domainDef.domain[0];
81
+ const max = domainDef.domain[domainDef.domain.length - 1];
82
+ return {
83
+ min: Number(min),
84
+ max: Number(max)
85
+ };
86
+ }, [resolvedAxisId, domains, isOrdinal]);
87
+ const handleClick = React.useCallback(() => {
88
+ if (resolvedAxisId === undefined || !axisDomain) {
89
+ return;
90
+ }
91
+ const zoom = (0, _rangeButtonValueToZoom.rangeButtonValueToZoom)(value, {
92
+ scaleType: resolvedAxis?.scaleType ?? 'linear',
93
+ data: resolvedAxis?.data,
94
+ domain: axisDomain
95
+ });
96
+ instance.setAxisZoomData(resolvedAxisId, {
97
+ axisId: resolvedAxisId,
98
+ start: zoom.start,
99
+ end: zoom.end
100
+ });
101
+ instance.setActiveRangeButtonKey(label);
102
+ }, [resolvedAxisId, resolvedAxis, axisDomain, value, instance, label]);
103
+
104
+ // Determine if this button is selected.
105
+ // When explicitly clicked, activeRangeButtonKey matches the label.
106
+ // When no button has been clicked and zoom is at full range, the null-value button is active.
107
+ const isActive = activeRangeButtonKey === label || activeRangeButtonKey === null && value === null && !canZoomOut;
108
+ const element = (0, _useComponentRenderer.useComponentRenderer)(slots.baseToggleButton, render, (0, _extends2.default)({}, slotProps.baseToggleButton, {
109
+ onClick: handleClick,
110
+ selected: isActive,
111
+ value: label,
112
+ size
113
+ }, other, {
114
+ ref
115
+ }));
116
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(React.Fragment, {
117
+ children: element
118
+ });
119
+ });
120
+ if (process.env.NODE_ENV !== "production") ChartsToolbarRangeButtonTrigger.displayName = "ChartsToolbarRangeButtonTrigger";
121
+ process.env.NODE_ENV !== "production" ? ChartsToolbarRangeButtonTrigger.propTypes = {
122
+ // ----------------------------- Warning --------------------------------
123
+ // | These PropTypes are generated from the TypeScript type definitions |
124
+ // | To update them edit the TypeScript types and run "pnpm proptypes" |
125
+ // ----------------------------------------------------------------------
126
+ /**
127
+ * The axis ID to apply the range to.
128
+ * Defaults to the first x-axis with zoom enabled.
129
+ */
130
+ axisId: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]),
131
+ /**
132
+ * The label used to identify the button for active-state tracking.
133
+ */
134
+ label: _propTypes.default.string.isRequired,
135
+ /**
136
+ * A function to customize the rendering of the component.
137
+ */
138
+ render: _propTypes.default.oneOfType([_propTypes.default.element, _propTypes.default.func]),
139
+ /**
140
+ * The size of the button.
141
+ * @default 'small'
142
+ */
143
+ size: _propTypes.default.oneOf(['large', 'medium', 'small']),
144
+ /**
145
+ * The range value. Specifies how far back from the end of the data to zoom.
146
+ *
147
+ * - `{ unit, step }` — A calendar interval from the end of the data (e.g., `{ unit: 'month', step: 3 }` for 3 months).
148
+ * - `[start, end]` — An absolute date range.
149
+ * - `(params) => { start, end }` — A function that receives axis context (`scaleType`, `data`, `domain`) and returns zoom percentages (0-100).
150
+ * - `null` — Resets zoom to show all data.
151
+ */
152
+ value: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.instanceOf(Date).isRequired), _propTypes.default.func, _propTypes.default.shape({
153
+ step: _propTypes.default.number,
154
+ unit: _propTypes.default.oneOf(['day', 'hour', 'microsecond', 'millisecond', 'minute', 'month', 'second', 'week', 'year']).isRequired
155
+ })])
156
+ } : void 0;