@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
@@ -8,39 +8,39 @@ export const AxisRoot = styled('g', {
8
8
  })({
9
9
  [`&.${axisClasses.directionY}`]: {
10
10
  [`.${axisClasses.tickLabel}`]: {
11
- alignmentBaseline: 'middle'
11
+ dominantBaseline: 'middle'
12
12
  },
13
13
  [`.${axisClasses.label}`]: {
14
- alignmentBaseline: 'baseline',
14
+ dominantBaseline: 'auto',
15
15
  textAnchor: 'middle'
16
16
  }
17
17
  },
18
18
  [`&.${axisClasses.left}`]: {
19
19
  [`.${axisClasses.tickLabel}`]: {
20
- alignmentBaseline: 'central',
20
+ dominantBaseline: 'central',
21
21
  textAnchor: 'end'
22
22
  }
23
23
  },
24
24
  [`&.${axisClasses.right}`]: {
25
25
  [`.${axisClasses.tickLabel}`]: {
26
- alignmentBaseline: 'central',
26
+ dominantBaseline: 'central',
27
27
  textAnchor: 'start'
28
28
  }
29
29
  },
30
30
  [`&.${axisClasses.bottom}`]: {
31
31
  [`.${axisClasses.tickLabel}, .${axisClasses.label}`]: {
32
- alignmentBaseline: 'hanging',
32
+ dominantBaseline: 'hanging',
33
33
  textAnchor: 'middle'
34
34
  }
35
35
  },
36
36
  [`&.${axisClasses.top}`]: {
37
37
  [`.${axisClasses.tickLabel}, .${axisClasses.label}`]: {
38
- alignmentBaseline: 'baseline',
38
+ dominantBaseline: 'baseline',
39
39
  textAnchor: 'middle'
40
40
  }
41
41
  }
42
42
  });
