@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
@@ -1,23 +1,16 @@
1
1
  'use client';
2
2
 
3
- import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
4
3
  import _extends from "@babel/runtime/helpers/esm/extends";
4
+ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
5
5
  const _excluded = ["slots", "slotProps", "skipAnimation", "onItemClick"];
6
6
  import * as React from 'react';
7
7
  import PropTypes from 'prop-types';
8
8
  import { styled } from '@mui/material/styles';
9
- import { warnOnce } from '@mui/x-internals/warning';
10
- import { line as d3Line } from '@mui/x-charts-vendor/d3-shape';
11
9
  import { LineElement, lineElementClasses } from "./LineElement.js";
12
- import { getValueToPositionMapper } from "../hooks/useScale.js";
13
- import { getCurveFactory } from "../internals/getCurve.js";
14
- import { isBandScale } from "../internals/isBandScale.js";
15
- import { DEFAULT_X_AXIS_KEY } from "../constants/index.js";
16
- import { useLineSeriesContext } from "../hooks/useLineSeries.js";
17
10
  import { useSkipAnimation } from "../hooks/useSkipAnimation.js";
18
- import { useChartGradientIdBuilder } from "../hooks/useChartGradientId.js";
19
11
  import { useXAxes, useYAxes } from "../hooks/index.js";
20
12
  import { useInternalIsZoomInteracting } from "../internals/plugins/featurePlugins/useChartCartesianAxis/useInternalIsZoomInteracting.js";
13
+ import { useLinePlotData } from "./useLinePlotData.js";
21
14
  import { jsx as _jsx } from "react/jsx-runtime";
