@mui/x-charts 7.0.0-alpha.3 → 7.0.0-alpha.5

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 (160) hide show
  1. package/BarChart/BarPlot.js +7 -6
  2. package/BarChart/formatter.js +15 -3
  3. package/CHANGELOG.md +465 -0
  4. package/ChartsAxis/ChartsAxis.js +4 -4
  5. package/ChartsLegend/ChartsLegend.d.ts +1 -1
  6. package/ChartsLegend/ChartsLegend.js +3 -2
  7. package/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
  8. package/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
  9. package/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
  10. package/ChartsReferenceLine/common.d.ts +1 -1
  11. package/ChartsText/ChartsText.d.ts +17 -0
  12. package/{internals/components → ChartsText}/ChartsText.js +32 -17
  13. package/ChartsText/index.d.ts +3 -0
  14. package/ChartsText/index.js +12 -0
  15. package/ChartsText/package.json +6 -0
  16. package/ChartsVoronoiHandler/ChartsVoronoiHandler.d.ts +14 -0
  17. package/ChartsVoronoiHandler/ChartsVoronoiHandler.js +174 -0
  18. package/ChartsVoronoiHandler/index.d.ts +1 -0
  19. package/ChartsVoronoiHandler/index.js +16 -0
  20. package/ChartsVoronoiHandler/package.json +6 -0
  21. package/ChartsXAxis/ChartsXAxis.js +3 -2
  22. package/ChartsYAxis/ChartsYAxis.js +1 -1
  23. package/LineChart/AreaPlot.js +3 -2
  24. package/LineChart/LineHighlightPlot.js +2 -1
  25. package/LineChart/LinePlot.js +3 -2
  26. package/LineChart/MarkPlot.js +2 -1
  27. package/LineChart/formatter.js +14 -2
  28. package/PieChart/PieArcLabelPlot.d.ts +2 -3
  29. package/PieChart/PieArcLabelPlot.js +0 -1
  30. package/PieChart/PieArcPlot.d.ts +2 -3
  31. package/PieChart/PieArcPlot.js +0 -1
  32. package/PieChart/PieChart.js +4 -4
  33. package/PieChart/PiePlot.js +20 -15
  34. package/PieChart/dataTransform/useTransformData.d.ts +2 -3
  35. package/ResponsiveChartContainer/index.js +2 -2
  36. package/ScatterChart/Scatter.js +14 -5
  37. package/ScatterChart/ScatterChart.d.ts +7 -1
  38. package/ScatterChart/ScatterChart.js +18 -1
  39. package/SparkLineChart/SparkLineChart.js +1 -0
  40. package/context/CartesianContextProvider.js +2 -2
  41. package/context/InteractionProvider.d.ts +10 -0
  42. package/context/InteractionProvider.js +21 -1
  43. package/context/SeriesContextProvider.js +1 -1
  44. package/esm/BarChart/BarPlot.js +7 -5
  45. package/esm/BarChart/formatter.js +20 -4
  46. package/esm/ChartsAxis/ChartsAxis.js +4 -4
  47. package/esm/ChartsLegend/ChartsLegend.js +2 -1
  48. package/esm/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
  49. package/esm/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
  50. package/esm/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
  51. package/esm/{internals/components → ChartsText}/ChartsText.js +33 -16
  52. package/esm/ChartsText/index.js +1 -0
  53. package/esm/ChartsVoronoiHandler/ChartsVoronoiHandler.js +168 -0
  54. package/esm/ChartsVoronoiHandler/index.js +1 -0
  55. package/esm/ChartsXAxis/ChartsXAxis.js +2 -1
  56. package/esm/ChartsYAxis/ChartsYAxis.js +1 -1
  57. package/esm/LineChart/AreaPlot.js +3 -2
  58. package/esm/LineChart/LineHighlightPlot.js +2 -1
  59. package/esm/LineChart/LinePlot.js +3 -2
  60. package/esm/LineChart/MarkPlot.js +2 -1
  61. package/esm/LineChart/formatter.js +16 -3
  62. package/esm/PieChart/PieArcLabelPlot.js +0 -1
  63. package/esm/PieChart/PieArcPlot.js +0 -1
  64. package/esm/PieChart/PieChart.js +4 -4
  65. package/esm/PieChart/PiePlot.js +20 -15
  66. package/esm/ResponsiveChartContainer/index.js +2 -2
  67. package/esm/ScatterChart/Scatter.js +14 -5
  68. package/esm/ScatterChart/ScatterChart.js +18 -1
  69. package/esm/SparkLineChart/SparkLineChart.js +1 -0
  70. package/esm/context/CartesianContextProvider.js +2 -2
  71. package/esm/context/InteractionProvider.js +21 -1
  72. package/esm/context/SeriesContextProvider.js +1 -1
  73. package/esm/hooks/useAxisEvents.js +20 -27
  74. package/esm/hooks/useInteractionItemProps.js +4 -1
  75. package/esm/index.js +2 -0
  76. package/esm/internals/getWordsByLines.js +14 -0
  77. package/esm/internals/utils.js +40 -0
  78. package/hooks/useAxisEvents.js +20 -27
  79. package/hooks/useInteractionItemProps.d.ts +2 -2
  80. package/hooks/useInteractionItemProps.js +4 -1
  81. package/index.d.ts +2 -0
  82. package/index.js +23 -1
  83. package/internals/defaultizeColor.d.ts +5 -4
  84. package/internals/{components/ChartsText.d.ts → getWordsByLines.d.ts} +2 -11
  85. package/internals/getWordsByLines.js +21 -0
  86. package/internals/utils.d.ts +13 -0
  87. package/internals/utils.js +42 -0
  88. package/legacy/BarChart/BarPlot.js +7 -5
  89. package/legacy/BarChart/formatter.js +23 -9
  90. package/legacy/ChartsAxis/ChartsAxis.js +4 -4
  91. package/legacy/ChartsLegend/ChartsLegend.js +2 -1
  92. package/legacy/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
  93. package/legacy/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
  94. package/legacy/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
  95. package/legacy/{internals/components → ChartsText}/ChartsText.js +38 -22
  96. package/legacy/ChartsText/index.js +1 -0
  97. package/legacy/ChartsVoronoiHandler/ChartsVoronoiHandler.js +162 -0
  98. package/legacy/ChartsVoronoiHandler/index.js +1 -0
  99. package/legacy/ChartsXAxis/ChartsXAxis.js +2 -1
  100. package/legacy/ChartsYAxis/ChartsYAxis.js +1 -1
  101. package/legacy/LineChart/AreaPlot.js +3 -2
  102. package/legacy/LineChart/LineHighlightPlot.js +2 -1
  103. package/legacy/LineChart/LinePlot.js +3 -2
  104. package/legacy/LineChart/MarkPlot.js +2 -1
  105. package/legacy/LineChart/formatter.js +19 -8
  106. package/legacy/PieChart/PieArcLabelPlot.js +0 -1
  107. package/legacy/PieChart/PieArcPlot.js +0 -1
  108. package/legacy/PieChart/PieChart.js +4 -4
  109. package/legacy/PieChart/PiePlot.js +20 -15
  110. package/legacy/ResponsiveChartContainer/index.js +2 -2
  111. package/legacy/ScatterChart/Scatter.js +17 -6
  112. package/legacy/ScatterChart/ScatterChart.js +18 -1
  113. package/legacy/SparkLineChart/SparkLineChart.js +1 -0
  114. package/legacy/context/CartesianContextProvider.js +2 -2
  115. package/legacy/context/InteractionProvider.js +21 -1
  116. package/legacy/context/SeriesContextProvider.js +1 -1
  117. package/legacy/hooks/useAxisEvents.js +20 -27
  118. package/legacy/hooks/useInteractionItemProps.js +6 -1
  119. package/legacy/index.js +3 -1
  120. package/legacy/internals/getWordsByLines.js +15 -0
  121. package/legacy/internals/utils.js +40 -0
  122. package/models/axis.d.ts +1 -1
  123. package/models/seriesType/config.d.ts +4 -3
  124. package/models/seriesType/pie.d.ts +29 -7
  125. package/models/seriesType/scatter.d.ts +5 -0
  126. package/modern/BarChart/BarPlot.js +7 -5
  127. package/modern/BarChart/formatter.js +15 -3
  128. package/modern/ChartsAxis/ChartsAxis.js +4 -4
  129. package/modern/ChartsLegend/ChartsLegend.js +2 -1
  130. package/modern/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
  131. package/modern/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
  132. package/modern/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
  133. package/modern/{internals/components → ChartsText}/ChartsText.js +33 -16
  134. package/modern/ChartsText/index.js +1 -0
  135. package/modern/ChartsVoronoiHandler/ChartsVoronoiHandler.js +166 -0
  136. package/modern/ChartsVoronoiHandler/index.js +1 -0
  137. package/modern/ChartsXAxis/ChartsXAxis.js +2 -1
  138. package/modern/ChartsYAxis/ChartsYAxis.js +1 -1
  139. package/modern/LineChart/AreaPlot.js +3 -2
  140. package/modern/LineChart/LineHighlightPlot.js +2 -1
  141. package/modern/LineChart/LinePlot.js +3 -2
  142. package/modern/LineChart/MarkPlot.js +2 -1
  143. package/modern/LineChart/formatter.js +14 -2
  144. package/modern/PieChart/PieArcLabelPlot.js +0 -1
  145. package/modern/PieChart/PieArcPlot.js +0 -1
  146. package/modern/PieChart/PieChart.js +4 -4
  147. package/modern/PieChart/PiePlot.js +20 -15
  148. package/modern/ResponsiveChartContainer/index.js +2 -2
  149. package/modern/ScatterChart/Scatter.js +14 -5
  150. package/modern/ScatterChart/ScatterChart.js +18 -1
  151. package/modern/SparkLineChart/SparkLineChart.js +1 -0
  152. package/modern/context/CartesianContextProvider.js +2 -2
  153. package/modern/context/InteractionProvider.js +21 -1
  154. package/modern/context/SeriesContextProvider.js +1 -1
  155. package/modern/hooks/useAxisEvents.js +20 -27
  156. package/modern/hooks/useInteractionItemProps.js +4 -1
  157. package/modern/index.js +3 -1
  158. package/modern/internals/getWordsByLines.js +14 -0
  159. package/modern/internals/utils.js +40 -0
  160. 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
  /**
@@ -25,6 +26,8 @@ var ScatterChart = /*#__PURE__*/React.forwardRef(function ScatterChart(props, re
25
26
  series = props.series,
26
27
  tooltip = props.tooltip,
27
28
  axisHighlight = props.axisHighlight,
29
+ voronoiMaxRadius = props.voronoiMaxRadius,
30
+ disableVoronoi = props.disableVoronoi,
28
31
  legend = props.legend,
29
32
  width = props.width,
30
33
  height = props.height,
@@ -52,7 +55,9 @@ var ScatterChart = /*#__PURE__*/React.forwardRef(function ScatterChart(props, re
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
@@ -84,6 +84,7 @@ var SparkLineChart = /*#__PURE__*/React.forwardRef(function SparkLineChart(props
84
84
  sx: sx,
85
85
  disableAxisListener: (!showTooltip || (tooltip == null ? void 0 : tooltip.trigger) !== 'axis') && (axisHighlight == null ? void 0 : axisHighlight.x) === 'none' && (axisHighlight == null ? void 0 : axisHighlight.y) === 'none',
86
86
  children: [plotType === 'bar' && /*#__PURE__*/_jsx(BarPlot, {
87
+ skipAnimation: true,
87
88
  slots: slots,
88
89
  slotProps: slotProps,
89
90
  sx: {
@@ -54,7 +54,7 @@ function CartesianContextProvider(_ref) {
54
54
  return axisConfig;
55
55
  }
56
56
  if (dataset === undefined) {
57
- throw Error('MUI: x-axis uses `dataKey` but no `dataset` is provided.');
57
+ throw Error('MUI-X-Charts: x-axis uses `dataKey` but no `dataset` is provided.');
58
58
  }
59
59
  return _extends({}, axisConfig, {
60
60
  data: dataset.map(function (d) {
@@ -70,7 +70,7 @@ function CartesianContextProvider(_ref) {
70
70
  return axisConfig;
71
71
  }
72
72
  if (dataset === undefined) {
73
- throw Error('MUI: y-axis uses `dataKey` but no `dataset` is provided.');
73
+ throw Error('MUI-X-Charts: y-axis uses `dataKey` but no `dataset` is provided.');
74
74
  }
75
75
  return _extends({}, axisConfig, {
76
76
  data: dataset.map(function (d) {
@@ -8,6 +8,7 @@ export var InteractionContext = /*#__PURE__*/React.createContext({
8
8
  x: null,
9
9
  y: null
10
10
  },
11
+ useVoronoiInteraction: false,
11
12
  dispatch: function dispatch() {
12
13
  return null;
13
14
  }
@@ -18,6 +19,21 @@ var dataReducer = function dataReducer(prevState, action) {
18
19
  return _extends({}, prevState, {
19
20
  item: action.data
20
21
  });
22
+ case 'exitChart':
23
+ if (prevState.item === null && prevState.axis.x === null && prevState.axis.y === null) {
24
+ return prevState;
25
+ }
26
+ return _extends({}, prevState, {
27
+ axis: {
28
+ x: null,
29
+ y: null
30
+ },
31
+ item: null
32
+ });
33
+ case 'updateVoronoiUsage':
34
+ return _extends({}, prevState, {
35
+ useVoronoiInteraction: action.useVoronoiInteraction
36
+ });
21
37
  case 'leaveItem':
22
38
  if (prevState.item === null || Object.keys(action.data).some(function (key) {
23
39
  return action.data[key] !== prevState.item[key];
@@ -29,6 +45,9 @@ var dataReducer = function dataReducer(prevState, action) {
29
45
  item: null
30
46
  });
31
47
  case 'updateAxis':
48
+ if (action.data.x === prevState.axis.x && action.data.y === prevState.axis.y) {
49
+ return prevState;
50
+ }
32
51
  return _extends({}, prevState, {
33
52
  axis: action.data
34
53
  });
@@ -43,7 +62,8 @@ export function InteractionProvider(_ref) {
43
62
  axis: {
44
63
  x: null,
45
64
  y: null
46
- }
65
+ },
66
+ useVoronoiInteraction: false
47
67
  }),
48
68
  _React$useReducer2 = _slicedToArray(_React$useReducer, 2),
49
69
  data = _React$useReducer2[0],
@@ -39,7 +39,7 @@ var formatSeries = function formatSeries(series, colors, dataset) {
39
39
  };
40
40
  }
41
41
  if (((_seriesGroups$type = seriesGroups[type]) == null ? void 0 : _seriesGroups$type.series[id]) !== undefined) {
42
- throw new Error("MUI: series' id \"".concat(id, "\" is not unique"));
42
+ throw new Error("MUI-X-Charts: series' id \"".concat(id, "\" is not unique"));
43
43
  }
44
44
  seriesGroups[type].series[id] = _extends({
45
45
  id: id
@@ -4,6 +4,10 @@ import { InteractionContext } from '../context/InteractionProvider';
4
4
  import { CartesianContext } from '../context/CartesianContextProvider';
5
5
  import { SVGContext, DrawingContext } from '../context/DrawingProvider';
6
6
  import { isBandScale } from '../internals/isBandScale';
7
+ import { getSVGPoint } from '../internals/utils';
8
+ function getAsANumber(value) {
9
+ return value instanceof Date ? value.getTime() : value;
10
+ }
7
11
  export var useAxisEvents = function useAxisEvents(disableAxisListener) {
8
12
  var svgRef = React.useContext(SVGContext);
9
13
  var _React$useContext = React.useContext(DrawingContext),
@@ -44,17 +48,18 @@ export var useAxisEvents = function useAxisEvents(disableAxisListener) {
44
48
  value: value
45
49
  };
46
50
  }
47
- var closestIndex = axisData == null ? void 0 : axisData.findIndex(function (v, index) {
48
- if (v > value) {
49
- // @ts-ignore
50
- if (index === 0 || Math.abs(value - v) <= Math.abs(value - axisData[index - 1])) {
51
+ var valueAsNumber = getAsANumber(value);
52
+ var closestIndex = axisData == null ? void 0 : axisData.findIndex(function (pointValue, index) {
53
+ var v = getAsANumber(pointValue);
54
+ if (v > valueAsNumber) {
55
+ if (index === 0 || Math.abs(valueAsNumber - v) <= Math.abs(valueAsNumber - getAsANumber(axisData[index - 1]))) {
51
56
  return true;
52
57
  }
53
58
  }
54
- if (v <= value) {
59
+ if (v <= valueAsNumber) {
55
60
  if (index === axisData.length - 1 ||
56
61
  // @ts-ignore
57
- Math.abs(value - v) < Math.abs(value - axisData[index + 1])) {
62
+ Math.abs(value - v) < Math.abs(value - getAsANumber(axisData[index + 1]))) {
58
63
  return true;
59
64
  }
60
65
  }
@@ -80,37 +85,25 @@ export var useAxisEvents = function useAxisEvents(disableAxisListener) {
80
85
  y: -1
81
86
  };
82
87
  dispatch({
83
- type: 'updateAxis',
84
- data: {
85
- x: null,
86
- y: null
87
- }
88
+ type: 'exitChart'
88
89
  });
89
90
  };
90
91
  var handleMouseMove = function handleMouseMove(event) {
91
- // Get mouse coordinate in global SVG space
92
- var pt = svgRef.current.createSVGPoint();
93
- pt.x = event.clientX;
94
- pt.y = event.clientY;
95
- var svgPt = pt.matrixTransform(svgRef.current.getScreenCTM().inverse());
92
+ var svgPoint = getSVGPoint(svgRef.current, event);
96
93
  mousePosition.current = {
97
- x: svgPt.x,
98
- y: svgPt.y
94
+ x: svgPoint.x,
95
+ y: svgPoint.y
99
96
  };
100
- var outsideX = svgPt.x < left || svgPt.x > left + width;
101
- var outsideY = svgPt.y < top || svgPt.y > top + height;
97
+ var outsideX = svgPoint.x < left || svgPoint.x > left + width;
98
+ var outsideY = svgPoint.y < top || svgPoint.y > top + height;
102
99
  if (outsideX || outsideY) {
103
100
  dispatch({
104
- type: 'updateAxis',
105
- data: {
106
- x: null,
107
- y: null
108
- }
101
+ type: 'exitChart'
109
102
  });
110
103
  return;
111
104
  }
112
- var newStateX = getUpdate(xAxis[usedXAxis], svgPt.x);
113
- var newStateY = getUpdate(yAxis[usedYAxis], svgPt.y);
105
+ var newStateX = getUpdate(xAxis[usedXAxis], svgPoint.x);
106
+ var newStateY = getUpdate(yAxis[usedYAxis], svgPoint.y);
114
107
  dispatch({
115
108
  type: 'updateAxis',
116
109
  data: {
@@ -1,11 +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 var useInteractionItemProps = function useInteractionItemProps(scope) {
4
+ export var useInteractionItemProps = function useInteractionItemProps(scope, skip) {
5
5
  var _React$useContext = React.useContext(InteractionContext),
6
6
  dispatchInteraction = _React$useContext.dispatch;
7
7
  var _React$useContext2 = React.useContext(HighlighContext),
8
8
  dispatchHighlight = _React$useContext2.dispatch;
9
+ if (skip) {
10
+ return function () {
11
+ return {};
12
+ };
13
+ }
9
14
  var getInteractionItemProps = function getInteractionItemProps(data) {
10
15
  var onMouseEnter = function onMouseEnter() {
11
16
  dispatchInteraction({
package/legacy/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-charts v7.0.0-alpha.3
2
+ * @mui/x-charts v7.0.0-alpha.5
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
@@ -15,9 +15,11 @@ export * from './ChartsReferenceLine';
15
15
  export * from './ChartsAxis';
16
16
  export * from './ChartsXAxis';
17
17
  export * from './ChartsYAxis';
18
+ export * from './ChartsText';
18
19
  export * from './ChartsTooltip';
19
20
  export * from './ChartsLegend';
20
21
  export * from './ChartsAxisHighlight';
22
+ export * from './ChartsVoronoiHandler';
21
23
  export * from './BarChart';
22
24
  export * from './LineChart';
23
25
  export * from './PieChart';
@@ -0,0 +1,15 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import { getStringSize } from './domUtils';
3
+ export function getWordsByLines(_ref) {
4
+ var style = _ref.style,
5
+ needsComputation = _ref.needsComputation,
6
+ text = _ref.text;
7
+ return text.split('\n').map(function (subText) {
8
+ return _extends({
9
+ text: subText
10
+ }, needsComputation ? getStringSize(subText, style) : {
11
+ width: 0,
12
+ height: 0
13
+ });
14
+ });
15
+ }
@@ -2,4 +2,44 @@
2
2
  export function getSymbol(shape) {
3
3
  var 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
+ var pt = svg.createSVGPoint();
13
+ pt.x = event.clientX;
14
+ pt.y = event.clientY;
15
+ return pt.matrixTransform(svg.getScreenCTM().inverse());
16
+ }
17
+
18
+ /**
19
+ * Helper that converts values and percentages into values.
20
+ * @param value The value provided by the developer. Can either be a number or a string with '%' or 'px'.
21
+ * @param refValue The numerical value associated to 100%.
22
+ * @returns The numerical value associated to the provided value.
23
+ */
24
+ export function getPercentageValue(value, refValue) {
25
+ if (typeof value === 'number') {
26
+ return value;
27
+ }
28
+ if (value === '100%') {
29
+ // Avoid potential rounding issues
30
+ return refValue;
31
+ }
32
+ if (value.endsWith('%')) {
33
+ var percentage = Number.parseFloat(value.slice(0, value.length - 1));
34
+ if (!Number.isNaN(percentage)) {
35
+ return percentage * refValue / 100;
36
+ }
37
+ }
38
+ if (value.endsWith('px')) {
39
+ var val = Number.parseFloat(value.slice(0, value.length - 2));
40
+ if (!Number.isNaN(val)) {
41
+ return val;
42
+ }
43
+ }
44
+ throw Error("MUI-Charts: Received an unknown value \"".concat(value, "\". It should be a number, or a string with a percentage value."));
5
45
  }
package/models/axis.d.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  import type { ScaleBand, ScaleLogarithmic, ScalePower, ScaleTime, ScaleLinear, ScalePoint } from 'd3-scale';
3
3
  import { ChartsAxisClasses } from '../ChartsAxis/axisClasses';
4
4
  import type { TickParams } from '../hooks/useTicks';
5
- import { ChartsTextProps } from '../internals/components/ChartsText';
5
+ import { ChartsTextProps } from '../ChartsText';
6
6
  export type D3Scale<Domain extends {
7
7
  toString(): string;
8
8
  } = number | Date | string, Range = number, Output = number> = ScaleBand<Domain> | ScaleLogarithmic<Range, Output> | ScalePoint<Domain> | ScalePower<Range, Output> | ScaleTime<Range, Output> | ScaleLinear<Range, Output>;
@@ -77,10 +77,11 @@ export type FormatterResult<T extends ChartSeriesType> = {
77
77
  } ? {
78
78
  stackingGroups: StackingGroupsType;
79
79
  } : {});
80
- export type DatasetType<T extends number | string | Date = number | string | Date> = {
80
+ export type DatasetElementType<T> = {
81
81
  [key: string]: T;
82
- }[];
83
- export type Formatter<T extends ChartSeriesType> = (params: FormatterParams<T>, dataset?: DatasetType<number>) => FormatterResult<T>;
82
+ };
83
+ export type DatasetType<T = number | string | Date | null | undefined> = DatasetElementType<T>[];
84
+ export type Formatter<T extends ChartSeriesType> = (params: FormatterParams<T>, dataset?: DatasetType) => FormatterResult<T>;
84
85
  export type LegendParams = {
85
86
  /**
86
87
  * The color used in the legend
@@ -17,14 +17,18 @@ export interface PieSeriesType<Tdata = PieValueType> extends CommonSeriesType<Td
17
17
  data: Tdata[];
18
18
  /**
19
19
  * The radius between circle center and the begining of the arc.
20
+ * Can be a number (in px) or a string with a percentage such as '50%'.
21
+ * The '100%' is the maximal radius that fit into the drawing area.
20
22
  * @default 0
21
23
  */
22
- innerRadius?: number;
24
+ innerRadius?: number | string;
23
25
  /**
24
26
  * The radius between circle center and the end of the arc.
25
- * @default R_max The maximal radius that fit into the drawing area.
27
+ * Can be a number (in px) or a string with a percentage such as '50%'.
28
+ * The '100%' is the maximal radius that fit into the drawing area.
29
+ * @default '100%'
26
30
  */
27
- outerRadius?: number;
31
+ outerRadius?: number | string;
28
32
  /**
29
33
  * The radius applied to arc corners (similar to border radius).
30
34
  * @default 0
@@ -56,14 +60,18 @@ export interface PieSeriesType<Tdata = PieValueType> extends CommonSeriesType<Td
56
60
  arcLabelMinAngle?: number;
57
61
  /**
58
62
  * The x coordinate of the pie center.
59
- * @default width/2 the center of the drawing area.
63
+ * Can be a number (in px) or a string with a percentage such as '50%'.
64
+ * The '100%' is the width the drawing area.
65
+ * @default '50%'
60
66
  */
61
- cx?: number;
67
+ cx?: number | string;
62
68
  /**
63
69
  * The y coordinate of the pie center.
64
- * @default height/2 the center of the drawing area.
70
+ * Can be a number (in px) or a string with a percentage such as '50%'.
71
+ * The '100%' is the height the drawing area.
72
+ * @default '50%'
65
73
  */
66
- cy?: number;
74
+ cy?: number | string;
67
75
  /**
68
76
  * Override the arc attibutes when it is highlighted.
69
77
  */
@@ -107,3 +115,17 @@ export type PieItemIdentifier = {
107
115
  export interface DefaultizedPieSeriesType extends DefaultizedProps<PieSeriesType, CommonDefaultizedProps> {
108
116
  data: DefaultizedPieValueType[];
109
117
  }
118
+ /**
119
+ * Props received when the parent components has done the percentage conversion.
120
+ */
121
+ export interface ComputedPieRadius {
122
+ /**
123
+ * The radius between circle center and the begining of the arc.
124
+ * @default 0
125
+ */
126
+ innerRadius?: number;
127
+ /**
128
+ * The radius between circle center and the end of the arc.
129
+ */
130
+ outerRadius: number;
131
+ }
@@ -10,6 +10,11 @@ export interface ScatterSeriesType extends CommonSeriesType<ScatterValueType>, C
10
10
  data: ScatterValueType[];
11
11
  markerSize?: number;
12
12
  label?: string;
13
+ /**
14
+ * If true, the interaction will not use element hover for this series.
15
+ * @default false
16
+ */
17
+ disableHover?: boolean;
13
18
  }
14
19
  /**
15
20
  * An object that allows to identify a single scatter item.
@@ -8,7 +8,8 @@ import { SeriesContext } from '../context/SeriesContextProvider';
8
8
  import { CartesianContext } from '../context/CartesianContextProvider';
9
9
  import { BarElement } from './BarElement';
10
10
  import { isBandScaleConfig } from '../models/axis';
11
- import { jsx as _jsx } from "react/jsx-runtime";
11
+ import { DEFAULT_X_AXIS_KEY, DEFAULT_Y_AXIS_KEY } from '../constants';
12
+
12
13
  /**
13
14
  * Solution of the equations
14
15
  * W = barWidth * N + offset * (N-1)
@@ -18,6 +19,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
18
19
  * @param gapRatio The ratio of the gap between bars over the bar width.
19
20
  * @returns The bar width and the offset between bars.
20
21
  */
22
+ import { jsx as _jsx } from "react/jsx-runtime";
21
23
  function getBandSize({
22
24
  bandWidth: W,
23
25
  numberOfGroups: N,
@@ -67,18 +69,18 @@ const useCompletedData = () => {
67
69
  let baseScaleConfig;
68
70
  if (verticalLayout) {
69
71
  if (!isBandScaleConfig(xAxisConfig)) {
70
- throw new Error(`Axis with id "${xAxisKey}" shoud be of type "band" to display the bar series of id "${seriesId}"`);
72
+ throw new Error(`MUI-X-Charts: ${xAxisKey === DEFAULT_X_AXIS_KEY ? 'The first `xAxis`' : `The x-axis with id "${xAxisKey}"`} shoud be of type "band" to display the bar series of id "${seriesId}"`);
71
73
  }
72
74
  if (xAxis[xAxisKey].data === undefined) {
73
- throw new Error(`Axis with id "${xAxisKey}" shoud have data property`);
75
+ throw new Error(`MUI-X-Charts: ${xAxisKey === DEFAULT_X_AXIS_KEY ? 'The first `xAxis`' : `The x-axis with id "${xAxisKey}"`} shoud have data property`);
74
76
  }
75
77
  baseScaleConfig = xAxisConfig;
76
78
  } else {
77
79
  if (!isBandScaleConfig(yAxisConfig)) {
78
- throw new Error(`Axis with id "${yAxisKey}" shoud be of type "band" to display the bar series of id "${seriesId}"`);
80
+ throw new Error(`MUI-X-Charts: ${yAxisKey === DEFAULT_Y_AXIS_KEY ? 'The first `yAxis`' : `The y-axis with id "${yAxisKey}"`} shoud be of type "band" to display the bar series of id "${seriesId}"`);
79
81
  }
80
82
  if (yAxis[yAxisKey].data === undefined) {
81
- throw new Error(`Axis with id "${xAxisKey}" shoud have data property`);
83
+ throw new Error(`MUI-X-Charts: ${yAxisKey === DEFAULT_Y_AXIS_KEY ? 'The first `yAxis`' : `The y-axis with id "${yAxisKey}"`} shoud have data property`);
82
84
  }
83
85
  baseScaleConfig = yAxisConfig;
84
86
  }
@@ -2,6 +2,7 @@ import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import { stack as d3Stack } from 'd3-shape';
3
3
  import { getStackingGroups } from '../internals/stackSeries';
4
4
  import defaultizeValueFormatter from '../internals/defaultizeValueFormatter';
5
+ let warnOnce = false;
5
6
  const formatter = (params, dataset) => {
6
7
  const {
7
8
  seriesOrder,
@@ -24,7 +25,7 @@ const formatter = (params, dataset) => {
24
25
  }
25
26
  });
26
27
  } else if (dataset === undefined) {
27
- throw new Error([`MUI: bar series with id='${id}' has no data.`, 'Either provide a data property to the series or use the dataset prop.'].join('\n'));
28
+ throw new Error([`MUI-X-Charts: bar series with id='${id}' has no data.`, 'Either provide a data property to the series or use the dataset prop.'].join('\n'));
28
29
  }
29
30
  });
30
31
  const completedSeries = {};
@@ -39,13 +40,24 @@ const formatter = (params, dataset) => {
39
40
  // Use dataKey if needed and available
40
41
  const dataKey = series[id].dataKey;
41
42
  return series[id].data === undefined && dataKey !== undefined ? dataKey : id;
42
- })).order(stackingOrder).offset(stackingOffset)(d3Dataset);
43
+ })).value((d, key) => d[key] ?? 0) // defaultize null value to 0
44
+ .order(stackingOrder).offset(stackingOffset)(d3Dataset);
43
45
  ids.forEach((id, index) => {
44
46
  const dataKey = series[id].dataKey;
45
47
  completedSeries[id] = _extends({
46
48
  layout: 'vertical'
47
49
  }, series[id], {
48
- data: dataKey ? dataset.map(d => d[dataKey]) : series[id].data,
50
+ data: dataKey ? dataset.map(data => {
51
+ const value = data[dataKey];
52
+ if (typeof value !== 'number') {
53
+ if (process.env.NODE_ENV !== 'production' && !warnOnce && value !== null) {
54
+ warnOnce = true;
55
+ console.error([`MUI-X charts: your dataset key "${dataKey}" is used for plotting bars, but contains nonnumerical elements.`, 'Bar plots only support numbers and null values.']);
56
+ }
57
+ return 0;
58
+ }
59
+ return value;
60
+ }) : series[id].data,
49
61
  stackedData: stackedSeries[index].map(([a, b]) => [a, b])
50
62
  });
51
63
  });
@@ -58,16 +58,16 @@ function ChartsAxis(props) {
58
58
  const topId = getAxisId(topAxis);
59
59
  const rightId = getAxisId(rightAxis);
60
60
  if (topId !== null && !xAxis[topId]) {
61
- throw Error(`MUI: id used for top axis "${topId}" is not defined`);
61
+ throw Error([`MUI-X-Charts: id used for top axis "${topId}" is not defined.`, `Available ids are: ${xAxisIds.join(', ')}.`].join('\n'));
62
62
  }
63
63
  if (leftId !== null && !yAxis[leftId]) {
64
- throw Error(`MUI: id used for left axis "${leftId}" is not defined`);
64
+ throw Error([`MUI-X-Charts: id used for left axis "${leftId}" is not defined.`, `Available ids are: ${yAxisIds.join(', ')}.`].join('\n'));
65
65
  }
66
66
  if (rightId !== null && !yAxis[rightId]) {
67
- throw Error(`MUI: id used for right axis "${rightId}" is not defined`);
67
+ throw Error([`MUI-X-Charts: id used for right axis "${rightId}" is not defined.`, `Available ids are: ${yAxisIds.join(', ')}.`].join('\n'));
68
68
  }
69
69
  if (bottomId !== null && !xAxis[bottomId]) {
70
- throw Error(`MUI: id used for bottom axis "${bottomId}" is not defined`);
70
+ throw Error([`MUI-X-Charts: id used for bottom axis "${bottomId}" is not defined.`, `Available ids are: ${xAxisIds.join(', ')}.`].join('\n'));
71
71
  }
72
72
  const topAxisProps = mergeProps(topAxis, slots, slotProps);
73
73
  const bottomAxisProps = mergeProps(bottomAxis, slots, slotProps);
@@ -12,7 +12,8 @@ import { DrawingContext } from '../context/DrawingProvider';
12
12
  import { getSeriesToDisplay } from './utils';
13
13
  import { SeriesContext } from '../context/SeriesContextProvider';
14
14
  import { getLegendUtilityClass } from './chartsLegendClasses';
15
- import { ChartsText, getWordsByLines } from '../internals/components/ChartsText';
15
+ import { ChartsText } from '../ChartsText';
16
+ import { getWordsByLines } from '../internals/getWordsByLines';
16
17
  import { jsx as _jsx } from "react/jsx-runtime";
17
18
  import { jsxs as _jsxs } from "react/jsx-runtime";
18
19
  const useUtilityClasses = ownerState => {
@@ -6,10 +6,10 @@ import { ChartsYReferenceLine } from './ChartsYReferenceLine';
6
6
  import { jsx as _jsx } from "react/jsx-runtime";
7
7
  function ChartsReferenceLine(props) {
8
8
  if (props.x !== undefined && props.y !== undefined) {
9
- throw new Error('MUI-X: The ChartsReferenceLine can not have both `x` and `y` props set.');
9
+ throw new Error('MUI-X-Charts: The ChartsReferenceLine can not have both `x` and `y` props set.');
10
10
  }
11
11
  if (props.x === undefined && props.y === undefined) {
12
- throw new Error('MUI-X: The ChartsReferenceLine should have a value in `x` or `y` prop.');
12
+ throw new Error('MUI-X-Charts: The ChartsReferenceLine should have a value in `x` or `y` prop.');
13
13
  }
14
14
  if (props.x !== undefined) {
15
15
  return /*#__PURE__*/_jsx(ChartsXReferenceLine, _extends({}, props));
@@ -3,7 +3,7 @@ import * as React from 'react';
3
3
  import composeClasses from '@mui/utils/composeClasses';
4
4
  import { useDrawingArea, useXScale } from '../hooks';
5
5
  import { ReferenceLineRoot } from './common';
6
- import { ChartsText } from '../internals/components/ChartsText';
6
+ import { ChartsText } from '../ChartsText';
7
7
  import { getReferenceLineUtilityClass } from './chartsReferenceLineClasses';
8
8
  import { jsx as _jsx } from "react/jsx-runtime";
9
9
  import { jsxs as _jsxs } from "react/jsx-runtime";
@@ -3,7 +3,7 @@ import * as React from 'react';
3
3
  import composeClasses from '@mui/utils/composeClasses';
4
4
  import { useDrawingArea, useYScale } from '../hooks';
5
5
  import { ReferenceLineRoot } from './common';
6
- import { ChartsText } from '../internals/components/ChartsText';
6
+ import { ChartsText } from '../ChartsText';
7
7
  import { getReferenceLineUtilityClass } from './chartsReferenceLineClasses';
8
8
  import { jsx as _jsx } from "react/jsx-runtime";
9
9
  import { jsxs as _jsxs } from "react/jsx-runtime";
@@ -1,23 +1,15 @@
1
- import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
2
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
3
  const _excluded = ["x", "y", "style", "text", "ownerState"],
4
4
  _excluded2 = ["angle", "textAnchor", "dominantBaseline"];
5
5
  import * as React from 'react';
6
- import { getStringSize } from '../domUtils';
6
+ import PropTypes from 'prop-types';
7
+ import { getWordsByLines } from '../internals/getWordsByLines';
7
8
  import { jsx as _jsx } from "react/jsx-runtime";
8
- export function getWordsByLines({
9
- style,
10
- needsComputation,
11
- text
12
- }) {
13
- return text.split('\n').map(subText => _extends({
14
- text: subText
15
- }, needsComputation ? getStringSize(subText, style) : {
16
- width: 0,
17
- height: 0
18
- }));
19
- }
20
- export function ChartsText(props) {
9
+ /**
10
+ * Helper component to manage multiline text in SVG
11
+ */
12
+ function ChartsText(props) {
21
13
  const {
22
14
  x,
23
15
  y,
@@ -74,4 +66,29 @@ export function ChartsText(props) {
74
66
  children: line.text
75
67
  }, index))
76
68
  }));
77
- }
69
+ }
70
+ process.env.NODE_ENV !== "production" ? ChartsText.propTypes = {
71
+ // ----------------------------- Warning --------------------------------
72
+ // | These PropTypes are generated from the TypeScript type definitions |
73
+ // | To update them edit the TypeScript types and run "yarn proptypes" |
74
+ // ----------------------------------------------------------------------
75
+ /**
76
+ * Height of a text line (in `em`).
77
+ */
78
+ lineHeight: PropTypes.number,
79
+ /**
80
+ * If `true`, the line width is computed.
81
+ * @default false
82
+ */
83
+ needsComputation: PropTypes.bool,
84
+ ownerState: PropTypes.any,
85
+ /**
86
+ * Style applied to text elements.
87
+ */
88
+ style: PropTypes.object,
89
+ /**
90
+ * Text displayed.
91
+ */
92
+ text: PropTypes.string.isRequired
93
+ } : void 0;
94
+ export { ChartsText };
@@ -0,0 +1 @@
1
+ export { ChartsText } from './ChartsText';