@mui/x-charts 7.0.0-alpha.2 → 7.0.0-alpha.4

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 (142) hide show
  1. package/BarChart/BarElement.d.ts +5 -1
  2. package/BarChart/BarElement.js +24 -1
  3. package/BarChart/index.d.ts +2 -1
  4. package/BarChart/index.js +15 -4
  5. package/CHANGELOG.md +364 -0
  6. package/ChartsLegend/index.d.ts +1 -0
  7. package/ChartsLegend/index.js +11 -0
  8. package/ChartsTooltip/ChartsAxisTooltipContent.d.ts +5 -2
  9. package/ChartsTooltip/ChartsAxisTooltipContent.js +93 -73
  10. package/ChartsTooltip/ChartsItemTooltipContent.d.ts +5 -2
  11. package/ChartsTooltip/ChartsItemTooltipContent.js +38 -57
  12. package/ChartsTooltip/DefaultChartsAxisTooltipContent.d.ts +7 -0
  13. package/ChartsTooltip/DefaultChartsAxisTooltipContent.js +174 -0
  14. package/ChartsTooltip/DefaultChartsItemTooltipContent.d.ts +8 -0
  15. package/ChartsTooltip/DefaultChartsItemTooltipContent.js +99 -0
  16. package/ChartsTooltip/index.d.ts +4 -0
  17. package/ChartsTooltip/index.js +44 -0
  18. package/ChartsVoronoiHandler/ChartsVoronoiHandler.d.ts +14 -0
  19. package/ChartsVoronoiHandler/ChartsVoronoiHandler.js +174 -0
  20. package/ChartsVoronoiHandler/index.d.ts +1 -0
  21. package/ChartsVoronoiHandler/index.js +16 -0
  22. package/ChartsVoronoiHandler/package.json +6 -0
  23. package/ChartsYAxis/ChartsYAxis.js +6 -4
  24. package/LineChart/extremums.js +25 -8
  25. package/LineChart/index.d.ts +1 -1
  26. package/LineChart/index.js +11 -11
  27. package/PieChart/PieArc.d.ts +5 -2
  28. package/PieChart/PieArc.js +17 -2
  29. package/PieChart/PieArcLabel.d.ts +1 -1
  30. package/PieChart/PieArcLabel.js +5 -10
  31. package/PieChart/PieArcLabelPlot.d.ts +5 -1
  32. package/PieChart/PieArcLabelPlot.js +91 -3
  33. package/PieChart/PieArcPlot.d.ts +5 -1
  34. package/PieChart/PieArcPlot.js +90 -3
  35. package/PieChart/index.d.ts +3 -1
  36. package/PieChart/index.js +26 -4
  37. package/README.md +0 -1
  38. package/ScatterChart/Scatter.js +15 -6
  39. package/ScatterChart/ScatterChart.d.ts +7 -1
  40. package/ScatterChart/ScatterChart.js +18 -1
  41. package/ScatterChart/index.d.ts +1 -1
  42. package/ScatterChart/index.js +8 -8
  43. package/SparkLineChart/SparkLineChart.js +1 -0
  44. package/context/InteractionProvider.d.ts +10 -0
  45. package/context/InteractionProvider.js +21 -1
  46. package/esm/BarChart/BarElement.js +26 -2
  47. package/esm/BarChart/index.js +2 -1
  48. package/esm/ChartsLegend/index.js +2 -1
  49. package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +95 -75
  50. package/esm/ChartsTooltip/ChartsItemTooltipContent.js +40 -58
  51. package/esm/ChartsTooltip/DefaultChartsAxisTooltipContent.js +168 -0
  52. package/esm/ChartsTooltip/DefaultChartsItemTooltipContent.js +92 -0
  53. package/esm/ChartsTooltip/index.js +5 -1
  54. package/esm/ChartsVoronoiHandler/ChartsVoronoiHandler.js +168 -0
  55. package/esm/ChartsVoronoiHandler/index.js +1 -0
  56. package/esm/ChartsYAxis/ChartsYAxis.js +6 -4
  57. package/esm/LineChart/extremums.js +25 -8
  58. package/esm/LineChart/index.js +1 -1
  59. package/esm/PieChart/PieArc.js +18 -2
  60. package/esm/PieChart/PieArcLabel.js +7 -11
  61. package/esm/PieChart/PieArcLabelPlot.js +92 -3
  62. package/esm/PieChart/PieArcPlot.js +91 -3
  63. package/esm/PieChart/index.js +3 -1
  64. package/esm/ScatterChart/Scatter.js +15 -6
  65. package/esm/ScatterChart/ScatterChart.js +18 -1
  66. package/esm/ScatterChart/index.js +1 -1
  67. package/esm/SparkLineChart/SparkLineChart.js +1 -0
  68. package/esm/context/InteractionProvider.js +21 -1
  69. package/esm/hooks/useAxisEvents.js +20 -27
  70. package/esm/hooks/useInteractionItemProps.js +4 -1
  71. package/esm/index.js +1 -0
  72. package/esm/internals/defaultizeValueFormatter.js +4 -3
  73. package/esm/internals/utils.js +11 -0
  74. package/hooks/useAxisEvents.js +20 -27
  75. package/hooks/useInteractionItemProps.d.ts +2 -2
  76. package/hooks/useInteractionItemProps.js +4 -1
  77. package/index.d.ts +1 -0
  78. package/index.js +12 -1
  79. package/internals/defaultizeColor.d.ts +1 -0
  80. package/internals/defaultizeValueFormatter.d.ts +3 -1
  81. package/internals/defaultizeValueFormatter.js +3 -3
  82. package/internals/utils.d.ts +6 -0
  83. package/internals/utils.js +12 -0
  84. package/legacy/BarChart/BarElement.js +26 -2
  85. package/legacy/BarChart/index.js +2 -1
  86. package/legacy/ChartsLegend/index.js +2 -1
  87. package/legacy/ChartsTooltip/ChartsAxisTooltipContent.js +95 -74
  88. package/legacy/ChartsTooltip/ChartsItemTooltipContent.js +40 -55
  89. package/legacy/ChartsTooltip/DefaultChartsAxisTooltipContent.js +167 -0
  90. package/legacy/ChartsTooltip/DefaultChartsItemTooltipContent.js +89 -0
  91. package/legacy/ChartsTooltip/index.js +5 -1
  92. package/legacy/ChartsVoronoiHandler/ChartsVoronoiHandler.js +162 -0
  93. package/legacy/ChartsVoronoiHandler/index.js +1 -0
  94. package/legacy/ChartsYAxis/ChartsYAxis.js +6 -4
  95. package/legacy/LineChart/extremums.js +29 -14
  96. package/legacy/LineChart/index.js +1 -1
  97. package/legacy/PieChart/PieArc.js +18 -2
  98. package/legacy/PieChart/PieArcLabel.js +7 -11
  99. package/legacy/PieChart/PieArcLabelPlot.js +92 -3
  100. package/legacy/PieChart/PieArcPlot.js +91 -3
  101. package/legacy/PieChart/index.js +3 -1
  102. package/legacy/ScatterChart/Scatter.js +18 -7
  103. package/legacy/ScatterChart/ScatterChart.js +18 -1
  104. package/legacy/ScatterChart/index.js +1 -1
  105. package/legacy/SparkLineChart/SparkLineChart.js +1 -0
  106. package/legacy/context/InteractionProvider.js +21 -1
  107. package/legacy/hooks/useAxisEvents.js +20 -27
  108. package/legacy/hooks/useInteractionItemProps.js +6 -1
  109. package/legacy/index.js +2 -1
  110. package/legacy/internals/defaultizeValueFormatter.js +4 -3
  111. package/legacy/internals/utils.js +11 -0
  112. package/models/seriesType/config.d.ts +5 -1
  113. package/models/seriesType/scatter.d.ts +6 -1
  114. package/modern/BarChart/BarElement.js +26 -2
  115. package/modern/BarChart/index.js +2 -1
  116. package/modern/ChartsLegend/index.js +2 -1
  117. package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +95 -74
  118. package/modern/ChartsTooltip/ChartsItemTooltipContent.js +40 -58
  119. package/modern/ChartsTooltip/DefaultChartsAxisTooltipContent.js +167 -0
  120. package/modern/ChartsTooltip/DefaultChartsItemTooltipContent.js +92 -0
  121. package/modern/ChartsTooltip/index.js +5 -1
  122. package/modern/ChartsVoronoiHandler/ChartsVoronoiHandler.js +166 -0
  123. package/modern/ChartsVoronoiHandler/index.js +1 -0
  124. package/modern/ChartsYAxis/ChartsYAxis.js +6 -4
  125. package/modern/LineChart/extremums.js +25 -8
  126. package/modern/LineChart/index.js +1 -1
  127. package/modern/PieChart/PieArc.js +18 -2
  128. package/modern/PieChart/PieArcLabel.js +7 -11
  129. package/modern/PieChart/PieArcLabelPlot.js +92 -3
  130. package/modern/PieChart/PieArcPlot.js +91 -3
  131. package/modern/PieChart/index.js +3 -1
  132. package/modern/ScatterChart/Scatter.js +15 -6
  133. package/modern/ScatterChart/ScatterChart.js +18 -1
  134. package/modern/ScatterChart/index.js +1 -1
  135. package/modern/SparkLineChart/SparkLineChart.js +1 -0
  136. package/modern/context/InteractionProvider.js +21 -1
  137. package/modern/hooks/useAxisEvents.js +20 -27
  138. package/modern/hooks/useInteractionItemProps.js +4 -1
  139. package/modern/index.js +2 -1
  140. package/modern/internals/defaultizeValueFormatter.js +3 -3
  141. package/modern/internals/utils.js +11 -0
  142. package/package.json +6 -4
