@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
@@ -0,0 +1,108 @@
1
+ "use strict";
2
+
3
+ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.useLinePlotData = useLinePlotData;
8
+ var React = _interopRequireWildcard(require("react"));
9
+ var _warning = require("@mui/x-internals/warning");
10
+ var _d3Shape = require("@mui/x-charts-vendor/d3-shape");
11
+ var _useChartGradientId = require("../hooks/useChartGradientId");
12
+ var _isBandScale = require("../internals/isBandScale");
13
+ var _getCurve = require("../internals/getCurve");
14
+ var _hooks = require("../hooks");
15
+ var _constants = require("../constants");
16
+ function useLinePlotData(xAxes, yAxes) {
17
+ const seriesData = (0, _hooks.useLineSeriesContext)();
18
+ const defaultXAxisId = (0, _hooks.useXAxes)().xAxisIds[0];
19
+ const defaultYAxisId = (0, _hooks.useYAxes)().yAxisIds[0];
20
+ const getGradientId = (0, _useChartGradientId.useChartGradientIdBuilder)();
21
+
22
+ // This memo prevents odd line chart behavior when hydrating.
23
+ const allData = React.useMemo(() => {
24
+ if (seriesData === undefined) {
25
+ return [];
26
+ }
27
+ const {
28
+ series,
29
+ stackingGroups
30
+ } = seriesData;
31
+ const linePlotData = [];
32
+ for (const stackingGroup of stackingGroups) {
33
+ const groupIds = stackingGroup.ids;
34
+ for (const seriesId of groupIds) {
35
+ const {
36
+ xAxisId = defaultXAxisId,
37
+ yAxisId = defaultYAxisId,
38
+ stackedData,
39
+ data,
40
+ connectNulls,
41
+ curve,
42
+ strictStepCurve
43
+ } = series[seriesId];
44
+ if (!(xAxisId in xAxes) || !(yAxisId in yAxes)) {
45
+ continue;
46
+ }
47
+ const xScale = xAxes[xAxisId].scale;
48
+ const xPosition = (0, _hooks.getValueToPositionMapper)(xScale);
49
+ const yScale = yAxes[yAxisId].scale;
50
+ const xData = xAxes[xAxisId].data;
51
+ const gradientId = yAxes[yAxisId].colorScale && getGradientId(yAxisId) || xAxes[xAxisId].colorScale && getGradientId(xAxisId) || undefined;
52
+ if (process.env.NODE_ENV !== 'production') {
53
+ if (xData === undefined) {
54
+ throw new Error(`MUI X Charts: ${xAxisId === _constants.DEFAULT_X_AXIS_KEY ? 'The first `xAxis`' : `The x-axis with id "${xAxisId}"`} should have data property to be able to display a line plot.`);
55
+ }
56
+ if (xData.length < stackedData.length) {
57
+ (0, _warning.warnOnce)(`MUI X Charts: The data length of the x axis (${xData.length} items) is lower than the length of series (${stackedData.length} items).`, 'error');
58
+ }
59
+ }
60
+ const shouldExpand = curve?.includes('step') && !strictStepCurve && (0, _isBandScale.isBandScale)(xScale);
61
+ const formattedData = xData?.flatMap((x, index) => {
62
+ const nullData = data[index] == null;
63
+ if (shouldExpand) {
64
+ const rep = [{
65
+ x,
66
+ y: stackedData[index],
67
+ nullData,
68
+ isExtension: false
69
+ }];
70
+ if (!nullData && (index === 0 || data[index - 1] == null)) {
71
+ rep.unshift({
72
+ x: (xScale(x) ?? 0) - (xScale.step() - xScale.bandwidth()) / 2,
73
+ y: stackedData[index],
74
+ nullData,
75
+ isExtension: true
76
+ });
77
+ }
78
+ if (!nullData && (index === data.length - 1 || data[index + 1] == null)) {
79
+ rep.push({
80
+ x: (xScale(x) ?? 0) + (xScale.step() + xScale.bandwidth()) / 2,
81
+ y: stackedData[index],
82
+ nullData,
83
+ isExtension: true
84
+ });
85
+ }
86
+ return rep;
87
+ }
88
+ return {
89
+ x,
90
+ y: stackedData[index],
91
+ nullData
92
+ };
93
+ }) ?? [];
94
+ const d3Data = connectNulls ? formattedData.filter(d => !d.nullData) : formattedData;
95
+ const linePath = (0, _d3Shape.line)().x(d => d.isExtension ? d.x : xPosition(d.x)).defined(d => connectNulls || !d.nullData || !!d.isExtension).y(d => yScale(d.y[1]));
96
+ const d = linePath.curve((0, _getCurve.getCurveFactory)(curve))(d3Data) || '';
97
+ linePlotData.push({
98
+ color: series[seriesId].color,
99
+ gradientId,
100
+ d,
101
+ seriesId
102
+ });
103
+ }
104
+ }
105
+ return linePlotData;
106
+ }, [seriesData, defaultXAxisId, defaultYAxisId, xAxes, yAxes, getGradientId]);
107
+ return allData;
108
+ }
@@ -12,15 +12,15 @@ var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runt
12
12
  var React = _interopRequireWildcard(require("react"));
