@mui/x-charts 7.7.1 → 7.9.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 (136) hide show
  1. package/BarChart/BarChart.d.ts +3 -3
  2. package/BarChart/BarElement.d.ts +225 -228
  3. package/BarChart/BarLabel/BarLabel.d.ts +225 -228
  4. package/BarChart/BarLabel/getBarLabel.d.ts +1 -1
  5. package/BarChart/useBarChartProps.d.ts +20 -88
  6. package/CHANGELOG.md +166 -1
  7. package/ChartContainer/ChartContainer.d.ts +1 -1
  8. package/ChartContainer/ChartContainer.js +3 -1
  9. package/ChartContainer/useChartContainerHooks.d.ts +1 -1
  10. package/ChartsAxisHighlight/ChartsAxisHighlight.js +19 -4
  11. package/ChartsReferenceLine/common.d.ts +0 -1
  12. package/ChartsSurface.js +5 -1
  13. package/ChartsTooltip/ChartsAxisTooltipContent.d.ts +3 -3
  14. package/ChartsTooltip/ChartsAxisTooltipContent.js +4 -39
  15. package/ChartsTooltip/ChartsItemTooltipContent.d.ts +7 -6
  16. package/ChartsTooltip/ChartsItemTooltipContent.js +4 -27
  17. package/ChartsTooltip/ChartsTooltip.d.ts +10 -9
  18. package/ChartsTooltip/ChartsTooltip.js +8 -2
  19. package/ChartsTooltip/ChartsTooltipTable.d.ts +15 -1
  20. package/ChartsTooltip/ChartsTooltipTable.js +19 -0
  21. package/ChartsTooltip/index.d.ts +1 -0
  22. package/ChartsTooltip/index.js +11 -0
  23. package/ChartsTooltip/utils.d.ts +7 -6
  24. package/ChartsTooltip/utils.js +24 -30
  25. package/ChartsVoronoiHandler/ChartsVoronoiHandler.js +6 -6
  26. package/ChartsXAxis/ChartsXAxis.js +7 -5
  27. package/ChartsYAxis/ChartsYAxis.js +3 -1
  28. package/Gauge/GaugeProvider.d.ts +1 -1
  29. package/LineChart/AnimatedArea.d.ts +225 -228
  30. package/LineChart/AnimatedLine.d.ts +225 -228
  31. package/LineChart/LineChart.d.ts +3 -3
  32. package/LineChart/MarkPlot.js +6 -2
  33. package/LineChart/useLineChartProps.d.ts +26 -103
  34. package/LineChart/useLineChartProps.js +3 -3
  35. package/PieChart/PieArc.d.ts +0 -1
  36. package/PieChart/PieArcLabel.d.ts +0 -1
  37. package/PieChart/PieChart.d.ts +3 -3
  38. package/PieChart/dataTransform/transition.d.ts +0 -1
  39. package/ResponsiveChartContainer/ResizableContainer.d.ts +1 -2
  40. package/ResponsiveChartContainer/ResponsiveChartContainer.js +3 -1
  41. package/ScatterChart/Scatter.js +7 -5
  42. package/ScatterChart/ScatterChart.d.ts +3 -3
  43. package/ScatterChart/ScatterChart.js +3 -1
  44. package/ScatterChart/useScatterChartProps.d.ts +20 -75
  45. package/SparkLineChart/SparkLineChart.d.ts +3 -3
  46. package/context/CartesianProvider/computeValue.d.ts +2 -2
  47. package/context/CartesianProvider/computeValue.js +36 -5
  48. package/context/CartesianProvider/normalizeAxis.d.ts +1 -1
  49. package/context/ZAxisContextProvider.js +7 -2
  50. package/esm/BarChart/useBarChartProps.js +0 -1
  51. package/esm/ChartContainer/ChartContainer.js +3 -1
  52. package/esm/ChartsAxisHighlight/ChartsAxisHighlight.js +19 -4
  53. package/esm/ChartsSurface.js +5 -1
  54. package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +3 -38
  55. package/esm/ChartsTooltip/ChartsItemTooltipContent.js +3 -26
  56. package/esm/ChartsTooltip/ChartsTooltip.js +8 -2
  57. package/esm/ChartsTooltip/ChartsTooltipTable.js +20 -0
  58. package/esm/ChartsTooltip/index.js +2 -1
  59. package/esm/ChartsTooltip/utils.js +23 -30
  60. package/esm/ChartsVoronoiHandler/ChartsVoronoiHandler.js +6 -6
  61. package/esm/ChartsXAxis/ChartsXAxis.js +7 -5
  62. package/esm/ChartsYAxis/ChartsYAxis.js +3 -1
  63. package/esm/LineChart/MarkPlot.js +6 -2
  64. package/esm/LineChart/useLineChartProps.js +3 -3
  65. package/esm/ResponsiveChartContainer/ResponsiveChartContainer.js +3 -1
  66. package/esm/ScatterChart/Scatter.js +7 -5
  67. package/esm/ScatterChart/ScatterChart.js +3 -1
  68. package/esm/context/CartesianProvider/computeValue.js +37 -6
  69. package/esm/context/ZAxisContextProvider.js +7 -2
  70. package/esm/hooks/index.js +1 -0
  71. package/esm/hooks/useAxis.js +17 -0
  72. package/esm/hooks/useAxisEvents.js +25 -17
  73. package/esm/hooks/useInteractionItemProps.js +11 -4
  74. package/esm/hooks/useScale.js +7 -14
  75. package/esm/hooks/useTicks.js +2 -1
  76. package/esm/internals/getSVGPoint.js +11 -0
  77. package/esm/internals/index.js +4 -0
  78. package/esm/internals/utils.js +0 -12
  79. package/hooks/index.d.ts +1 -0
  80. package/hooks/index.js +12 -0
  81. package/hooks/useAxis.d.ts +2 -0
  82. package/hooks/useAxis.js +24 -0
  83. package/hooks/useAxisEvents.js +25 -17
  84. package/hooks/useChartDimensions.d.ts +1 -1
  85. package/hooks/useColor.d.ts +1 -1
  86. package/hooks/useInteractionItemProps.d.ts +4 -2
  87. package/hooks/useInteractionItemProps.js +11 -4
  88. package/hooks/useScale.js +6 -14
  89. package/hooks/useTicks.js +2 -1
  90. package/index.js +1 -1
  91. package/internals/components/AxisSharedComponents.d.ts +0 -1
  92. package/internals/components/ChartsAxesGradients/ChartsAxesGradients.d.ts +1 -1
  93. package/internals/defaultizeColor.d.ts +68 -68
  94. package/internals/getSVGPoint.d.ts +6 -0
  95. package/internals/getSVGPoint.js +17 -0
  96. package/internals/getWordsByLines.d.ts +0 -1
  97. package/internals/index.d.ts +4 -0
  98. package/internals/index.js +40 -0
  99. package/internals/useAnimatedPath.d.ts +0 -1
  100. package/internals/utils.d.ts +0 -6
  101. package/internals/utils.js +0 -13
  102. package/models/axis.d.ts +1 -2
  103. package/models/colorMapping.d.ts +1 -1
  104. package/models/z-axis.d.ts +8 -0
  105. package/modern/BarChart/useBarChartProps.js +0 -1
  106. package/modern/ChartContainer/ChartContainer.js +3 -1
  107. package/modern/ChartsAxisHighlight/ChartsAxisHighlight.js +19 -4
  108. package/modern/ChartsSurface.js +5 -1
  109. package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +3 -38
  110. package/modern/ChartsTooltip/ChartsItemTooltipContent.js +3 -26
  111. package/modern/ChartsTooltip/ChartsTooltip.js +8 -2
  112. package/modern/ChartsTooltip/ChartsTooltipTable.js +20 -0
  113. package/modern/ChartsTooltip/index.js +2 -1
  114. package/modern/ChartsTooltip/utils.js +23 -30
  115. package/modern/ChartsVoronoiHandler/ChartsVoronoiHandler.js +6 -6
  116. package/modern/ChartsXAxis/ChartsXAxis.js +7 -5
  117. package/modern/ChartsYAxis/ChartsYAxis.js +3 -1
  118. package/modern/LineChart/MarkPlot.js +6 -2
  119. package/modern/LineChart/useLineChartProps.js +3 -3
  120. package/modern/ResponsiveChartContainer/ResponsiveChartContainer.js +3 -1
  121. package/modern/ScatterChart/Scatter.js +7 -5
  122. package/modern/ScatterChart/ScatterChart.js +3 -1
  123. package/modern/context/CartesianProvider/computeValue.js +37 -6
  124. package/modern/context/ZAxisContextProvider.js +7 -2
  125. package/modern/hooks/index.js +1 -0
  126. package/modern/hooks/useAxis.js +17 -0
  127. package/modern/hooks/useAxisEvents.js +25 -17
  128. package/modern/hooks/useInteractionItemProps.js +11 -4
  129. package/modern/hooks/useScale.js +7 -14
  130. package/modern/hooks/useTicks.js +2 -1
  131. package/modern/index.js +1 -1
  132. package/modern/internals/getSVGPoint.js +11 -0
  133. package/modern/internals/index.js +4 -0
  134. package/modern/internals/utils.js +0 -12
  135. package/package.json +3 -3
  136. package/themeAugmentation/props.d.ts +2 -1
