@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,135 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import useId from '@mui/utils/useId';
3
+ import { DEFAULT_X_AXIS_KEY, DEFAULT_Y_AXIS_KEY } from '../constants';
4
+ /**
5
+ * A helper function that extracts BarChartProps from the input props
6
+ * and returns an object with props for the children components of BarChart.
7
+ *
8
+ * @param props The input props for BarChart
9
+ * @returns An object with props for the children components of BarChart
10
+ */
11
+ export const useBarChartProps = 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
+ axisHighlight,
25
+ legend,
26
+ grid,
27
+ topAxis,
28
+ leftAxis,
29
+ rightAxis,
30
+ bottomAxis,
31
+ children,
32
+ slots,
33
+ slotProps,
34
+ skipAnimation,
35
+ loading,
36
+ layout,
37
+ onItemClick,
38
+ highlightedItem,
39
+ onHighlightChange,
40
+ borderRadius,
41
+ barLabel
42
+ } = props;
43
+ const id = useId();
44
+ const clipPathId = `${id}-clip-path`;
45
+ const hasHorizontalSeries = layout === 'horizontal' || layout === undefined && series.some(item => item.layout === 'horizontal');
46
+ const defaultAxisConfig = {
47
+ scaleType: 'band',
48
+ data: Array.from({
49
+ length: Math.max(...series.map(s => (s.data ?? dataset ?? []).length))
50
+ }, (_, index) => index)
51
+ };
52
+ const chartContainerProps = {
53
+ series: series.map(s => _extends({
54
+ type: 'bar'
55
+ }, s, {
56
+ layout: hasHorizontalSeries ? 'horizontal' : 'vertical'
57
+ })),
58
+ width,
59
+ height,
60
+ margin,
61
+ colors,
62
+ dataset,
63
+ xAxis: xAxis ?? (hasHorizontalSeries ? undefined : [_extends({
64
+ id: DEFAULT_X_AXIS_KEY
65
+ }, defaultAxisConfig)]),
66
+ yAxis: yAxis ?? (hasHorizontalSeries ? [_extends({
67
+ id: DEFAULT_Y_AXIS_KEY
68
+ }, defaultAxisConfig)] : undefined),
69
+ sx,
70
+ highlightedItem,
71
+ onHighlightChange,
72
+ disableAxisListener: tooltip?.trigger !== 'axis' && axisHighlight?.x === 'none' && axisHighlight?.y === 'none' && !onAxisClick
73
+ };
74
+ const barPlotProps = {
75
+ onItemClick,
76
+ slots,
77
+ slotProps,
78
+ skipAnimation,
79
+ borderRadius,
80
+ barLabel
81
+ };
82
+ const axisClickHandlerProps = {
83
+ onAxisClick
84
+ };
85
+ const gridProps = {
86
+ vertical: grid?.vertical,
87
+ horizontal: grid?.horizontal
88
+ };
89
+ const clipPathGroupProps = {
90
+ clipPath: `url(#${clipPathId})`
91
+ };
92
+ const clipPathProps = {
93
+ id: clipPathId
94
+ };
95
+ const overlayProps = {
96
+ slots,
97
+ slotProps,
98
+ loading
99
+ };
100
+ const chartsAxisProps = {
101
+ topAxis,
102
+ leftAxis,
103
+ rightAxis,
104
+ bottomAxis,
105
+ slots,
106
+ slotProps
107
+ };
108
+ const axisHighlightProps = _extends({}, hasHorizontalSeries ? {
109
+ y: 'band'
110
+ } : {
111
+ x: 'band'
112
+ }, axisHighlight);
113
+ const legendProps = _extends({}, legend, {
114
+ slots,
115
+ slotProps
116
+ });
117
+ const tooltipProps = _extends({}, tooltip, {
118
+ slots,
119
+ slotProps
120
+ });
121
+ return {
122
+ chartContainerProps,
123
+ barPlotProps,
124
+ axisClickHandlerProps,
125
+ gridProps,
126
+ clipPathProps,
127
+ clipPathGroupProps,
128
+ overlayProps,
129
+ chartsAxisProps,
130
+ axisHighlightProps,
131
+ legendProps,
132
+ tooltipProps,
133
+ children
134
+ };
135
+ };
@@ -1,16 +1,14 @@
1
1
  import * as React from 'react';