13
13
  var _propTypes = _interopRequireDefault(require("prop-types"));
14
14
  var _useSlotProps2 = _interopRequireDefault(require("@mui/utils/useSlotProps"));
15
- var _useScale = require("../hooks/useScale");
16
15
  var _useInteractionItemProps = require("../hooks/useInteractionItemProps");
17
16
  var _useStore = require("../internals/store/useStore");
18
17
  var _useSelector = require("../internals/store/useSelector");
19
18
  var _useItemHighlightedGetter = require("../hooks/useItemHighlightedGetter");
20
19
  var _useChartVoronoi = require("../internals/plugins/featurePlugins/useChartVoronoi");
21
- var _ChartProvider = require("../context/ChartProvider");
22
20
  var _ScatterMarker = require("./ScatterMarker");
23
21
  var _scatterClasses = require("./scatterClasses");
22
+ var _useScatterPlotData = require("./useScatterPlotData");
23
+ var _ChartProvider = require("../context/ChartProvider");
24
24
  var _jsxRuntime = require("react/jsx-runtime");
25
25
  const _excluded = ["ownerState"];
26
26
  /**
@@ -55,37 +55,7 @@ function Scatter(props) {
55
55
  isFaded,
56
56
  isHighlighted
57
57
  } = (0, _useItemHighlightedGetter.useItemHighlightedGetter)();
58
- const cleanData = React.useMemo(() => {
59
- const getXPosition = (0, _useScale.getValueToPositionMapper)(xScale);
60
- const getYPosition = (0, _useScale.getValueToPositionMapper)(yScale);
61
- const temp = [];
62
- for (let i = 0; i < series.data.length; i += 1) {
63
- const scatterPoint = series.data[i];
64
- const x = getXPosition(scatterPoint.x);
65
- const y = getYPosition(scatterPoint.y);
66
- const isInRange = instance.isPointInside(x, y);
67
- if (isInRange) {
68
- const currentItem = {
69
- seriesId: series.id,
70
- dataIndex: i
71
- };
72
- const isItemHighlighted = isHighlighted(currentItem);
73
- temp.push({
74
- x,
75
- y,
76
- isHighlighted: isItemHighlighted,
77
- isFaded: !isItemHighlighted && isFaded(currentItem),
78
- id: scatterPoint.id,
79
- seriesId: series.id,
80
- type: 'scatter',
81
- dataIndex: i,
82
- color: colorGetter ? colorGetter(i) : color
83
- });
84
- }
85
- }
86
- return temp;
87
- }, [xScale, yScale, series.data, series.id, isHighlighted, isFaded, colorGetter, color, instance]);
88
- const interactionItemProps = (0, _useInteractionItemProps.useInteractionAllItemProps)(cleanData, skipInteractionHandlers);
58
+ const scatterPlotData = (0, _useScatterPlotData.useScatterPlotData)(series, xScale, yScale, instance.isPointInside);
89
59
  const Marker = slots?.marker ?? _ScatterMarker.ScatterMarker;
90
60
  const _useSlotProps = (0, _useSlotProps2.default)({
91
61
  elementType: Marker,
@@ -101,21 +71,25 @@ function Scatter(props) {
101
71
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("g", {
102
72
  "data-series": series.id,
103
73
  className: classes.root,
104
- children: cleanData.map((dataPoint, i) => /*#__PURE__*/(0, _jsxRuntime.jsx)(Marker, (0, _extends2.default)({
105
- dataIndex: dataPoint.dataIndex,
106
- color: dataPoint.color,
107
- isHighlighted: dataPoint.isHighlighted,
108
- isFaded: dataPoint.isFaded,
109
- x: dataPoint.x,
110
- y: dataPoint.y,
111
- onClick: onItemClick && (event => onItemClick(event, {
112
- type: 'scatter',
113
- seriesId: series.id,
114
- dataIndex: dataPoint.dataIndex
115
- })),
116
- "data-highlighted": dataPoint.isHighlighted || undefined,
117
- "data-faded": dataPoint.isFaded || undefined
118
- }, interactionItemProps[i], markerProps), dataPoint.id ?? dataPoint.dataIndex))
74
+ children: scatterPlotData.map((dataPoint, i) => {
75
+ const isItemHighlighted = isHighlighted(dataPoint);
76
+ const isItemFaded = !isItemHighlighted && isFaded(dataPoint);
77
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(Marker, (0, _extends2.default)({
78
+ dataIndex: dataPoint.dataIndex,
79
+ color: colorGetter ? colorGetter(i) : color,
80
+ isHighlighted: isItemHighlighted,
81
+ isFaded: isItemFaded,
82
+ x: dataPoint.x,
83
+ y: dataPoint.y,
84
+ onClick: onItemClick && (event => onItemClick(event, {
85
+ type: 'scatter',
86
+ seriesId: series.id,
87
+ dataIndex: dataPoint.dataIndex
88
+ })),
89
+ "data-highlighted": isItemHighlighted || undefined,
90
+ "data-faded": isItemFaded || undefined
91
+ }, skipInteractionHandlers ? undefined : (0, _useInteractionItemProps.getInteractionItemProps)(instance, dataPoint), markerProps), dataPoint.id ?? dataPoint.dataIndex);
92
+ })
119
93
  });
