@mui/x-charts 6.0.0-alpha.6 → 6.0.0-alpha.8

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 (142) hide show
  1. package/BarChart/BarChart.d.ts +19 -2
  2. package/BarChart/BarChart.js +84 -22
  3. package/BarChart/BarElement.d.ts +22 -0
  4. package/BarChart/BarElement.js +21 -10
  5. package/BarChart/BarPlot.d.ts +14 -1
  6. package/BarChart/BarPlot.js +48 -19
  7. package/BarChart/extremums.js +19 -3
  8. package/BarChart/formatter.js +3 -1
  9. package/CHANGELOG.md +213 -28
  10. package/ChartsAxis/ChartsAxis.d.ts +11 -1
  11. package/ChartsAxis/ChartsAxis.js +51 -6
  12. package/ChartsAxisHighlight/ChartsAxisHighlight.d.ts +3 -2
  13. package/ChartsAxisHighlight/ChartsAxisHighlight.js +11 -3
  14. package/ChartsLegend/ChartsLegend.d.ts +25 -2
  15. package/ChartsLegend/ChartsLegend.js +49 -17
  16. package/ChartsTooltip/ChartsAxisTooltipContent.js +13 -9
  17. package/ChartsTooltip/ChartsTooltipTable.d.ts +2 -9
  18. package/ChartsXAxis/ChartsXAxis.js +44 -9
  19. package/ChartsYAxis/ChartsYAxis.js +44 -9
  20. package/LineChart/AreaElement.d.ts +22 -0
  21. package/LineChart/AreaElement.js +31 -11
  22. package/LineChart/AreaPlot.d.ts +14 -1
  23. package/LineChart/AreaPlot.js +29 -3
  24. package/LineChart/LineChart.d.ts +20 -2
  25. package/LineChart/LineChart.js +63 -11
  26. package/LineChart/LineElement.d.ts +22 -0
  27. package/LineChart/LineElement.js +31 -10
  28. package/LineChart/LinePlot.d.ts +14 -1
  29. package/LineChart/LinePlot.js +35 -4
  30. package/LineChart/MarkPlot.d.ts +24 -1
  31. package/LineChart/MarkPlot.js +29 -4
  32. package/PieChart/PieArcLabel.js +0 -1
  33. package/PieChart/PieChart.d.ts +14 -2
  34. package/PieChart/PieChart.js +52 -10
  35. package/PieChart/PiePlot.d.ts +27 -1
  36. package/PieChart/PiePlot.js +29 -6
  37. package/ScatterChart/ScatterChart.d.ts +18 -2
  38. package/ScatterChart/ScatterChart.js +56 -10
  39. package/ScatterChart/ScatterPlot.d.ts +24 -1
  40. package/ScatterChart/ScatterPlot.js +28 -4
  41. package/SparkLineChart/SparkLineChart.d.ts +18 -0
  42. package/SparkLineChart/SparkLineChart.js +29 -6
  43. package/colorPalettes/colorPalettes.js +2 -2
  44. package/context/CartesianContextProvider.js +18 -12
  45. package/esm/BarChart/BarChart.js +88 -26
  46. package/esm/BarChart/BarElement.js +21 -11
  47. package/esm/BarChart/BarPlot.js +49 -20
  48. package/esm/BarChart/extremums.js +18 -2
  49. package/esm/BarChart/formatter.js +3 -1
  50. package/esm/ChartsAxis/ChartsAxis.js +51 -6
  51. package/esm/ChartsAxisHighlight/ChartsAxisHighlight.js +11 -3
  52. package/esm/ChartsLegend/ChartsLegend.js +47 -14
  53. package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +13 -9
  54. package/esm/ChartsXAxis/ChartsXAxis.js +45 -9
  55. package/esm/ChartsYAxis/ChartsYAxis.js +45 -9
  56. package/esm/LineChart/AreaElement.js +31 -11
  57. package/esm/LineChart/AreaPlot.js +31 -4
  58. package/esm/LineChart/LineChart.js +63 -11
  59. package/esm/LineChart/LineElement.js +31 -11
  60. package/esm/LineChart/LinePlot.js +43 -8
  61. package/esm/LineChart/MarkPlot.js +32 -5
  62. package/esm/PieChart/PieArcLabel.js +0 -1
  63. package/esm/PieChart/PieChart.js +52 -10
  64. package/esm/PieChart/PiePlot.js +31 -6
  65. package/esm/ScatterChart/ScatterChart.js +56 -10
  66. package/esm/ScatterChart/ScatterPlot.js +29 -4
  67. package/esm/SparkLineChart/SparkLineChart.js +29 -6
  68. package/esm/colorPalettes/colorPalettes.js +2 -2
  69. package/esm/context/CartesianContextProvider.js +18 -12
  70. package/esm/hooks/useAxisEvents.js +21 -38
  71. package/esm/hooks/useTicks.js +11 -8
  72. package/esm/internals/components/AxisSharedComponents.js +10 -10
  73. package/hooks/useAxisEvents.js +21 -38
  74. package/hooks/useTicks.d.ts +20 -5
  75. package/hooks/useTicks.js +11 -8
  76. package/index.js +1 -1
  77. package/internals/components/AxisSharedComponents.d.ts +4 -4
  78. package/internals/components/AxisSharedComponents.js +15 -15
  79. package/internals/defaultizeColor.d.ts +1 -0
  80. package/legacy/BarChart/BarChart.js +93 -29
  81. package/legacy/BarChart/BarElement.js +20 -10
  82. package/legacy/BarChart/BarPlot.js +49 -20
  83. package/legacy/BarChart/extremums.js +22 -2
  84. package/legacy/BarChart/formatter.js +3 -1
  85. package/legacy/ChartsAxis/ChartsAxis.js +51 -6
  86. package/legacy/ChartsAxisHighlight/ChartsAxisHighlight.js +11 -3
  87. package/legacy/ChartsLegend/ChartsLegend.js +46 -15
  88. package/legacy/ChartsTooltip/ChartsAxisTooltipContent.js +13 -9
  89. package/legacy/ChartsXAxis/ChartsXAxis.js +45 -9
  90. package/legacy/ChartsYAxis/ChartsYAxis.js +45 -9
  91. package/legacy/LineChart/AreaElement.js +30 -10
  92. package/legacy/LineChart/AreaPlot.js +29 -4
  93. package/legacy/LineChart/LineChart.js +63 -11
  94. package/legacy/LineChart/LineElement.js +30 -10
  95. package/legacy/LineChart/LinePlot.js +36 -5
  96. package/legacy/LineChart/MarkPlot.js +30 -5
  97. package/legacy/PieChart/PieArcLabel.js +0 -1
  98. package/legacy/PieChart/PieChart.js +52 -10
  99. package/legacy/PieChart/PiePlot.js +29 -6
  100. package/legacy/ScatterChart/ScatterChart.js +56 -10
  101. package/legacy/ScatterChart/ScatterPlot.js +27 -4
  102. package/legacy/SparkLineChart/SparkLineChart.js +29 -6
  103. package/legacy/colorPalettes/colorPalettes.js +2 -2
  104. package/legacy/context/CartesianContextProvider.js +18 -12
  105. package/legacy/hooks/useAxisEvents.js +21 -37
  106. package/legacy/hooks/useTicks.js +11 -11
  107. package/legacy/index.js +1 -1
  108. package/legacy/internals/components/AxisSharedComponents.js +10 -10
  109. package/models/axis.d.ts +24 -1
  110. package/models/seriesType/bar.d.ts +6 -1
  111. package/modern/BarChart/BarChart.js +85 -23
  112. package/modern/BarChart/BarElement.js +20 -11
  113. package/modern/BarChart/BarPlot.js +48 -19
  114. package/modern/BarChart/extremums.js +18 -2
  115. package/modern/BarChart/formatter.js +3 -1
  116. package/modern/ChartsAxis/ChartsAxis.js +51 -6
  117. package/modern/ChartsAxisHighlight/ChartsAxisHighlight.js +11 -3
  118. package/modern/ChartsLegend/ChartsLegend.js +46 -14
  119. package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +13 -9
  120. package/modern/ChartsXAxis/ChartsXAxis.js +44 -9
  121. package/modern/ChartsYAxis/ChartsYAxis.js +44 -9
  122. package/modern/LineChart/AreaElement.js +30 -11
  123. package/modern/LineChart/AreaPlot.js +31 -4
  124. package/modern/LineChart/LineChart.js +63 -11
  125. package/modern/LineChart/LineElement.js +30 -11
  126. package/modern/LineChart/LinePlot.js +37 -5
  127. package/modern/LineChart/MarkPlot.js +31 -5
  128. package/modern/PieChart/PieArcLabel.js +0 -1
  129. package/modern/PieChart/PieChart.js +52 -10
  130. package/modern/PieChart/PiePlot.js +30 -6
  131. package/modern/ScatterChart/ScatterChart.js +56 -10
  132. package/modern/ScatterChart/ScatterPlot.js +28 -4
  133. package/modern/SparkLineChart/SparkLineChart.js +29 -6
  134. package/modern/colorPalettes/colorPalettes.js +2 -2
  135. package/modern/context/CartesianContextProvider.js +18 -12
  136. package/modern/hooks/useAxisEvents.js +21 -38
  137. package/modern/hooks/useTicks.js +11 -8
  138. package/modern/index.js +1 -1
  139. package/modern/internals/components/AxisSharedComponents.js +10 -10
  140. package/package.json +5 -5
  141. package/themeAugmentation/components.d.ts +0 -10
  142. package/themeAugmentation/overrides.d.ts +0 -2
