@mui/x-charts 8.6.0 → 8.7.0

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 (140) hide show
  1. package/BarChart/BarPlot.js +11 -150
  2. package/BarChart/useBarPlotData.d.ts +8 -0
  3. package/BarChart/useBarPlotData.js +146 -0
  4. package/CHANGELOG.md +104 -1
  5. package/ChartContainer/ChartContainer.d.ts +1 -21
  6. package/ChartContainer/ChartContainer.js +0 -8
  7. package/ChartContainer/index.d.ts +8 -1
  8. package/ChartsReferenceLine/ChartsReferenceLine.d.ts +1 -1
  9. package/ChartsReferenceLine/ChartsXReferenceLine.d.ts +3 -0
  10. package/ChartsReferenceLine/ChartsXReferenceLine.js +48 -1
  11. package/ChartsReferenceLine/ChartsYReferenceLine.d.ts +3 -0
  12. package/ChartsReferenceLine/ChartsYReferenceLine.js +48 -1
  13. package/ChartsReferenceLine/index.d.ts +3 -1
  14. package/ChartsSurface/ChartsSurface.js +2 -1
  15. package/ChartsTooltip/ChartsTooltipContainer.js +6 -3
  16. package/ChartsTooltip/ChartsTooltipTable.d.ts +1 -1
  17. package/ChartsTooltip/utils.js +18 -29
  18. package/LineChart/AreaPlot.js +5 -115
  19. package/LineChart/LinePlot.js +5 -99
  20. package/LineChart/useAreaPlotData.d.ts +12 -0
  21. package/LineChart/useAreaPlotData.js +125 -0
  22. package/LineChart/useLinePlotData.d.ts +11 -0
  23. package/LineChart/useLinePlotData.js +108 -0
  24. package/ScatterChart/Scatter.js +22 -48
  25. package/ScatterChart/useScatterPlotData.d.ts +8 -0
  26. package/ScatterChart/useScatterPlotData.js +33 -0
  27. package/context/ChartApi.d.ts +22 -0
  28. package/context/ChartApi.js +5 -0
  29. package/context/ChartProvider/ChartContext.js +1 -0
  30. package/context/index.d.ts +2 -1
  31. package/context/useChartApiContext.d.ts +1 -1
  32. package/esm/BarChart/BarPlot.js +12 -152
  33. package/esm/BarChart/useBarPlotData.d.ts +8 -0
  34. package/esm/BarChart/useBarPlotData.js +139 -0
  35. package/esm/ChartContainer/ChartContainer.d.ts +1 -21
  36. package/esm/ChartContainer/ChartContainer.js +0 -8
  37. package/esm/ChartContainer/index.d.ts +8 -1
  38. package/esm/ChartContainer/index.js +6 -1
  39. package/esm/ChartsReferenceLine/ChartsReferenceLine.d.ts +1 -1
  40. package/esm/ChartsReferenceLine/ChartsXReferenceLine.d.ts +3 -0
  41. package/esm/ChartsReferenceLine/ChartsXReferenceLine.js +47 -0
  42. package/esm/ChartsReferenceLine/ChartsYReferenceLine.d.ts +3 -0
  43. package/esm/ChartsReferenceLine/ChartsYReferenceLine.js +47 -0
  44. package/esm/ChartsReferenceLine/index.d.ts +3 -1
  45. package/esm/ChartsReferenceLine/index.js +2 -1
  46. package/esm/ChartsSurface/ChartsSurface.js +2 -1
  47. package/esm/ChartsTooltip/ChartsTooltipContainer.js +6 -3
  48. package/esm/ChartsTooltip/ChartsTooltipTable.d.ts +1 -1
  49. package/esm/ChartsTooltip/utils.js +18 -29
  50. package/esm/LineChart/AreaPlot.js +5 -115
  51. package/esm/LineChart/LinePlot.js +5 -99
  52. package/esm/LineChart/useAreaPlotData.d.ts +12 -0
  53. package/esm/LineChart/useAreaPlotData.js +118 -0
  54. package/esm/LineChart/useLinePlotData.d.ts +11 -0
  55. package/esm/LineChart/useLinePlotData.js +101 -0
  56. package/esm/ScatterChart/Scatter.js +23 -49
  57. package/esm/ScatterChart/useScatterPlotData.d.ts +8 -0
  58. package/esm/ScatterChart/useScatterPlotData.js +26 -0
  59. package/esm/context/ChartApi.d.ts +22 -0
  60. package/esm/context/ChartApi.js +1 -0
  61. package/esm/context/ChartProvider/ChartContext.js +2 -0
  62. package/esm/context/index.d.ts +2 -1
  63. package/esm/context/useChartApiContext.d.ts +1 -1
  64. package/esm/hooks/useInteractionItemProps.d.ts +14 -9
  65. package/esm/hooks/useInteractionItemProps.js +28 -28
  66. package/esm/index.d.ts +2 -1
  67. package/esm/index.js +2 -2
  68. package/esm/internals/index.d.ts +5 -0
  69. package/esm/internals/index.js +5 -0
  70. package/esm/internals/plugins/corePlugins/corePlugins.d.ts +3 -2
  71. package/esm/internals/plugins/corePlugins/corePlugins.js +2 -1
  72. package/esm/internals/plugins/corePlugins/useChartAnimation/useChartAnimation.selectors.d.ts +1 -1
  73. package/esm/internals/plugins/corePlugins/useChartDimensions/useChartDimensions.js +1 -29
  74. package/esm/internals/plugins/corePlugins/useChartDimensions/useChartDimensions.selectors.d.ts +3 -3
  75. package/esm/internals/plugins/corePlugins/useChartDimensions/useChartDimensions.types.d.ts +0 -6
  76. package/esm/internals/plugins/corePlugins/useChartId/useChartId.js +2 -0
  77. package/esm/internals/plugins/corePlugins/useChartId/useChartId.selectors.d.ts +1 -1
  78. package/esm/internals/plugins/corePlugins/useChartInteractionListener/index.d.ts +2 -0
  79. package/esm/internals/plugins/corePlugins/useChartInteractionListener/index.js +1 -0
  80. package/esm/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.d.ts +3 -0
  81. package/esm/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.js +77 -0
  82. package/esm/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.types.d.ts +31 -0
  83. package/esm/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.types.js +1 -0
  84. package/esm/internals/plugins/corePlugins/useChartSeries/useChartSeries.selectors.d.ts +2 -2
  85. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartAxisSize.selectors.d.ts +4 -4
  86. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxis.js +44 -33
  87. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisRendering.selectors.d.ts +5 -5
  88. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianInteraction.selectors.d.ts +7 -7
  89. package/esm/internals/plugins/featurePlugins/useChartHighlight/useChartHighlight.selectors.d.ts +5 -5
  90. package/esm/internals/plugins/featurePlugins/useChartInteraction/useChartInteraction.selectors.d.ts +6 -6
  91. package/esm/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarAxis.js +34 -34
  92. package/esm/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarAxis.selectors.d.ts +5 -5
  93. package/esm/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarInteraction.selectors.d.ts +6 -6
  94. package/esm/internals/plugins/featurePlugins/useChartVoronoi/useChartVoronoi.js +47 -30
  95. package/esm/internals/plugins/featurePlugins/useChartVoronoi/useChartVoronoi.selectors.d.ts +1 -1
  96. package/esm/internals/plugins/featurePlugins/useChartZAxis/useChartZAxis.selectors.d.ts +1 -1
  97. package/esm/internals/store/useCharts.d.ts +1 -1
  98. package/esm/locales/elGR.d.ts +19 -0
  99. package/esm/locales/elGR.js +15 -0
  100. package/esm/locales/index.d.ts +1 -0
  101. package/esm/locales/index.js +1 -0
  102. package/hooks/useInteractionItemProps.d.ts +14 -9
  103. package/hooks/useInteractionItemProps.js +29 -28
  104. package/index.d.ts +2 -1
  105. package/index.js +37 -11
  106. package/internals/index.d.ts +5 -0
  107. package/internals/index.js +44 -0
  108. package/internals/plugins/corePlugins/corePlugins.d.ts +3 -2
  109. package/internals/plugins/corePlugins/corePlugins.js +2 -1
  110. package/internals/plugins/corePlugins/useChartAnimation/useChartAnimation.selectors.d.ts +1 -1
  111. package/internals/plugins/corePlugins/useChartDimensions/useChartDimensions.js +1 -29
  112. package/internals/plugins/corePlugins/useChartDimensions/useChartDimensions.selectors.d.ts +3 -3
  113. package/internals/plugins/corePlugins/useChartDimensions/useChartDimensions.types.d.ts +0 -6
  114. package/internals/plugins/corePlugins/useChartId/useChartId.js +1 -0
  115. package/internals/plugins/corePlugins/useChartId/useChartId.selectors.d.ts +1 -1
  116. package/internals/plugins/corePlugins/useChartInteractionListener/index.d.ts +2 -0
  117. package/internals/plugins/corePlugins/useChartInteractionListener/index.js +12 -0
  118. package/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.d.ts +3 -0
  119. package/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.js +84 -0
  120. package/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.types.d.ts +31 -0
  121. package/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.types.js +5 -0
  122. package/internals/plugins/corePlugins/useChartSeries/useChartSeries.selectors.d.ts +2 -2
  123. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartAxisSize.selectors.d.ts +4 -4
  124. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxis.js +44 -33
  125. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisRendering.selectors.d.ts +5 -5
  126. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianInteraction.selectors.d.ts +7 -7
  127. package/internals/plugins/featurePlugins/useChartHighlight/useChartHighlight.selectors.d.ts +5 -5
  128. package/internals/plugins/featurePlugins/useChartInteraction/useChartInteraction.selectors.d.ts +6 -6
  129. package/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarAxis.js +34 -34
  130. package/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarAxis.selectors.d.ts +5 -5
  131. package/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarInteraction.selectors.d.ts +6 -6
  132. package/internals/plugins/featurePlugins/useChartVoronoi/useChartVoronoi.js +46 -30
  133. package/internals/plugins/featurePlugins/useChartVoronoi/useChartVoronoi.selectors.d.ts +1 -1
  134. package/internals/plugins/featurePlugins/useChartZAxis/useChartZAxis.selectors.d.ts +1 -1
  135. package/internals/store/useCharts.d.ts +1 -1
  136. package/locales/elGR.d.ts +19 -0
  137. package/locales/elGR.js +21 -0
  138. package/locales/index.d.ts +1 -0
  139. package/locales/index.js +11 -0
  140. package/package.json +3 -2
