@mui/x-charts 7.7.0 → 7.8.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 (167) hide show
  1. package/BarChart/BarChart.js +21 -104
  2. package/BarChart/BarElement.d.ts +225 -228
  3. package/BarChart/BarLabel/BarLabel.d.ts +225 -228
  4. package/BarChart/BarLabel/BarLabelPlot.d.ts +0 -3
  5. package/BarChart/BarLabel/BarLabelPlot.js +1 -24
  6. package/BarChart/BarLabel/getBarLabel.d.ts +1 -1
  7. package/BarChart/BarPlot.js +2 -2
  8. package/BarChart/checkScaleErrors.d.ts +5 -9
  9. package/BarChart/types.d.ts +2 -2
  10. package/BarChart/useBarChartProps.d.ts +34 -0
  11. package/BarChart/useBarChartProps.js +143 -0
  12. package/CHANGELOG.md +181 -0
  13. package/ChartContainer/ChartContainer.d.ts +2 -2
  14. package/ChartContainer/ChartContainer.js +6 -10
  15. package/ChartContainer/useChartContainerHooks.d.ts +11 -0
  16. package/ChartContainer/useChartContainerHooks.js +34 -0
  17. package/ChartContainer/usePluginsMerge.d.ts +1 -2
  18. package/ChartsAxis/ChartsAxis.js +2 -2
  19. package/ChartsAxisHighlight/ChartsAxisHighlight.js +21 -6
  20. package/ChartsGrid/ChartsGrid.js +2 -2
  21. package/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +2 -2
  22. package/ChartsReferenceLine/common.d.ts +0 -1
  23. package/ChartsTooltip/ChartsAxisTooltipContent.js +2 -2
  24. package/ChartsTooltip/ChartsItemTooltipContent.js +2 -2
  25. package/ChartsTooltip/ChartsTooltipTable.d.ts +0 -1
  26. package/ChartsVoronoiHandler/ChartsVoronoiHandler.js +4 -4
  27. package/ChartsXAxis/ChartsXAxis.js +2 -2
  28. package/ChartsYAxis/ChartsYAxis.js +5 -3
  29. package/Gauge/GaugeProvider.d.ts +1 -1
  30. package/LineChart/AnimatedArea.d.ts +225 -228
  31. package/LineChart/AnimatedLine.d.ts +225 -228
  32. package/LineChart/AreaPlot.js +2 -2
  33. package/LineChart/LineChart.js +24 -106
  34. package/LineChart/LineHighlightPlot.js +2 -2
  35. package/LineChart/LinePlot.js +2 -2
  36. package/LineChart/MarkPlot.js +2 -2
  37. package/LineChart/useLineChartProps.d.ts +40 -0
  38. package/LineChart/useLineChartProps.js +152 -0
  39. package/PieChart/PieArc.d.ts +0 -1
  40. package/PieChart/PieArcLabel.d.ts +0 -1
  41. package/PieChart/dataTransform/transition.d.ts +0 -1
  42. package/ResponsiveChartContainer/ResizableContainer.d.ts +1 -2
  43. package/ScatterChart/ScatterChart.js +20 -75
  44. package/ScatterChart/ScatterPlot.js +2 -2
  45. package/ScatterChart/useScatterChartProps.d.ts +31 -0
  46. package/ScatterChart/useScatterChartProps.js +116 -0
  47. package/context/CartesianProvider/CartesianContext.d.ts +25 -0
  48. package/context/CartesianProvider/CartesianContext.js +21 -0
  49. package/context/CartesianProvider/CartesianProvider.d.ts +34 -0
  50. package/context/CartesianProvider/CartesianProvider.js +44 -0
  51. package/context/CartesianProvider/computeValue.d.ts +19 -0
  52. package/context/CartesianProvider/computeValue.js +104 -0
  53. package/context/CartesianProvider/getAxisExtremum.d.ts +4 -0
  54. package/context/CartesianProvider/getAxisExtremum.js +28 -0
  55. package/context/CartesianProvider/index.d.ts +9 -0
  56. package/context/CartesianProvider/index.js +51 -0
  57. package/context/CartesianProvider/normalizeAxis.d.ts +5 -0
  58. package/context/CartesianProvider/normalizeAxis.js +23 -0
  59. package/context/CartesianProvider/useCartesianContext.d.ts +2 -0
  60. package/context/CartesianProvider/useCartesianContext.js +17 -0
  61. package/context/ColorProvider.d.ts +2 -2
  62. package/esm/BarChart/BarChart.js +21 -104
  63. package/esm/BarChart/BarLabel/BarLabelPlot.js +0 -23
  64. package/esm/BarChart/BarPlot.js +2 -2
  65. package/esm/BarChart/useBarChartProps.js +135 -0
  66. package/esm/ChartContainer/ChartContainer.js +5 -9
  67. package/esm/ChartContainer/useChartContainerHooks.js +24 -0
  68. package/esm/ChartsAxis/ChartsAxis.js +2 -2
  69. package/esm/ChartsAxisHighlight/ChartsAxisHighlight.js +21 -6
  70. package/esm/ChartsGrid/ChartsGrid.js +2 -2
  71. package/esm/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +2 -2
  72. package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +2 -2
  73. package/esm/ChartsTooltip/ChartsItemTooltipContent.js +2 -2
  74. package/esm/ChartsVoronoiHandler/ChartsVoronoiHandler.js +3 -3
  75. package/esm/ChartsXAxis/ChartsXAxis.js +2 -2
  76. package/esm/ChartsYAxis/ChartsYAxis.js +5 -3
  77. package/esm/LineChart/AreaPlot.js +2 -2
  78. package/esm/LineChart/LineChart.js +24 -106
  79. package/esm/LineChart/LineHighlightPlot.js +2 -2
  80. package/esm/LineChart/LinePlot.js +2 -2
  81. package/esm/LineChart/MarkPlot.js +2 -2
  82. package/esm/LineChart/useLineChartProps.js +144 -0
  83. package/esm/ScatterChart/ScatterChart.js +20 -75
  84. package/esm/ScatterChart/ScatterPlot.js +2 -2
  85. package/esm/ScatterChart/useScatterChartProps.js +108 -0
  86. package/esm/context/CartesianProvider/CartesianContext.js +13 -0
  87. package/esm/context/CartesianProvider/CartesianProvider.js +37 -0
  88. package/esm/context/CartesianProvider/computeValue.js +97 -0
  89. package/esm/context/CartesianProvider/getAxisExtremum.js +21 -0
  90. package/esm/context/CartesianProvider/index.js +10 -0
  91. package/esm/context/CartesianProvider/normalizeAxis.js +15 -0
  92. package/esm/context/CartesianProvider/useCartesianContext.js +8 -0
  93. package/esm/hooks/useAxisEvents.js +7 -10
  94. package/esm/hooks/useColorScale.js +3 -3
  95. package/esm/hooks/useScale.js +4 -5
  96. package/esm/hooks/useTicks.js +2 -1
  97. package/esm/internals/components/ChartsAxesGradients/ChartsAxesGradients.js +2 -2
  98. package/esm/internals/getSVGPoint.js +11 -0
  99. package/esm/internals/index.js +8 -2
  100. package/esm/internals/utils.js +0 -12
  101. package/hooks/useAxisEvents.js +8 -11
  102. package/hooks/useChartDimensions.d.ts +1 -1
  103. package/hooks/useColor.d.ts +1 -1
  104. package/hooks/useColorScale.js +3 -3
  105. package/hooks/useDrawingArea.d.ts +2 -8
  106. package/hooks/useScale.js +4 -7
  107. package/hooks/useTicks.js +2 -1
  108. package/index.js +1 -1
  109. package/internals/components/AxisSharedComponents.d.ts +0 -1
  110. package/internals/components/ChartsAxesGradients/ChartsAxesGradients.d.ts +2 -1
  111. package/internals/components/ChartsAxesGradients/ChartsAxesGradients.js +2 -2
  112. package/internals/defaultizeColor.d.ts +68 -68
  113. package/internals/getSVGPoint.d.ts +6 -0
  114. package/internals/getSVGPoint.js +17 -0
  115. package/internals/getWordsByLines.d.ts +0 -1
  116. package/internals/index.d.ts +9 -1
  117. package/internals/index.js +69 -5
  118. package/internals/useAnimatedPath.d.ts +0 -1
  119. package/internals/utils.d.ts +0 -6
  120. package/internals/utils.js +0 -13
  121. package/models/axis.d.ts +1 -2
  122. package/models/plugin.d.ts +4 -1
  123. package/modern/BarChart/BarChart.js +21 -104
  124. package/modern/BarChart/BarLabel/BarLabelPlot.js +0 -23
  125. package/modern/BarChart/BarPlot.js +2 -2
  126. package/modern/BarChart/useBarChartProps.js +135 -0
  127. package/modern/ChartContainer/ChartContainer.js +5 -9
  128. package/modern/ChartContainer/useChartContainerHooks.js +24 -0
  129. package/modern/ChartsAxis/ChartsAxis.js +2 -2
  130. package/modern/ChartsAxisHighlight/ChartsAxisHighlight.js +21 -6
  131. package/modern/ChartsGrid/ChartsGrid.js +2 -2
  132. package/modern/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +2 -2
  133. package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +2 -2
  134. package/modern/ChartsTooltip/ChartsItemTooltipContent.js +2 -2
  135. package/modern/ChartsVoronoiHandler/ChartsVoronoiHandler.js +3 -3
  136. package/modern/ChartsXAxis/ChartsXAxis.js +2 -2
  137. package/modern/ChartsYAxis/ChartsYAxis.js +5 -3
  138. package/modern/LineChart/AreaPlot.js +2 -2
  139. package/modern/LineChart/LineChart.js +24 -106
  140. package/modern/LineChart/LineHighlightPlot.js +2 -2
  141. package/modern/LineChart/LinePlot.js +2 -2
  142. package/modern/LineChart/MarkPlot.js +2 -2
  143. package/modern/LineChart/useLineChartProps.js +144 -0
  144. package/modern/ScatterChart/ScatterChart.js +20 -75
  145. package/modern/ScatterChart/ScatterPlot.js +2 -2
  146. package/modern/ScatterChart/useScatterChartProps.js +108 -0
  147. package/modern/context/CartesianProvider/CartesianContext.js +13 -0
  148. package/modern/context/CartesianProvider/CartesianProvider.js +37 -0
  149. package/modern/context/CartesianProvider/computeValue.js +97 -0
  150. package/modern/context/CartesianProvider/getAxisExtremum.js +21 -0
  151. package/modern/context/CartesianProvider/index.js +10 -0
  152. package/modern/context/CartesianProvider/normalizeAxis.js +15 -0
  153. package/modern/context/CartesianProvider/useCartesianContext.js +8 -0
  154. package/modern/hooks/useAxisEvents.js +7 -10
  155. package/modern/hooks/useColorScale.js +3 -3
  156. package/modern/hooks/useScale.js +4 -5
  157. package/modern/hooks/useTicks.js +2 -1
  158. package/modern/index.js +1 -1
  159. package/modern/internals/components/ChartsAxesGradients/ChartsAxesGradients.js +2 -2
  160. package/modern/internals/getSVGPoint.js +11 -0
  161. package/modern/internals/index.js +8 -2
  162. package/modern/internals/utils.js +0 -12
  163. package/package.json +3 -3
  164. package/context/CartesianContextProvider.d.ts +0 -61
  165. package/context/CartesianContextProvider.js +0 -220
  166. package/esm/context/CartesianContextProvider.js +0 -211
  167. package/modern/context/CartesianContextProvider.js +0 -211