@@ -1,8 +1,9 @@
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"];
3
+ var _excluded = ["id", "dataIndex", "classes", "color", "highlightScope", "slots", "slotProps"];
4
4
  import * as React from 'react';
5
5
  import composeClasses from '@mui/utils/composeClasses';
6
+ import { useSlotProps } from '@mui/base/utils';
6
7
  import generateUtilityClass from '@mui/utils/generateUtilityClass';
7
8
  import { styled } from '@mui/material/styles';
8
9
  import { color as d3Color } from 'd3-color';
@@ -22,7 +23,7 @@ var useUtilityClasses = function useUtilityClasses(ownerState) {
22
23
  };
23
24
  return composeClasses(slots, getBarElementUtilityClass, classes);
24
25
  };
25
- var BarElementPath = styled('rect', {
26
+ export var BarElementPath = styled('rect', {
26
27
  name: 'MuiBarElement',
27
28
  slot: 'Root',
28
29
  overridesResolver: function overridesResolver(_, styles) {
@@ -39,11 +40,14 @@ var BarElementPath = styled('rect', {
39
40
  };
40
41
  });
41
42
  export function BarElement(props) {
43
+ var _slots$bar;
42
44
  var id = props.id,
43
45
  dataIndex = props.dataIndex,
44
46
  innerClasses = props.classes,
45
47
  color = props.color,
46
48
  highlightScope = props.highlightScope,
49
+ slots = props.slots,
50
+ slotProps = props.slotProps,
47
51
  other = _objectWithoutProperties(props, _excluded);
48
52
  var getInteractionItemProps = useInteractionItemProps(highlightScope);
49
53
  var _React$useContext = React.useContext(InteractionContext),
@@ -67,12 +71,18 @@ export function BarElement(props) {
67
71
  isHighlighted: isHighlighted
68
72
  };
69
73
  var classes = useUtilityClasses(ownerState);
70
- return /*#__PURE__*/_jsx(BarElementPath, _extends({}, other, {
71
- ownerState: ownerState,
72
- className: classes.root
73
- }, getInteractionItemProps({
74
- type: 'bar',
75
- seriesId: id,
76
- dataIndex: dataIndex
77
- })));
74
+ var Bar = (_slots$bar = slots == null ? void 0 : slots.bar) != null ? _slots$bar : BarElementPath;
75
+ var barProps = useSlotProps({
76
+ elementType: Bar,
77
+ externalSlotProps: slotProps == null ? void 0 : slotProps.bar,
78
+ additionalProps: _extends({}, other, getInteractionItemProps({
79
+ type: 'bar',
80
+ seriesId: id,
81
+ dataIndex: dataIndex
82
+ }), {
83
+ className: classes.root
84
+ }),
85
+ ownerState: ownerState
86
+ });
87
+ return /*#__PURE__*/_jsx(Bar, _extends({}, barProps));
78
88
  }
@@ -1,5 +1,7 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
1
2
  import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
3
  import * as React from 'react';
4
+ import PropTypes from 'prop-types';
3
5
  import { SeriesContext } from '../context/SeriesContextProvider';
4
6
  import { CartesianContext } from '../context/CartesianContextProvider';
5
7
  import { BarElement } from './BarElement';
@@ -32,7 +34,7 @@ function getBandSize(_ref) {
32
34
  offset: offset
33
35
  };
34
36
  }
35
- export function BarPlot() {
37
+ function BarPlot(props) {
36
38
  var seriesData = React.useContext(SeriesContext).bar;
37
39
  var axisData = React.useContext(CartesianContext);
38
40
  if (seriesData === undefined) {
@@ -55,45 +57,72 @@ export function BarPlot() {
55
57
  var yAxisKey = (_series$seriesId$yAxi = series[seriesId].yAxisKey) != null ? _series$seriesId$yAxi : defaultYAxisId;
56
58
  var xAxisConfig = xAxis[xAxisKey];
57
59
  var yAxisConfig = yAxis[yAxisKey];
58
- if (!isBandScaleConfig(xAxisConfig)) {
59
- throw new Error("Axis with id \"".concat(xAxisKey, "\" shoud be of type \"band\" to display the bar series of id \"").concat(seriesId, "\""));
60
- }
61
- if (xAxis[xAxisKey].data === undefined) {
62
- throw new Error("Axis with id \"".concat(xAxisKey, "\" shoud have data property"));
60
+ var verticalLayout = series[seriesId].layout === 'vertical';
61
+ var baseScaleConfig;
62
+ if (verticalLayout) {
63
+ if (!isBandScaleConfig(xAxisConfig)) {
64
+ throw new Error("Axis with id \"".concat(xAxisKey, "\" shoud be of type \"band\" to display the bar series of id \"").concat(seriesId, "\""));
65
+ }
66
+ if (xAxis[xAxisKey].data === undefined) {
67
+ throw new Error("Axis with id \"".concat(xAxisKey, "\" shoud have data property"));
68
+ }
69
+ baseScaleConfig = xAxisConfig;
70
+ } else {
71
+ if (!isBandScaleConfig(yAxisConfig)) {
72
+ throw new Error("Axis with id \"".concat(yAxisKey, "\" shoud be of type \"band\" to display the bar series of id \"").concat(seriesId, "\""));
73
+ }
74
+ if (yAxis[yAxisKey].data === undefined) {
75
+ throw new Error("Axis with id \"".concat(xAxisKey, "\" shoud have data property"));
76
+ }
77
+ baseScaleConfig = yAxisConfig;
63
78
  }
64
79
  var xScale = xAxisConfig.scale;
65
80
  var yScale = yAxisConfig.scale;
66
-
67
- // Currently assuming all bars are vertical
68
- var bandWidth = xScale.bandwidth();
81
+ var bandWidth = baseScaleConfig.scale.bandwidth();
69
82
  var _getBandSize = getBandSize({
70
83
  bandWidth: bandWidth,
71
84
  numberOfGroups: stackingGroups.length,
72
- gapRatio: xAxisConfig.barGapRatio
85
+ gapRatio: baseScaleConfig.barGapRatio
73
86
  }),
74
87
  barWidth = _getBandSize.barWidth,
75
88
  offset = _getBandSize.offset;
76
-
77
- // @ts-ignore TODO: fix when adding a correct API for customisation
89
+ var barOffset = groupIndex * (barWidth + offset);
78
90
  var _series$seriesId = series[seriesId],
79
91
  stackedData = _series$seriesId.stackedData,
80
92
  color = _series$seriesId.color;
81
93
  return stackedData.map(function (values, dataIndex) {
82
- var _xAxis$xAxisKey$data;
94
+ var _xAxis$xAxisKey$data, _yAxis$yAxisKey$data;
83
95
  var baseline = Math.min.apply(Math, _toConsumableArray(values));
84
96
  var value = Math.max.apply(Math, _toConsumableArray(values));
85
- return /*#__PURE__*/_jsx(BarElement, {
97
+ return /*#__PURE__*/_jsx(BarElement, _extends({
86
98
  id: seriesId,
87
99
  dataIndex: dataIndex,
88
- x: xScale((_xAxis$xAxisKey$data = xAxis[xAxisKey].data) == null ? void 0 : _xAxis$xAxisKey$data[dataIndex]) + groupIndex * (barWidth + offset),
89
- y: yScale(value),
90
- height: yScale(baseline) - yScale(value),
91
- width: barWidth,
100
+ x: verticalLayout ? xScale((_xAxis$xAxisKey$data = xAxis[xAxisKey].data) == null ? void 0 : _xAxis$xAxisKey$data[dataIndex]) + barOffset : xScale(baseline),
101
+ y: verticalLayout ? yScale(value) : yScale((_yAxis$yAxisKey$data = yAxis[yAxisKey].data) == null ? void 0 : _yAxis$yAxisKey$data[dataIndex]) + barOffset,
102
+ height: verticalLayout ? Math.abs(yScale(baseline) - yScale(value)) : barWidth,
103
+ width: verticalLayout ? barWidth : Math.abs(xScale(baseline) - xScale(value)),
92
104
  color: color,
93
105
  highlightScope: series[seriesId].highlightScope
94
- }, "".concat(seriesId, "-").concat(dataIndex));
106
+ }, props), "".concat(seriesId, "-").concat(dataIndex));
95
107
  });
96
108
  });
97
109
  })
98
110
  });
99
- }
111
+ }
112
+ process.env.NODE_ENV !== "production" ? BarPlot.propTypes = {
113
+ // ----------------------------- Warning --------------------------------
114
+ // | These PropTypes are generated from the TypeScript type definitions |
115
+ // | To update them edit the TypeScript types and run "yarn proptypes" |
116
+ // ----------------------------------------------------------------------
117
+ /**
118
+ * The props used for each component slot.
119
+ * @default {}
120
+ */
121
+ slotProps: PropTypes.object,
122
+ /**
123
+ * Overridable component slots.
124
+ * @default {}
125
+ */
126
+ slots: PropTypes.object
127
+ } : void 0;
128
+ export { BarPlot };
@@ -1,13 +1,13 @@
1
1
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
2
  import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