@@ -1,7 +1,6 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import useId from '@mui/utils/useId';
3
3
  import { DEFAULT_X_AXIS_KEY, DEFAULT_Y_AXIS_KEY } from '../constants';
4
-
5
4
  /**
6
5
  * A helper function that extracts BarChartProps from the input props
7
6
  * and returns an object with props for the children components of BarChart.
@@ -283,7 +283,9 @@ process.env.NODE_ENV !== "production" ? ChartContainer.propTypes = {
283
283
  })]),
284
284
  data: PropTypes.array,
285
285
  dataKey: PropTypes.string,
286
- id: PropTypes.string
286
+ id: PropTypes.string,
287
+ max: PropTypes.number,
288
+ min: PropTypes.number
287
289
  }))
288
290
  } : void 0;
289
291
  export { ChartContainer };
@@ -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'
@@ -9,7 +9,11 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
9
9
  const ChartChartsSurfaceStyles = styled('svg', {
10
10
  name: 'MuiChartsSurface',
11
11
  slot: 'Root'
12
- })(() => ({}));
12
+ })(() => ({
13
+ // This prevents default touch actions when using the svg on mobile devices.
14
+ // For example, prevent page scroll & zoom.
15
+ touchAction: 'none'
16
+ }));
13
17
  const ChartsSurface = /*#__PURE__*/React.forwardRef(function ChartsSurface(props, ref) {
14
18
  const {
15
19
  children,
@@ -1,6 +1,5 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import * as React from 'react';
3
- import PropTypes from 'prop-types';
4
3
  import { useSlotProps } from '@mui/base/utils';
5
4
  import { useCartesianContext } from '../context/CartesianProvider';
6
5
  import { DefaultChartsAxisTooltipContent } from './DefaultChartsAxisTooltipContent';
@@ -9,6 +8,9 @@ import { useColorProcessor } from '../hooks/useColor';
9
8
  import { isCartesianSeriesType } from '../internals/isCartesian';
10
9
  import { useSeries } from '../hooks/useSeries';
11
10
  import { jsx as _jsx } from "react/jsx-runtime";
11
+ /**
12
+ * @ignore - internal component.
13
+ */
12
14
  function ChartsAxisTooltipContent(props) {
13
15
  const {
14
16
  content,
@@ -71,41 +73,4 @@ function ChartsAxisTooltipContent(props) {
71
73
  });
72
74
  return /*#__PURE__*/_jsx(Content, _extends({}, chartTooltipContentProps));
73
75
  }
74
- process.env.NODE_ENV !== "production" ? ChartsAxisTooltipContent.propTypes = {
75
- // ----------------------------- Warning --------------------------------
76
- // | These PropTypes are generated from the TypeScript type definitions |
77
- // | To update them edit the TypeScript types and run "pnpm proptypes" |
78
- // ----------------------------------------------------------------------
79
- axisData: PropTypes.shape({
80
- x: PropTypes.shape({
81
- index: PropTypes.number,
82
- value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired
83
- }),
84
- y: PropTypes.shape({
85
- index: PropTypes.number,
86
- value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired
87
- })
88
- }).isRequired,
89
- classes: PropTypes.object.isRequired,
90
- content: PropTypes.elementType,
91
- contentProps: PropTypes.shape({
92
- axis: PropTypes.object,
93
- axisData: PropTypes.shape({
94
- x: PropTypes.shape({
95
- index: PropTypes.number,
96
- value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired
97
- }),
98
- y: PropTypes.shape({
99
- index: PropTypes.number,
100
- value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired
101
- })
102
- }),
103
- axisValue: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]),
104
- classes: PropTypes.object,
105
- dataIndex: PropTypes.number,
106
- series: PropTypes.arrayOf(PropTypes.object),
107
- sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
108
- }),
109
- sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
110
- } : void 0;
111
76
  export { ChartsAxisTooltipContent };
@@ -1,6 +1,5 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import * as React from 'react';
3
- import PropTypes from 'prop-types';
4
3
  import { useSlotProps } from '@mui/base/utils';
5
4
  import { DefaultChartsItemTooltipContent } from './DefaultChartsItemTooltipContent';
6
5
  import { useCartesianContext } from '../context/CartesianProvider';
@@ -8,6 +7,9 @@ import { ZAxisContext } from '../context/ZAxisContextProvider';
8
7
  import { useColorProcessor } from '../hooks/useColor';
9
8
  import { useSeries } from '../hooks/useSeries';
10
9
  import { jsx as _jsx } from "react/jsx-runtime";
10
+ /**
11
+ * @ignore - internal component.
12
+ */
11
13
  function ChartsItemTooltipContent(props) {
12
14
  const {
13
15
  content,
@@ -47,29 +49,4 @@ function ChartsItemTooltipContent(props) {
47
49
  });
48
50
  return /*#__PURE__*/_jsx(Content, _extends({}, chartTooltipContentProps));
49
51
  }
50
- process.env.NODE_ENV !== "production" ? ChartsItemTooltipContent.propTypes = {
51
- // ----------------------------- Warning --------------------------------
52
- // | These PropTypes are generated from the TypeScript type definitions |
53
- // | To update them edit the TypeScript types and run "pnpm proptypes" |
54
- // ----------------------------------------------------------------------
55
- classes: PropTypes.object.isRequired,
56
- content: PropTypes.elementType,
57
- contentProps: PropTypes.shape({
58
- classes: PropTypes.object,
59
- getColor: PropTypes.func,
60
- itemData: PropTypes.shape({
61
- dataIndex: PropTypes.number,
62
- seriesId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
63
- type: PropTypes.oneOf(['bar', 'line', 'pie', 'scatter']).isRequired
64
- }),
65
- series: PropTypes.object,
66
- sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
67
- }),
68
- itemData: PropTypes.shape({
69
- dataIndex: PropTypes.number,
70
- seriesId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
71
- type: PropTypes.oneOf(['bar', 'line', 'pie', 'scatter']).isRequired
72
- }).isRequired,
73
- sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
74
- } : void 0;
75
52
  export { ChartsItemTooltipContent };
@@ -77,8 +77,14 @@ function ChartsTooltip(props) {
77
77
  externalSlotProps: slotProps?.popper,
78
78
  additionalProps: {
79
79
  open: popperOpen,
80
- placement: 'right-start',
81
- anchorEl: generateVirtualElement(mousePosition)
80
+ placement: mousePosition?.pointerType === 'mouse' ? 'right-start' : 'top',
81
+ anchorEl: generateVirtualElement(mousePosition),
82
+ modifiers: [{
83
+ name: 'offset',
84
+ options: {
85
+ offset: [0, mousePosition?.pointerType === 'touch' ? 40 - mousePosition.height : 0]
86
+ }
87
+ }]
82
88
  },
83
89
  ownerState: {}
84
90
  });