@@ -0,0 +1,144 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import useId from '@mui/utils/useId';
3
+ import { DEFAULT_X_AXIS_KEY } from '../constants';
4
+ /**
5
+ * A helper function that extracts LineChartProps from the input props
6
+ * and returns an object with props for the children components of LineChart.
7
+ *
8
+ * @param props The input props for LineChart
9
+ * @returns An object with props for the children components of LineChart
10
+ */
11
+ export const useLineChartProps = props => {
12
+ const {
13
+ xAxis,
14
+ yAxis,
15
+ series,
16
+ width,
17
+ height,
18
+ margin,
19
+ colors,
20
+ dataset,
21
+ sx,
22
+ tooltip,
23
+ onAxisClick,
24
+ onAreaClick,
25
+ onLineClick,
26
+ onMarkClick,
27
+ axisHighlight,
28
+ disableLineItemHighlight,
29
+ legend,
30
+ grid,
31
+ topAxis,
32
+ leftAxis,
33
+ rightAxis,
34
+ bottomAxis,
35
+ children,
36
+ slots,
37
+ slotProps,
38
+ skipAnimation,
39
+ loading,
40
+ highlightedItem,
41
+ onHighlightChange
42
+ } = props;
43
+ const id = useId();
44
+ const clipPathId = `${id}-clip-path`;
45
+ const chartContainerProps = {
46
+ series: series.map(s => _extends({
47
+ disableHighlight: !!disableLineItemHighlight,
48
+ type: 'line'
49
+ }, s)),
50
+ width,
51
+ height,
52
+ margin,
53
+ colors,
54
+ dataset,
55
+ xAxis: xAxis ?? [{
56
+ id: DEFAULT_X_AXIS_KEY,
57
+ scaleType: 'point',
58
+ data: Array.from({
59
+ length: Math.max(...series.map(s => (s.data ?? dataset ?? []).length))
60
+ }, (_, index) => index)
61
+ }],
62
+ yAxis,
63
+ sx,
64
+ highlightedItem,
65
+ onHighlightChange,
66
+ disableAxisListener: tooltip?.trigger !== 'axis' && axisHighlight?.x === 'none' && axisHighlight?.y === 'none' && !onAxisClick
67
+ };
68
+ const axisClickHandlerProps = {
69
+ onAxisClick
70
+ };
71
+ const gridProps = {
72
+ vertical: grid?.vertical,
73
+ horizontal: grid?.horizontal
74
+ };
75
+ const clipPathGroupProps = {
76
+ clipPath: `url(#${clipPathId})`
77
+ };
78
+ const clipPathProps = {
79
+ id: clipPathId
80
+ };
81
+ const areaPlotProps = {
82
+ slots,
83
+ slotProps,
84
+ onItemClick: onAreaClick,
85
+ skipAnimation
86
+ };
87
+ const linePlotProps = {
88
+ slots,
89
+ slotProps,
90
+ onItemClick: onLineClick,
91
+ skipAnimation
92
+ };
93
+ const markPlotProps = {
94
+ slots,
95
+ slotProps,
96
+ onItemClick: onMarkClick,
97
+ skipAnimation
98
+ };
99
+ const overlayProps = {
100
+ slots,
101
+ slotProps,
102
+ loading
103
+ };
104
+ const chartsAxisProps = {
105
+ topAxis,
106
+ leftAxis,
107
+ rightAxis,
108
+ bottomAxis,
109
+ slots,
110
+ slotProps
111
+ };
112
+ const axisHighlightProps = _extends({
113
+ x: 'line'
114
+ }, axisHighlight);
115
+ const lineHighlightPlotProps = {
116
+ slots,
117
+ slotProps
118
+ };
119
+ const legendProps = _extends({}, legend, {
120
+ slots,
121
+ slotProps
122
+ });
123
+ const tooltipProps = _extends({}, tooltip, {
124
+ slots,
125
+ slotProps
126
+ });
127
+ return {
128
+ chartContainerProps,
129
+ axisClickHandlerProps,
130
+ gridProps,
131
+ clipPathProps,
132
+ clipPathGroupProps,
133
+ areaPlotProps,
134
+ linePlotProps,
135
+ markPlotProps,
136
+ overlayProps,
137
+ chartsAxisProps,
138
+ axisHighlightProps,
139
+ lineHighlightPlotProps,
140
+ legendProps,
141
+ tooltipProps,
142
+ children
143
+ };
144
+ };
@@ -11,6 +11,7 @@ import { ChartsAxisHighlight } from '../ChartsAxisHighlight';
11
11
  import { ChartsVoronoiHandler } from '../ChartsVoronoiHandler/ChartsVoronoiHandler';