22
15
  const LinePlotRoot = styled('g', {
23
16
  name: 'MuiAreaPlot',
@@ -28,100 +21,13 @@ const LinePlotRoot = styled('g', {
28
21
  }
29
22
  });
30
23
  const useAggregatedData = () => {
31
- const seriesData = useLineSeriesContext();
32
24
  const {
33
- xAxis,
34
- xAxisIds
25
+ xAxis: xAxes
35
26
  } = useXAxes();
36
27
  const {
37
- yAxis,
38
- yAxisIds
28
+ yAxis: yAxes
39
29
  } = useYAxes();
40
- const getGradientId = useChartGradientIdBuilder();
41
-
42
- // This memo prevents odd line chart behavior when hydrating.
43
- const allData = React.useMemo(() => {
44
- if (seriesData === undefined) {
45
- return [];
46
- }
47
- const {
48
- series,
49
- stackingGroups
50
- } = seriesData;
51
- const defaultXAxisId = xAxisIds[0];
52
- const defaultYAxisId = yAxisIds[0];
53
- return stackingGroups.flatMap(({
54
- ids: groupIds
55
- }) => {
56
- return groupIds.flatMap(seriesId => {
57
- const {
58
- xAxisId = defaultXAxisId,
59
- yAxisId = defaultYAxisId,
60
- stackedData,
61
- data,
62
- connectNulls,
63
- curve,
64
- strictStepCurve
65
- } = series[seriesId];
66
- const xScale = xAxis[xAxisId].scale;
67
- const xPosition = getValueToPositionMapper(xScale);
68
- const yScale = yAxis[yAxisId].scale;
69
- const xData = xAxis[xAxisId].data;
70
- const gradientId = yAxis[yAxisId].colorScale && getGradientId(yAxisId) || xAxis[xAxisId].colorScale && getGradientId(xAxisId) || undefined;
71
- if (process.env.NODE_ENV !== 'production') {
72
- if (xData === undefined) {
73
- throw new Error(`MUI X Charts: ${xAxisId === 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.`);
74
- }
75
- if (xData.length < stackedData.length) {
76
- 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');
77
- }
78
- }
79
- const shouldExpand = curve?.includes('step') && !strictStepCurve && isBandScale(xScale);
80
- const formattedData = xData?.flatMap((x, index) => {
81
- const nullData = data[index] == null;
82
- if (shouldExpand) {
83
- const rep = [{
84
- x,
85
- y: stackedData[index],
86
- nullData,
87
- isExtension: false
88
- }];
89
- if (!nullData && (index === 0 || data[index - 1] == null)) {
90
- rep.unshift({
91
- x: (xScale(x) ?? 0) - (xScale.step() - xScale.bandwidth()) / 2,
92
- y: stackedData[index],
93
- nullData,
94
- isExtension: true
95
- });
96
- }
97
- if (!nullData && (index === data.length - 1 || data[index + 1] == null)) {
98
- rep.push({
99
- x: (xScale(x) ?? 0) + (xScale.step() + xScale.bandwidth()) / 2,
100
- y: stackedData[index],
101
- nullData,
102
- isExtension: true
103
- });
104
- }
105
- return rep;
106
- }
107
- return {
108
- x,
109
- y: stackedData[index],
110
- nullData
111
- };
112
- }) ?? [];
113
- const d3Data = connectNulls ? formattedData.filter(d => !d.nullData) : formattedData;
114
- const linePath = d3Line().x(d => d.isExtension ? d.x : xPosition(d.x)).defined(d => connectNulls || !d.nullData || !!d.isExtension).y(d => yScale(d.y[1]));
115
- const d = linePath.curve(getCurveFactory(curve))(d3Data) || '';
116
- return _extends({}, series[seriesId], {
117
- gradientId,
118
- d,
119
- seriesId
120
- });
121
- });
122
- });
123
- }, [seriesData, xAxisIds, yAxisIds, xAxis, yAxis, getGradientId]);
124
- return allData;
30
+ return useLinePlotData(xAxes, yAxes);
125
31
  };
126
32
 
127
33
  /**
@@ -0,0 +1,12 @@
1
+ import { ComputedAxisConfig } from "../internals/plugins/featurePlugins/useChartCartesianAxis/index.js";
2
+ import { ChartsXAxisProps, ChartsYAxisProps } from "../models/index.js";
3
+ import { SeriesId } from "../models/seriesType/common.js";
4
+ interface AreaPlotDataPoint {
5
+ d: string;
6
+ seriesId: SeriesId;
7
+ color: string;
8
+ area?: boolean;
9
+ gradientId?: string;
10
+ }
11
+ export declare function useAreaPlotData(xAxes: ComputedAxisConfig<ChartsXAxisProps>, yAxes: ComputedAxisConfig<ChartsYAxisProps>): AreaPlotDataPoint[];
12
+ export {};
@@ -0,0 +1,118 @@
1
+ import * as React from 'react';
2
+ import { area as d3Area } from '@mui/x-charts-vendor/d3-shape';
3
+ import { useChartGradientIdBuilder } from "../hooks/useChartGradientId.js";
4
+ import { isBandScale } from "../internals/isBandScale.js";
5
+ import { getCurveFactory } from "../internals/getCurve.js";
6
+ import { getValueToPositionMapper, useLineSeriesContext, useXAxes, useYAxes } from "../hooks/index.js";
7
+ import { DEFAULT_X_AXIS_KEY } from "../constants/index.js";
8
+ export function useAreaPlotData(xAxes, yAxes) {
9
+ const seriesData = useLineSeriesContext();
10
+ const defaultXAxisId = useXAxes().xAxisIds[0];
11
+ const defaultYAxisId = useYAxes().yAxisIds[0];
12
+ const getGradientId = useChartGradientIdBuilder();
13
+
14
+ // This memo prevents odd line chart behavior when hydrating.
15
+ const allData = React.useMemo(() => {
16
+ if (seriesData === undefined) {
17
+ return [];
18
+ }
19
+ const {
20
+ series,
21
+ stackingGroups
22
+ } = seriesData;
23
+ const areaPlotData = [];
24
+ for (const stackingGroup of stackingGroups) {
25
+ const groupIds = stackingGroup.ids;
26
+ for (let i = groupIds.length - 1; i >= 0; i -= 1) {
27
+ const seriesId = groupIds[i];
28
+ const {
29
+ xAxisId = defaultXAxisId,
30
+ yAxisId = defaultYAxisId,
31
+ stackedData,
32
+ data,
33
+ connectNulls,
34
+ baseline,
35
+ curve,
36
+ strictStepCurve
37
+ } = series[seriesId];
38
+ if (!(xAxisId in xAxes) || !(yAxisId in yAxes)) {
39
+ continue;
40
+ }
41
+ const xScale = xAxes[xAxisId].scale;
42
+ const xPosition = getValueToPositionMapper(xScale);
43
+ const yScale = yAxes[yAxisId].scale;
44
+ const xData = xAxes[xAxisId].data;
45
+ const gradientId = yAxes[yAxisId].colorScale && getGradientId(yAxisId) || xAxes[xAxisId].colorScale && getGradientId(xAxisId) || undefined;
46
+ if (process.env.NODE_ENV !== 'production') {
47
+ if (xData === undefined) {
48
+ throw new Error(`MUI X Charts: ${xAxisId === 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.`);
49
+ }
50
+ if (xData.length < stackedData.length) {
51
+ throw new Error(`MUI X Charts: The data length of the x axis (${xData.length} items) is lower than the length of series (${stackedData.length} items).`);
52
+ }
53
+ }
54
+ const shouldExpand = curve?.includes('step') && !strictStepCurve && isBandScale(xScale);
55
+ const formattedData = xData?.flatMap((x, index) => {
56
+ const nullData = data[index] == null;
57
+ if (shouldExpand) {
58
+ const rep = [{
59
+ x,
60
+ y: stackedData[index],
61
+ nullData,
62
+ isExtension: false
63
+ }];
64
+ if (!nullData && (index === 0 || data[index - 1] == null)) {
65
+ rep.unshift({
66
+ x: (xScale(x) ?? 0) - (xScale.step() - xScale.bandwidth()) / 2,
67
+ y: stackedData[index],
68
+ nullData,
69
+ isExtension: true
70
+ });
71
+ }
72
+ if (!nullData && (index === data.length - 1 || data[index + 1] == null)) {
73
+ rep.push({
74
+ x: (xScale(x) ?? 0) + (xScale.step() + xScale.bandwidth()) / 2,
75
+ y: stackedData[index],
76
+ nullData,
77
+ isExtension: true
78
+ });
79
+ }
80
+ return rep;
81
+ }
82
+ return {
83
+ x,
84
+ y: stackedData[index],
85
+ nullData
86
+ };
87
+ }) ?? [];
88
+ const d3Data = connectNulls ? formattedData.filter(d => !d.nullData) : formattedData;
89
+ const areaPath = d3Area().x(d => d.isExtension ? d.x : xPosition(d.x)).defined(d => connectNulls || !d.nullData || !!d.isExtension).y0(d => {
90
+ if (typeof baseline === 'number') {
91
+ return yScale(baseline);
92
+ }
93
+ if (baseline === 'max') {
94
+ return yScale.range()[1];
95
+ }
96
+ if (baseline === 'min') {
97
+ return yScale.range()[0];
98
+ }
99
+ const value = d.y && yScale(d.y[0]);
100
+ if (Number.isNaN(value)) {
101
+ return yScale.range()[0];
102
+ }
103
+ return value;
104
+ }).y1(d => d.y && yScale(d.y[1]));
105
+ const d = areaPath.curve(getCurveFactory(curve))(d3Data) || '';
106
+ areaPlotData.push({
107
+ area: series[seriesId].area,
108
+ color: series[seriesId].color,
109
+ gradientId,
110
+ d,
111
+ seriesId
112
+ });
113
+ }
114
+ }
115
+ return areaPlotData;
116
+ }, [seriesData, defaultXAxisId, defaultYAxisId, xAxes, yAxes, getGradientId]);
117
+ return allData;
118
+ }
@@ -0,0 +1,11 @@
1
+ import { ComputedAxisConfig } from "../internals/plugins/featurePlugins/useChartCartesianAxis/index.js";
2
+ import { ChartsXAxisProps, ChartsYAxisProps } from "../models/index.js";
3
+ import { SeriesId } from "../models/seriesType/common.js";
4
+ interface LinePlotDataPoint {
5
+ d: string;
6
+ seriesId: SeriesId;
7
+ color: string;
8
+ gradientId?: string;
9
+ }
10
+ export declare function useLinePlotData(xAxes: ComputedAxisConfig<ChartsXAxisProps>, yAxes: ComputedAxisConfig<ChartsYAxisProps>): LinePlotDataPoint[];
11
+ export {};
@@ -0,0 +1,101 @@
1
+ import * as React from 'react';
2
+ import { warnOnce } from '@mui/x-internals/warning';
3
+ import { line as d3Line } from '@mui/x-charts-vendor/d3-shape';
4
+ import { useChartGradientIdBuilder } from "../hooks/useChartGradientId.js";
5
+ import { isBandScale } from "../internals/isBandScale.js";
6
+ import { getCurveFactory } from "../internals/getCurve.js";
7
+ import { getValueToPositionMapper, useLineSeriesContext, useXAxes, useYAxes } from "../hooks/index.js";
8
+ import { DEFAULT_X_AXIS_KEY } from "../constants/index.js";
9
+ export function useLinePlotData(xAxes, yAxes) {
10
+ const seriesData = useLineSeriesContext();
11
+ const defaultXAxisId = useXAxes().xAxisIds[0];
12
+ const defaultYAxisId = useYAxes().yAxisIds[0];
13
+ const getGradientId = useChartGradientIdBuilder();
14
+
15
+ // This memo prevents odd line chart behavior when hydrating.
16
+ const allData = React.useMemo(() => {
17
+ if (seriesData === undefined) {
18
+ return [];
19
+ }
20
+ const {
21
+ series,
22
+ stackingGroups
23
+ } = seriesData;
24
+ const linePlotData = [];
25
+ for (const stackingGroup of stackingGroups) {
26
+ const groupIds = stackingGroup.ids;
27
+ for (const seriesId of groupIds) {
28
+ const {
29
+ xAxisId = defaultXAxisId,
30
+ yAxisId = defaultYAxisId,
31
+ stackedData,
32
+ data,
33
+ connectNulls,
34
+ curve,
35
+ strictStepCurve
36
+ } = series[seriesId];
37
+ if (!(xAxisId in xAxes) || !(yAxisId in yAxes)) {
38
+ continue;
39
+ }
40
+ const xScale = xAxes[xAxisId].scale;
41
+ const xPosition = getValueToPositionMapper(xScale);
42
+ const yScale = yAxes[yAxisId].scale;
43
+ const xData = xAxes[xAxisId].data;
44
+ const gradientId = yAxes[yAxisId].colorScale && getGradientId(yAxisId) || xAxes[xAxisId].colorScale && getGradientId(xAxisId) || undefined;
45
+ if (process.env.NODE_ENV !== 'production') {
46
+ if (xData === undefined) {
47
+ throw new Error(`MUI X Charts: ${xAxisId === 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.`);
48
+ }
49
+ if (xData.length < stackedData.length) {
50
+ 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');
51
+ }
52
+ }
53
+ const shouldExpand = curve?.includes('step') && !strictStepCurve && isBandScale(xScale);
54
+ const formattedData = xData?.flatMap((x, index) => {
55
+ const nullData = data[index] == null;
56
+ if (shouldExpand) {
57
+ const rep = [{
58
+ x,
59
+ y: stackedData[index],
60
+ nullData,
61
+ isExtension: false
62
+ }];
63
+ if (!nullData && (index === 0 || data[index - 1] == null)) {
64
+ rep.unshift({
65
+ x: (xScale(x) ?? 0) - (xScale.step() - xScale.bandwidth()) / 2,
66
+ y: stackedData[index],
67
+ nullData,
68
+ isExtension: true
69
+ });
70
+ }
71
+ if (!nullData && (index === data.length - 1 || data[index + 1] == null)) {
72
+ rep.push({
73
+ x: (xScale(x) ?? 0) + (xScale.step() + xScale.bandwidth()) / 2,
74
+ y: stackedData[index],
75
+ nullData,
76
+ isExtension: true
77
+ });
78
+ }
79
+ return rep;
80
+ }
81
+ return {
82
+ x,
83
+ y: stackedData[index],
84
+ nullData
85
+ };
86
+ }) ?? [];
87
+ const d3Data = connectNulls ? formattedData.filter(d => !d.nullData) : formattedData;
88
+ const linePath = d3Line().x(d => d.isExtension ? d.x : xPosition(d.x)).defined(d => connectNulls || !d.nullData || !!d.isExtension).y(d => yScale(d.y[1]));
89
+ const d = linePath.curve(getCurveFactory(curve))(d3Data) || '';
90
+ linePlotData.push({
91
+ color: series[seriesId].color,
92
+ gradientId,
93
+ d,
94
+ seriesId
95
+ });
96
+ }
97
+ }
98
+ return linePlotData;
99
+ }, [seriesData, defaultXAxisId, defaultYAxisId, xAxes, yAxes, getGradientId]);
100
+ return allData;
101
+ }
@@ -6,15 +6,15 @@ const _excluded = ["ownerState"];
6
6
  import * as React from 'react';
7
7
  import PropTypes from 'prop-types';
8
8
  import useSlotProps from '@mui/utils/useSlotProps';
9
- import { getValueToPositionMapper } from "../hooks/useScale.js";
10
- import { useInteractionAllItemProps } from "../hooks/useInteractionItemProps.js";
9
+ import { getInteractionItemProps } from "../hooks/useInteractionItemProps.js";
11
10
  import { useStore } from "../internals/store/useStore.js";
12
11
  import { useSelector } from "../internals/store/useSelector.js";
13
12
  import { useItemHighlightedGetter } from "../hooks/useItemHighlightedGetter.js";
14
13
  import { selectorChartsVoronoiIsVoronoiEnabled } from "../internals/plugins/featurePlugins/useChartVoronoi/index.js";
15
- import { useChartContext } from "../context/ChartProvider/index.js";
16
14
  import { ScatterMarker } from "./ScatterMarker.js";
17
15
  import { useUtilityClasses } from "./scatterClasses.js";
16
+ import { useScatterPlotData } from "./useScatterPlotData.js";
17
+ import { useChartContext } from "../context/ChartProvider/index.js";
18
18
  import { jsx as _jsx } from "react/jsx-runtime";
19
19
  /**
20
20
  * Demos:
@@ -48,37 +48,7 @@ function Scatter(props) {
48
48
  isFaded,
49
49
  isHighlighted
50
50
  } = useItemHighlightedGetter();
51
- const cleanData = React.useMemo(() => {
52
- const getXPosition = getValueToPositionMapper(xScale);
53
- const getYPosition = getValueToPositionMapper(yScale);
54
- const temp = [];
55
- for (let i = 0; i < series.data.length; i += 1) {
56
- const scatterPoint = series.data[i];
57
- const x = getXPosition(scatterPoint.x);
58
- const y = getYPosition(scatterPoint.y);
59
- const isInRange = instance.isPointInside(x, y);
60
- if (isInRange) {
61
- const currentItem = {
62
- seriesId: series.id,
63
- dataIndex: i
64
- };
65
- const isItemHighlighted = isHighlighted(currentItem);
66
- temp.push({
67
- x,
68
- y,
69
- isHighlighted: isItemHighlighted,
70
- isFaded: !isItemHighlighted && isFaded(currentItem),
71
- id: scatterPoint.id,
72
- seriesId: series.id,
73
- type: 'scatter',
74
- dataIndex: i,
75
- color: colorGetter ? colorGetter(i) : color
76
- });
77
- }
78
- }
79
- return temp;
80
- }, [xScale, yScale, series.data, series.id, isHighlighted, isFaded, colorGetter, color, instance]);
81
- const interactionItemProps = useInteractionAllItemProps(cleanData, skipInteractionHandlers);
51
+ const scatterPlotData = useScatterPlotData(series, xScale, yScale, instance.isPointInside);
82
52
  const Marker = slots?.marker ?? ScatterMarker;
83
53
  const _useSlotProps = useSlotProps({
84
54
  elementType: Marker,
@@ -94,21 +64,25 @@ function Scatter(props) {
94
64
  return /*#__PURE__*/_jsx("g", {
95
65
  "data-series": series.id,
96
66
  className: classes.root,
97
- children: cleanData.map((dataPoint, i) => /*#__PURE__*/_jsx(Marker, _extends({
98
- dataIndex: dataPoint.dataIndex,
99
- color: dataPoint.color,
100
- isHighlighted: dataPoint.isHighlighted,
101
- isFaded: dataPoint.isFaded,
102
- x: dataPoint.x,
103
- y: dataPoint.y,
104
- onClick: onItemClick && (event => onItemClick(event, {
105
- type: 'scatter',
106
- seriesId: series.id,
107
- dataIndex: dataPoint.dataIndex
108
- })),
109
- "data-highlighted": dataPoint.isHighlighted || undefined,
110
- "data-faded": dataPoint.isFaded || undefined
111
- }, interactionItemProps[i], markerProps), dataPoint.id ?? dataPoint.dataIndex))
67
+ children: scatterPlotData.map((dataPoint, i) => {
68
+ const isItemHighlighted = isHighlighted(dataPoint);
69
+ const isItemFaded = !isItemHighlighted && isFaded(dataPoint);
70
+ return /*#__PURE__*/_jsx(Marker, _extends({
71
+ dataIndex: dataPoint.dataIndex,
72
+ color: colorGetter ? colorGetter(i) : color,
73
+ isHighlighted: isItemHighlighted,
74
+ isFaded: isItemFaded,
75
+ x: dataPoint.x,
76
+ y: dataPoint.y,
77
+ onClick: onItemClick && (event => onItemClick(event, {
78
+ type: 'scatter',
79
+ seriesId: series.id,
80
+ dataIndex: dataPoint.dataIndex
81
+ })),
82
+ "data-highlighted": isItemHighlighted || undefined,
83
+ "data-faded": isItemFaded || undefined
84
+ }, skipInteractionHandlers ? undefined : getInteractionItemProps(instance, dataPoint), markerProps), dataPoint.id ?? dataPoint.dataIndex);
85
+ })
112
86
  });
113
87
  }