@@ -1,6 +1,10 @@
1
1
  import { styled } from '@mui/material/styles';
2
2
  import { shouldForwardProp } from '@mui/system';
3
3
  import { chartsTooltipClasses } from './chartsTooltipClasses';
4
+
5
+ /**
6
+ * @ignore - internal component.
7
+ */
4
8
  export const ChartsTooltipPaper = styled('div', {
5
9
  name: 'MuiChartsTooltip',
6
10
  slot: 'Container'
@@ -13,6 +17,10 @@ export const ChartsTooltipPaper = styled('div', {
13
17
  transition: theme.transitions.create('box-shadow'),
14
18
  borderRadius: theme.shape.borderRadius
15
19
  }));
20
+
21
+ /**
22
+ * @ignore - internal component.
23
+ */
16
24
  export const ChartsTooltipTable = styled('table', {
17
25
  name: 'MuiChartsTooltip',
18
26
  slot: 'Table'
@@ -24,6 +32,10 @@ export const ChartsTooltipTable = styled('table', {
24
32
  borderBottom: `solid ${(theme.vars || theme).palette.divider} 1px`
25
33
  }
26
34
  }));
35
+
36
+ /**
37
+ * @ignore - internal component.
38
+ */
27
39
  export const ChartsTooltipRow = styled('tr', {
28
40
  name: 'MuiChartsTooltip',
29
41
  slot: 'Row'
@@ -37,6 +49,10 @@ export const ChartsTooltipRow = styled('tr', {
37
49
  paddingBottom: theme.spacing(1)
38
50
  }
39
51
  }));
52
+
53
+ /**
54
+ * @ignore - internal component.
55
+ */
40
56
  export const ChartsTooltipCell = styled('td', {
41
57
  name: 'MuiChartsTooltip',
42
58
  slot: 'Cell'
@@ -59,6 +75,10 @@ export const ChartsTooltipCell = styled('td', {
59
75
  paddingRight: theme.spacing(2)
60
76
  }
61
77
  }));
78
+
79
+ /**
80
+ * @ignore - internal component.
81
+ */
62
82
  export const ChartsTooltipMark = styled('div', {
63
83
  name: 'MuiChartsTooltip',
64
84
  slot: 'Mark',
@@ -3,4 +3,5 @@ export * from './chartsTooltipClasses';
3
3
  export * from './ChartsAxisTooltipContent';
4
4
  export * from './ChartsItemTooltipContent';
5
5
  export * from './DefaultChartsAxisTooltipContent';
6
- export * from './DefaultChartsItemTooltipContent';
6
+ export * from './DefaultChartsItemTooltipContent';
7
+ export * from './ChartsTooltipTable';
@@ -1,3 +1,4 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
1
2
  import * as React from 'react';
2
3
  import { useSvgRef } from '../hooks';
3
4
  export function generateVirtualElement(mousePosition) {
@@ -20,26 +21,19 @@ export function generateVirtualElement(mousePosition) {
20
21
  x,
21
22
  y
22
23
  } = mousePosition;
24
+ const boundingBox = {
25
+ width: 0,
26
+ height: 0,
27
+ x,
28
+ y,
29
+ top: y,
30
+ right: x,
31
+ bottom: y,
32
+ left: x
33
+ };
23
34
  return {
24
- getBoundingClientRect: () => ({
25
- width: 0,
26
- height: 0,
27
- x,
28
- y,
29
- top: y,
30
- right: x,
31
- bottom: y,
32
- left: x,
33
- toJSON: () => JSON.stringify({
34
- width: 0,
35
- height: 0,
36
- x,
37
- y,
38
- top: y,
39
- right: x,
40
- bottom: y,
41
- left: x
42
- })
35
+ getBoundingClientRect: () => _extends({}, boundingBox, {
36
+ toJSON: () => JSON.stringify(boundingBox)
43
37
  })
44
38
  };
45
39
  }
@@ -57,21 +51,20 @@ export function useMouseTracker() {
57
51
  setMousePosition(null);
58
52
  };
59
53
  const handleMove = event => {
60
- const target = 'targetTouches' in event ? event.targetTouches[0] : event;
61
54
  setMousePosition({
62
- x: target.clientX,
63
- y: target.clientY
55
+ x: event.clientX,
56
+ y: event.clientY,
57
+ height: event.height,
58
+ pointerType: event.pointerType
64
59
  });
65
60
  };
66
- element.addEventListener('mouseout', handleOut);
67
- element.addEventListener('mousemove', handleMove);
68
- element.addEventListener('touchend', handleOut);
69
- element.addEventListener('touchmove', handleMove);
61
+ element.addEventListener('pointerdown', handleMove);
62
+ element.addEventListener('pointermove', handleMove);
63
+ element.addEventListener('pointerup', handleOut);
70
64
  return () => {
71
- element.removeEventListener('mouseout', handleOut);
72
- element.removeEventListener('mousemove', handleMove);
73
- element.addEventListener('touchend', handleOut);
74
- element.addEventListener('touchmove', handleMove);
65
+ element.removeEventListener('pointerdown', handleMove);
66
+ element.removeEventListener('pointermove', handleMove);
67
+ element.removeEventListener('pointerup', handleOut);
75
68
  };
76
69
  }, [svgRef]);
77
70
  return mousePosition;
@@ -5,7 +5,7 @@ import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
5
5
  import { InteractionContext } from '../context/InteractionProvider';
6
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';
@@ -96,7 +96,7 @@ function ChartsVoronoiHandler(props) {
96
96
  // TODO: A perf optimisation of voronoi could be to use the last point as the initial point for the next search.
97
97
  function getClosestPoint(event) {
98
98
  // Get mouse coordinate in global SVG space
99
- const svgPoint = getSVGPoint(svgRef.current, event);
99
+ const svgPoint = getSVGPoint(element, event);
100
100
  const outsideX = svgPoint.x < left || svgPoint.x > left + width;
101
101
  const outsideY = svgPoint.y < top || svgPoint.y > top + height;
102
102
  if (outsideX || outsideY) {
@@ -191,12 +191,12 @@ function ChartsVoronoiHandler(props) {
191
191
  dataIndex
192
192
  });
193
193
  };
194
- element.addEventListener('mouseout', handleMouseOut);
195
- element.addEventListener('mousemove', handleMouseMove);
194
+ element.addEventListener('pointerout', handleMouseOut);
195
+ element.addEventListener('pointermove', handleMouseMove);
196
196
  element.addEventListener('click', handleMouseClick);
197
197
  return () => {
198
- element.removeEventListener('mouseout', handleMouseOut);
199
- element.removeEventListener('mousemove', handleMouseMove);
198
+ element.removeEventListener('pointerout', handleMouseOut);
199
+ element.removeEventListener('pointermove', handleMouseMove);
200
200
  element.removeEventListener('click', handleMouseClick);
201
201
  };
202
202
  }, [svgRef, dispatch, left, width, top, height, yAxis, xAxis, voronoiMaxRadius, onItemClick, setHighlighted, clearHighlighted]);
@@ -209,10 +209,10 @@ function ChartsXAxis(inProps) {
209
209
  transform: `translate(0, ${position === 'bottom' ? top + height : top})`,
210
210
  className: classes.root,
211
211
  children: [!disableLine && /*#__PURE__*/_jsx(Line, _extends({
212
- x1: xScale.range()[0],
213
- x2: xScale.range()[1],
212
+ x1: left,
213
+ x2: left + width,
214
214
  className: classes.line
215
- }, slotProps?.axisLine)), xTicksWithDimension.map(({
215
+ }, slotProps?.axisLine)), xTicksWithDimension.filter(tick => tick.offset >= left - 1 && tick.offset <= left + width + 1).map(({
216
216
  formattedValue,
217
217
  offset,
218
218
  labelOffset,
@@ -220,13 +220,15 @@ function ChartsXAxis(inProps) {
220
220
  }, index) => {
221
221
  const xTickLabel = labelOffset ?? 0;
222
222
  const yTickLabel = positionSign * (tickSize + 3);
223
+ const showTick = offset >= left - 1 && offset <= left + width + 1;
224
+ const showTickLabel = offset + xTickLabel >= left - 1 && offset + xTickLabel <= left + width + 1;
223
225
  return /*#__PURE__*/_jsxs("g", {
224
226
  transform: `translate(${offset}, 0)`,
225
227
  className: classes.tickContainer,
226
- children: [!disableTicks && /*#__PURE__*/_jsx(Tick, _extends({
228
+ children: [!disableTicks && showTick && /*#__PURE__*/_jsx(Tick, _extends({
227
229
  y2: positionSign * tickSize,
228
230
  className: classes.tick
229
- }, slotProps?.axisTick)), formattedValue !== undefined && !skipLabel && /*#__PURE__*/_jsx(TickLabel, _extends({
231
+ }, slotProps?.axisTick)), formattedValue !== undefined && !skipLabel && showTickLabel && /*#__PURE__*/_jsx(TickLabel, _extends({
230
232
  x: xTickLabel,
231
233
  y: yTickLabel
232
234
  }, axisTickLabelProps, {
@@ -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
  },
@@ -11,6 +11,7 @@ import { DEFAULT_X_AXIS_KEY } from '../constants';
11
11
  import { cleanId } from '../internals/utils';
12
12
  import getColor from './getColor';
13
13
  import { useLineSeries } from '../hooks/useSeries';
14
+ import { useDrawingArea } from '../hooks/useDrawingArea';
14
15
  import { jsx as _jsx } from "react/jsx-runtime";
15
16
  /**
16
17
  * Demos:
@@ -33,6 +34,10 @@ function MarkPlot(props) {
33
34
  const seriesData = useLineSeries();
34
35
  const axisData = useCartesianContext();
35
36
  const chartId = useChartId();
37
+ const {
38
+ left,
39
+ width
40
+ } = useDrawingArea();
36
41
  const Mark = slots?.mark ?? MarkElement;
37
42
  if (seriesData === undefined) {
38
43
  return null;
@@ -67,13 +72,12 @@ function MarkPlot(props) {
67
72
  const xScale = getValueToPositionMapper(xAxis[xAxisKey].scale);
68
73
  const yScale = yAxis[yAxisKey].scale;
69
74
  const xData = xAxis[xAxisKey].data;
70
- const xRange = xAxis[xAxisKey].scale.range();
71
75
  const yRange = yScale.range();
72
76
  const isInRange = ({
73
77
  x,
74
78
  y
75
79
  }) => {
76
- if (x < Math.min(...xRange) || x > Math.max(...xRange)) {
80
+ if (x < left || x > left + width) {
77
81
  return false;
78
82
  }
79
83
  if (y < Math.min(...yRange) || y > Math.max(...yRange)) {
@@ -81,19 +81,19 @@ export const useLineChartProps = props => {
81
81
  const areaPlotProps = {
82
82
  slots,
83
83
  slotProps,
84
- onAreaClick,
84
+ onItemClick: onAreaClick,
85
85
  skipAnimation
86
86
  };
87
87
  const linePlotProps = {
88
88
  slots,
89
89
  slotProps,
90
- onLineClick,
90
+ onItemClick: onLineClick,
91
91
  skipAnimation
92
92
  };
93
93
  const markPlotProps = {
94
94
  slots,
95
95
  slotProps,
96
- onMarkClick,
96
+ onItemClick: onMarkClick,
97
97
  skipAnimation
98
98
  };
99
99
  const overlayProps = {
@@ -229,7 +229,9 @@ process.env.NODE_ENV !== "production" ? ResponsiveChartContainer.propTypes = {
229
229
  })]),
230
230
  data: PropTypes.array,
231
231
  dataKey: PropTypes.string,
232
- id: PropTypes.string
232
+ id: PropTypes.string,
233
+ max: PropTypes.number,
234
+ min: PropTypes.number
233
235
  }))
234
236
  } : void 0;
235
237
  export { ResponsiveChartContainer };
@@ -5,6 +5,7 @@ import { getValueToPositionMapper } from '../hooks/useScale';
5
5
  import { useInteractionItemProps } from '../hooks/useInteractionItemProps';
6
6
  import { InteractionContext } from '../context/InteractionProvider';
7
7
  import { useHighlighted } from '../context';
8
+ import { useDrawingArea } from '../hooks/useDrawingArea';
8
9
  import { jsx as _jsx } from "react/jsx-runtime";
9
10
  /**
10
11
  * Demos:
@@ -26,6 +27,10 @@ function Scatter(props) {
26
27
  markerSize,
27
28
  onItemClick
28
29
  } = props;
30
+ const {
31
+ left,
32
+ width
33
+ } = useDrawingArea();
29
34
  const {
30
35
  useVoronoiInteraction
31
36
  } = React.useContext(InteractionContext);
@@ -38,10 +43,7 @@ function Scatter(props) {
38
43
  const cleanData = React.useMemo(() => {
39
44
  const getXPosition = getValueToPositionMapper(xScale);
40
45
  const getYPosition = getValueToPositionMapper(yScale);
41
- const xRange = xScale.range();
42
46
  const yRange = yScale.range();
43
- const minXRange = Math.min(...xRange);
44
- const maxXRange = Math.max(...xRange);
45
47
  const minYRange = Math.min(...yRange);
46
48
  const maxYRange = Math.max(...yRange);
47
49
  const temp = [];
@@ -49,7 +51,7 @@ function Scatter(props) {
49
51
  const scatterPoint = series.data[i];
50
52
  const x = getXPosition(scatterPoint.x);
51
53
  const y = getYPosition(scatterPoint.y);
52
- const isInRange = x >= minXRange && x <= maxXRange && y >= minYRange && y <= maxYRange;
54
+ const isInRange = x >= left && x <= left + width && y >= minYRange && y <= maxYRange;
53
55
  const pointCtx = {
54
56
  type: 'scatter',
55
57
  seriesId: series.id,
@@ -74,7 +76,7 @@ function Scatter(props) {
74
76
  }
75
77
  }
76
78
  return temp;
77
- }, [xScale, yScale, series.data, series.id, getInteractionItemProps, color, colorGetter, isFaded, isHighlighted]);
79
+ }, [xScale, yScale, left, width, series.data, series.id, isHighlighted, isFaded, getInteractionItemProps, colorGetter, color]);
78
80
  return /*#__PURE__*/_jsx("g", {
79
81
  children: cleanData.map(dataPoint => /*#__PURE__*/_jsx("circle", _extends({
80
82
  cx: 0,
@@ -339,7 +339,9 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
339
339
  })]),
340
340
  data: PropTypes.array,
341
341
  dataKey: PropTypes.string,
342
- id: PropTypes.string
342
+ id: PropTypes.string,
343
+ max: PropTypes.number,
344
+ min: PropTypes.number
343
345
  }))
344
346
  } : void 0;
345
347
  export { ScatterChart };
@@ -1,5 +1,5 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
- import { scaleBand, scalePoint } from 'd3-scale';
2
+ import { scaleBand, scalePoint, scaleTime } from 'd3-scale';
3
3
  import { DEFAULT_X_AXIS_KEY, DEFAULT_Y_AXIS_KEY } from '../../constants';
4
4
  import { isBandScaleConfig, isPointScaleConfig } from '../../models/axis';
5
5
  import { getColorScale, getOrdinalColorScale } from '../../internals/colorScale';
@@ -10,9 +10,26 @@ const getRange = (drawingArea, axisName, isReverse) => {
10
10
  const range = axisName === 'x' ? [drawingArea.left, drawingArea.left + drawingArea.width] : [drawingArea.top + drawingArea.height, drawingArea.top];
11
11
  return isReverse ? range.reverse() : range;
12
12
  };
13
+ const zoomedScaleRange = (scaleRange, zoomRange) => {
14
+ const rangeGap = scaleRange[1] - scaleRange[0];
15
+ const zoomGap = zoomRange[1] - zoomRange[0];
16
+
17
+ // If current zoom show the scale between p1 and p2 percents
18
+ // The range should be extended by adding [0, p1] and [p2, 100] segments
19
+ const min = scaleRange[0] - zoomRange[0] * rangeGap / zoomGap;
20
+ const max = scaleRange[1] + (100 - zoomRange[1]) * rangeGap / zoomGap;
21
+ return [min, max];
22
+ };
23
+ const isDateData = data => data?.[0] instanceof Date;
24
+ function createDateFormatter(axis, range) {
25
+ const timeScale = scaleTime(axis.data, range);
26
+ return (v, {
27
+ location
28
+ }) => location === 'tick' ? timeScale.tickFormat(axis.tickNumber)(v) : `${v.toLocaleString()}`;
29
+ }
13
30
  const DEFAULT_CATEGORY_GAP_RATIO = 0.2;
14
31
  const DEFAULT_BAR_GAP_RATIO = 0.1;
15
- export function computeValue(drawingArea, formattedSeries, inAxis, extremumGetters, axisName) {
32
+ export function computeValue(drawingArea, formattedSeries, inAxis, extremumGetters, axisName, zoomRange = [0, 100]) {
16
33
  const DEFAULT_AXIS_KEY = axisName === 'x' ? DEFAULT_X_AXIS_KEY : DEFAULT_Y_AXIS_KEY;
17
34
  const allAxis = [...(inAxis?.map((axis, index) => _extends({
18
35
  id: `defaultized-${axisName}-axis-${index}`
@@ -32,26 +49,36 @@ export function computeValue(drawingArea, formattedSeries, inAxis, extremumGette
32
49
  const barGapRatio = axis.barGapRatio ?? DEFAULT_BAR_GAP_RATIO;
33
50
  // Reverse range because ordinal scales are presented from top to bottom on y-axis
34
51
  const scaleRange = axisName === 'x' ? range : [range[1], range[0]];
52
+ const zoomedRange = zoomedScaleRange(scaleRange, zoomRange);
35
53
  completeAxis[axis.id] = _extends({
36
54
  categoryGapRatio,
37
55
  barGapRatio
38
56
  }, axis, {
39
- scale: scaleBand(axis.data, scaleRange).paddingInner(categoryGapRatio).paddingOuter(categoryGapRatio / 2),
57
+ scale: scaleBand(axis.data, zoomedRange).paddingInner(categoryGapRatio).paddingOuter(categoryGapRatio / 2),
40
58
  tickNumber: axis.data.length,
41
59
  colorScale: axis.colorMap && (axis.colorMap.type === 'ordinal' ? getOrdinalColorScale(_extends({
42
60
  values: axis.data
43
61
  }, axis.colorMap)) : getColorScale(axis.colorMap))
44
62
  });
63
+ if (isDateData(axis.data)) {
64
+ const dateFormatter = createDateFormatter(axis, scaleRange);
65
+ completeAxis[axis.id].valueFormatter = axis.valueFormatter ?? dateFormatter;
66
+ }
45
67
  }
46
68
  if (isPointScaleConfig(axis)) {
47
69
  const scaleRange = axisName === 'x' ? range : [...range].reverse();
70
+ const zoomedRange = zoomedScaleRange(scaleRange, zoomRange);
48
71
  completeAxis[axis.id] = _extends({}, axis, {
49
- scale: scalePoint(axis.data, scaleRange),
72
+ scale: scalePoint(axis.data, zoomedRange),
50
73
  tickNumber: axis.data.length,
51
74
  colorScale: axis.colorMap && (axis.colorMap.type === 'ordinal' ? getOrdinalColorScale(_extends({
52
75
  values: axis.data
53
76
  }, axis.colorMap)) : getColorScale(axis.colorMap))
54
77
  });
78
+ if (isDateData(axis.data)) {
79
+ const dateFormatter = createDateFormatter(axis, scaleRange);
80
+ completeAxis[axis.id].valueFormatter = axis.valueFormatter ?? dateFormatter;
81
+ }
55
82
  }
56
83
  if (axis.scaleType === 'band' || axis.scaleType === 'point') {
57
84
  // Could be merged with the two previous "if conditions" but then TS does not get that `axis.scaleType` can't be `band` or `point`.
@@ -59,11 +86,15 @@ export function computeValue(drawingArea, formattedSeries, inAxis, extremumGette
59
86
  }
60
87
  const scaleType = axis.scaleType ?? 'linear';
61
88
  const extremums = [axis.min ?? minData, axis.max ?? maxData];
62
- const tickNumber = getTickNumber(_extends({}, axis, {
89
+ const rawTickNumber = getTickNumber(_extends({}, axis, {
63
90
  range,
64
91
  domain: extremums
65
92
  }));
66
- const scale = getScale(scaleType, extremums, range).nice(tickNumber);
93
+ const tickNumber = rawTickNumber / ((zoomRange[1] - zoomRange[0]) / 100);
94
+ const zoomedRange = zoomedScaleRange(range, zoomRange);
95
+
96
+ // TODO: move nice to prop? Disable when there is zoom?
97
+ const scale = getScale(scaleType, extremums, zoomedRange).nice(rawTickNumber);
67
98
  const [minDomain, maxDomain] = scale.domain();
68
99
  const domain = [axis.min ?? minDomain, axis.max ?? maxDomain];
69
100
  completeAxis[axis.id] = _extends({}, axis, {