12
12
  import { ChartsGrid } from '../ChartsGrid';
13
13
  import { ZAxisContextProvider } from '../context/ZAxisContextProvider';
14
+ import { useScatterChartProps } from './useScatterChartProps';
14
15
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
15
16
  /**
16
17
  * Demos:
@@ -24,81 +25,25 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
24
25
  */
25
26
  const ScatterChart = /*#__PURE__*/React.forwardRef(function ScatterChart(props, ref) {
26
27
  const {
27
- xAxis,
28
- yAxis,
29
- zAxis,
30
- series,
31
- tooltip,
32
- axisHighlight,
33
- voronoiMaxRadius,
34
- disableVoronoi,
35
- legend,
36
- width,
37
- height,
38
- margin,
39
- colors,
40
- sx,
41
- grid,
42
- topAxis,
43
- leftAxis,
44
- rightAxis,
45
- bottomAxis,
46
- onItemClick,
47
- children,
48
- slots,
49
- slotProps,
50
- loading,
51
- highlightedItem,
52
- onHighlightChange
53
- } = props;
54
- return /*#__PURE__*/_jsx(ResponsiveChartContainer, {
55
- ref: ref,
56
- series: series.map(s => _extends({
57
- type: 'scatter'
58
- }, s)),
59
- width: width,
60
- height: height,
61
- margin: margin,
62
- colors: colors,
63
- xAxis: xAxis,
64
- yAxis: yAxis,
65
- sx: sx,
66
- highlightedItem: highlightedItem,
67
- onHighlightChange: onHighlightChange,
68
- children: /*#__PURE__*/_jsxs(ZAxisContextProvider, {
69
- zAxis: zAxis,
70
- children: [!disableVoronoi && /*#__PURE__*/_jsx(ChartsVoronoiHandler, {
71
- voronoiMaxRadius: voronoiMaxRadius,
72
- onItemClick: onItemClick
73
- }), /*#__PURE__*/_jsx(ChartsAxis, {
74
- topAxis: topAxis,
75
- leftAxis: leftAxis,
76
- rightAxis: rightAxis,
77
- bottomAxis: bottomAxis,
78
- slots: slots,
79
- slotProps: slotProps
80
- }), grid && /*#__PURE__*/_jsx(ChartsGrid, {
81
- vertical: grid.vertical,
82
- horizontal: grid.horizontal
83
- }), /*#__PURE__*/_jsx(ScatterPlot, {
84
- slots: slots,
85
- slotProps: slotProps,
86
- onItemClick: disableVoronoi ? onItemClick : undefined
87
- }), /*#__PURE__*/_jsx(ChartsOverlay, {
88
- loading: loading,
89
- slots: slots,
90
- slotProps: slotProps
91
- }), /*#__PURE__*/_jsx(ChartsLegend, _extends({}, legend, {
92
- slots: slots,
93
- slotProps: slotProps
94
- })), /*#__PURE__*/_jsx(ChartsAxisHighlight, _extends({
95
- x: "none",
96
- y: "none"
97
- }, axisHighlight)), !loading && /*#__PURE__*/_jsx(ChartsTooltip, _extends({
98
- trigger: "item"
99
- }, tooltip)), children]
100
- })
101
- });
28
+ chartContainerProps,
29
+ zAxisProps,
30
+ voronoiHandlerProps,
31
+ chartsAxisProps,
32
+ gridProps,
33
+ scatterPlotProps,
34
+ overlayProps,
35
+ legendProps,
36
+ axisHighlightProps,
37
+ tooltipProps,
38
+ children
39
+ } = useScatterChartProps(props);
40
+ return /*#__PURE__*/_jsx(ResponsiveChartContainer, _extends({
41
+ ref: ref
42
+ }, chartContainerProps, {
43
+ children: /*#__PURE__*/_jsxs(ZAxisContextProvider, _extends({}, zAxisProps, {
44
+ children: [!props.disableVoronoi && /*#__PURE__*/_jsx(ChartsVoronoiHandler, _extends({}, voronoiHandlerProps)), /*#__PURE__*/_jsx(ChartsAxis, _extends({}, chartsAxisProps)), props.grid && /*#__PURE__*/_jsx(ChartsGrid, _extends({}, gridProps)), /*#__PURE__*/_jsx(ScatterPlot, _extends({}, scatterPlotProps)), /*#__PURE__*/_jsx(ChartsOverlay, _extends({}, overlayProps)), /*#__PURE__*/_jsx(ChartsLegend, _extends({}, legendProps)), /*#__PURE__*/_jsx(ChartsAxisHighlight, _extends({}, axisHighlightProps)), !props.loading && /*#__PURE__*/_jsx(ChartsTooltip, _extends({}, tooltipProps)), children]
45
+ }))
46
+ }));
102
47
  });