114
88
  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,26 @@
1
+ import * as React from 'react';
2
+ import { getValueToPositionMapper } from "../hooks/index.js";
3
+ export function useScatterPlotData(series, xScale, yScale, isPointInside) {
4
+ return React.useMemo(() => {
5
+ const getXPosition = getValueToPositionMapper(xScale);
6
+ const getYPosition = getValueToPositionMapper(yScale);
7
+ const temp = [];
8
+ for (let i = 0; i < series.data.length; i += 1) {
9
+ const scatterPoint = series.data[i];
10
+ const x = getXPosition(scatterPoint.x);
11
+ const y = getYPosition(scatterPoint.y);
12
+ const isInRange = isPointInside(x, y);
13
+ if (isInRange) {
14
+ temp.push({
15
+ x,
16
+ y,
17
+ id: scatterPoint.id,
18
+ seriesId: series.id,
19
+ type: 'scatter',
20
+ dataIndex: i
21
+ });
22
+ }
23
+ }
24
+ return temp;
25
+ }, [xScale, yScale, series.data, series.id, isPointInside]);
26
+ }
@@ -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 @@
1
+ export {};
@@ -1,3 +1,5 @@
1
+ 'use client';
2
+
1
3
  import * as React from 'react';
2
4
  /**
3
5
  * @ignore - internal component.
@@ -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.
@@ -1,16 +1,21 @@
1
1
  import * as React from 'react';
2
2
  import { SeriesItemIdentifier } from "../models/index.js";
3
+ import { UseChartHighlightSignature } from "../internals/plugins/featurePlugins/useChartHighlight/index.js";
4
+ import { UseChartInteractionSignature } from "../internals/plugins/featurePlugins/useChartInteraction/index.js";
5
+ import { ChartItemIdentifier, ChartSeriesType } from "../models/seriesType/config.js";
6
+ import { ChartInstance } from "../internals/plugins/models/index.js";
3
7
  export declare const useInteractionItemProps: (data: SeriesItemIdentifier, skip?: boolean) => {
4
8
  onPointerEnter?: () => void;
5
9
  onPointerLeave?: () => void;
6
10
  onPointerDown?: (event: React.PointerEvent) => void;
7
11
  };
8
- export declare const useInteractionAllItemProps: (data: SeriesItemIdentifier[], skip?: boolean) => ({
9
- onPointerEnter?: undefined;
10
- onPointerLeave?: undefined;
11
- onPointerDown?: undefined;
12
- } | {
13
- onPointerEnter: () => void;
14
- onPointerLeave: () => void;
15
- onPointerDown: (event: React.PointerEvent) => void;
16
- })[];
12
+ export declare const useInteractionAllItemProps: (data: SeriesItemIdentifier[], skip?: boolean) => {
13
+ onPointerEnter?: () => void;
14
+ onPointerLeave?: () => void;
15
+ onPointerDown?: (event: React.PointerEvent) => void;
16
+ }[];
17
+ export declare function getInteractionItemProps(instance: ChartInstance<[UseChartInteractionSignature, UseChartHighlightSignature]>, item: ChartItemIdentifier<ChartSeriesType>): {
18
+ onPointerEnter?: () => void;
19
+ onPointerLeave?: () => void;
20
+ onPointerDown?: (event: React.PointerEvent) => void;
21
+ };
@@ -2,11 +2,11 @@
2
2
 
3
3
  import * as React from 'react';
4
4
  import { useChartContext } from "../context/ChartProvider/index.js";
5
- const onPointerDown = event => {
5
+ function onPointerDown(event) {
6
6
  if ('hasPointerCapture' in event.currentTarget && event.currentTarget.hasPointerCapture(event.pointerId)) {
7
7
  event.currentTarget.releasePointerCapture(event.pointerId);
8
8
  }
9
- };
9
+ }
10
10
  export const useInteractionItemProps = (data, skip) => {
11
11
  const {
12
12
  instance
@@ -56,32 +56,32 @@ export const useInteractionAllItemProps = (data, skip) => {
56
56
  } = useChartContext();
57
57
  const results = React.useMemo(() => {
58
58
  return data.map(item => {
59
- if (skip) {
60
- return {};
61
- }
62
- const onPointerEnter = () => {
63
- if (!item) {
64
- return;
65
- }
66
- instance.setItemInteraction(item);
67
- instance.setHighlight({
68
- seriesId: item.seriesId,
69
- dataIndex: item.dataIndex
70
- });
71
- };
72
- const onPointerLeave = () => {
73
- if (!item) {
74
- return;
75
- }
76
- instance.removeItemInteraction(item);
77
- instance.clearHighlight();
78
- };
79
- return {
80
- onPointerEnter,
81
- onPointerLeave,
82
- onPointerDown
83
- };
59
+ return skip ? {} : getInteractionItemProps(instance, item);
84
60
  });
85
61
  }, [data, instance, skip]);
86
62
  return results;
87
- };
63
+ };
64
+ export function getInteractionItemProps(instance, item) {
65
+ function onPointerEnter() {
66
+ if (!item) {
67
+ return;
68
+ }
69
+ instance.setItemInteraction(item);
70
+ instance.setHighlight({
71
+ seriesId: item.seriesId,
72
+ dataIndex: item.dataIndex
73
+ });
74
+ }
75
+ function onPointerLeave() {
76
+ if (!item) {
77
+ return;
78
+ }
79
+ instance.removeItemInteraction(item);
80
+ instance.clearHighlight();
81
+ }
82
+ return {
83
+ onPointerEnter,
84
+ onPointerLeave,
85
+ onPointerDown
86
+ };
87
+ }