120
94
  }
121
95
  process.env.NODE_ENV !== "production" ? Scatter.propTypes = {
@@ -0,0 +1,8 @@
1
+ import { SeriesId } from "../models/seriesType/common.js";
2
+ import { D3Scale } from "../models/axis.js";
3
+ import { DefaultizedScatterSeriesType, ScatterValueType } from "../models/index.js";
4
+ export declare function useScatterPlotData(series: DefaultizedScatterSeriesType, xScale: D3Scale, yScale: D3Scale, isPointInside: (x: number, y: number) => boolean): (ScatterValueType & {
5
+ dataIndex: number;
6
+ seriesId: SeriesId;
7
+ type: "scatter";
8
+ })[];
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+
3
+ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.useScatterPlotData = useScatterPlotData;
8
+ var React = _interopRequireWildcard(require("react"));
9
+ var _hooks = require("../hooks");
10
+ function useScatterPlotData(series, xScale, yScale, isPointInside) {
11
+ return React.useMemo(() => {
12
+ const getXPosition = (0, _hooks.getValueToPositionMapper)(xScale);
13
+ const getYPosition = (0, _hooks.getValueToPositionMapper)(yScale);
14
+ const temp = [];
15
+ for (let i = 0; i < series.data.length; i += 1) {
16
+ const scatterPoint = series.data[i];
17
+ const x = getXPosition(scatterPoint.x);
18
+ const y = getYPosition(scatterPoint.y);
19
+ const isInRange = isPointInside(x, y);
20
+ if (isInRange) {
21
+ temp.push({
22
+ x,
23
+ y,
24
+ id: scatterPoint.id,
25
+ seriesId: series.id,
26
+ type: 'scatter',
27
+ dataIndex: i
28
+ });
29
+ }
30
+ }
31
+ return temp;
32
+ }, [xScale, yScale, series.data, series.id, isPointInside]);
33
+ }
@@ -0,0 +1,22 @@
1
+ import type { PieChartPluginSignatures } from "../PieChart/PieChart.plugins.js";
2
+ import type { BarChartPluginsSignatures } from "../BarChart/BarChart.plugins.js";
3
+ import type { ScatterChartPluginsSignatures } from "../ScatterChart/ScatterChart.plugins.js";
4
+ import type { LineChartPluginsSignatures } from "../LineChart/LineChart.plugins.js";
5
+ import type { AllPluginSignatures, DefaultPluginSignatures } from "../internals/plugins/allPlugins.js";
6
+ import type { ChartAnyPluginSignature } from "../internals/plugins/models/plugin.js";
7
+ import type { ChartPublicAPI } from "../internals/plugins/models/index.js";
8
+ export type PluginsPerSeriesType = {
9
+ line: LineChartPluginsSignatures;
10
+ scatter: ScatterChartPluginsSignatures;
11
+ bar: BarChartPluginsSignatures;
12
+ pie: PieChartPluginSignatures;
13
+ composition: DefaultPluginSignatures;
14
+ };
15
+ /**
16
+ * The API of the chart `apiRef` object.
17
+ * The chart type can be passed as the first generic parameter to narrow down the API to the specific chart type.
18
+ * @example ChartApi<'bar'>
19
+ * If the chart is being created using composition, the `composition` value can be used.
20
+ * @example ChartApi<'composition'>
21
+ */
22
+ export type ChartApi<TSeries extends keyof PluginsPerSeriesType | undefined = undefined, TSignatures extends readonly ChartAnyPluginSignature[] = (TSeries extends keyof PluginsPerSeriesType ? PluginsPerSeriesType[TSeries] : AllPluginSignatures)> = ChartPublicAPI<TSignatures>;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -1,4 +1,5 @@
1
1
  "use strict";
2
+ 'use client';
2
3
 
3
4
  var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
4
5
  Object.defineProperty(exports, "__esModule", {
@@ -1,2 +1,3 @@
1
1
  export type { HighlightScope, FadeOptions, HighlightItemData, HighlightOptions } from "../internals/plugins/featurePlugins/useChartHighlight/index.js";
2
- export * from "./useChartApiContext.js";
2
+ export * from "./useChartApiContext.js";
3
+ export type { ChartApi } from "./ChartApi.js";
@@ -1,5 +1,5 @@
1
1
  import * as React from 'react';
2
- import { ChartApi } from "../ChartContainer/index.js";
2
+ import { ChartApi } from "./ChartApi.js";
3
3
  /**
4
4
  * The `useChartApiContext` hook provides access to the chart API.
5
5
  * This is only available when the chart is rendered within a chart or a `ChartDataProvider` component.
@@ -8,160 +8,14 @@ import PropTypes from 'prop-types';
8
8
  import { styled } from '@mui/material/styles';
9
9
  import { barElementClasses } from "./barElementClasses.js";
10
10
  import { BarElement } from "./BarElement.js";
11
- import getColor from "./seriesConfig/getColor.js";
12
- import { useChartId, useDrawingArea, useXAxes, useYAxes } from "../hooks/index.js";
11
+ import { useDrawingArea, useXAxes, useYAxes } from "../hooks/index.js";
13
12
  import { BarClipPath } from "./BarClipPath.js";
14
13
  import { BarLabelPlot } from "./BarLabel/BarLabelPlot.js";
15
- import { checkScaleErrors } from "./checkScaleErrors.js";
16
- import { useBarSeriesContext } from "../hooks/useBarSeries.js";
17
14
  import { useSkipAnimation } from "../hooks/useSkipAnimation.js";
18
15
  import { useInternalIsZoomInteracting } from "../internals/plugins/featurePlugins/useChartCartesianAxis/useInternalIsZoomInteracting.js";
16
+ import { useBarPlotData } from "./useBarPlotData.js";
19
17
  import { useUtilityClasses } from "./barClasses.js";
20
-
21
- /**
22
- * Solution of the equations
23
- * W = barWidth * N + offset * (N-1)
24
- * offset / (offset + barWidth) = r
25
- * @param bandWidth The width available to place bars.
26
- * @param numberOfGroups The number of bars to place in that space.
27
- * @param gapRatio The ratio of the gap between bars over the bar width.
28
- * @returns The bar width and the offset between bars.
29
- */
30
18
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
31
- function getBandSize({
32
- bandWidth: W,
33
- numberOfGroups: N,
34
- gapRatio: r
35
- }) {
36
- if (r === 0) {
37
- return {
38
- barWidth: W / N,
39
- offset: 0
40
- };
41
- }
42
- const barWidth = W / (N + (N - 1) * r);
43
- const offset = r * barWidth;
44
- return {
45
- barWidth,
46
- offset
47
- };
48
- }
49
- const useAggregatedData = () => {
50
- const seriesData = useBarSeriesContext() ?? {
51
- series: {},
52
- stackingGroups: [],
53
- seriesOrder: []
54
- };
55
- const drawingArea = useDrawingArea();
56
- const chartId = useChartId();
57
- const {
58
- series,
59
- stackingGroups
60
- } = seriesData;
61
- const {
62
- xAxis,
63
- xAxisIds
64
- } = useXAxes();
65
- const {
66
- yAxis,
67
- yAxisIds
68
- } = useYAxes();
69
- const defaultXAxisId = xAxisIds[0];
70
- const defaultYAxisId = yAxisIds[0];
71
- const masks = {};
72
- const data = stackingGroups.flatMap(({
73
- ids: seriesIds
74
- }, groupIndex) => {
75
- const xMin = drawingArea.left;
76
- const xMax = drawingArea.left + drawingArea.width;
77
- const yMin = drawingArea.top;
78
- const yMax = drawingArea.top + drawingArea.height;
79
- return seriesIds.map(seriesId => {
80
- const xAxisId = series[seriesId].xAxisId ?? defaultXAxisId;
81
- const yAxisId = series[seriesId].yAxisId ?? defaultYAxisId;
82
- const xAxisConfig = xAxis[xAxisId];
83
- const yAxisConfig = yAxis[yAxisId];
84
- const verticalLayout = series[seriesId].layout === 'vertical';
85
- checkScaleErrors(verticalLayout, seriesId, series[seriesId], xAxisId, xAxis, yAxisId, yAxis);
86
- const baseScaleConfig = verticalLayout ? xAxisConfig : yAxisConfig;
87
- const xScale = xAxisConfig.scale;
88
- const yScale = yAxisConfig.scale;
89
- const colorGetter = getColor(series[seriesId], xAxis[xAxisId], yAxis[yAxisId]);
90
- const bandWidth = baseScaleConfig.scale.bandwidth();
91
- const {
92
- barWidth,
93
- offset
94
- } = getBandSize({
95
- bandWidth,
96
- numberOfGroups: stackingGroups.length,
97
- gapRatio: baseScaleConfig.barGapRatio
98
- });
99
- const barOffset = groupIndex * (barWidth + offset);
100
- const {
101
- stackedData,
102
- data: currentSeriesData,
103
- layout
104
- } = series[seriesId];
105
- const seriesDataPoints = baseScaleConfig.data.map((baseValue, dataIndex) => {
106
- if (currentSeriesData[dataIndex] == null) {
107
- return null;
108
- }
109
- const values = stackedData[dataIndex];
110
- const valueCoordinates = values.map(v => verticalLayout ? yScale(v) : xScale(v));
111
- const minValueCoord = Math.round(Math.min(...valueCoordinates));
112
- const maxValueCoord = Math.round(Math.max(...valueCoordinates));
113
- const stackId = series[seriesId].stack;
114
- const result = {
115
- seriesId,
116
- dataIndex,
117
- layout,
118
- x: verticalLayout ? xScale(baseValue) + barOffset : minValueCoord,
119
- y: verticalLayout ? minValueCoord : yScale(baseValue) + barOffset,
120
- xOrigin: xScale(0) ?? 0,
121
- yOrigin: yScale(0) ?? 0,
122
- height: verticalLayout ? maxValueCoord - minValueCoord : barWidth,
123
- width: verticalLayout ? barWidth : maxValueCoord - minValueCoord,
124
- color: colorGetter(dataIndex),
125
- value: currentSeriesData[dataIndex],
126
- maskId: `${chartId}_${stackId || seriesId}_${groupIndex}_${dataIndex}`
127
- };
128
- if (result.x > xMax || result.x + result.width < xMin || result.y > yMax || result.y + result.height < yMin) {
129
- return null;
130
- }
131
- if (!masks[result.maskId]) {
132
- masks[result.maskId] = {
133
- id: result.maskId,
134
- width: 0,
135
- height: 0,
136
- hasNegative: false,
137
- hasPositive: false,
138
- layout: result.layout,
139
- xOrigin: xScale(0),
140
- yOrigin: yScale(0),
141
- x: 0,
142
- y: 0
143
- };
144
- }
145
- const mask = masks[result.maskId];
146
- mask.width = result.layout === 'vertical' ? result.width : mask.width + result.width;
147
- mask.height = result.layout === 'vertical' ? mask.height + result.height : result.height;
148
- mask.x = Math.min(mask.x === 0 ? Infinity : mask.x, result.x);
149
- mask.y = Math.min(mask.y === 0 ? Infinity : mask.y, result.y);
150
- mask.hasNegative = mask.hasNegative || (result.value ?? 0) < 0;
151
- mask.hasPositive = mask.hasPositive || (result.value ?? 0) > 0;
152
- return result;
153
- }).filter(rectangle => rectangle !== null);
154
- return {
155
- seriesId,
156
- data: seriesDataPoints
157
- };
158
- });
159
- });
160
- return {
161
- completedData: data,
162
- masksData: Object.values(masks)
163
- };
164
- };
165
19
  const BarPlotRoot = styled('g', {
166
20
  name: 'MuiBarPlot',
167
21
  slot: 'Root'
@@ -183,10 +37,6 @@ const BarPlotRoot = styled('g', {
183
37
  * - [BarPlot API](https://mui.com/x/api/charts/bar-plot/)
184
38
  */
185
39
  function BarPlot(props) {
186
- const {
187
- completedData,
188
- masksData
189
- } = useAggregatedData();
190
40
  const {
191
41
  skipAnimation: inSkipAnimation,
192
42
  onItemClick,
@@ -196,6 +46,16 @@ function BarPlot(props) {
196
46
  other = _objectWithoutPropertiesLoose(props, _excluded);
197
47
  const isZoomInteracting = useInternalIsZoomInteracting();
198
48
  const skipAnimation = useSkipAnimation(isZoomInteracting || inSkipAnimation);
49
+ const {
50
+ xAxis: xAxes
51
+ } = useXAxes();
52
+ const {
53
+ yAxis: yAxes
54
+ } = useYAxes();
55
+ const {
56
+ completedData,
57
+ masksData
58
+ } = useBarPlotData(useDrawingArea(), xAxes, yAxes);
199
59
  const withoutBorderRadius = !borderRadius || borderRadius <= 0;
200
60
  const classes = useUtilityClasses();
201
61
  return /*#__PURE__*/_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,139 @@
1
+ import getColor from "./seriesConfig/getColor.js";
2
+ import { useChartId, useXAxes, useYAxes } from "../hooks/index.js";
3
+ import { checkScaleErrors } from "./checkScaleErrors.js";
4
+ import { useBarSeriesContext } from "../hooks/useBarSeries.js";
5
+ export function useBarPlotData(drawingArea, xAxes, yAxes) {
6
+ const seriesData = useBarSeriesContext() ?? {
7
+ series: {},
8
+ stackingGroups: [],
9
+ seriesOrder: []
10
+ };
11
+ const defaultXAxisId = useXAxes().xAxisIds[0];
12
+ const defaultYAxisId = useYAxes().yAxisIds[0];
13
+ const chartId = useChartId();
14
+ const {
15
+ series,
16
+ stackingGroups
17
+ } = seriesData;
18
+ const masks = {};
19
+ const data = stackingGroups.flatMap(({
20
+ ids: seriesIds
21
+ }, groupIndex) => {
22
+ const xMin = drawingArea.left;
23
+ const xMax = drawingArea.left + drawingArea.width;
24
+ const yMin = drawingArea.top;
25
+ const yMax = drawingArea.top + drawingArea.height;
26
+ return seriesIds.map(seriesId => {
27
+ const xAxisId = series[seriesId].xAxisId ?? defaultXAxisId;
28
+ const yAxisId = series[seriesId].yAxisId ?? defaultYAxisId;
29
+ const xAxisConfig = xAxes[xAxisId];
30
+ const yAxisConfig = yAxes[yAxisId];
31
+ const verticalLayout = series[seriesId].layout === 'vertical';
32
+ checkScaleErrors(verticalLayout, seriesId, series[seriesId], xAxisId, xAxes, yAxisId, yAxes);
33
+ const baseScaleConfig = verticalLayout ? xAxisConfig : yAxisConfig;
34
+ const xScale = xAxisConfig.scale;
35
+ const yScale = yAxisConfig.scale;
36
+ const colorGetter = getColor(series[seriesId], xAxes[xAxisId], yAxes[yAxisId]);
37
+ const bandWidth = baseScaleConfig.scale.bandwidth();
38
+ const {
39
+ barWidth,
40
+ offset
41
+ } = getBandSize({
42
+ bandWidth,
43
+ numberOfGroups: stackingGroups.length,
44
+ gapRatio: baseScaleConfig.barGapRatio
45
+ });
46
+ const barOffset = groupIndex * (barWidth + offset);
47
+ const {
48
+ stackedData,
49
+ data: currentSeriesData,
50
+ layout
51
+ } = series[seriesId];
52
+ const seriesDataPoints = baseScaleConfig.data.map((baseValue, dataIndex) => {
53
+ if (currentSeriesData[dataIndex] == null) {
54
+ return null;
55
+ }
56
+ const values = stackedData[dataIndex];
57
+ const valueCoordinates = values.map(v => verticalLayout ? yScale(v) : xScale(v));
58
+ const minValueCoord = Math.round(Math.min(...valueCoordinates));
59
+ const maxValueCoord = Math.round(Math.max(...valueCoordinates));
60
+ const stackId = series[seriesId].stack;
61
+ const result = {
62
+ seriesId,
63
+ dataIndex,
64
+ layout,
65
+ x: verticalLayout ? xScale(baseValue) + barOffset : minValueCoord,
66
+ y: verticalLayout ? minValueCoord : yScale(baseValue) + barOffset,
67
+ xOrigin: xScale(0) ?? 0,
68
+ yOrigin: yScale(0) ?? 0,
69
+ height: verticalLayout ? maxValueCoord - minValueCoord : barWidth,
70
+ width: verticalLayout ? barWidth : maxValueCoord - minValueCoord,
71
+ color: colorGetter(dataIndex),
72
+ value: currentSeriesData[dataIndex],
73
+ maskId: `${chartId}_${stackId || seriesId}_${groupIndex}_${dataIndex}`
74
+ };
75
+ if (result.x > xMax || result.x + result.width < xMin || result.y > yMax || result.y + result.height < yMin) {
76
+ return null;
77
+ }
78
+ if (!masks[result.maskId]) {
79
+ masks[result.maskId] = {
80
+ id: result.maskId,
81
+ width: 0,
82
+ height: 0,
83
+ hasNegative: false,
84
+ hasPositive: false,
85
+ layout: result.layout,
86
+ xOrigin: xScale(0),
87
+ yOrigin: yScale(0),
88
+ x: 0,
89
+ y: 0
90
+ };
91
+ }
92
+ const mask = masks[result.maskId];
93
+ mask.width = result.layout === 'vertical' ? result.width : mask.width + result.width;
94
+ mask.height = result.layout === 'vertical' ? mask.height + result.height : result.height;
95
+ mask.x = Math.min(mask.x === 0 ? Infinity : mask.x, result.x);
96
+ mask.y = Math.min(mask.y === 0 ? Infinity : mask.y, result.y);
97
+ mask.hasNegative = mask.hasNegative || (result.value ?? 0) < 0;
98
+ mask.hasPositive = mask.hasPositive || (result.value ?? 0) > 0;
99
+ return result;
100
+ }).filter(rectangle => rectangle !== null);
101
+ return {
102
+ seriesId,
103
+ data: seriesDataPoints
104
+ };
105
+ });
106
+ });
107
+ return {
108
+ completedData: data,
109
+ masksData: Object.values(masks)
110
+ };
111
+ }
112
+
113
+ /**
114
+ * Solution of the equations
115
+ * W = barWidth * N + offset * (N-1)
116
+ * offset / (offset + barWidth) = r
117
+ * @param bandWidth The width available to place bars.
118
+ * @param numberOfGroups The number of bars to place in that space.
119
+ * @param gapRatio The ratio of the gap between bars over the bar width.
120
+ * @returns The bar width and the offset between bars.
121
+ */
122
+ function getBandSize({
123
+ bandWidth: W,
124
+ numberOfGroups: N,
125
+ gapRatio: r
126
+ }) {
127
+ if (r === 0) {
128
+ return {
129
+ barWidth: W / N,
130
+ offset: 0
131
+ };
132
+ }
133
+ const barWidth = W / (N + (N - 1) * r);
134
+ const offset = r * barWidth;
135
+ return {
136
+ barWidth,
137
+ offset
138
+ };
139
+ }
@@ -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
  *