103
48
  process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
104
49
  // ----------------------------- Warning --------------------------------
@@ -2,7 +2,7 @@ import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import * as React from 'react';
3
3
  import PropTypes from 'prop-types';
4
4
  import { Scatter } from './Scatter';
5
- import { CartesianContext } from '../context/CartesianContextProvider';
5
+ import { useCartesianContext } from '../context/CartesianProvider';
6
6
  import getColor from './getColor';
7
7
  import { ZAxisContext } from '../context/ZAxisContextProvider';
8
8
  import { useScatterSeries } from '../hooks/useSeries';
@@ -24,7 +24,7 @@ function ScatterPlot(props) {
24
24
  onItemClick
25
25
  } = props;
26
26
  const seriesData = useScatterSeries();
27
- const axisData = React.useContext(CartesianContext);
27
+ const axisData = useCartesianContext();
28
28
  const {
29
29
  zAxis,
30
30
  zAxisIds
@@ -0,0 +1,108 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ /**
3
+ * A helper function that extracts ScatterChartProps from the input props
4
+ * and returns an object with props for the children components of ScatterChart.
5
+ *
6
+ * @param props The input props for ScatterChart
7
+ * @returns An object with props for the children components of ScatterChart
8
+ */
9
+ export const useScatterChartProps = props => {
10
+ const {
11
+ xAxis,
12
+ yAxis,
13
+ zAxis,
14
+ series,
15
+ tooltip,
16
+ axisHighlight,
17
+ voronoiMaxRadius,
18
+ disableVoronoi,
19
+ legend,
20
+ width,
21
+ height,
22
+ margin,
23
+ colors,
24
+ sx,
25
+ grid,
26
+ topAxis,
27
+ leftAxis,
28
+ rightAxis,
29
+ bottomAxis,
30
+ onItemClick,
31
+ children,
32
+ slots,
33
+ slotProps,
34
+ loading,
35
+ highlightedItem,
36
+ onHighlightChange
37
+ } = props;
38
+ const chartContainerProps = {
39
+ series: series.map(s => _extends({
40
+ type: 'scatter'
41
+ }, s)),
42
+ width,
43
+ height,
44
+ margin,
45
+ colors,
46
+ xAxis,
47
+ yAxis,
48
+ sx,
49
+ highlightedItem,
50
+ onHighlightChange
51
+ };
52
+ const zAxisProps = {
53
+ zAxis
54
+ };
55
+ const voronoiHandlerProps = {
56
+ voronoiMaxRadius,
57
+ onItemClick: onItemClick
58
+ };
59
+ const chartsAxisProps = {
60
+ topAxis,
61
+ leftAxis,
62
+ rightAxis,
63
+ bottomAxis,
64
+ slots,
65
+ slotProps
66
+ };
67
+ const gridProps = {
68
+ vertical: grid?.vertical,
69
+ horizontal: grid?.horizontal
70
+ };
71
+ const scatterPlotProps = {
72
+ onItemClick: disableVoronoi ? onItemClick : undefined,
73
+ slots,
74
+ slotProps
75
+ };
76
+ const overlayProps = {
77
+ loading,
78
+ slots,
79
+ slotProps
80
+ };
81
+ const legendProps = _extends({}, legend, {
82
+ slots,
83
+ slotProps
84
+ });
85
+ const axisHighlightProps = _extends({
86
+ y: 'none',
87
+ x: 'none'
88
+ }, axisHighlight);
89
+ const tooltipProps = _extends({
90
+ trigger: 'item'
91
+ }, tooltip, {
92
+ slots,
93
+ slotProps
94
+ });
95
+ return {
96
+ chartContainerProps,
97
+ zAxisProps,
98
+ voronoiHandlerProps,
99
+ chartsAxisProps,
100
+ gridProps,
101
+ scatterPlotProps,
102
+ overlayProps,
103
+ legendProps,
104
+ axisHighlightProps,
105
+ tooltipProps,
106
+ children
107
+ };
108
+ };
@@ -0,0 +1,13 @@
1
+ import * as React from 'react';
2
+ export const CartesianContext = /*#__PURE__*/React.createContext({
3
+ isInitialized: false,
4
+ data: {
5
+ xAxis: {},
6
+ yAxis: {},
7
+ xAxisIds: [],
8
+ yAxisIds: []
9
+ }
10
+ });
11
+ if (process.env.NODE_ENV !== 'production') {
12
+ CartesianContext.displayName = 'CartesianContext';
13
+ }
@@ -0,0 +1,37 @@
1
+ import * as React from 'react';
2
+ import { useDrawingArea } from '../../hooks/useDrawingArea';
3
+ import { useSeries } from '../../hooks/useSeries';
4
+ import { CartesianContext } from './CartesianContext';
5
+ import { normalizeAxis } from './normalizeAxis';
6
+ import { computeValue } from './computeValue';
7
+ import { jsx as _jsx } from "react/jsx-runtime";
8
+ function CartesianContextProvider(props) {
9
+ const {
10
+ xAxis: inXAxis,
11
+ yAxis: inYAxis,
12
+ dataset,
13
+ xExtremumGetters,
14
+ yExtremumGetters,
15
+ children
16
+ } = props;
17
+ const formattedSeries = useSeries();
18
+ const drawingArea = useDrawingArea();
19
+ const xAxis = React.useMemo(() => normalizeAxis(inXAxis, dataset, 'x'), [inXAxis, dataset]);
20
+ const yAxis = React.useMemo(() => normalizeAxis(inYAxis, dataset, 'y'), [inYAxis, dataset]);
21
+ const xValues = React.useMemo(() => computeValue(drawingArea, formattedSeries, xAxis, xExtremumGetters, 'x'), [drawingArea, formattedSeries, xAxis, xExtremumGetters]);
22
+ const yValues = React.useMemo(() => computeValue(drawingArea, formattedSeries, yAxis, yExtremumGetters, 'y'), [drawingArea, formattedSeries, yAxis, yExtremumGetters]);
23
+ const value = React.useMemo(() => ({
24
+ isInitialized: true,
25
+ data: {
26
+ xAxis: xValues.axis,
27
+ yAxis: yValues.axis,
28
+ xAxisIds: xValues.axisIds,
29
+ yAxisIds: yValues.axisIds
30
+ }
31
+ }), [xValues, yValues]);
32
+ return /*#__PURE__*/_jsx(CartesianContext.Provider, {
33
+ value: value,
34
+ children: children
35
+ });
36
+ }
37
+ export { CartesianContextProvider };
@@ -0,0 +1,97 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import { scaleBand, scalePoint, scaleTime } from 'd3-scale';
3
+ import { DEFAULT_X_AXIS_KEY, DEFAULT_Y_AXIS_KEY } from '../../constants';
4
+ import { isBandScaleConfig, isPointScaleConfig } from '../../models/axis';
5
+ import { getColorScale, getOrdinalColorScale } from '../../internals/colorScale';
6
+ import { getTickNumber } from '../../hooks/useTicks';
7
+ import { getScale } from '../../internals/getScale';
8
+ import { getAxisExtremum } from './getAxisExtremum';
9
+ const getRange = (drawingArea, axisName, isReverse) => {
10
+ const range = axisName === 'x' ? [drawingArea.left, drawingArea.left + drawingArea.width] : [drawingArea.top + drawingArea.height, drawingArea.top];
11
+ return isReverse ? range.reverse() : range;
12
+ };
13
+ const isDateData = data => data?.[0] instanceof Date;
14
+ function createDateFormatter(axis, range) {
15
+ const timeScale = scaleTime(axis.data, range);
16
+ return (v, {
17
+ location
18
+ }) => location === 'tick' ? timeScale.tickFormat(axis.tickNumber)(v) : `${v.toLocaleString()}`;
19
+ }
20
+ const DEFAULT_CATEGORY_GAP_RATIO = 0.2;
21
+ const DEFAULT_BAR_GAP_RATIO = 0.1;
22
+ export function computeValue(drawingArea, formattedSeries, inAxis, extremumGetters, axisName) {
23
+ const DEFAULT_AXIS_KEY = axisName === 'x' ? DEFAULT_X_AXIS_KEY : DEFAULT_Y_AXIS_KEY;
24
+ const allAxis = [...(inAxis?.map((axis, index) => _extends({
25
+ id: `defaultized-${axisName}-axis-${index}`
26
+ }, axis)) ?? []), ...(inAxis === undefined || inAxis.findIndex(({
27
+ id
28
+ }) => id === DEFAULT_AXIS_KEY) === -1 ? [{
29
+ id: DEFAULT_AXIS_KEY,
30
+ scaleType: 'linear'
31
+ }] : [])];
32
+ const completeAxis = {};
33
+ allAxis.forEach((axis, axisIndex) => {
34
+ const isDefaultAxis = axisIndex === 0;
35
+ const [minData, maxData] = getAxisExtremum(axis, extremumGetters, isDefaultAxis, formattedSeries);
36
+ const range = getRange(drawingArea, axisName, axis.reverse);
37
+ if (isBandScaleConfig(axis)) {
38
+ const categoryGapRatio = axis.categoryGapRatio ?? DEFAULT_CATEGORY_GAP_RATIO;
39
+ const barGapRatio = axis.barGapRatio ?? DEFAULT_BAR_GAP_RATIO;
40
+ // Reverse range because ordinal scales are presented from top to bottom on y-axis
41
+ const scaleRange = axisName === 'x' ? range : [range[1], range[0]];
42
+ completeAxis[axis.id] = _extends({
43
+ categoryGapRatio,
44
+ barGapRatio
45
+ }, axis, {
46
+ scale: scaleBand(axis.data, scaleRange).paddingInner(categoryGapRatio).paddingOuter(categoryGapRatio / 2),
47
+ tickNumber: axis.data.length,
48
+ colorScale: axis.colorMap && (axis.colorMap.type === 'ordinal' ? getOrdinalColorScale(_extends({
49
+ values: axis.data
50
+ }, axis.colorMap)) : getColorScale(axis.colorMap))
51
+ });
52
+ if (isDateData(axis.data)) {
53
+ const dateFormatter = createDateFormatter(axis, scaleRange);
54
+ completeAxis[axis.id].valueFormatter = axis.valueFormatter ?? dateFormatter;
55
+ }
56
+ }
57
+ if (isPointScaleConfig(axis)) {
58
+ const scaleRange = axisName === 'x' ? range : [...range].reverse();
59
+ completeAxis[axis.id] = _extends({}, axis, {
60
+ scale: scalePoint(axis.data, scaleRange),
61
+ tickNumber: axis.data.length,
62
+ colorScale: axis.colorMap && (axis.colorMap.type === 'ordinal' ? getOrdinalColorScale(_extends({
63
+ values: axis.data
64
+ }, axis.colorMap)) : getColorScale(axis.colorMap))
65
+ });
66
+ if (isDateData(axis.data)) {
67
+ const dateFormatter = createDateFormatter(axis, scaleRange);
68
+ completeAxis[axis.id].valueFormatter = axis.valueFormatter ?? dateFormatter;
69
+ }
70
+ }
71
+ if (axis.scaleType === 'band' || axis.scaleType === 'point') {
72
+ // Could be merged with the two previous "if conditions" but then TS does not get that `axis.scaleType` can't be `band` or `point`.
73
+ return;
74
+ }
75
+ const scaleType = axis.scaleType ?? 'linear';
76
+ const extremums = [axis.min ?? minData, axis.max ?? maxData];
77
+ const tickNumber = getTickNumber(_extends({}, axis, {
78
+ range,
79
+ domain: extremums
80
+ }));
81
+ const scale = getScale(scaleType, extremums, range).nice(tickNumber);
82
+ const [minDomain, maxDomain] = scale.domain();
83
+ const domain = [axis.min ?? minDomain, axis.max ?? maxDomain];
84
+ completeAxis[axis.id] = _extends({}, axis, {
85
+ scaleType: scaleType,
86
+ scale: scale.domain(domain),
87
+ tickNumber,
88
+ colorScale: axis.colorMap && getColorScale(axis.colorMap)
89
+ });
90
+ });
91
+ return {
92
+ axis: completeAxis,
93
+ axisIds: allAxis.map(({
94
+ id
95
+ }) => id)
96
+ };
97
+ }
@@ -0,0 +1,21 @@
1
+ const axisExtremumCallback = (acc, chartType, axis, getters, isDefaultAxis, formattedSeries) => {
2
+ const getter = getters[chartType];
3
+ const series = formattedSeries[chartType]?.series ?? {};
4
+ const [minChartTypeData, maxChartTypeData] = getter?.({
5
+ series,
6
+ axis,
7
+ isDefaultAxis
8
+ }) ?? [null, null];
9
+ const [minData, maxData] = acc;
10
+ if (minData === null || maxData === null) {
11
+ return [minChartTypeData, maxChartTypeData];
12
+ }
13
+ if (minChartTypeData === null || maxChartTypeData === null) {
14
+ return [minData, maxData];
15
+ }
16
+ return [Math.min(minChartTypeData, minData), Math.max(maxChartTypeData, maxData)];
17
+ };
18
+ export const getAxisExtremum = (axis, getters, isDefaultAxis, formattedSeries) => {
19
+ const charTypes = Object.keys(getters);
20
+ return charTypes.reduce((acc, charType) => axisExtremumCallback(acc, charType, axis, getters, isDefaultAxis, formattedSeries), [null, null]);
21
+ };
@@ -0,0 +1,10 @@
1
+ import { computeValue } from './computeValue';
2
+ import { normalizeAxis } from './normalizeAxis';
3
+ export * from './CartesianProvider';
4
+ export * from './CartesianContext';
5
+ export * from './useCartesianContext';
6
+ const cartesianProviderUtils = {
7
+ computeValue,
8
+ normalizeAxis
9
+ };
10
+ export { cartesianProviderUtils };
@@ -0,0 +1,15 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ export const normalizeAxis = (axis, dataset, axisName) => {
3
+ return axis?.map(axisConfig => {
4
+ const dataKey = axisConfig.dataKey;
5
+ if (dataKey === undefined || axisConfig.data !== undefined) {
6
+ return axisConfig;
7
+ }
8
+ if (dataset === undefined) {
9
+ throw Error(`MUI X Charts: ${axisName}-axis uses \`dataKey\` but no \`dataset\` is provided.`);
10
+ }
11
+ return _extends({}, axisConfig, {
12
+ data: dataset.map(d => d[dataKey])
13
+ });
14
+ });
15
+ };
@@ -0,0 +1,8 @@
1
+ import * as React from 'react';
2
+ import { CartesianContext } from './CartesianContext';
3
+ export const useCartesianContext = () => {
4
+ const {
5
+ data
6
+ } = React.useContext(CartesianContext);
7
+ return data;
8
+ };
@@ -1,8 +1,8 @@
1
1
  import * as React from 'react';
2
2
  import { InteractionContext } from '../context/InteractionProvider';
3
- import { CartesianContext } from '../context/CartesianContextProvider';
3
+ import { useCartesianContext } from '../context/CartesianProvider';
4
4
  import { isBandScale } from '../internals/isBandScale';
5
- import { getSVGPoint } from '../internals/utils';
5
+ import { getSVGPoint } from '../internals/getSVGPoint';
6
6
  import { useSvgRef } from './useSvgRef';
7
7
  import { useDrawingArea } from './useDrawingArea';
8
8
  function getAsANumber(value) {
@@ -21,7 +21,7 @@ export const useAxisEvents = disableAxisListener => {
21
21
  yAxis,
22
22
  xAxisIds,
23
23
  yAxisIds
24
- } = React.useContext(CartesianContext);
24
+ } = useCartesianContext();
25
25
  const {
26
26
  dispatch
27
27
  } = React.useContext(InteractionContext);
@@ -38,10 +38,7 @@ export const useAxisEvents = disableAxisListener => {
38
38
  if (element === null || disableAxisListener) {
39
39
  return () => {};
40
40
  }
41
- const getUpdate = (axisConfig, mouseValue) => {
42
- if (usedXAxis === null) {
43
- return null;
44
- }
41
+ function getNewAxisState(axisConfig, mouseValue) {
45
42
  const {
46
43
  scale,
47
44
  data: axisData,
@@ -89,7 +86,7 @@ export const useAxisEvents = disableAxisListener => {
89
86
  index: dataIndex,
90
87
  value: axisData[dataIndex]
91
88
  };
92
- };
89
+ }
93
90
  const handleOut = () => {
94
91
  mousePosition.current = {
95
92
  x: -1,
@@ -114,8 +111,8 @@ export const useAxisEvents = disableAxisListener => {
114
111
  });
115
112
  return;
116
113
  }
117
- const newStateX = getUpdate(xAxis[usedXAxis], svgPoint.x);
118
- const newStateY = getUpdate(yAxis[usedYAxis], svgPoint.y);
114
+ const newStateX = getNewAxisState(xAxis[usedXAxis], svgPoint.x);
115
+ const newStateY = getNewAxisState(yAxis[usedYAxis], svgPoint.y);
119
116
  dispatch({
120
117
  type: 'updateAxis',
121
118
  data: {
@@ -1,11 +1,11 @@
1
1
  import * as React from 'react';
2
- import { CartesianContext } from '../context/CartesianContextProvider';
2
+ import { useCartesianContext } from '../context/CartesianProvider';
3
3
  import { ZAxisContext } from '../context/ZAxisContextProvider';
4
4
  export function useXColorScale(identifier) {
5
5
  const {
6
6
  xAxis,
7
7
  xAxisIds
8
- } = React.useContext(CartesianContext);
8
+ } = useCartesianContext();
9
9
  const id = typeof identifier === 'string' ? identifier : xAxisIds[identifier ?? 0];
10
10
  return xAxis[id].colorScale;
11
11
  }
@@ -13,7 +13,7 @@ export function useYColorScale(identifier) {
13
13
  const {
14
14
  yAxis,
15
15
  yAxisIds
16
- } = React.useContext(CartesianContext);
16
+ } = useCartesianContext();
17
17
  const id = typeof identifier === 'string' ? identifier : yAxisIds[identifier ?? 0];
18
18
  return yAxis[id].colorScale;
19
19
  }