43
- export const Line = styled('line', {
43
+ export const ChartsLine = styled('line', {
44
44
  name: 'MuiChartsAxis',
45
45
  slot: 'Line',
46
46
  overridesResolver: (props, styles) => styles.line
@@ -51,7 +51,7 @@ export const Line = styled('line', {
51
51
  shapeRendering: 'crispEdges',
52
52
  strokeWidth: 1
53
53
  }));
54
- export const Tick = styled('line', {
54
+ export const ChartsTick = styled('line', {
55
55
  name: 'MuiChartsAxis',
56
56
  slot: 'Tick',
57
57
  overridesResolver: (props, styles) => styles.tick
@@ -61,7 +61,7 @@ export const Tick = styled('line', {
61
61
  stroke: theme.palette.text.primary,
62
62
  shapeRendering: 'crispEdges'
63
63
  }));
64
- export const TickLabel = styled('text', {
64
+ export const ChartsTickLabel = styled('text', {
65
65
  name: 'MuiChartsAxis',
66
66
  slot: 'TickLabel',
67
67
  overridesResolver: (props, styles) => styles.tickLabel
@@ -70,7 +70,7 @@ export const TickLabel = styled('text', {
70
70
  }) => _extends({}, theme.typography.caption, {
71
71
  fill: theme.palette.text.primary
72
72
  }));
73
- export const Label = styled('text', {
73
+ export const ChartsLabel = styled('text', {
74
74
  name: 'MuiChartsAxis',
75
75
  slot: 'Label',
76
76
  overridesResolver: (props, styles) => styles.label
@@ -41,66 +41,49 @@ const useAxisEvents = disableAxisListener => {
41
41
  if (element === null || disableAxisListener) {
42
42
  return () => {};
43
43
  }
44
- const getUpdateY = y => {
45
- if (usedYAxis === null) {
46
- return null;
47
- }
48
- const {
49
- scale: yScale,
50
- data: yAxisData
51
- } = yAxis[usedYAxis];
52
- if (!(0, _isBandScale.isBandScale)(yScale)) {
53
- return {
54
- value: yScale.invert(y)
55
- };
56
- }
57
- const dataIndex = Math.floor((y - yScale.range()[0]) / yScale.step());
58
- if (dataIndex < 0 || dataIndex >= yAxisData.length) {
59
- return null;
60
- }
61
- return {
62
- index: dataIndex,
63
- value: yAxisData[dataIndex]
64
- };
65
- };
66
- const getUpdateX = x => {
44
+ const getUpdate = (axisConfig, mouseValue) => {
67
45
  if (usedXAxis === null) {
68
46
  return null;
69
47
  }
70
48
  const {
71
- scale: xScale,
72
- data: xAxisData
73
- } = xAxis[usedXAxis];
74
- if (!(0, _isBandScale.isBandScale)(xScale)) {
75
- const value = xScale.invert(x);
76
- const closestIndex = xAxisData?.findIndex((v, index) => {
49
+ scale,
50
+ data: axisData
51
+ } = axisConfig;
52
+ if (!(0, _isBandScale.isBandScale)(scale)) {
53
+ const value = scale.invert(mouseValue);
54
+ if (axisData === undefined) {
55
+ return {
56
+ value
57
+ };
58
+ }
59
+ const closestIndex = axisData?.findIndex((v, index) => {
77
60
  if (v > value) {
78
61
  // @ts-ignore
79
- if (index === 0 || Math.abs(value - v) <= Math.abs(value - xAxisData[index - 1])) {
62
+ if (index === 0 || Math.abs(value - v) <= Math.abs(value - axisData[index - 1])) {
80
63
  return true;
81
64
  }
82
65
  }
83
66
  if (v <= value) {
84
- if (index === xAxisData.length - 1 ||
67
+ if (index === axisData.length - 1 ||
85
68
  // @ts-ignore
86
- Math.abs(value - v) < Math.abs(value - xAxisData[index + 1])) {
69
+ Math.abs(value - v) < Math.abs(value - axisData[index + 1])) {
87
70
  return true;
88
71
  }
89
72
  }
90
73
  return false;
91
74
  });
92
75
  return {
93
- value: closestIndex !== undefined && closestIndex >= 0 ? xAxisData[closestIndex] : value,
76
+ value: closestIndex !== undefined && closestIndex >= 0 ? axisData[closestIndex] : value,
94
77
  index: closestIndex
95
78
  };
96
79
  }
97
- const dataIndex = xScale.bandwidth() === 0 ? Math.floor((x - xScale.range()[0] + xScale.step() / 2) / xScale.step()) : Math.floor((x - xScale.range()[0]) / xScale.step());
98
- if (dataIndex < 0 || dataIndex >= xAxisData.length) {
80
+ 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());
81
+ if (dataIndex < 0 || dataIndex >= axisData.length) {
99
82
  return null;
100
83
  }
101
84
  return {
102
85
  index: dataIndex,
103
- value: xAxisData[dataIndex]
86
+ value: axisData[dataIndex]
104
87
  };
105
88
  };
106
89
  const handleMouseOut = () => {
@@ -138,8 +121,8 @@ const useAxisEvents = disableAxisListener => {
138
121
  });
139
122
  return;
140
123
  }
141
- const newStateX = getUpdateX(svgPt.x);
142
- const newStateY = getUpdateY(svgPt.y);
124
+ const newStateX = getUpdate(xAxis[usedXAxis], svgPt.x);
125
+ const newStateY = getUpdate(yAxis[usedYAxis], svgPt.y);
143
126
  dispatch({
144
127
  type: 'updateAxis',
145
128
  data: {
@@ -1,11 +1,26 @@
1
1
  import { D3Scale } from '../models/axis';
2
- export type TickParams = {
3
- maxTicks?: number;
4
- minTicks?: number;
5
- tickSpacing?: number;
6
- };
2
+ export interface TickParams {
3
+ /**
4
+ * Maximal step between two ticks.
5
+ * When using time data, the value is assumed to be in ms.
6
+ * Not supported by categorical axis (band, points).
7
+ */
8
+ tickMaxStep?: number;
9
+ /**
10
+ * Maximal step between two ticks.
11
+ * When using time data, the value is assumed to be in ms.
12
+ * Not supported by categorical axis (band, points).
13
+ */
14
+ tickMinStep?: number;
15
+ /**
16
+ * The number of ticks. This number is not guaranted.
17
+ * Not supported by categorical axis (band, points).
18
+ */
19
+ tickNumber?: number;
20
+ }
7
21
  export declare function getTicksNumber(params: TickParams & {
8
22
  range: any[];
23
+ domain: any[];
9
24
  }): number;
10
25
  declare function useTicks(options: {
11
26
  scale: D3Scale;
package/hooks/useTicks.js CHANGED
@@ -11,13 +11,16 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
11
11
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
12
12
  function getTicksNumber(params) {
13
13
  const {
14
- maxTicks = 999,
15
- minTicks = 2,
16
- tickSpacing = 50,
17
- range
14
+ tickMaxStep,
15
+ tickMinStep,
16
+ tickNumber,
17
+ range,
18
+ domain
18
19
  } = params;
19
- const estimatedTickNumber = Math.floor(Math.abs(range[1] - range[0]) / tickSpacing);
20
- return Math.min(maxTicks, Math.max(minTicks, estimatedTickNumber));
20
+ const maxTicks = tickMinStep === undefined ? 999 : Math.floor(Math.abs(domain[1] - domain[0]) / tickMinStep);
21
+ const minTicks = tickMaxStep === undefined ? 2 : Math.ceil(Math.abs(domain[1] - domain[0]) / tickMaxStep);
22
+ const defaultizedTickNumber = tickNumber ?? Math.floor(Math.abs(range[1] - range[0]) / 50);
23
+ return Math.min(maxTicks, Math.max(minTicks, defaultizedTickNumber));
21
24
  }
22
25
  function useTicks(options) {
23
26
  const {
@@ -31,9 +34,9 @@ function useTicks(options) {
31
34
  const domain = scale.domain();
32
35
  if (scale.bandwidth() > 0) {
33
36
  // scale type = 'band'
34
- return [...domain.map((value, index) => ({
37
+ return [...domain.map(value => ({
35
38
  formattedValue: valueFormatter?.(value) ?? value,
36
- offset: index === 0 ? scale.range()[0] : scale(value) - (scale.step() - scale.bandwidth()) / 2,
39
+ offset: scale(value) - (scale.step() - scale.bandwidth()) / 2,
37
40
  labelOffset: scale.step() / 2
38
41
  })), {
39
42
  formattedValue: undefined,
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-charts v6.0.0-alpha.6
2
+ * @mui/x-charts v6.0.0-alpha.8
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
@@ -1,6 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  export declare const AxisRoot: import("@emotion/styled").StyledComponent<import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme>, Pick<import("react").SVGProps<SVGGElement>, keyof import("react").SVGProps<SVGGElement>>, {}>;
3
- export declare const Line: import("@emotion/styled").StyledComponent<import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme>, Pick<import("react").SVGLineElementAttributes<SVGLineElement>, keyof import("react").SVGLineElementAttributes<SVGLineElement>>, {}>;
4
- export declare const Tick: import("@emotion/styled").StyledComponent<import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme>, Pick<import("react").SVGLineElementAttributes<SVGLineElement>, keyof import("react").SVGLineElementAttributes<SVGLineElement>>, {}>;
5
- export declare const TickLabel: import("@emotion/styled").StyledComponent<import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme>, Pick<import("react").SVGTextElementAttributes<SVGTextElement>, keyof import("react").SVGTextElementAttributes<SVGTextElement>>, {}>;
6
- export declare const Label: import("@emotion/styled").StyledComponent<import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme>, Pick<import("react").SVGTextElementAttributes<SVGTextElement>, keyof import("react").SVGTextElementAttributes<SVGTextElement>>, {}>;
3
+ export declare const ChartsLine: import("@emotion/styled").StyledComponent<import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme>, Pick<import("react").SVGLineElementAttributes<SVGLineElement>, keyof import("react").SVGLineElementAttributes<SVGLineElement>>, {}>;
4
+ export declare const ChartsTick: import("@emotion/styled").StyledComponent<import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme>, Pick<import("react").SVGLineElementAttributes<SVGLineElement>, keyof import("react").SVGLineElementAttributes<SVGLineElement>>, {}>;
5
+ export declare const ChartsTickLabel: import("@emotion/styled").StyledComponent<import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme>, Pick<import("react").SVGTextElementAttributes<SVGTextElement>, keyof import("react").SVGTextElementAttributes<SVGTextElement>>, {}>;
6
+ export declare const ChartsLabel: import("@emotion/styled").StyledComponent<import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme>, Pick<import("react").SVGTextElementAttributes<SVGTextElement>, keyof import("react").SVGTextElementAttributes<SVGTextElement>>, {}>;
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.TickLabel = exports.Tick = exports.Line = exports.Label = exports.AxisRoot = void 0;
7
+ exports.ChartsTickLabel = exports.ChartsTick = exports.ChartsLine = exports.ChartsLabel = exports.AxisRoot = void 0;
8
8
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
9
  var _styles = require("@mui/material/styles");
10
10
  var _axisClasses = require("../../ChartsAxis/axisClasses");
@@ -15,40 +15,40 @@ const AxisRoot = (0, _styles.styled)('g', {
15
15
  })({
16
16
  [`&.${_axisClasses.axisClasses.directionY}`]: {
17
17
  [`.${_axisClasses.axisClasses.tickLabel}`]: {
18
- alignmentBaseline: 'middle'
18
+ dominantBaseline: 'middle'
19
19
  },
20
20
  [`.${_axisClasses.axisClasses.label}`]: {
21
- alignmentBaseline: 'baseline',
21
+ dominantBaseline: 'auto',
22
22
  textAnchor: 'middle'
23
23
  }
24
24
  },
25
25
  [`&.${_axisClasses.axisClasses.left}`]: {
26
26
  [`.${_axisClasses.axisClasses.tickLabel}`]: {
27
- alignmentBaseline: 'central',
27
+ dominantBaseline: 'central',
28
28
  textAnchor: 'end'
29
29
  }
30
30
  },
31
31
  [`&.${_axisClasses.axisClasses.right}`]: {
32
32
  [`.${_axisClasses.axisClasses.tickLabel}`]: {
33
- alignmentBaseline: 'central',
33
+ dominantBaseline: 'central',
34
34
  textAnchor: 'start'
35
35
  }
36
36
  },
37
37
  [`&.${_axisClasses.axisClasses.bottom}`]: {
38
38
  [`.${_axisClasses.axisClasses.tickLabel}, .${_axisClasses.axisClasses.label}`]: {
39
- alignmentBaseline: 'hanging',
39
+ dominantBaseline: 'hanging',
40
40
  textAnchor: 'middle'
41
41
  }
42
42
  },
43
43
  [`&.${_axisClasses.axisClasses.top}`]: {
44
44
  [`.${_axisClasses.axisClasses.tickLabel}, .${_axisClasses.axisClasses.label}`]: {
45
- alignmentBaseline: 'baseline',
45
+ dominantBaseline: 'baseline',
46
46
  textAnchor: 'middle'
47
47
  }
48
48
  }
49
49
  });
50
50
  exports.AxisRoot = AxisRoot;
51
- const Line = (0, _styles.styled)('line', {
51
+ const ChartsLine = (0, _styles.styled)('line', {
52
52
  name: 'MuiChartsAxis',
53
53
  slot: 'Line',
54
54
  overridesResolver: (props, styles) => styles.line
@@ -59,8 +59,8 @@ const Line = (0, _styles.styled)('line', {
59
59
  shapeRendering: 'crispEdges',
60
60
  strokeWidth: 1
61
61
  }));
62
- exports.Line = Line;
63
- const Tick = (0, _styles.styled)('line', {
62
+ exports.ChartsLine = ChartsLine;
63
+ const ChartsTick = (0, _styles.styled)('line', {
64
64
  name: 'MuiChartsAxis',
65
65
  slot: 'Tick',
66
66
  overridesResolver: (props, styles) => styles.tick
@@ -70,8 +70,8 @@ const Tick = (0, _styles.styled)('line', {
70
70
  stroke: theme.palette.text.primary,
71
71
  shapeRendering: 'crispEdges'
72
72
  }));
73
- exports.Tick = Tick;
74
- const TickLabel = (0, _styles.styled)('text', {
73
+ exports.ChartsTick = ChartsTick;
74
+ const ChartsTickLabel = (0, _styles.styled)('text', {
75
75
  name: 'MuiChartsAxis',
76
76
  slot: 'TickLabel',
77
77
  overridesResolver: (props, styles) => styles.tickLabel
@@ -80,8 +80,8 @@ const TickLabel = (0, _styles.styled)('text', {
80
80
  }) => (0, _extends2.default)({}, theme.typography.caption, {
81
81
  fill: theme.palette.text.primary
82
82
  }));
83
- exports.TickLabel = TickLabel;
84
- const Label = (0, _styles.styled)('text', {
83
+ exports.ChartsTickLabel = ChartsTickLabel;
84
+ const ChartsLabel = (0, _styles.styled)('text', {
85
85
  name: 'MuiChartsAxis',
86
86
  slot: 'Label',
87
87
  overridesResolver: (props, styles) => styles.label
@@ -90,4 +90,4 @@ const Label = (0, _styles.styled)('text', {
90
90
  }) => (0, _extends2.default)({}, theme.typography.body1, {
91
91
  fill: theme.palette.text.primary
92
92
  }));
93
- exports.Label = Label;
93
+ exports.ChartsLabel = ChartsLabel;
@@ -39,6 +39,7 @@ export declare function defaultizeColor(series: AllSeriesType, seriesIndex: numb
39
39
  data?: number[] | undefined;
40
40
  dataKey?: string | undefined;
41
41
  label?: string | undefined;
42
+ layout?: "horizontal" | "vertical" | undefined;
42
43
  id?: string | undefined;
43
44
  color: string;
44
45
  valueFormatter?: ((value: number) => string) | undefined;
@@ -1,12 +1,12 @@
1
- import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
3
3
  import * as React from 'react';
4
4
  import useId from '@mui/utils/useId';
5
5
  import PropTypes from 'prop-types';
6
6
  import { BarPlot } from './BarPlot';
7
7
  import { ResponsiveChartContainer } from '../ResponsiveChartContainer';
8
8
  import { ChartsAxis } from '../ChartsAxis';
9
- import { DEFAULT_X_AXIS_KEY } from '../constants';
9
+ import { DEFAULT_X_AXIS_KEY, DEFAULT_Y_AXIS_KEY } from '../constants';
10
10
  import { ChartsTooltip } from '../ChartsTooltip';
11
11
  import { ChartsLegend } from '../ChartsLegend';
12
12
  import { ChartsAxisHighlight } from '../ChartsAxisHighlight';
@@ -23,6 +23,7 @@ var BarChart = /*#__PURE__*/React.forwardRef(function BarChart(props, ref) {
23
23
  colors = props.colors,
24
24
  dataset = props.dataset,
25
25
  sx = props.sx,
26
+ layout = props.layout,
26
27
  tooltip = props.tooltip,
27
28
  axisHighlight = props.axisHighlight,
28
29
  legend = props.legend,
@@ -30,47 +31,72 @@ var BarChart = /*#__PURE__*/React.forwardRef(function BarChart(props, ref) {
30
31
  leftAxis = props.leftAxis,
31
32
  rightAxis = props.rightAxis,
32
33
  bottomAxis = props.bottomAxis,
33
- children = props.children;
34
+ children = props.children,
35
+ slots = props.slots,
36
+ slotProps = props.slotProps;
34
37
  var id = useId();
35
38
  var clipPathId = "".concat(id, "-clip-path");
39
+ var hasHorizontalSeries = layout === 'horizontal' || layout === undefined && series.some(function (item) {
40
+ return item.layout === 'horizontal';
41
+ });
42
+ var defaultAxisConfig = {
43
+ scaleType: 'band',
44
+ data: Array.from({
45
+ length: Math.max.apply(Math, _toConsumableArray(series.map(function (s) {
46
+ var _ref, _s$data;
47
+ return ((_ref = (_s$data = s.data) != null ? _s$data : dataset) != null ? _ref : []).length;
48
+ })))
49
+ }, function (_, index) {
50
+ return index;
51
+ })
52
+ };
53
+ var defaultizedAxisHighlight = _extends({}, hasHorizontalSeries ? {
54
+ y: 'band'
55
+ } : {
56
+ x: 'band'
57
+ }, axisHighlight);
36
58
  return /*#__PURE__*/_jsxs(ResponsiveChartContainer, {
37
59
  ref: ref,
38
60
  series: series.map(function (s) {
39
61
  return _extends({
40
62
  type: 'bar'
41
- }, s);
63
+ }, s, {
64
+ layout: hasHorizontalSeries ? 'horizontal' : 'vertical'
65
+ });
42
66
  }),
43
67
  width: width,
44
68
  height: height,
45
69
  margin: margin,
46
- xAxis: xAxis != null ? xAxis : [{
47
- id: DEFAULT_X_AXIS_KEY,
48
- scaleType: 'band',
49
- data: Array.from({
50
- length: Math.max.apply(Math, _toConsumableArray(series.map(function (s) {
51
- var _ref, _s$data;
52
- return ((_ref = (_s$data = s.data) != null ? _s$data : dataset) != null ? _ref : []).length;
53
- })))
54
- }, function (_, index) {
55
- return index;
56
- })
57
- }],
58
- yAxis: yAxis,
70
+ xAxis: xAxis != null ? xAxis : hasHorizontalSeries ? undefined : [_extends({
71
+ id: DEFAULT_X_AXIS_KEY
72
+ }, defaultAxisConfig)],
73
+ yAxis: yAxis != null ? yAxis : hasHorizontalSeries ? [_extends({
74
+ id: DEFAULT_Y_AXIS_KEY
75
+ }, defaultAxisConfig)] : undefined,
59
76
  colors: colors,
60
77
  dataset: dataset,
61
78
  sx: sx,
62
79
  disableAxisListener: (tooltip == null ? void 0 : tooltip.trigger) !== 'axis' && (axisHighlight == null ? void 0 : axisHighlight.x) === 'none' && (axisHighlight == null ? void 0 : axisHighlight.y) === 'none',
63
80
  children: [/*#__PURE__*/_jsx("g", {
64
81
  clipPath: "url(#".concat(clipPathId, ")"),
65
- children: /*#__PURE__*/_jsx(BarPlot, {})
82
+ children: /*#__PURE__*/_jsx(BarPlot, {
83
+ slots: slots,
84
+ slotProps: slotProps
85
+ })
66
86
  }), /*#__PURE__*/_jsx(ChartsAxis, {
67
87
  topAxis: topAxis,
68
88
  leftAxis: leftAxis,
69
89
  rightAxis: rightAxis,
70
- bottomAxis: bottomAxis
71
- }), /*#__PURE__*/_jsx(ChartsLegend, _extends({}, legend)), /*#__PURE__*/_jsx(ChartsAxisHighlight, _extends({
72
- x: "band"
73
- }, axisHighlight)), /*#__PURE__*/_jsx(ChartsTooltip, _extends({}, tooltip)), /*#__PURE__*/_jsx(ChartsClipPath, {
90
+ bottomAxis: bottomAxis,
91
+ slots: slots,
92
+ slotProps: slotProps
93
+ }), /*#__PURE__*/_jsx(ChartsLegend, _extends({}, legend, {
94
+ slots: slots,
95
+ slotProps: slotProps
96
+ })), /*#__PURE__*/_jsx(ChartsAxisHighlight, _extends({}, defaultizedAxisHighlight)), /*#__PURE__*/_jsx(ChartsTooltip, _extends({}, tooltip, {
97
+ slots: slots,
98
+ slotProps: slotProps
99
+ })), /*#__PURE__*/_jsx(ChartsClipPath, {
74
100
  id: clipPathId
75
101
  }), children]
76
102
  });
@@ -82,7 +108,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
82
108
  // ----------------------------------------------------------------------
83
109
  axisHighlight: PropTypes.shape({
84
110
  x: PropTypes.oneOf(['band', 'line', 'none']),
85
- y: PropTypes.oneOf(['line', 'none'])
111
+ y: PropTypes.oneOf(['band', 'line', 'none'])
86
112
  }),
87
113
  /**
88
114
  * Indicate which axis to display the bottom of the charts.
@@ -98,8 +124,13 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
98
124
  label: PropTypes.string,
99
125
  labelFontSize: PropTypes.number,
100
126
  position: PropTypes.oneOf(['bottom', 'top']),
127
+ slotProps: PropTypes.object,
128
+ slots: PropTypes.object,
101
129
  stroke: PropTypes.string,
102
130
  tickFontSize: PropTypes.number,
131
+ tickMaxStep: PropTypes.number,
132
+ tickMinStep: PropTypes.number,
133
+ tickNumber: PropTypes.number,
103
134
  tickSize: PropTypes.number
104
135
  }), PropTypes.string]),
105
136
  children: PropTypes.node,
@@ -112,6 +143,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
112
143
  desc: PropTypes.string,
113
144
  disableAxisListener: PropTypes.bool,
114
145
  height: PropTypes.number,
146
+ layout: PropTypes.oneOf(['horizontal', 'vertical']),
115
147
  /**
116
148
  * Indicate which axis to display the left of the charts.
117
149
  * Can be a string (the id of the axis) or an object `ChartsYAxisProps`.
@@ -126,8 +158,13 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
126
158
  label: PropTypes.string,
127
159
  labelFontSize: PropTypes.number,
128
160
  position: PropTypes.oneOf(['left', 'right']),
161
+ slotProps: PropTypes.object,
162
+ slots: PropTypes.object,
129
163
  stroke: PropTypes.string,
130
164
  tickFontSize: PropTypes.number,
165
+ tickMaxStep: PropTypes.number,
166
+ tickMinStep: PropTypes.number,
167
+ tickNumber: PropTypes.number,
131
168
  tickSize: PropTypes.number
132
169
  }), PropTypes.string]),
133
170
  legend: PropTypes.shape({
@@ -144,6 +181,8 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
144
181
  horizontal: PropTypes.oneOf(['left', 'middle', 'right']).isRequired,
145
182
  vertical: PropTypes.oneOf(['bottom', 'middle', 'top']).isRequired
146
183
  }),
184
+ slotProps: PropTypes.object,
185
+ slots: PropTypes.object,
147
186
  spacing: PropTypes.number
148
187
  }),
149
188
  margin: PropTypes.shape({
@@ -166,8 +205,13 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
166
205
  label: PropTypes.string,
167
206
  labelFontSize: PropTypes.number,
168
207
  position: PropTypes.oneOf(['left', 'right']),
208
+ slotProps: PropTypes.object,
209
+ slots: PropTypes.object,
169
210
  stroke: PropTypes.string,
170
211
  tickFontSize: PropTypes.number,
212
+ tickMaxStep: PropTypes.number,
213
+ tickMinStep: PropTypes.number,
214
+ tickNumber: PropTypes.number,
171
215
  tickSize: PropTypes.number
172
216
  }), PropTypes.string]),
173
217
  series: PropTypes.arrayOf(PropTypes.shape({
@@ -180,6 +224,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
180
224
  }),
181
225
  id: PropTypes.string,
182
226
  label: PropTypes.string,
227
+ layout: PropTypes.oneOf(['horizontal', 'vertical']),
183
228
  stack: PropTypes.string,
184
229
  stackOffset: PropTypes.oneOf(['diverging', 'expand', 'none', 'silhouette', 'wiggle']),
185
230
  stackOrder: PropTypes.oneOf(['appearance', 'ascending', 'descending', 'insideOut', 'none', 'reverse']),
@@ -188,6 +233,16 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
188
233
  xAxisKey: PropTypes.string,
189
234
  yAxisKey: PropTypes.string
190
235
  })).isRequired,
236
+ /**
237
+ * The props used for each component slot.
238
+ * @default {}
239
+ */
240
+ slotProps: PropTypes.object,
241
+ /**
242
+ * Overridable component slots.
243
+ * @default {}
244
+ */
245
+ slots: PropTypes.object,
191
246
  sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
192
247
  title: PropTypes.string,
193
248
  tooltip: PropTypes.shape({
@@ -210,8 +265,13 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
210
265
  label: PropTypes.string,
211
266
  labelFontSize: PropTypes.number,
212
267
  position: PropTypes.oneOf(['bottom', 'top']),
268
+ slotProps: PropTypes.object,
269
+ slots: PropTypes.object,
213
270
  stroke: PropTypes.string,
214
271
  tickFontSize: PropTypes.number,
272
+ tickMaxStep: PropTypes.number,
273
+ tickMinStep: PropTypes.number,
274
+ tickNumber: PropTypes.number,
215
275
  tickSize: PropTypes.number
216
276
  }), PropTypes.string]),
217
277
  viewBox: PropTypes.shape({
@@ -234,15 +294,17 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
234
294
  label: PropTypes.string,
235
295
  labelFontSize: PropTypes.number,
236
296
  max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
237
- maxTicks: PropTypes.number,
238
297
  min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
239
- minTicks: PropTypes.number,
240
298
  position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
241
299
  scaleType: PropTypes.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
300
+ slotProps: PropTypes.object,
301
+ slots: PropTypes.object,
242
302
  stroke: PropTypes.string,
243
303
  tickFontSize: PropTypes.number,
304
+ tickMaxStep: PropTypes.number,
305
+ tickMinStep: PropTypes.number,
306
+ tickNumber: PropTypes.number,
244
307
  tickSize: PropTypes.number,
245
- tickSpacing: PropTypes.number,
246
308
  valueFormatter: PropTypes.func
247
309
  })),
248
310
  yAxis: PropTypes.arrayOf(PropTypes.shape({
@@ -258,15 +320,17 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
258
320
  label: PropTypes.string,
259
321
  labelFontSize: PropTypes.number,
260
322
  max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
261
- maxTicks: PropTypes.number,
262
323
  min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
263
- minTicks: PropTypes.number,
264
324
  position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
265
325
  scaleType: PropTypes.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
326
+ slotProps: PropTypes.object,
327
+ slots: PropTypes.object,
266
328
  stroke: PropTypes.string,
267
329
  tickFontSize: PropTypes.number,
330
+ tickMaxStep: PropTypes.number,
331
+ tickMinStep: PropTypes.number,
332
+ tickNumber: PropTypes.number,
268
333
  tickSize: PropTypes.number,
269
- tickSpacing: PropTypes.number,
270
334
  valueFormatter: PropTypes.func
271
335
  }))
272
336
  } : void 0;