3
- export var getExtremumX = function getExtremumX(params) {
3
+ var getBaseExtremum = function getBaseExtremum(params) {
4
4
  var _axis$data, _axis$data2;
5
5
  var axis = params.axis;
6
6
  var minX = Math.min.apply(Math, _toConsumableArray((_axis$data = axis.data) != null ? _axis$data : []));
7
7
  var maxX = Math.max.apply(Math, _toConsumableArray((_axis$data2 = axis.data) != null ? _axis$data2 : []));
8
8
  return [minX, maxX];
9
9
  };
10
- export var getExtremumY = function getExtremumY(params) {
10
+ var getValueExtremum = function getValueExtremum(params) {
11
11
  var series = params.series,
12
12
  axis = params.axis,
13
13
  isDefaultAxis = params.isDefaultAxis;
@@ -22,4 +22,24 @@ export var getExtremumY = function getExtremumY(params) {
22
22
  seriesMax = _series$seriesId$stac2[1];
23
23
  return [acc[0] === null ? seriesMin : Math.min(seriesMin, acc[0]), acc[1] === null ? seriesMax : Math.max(seriesMax, acc[1])];
24
24
  }, [null, null]);
25
+ };
26
+ export var getExtremumX = function getExtremumX(params) {
27
+ // Notice that bar should be all horizontal or all vertical.
28
+ // Don't think it's a problem for now
29
+ var isHorizontal = Object.keys(params.series).some(function (seriesId) {
30
+ return params.series[seriesId].layout === 'horizontal';
31
+ });
32
+ if (isHorizontal) {
33
+ return getValueExtremum(params);
34
+ }
35
+ return getBaseExtremum(params);
36
+ };
37
+ export var getExtremumY = function getExtremumY(params) {
38
+ var isHorizontal = Object.keys(params.series).some(function (seriesId) {
39
+ return params.series[seriesId].layout === 'horizontal';
40
+ });
41
+ if (isHorizontal) {
42
+ return getBaseExtremum(params);
43
+ }
44
+ return getValueExtremum(params);
25
45
  };
@@ -38,7 +38,9 @@ var formatter = function formatter(params, dataset) {
38
38
  })).order(stackingOrder).offset(stackingOffset)(d3Dataset);