@@ -14,160 +14,15 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
14
14
  var _styles = require("@mui/material/styles");
15
15
  var _barElementClasses = require("./barElementClasses");
16
16
  var _BarElement = require("./BarElement");
17
- var _getColor = _interopRequireDefault(require("./seriesConfig/getColor"));
18
17
  var _hooks = require("../hooks");
19
18
  var _BarClipPath = require("./BarClipPath");
20
19
  var _BarLabelPlot = require("./BarLabel/BarLabelPlot");
21
- var _checkScaleErrors = require("./checkScaleErrors");
22
- var _useBarSeries = require("../hooks/useBarSeries");
23
20
  var _useSkipAnimation = require("../hooks/useSkipAnimation");
24
21
  var _useInternalIsZoomInteracting = require("../internals/plugins/featurePlugins/useChartCartesianAxis/useInternalIsZoomInteracting");
22
+ var _useBarPlotData = require("./useBarPlotData");
25
23
  var _barClasses = require("./barClasses");
26
24
  var _jsxRuntime = require("react/jsx-runtime");
27
25
  const _excluded = ["skipAnimation", "onItemClick", "borderRadius", "barLabel"];
28
- /**
29
- * Solution of the equations
30
- * W = barWidth * N + offset * (N-1)
31
- * offset / (offset + barWidth) = r
32
- * @param bandWidth The width available to place bars.
33
- * @param numberOfGroups The number of bars to place in that space.
34
- * @param gapRatio The ratio of the gap between bars over the bar width.
35
- * @returns The bar width and the offset between bars.
36
- */
37
- function getBandSize({
38
- bandWidth: W,
39
- numberOfGroups: N,
40
- gapRatio: r
41
- }) {
42
- if (r === 0) {
43
- return {
44
- barWidth: W / N,
45
- offset: 0
46
- };
47
- }
48
- const barWidth = W / (N + (N - 1) * r);
49
- const offset = r * barWidth;
50
- return {
51
- barWidth,
52
- offset
53
- };
54
- }
55
- const useAggregatedData = () => {
56
- const seriesData = (0, _useBarSeries.useBarSeriesContext)() ?? {
57
- series: {},
58
- stackingGroups: [],
59
- seriesOrder: []
60
- };
61
- const drawingArea = (0, _hooks.useDrawingArea)();
62
- const chartId = (0, _hooks.useChartId)();
63
- const {
64
- series,
65
- stackingGroups
66
- } = seriesData;
67
- const {
68
- xAxis,
69
- xAxisIds
70
- } = (0, _hooks.useXAxes)();
71
- const {
72
- yAxis,
73
- yAxisIds
74
- } = (0, _hooks.useYAxes)();
75
- const defaultXAxisId = xAxisIds[0];
76
- const defaultYAxisId = yAxisIds[0];
77
- const masks = {};
78
- const data = stackingGroups.flatMap(({
79
- ids: seriesIds
80
- }, groupIndex) => {
81
- const xMin = drawingArea.left;
82
- const xMax = drawingArea.left + drawingArea.width;
83
- const yMin = drawingArea.top;
84
- const yMax = drawingArea.top + drawingArea.height;
85
- return seriesIds.map(seriesId => {
86
- const xAxisId = series[seriesId].xAxisId ?? defaultXAxisId;
87
- const yAxisId = series[seriesId].yAxisId ?? defaultYAxisId;
88
- const xAxisConfig = xAxis[xAxisId];
89
- const yAxisConfig = yAxis[yAxisId];
90
- const verticalLayout = series[seriesId].layout === 'vertical';
91
- (0, _checkScaleErrors.checkScaleErrors)(verticalLayout, seriesId, series[seriesId], xAxisId, xAxis, yAxisId, yAxis);
92
- const baseScaleConfig = verticalLayout ? xAxisConfig : yAxisConfig;
93
- const xScale = xAxisConfig.scale;
94
- const yScale = yAxisConfig.scale;
95
- const colorGetter = (0, _getColor.default)(series[seriesId], xAxis[xAxisId], yAxis[yAxisId]);
96
- const bandWidth = baseScaleConfig.scale.bandwidth();
97
- const {
98
- barWidth,
99
- offset
100
- } = getBandSize({
101
- bandWidth,
102
- numberOfGroups: stackingGroups.length,
103
- gapRatio: baseScaleConfig.barGapRatio
104
- });
105
- const barOffset = groupIndex * (barWidth + offset);
106
- const {
107
- stackedData,
108
- data: currentSeriesData,
109
- layout
110
- } = series[seriesId];
111
- const seriesDataPoints = baseScaleConfig.data.map((baseValue, dataIndex) => {
112
- if (currentSeriesData[dataIndex] == null) {
113
- return null;
114
- }
115
- const values = stackedData[dataIndex];
116
- const valueCoordinates = values.map(v => verticalLayout ? yScale(v) : xScale(v));
117
- const minValueCoord = Math.round(Math.min(...valueCoordinates));
118
- const maxValueCoord = Math.round(Math.max(...valueCoordinates));
119
- const stackId = series[seriesId].stack;
120
- const result = {
121
- seriesId,
122
- dataIndex,
123
- layout,
124
- x: verticalLayout ? xScale(baseValue) + barOffset : minValueCoord,
125
- y: verticalLayout ? minValueCoord : yScale(baseValue) + barOffset,
126
- xOrigin: xScale(0) ?? 0,
127
- yOrigin: yScale(0) ?? 0,
128
- height: verticalLayout ? maxValueCoord - minValueCoord : barWidth,
129
- width: verticalLayout ? barWidth : maxValueCoord - minValueCoord,
130
- color: colorGetter(dataIndex),
131
- value: currentSeriesData[dataIndex],
132
- maskId: `${chartId}_${stackId || seriesId}_${groupIndex}_${dataIndex}`
133
- };
134
- if (result.x > xMax || result.x + result.width < xMin || result.y > yMax || result.y + result.height < yMin) {
135
- return null;
136
- }
137
- if (!masks[result.maskId]) {
138
- masks[result.maskId] = {
139
- id: result.maskId,
140
- width: 0,
141
- height: 0,
142
- hasNegative: false,
143
- hasPositive: false,
144
- layout: result.layout,
145
- xOrigin: xScale(0),
146
- yOrigin: yScale(0),
147
- x: 0,
148
- y: 0
149
- };
150
- }
151
- const mask = masks[result.maskId];
152
- mask.width = result.layout === 'vertical' ? result.width : mask.width + result.width;
153
- mask.height = result.layout === 'vertical' ? mask.height + result.height : result.height;
154
- mask.x = Math.min(mask.x === 0 ? Infinity : mask.x, result.x);
155
- mask.y = Math.min(mask.y === 0 ? Infinity : mask.y, result.y);
156
- mask.hasNegative = mask.hasNegative || (result.value ?? 0) < 0;
157
- mask.hasPositive = mask.hasPositive || (result.value ?? 0) > 0;
158
- return result;
159
- }).filter(rectangle => rectangle !== null);
160
- return {
161
- seriesId,
162
- data: seriesDataPoints
163
- };
164
- });
165
- });
166
- return {
167
- completedData: data,
168
- masksData: Object.values(masks)
169
- };
170
- };
171
26
  const BarPlotRoot = (0, _styles.styled)('g', {
172
27
  name: 'MuiBarPlot',
173
28
  slot: 'Root'
@@ -189,10 +44,6 @@ const BarPlotRoot = (0, _styles.styled)('g', {
189
44
  * - [BarPlot API](https://mui.com/x/api/charts/bar-plot/)
190
45
  */
191
46
  function BarPlot(props) {
192
- const {
193
- completedData,
194
- masksData
195
- } = useAggregatedData();
196
47
  const {
197
48
  skipAnimation: inSkipAnimation,
198
49
  onItemClick,
@@ -202,6 +53,16 @@ function BarPlot(props) {
202
53
  other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
203
54
  const isZoomInteracting = (0, _useInternalIsZoomInteracting.useInternalIsZoomInteracting)();
204
55
  const skipAnimation = (0, _useSkipAnimation.useSkipAnimation)(isZoomInteracting || inSkipAnimation);
56
+ const {
57
+ xAxis: xAxes
58
+ } = (0, _hooks.useXAxes)();
59
+ const {
60
+ yAxis: yAxes
61
+ } = (0, _hooks.useYAxes)();
62
+ const {
63
+ completedData,
64
+ masksData
65
+ } = (0, _useBarPlotData.useBarPlotData)((0, _hooks.useDrawingArea)(), xAxes, yAxes);
205
66
  const withoutBorderRadius = !borderRadius || borderRadius <= 0;
206
67
  const classes = (0, _barClasses.useUtilityClasses)();
207
68
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(BarPlotRoot, {
@@ -0,0 +1,8 @@
1
+ import { ChartsXAxisProps, ChartsYAxisProps } from "../models/axis.js";
2
+ import { ChartDrawingArea } from "../hooks/index.js";
3
+ import { MaskData, ProcessedBarSeriesData } from "./types.js";
4
+ import { ComputedAxisConfig } from "../internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxis.types.js";
5
+ export declare function useBarPlotData(drawingArea: ChartDrawingArea, xAxes: ComputedAxisConfig<ChartsXAxisProps>, yAxes: ComputedAxisConfig<ChartsYAxisProps>): {
6
+ completedData: ProcessedBarSeriesData[];
7
+ masksData: MaskData[];
8
+ };
@@ -0,0 +1,146 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.useBarPlotData = useBarPlotData;
8
+ var _getColor = _interopRequireDefault(require("./seriesConfig/getColor"));
9
+ var _hooks = require("../hooks");
10
+ var _checkScaleErrors = require("./checkScaleErrors");
11
+ var _useBarSeries = require("../hooks/useBarSeries");
12
+ function useBarPlotData(drawingArea, xAxes, yAxes) {
13
+ const seriesData = (0, _useBarSeries.useBarSeriesContext)() ?? {
14
+ series: {},
15
+ stackingGroups: [],
16
+ seriesOrder: []
17
+ };
18
+ const defaultXAxisId = (0, _hooks.useXAxes)().xAxisIds[0];
19
+ const defaultYAxisId = (0, _hooks.useYAxes)().yAxisIds[0];
20
+ const chartId = (0, _hooks.useChartId)();
21
+ const {
22
+ series,
23
+ stackingGroups
24
+ } = seriesData;
25
+ const masks = {};
26
+ const data = stackingGroups.flatMap(({
27
+ ids: seriesIds
28
+ }, groupIndex) => {
29
+ const xMin = drawingArea.left;
30
+ const xMax = drawingArea.left + drawingArea.width;
31
+ const yMin = drawingArea.top;
32
+ const yMax = drawingArea.top + drawingArea.height;
33
+ return seriesIds.map(seriesId => {
34
+ const xAxisId = series[seriesId].xAxisId ?? defaultXAxisId;
35
+ const yAxisId = series[seriesId].yAxisId ?? defaultYAxisId;
36
+ const xAxisConfig = xAxes[xAxisId];
37
+ const yAxisConfig = yAxes[yAxisId];
38
+ const verticalLayout = series[seriesId].layout === 'vertical';
39
+ (0, _checkScaleErrors.checkScaleErrors)(verticalLayout, seriesId, series[seriesId], xAxisId, xAxes, yAxisId, yAxes);
40
+ const baseScaleConfig = verticalLayout ? xAxisConfig : yAxisConfig;
41
+ const xScale = xAxisConfig.scale;
42
+ const yScale = yAxisConfig.scale;
43
+ const colorGetter = (0, _getColor.default)(series[seriesId], xAxes[xAxisId], yAxes[yAxisId]);
44
+ const bandWidth = baseScaleConfig.scale.bandwidth();
45
+ const {
46
+ barWidth,
47
+ offset
48
+ } = getBandSize({
49
+ bandWidth,
50
+ numberOfGroups: stackingGroups.length,
51
+ gapRatio: baseScaleConfig.barGapRatio
52
+ });
53
+ const barOffset = groupIndex * (barWidth + offset);
54
+ const {
55
+ stackedData,
56
+ data: currentSeriesData,
57
+ layout
58
+ } = series[seriesId];
59
+ const seriesDataPoints = baseScaleConfig.data.map((baseValue, dataIndex) => {
60
+ if (currentSeriesData[dataIndex] == null) {
61
+ return null;
62
+ }
63
+ const values = stackedData[dataIndex];
64
+ const valueCoordinates = values.map(v => verticalLayout ? yScale(v) : xScale(v));
65
+ const minValueCoord = Math.round(Math.min(...valueCoordinates));
66
+ const maxValueCoord = Math.round(Math.max(...valueCoordinates));
67
+ const stackId = series[seriesId].stack;
68
+ const result = {
69
+ seriesId,
70
+ dataIndex,
71
+ layout,
72
+ x: verticalLayout ? xScale(baseValue) + barOffset : minValueCoord,
73
+ y: verticalLayout ? minValueCoord : yScale(baseValue) + barOffset,
74
+ xOrigin: xScale(0) ?? 0,
75
+ yOrigin: yScale(0) ?? 0,
76
+ height: verticalLayout ? maxValueCoord - minValueCoord : barWidth,
77
+ width: verticalLayout ? barWidth : maxValueCoord - minValueCoord,
78
+ color: colorGetter(dataIndex),
79
+ value: currentSeriesData[dataIndex],
80
+ maskId: `${chartId}_${stackId || seriesId}_${groupIndex}_${dataIndex}`
81
+ };
82
+ if (result.x > xMax || result.x + result.width < xMin || result.y > yMax || result.y + result.height < yMin) {
83
+ return null;
84
+ }
85
+ if (!masks[result.maskId]) {
86
+ masks[result.maskId] = {
87
+ id: result.maskId,
88
+ width: 0,
89
+ height: 0,
90
+ hasNegative: false,
91
+ hasPositive: false,
92
+ layout: result.layout,
93
+ xOrigin: xScale(0),
94
+ yOrigin: yScale(0),
95
+ x: 0,
96
+ y: 0
97
+ };
98
+ }
99
+ const mask = masks[result.maskId];
100
+ mask.width = result.layout === 'vertical' ? result.width : mask.width + result.width;
101
+ mask.height = result.layout === 'vertical' ? mask.height + result.height : result.height;
102
+ mask.x = Math.min(mask.x === 0 ? Infinity : mask.x, result.x);
103
+ mask.y = Math.min(mask.y === 0 ? Infinity : mask.y, result.y);
104
+ mask.hasNegative = mask.hasNegative || (result.value ?? 0) < 0;
105
+ mask.hasPositive = mask.hasPositive || (result.value ?? 0) > 0;
106
+ return result;
107
+ }).filter(rectangle => rectangle !== null);
108
+ return {
109
+ seriesId,
110
+ data: seriesDataPoints
111
+ };
112
+ });
113
+ });
114
+ return {
115
+ completedData: data,
116
+ masksData: Object.values(masks)
117
+ };
118
+ }
119
+
120
+ /**
121
+ * Solution of the equations
122
+ * W = barWidth * N + offset * (N-1)
123
+ * offset / (offset + barWidth) = r
124
+ * @param bandWidth The width available to place bars.
125
+ * @param numberOfGroups The number of bars to place in that space.
126
+ * @param gapRatio The ratio of the gap between bars over the bar width.
127
+ * @returns The bar width and the offset between bars.
128
+ */
129
+ function getBandSize({
130
+ bandWidth: W,
131
+ numberOfGroups: N,
132
+ gapRatio: r
133
+ }) {
134
+ if (r === 0) {
135
+ return {
136
+ barWidth: W / N,
137
+ offset: 0
138
+ };
139
+ }
140
+ const barWidth = W / (N + (N - 1) * r);
141
+ const offset = r * barWidth;
142
+ return {
143
+ barWidth,
144
+ offset
145
+ };
146
+ }
package/CHANGELOG.md CHANGED
@@ -5,6 +5,109 @@
5
5
  All notable changes to this project will be documented in this file.
6
6
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
7
7
 
8
+ ## 8.7.0
9
+
10
+ _Jul 4, 2025_
11
+
12
+ We'd like to extend a big thank you to the 15 contributors who made this release possible. Here are some highlights ✨:
13
+
14
+ - 📊 Add `useChartProApiRef` for easier access to the API
15
+ - 📆 Support different start and end `referenceDate` props on range components
16
+ - 📚 Documentation improvements
17
+ - 🐞 Bugfixes
18
+ - 🌎 Improve Greek (el-GR) translations on the Charts
19
+ - 🌎 Improve Danish (da-DK) locale on the Data Grid
20
+
21
+ Special thanks go out to the community members for their valuable contributions:
22
+ @ShahrazH, @vadimkuragkovskiy, @whythecode
23
+
24
+ The following are all team members who have contributed to this release:
25
+ @alexfauquette, @brijeshb42, @mapache-salvaje, @arminmeh, @bernardobelchior, @bharatkashyap, @Janpot, @JCQuintas, @KenanYusuf, @LukasTy, @michelengelen, @rita-codes
26
+
27
+ ### Data Grid
28
+
29
+ #### `@mui/x-data-grid@8.7.0`
30
+
31
+ - [DataGrid] Fix column state restore with controlled column visibility model (#18567) @arminmeh
32
+ - [DataGrid] Fix styling virtualized column headers (#18603) @KenanYusuf
33
+ - [l10n] Improve Danish (da-DK) locale (#18537) @ShahrazH
34
+
35
+ #### `@mui/x-data-grid-pro@8.7.0` [![pro](https://mui.com/r/x-pro-svg)](https://mui.com/r/x-pro-svg-link 'Pro plan')
36
+
37
+ Same changes as in `@mui/x-data-grid@8.7.0`.
38
+
39
+ #### `@mui/x-data-grid-premium@8.7.0` [![premium](https://mui.com/r/x-premium-svg)](https://mui.com/r/x-premium-svg-link 'Premium plan')
40
+
41
+ Same changes as in `@mui/x-data-grid-pro@8.7.0`.
42
+
43
+ ### Date and Time Pickers
44
+
45
+ #### `@mui/x-date-pickers@8.7.0`
46
+
47
+ - [pickers] Support different `start` and `end` `referenceDate` props on range components (#18549) @LukasTy
48
+
49
+ #### `@mui/x-date-pickers-pro@8.7.0` [![pro](https://mui.com/r/x-pro-svg)](https://mui.com/r/x-pro-svg-link 'Pro plan')
50
+
51
+ Same changes as in `@mui/x-date-pickers@8.7.0`.
52
+
53
+ ### Charts
54
+
55
+ #### `@mui/x-charts@8.7.0`
56
+
57
+ - [charts] Export `ChartsReferenceLineProps` (#18598) @bernardobelchior
58
+ - [charts] Extract bar and line plot logic into reusable hooks (#18541) @bernardobelchior
59
+ - [charts] Extract plot logic into separate files for reuse (#18522) @bernardobelchior
60
+ - [charts] Profile charts benchmarks using chromium (#18528) @bernardobelchior
61
+ - [l10n] Add Greek (el-GR) locale to charts (#18548) @whythecode
62
+
63
+ #### `@mui/x-charts-pro@8.7.0` [![pro](https://mui.com/r/x-pro-svg)](https://mui.com/r/x-pro-svg-link 'Pro plan')
64
+
65
+ Same changes as in `@mui/x-charts@8.7.0`, plus:
66
+
67
+ - [charts-pro] Add `useChartProApiRef` for easier refs (#18013) @JCQuintas
68
+ - [charts-pro] Add tests and classes to zoom slider (#18660) @JCQuintas
69
+ - [charts-pro] Fix geometry not handling gestures in specific scenarios (#18651) @JCQuintas
70
+ - [charts-pro] Rename `useChartApiContext` to `useChartProApiContext` (#18565) @JCQuintas
71
+ - [charts-pro] Zoom pointer improvements (#17480) @JCQuintas
72
+
73
+ ### Tree View
74
+
75
+ #### `@mui/x-tree-view@8.7.0`
76
+
77
+ Internal changes.
78
+
79
+ #### `@mui/x-tree-view-pro@8.7.0` [![pro](https://mui.com/r/x-pro-svg)](https://mui.com/r/x-pro-svg-link 'Pro plan')
80
+
81
+ Same changes as in `@mui/x-tree-view@8.7.0`, plus:
82
+
83
+ - [tree view pro] Add missing `dataSource` JSDoc (#18650) @LukasTy
84
+
85
+ ### Docs
86
+
87
+ - [docs] Add MCP stub (#18204) @bharatkashyap
88
+ - [docs] Fix AI Assistant proxy rewrite prefix (#18661) @arminmeh
89
+ - [docs] Improve test README.MD (#18634) @LukasTy
90
+ - [docs] Provide workaround for pie chart composition (#18600) @alexfauquette
91
+ - [docs][charts] Add donut chart as a special case of a pie chart (#18652) @bernardobelchior
92
+ - [docs][charts] Centralize country and continent data (#18604) @bernardobelchior
93
+ - [docs][data grid] Audit and revise the Pro row docs (#17926) @mapache-salvaje
94
+ - [docs][pickers] Add mention of theme augmentation in relevant migration section (#18608) @LukasTy
95
+
96
+ ### Core
97
+
98
+ - [core] Avoid stringifying `document` object (#18657) @vadimkuragkovskiy
99
+
100
+ ### Miscellaneous
101
+
102
+ - [code-infra] Bump code-infra version and fix breaking changes (#18653) @brijeshb42
103
+ - [code-infra] Ensure `material-ui/disallow-react-api-in-server-components` ESLint rule is applied (#18570) @LukasTy
104
+ - [code-infra] Migrate to flat eslint config (#18562) @brijeshb42
105
+ - [code-infra] Refactor eslint config (#18643) @LukasTy
106
+ - [infra] Add renovatebot rule for latest infra packages (#18609) @Janpot
107
+ - [infra] Move pushArgos script to code-infra (#18667) @Janpot
108
+ - [infra] Updates release script to fetch latest major version from upstream (#18552) @michelengelen
109
+ - [release] Add missing contributor to changelog (#18561) @bernardobelchior
110
+
8
111
  ## 8.6.0
9
112
 
10
113
  _Jun 27, 2025_
@@ -19,7 +122,7 @@ We'd like to extend a big thank you to the 12 contributors who made this release
19
122
  - 🌎 Improve German (de-DE) locale
20
123
 
21
124
  Special thanks go out to the community members for their valuable contributions:
22
- @ShahrazH, @vadimka123
125
+ @omalyutin, @ShahrazH, @vadimka123
23
126
 
24
127
  The following are all team members who have contributed to this release:
25
128
  @arminmeh, @bernardobelchior, @JCQuintas, @KenanYusuf, @LukasTy, @MBilalShafi, @michelengelen, @noraleonte, @rita-codes, @sai6855
@@ -1,30 +1,10 @@
1
1
  import * as React from 'react';
2
- import { PieChartPluginSignatures } from "../PieChart/PieChart.plugins.js";
3
- import { BarChartPluginsSignatures } from "../BarChart/BarChart.plugins.js";
4
- import { ScatterChartPluginsSignatures } from "../ScatterChart/ScatterChart.plugins.js";
5
- import { LineChartPluginsSignatures } from "../LineChart/LineChart.plugins.js";
6
2
  import { ChartSeriesType } from "../models/seriesType/config.js";
7
3
  import { ChartDataProviderProps } from "../ChartDataProvider/index.js";
8
4
  import { ChartsSurfaceProps } from "../ChartsSurface/index.js";
9
- import { AllPluginSignatures, DefaultPluginSignatures } from "../internals/plugins/allPlugins.js";
5
+ import { AllPluginSignatures } from "../internals/plugins/allPlugins.js";
10
6
  import { ChartAnyPluginSignature } from "../internals/plugins/models/plugin.js";
11
- import { ChartPublicAPI } from "../internals/plugins/models/index.js";
12
7
  export type ChartContainerProps<SeriesType extends ChartSeriesType = ChartSeriesType, TSignatures extends readonly ChartAnyPluginSignature[] = AllPluginSignatures<SeriesType>> = Omit<ChartDataProviderProps<SeriesType, TSignatures>, 'children'> & ChartsSurfaceProps;
13
- type PluginsPerSeriesType = {
14
- line: LineChartPluginsSignatures;
15
- scatter: ScatterChartPluginsSignatures;
16
- bar: BarChartPluginsSignatures;
17
- pie: PieChartPluginSignatures;
18
- composition: DefaultPluginSignatures;
19
- };
20
- /**
21
- * The API of the chart `apiRef` object.
22
- * The chart type can be passed as the first generic parameter to narrow down the API to the specific chart type.
23
- * @example ChartApi<'bar'>
24
- * If the chart is being created using composition, the `composition` value can be used.
25
- * @example ChartApi<'composition'>
26
- */
27
- export type ChartApi<TSeries extends keyof PluginsPerSeriesType | undefined = undefined, TSignatures extends readonly ChartAnyPluginSignature[] = (TSeries extends keyof PluginsPerSeriesType ? PluginsPerSeriesType[TSeries] : AllPluginSignatures)> = ChartPublicAPI<TSignatures>;
28
8
  /**
29
9
  * It sets up the data providers as well as the `<svg>` for the chart.
30
10
  *
@@ -14,14 +14,6 @@ var _ChartDataProvider = require("../ChartDataProvider");
14
14
  var _useChartContainerProps = require("./useChartContainerProps");
15
15
  var _ChartsSurface = require("../ChartsSurface");
16
16
  var _jsxRuntime = require("react/jsx-runtime");
17
- /**
18
- * The API of the chart `apiRef` object.
19
- * The chart type can be passed as the first generic parameter to narrow down the API to the specific chart type.
20
- * @example ChartApi<'bar'>
21
- * If the chart is being created using composition, the `composition` value can be used.
22
- * @example ChartApi<'composition'>
23
- */
24
-
25
17
  /**
26
18
  * It sets up the data providers as well as the `<svg>` for the chart.
27
19
  *
@@ -1 +1,8 @@
1
- export * from "./ChartContainer.js";
1
+ import type { ChartApi as ChartApiOriginal, PluginsPerSeriesType } from "../context/ChartApi.js";
2
+ import type { ChartAnyPluginSignature } from "../internals/plugins/models/plugin.js";
3
+ import type { AllPluginSignatures } from "../internals/plugins/allPlugins.js";
4
+ export * from "./ChartContainer.js";
5
+ /**
6
+ * @deprecated Use `ChartApi` from `@mui/x-charts/context` instead.
7
+ */
8
+ export type ChartApi<TSeries extends keyof PluginsPerSeriesType | undefined = undefined, TSignatures extends readonly ChartAnyPluginSignature[] = (TSeries extends keyof PluginsPerSeriesType ? PluginsPerSeriesType[TSeries] : AllPluginSignatures)> = ChartApiOriginal<TSeries, TSignatures>;
@@ -7,4 +7,4 @@ declare function ChartsReferenceLine(props: ChartsReferenceLineProps): React.JSX
7
7
  declare namespace ChartsReferenceLine {
8
8
  var propTypes: any;
9
9
  }
10
- export { ChartsReferenceLine };
10
+ export { ChartsReferenceLine, type ChartsReferenceLineProps };
@@ -10,4 +10,7 @@ export type ChartsXReferenceLineProps<TValue extends string | number | Date = st
10
10
  };
11
11
  export declare function getXReferenceLineClasses(classes?: Partial<ChartsReferenceLineClasses>): Record<"root" | "line" | "label", string>;
12
12
  declare function ChartsXReferenceLine(props: ChartsXReferenceLineProps): React.JSX.Element | null;
13
+ declare namespace ChartsXReferenceLine {
14
+ var propTypes: any;
15
+ }
13
16
  export { ChartsXReferenceLine };
@@ -10,6 +10,7 @@ exports.ChartsXReferenceLine = ChartsXReferenceLine;
10
10
  exports.getXReferenceLineClasses = getXReferenceLineClasses;
11
11
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
12
12
  var React = _interopRequireWildcard(require("react"));
13
+ var _propTypes = _interopRequireDefault(require("prop-types"));
13
14
  var _composeClasses = _interopRequireDefault(require("@mui/utils/composeClasses"));
14
15
  var _warning = require("@mui/x-internals/warning");
15
16
  var _hooks = require("../hooks");
@@ -106,4 +107,50 @@ function ChartsXReferenceLine(props) {
106
107
  style: (0, _extends2.default)({}, textParams.style, labelStyle)
107
108
  }))]
108
109
  });
109
- }
110
+ }
111
+ process.env.NODE_ENV !== "production" ? ChartsXReferenceLine.propTypes = {
112
+ // ----------------------------- Warning --------------------------------
113
+ // | These PropTypes are generated from the TypeScript type definitions |
114
+ // | To update them edit the TypeScript types and run "pnpm proptypes" |
115
+ // ----------------------------------------------------------------------
116
+ /**
117
+ * The id of the axis used for the reference value.
118
+ * @default The `id` of the first defined axis.
119
+ */
120
+ axisId: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]),
121
+ /**
122
+ * Override or extend the styles applied to the component.
123
+ */
124
+ classes: _propTypes.default.object,
125
+ /**
126
+ * The label to display along the reference line.
127
+ */
128
+ label: _propTypes.default.string,
129
+ /**
130
+ * The alignment if the label is in the chart drawing area.
131
+ * @default 'middle'
132
+ */
133
+ labelAlign: _propTypes.default.oneOf(['end', 'middle', 'start']),
134
+ /**
135
+ * The style applied to the label.
136
+ */
137
+ labelStyle: _propTypes.default.object,
138
+ /**
139
+ * The style applied to the line.
140
+ */
141
+ lineStyle: _propTypes.default.object,
142
+ /**
143
+ * Additional space around the label in px.
144
+ * Can be a number or an object `{ x, y }` to distinguish space with the reference line and space with axes.
145
+ * @default 5
146
+ */
147
+ spacing: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.shape({
148
+ x: _propTypes.default.number,
149
+ y: _propTypes.default.number
150
+ })]),
151
+ /**
152
+ * The x value associated with the reference line.
153
+ * If defined the reference line will be vertical.
154
+ */
155
+ x: _propTypes.default.oneOfType([_propTypes.default.instanceOf(Date), _propTypes.default.number, _propTypes.default.string]).isRequired
156
+ } : void 0;
@@ -10,4 +10,7 @@ export type ChartsYReferenceLineProps<TValue extends string | number | Date = st
10
10
  };
11
11
  export declare function getYReferenceLineClasses(classes?: Partial<ChartsReferenceLineClasses>): Record<"root" | "line" | "label", string>;
12
12
  declare function ChartsYReferenceLine(props: ChartsYReferenceLineProps): React.JSX.Element | null;
13
+ declare namespace ChartsYReferenceLine {
14
+ var propTypes: any;
15
+ }
13
16
  export { ChartsYReferenceLine };
@@ -10,6 +10,7 @@ exports.ChartsYReferenceLine = ChartsYReferenceLine;
10
10
  exports.getYReferenceLineClasses = getYReferenceLineClasses;
11
11
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
12
12
  var React = _interopRequireWildcard(require("react"));
13
+ var _propTypes = _interopRequireDefault(require("prop-types"));
13
14
  var _composeClasses = _interopRequireDefault(require("@mui/utils/composeClasses"));
14
15
  var _warning = require("@mui/x-internals/warning");
15
16
  var _hooks = require("../hooks");
@@ -106,4 +107,50 @@ function ChartsYReferenceLine(props) {
106
107
  style: (0, _extends2.default)({}, textParams.style, labelStyle)
107
108
  }))]
108
109
  });
109
- }
110
+ }
111
+ process.env.NODE_ENV !== "production" ? ChartsYReferenceLine.propTypes = {
112
+ // ----------------------------- Warning --------------------------------
113
+ // | These PropTypes are generated from the TypeScript type definitions |
114
+ // | To update them edit the TypeScript types and run "pnpm proptypes" |
115
+ // ----------------------------------------------------------------------
116
+ /**
117
+ * The id of the axis used for the reference value.
118
+ * @default The `id` of the first defined axis.
119
+ */
120
+ axisId: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]),
121
+ /**
122
+ * Override or extend the styles applied to the component.
123
+ */
124
+ classes: _propTypes.default.object,
125
+ /**
126
+ * The label to display along the reference line.
127
+ */
128
+ label: _propTypes.default.string,
129
+ /**
130
+ * The alignment if the label is in the chart drawing area.
131
+ * @default 'middle'
132
+ */
133
+ labelAlign: _propTypes.default.oneOf(['end', 'middle', 'start']),
134
+ /**
135
+ * The style applied to the label.
136
+ */
137
+ labelStyle: _propTypes.default.object,
138
+ /**
139
+ * The style applied to the line.
140
+ */
141
+ lineStyle: _propTypes.default.object,
142
+ /**
143
+ * Additional space around the label in px.
144
+ * Can be a number or an object `{ x, y }` to distinguish space with the reference line and space with axes.
145
+ * @default 5
146
+ */
147
+ spacing: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.shape({
148
+ x: _propTypes.default.number,
149
+ y: _propTypes.default.number
150
+ })]),
151
+ /**
152
+ * The y value associated with the reference line.
153
+ * If defined the reference line will be horizontal.
154
+ */
155
+ y: _propTypes.default.oneOfType([_propTypes.default.instanceOf(Date), _propTypes.default.number, _propTypes.default.string]).isRequired
156
+ } : void 0;
@@ -1,2 +1,4 @@
1
1
  export * from "./ChartsReferenceLine.js";
2
- export * from "./chartsReferenceLineClasses.js";
2
+ export * from "./chartsReferenceLineClasses.js";
3
+ export type { ChartsXReferenceLineProps } from "./ChartsXReferenceLine.js";
4
+ export type { ChartsYReferenceLineProps } from "./ChartsYReferenceLine.js";