2
2
  import PropTypes from 'prop-types';
3
- import useForkRef from '@mui/utils/useForkRef';
4
3
  import { DrawingProvider } from '../context/DrawingProvider';
5
4
  import { SeriesContextProvider } from '../context/SeriesContextProvider';
6
5
  import { InteractionProvider } from '../context/InteractionProvider';
7
6
  import { ColorProvider } from '../context/ColorProvider';
8
- import { useReducedMotion } from '../hooks/useReducedMotion';
9
7
  import { ChartsSurface } from '../ChartsSurface';
10
- import { CartesianContextProvider } from '../context/CartesianContextProvider';
8
+ import { CartesianContextProvider } from '../context/CartesianProvider';
11
9
  import { ChartsAxesGradients } from '../internals/components/ChartsAxesGradients';
12
10
  import { HighlightedProvider, ZAxisContextProvider } from '../context';
13
- import { usePluginsMerge } from './usePluginsMerge';
11
+ import { useChartContainerHooks } from './useChartContainerHooks';
14
12
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
15
13
  const ChartContainer = /*#__PURE__*/React.forwardRef(function ChartContainer(props, ref) {
16
14
  const {
@@ -32,16 +30,14 @@ const ChartContainer = /*#__PURE__*/React.forwardRef(function ChartContainer(pro
32
30
  plugins,
33
31
  children
34
32
  } = props;
35
- const svgRef = React.useRef(null);
36
- const handleRef = useForkRef(ref, svgRef);
37
33
  const {
34
+ svgRef,
35
+ handleRef,
38
36
  xExtremumGetters,
39
37
  yExtremumGetters,
40
38
  seriesFormatters,
41
39
  colorProcessors
42
- } = usePluginsMerge(plugins);
43
- useReducedMotion(); // a11y reduce motion (see: https://react-spring.dev/docs/utilities/use-reduced-motion)
44
-
40
+ } = useChartContainerHooks(ref, plugins);
45
41
  return /*#__PURE__*/_jsx(DrawingProvider, {
46
42
  width: width,
47
43
  height: height,
@@ -0,0 +1,24 @@
1
+ import useForkRef from '@mui/utils/useForkRef';
2
+ import * as React from 'react';
3
+ import { usePluginsMerge } from './usePluginsMerge';
4
+ import { useReducedMotion } from '../hooks/useReducedMotion';
5
+ export const useChartContainerHooks = (ref, plugins) => {
6
+ const svgRef = React.useRef(null);
7
+ const handleRef = useForkRef(ref, svgRef);
8
+ const {
9
+ xExtremumGetters,
10
+ yExtremumGetters,
11
+ seriesFormatters,
12
+ colorProcessors
13
+ } = usePluginsMerge(plugins);
14
+ useReducedMotion(); // a11y reduce motion (see: https://react-spring.dev/docs/utilities/use-reduced-motion)
15
+
16
+ return {
17
+ svgRef,
18
+ handleRef,
19
+ xExtremumGetters,
20
+ yExtremumGetters,
21
+ seriesFormatters,
22
+ colorProcessors
23
+ };
24
+ };
@@ -1,7 +1,7 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import * as React from 'react';
3
3
  import PropTypes from 'prop-types';
4
- import { CartesianContext } from '../context/CartesianContextProvider';
4
+ import { useCartesianContext } from '../context/CartesianProvider';
5
5
  import { ChartsXAxis } from '../ChartsXAxis';
6
6
  import { ChartsYAxis } from '../ChartsYAxis';
7
7
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
@@ -47,7 +47,7 @@ function ChartsAxis(props) {
47
47
  xAxisIds,
48
48
  yAxis,
49
49
  yAxisIds
50
- } = React.useContext(CartesianContext);
50
+ } = useCartesianContext();
51
51
 
52
52
  // TODO: use for plotting line without ticks or any thing
53
53
  // const drawingArea = React.useContext(DrawingContext);
@@ -6,7 +6,7 @@ import generateUtilityClass from '@mui/utils/generateUtilityClass';
6
6
  import generateUtilityClasses from '@mui/utils/generateUtilityClasses';
7
7
  import { styled } from '@mui/material/styles';
8
8
  import { InteractionContext } from '../context/InteractionProvider';
9
- import { CartesianContext } from '../context/CartesianContextProvider';
9
+ import { useCartesianContext } from '../context/CartesianProvider';
10
10
  import { getValueToPositionMapper } from '../hooks/useScale';
11
11
  import { isBandScale } from '../internals/isBandScale';
12
12
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
@@ -55,7 +55,7 @@ function ChartsAxisHighlight(props) {
55
55
  xAxis,
56
56
  yAxisIds,
57
57
  yAxis
58
- } = React.useContext(CartesianContext);
58
+ } = useCartesianContext();
59
59
  const classes = useUtilityClasses();
60
60
  const USED_X_AXIS_ID = xAxisIds[0];
61
61
  const USED_Y_AXIS_ID = yAxisIds[0];
@@ -66,15 +66,30 @@ function ChartsAxisHighlight(props) {
66
66
  } = React.useContext(InteractionContext);
67
67
  const getXPosition = getValueToPositionMapper(xScale);
68
68
  const getYPosition = getValueToPositionMapper(yScale);
69
+ const axisX = axis.x;
70
+ const axisY = axis.y;
71
+ const isBandScaleX = xAxisHighlight === 'band' && axisX !== null && isBandScale(xScale);
72
+ const isBandScaleY = yAxisHighlight === 'band' && axisY !== null && isBandScale(yScale);
73
+ if (process.env.NODE_ENV !== 'production') {
74
+ const isXError = isBandScaleX && xScale(axisX.value) === undefined;
75
+ const isYError = isBandScaleY && yScale(axisY.value) === undefined;
76
+ if (isXError || isYError) {
77
+ console.error([`MUI X Charts: The position value provided for the axis is not valid for the current scale.`, `This probably means something is wrong with the data passed to the chart.`, `The ChartsAxisHighlight component will not be displayed.`].join('\n'));
78
+ }
79
+ }
69
80
  return /*#__PURE__*/_jsxs(React.Fragment, {
70
- children: [xAxisHighlight === 'band' && axis.x !== null && isBandScale(xScale) && /*#__PURE__*/_jsx(ChartsAxisHighlightPath, {
71
- d: `M ${xScale(axis.x.value) - (xScale.step() - xScale.bandwidth()) / 2} ${yScale.range()[0]} l ${xScale.step()} 0 l 0 ${yScale.range()[1] - yScale.range()[0]} l ${-xScale.step()} 0 Z`,
81
+ children: [isBandScaleX && xScale(axisX.value) !== undefined && /*#__PURE__*/_jsx(ChartsAxisHighlightPath
82
+ // @ts-expect-error, xScale value is checked in the statement above
83
+ , {
84
+ d: `M ${xScale(axisX.value) - (xScale.step() - xScale.bandwidth()) / 2} ${yScale.range()[0]} l ${xScale.step()} 0 l 0 ${yScale.range()[1] - yScale.range()[0]} l ${-xScale.step()} 0 Z`,
72
85
  className: classes.root,
73
86
  ownerState: {
74
87
  axisHighlight: 'band'
75
88
  }
76
- }), yAxisHighlight === 'band' && axis.y !== null && isBandScale(yScale) && /*#__PURE__*/_jsx(ChartsAxisHighlightPath, {
77
- d: `M ${xScale.range()[0]} ${yScale(axis.y.value) - (yScale.step() - yScale.bandwidth()) / 2} l 0 ${yScale.step()} l ${xScale.range()[1] - xScale.range()[0]} 0 l 0 ${-yScale.step()} Z`,
89
+ }), isBandScaleY && yScale(axisY.value) === undefined && /*#__PURE__*/_jsx(ChartsAxisHighlightPath, {
90
+ d: `M ${xScale.range()[0]} ${
91
+ // @ts-expect-error, yScale value is checked in the statement above
92
+ yScale(axisY.value) - (yScale.step() - yScale.bandwidth()) / 2} l 0 ${yScale.step()} l ${xScale.range()[1] - xScale.range()[0]} 0 l 0 ${-yScale.step()} Z`,
78
93
  className: classes.root,
79
94
  ownerState: {
80
95
  axisHighlight: 'band'
@@ -5,7 +5,7 @@ import * as React from 'react';
5
5
  import PropTypes from 'prop-types';
6
6
  import composeClasses from '@mui/utils/composeClasses';
7
7
  import { styled, useThemeProps } from '@mui/material/styles';
8
- import { CartesianContext } from '../context/CartesianContextProvider';
8
+ import { useCartesianContext } from '../context/CartesianProvider';
9
9
  import { useTicks } from '../hooks/useTicks';
10
10
  import { getChartsGridUtilityClass, chartsGridClasses } from './chartsGridClasses';
11
11
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
@@ -63,7 +63,7 @@ function ChartsGrid(props) {
63
63
  xAxisIds,
64
64
  yAxis,
65
65
  yAxisIds
66
- } = React.useContext(CartesianContext);
66
+ } = useCartesianContext();
67
67
  const classes = useUtilityClasses(themeProps);
68
68
  const horizontalAxisId = yAxisIds[0];
69
69
  const verticalAxisId = xAxisIds[0];
@@ -1,9 +1,9 @@
1
1
  import * as React from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
  import { InteractionContext } from '../context/InteractionProvider';
4
- import { CartesianContext } from '../context/CartesianContextProvider';
5
4
  import { useSeries } from '../hooks/useSeries';
6
5
  import { useSvgRef } from '../hooks';
6
+ import { useCartesianContext } from '../context/CartesianProvider';
7
7
  import { jsx as _jsx } from "react/jsx-runtime";
8
8
  function ChartsOnAxisClickHandler(props) {
9
9
  const {
@@ -19,7 +19,7 @@ function ChartsOnAxisClickHandler(props) {
19
19
  xAxis,
20
20
  yAxisIds,
21
21
  yAxis
22
- } = React.useContext(CartesianContext);
22
+ } = useCartesianContext();
23
23
  React.useEffect(() => {
24
24
  const element = svgRef.current;
25
25
  if (element === null || !onAxisClick) {
@@ -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 { useSlotProps } from '@mui/base/utils';
5
- import { CartesianContext } from '../context/CartesianContextProvider';
5
+ import { useCartesianContext } from '../context/CartesianProvider';
6
6
  import { DefaultChartsAxisTooltipContent } from './DefaultChartsAxisTooltipContent';
7
7
  import { ZAxisContext } from '../context/ZAxisContextProvider';
8
8
  import { useColorProcessor } from '../hooks/useColor';
@@ -25,7 +25,7 @@ function ChartsAxisTooltipContent(props) {
25
25
  xAxis,
26
26
  yAxisIds,
27
27
  yAxis
28
- } = React.useContext(CartesianContext);
28
+ } = useCartesianContext();
29
29
  const {
30
30
  zAxisIds,
31
31
  zAxis
@@ -3,7 +3,7 @@ import * as React from 'react';
3
3
  import PropTypes from 'prop-types';
4
4
  import { useSlotProps } from '@mui/base/utils';
5
5
  import { DefaultChartsItemTooltipContent } from './DefaultChartsItemTooltipContent';
6
- import { CartesianContext } from '../context/CartesianContextProvider';
6
+ import { useCartesianContext } from '../context/CartesianProvider';
7
7
  import { ZAxisContext } from '../context/ZAxisContextProvider';
8
8
  import { useColorProcessor } from '../hooks/useColor';
9
9
  import { useSeries } from '../hooks/useSeries';
@@ -22,7 +22,7 @@ function ChartsItemTooltipContent(props) {
22
22
  yAxis,
23
23
  xAxisIds,
24
24
  yAxisIds
25
- } = React.useContext(CartesianContext);
25
+ } = useCartesianContext();
26
26
  const {
27
27
  zAxis,
28
28
  zAxisIds
@@ -3,9 +3,9 @@ import PropTypes from 'prop-types';
3
3
  import { Delaunay } from 'd3-delaunay';
4
4
  import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
5
5
  import { InteractionContext } from '../context/InteractionProvider';
6
- import { CartesianContext } from '../context/CartesianContextProvider';
6
+ import { useCartesianContext } from '../context/CartesianProvider';
7
7
  import { getValueToPositionMapper } from '../hooks/useScale';
8
- import { getSVGPoint } from '../internals/utils';
8
+ import { getSVGPoint } from '../internals/getSVGPoint';
9
9
  import { useDrawingArea, useSvgRef } from '../hooks';
10
10
  import { useHighlighted } from '../context';
11
11
  import { useScatterSeries } from '../hooks/useSeries';
@@ -27,7 +27,7 @@ function ChartsVoronoiHandler(props) {
27
27
  yAxis,
28
28
  xAxisIds,
29
29
  yAxisIds
30
- } = React.useContext(CartesianContext);
30
+ } = useCartesianContext();
31
31
  const {
32
32
  dispatch
33
33
  } = React.useContext(InteractionContext);
@@ -6,7 +6,7 @@ import PropTypes from 'prop-types';
6
6
  import { useSlotProps } from '@mui/base/utils';
7
7
  import { unstable_composeClasses as composeClasses } from '@mui/utils';
8
8
  import { useThemeProps, useTheme } from '@mui/material/styles';
9
- import { CartesianContext } from '../context/CartesianContextProvider';
9
+ import { useCartesianContext } from '../context/CartesianProvider';
10
10
  import { useTicks } from '../hooks/useTicks';
11
11
  import { getAxisUtilityClass } from '../ChartsAxis/axisClasses';
12
12
  import { AxisRoot } from '../internals/components/AxisSharedComponents';
@@ -107,7 +107,7 @@ function ChartsXAxis(inProps) {
107
107
  const {
108
108
  xAxisIds,
109
109
  xAxis
110
- } = React.useContext(CartesianContext);
110
+ } = useCartesianContext();
111
111
  const _xAxis = xAxis[inProps.axisId ?? xAxisIds[0]],
112
112
  {
113
113
  scale: xScale,
@@ -6,7 +6,7 @@ import PropTypes from 'prop-types';
6
6
  import { useSlotProps } from '@mui/base/utils';
7
7
  import { unstable_composeClasses as composeClasses } from '@mui/utils';
8
8
  import { useThemeProps, useTheme } from '@mui/material/styles';
9
- import { CartesianContext } from '../context/CartesianContextProvider';
9
+ import { useCartesianContext } from '../context/CartesianProvider';
10
10
  import { useTicks } from '../hooks/useTicks';
11
11
  import { useDrawingArea } from '../hooks/useDrawingArea';
12
12
  import { AxisRoot } from '../internals/components/AxisSharedComponents';
@@ -50,7 +50,7 @@ function ChartsYAxis(inProps) {
50
50
  const {
51
51
  yAxisIds,
52
52
  yAxis
53
- } = React.useContext(CartesianContext);
53
+ } = useCartesianContext();
54
54
  const _yAxis = yAxis[inProps.axisId ?? yAxisIds[0]],
55
55
  {
56
56
  scale: yScale,
@@ -81,6 +81,7 @@ function ChartsYAxis(inProps) {
81
81
  tickLabelInterval
82
82
  } = defaultizedProps;
83
83
  const theme = useTheme();
84
+ const isRTL = theme.direction === 'rtl';
84
85
  const classes = useUtilityClasses(_extends({}, defaultizedProps, {
85
86
  theme
86
87
  }));
@@ -108,13 +109,14 @@ function ChartsYAxis(inProps) {
108
109
  const Tick = slots?.axisTick ?? 'line';
109
110
  const TickLabel = slots?.axisTickLabel ?? ChartsText;
110
111
  const Label = slots?.axisLabel ?? ChartsText;
112
+ const revertAnchor = !isRTL && position === 'right' || isRTL && position !== 'right';
111
113
  const axisTickLabelProps = useSlotProps({
112
114
  elementType: TickLabel,
113
115
  externalSlotProps: slotProps?.axisTickLabel,
114
116
  additionalProps: {
115
117
  style: _extends({
116
118
  fontSize: tickFontSize,
117
- textAnchor: position === 'right' ? 'start' : 'end',
119
+ textAnchor: revertAnchor ? 'start' : 'end',
118
120
  dominantBaseline: 'central'
119
121
  }, tickLabelStyle)
120
122
  },
@@ -4,7 +4,7 @@ const _excluded = ["slots", "slotProps", "onItemClick", "skipAnimation"];
4
4
  import * as React from 'react';
5
5
  import PropTypes from 'prop-types';
6
6
  import { area as d3Area } from 'd3-shape';
7
- import { CartesianContext } from '../context/CartesianContextProvider';
7
+ import { useCartesianContext } from '../context/CartesianProvider';
8
8
  import { AreaElement } from './AreaElement';
9
9
  import { getValueToPositionMapper } from '../hooks/useScale';
10
10
  import getCurveFactory from '../internals/getCurve';
@@ -14,7 +14,7 @@ import { useLineSeries } from '../hooks/useSeries';
14
14
  import { jsx as _jsx } from "react/jsx-runtime";
15
15
  const useAggregatedData = () => {
16
16
  const seriesData = useLineSeries();
17
- const axisData = React.useContext(CartesianContext);
17
+ const axisData = useCartesianContext();
18
18
  if (seriesData === undefined) {
19
19
  return [];
20
20
  }
@@ -1,13 +1,11 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import * as React from 'react';
3
- import useId from '@mui/utils/useId';
4
3
  import PropTypes from 'prop-types';
5
4
  import { AreaPlot } from './AreaPlot';
6
5
  import { LinePlot } from './LinePlot';
7
6
  import { ResponsiveChartContainer } from '../ResponsiveChartContainer';
8
7
  import { MarkPlot } from './MarkPlot';
9
8
  import { ChartsAxis } from '../ChartsAxis/ChartsAxis';
10
- import { DEFAULT_X_AXIS_KEY } from '../constants';
11
9
  import { ChartsTooltip } from '../ChartsTooltip';
12
10
  import { ChartsLegend } from '../ChartsLegend';
13
11
  import { ChartsAxisHighlight } from '../ChartsAxisHighlight';
@@ -16,6 +14,7 @@ import { LineHighlightPlot } from './LineHighlightPlot';
16
14
  import { ChartsGrid } from '../ChartsGrid';
17
15
  import { ChartsOnAxisClickHandler } from '../ChartsOnAxisClickHandler';
18
16
  import { ChartsOverlay } from '../ChartsOverlay';
17
+ import { useLineChartProps } from './useLineChartProps';
19
18
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
20
19
  /**
21
20
  * Demos:
@@ -29,110 +28,29 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
29
28
  */
30
29
  const LineChart = /*#__PURE__*/React.forwardRef(function LineChart(props, ref) {
31
30
  const {
32
- xAxis,
33
- yAxis,
34
- series,
35
- width,
36
- height,
37
- margin,
38
- colors,
39
- dataset,
40
- sx,
41
- tooltip,
42
- onAxisClick,
43
- onAreaClick,
44
- onLineClick,
45
- onMarkClick,
46
- axisHighlight = {
47
- x: 'line'
48
- },
49
- disableLineItemHighlight,
50
- legend,
51
- grid,
52
- topAxis,
53
- leftAxis,
54
- rightAxis,
55
- bottomAxis,
56
- children,
57
- slots,
58
- slotProps,
59
- skipAnimation,
60
- loading,
61
- highlightedItem,
62
- onHighlightChange
63
- } = props;
64
- const id = useId();
65
- const clipPathId = `${id}-clip-path`;
66
- return /*#__PURE__*/_jsxs(ResponsiveChartContainer, {
67
- ref: ref,
68
- series: series.map(s => _extends({
69
- disableHighlight: !!disableLineItemHighlight,
70
- type: 'line'
71
- }, s)),
72
- width: width,
73
- height: height,
74
- margin: margin,
75
- xAxis: xAxis ?? [{
76
- id: DEFAULT_X_AXIS_KEY,
77
- scaleType: 'point',
78
- data: Array.from({
79
- length: Math.max(...series.map(s => (s.data ?? dataset ?? []).length))
80
- }, (_, index) => index)
81
- }],
82
- yAxis: yAxis,
83
- colors: colors,
84
- dataset: dataset,
85
- sx: sx,
86
- disableAxisListener: tooltip?.trigger !== 'axis' && axisHighlight?.x === 'none' && axisHighlight?.y === 'none' && !onAxisClick,
87
- highlightedItem: highlightedItem,
88
- onHighlightChange: onHighlightChange,
89
- children: [onAxisClick && /*#__PURE__*/_jsx(ChartsOnAxisClickHandler, {
90
- onAxisClick: onAxisClick
91
- }), grid && /*#__PURE__*/_jsx(ChartsGrid, {
92
- vertical: grid.vertical,
93
- horizontal: grid.horizontal
94
- }), /*#__PURE__*/_jsxs("g", {
95
- clipPath: `url(#${clipPathId})`,
96
- children: [/*#__PURE__*/_jsx(AreaPlot, {
97
- slots: slots,
98
- slotProps: slotProps,
99
- onItemClick: onAreaClick,
100
- skipAnimation: skipAnimation
101
- }), /*#__PURE__*/_jsx(LinePlot, {
102
- slots: slots,
103
- slotProps: slotProps,
104
- onItemClick: onLineClick,
105
- skipAnimation: skipAnimation
106
- }), /*#__PURE__*/_jsx(ChartsOverlay, {
107
- loading: loading,
108
- slots: slots,
109
- slotProps: slotProps
110
- })]
111
- }), /*#__PURE__*/_jsx(ChartsAxis, {
112
- topAxis: topAxis,
113
- leftAxis: leftAxis,
114
- rightAxis: rightAxis,
115
- bottomAxis: bottomAxis,
116
- slots: slots,
117
- slotProps: slotProps
118
- }), /*#__PURE__*/_jsx(ChartsAxisHighlight, _extends({}, axisHighlight)), /*#__PURE__*/_jsx(MarkPlot, {
119
- slots: slots,
120
- slotProps: slotProps,
121
- onItemClick: onMarkClick,
122
- skipAnimation: skipAnimation
123
- }), /*#__PURE__*/_jsx(LineHighlightPlot, {
124
- slots: slots,
125
- slotProps: slotProps
126
- }), /*#__PURE__*/_jsx(ChartsLegend, _extends({}, legend, {
127
- slots: slots,
128
- slotProps: slotProps
129
- })), !loading && /*#__PURE__*/_jsx(ChartsTooltip, _extends({}, tooltip, {
130
- slots: slots,
131
- slotProps: slotProps
132
- })), /*#__PURE__*/_jsx(ChartsClipPath, {
133
- id: clipPathId
134
- }), children]
135
- });
31
+ chartContainerProps,
32
+ axisClickHandlerProps,
33
+ gridProps,
34
+ clipPathProps,
35
+ clipPathGroupProps,
36
+ areaPlotProps,
37
+ linePlotProps,
38
+ markPlotProps,
39
+ overlayProps,
40
+ chartsAxisProps,
41
+ axisHighlightProps,
42
+ lineHighlightPlotProps,
43
+ legendProps,
44
+ tooltipProps,
45
+ children
46
+ } = useLineChartProps(props);
47
+ return /*#__PURE__*/_jsxs(ResponsiveChartContainer, _extends({
48
+ ref: ref
49
+ }, chartContainerProps, {
50
+ children: [props.onAxisClick && /*#__PURE__*/_jsx(ChartsOnAxisClickHandler, _extends({}, axisClickHandlerProps)), props.grid && /*#__PURE__*/_jsx(ChartsGrid, _extends({}, gridProps)), /*#__PURE__*/_jsxs("g", _extends({}, clipPathGroupProps, {
51
+ children: [/*#__PURE__*/_jsx(AreaPlot, _extends({}, areaPlotProps)), /*#__PURE__*/_jsx(LinePlot, _extends({}, linePlotProps)), /*#__PURE__*/_jsx(ChartsOverlay, _extends({}, overlayProps))]
52
+ })), /*#__PURE__*/_jsx(ChartsAxis, _extends({}, chartsAxisProps)), /*#__PURE__*/_jsx(ChartsAxisHighlight, _extends({}, axisHighlightProps)), /*#__PURE__*/_jsx(MarkPlot, _extends({}, markPlotProps)), /*#__PURE__*/_jsx(LineHighlightPlot, _extends({}, lineHighlightPlotProps)), /*#__PURE__*/_jsx(ChartsLegend, _extends({}, legendProps)), !props.loading && /*#__PURE__*/_jsx(ChartsTooltip, _extends({}, tooltipProps)), /*#__PURE__*/_jsx(ChartsClipPath, _extends({}, clipPathProps)), children]
53
+ }));
136
54
  });
137
55
  process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
138
56
  // ----------------------------- Warning --------------------------------
@@ -3,7 +3,7 @@ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWith
3
3
  const _excluded = ["slots", "slotProps"];
4
4
  import * as React from 'react';
5
5
  import PropTypes from 'prop-types';
6
- import { CartesianContext } from '../context/CartesianContextProvider';
6
+ import { useCartesianContext } from '../context/CartesianProvider';
7
7
  import { LineHighlightElement } from './LineHighlightElement';
8
8
  import { getValueToPositionMapper } from '../hooks/useScale';
9
9
  import { InteractionContext } from '../context/InteractionProvider';
@@ -28,7 +28,7 @@ function LineHighlightPlot(props) {
28
28
  } = props,
29
29
  other = _objectWithoutPropertiesLoose(props, _excluded);
30
30
  const seriesData = useLineSeries();
31
- const axisData = React.useContext(CartesianContext);
31
+ const axisData = useCartesianContext();
32
32
  const {
33
33
  axis
34
34
  } = React.useContext(InteractionContext);
@@ -4,7 +4,7 @@ const _excluded = ["slots", "slotProps", "skipAnimation", "onItemClick"];
4
4
  import * as React from 'react';
5
5
  import PropTypes from 'prop-types';
6
6
  import { line as d3Line } from 'd3-shape';
7
- import { CartesianContext } from '../context/CartesianContextProvider';
7
+ import { useCartesianContext } from '../context/CartesianProvider';
8
8
  import { LineElement } from './LineElement';
9
9
  import { getValueToPositionMapper } from '../hooks/useScale';
10
10
  import getCurveFactory from '../internals/getCurve';
@@ -14,7 +14,7 @@ import { useLineSeries } from '../hooks/useSeries';
14
14
  import { jsx as _jsx } from "react/jsx-runtime";
15
15
  const useAggregatedData = () => {
16
16
  const seriesData = useLineSeries();
17
- const axisData = React.useContext(CartesianContext);
17
+ const axisData = useCartesianContext();
18
18
  if (seriesData === undefined) {
19
19
  return [];
20
20
  }
@@ -3,7 +3,7 @@ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWith
3
3
  const _excluded = ["slots", "slotProps", "skipAnimation", "onItemClick"];
4
4
  import * as React from 'react';
5
5
  import PropTypes from 'prop-types';
6
- import { CartesianContext } from '../context/CartesianContextProvider';
6
+ import { useCartesianContext } from '../context/CartesianProvider';
7
7
  import { MarkElement } from './MarkElement';
8
8
  import { getValueToPositionMapper } from '../hooks/useScale';
9
9
  import { useChartId } from '../hooks/useChartId';
@@ -31,7 +31,7 @@ function MarkPlot(props) {
31
31
  } = props,
32
32
  other = _objectWithoutPropertiesLoose(props, _excluded);
33
33
  const seriesData = useLineSeries();
34
- const axisData = React.useContext(CartesianContext);
34
+ const axisData = useCartesianContext();
35
35
  const chartId = useChartId();
36
36
  const Mark = slots?.mark ?? MarkElement;
37
37
  if (seriesData === undefined) {