39
39
  ids.forEach(function (id, index) {
40
40
  var dataKey = series[id].dataKey;
41
- completedSeries[id] = _extends({}, series[id], {
41
+ completedSeries[id] = _extends({
42
+ layout: 'vertical'
43
+ }, series[id], {
42
44
  data: dataKey ? dataset.map(function (d) {
43
45
  return d[dataKey];
44
46
  }) : series[id].data,
@@ -16,11 +16,22 @@ var getAxisId = function getAxisId(propsValue) {
16
16
  }
17
17
  return propsValue;
18
18
  };
19
+ var mergeProps = function mergeProps(axisConfig, slots, slotProps) {
20
+ return _typeof(axisConfig) === 'object' ? _extends({}, axisConfig, {
21
+ slots: _extends({}, slots, axisConfig == null ? void 0 : axisConfig.slots),
22
+ slotProps: _extends({}, slotProps, axisConfig == null ? void 0 : axisConfig.slotProps)
23
+ }) : {
24
+ slots: slots,
25
+ slotProps: slotProps
26
+ };
27
+ };
19
28
  function ChartsAxis(props) {
20
29
  var topAxis = props.topAxis,
21
30
  leftAxis = props.leftAxis,
22
31
  rightAxis = props.rightAxis,
23
- bottomAxis = props.bottomAxis;
32
+ bottomAxis = props.bottomAxis,
33
+ slots = props.slots,
34
+ slotProps = props.slotProps;
24
35
  var _React$useContext = React.useContext(CartesianContext),
25
36
  xAxis = _React$useContext.xAxis,
26
37
  xAxisIds = _React$useContext.xAxisIds,
@@ -46,20 +57,24 @@ function ChartsAxis(props) {
46
57
  if (bottomId !== null && !xAxis[bottomId]) {
47
58
  throw Error("MUI: id used for bottom axis \"".concat(bottomId, "\" is not defined"));
48
59
  }
60
+ var topAxisProps = mergeProps(topAxis, slots, slotProps);
61
+ var bottomAxisProps = mergeProps(bottomAxis, slots, slotProps);
62
+ var leftAxisProps = mergeProps(leftAxis, slots, slotProps);
63
+ var rightAxisProps = mergeProps(rightAxis, slots, slotProps);
49
64
  return /*#__PURE__*/_jsxs(React.Fragment, {
50
- children: [topId && /*#__PURE__*/_jsx(ChartsXAxis, _extends({
65
+ children: [topId && /*#__PURE__*/_jsx(ChartsXAxis, _extends({}, topAxisProps, {
51
66
  position: "top",
52
67
  axisId: topId
53
- }, _typeof(topAxis) === 'object' ? topAxis : {})), bottomId && /*#__PURE__*/_jsx(ChartsXAxis, _extends({
68
+ })), bottomId && /*#__PURE__*/_jsx(ChartsXAxis, _extends({}, bottomAxisProps, {
54
69
  position: "bottom",
55
70
  axisId: bottomId
56
- }, _typeof(bottomAxis) === 'object' ? bottomAxis : {})), leftId && /*#__PURE__*/_jsx(ChartsYAxis, _extends({
71
+ })), leftId && /*#__PURE__*/_jsx(ChartsYAxis, _extends({}, leftAxisProps, {
57
72
  position: "left",
58
73
  axisId: leftId
59
- }, _typeof(leftAxis) === 'object' ? leftAxis : {})), rightId && /*#__PURE__*/_jsx(ChartsYAxis, _extends({
74
+ })), rightId && /*#__PURE__*/_jsx(ChartsYAxis, _extends({}, rightAxisProps, {
60
75
  position: "right",
61
76
  axisId: rightId
62
- }, _typeof(rightAxis) === 'object' ? rightAxis : {}))]
77
+ }))]
63
78
  });
64
79
  }
65
80
  process.env.NODE_ENV !== "production" ? ChartsAxis.propTypes = {
@@ -81,8 +96,13 @@ process.env.NODE_ENV !== "production" ? ChartsAxis.propTypes = {
81
96
  label: PropTypes.string,
82
97
  labelFontSize: PropTypes.number,
83
98
  position: PropTypes.oneOf(['bottom', 'top']),
99
+ slotProps: PropTypes.object,
100
+ slots: PropTypes.object,
84
101
  stroke: PropTypes.string,
85
102
  tickFontSize: PropTypes.number,
103
+ tickMaxStep: PropTypes.number,
104
+ tickMinStep: PropTypes.number,
105
+ tickNumber: PropTypes.number,
86
106
  tickSize: PropTypes.number
87
107
  }), PropTypes.string]),
88
108
  /**
@@ -99,8 +119,13 @@ process.env.NODE_ENV !== "production" ? ChartsAxis.propTypes = {
99
119
  label: PropTypes.string,
100
120
  labelFontSize: PropTypes.number,
101
121
  position: PropTypes.oneOf(['left', 'right']),
122
+ slotProps: PropTypes.object,
123
+ slots: PropTypes.object,
102
124
  stroke: PropTypes.string,
103
125
  tickFontSize: PropTypes.number,
126
+ tickMaxStep: PropTypes.number,
127
+ tickMinStep: PropTypes.number,
128
+ tickNumber: PropTypes.number,
104
129
  tickSize: PropTypes.number
105
130
  }), PropTypes.string]),
106
131
  /**
@@ -117,10 +142,25 @@ process.env.NODE_ENV !== "production" ? ChartsAxis.propTypes = {
117
142
  label: PropTypes.string,
118
143
  labelFontSize: PropTypes.number,
119
144
  position: PropTypes.oneOf(['left', 'right']),
145
+ slotProps: PropTypes.object,
146
+ slots: PropTypes.object,
120
147
  stroke: PropTypes.string,
121
148
  tickFontSize: PropTypes.number,
149
+ tickMaxStep: PropTypes.number,
150
+ tickMinStep: PropTypes.number,
151
+ tickNumber: PropTypes.number,
122
152
  tickSize: PropTypes.number
123
153
  }), PropTypes.string]),
154
+ /**
155
+ * The props used for each component slot.
156
+ * @default {}
157
+ */
158
+ slotProps: PropTypes.object,
159
+ /**
160
+ * Overridable component slots.
161
+ * @default {}
162
+ */
163
+ slots: PropTypes.object,
124
164
  /**
125
165
  * Indicate which axis to display the top of the charts.
126
166
  * Can be a string (the id of the axis) or an object `ChartsXAxisProps`.
@@ -135,8 +175,13 @@ process.env.NODE_ENV !== "production" ? ChartsAxis.propTypes = {
135
175
  label: PropTypes.string,
136
176
  labelFontSize: PropTypes.number,
137
177
  position: PropTypes.oneOf(['bottom', 'top']),
178
+ slotProps: PropTypes.object,
179
+ slots: PropTypes.object,
138
180
  stroke: PropTypes.string,
139
181
  tickFontSize: PropTypes.number,
182
+ tickMaxStep: PropTypes.number,
183
+ tickMinStep: PropTypes.number,
184
+ tickNumber: PropTypes.number,
140
185
  tickSize: PropTypes.number
141
186
  }), PropTypes.string])
142
187
  } : void 0;
@@ -21,6 +21,7 @@ function ChartsAxisHighlight(props) {
21
21
  var _React$useContext2 = React.useContext(InteractionContext),
22
22
  axis = _React$useContext2.axis;
23
23
  var getXPosition = getValueToPositionMapper(xScale);
24
+ var getYPosition = getValueToPositionMapper(yScale);
24
25
  return /*#__PURE__*/_jsxs(React.Fragment, {
25
26
  children: [xAxisHighlight === 'band' && axis.x !== null && isBandScale(xScale) && /*#__PURE__*/_jsx("path", {
26
27
  d: "M ".concat(xScale(axis.x.value) - (xScale.step() - xScale.bandwidth()) / 2, " ").concat(yScale.range()[0], " l ").concat(xScale.step(), " 0 l 0 ").concat(yScale.range()[1] - yScale.range()[0], " l ").concat(-xScale.step(), " 0 Z"),
@@ -29,15 +30,22 @@ function ChartsAxisHighlight(props) {
29
30
  style: {
30
31
  pointerEvents: 'none'
31
32
  }
33
+ }), yAxisHighlight === 'band' && axis.y !== null && isBandScale(yScale) && /*#__PURE__*/_jsx("path", {
34
+ d: "M ".concat(xScale.range()[0], " ").concat(yScale(axis.y.value) - (yScale.step() - yScale.bandwidth()) / 2, " l 0 ").concat(yScale.step(), " l ").concat(xScale.range()[1] - xScale.range()[0], " 0 l 0 ").concat(-yScale.step(), " Z"),
35
+ fill: "gray",
36
+ fillOpacity: 0.1,
37
+ style: {
38
+ pointerEvents: 'none'
39
+ }
32
40
  }), xAxisHighlight === 'line' && axis.x !== null && /*#__PURE__*/_jsx("path", {
33
- d: "M ".concat(getXPosition(axis.x.value), " ").concat(yScale(yScale.domain()[0]), " L ").concat(getXPosition(axis.x.value), " ").concat(yScale(yScale.domain().at(-1))),
41
+ d: "M ".concat(getXPosition(axis.x.value), " ").concat(yScale.range()[0], " L ").concat(getXPosition(axis.x.value), " ").concat(yScale.range()[1]),
34
42
  stroke: "black",
35
43
  strokeDasharray: "5 2",
36
44
  style: {
37
45
  pointerEvents: 'none'
38
46
  }
39
47
  }), yAxisHighlight === 'line' && axis.y !== null && /*#__PURE__*/_jsx("path", {
40
- d: "M ".concat(xScale.range()[0], " ").concat(yScale(axis.y.value), " L ").concat(xScale.range()[1], " ").concat(yScale(axis.y.value)),
48
+ d: "M ".concat(xScale.range()[0], " ").concat(getYPosition(axis.y.value), " L ").concat(xScale.range()[1], " ").concat(getYPosition(axis.y.value)),
41
49
  stroke: "black",
42
50
  strokeDasharray: "5 2",
43
51
  style: {
@@ -52,6 +60,6 @@ process.env.NODE_ENV !== "production" ? ChartsAxisHighlight.propTypes = {
52
60
  // | To update them edit the TypeScript types and run "yarn proptypes" |
53
61
  // ----------------------------------------------------------------------
54
62
  x: PropTypes.oneOf(['band', 'line', 'none']),
55
- y: PropTypes.oneOf(['line', 'none'])
63
+ y: PropTypes.oneOf(['band', 'line', 'none'])
56
64
  } : void 0;
57
65
  export { ChartsAxisHighlight };
@@ -1,5 +1,6 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import * as React from 'react';
3
+ import { useSlotProps } from '@mui/base/utils';
3
4
  import { unstable_composeClasses as composeClasses } from '@mui/utils';
4
5
  import { useThemeProps, useTheme, styled } from '@mui/material/styles';
5
6
  import { DrawingContext } from '../context/DrawingProvider';
@@ -123,7 +124,7 @@ export var ChartsLegendLabel = styled('text', {
123
124
  color: 'inherit',
124
125
  transform: "translate(\n calc(var(--ChartsLegend-itemMarkSize) + var(--ChartsLegend-labelSpacing)),\n calc(0.5 * var(--ChartsLegend-itemMarkSize))\n )",
125
126
  fill: theme.palette.text.primary,
126
- alignmentBaseline: 'central'
127
+ dominantBaseline: 'central'
127
128
  });
128
129
  });
129
130
  var defaultProps = {
@@ -136,25 +137,18 @@ var defaultProps = {
136
137
  itemWidth: 100,
137
138
  spacing: 2
138
139
  };
139
- export function ChartsLegend(inProps) {
140
- var props = useThemeProps({
141
- props: _extends({}, defaultProps, inProps),
142
- name: 'MuiChartsLegend'
143
- });
144
- var position = props.position,
140
+ function DefaultChartsLegend(props) {
141
+ var hidden = props.hidden,
142
+ position = props.position,
145
143
  direction = props.direction,
146
144
  offset = props.offset,
147
- hidden = props.hidden;
148
- var theme = useTheme();
149
- var classes = useUtilityClasses(_extends({}, props, {
150
- theme: theme
151
- }));
152
- var drawingArea = React.useContext(DrawingContext);
153
- var series = React.useContext(SeriesContext);
145
+ series = props.series,
146
+ seriesToDisplay = props.seriesToDisplay,
147
+ drawingArea = props.drawingArea,
148
+ classes = props.classes;
154
149
  if (hidden) {
155
150
  return null;
156
151
  }
157
- var seriesToDisplay = getSeriesToDisplay(series);
158
152
  return /*#__PURE__*/_jsx(ChartsLegendRoot, {
159
153
  ownerState: {
160
154
  direction: direction,
@@ -187,4 +181,41 @@ export function ChartsLegend(inProps) {
187
181
  }, id);
188
182
  })
189
183
  });
184
+ }
185
+ export function ChartsLegend(inProps) {
186
+ var _slots$legend;
187
+ var props = useThemeProps({
188
+ props: _extends({}, defaultProps, inProps),
189
+ name: 'MuiChartsLegend'
190
+ });
191
+ var position = props.position,
192
+ direction = props.direction,
193
+ offset = props.offset,
194
+ hidden = props.hidden,
195
+ slots = props.slots,
196
+ slotProps = props.slotProps;
197
+ var theme = useTheme();
198
+ var classes = useUtilityClasses(_extends({}, props, {
199
+ theme: theme
200
+ }));
201
+ var drawingArea = React.useContext(DrawingContext);
202
+ var series = React.useContext(SeriesContext);
203
+ var seriesToDisplay = getSeriesToDisplay(series);
204
+ var ChartLegendRender = (_slots$legend = slots == null ? void 0 : slots.legend) != null ? _slots$legend : DefaultChartsLegend;
205
+ var chartLegendRenderProps = useSlotProps({
206
+ elementType: ChartLegendRender,
207
+ externalSlotProps: slotProps == null ? void 0 : slotProps.legend,
208
+ additionalProps: {
209
+ position: position,
210
+ direction: direction,
211
+ offset: offset,
212
+ classes: classes,
213
+ drawingArea: drawingArea,
214
+ series: series,
215
+ hidden: hidden,
216
+ seriesToDisplay: seriesToDisplay
217
+ },
218
+ ownerState: {}
219
+ });
220
+ return /*#__PURE__*/_jsx(ChartLegendRender, _extends({}, chartLegendRenderProps));
190
221
  }
@@ -71,30 +71,34 @@ export function ChartsAxisTooltipContent(props) {
71
71
  axisData = props.axisData,
72
72
  sx = props.sx,
73
73
  classes = props.classes;
74
- var dataIndex = axisData.x && axisData.x.index;
75
- var axisValue = axisData.x && axisData.x.value;
74
+ var isXaxis = (axisData.x && axisData.x.index) !== undefined;
75
+ var dataIndex = isXaxis ? axisData.x && axisData.x.index : axisData.y && axisData.y.index;
76
+ var axisValue = isXaxis ? axisData.x && axisData.x.value : axisData.y && axisData.y.value;
76
77
  var _React$useContext = React.useContext(CartesianContext),
77
78
  xAxisIds = _React$useContext.xAxisIds,
78
- xAxis = _React$useContext.xAxis;
79
+ xAxis = _React$useContext.xAxis,
80
+ yAxisIds = _React$useContext.yAxisIds,
81
+ yAxis = _React$useContext.yAxis;
79
82
  var series = React.useContext(SeriesContext);
80
- var USED_X_AXIS_ID = xAxisIds[0];
83
+ var USED_AXIS_ID = isXaxis ? xAxisIds[0] : yAxisIds[0];
81
84
  var relevantSeries = React.useMemo(function () {
82
85
  var rep = [];
83
86
  Object.keys(series).filter(function (seriesType) {
84
87
  return ['bar', 'line', 'scatter'].includes(seriesType);
85
88
  }).forEach(function (seriesType) {
86
89
  series[seriesType].seriesOrder.forEach(function (seriesId) {
87
- var axisKey = series[seriesType].series[seriesId].xAxisKey;
88
- if (axisKey === undefined || axisKey === USED_X_AXIS_ID) {
90
+ var item = series[seriesType].series[seriesId];
91
+ var axisKey = isXaxis ? item.xAxisKey : item.yAxisKey;
92
+ if (axisKey === undefined || axisKey === USED_AXIS_ID) {
89
93
  rep.push(series[seriesType].series[seriesId]);
90
94
  }
91
95
  });
92
96
  });
93
97
  return rep;
94
- }, [USED_X_AXIS_ID, series]);
98
+ }, [USED_AXIS_ID, isXaxis, series]);
95
99
  var relevantAxis = React.useMemo(function () {
96
- return xAxis[USED_X_AXIS_ID];
97
- }, [USED_X_AXIS_ID, xAxis]);
100
+ return isXaxis ? xAxis[USED_AXIS_ID] : yAxis[USED_AXIS_ID];
101
+ }, [USED_AXIS_ID, isXaxis, xAxis, yAxis]);
98
102
  var Content = content != null ? content : DefaultChartsAxisContent;
99
103
  return /*#__PURE__*/_jsx(Content, {
100
104
  axisData: axisData,
@@ -9,7 +9,7 @@ import { CartesianContext } from '../context/CartesianContextProvider';
9
9
  import { DrawingContext } from '../context/DrawingProvider';
10
10
  import useTicks from '../hooks/useTicks';
11
11
  import { getAxisUtilityClass } from '../ChartsAxis/axisClasses';
12
- import { Line, Tick, TickLabel, Label, AxisRoot } from '../internals/components/AxisSharedComponents';
12
+ import { ChartsLine, ChartsTick, ChartsTickLabel, ChartsLabel, AxisRoot } from '../internals/components/AxisSharedComponents';
13
13
  import { jsx as _jsx } from "react/jsx-runtime";
14
14
  import { jsxs as _jsxs } from "react/jsx-runtime";
15
15
  var useUtilityClasses = function useUtilityClasses(ownerState) {
@@ -34,6 +34,7 @@ var defaultProps = {
34
34
  tickSize: 6
35
35
  };
36
36
  function ChartsXAxis(inProps) {
37
+ var _slots$axisLine, _slots$axisTick, _slots$axisTickLabel, _slots$axisLabel;
37
38
  var props = useThemeProps({
38
39
  props: _extends({}, defaultProps, inProps),
39
40
  name: 'MuiChartsXAxis'
@@ -51,7 +52,9 @@ function ChartsXAxis(inProps) {
51
52
  label = defaultizedProps.label,
52
53
  labelFontSize = defaultizedProps.labelFontSize,
53
54
  tickSizeProp = defaultizedProps.tickSize,
54
- valueFormatter = defaultizedProps.valueFormatter;
55
+ valueFormatter = defaultizedProps.valueFormatter,
56
+ slots = defaultizedProps.slots,
57
+ slotProps = defaultizedProps.slotProps;
55
58
  var theme = useTheme();
56
59
  var classes = useUtilityClasses(_extends({}, defaultizedProps, {
57
60
  theme: theme
@@ -72,14 +75,18 @@ function ChartsXAxis(inProps) {
72
75
  x: left + width / 2,
73
76
  y: positionSigne * (tickFontSize + tickSize + 10)
74
77
  };
78
+ var Line = (_slots$axisLine = slots == null ? void 0 : slots.axisLine) != null ? _slots$axisLine : ChartsLine;
79
+ var Tick = (_slots$axisTick = slots == null ? void 0 : slots.axisTick) != null ? _slots$axisTick : ChartsTick;
80
+ var TickLabel = (_slots$axisTickLabel = slots == null ? void 0 : slots.axisTickLabel) != null ? _slots$axisTickLabel : ChartsTickLabel;
81
+ var Label = (_slots$axisLabel = slots == null ? void 0 : slots.axisLabel) != null ? _slots$axisLabel : ChartsLabel;
75
82
  return /*#__PURE__*/_jsxs(AxisRoot, {
76
83
  transform: "translate(0, ".concat(position === 'bottom' ? top + height : top, ")"),
77
84
  className: classes.root,
78
- children: [!disableLine && /*#__PURE__*/_jsx(Line, {
85
+ children: [!disableLine && /*#__PURE__*/_jsx(Line, _extends({
79
86
  x1: xScale.range()[0],
80
87
  x2: xScale.range()[1],
81
88
  className: classes.line
82
- }), xTicks.map(function (_ref, index) {
89
+ }, slotProps == null ? void 0 : slotProps.axisLine)), xTicks.map(function (_ref, index) {
83
90
  var formattedValue = _ref.formattedValue,
84
91
  offset = _ref.offset,
85
92
  labelOffset = _ref.labelOffset;
@@ -88,26 +95,28 @@ function ChartsXAxis(inProps) {
88
95
  return /*#__PURE__*/_jsxs("g", {
89
96
  transform: "translate(".concat(offset, ", 0)"),
90
97
  className: classes.tickContainer,
91
- children: [!disableTicks && /*#__PURE__*/_jsx(Tick, {
98
+ children: [!disableTicks && /*#__PURE__*/_jsx(Tick, _extends({
92
99
  y2: positionSigne * tickSize,
93
100
  className: classes.tick
94
- }), formattedValue !== undefined && /*#__PURE__*/_jsx(TickLabel, {
101
+ }, slotProps == null ? void 0 : slotProps.axisTick)), formattedValue !== undefined && /*#__PURE__*/_jsx(TickLabel, _extends({
95
102
  x: xTickLabel,
96
103
  y: yTickLabel,
97
104
  "transform-origin": "".concat(xTickLabel, "px ").concat(yTickLabel, "px"),
98
105
  sx: {
99
106
  fontSize: tickFontSize
100
107
  },
101
- className: classes.tickLabel,
108
+ className: classes.tickLabel
109
+ }, slotProps == null ? void 0 : slotProps.axisTickLabel, {
102
110
  children: formattedValue
103
- })]
111
+ }))]
104
112
  }, index);
105
113
  }), label && /*#__PURE__*/_jsx(Label, _extends({}, labelRefPoint, {
106
114
  sx: {
107
115
  fontSize: labelFontSize,
108
116
  transformOrigin: "".concat(labelRefPoint.x, "px ").concat(labelRefPoint.y, "px")
109
117
  },
110
- className: classes.label,
118
+ className: classes.label
119
+ }, slotProps == null ? void 0 : slotProps.axisLabel, {
111
120
  children: label
112
121
  }))]
113
122
  });
@@ -153,6 +162,16 @@ process.env.NODE_ENV !== "production" ? ChartsXAxis.propTypes = {
153
162
  * Position of the axis.
154
163
  */
155
164
  position: PropTypes.oneOf(['bottom', 'top']),
165
+ /**
166
+ * The props used for each component slot.
167
+ * @default {}
168
+ */
169
+ slotProps: PropTypes.object,
170
+ /**
171
+ * Overridable component slots.
172
+ * @default {}
173
+ */
174
+ slots: PropTypes.object,
156
175
  /**
157
176
  * The stroke color of the axis line.
158
177
  * @default 'currentColor'
@@ -163,6 +182,23 @@ process.env.NODE_ENV !== "production" ? ChartsXAxis.propTypes = {
163
182
  * @default 12
164
183
  */
165
184
  tickFontSize: PropTypes.number,
185
+ /**
186
+ * Maximal step between two ticks.
187
+ * When using time data, the value is assumed to be in ms.
188
+ * Not supported by categorical axis (band, points).
189
+ */
190
+ tickMaxStep: PropTypes.number,
191
+ /**
192
+ * Maximal step between two ticks.
193
+ * When using time data, the value is assumed to be in ms.
194
+ * Not supported by categorical axis (band, points).
195
+ */
196
+ tickMinStep: PropTypes.number,
197
+ /**
198
+ * The number of ticks. This number is not guaranted.
199
+ * Not supported by categorical axis (band, points).
200
+ */
201
+ tickNumber: PropTypes.number,
166
202
  /**
167
203
  * The size of the ticks.
168
204
  * @default 6