@@ -7,6 +7,7 @@ import { ChartsAxis } from '../ChartsAxis';
7
7
  import { ChartsTooltip } from '../ChartsTooltip';
8
8
  import { ChartsLegend } from '../ChartsLegend';
9
9
  import { ChartsAxisHighlight } from '../ChartsAxisHighlight';
10
+ import { ChartsVoronoiHandler } from '../ChartsVoronoiHandler/ChartsVoronoiHandler';
10
11
  import { jsx as _jsx } from "react/jsx-runtime";
11
12
  import { jsxs as _jsxs } from "react/jsx-runtime";
12
13
  /**
@@ -26,6 +27,8 @@ const ScatterChart = /*#__PURE__*/React.forwardRef(function ScatterChart(props,
26
27
  series,
27
28
  tooltip,
28
29
  axisHighlight,
30
+ voronoiMaxRadius,
31
+ disableVoronoi,
29
32
  legend,
30
33
  width,
31
34
  height,
@@ -52,7 +55,9 @@ const ScatterChart = /*#__PURE__*/React.forwardRef(function ScatterChart(props,
52
55
  xAxis: xAxis,
53
56
  yAxis: yAxis,
54
57
  sx: sx,
55
- children: [/*#__PURE__*/_jsx(ChartsAxis, {
58
+ children: [!disableVoronoi && /*#__PURE__*/_jsx(ChartsVoronoiHandler, {
59
+ voronoiMaxRadius: voronoiMaxRadius
60
+ }), /*#__PURE__*/_jsx(ChartsAxis, {
56
61
  topAxis: topAxis,
57
62
  leftAxis: leftAxis,
58
63
  rightAxis: rightAxis,
@@ -126,6 +131,11 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
126
131
  * @default false
127
132
  */
128
133
  disableAxisListener: PropTypes.bool,
134
+ /**
135
+ * If true, the interaction will not use the Voronoi cell and fall back to hover events.
136
+ * @default false
137
+ */
138
+ disableVoronoi: PropTypes.bool,
129
139
  /**
130
140
  * The height of the chart in px. If not defined, it takes the height of the parent element.
131
141
  * @default undefined
@@ -218,6 +228,7 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
218
228
  x: PropTypes.number.isRequired,
219
229
  y: PropTypes.number.isRequired
220
230
  })).isRequired,
231
+ disableHover: PropTypes.bool,
221
232
  highlightScope: PropTypes.shape({
222
233
  faded: PropTypes.oneOf(['global', 'none', 'series']),
223
234
  highlighted: PropTypes.oneOf(['item', 'none', 'series'])
@@ -283,6 +294,12 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
283
294
  x: PropTypes.number,
284
295
  y: PropTypes.number
285
296
  }),
297
+ /**
298
+ * Defines the maximal distance between a scatter point and the pointer that triggers the interaction.
299
+ * If `undefined`, the radius is assumed to be infinite.
300
+ * @default undefined
301
+ */
302
+ voronoiMaxRadius: PropTypes.number,
286
303
  /**
287
304
  * The width of the chart in px. If not defined, it takes the width of the parent element.
288
305
  * @default undefined
@@ -1,3 +1,3 @@
1
- export * from './ScatterPlot';
2
1
  export * from './ScatterChart';
2
+ export * from './ScatterPlot';
3
3
  export * from './Scatter';
@@ -78,6 +78,7 @@ const SparkLineChart = /*#__PURE__*/React.forwardRef(function SparkLineChart(pro
78
78
  sx: sx,
79
79
  disableAxisListener: (!showTooltip || (tooltip == null ? void 0 : tooltip.trigger) !== 'axis') && (axisHighlight == null ? void 0 : axisHighlight.x) === 'none' && (axisHighlight == null ? void 0 : axisHighlight.y) === 'none',
80
80
  children: [plotType === 'bar' && /*#__PURE__*/_jsx(BarPlot, {
81
+ skipAnimation: true,
81
82
  slots: slots,
82
83
  slotProps: slotProps,
83
84
  sx: {
@@ -7,6 +7,7 @@ export const InteractionContext = /*#__PURE__*/React.createContext({
7
7
  x: null,
8
8
  y: null
9
9
  },
10
+ useVoronoiInteraction: false,
10
11
  dispatch: () => null
11
12
  });
12
13
  const dataReducer = (prevState, action) => {
@@ -15,6 +16,21 @@ const dataReducer = (prevState, action) => {
15
16
  return _extends({}, prevState, {
16
17
  item: action.data
17
18
  });
19
+ case 'exitChart':
20
+ if (prevState.item === null && prevState.axis.x === null && prevState.axis.y === null) {
21
+ return prevState;
22
+ }
23
+ return _extends({}, prevState, {
24
+ axis: {
25
+ x: null,
26
+ y: null
27
+ },
28
+ item: null
29
+ });
30
+ case 'updateVoronoiUsage':
31
+ return _extends({}, prevState, {
32
+ useVoronoiInteraction: action.useVoronoiInteraction
33
+ });
18
34
  case 'leaveItem':
19
35
  if (prevState.item === null || Object.keys(action.data).some(key => action.data[key] !== prevState.item[key])) {
20
36
  // The item is already something else
@@ -24,6 +40,9 @@ const dataReducer = (prevState, action) => {
24
40
  item: null
25
41
  });
26
42
  case 'updateAxis':
43
+ if (action.data.x === prevState.axis.x && action.data.y === prevState.axis.y) {
44
+ return prevState;
45
+ }
27
46
  return _extends({}, prevState, {
28
47
  axis: action.data
29
48
  });
@@ -39,7 +58,8 @@ export function InteractionProvider({
39
58
  axis: {
40
59
  x: null,
41
60
  y: null
42
- }
61
+ },
62
+ useVoronoiInteraction: false
43
63
  });
44
64
  const value = React.useMemo(() => _extends({}, data, {
45
65
  dispatch
@@ -3,6 +3,10 @@ import { InteractionContext } from '../context/InteractionProvider';
3
3
  import { CartesianContext } from '../context/CartesianContextProvider';
4
4
  import { SVGContext, DrawingContext } from '../context/DrawingProvider';
5
5
  import { isBandScale } from '../internals/isBandScale';
6
+ import { getSVGPoint } from '../internals/utils';
7
+ function getAsANumber(value) {
8
+ return value instanceof Date ? value.getTime() : value;
9
+ }
6
10
  export const useAxisEvents = disableAxisListener => {
7
11
  const svgRef = React.useContext(SVGContext);
8
12
  const {
@@ -48,17 +52,18 @@ export const useAxisEvents = disableAxisListener => {
48
52
  value
49
53
  };
50
54
  }
51
- const closestIndex = axisData == null ? void 0 : axisData.findIndex((v, index) => {
52
- if (v > value) {
53
- // @ts-ignore
54
- if (index === 0 || Math.abs(value - v) <= Math.abs(value - axisData[index - 1])) {
55
+ const valueAsNumber = getAsANumber(value);
56
+ const closestIndex = axisData == null ? void 0 : axisData.findIndex((pointValue, index) => {
57
+ const v = getAsANumber(pointValue);
58
+ if (v > valueAsNumber) {
59
+ if (index === 0 || Math.abs(valueAsNumber - v) <= Math.abs(valueAsNumber - getAsANumber(axisData[index - 1]))) {
55
60
  return true;
56
61
  }
57
62
  }
58
- if (v <= value) {
63
+ if (v <= valueAsNumber) {
59
64
  if (index === axisData.length - 1 ||
60
65
  // @ts-ignore
61
- Math.abs(value - v) < Math.abs(value - axisData[index + 1])) {
66
+ Math.abs(value - v) < Math.abs(value - getAsANumber(axisData[index + 1]))) {
62
67
  return true;
63
68
  }
64
69
  }
@@ -84,37 +89,25 @@ export const useAxisEvents = disableAxisListener => {
84
89
  y: -1
85
90
  };
86
91
  dispatch({
87
- type: 'updateAxis',
88
- data: {
89
- x: null,
90
- y: null
91
- }
92
+ type: 'exitChart'
92
93
  });
93
94
  };
94
95
  const handleMouseMove = event => {
95
- // Get mouse coordinate in global SVG space
96
- const pt = svgRef.current.createSVGPoint();
97
- pt.x = event.clientX;
98
- pt.y = event.clientY;
99
- const svgPt = pt.matrixTransform(svgRef.current.getScreenCTM().inverse());
96
+ const svgPoint = getSVGPoint(svgRef.current, event);
100
97
  mousePosition.current = {
101
- x: svgPt.x,
102
- y: svgPt.y
98
+ x: svgPoint.x,
99
+ y: svgPoint.y
103
100
  };
104
- const outsideX = svgPt.x < left || svgPt.x > left + width;
105
- const outsideY = svgPt.y < top || svgPt.y > top + height;
101
+ const outsideX = svgPoint.x < left || svgPoint.x > left + width;
102
+ const outsideY = svgPoint.y < top || svgPoint.y > top + height;
106
103
  if (outsideX || outsideY) {
107
104
  dispatch({
108
- type: 'updateAxis',
109
- data: {
110
- x: null,
111
- y: null
112
- }
105
+ type: 'exitChart'
113
106
  });
114
107
  return;
115
108
  }
116
- const newStateX = getUpdate(xAxis[usedXAxis], svgPt.x);
117
- const newStateY = getUpdate(yAxis[usedYAxis], svgPt.y);
109
+ const newStateX = getUpdate(xAxis[usedXAxis], svgPoint.x);
110
+ const newStateY = getUpdate(yAxis[usedYAxis], svgPoint.y);
118
111
  dispatch({
119
112
  type: 'updateAxis',
120
113
  data: {
@@ -1,13 +1,16 @@
1
1
  import * as React from 'react';
2
2
  import { InteractionContext } from '../context/InteractionProvider';
3
3
  import { HighlighContext } from '../context/HighlightProvider';
4
- export const useInteractionItemProps = scope => {
4
+ export const useInteractionItemProps = (scope, skip) => {
5
5
  const {
6
6
  dispatch: dispatchInteraction
7
7
  } = React.useContext(InteractionContext);
8
8
  const {
9
9
  dispatch: dispatchHighlight
10
10
  } = React.useContext(HighlighContext);
11
+ if (skip) {
12
+ return () => ({});
13
+ }
11
14
  const getInteractionItemProps = data => {
12
15
  const onMouseEnter = () => {
13
16
  dispatchInteraction({
package/esm/index.js CHANGED
@@ -11,6 +11,7 @@ export * from './ChartsYAxis';
11
11
  export * from './ChartsTooltip';
12
12
  export * from './ChartsLegend';
13
13
  export * from './ChartsAxisHighlight';
14
+ export * from './ChartsVoronoiHandler';
14
15
  export * from './BarChart';
15
16
  export * from './LineChart';
16
17
  export * from './PieChart';
@@ -2,9 +2,10 @@ import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  function defaultizeValueFormatter(series, defaultValueFormatter) {
3
3
  const defaultizedSeries = {};
4
4
  Object.keys(series).forEach(seriesId => {
5
- defaultizedSeries[seriesId] = _extends({
6
- valueFormatter: defaultValueFormatter
7
- }, series[seriesId]);
5
+ var _series$seriesId$valu;
6
+ defaultizedSeries[seriesId] = _extends({}, series[seriesId], {
7
+ valueFormatter: (_series$seriesId$valu = series[seriesId].valueFormatter) != null ? _series$seriesId$valu : defaultValueFormatter
8
+ });
8
9
  });
9
10
  return defaultizedSeries;
10
11
  }
@@ -2,4 +2,15 @@
2
2
  export function getSymbol(shape) {
3
3
  const symbolNames = 'circle cross diamond square star triangle wye'.split(/ /);
4
4
  return symbolNames.indexOf(shape) || 0;
5
+ }
6
+ /**
7
+ * Transform mouse event position to corrdinates inside the SVG.
8
+ * @param svg The SVG element
9
+ * @param event The mouseEvent to transform
10
+ */
11
+ export function getSVGPoint(svg, event) {
12
+ const pt = svg.createSVGPoint();
13
+ pt.x = event.clientX;
14
+ pt.y = event.clientY;
15
+ return pt.matrixTransform(svg.getScreenCTM().inverse());
5
16
  }
@@ -9,8 +9,12 @@ var _InteractionProvider = require("../context/InteractionProvider");
9
9
  var _CartesianContextProvider = require("../context/CartesianContextProvider");
10
10
  var _DrawingProvider = require("../context/DrawingProvider");
11
11
  var _isBandScale = require("../internals/isBandScale");
12
+ var _utils = require("../internals/utils");
12
13
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
13
14
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
15
+ function getAsANumber(value) {
16
+ return value instanceof Date ? value.getTime() : value;
17
+ }
14
18
  const useAxisEvents = disableAxisListener => {
15
19
  const svgRef = React.useContext(_DrawingProvider.SVGContext);
16
20
  const {
@@ -56,17 +60,18 @@ const useAxisEvents = disableAxisListener => {
56
60
  value
57
61
  };
58
62
  }
59
- const closestIndex = axisData?.findIndex((v, index) => {
60
- if (v > value) {
61
- // @ts-ignore
62
- if (index === 0 || Math.abs(value - v) <= Math.abs(value - axisData[index - 1])) {
63
+ const valueAsNumber = getAsANumber(value);
64
+ const closestIndex = axisData?.findIndex((pointValue, index) => {
65
+ const v = getAsANumber(pointValue);
66
+ if (v > valueAsNumber) {
67
+ if (index === 0 || Math.abs(valueAsNumber - v) <= Math.abs(valueAsNumber - getAsANumber(axisData[index - 1]))) {
63
68
  return true;
64
69
  }
65
70
  }
66
- if (v <= value) {
71
+ if (v <= valueAsNumber) {
67
72
  if (index === axisData.length - 1 ||
68
73
  // @ts-ignore
69
- Math.abs(value - v) < Math.abs(value - axisData[index + 1])) {
74
+ Math.abs(value - v) < Math.abs(value - getAsANumber(axisData[index + 1]))) {
70
75
  return true;
71
76
  }
72
77
  }
@@ -92,37 +97,25 @@ const useAxisEvents = disableAxisListener => {
92
97
  y: -1
93
98
  };
94
99
  dispatch({
95
- type: 'updateAxis',
96
- data: {
97
- x: null,
98
- y: null
99
- }
100
+ type: 'exitChart'
100
101
  });
101
102
  };
102
103
  const handleMouseMove = event => {
103
- // Get mouse coordinate in global SVG space
104
- const pt = svgRef.current.createSVGPoint();
105
- pt.x = event.clientX;
106
- pt.y = event.clientY;
107
- const svgPt = pt.matrixTransform(svgRef.current.getScreenCTM().inverse());
104
+ const svgPoint = (0, _utils.getSVGPoint)(svgRef.current, event);
108
105
  mousePosition.current = {
109
- x: svgPt.x,
110
- y: svgPt.y
106
+ x: svgPoint.x,
107
+ y: svgPoint.y
111
108
  };
112
- const outsideX = svgPt.x < left || svgPt.x > left + width;
113
- const outsideY = svgPt.y < top || svgPt.y > top + height;
109
+ const outsideX = svgPoint.x < left || svgPoint.x > left + width;
110
+ const outsideY = svgPoint.y < top || svgPoint.y > top + height;
114
111
  if (outsideX || outsideY) {
115
112
  dispatch({
116
- type: 'updateAxis',
117
- data: {
118
- x: null,
119
- y: null
120
- }
113
+ type: 'exitChart'
121
114
  });
122
115
  return;
123
116
  }
124
- const newStateX = getUpdate(xAxis[usedXAxis], svgPt.x);
125
- const newStateY = getUpdate(yAxis[usedYAxis], svgPt.y);
117
+ const newStateX = getUpdate(xAxis[usedXAxis], svgPoint.x);
118
+ const newStateY = getUpdate(yAxis[usedYAxis], svgPoint.y);
126
119
  dispatch({
127
120
  type: 'updateAxis',
128
121
  data: {
@@ -1,8 +1,8 @@
1
1
  import { HighlightScope } from '../context/HighlightProvider';
2
2
  import { SeriesItemIdentifier } from '../models';
3
- export declare const useInteractionItemProps: (scope?: Partial<HighlightScope>) => (data: SeriesItemIdentifier) => {
3
+ export declare const useInteractionItemProps: (scope?: Partial<HighlightScope>, skip?: boolean) => (() => {}) | ((data: SeriesItemIdentifier) => {
4
4
  onMouseEnter: () => void;
5
5
  onMouseLeave: () => void;
6
- };
6
+ });
7
7
  export declare const getIsHighlighted: (selectedItem: SeriesItemIdentifier | null, currentItem: SeriesItemIdentifier, highlightScope?: Partial<HighlightScope>) => boolean;
8
8
  export declare const getIsFaded: (selectedItem: SeriesItemIdentifier | null, currentItem: SeriesItemIdentifier, highlightScope?: Partial<HighlightScope>) => boolean;
@@ -9,13 +9,16 @@ var _InteractionProvider = require("../context/InteractionProvider");
9
9
  var _HighlightProvider = require("../context/HighlightProvider");
10
10
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
11
11
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
12
- const useInteractionItemProps = scope => {
12
+ const useInteractionItemProps = (scope, skip) => {
13
13
  const {
14
14
  dispatch: dispatchInteraction
15
15
  } = React.useContext(_InteractionProvider.InteractionContext);
16
16
  const {
17
17
  dispatch: dispatchHighlight
18
18
  } = React.useContext(_HighlightProvider.HighlighContext);
19
+ if (skip) {
20
+ return () => ({});
21
+ }
19
22
  const getInteractionItemProps = data => {
20
23
  const onMouseEnter = () => {
21
24
  dispatchInteraction({
package/index.d.ts CHANGED
@@ -11,6 +11,7 @@ export * from './ChartsYAxis';
11
11
  export * from './ChartsTooltip';
12
12
  export * from './ChartsLegend';
13
13
  export * from './ChartsAxisHighlight';
14
+ export * from './ChartsVoronoiHandler';
14
15
  export * from './BarChart';
15
16
  export * from './LineChart';
16
17
  export * from './PieChart';
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-charts v7.0.0-alpha.2
2
+ * @mui/x-charts v7.0.0-alpha.4
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
@@ -153,6 +153,17 @@ Object.keys(_ChartsAxisHighlight).forEach(function (key) {
153
153
  }
154
154
  });
155
155
  });
156
+ var _ChartsVoronoiHandler = require("./ChartsVoronoiHandler");
157
+ Object.keys(_ChartsVoronoiHandler).forEach(function (key) {
158
+ if (key === "default" || key === "__esModule") return;
159
+ if (key in exports && exports[key] === _ChartsVoronoiHandler[key]) return;
160
+ Object.defineProperty(exports, key, {
161
+ enumerable: true,
162
+ get: function () {
163
+ return _ChartsVoronoiHandler[key];
164
+ }
165
+ });
166
+ });
156
167
  var _BarChart = require("./BarChart");
157
168
  Object.keys(_BarChart).forEach(function (key) {
158
169
  if (key === "default" || key === "__esModule") return;
@@ -77,6 +77,7 @@ export declare function defaultizeColor(series: AllSeriesType, seriesIndex: numb
77
77
  data: import("../models/seriesType").ScatterValueType[];
78
78
  markerSize?: number | undefined;
79
79
  label?: string | undefined;
80
+ disableHover?: boolean | undefined;
80
81
  id?: string | undefined;
81
82
  color: string;
82
83
  valueFormatter?: ((value: import("../models/seriesType").ScatterValueType) => string) | undefined;
@@ -1,4 +1,6 @@
1
- declare function defaultizeValueFormatter<ISeries extends {}, IFormatter extends (v: any) => string>(series: {
1
+ declare function defaultizeValueFormatter<ISeries extends {
2
+ valueFormatter?: IFormatter;
3
+ }, IFormatter extends (v: any) => string>(series: {
2
4
  [id: string]: ISeries;
3
5
  }, defaultValueFormatter: IFormatter): {
4
6
  [id: string]: ISeries & {
@@ -9,9 +9,9 @@ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")
9
9
  function defaultizeValueFormatter(series, defaultValueFormatter) {
10
10
  const defaultizedSeries = {};
11
11
  Object.keys(series).forEach(seriesId => {
12
- defaultizedSeries[seriesId] = (0, _extends2.default)({
13
- valueFormatter: defaultValueFormatter
14
- }, series[seriesId]);
12
+ defaultizedSeries[seriesId] = (0, _extends2.default)({}, series[seriesId], {
13
+ valueFormatter: series[seriesId].valueFormatter ?? defaultValueFormatter
14
+ });
15
15
  });
16
16
  return defaultizedSeries;
17
17
  }
@@ -4,4 +4,10 @@ type Without<T, U> = {
4
4
  [P in Exclude<keyof T, keyof U>]?: never;
5
5
  };
6
6
  export type XOR<T, U> = T | U extends object ? (Without<T, U> & U) | (Without<U, T> & T) : T | U;
7
+ /**
8
+ * Transform mouse event position to corrdinates inside the SVG.
9
+ * @param svg The SVG element
10
+ * @param event The mouseEvent to transform
11
+ */
12
+ export declare function getSVGPoint(svg: SVGSVGElement, event: MouseEvent): DOMPoint;
7
13
  export {};
@@ -3,9 +3,21 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.getSVGPoint = getSVGPoint;
6
7
  exports.getSymbol = getSymbol;
7
8
  // Returns the index of a defined shape
8
9
  function getSymbol(shape) {
9
10
  const symbolNames = 'circle cross diamond square star triangle wye'.split(/ /);
10
11
  return symbolNames.indexOf(shape) || 0;
12
+ }
13
+ /**
14
+ * Transform mouse event position to corrdinates inside the SVG.
15
+ * @param svg The SVG element
16
+ * @param event The mouseEvent to transform
17
+ */
18
+ function getSVGPoint(svg, event) {
19
+ const pt = svg.createSVGPoint();
20
+ pt.x = event.clientX;
21
+ pt.y = event.clientY;
22
+ return pt.matrixTransform(svg.getScreenCTM().inverse());
11
23
  }
@@ -2,6 +2,7 @@ import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
3
3
  var _excluded = ["id", "dataIndex", "classes", "color", "highlightScope", "slots", "slotProps", "style"];
4
4
  import * as React from 'react';
5
+ import PropTypes from 'prop-types';
5
6
  import composeClasses from '@mui/utils/composeClasses';
6
7
  import { useSlotProps } from '@mui/base/utils';
7
8
  import generateUtilityClass from '@mui/utils/generateUtilityClass';
@@ -40,7 +41,7 @@ export var BarElementPath = styled(animated.rect, {
40
41
  opacity: ownerState.isFaded && 0.3 || 1
41
42
  };
42
43
  });
43
- export function BarElement(props) {
44
+ function BarElement(props) {
44
45
  var _slots$bar;
45
46
  var id = props.id,
46
47
  dataIndex = props.dataIndex,
@@ -88,4 +89,27 @@ export function BarElement(props) {
88
89
  ownerState: ownerState
89
90
  });
90
91
  return /*#__PURE__*/_jsx(Bar, _extends({}, barProps));
91
- }
92
+ }
93
+ process.env.NODE_ENV !== "production" ? BarElement.propTypes = {
94
+ // ----------------------------- Warning --------------------------------
95
+ // | These PropTypes are generated from the TypeScript type definitions |
96
+ // | To update them edit the TypeScript types and run "yarn proptypes" |
97
+ // ----------------------------------------------------------------------
98
+ classes: PropTypes.object,
99
+ dataIndex: PropTypes.number.isRequired,
100
+ highlightScope: PropTypes.shape({
101
+ faded: PropTypes.oneOf(['global', 'none', 'series']),
102
+ highlighted: PropTypes.oneOf(['item', 'none', 'series'])
103
+ }),
104
+ /**
105
+ * The props used for each component slot.
106
+ * @default {}
107
+ */
108
+ slotProps: PropTypes.object,
109
+ /**
110
+ * Overridable component slots.
111
+ * @default {}
112
+ */
113
+ slots: PropTypes.object
114
+ } : void 0;
115
+ export { BarElement };
@@ -1,2 +1,3 @@
1
+ export * from './BarChart';
1
2
  export * from './BarPlot';
2
- export * from './BarChart';
3
+ export * from './BarElement';
@@ -1,2 +1,3 @@
1
1
  export * from './ChartsLegend';
2
- export * from './chartsLegendClasses';
2
+ export * from './chartsLegendClasses';
3
+ export * from './utils';