@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
@@ -0,0 +1,17 @@
1
+ import * as React from 'react';
2
+ import { GetWordsByLinesParams } from '../internals/getWordsByLines';
3
+ export interface ChartsTextProps extends Omit<React.SVGTextElementAttributes<SVGTextElement>, 'width' | 'ref' | 'style' | 'dominantBaseline'>, GetWordsByLinesParams {
4
+ /**
5
+ * Height of a text line (in `em`).
6
+ */
7
+ lineHeight?: number;
8
+ ownerState?: any;
9
+ }
10
+ /**
11
+ * Helper component to manage multiline text in SVG
12
+ */
13
+ declare function ChartsText(props: ChartsTextProps): React.JSX.Element;
14
+ declare namespace ChartsText {
15
+ var propTypes: any;
16
+ }
17
+ export { ChartsText };
@@ -5,28 +5,19 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.ChartsText = ChartsText;
8
- exports.getWordsByLines = getWordsByLines;
9
- var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
10
8
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
+ var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
11
10
  var React = _interopRequireWildcard(require("react"));
12
- var _domUtils = require("../domUtils");
11
+ var _propTypes = _interopRequireDefault(require("prop-types"));
12
+ var _getWordsByLines = require("../internals/getWordsByLines");
13
13
  var _jsxRuntime = require("react/jsx-runtime");
14
14
  const _excluded = ["x", "y", "style", "text", "ownerState"],
15
15
  _excluded2 = ["angle", "textAnchor", "dominantBaseline"];
16
16
  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); }
17
17
  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; }
18
- function getWordsByLines({
19
- style,
20
- needsComputation,
21
- text
22
- }) {
23
- return text.split('\n').map(subText => (0, _extends2.default)({
24
- text: subText
25
- }, needsComputation ? (0, _domUtils.getStringSize)(subText, style) : {
26
- width: 0,
27
- height: 0
28
- }));
29
- }
18
+ /**
19
+ * Helper component to manage multiline text in SVG
20
+ */
30
21
  function ChartsText(props) {
31
22
  const {
32
23
  x,
@@ -42,7 +33,7 @@ function ChartsText(props) {
42
33
  dominantBaseline
43
34
  } = _ref,
44
35
  style = (0, _objectWithoutPropertiesLoose2.default)(_ref, _excluded2);
45
- const wordsByLines = React.useMemo(() => getWordsByLines({
36
+ const wordsByLines = React.useMemo(() => (0, _getWordsByLines.getWordsByLines)({
46
37
  style,
47
38
  needsComputation: text.includes('\n'),
48
39
  text
@@ -84,4 +75,28 @@ function ChartsText(props) {
84
75
  children: line.text
85
76
  }, index))
86
77
  }));
87
- }
78
+ }
79
+ process.env.NODE_ENV !== "production" ? ChartsText.propTypes = {
80
+ // ----------------------------- Warning --------------------------------
81
+ // | These PropTypes are generated from the TypeScript type definitions |
82
+ // | To update them edit the TypeScript types and run "yarn proptypes" |
83
+ // ----------------------------------------------------------------------
84
+ /**
85
+ * Height of a text line (in `em`).
86
+ */
87
+ lineHeight: _propTypes.default.number,
88
+ /**
89
+ * If `true`, the line width is computed.
90
+ * @default false
91
+ */
92
+ needsComputation: _propTypes.default.bool,
93
+ ownerState: _propTypes.default.any,
94
+ /**
95
+ * Style applied to text elements.
96
+ */
97
+ style: _propTypes.default.object,
98
+ /**
99
+ * Text displayed.
100
+ */
101
+ text: _propTypes.default.string.isRequired
102
+ } : void 0;
@@ -0,0 +1,3 @@
1
+ export { ChartsText } from './ChartsText';
2
+ export type { ChartsTextProps } from './ChartsText';
3
+ export type { ChartsTextStyle } from '../internals/getWordsByLines';
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "ChartsText", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _ChartsText.ChartsText;
10
+ }
11
+ });
12
+ var _ChartsText = require("./ChartsText");
@@ -0,0 +1,6 @@
1
+ {
2
+ "sideEffects": false,
3
+ "module": "../esm/ChartsText/index.js",
4
+ "main": "./index.js",
5
+ "types": "./index.d.ts"
6
+ }
@@ -0,0 +1,14 @@
1
+ import * as React from 'react';
2
+ export type ChartsVoronoiHandlerProps = {
3
+ /**
4
+ * Defines the maximal distance between a scatter point and the pointer that triggers the interaction.
5
+ * If `undefined`, the radius is assumed to be infinite.
6
+ * @default undefined
7
+ */
8
+ voronoiMaxRadius?: number | undefined;
9
+ };
10
+ declare function ChartsVoronoiHandler(props: ChartsVoronoiHandlerProps): React.JSX.Element;
11
+ declare namespace ChartsVoronoiHandler {
12
+ var propTypes: any;
13
+ }
14
+ export { ChartsVoronoiHandler };
@@ -0,0 +1,174 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.ChartsVoronoiHandler = ChartsVoronoiHandler;
8
+ var React = _interopRequireWildcard(require("react"));
9
+ var _propTypes = _interopRequireDefault(require("prop-types"));
10
+ var _d3Delaunay = require("d3-delaunay");
11
+ var _useEnhancedEffect = _interopRequireDefault(require("@mui/utils/useEnhancedEffect"));
12
+ var _InteractionProvider = require("../context/InteractionProvider");
13
+ var _CartesianContextProvider = require("../context/CartesianContextProvider");
14
+ var _DrawingProvider = require("../context/DrawingProvider");
15
+ var _SeriesContextProvider = require("../context/SeriesContextProvider");
16
+ var _useScale = require("../hooks/useScale");
17
+ var _utils = require("../internals/utils");
18
+ var _jsxRuntime = require("react/jsx-runtime");
19
+ 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); }
20
+ 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; }
21
+ function ChartsVoronoiHandler(props) {
22
+ const {
23
+ voronoiMaxRadius
24
+ } = props;
25
+ const svgRef = React.useContext(_DrawingProvider.SVGContext);
26
+ const {
27
+ width,
28
+ height,
29
+ top,
30
+ left
31
+ } = React.useContext(_DrawingProvider.DrawingContext);
32
+ const {
33
+ xAxis,
34
+ yAxis,
35
+ xAxisIds,
36
+ yAxisIds
37
+ } = React.useContext(_CartesianContextProvider.CartesianContext);
38
+ const {
39
+ dispatch
40
+ } = React.useContext(_InteractionProvider.InteractionContext);
41
+ const {
42
+ series,
43
+ seriesOrder
44
+ } = React.useContext(_SeriesContextProvider.SeriesContext).scatter ?? {};
45
+ const voronoiRef = React.useRef({});
46
+ const defaultXAxisId = xAxisIds[0];
47
+ const defaultYAxisId = yAxisIds[0];
48
+ (0, _useEnhancedEffect.default)(() => {
49
+ dispatch({
50
+ type: 'updateVoronoiUsage',
51
+ useVoronoiInteraction: true
52
+ });
53
+ return () => {
54
+ dispatch({
55
+ type: 'updateVoronoiUsage',
56
+ useVoronoiInteraction: false
57
+ });
58
+ };
59
+ }, [dispatch]);
60
+ (0, _useEnhancedEffect.default)(() => {
61
+ if (seriesOrder === undefined || series === undefined) {
62
+ // If there is no scatter chart series
63
+ return;
64
+ }
65
+ voronoiRef.current = {};
66
+ let points = [];
67
+ seriesOrder.forEach(seriesId => {
68
+ const {
69
+ data,
70
+ xAxisKey,
71
+ yAxisKey
72
+ } = series[seriesId];
73
+ const xScale = xAxis[xAxisKey ?? defaultXAxisId].scale;
74
+ const yScale = yAxis[yAxisKey ?? defaultYAxisId].scale;
75
+ const getXPosition = (0, _useScale.getValueToPositionMapper)(xScale);
76
+ const getYPosition = (0, _useScale.getValueToPositionMapper)(yScale);
77
+ const seriesPoints = data.flatMap(({
78
+ x,
79
+ y
80
+ }) => [getXPosition(x), getYPosition(y)]);
81
+ voronoiRef.current[seriesId] = {
82
+ startIndex: points.length,
83
+ endIndex: points.length + seriesPoints.length
84
+ };
85
+ points = points.concat(seriesPoints);
86
+ });
87
+ voronoiRef.current.delauney = new _d3Delaunay.Delaunay(points);
88
+ }, [defaultXAxisId, defaultYAxisId, series, seriesOrder, xAxis, yAxis]);
89
+ React.useEffect(() => {
90
+ const element = svgRef.current;
91
+ if (element === null) {
92
+ return undefined;
93
+ }
94
+ const handleMouseOut = () => {
95
+ dispatch({
96
+ type: 'exitChart'
97
+ });
98
+ };
99
+
100
+ // TODO: A perf optimisation of voronoi could be to use the last point as the intial point for the next search.
101
+ const handleMouseMove = event => {
102
+ // Get mouse coordinate in global SVG space
103
+ const svgPoint = (0, _utils.getSVGPoint)(svgRef.current, event);
104
+ const outsideX = svgPoint.x < left || svgPoint.x > left + width;
105
+ const outsideY = svgPoint.y < top || svgPoint.y > top + height;
106
+ if (outsideX || outsideY) {
107
+ dispatch({
108
+ type: 'exitChart'
109
+ });
110
+ return;
111
+ }
112
+ if (!voronoiRef.current.delauney) {
113
+ return;
114
+ }
115
+ const closestPointIndex = voronoiRef.current.delauney?.find(svgPoint.x, svgPoint.y);
116
+ if (closestPointIndex !== undefined) {
117
+ const seriesId = Object.keys(voronoiRef.current).find(id => {
118
+ if (id === 'delauney') {
119
+ return false;
120
+ }
121
+ return 2 * closestPointIndex >= voronoiRef.current[id].startIndex && 2 * closestPointIndex < voronoiRef.current[id].endIndex;
122
+ });
123
+ if (seriesId === undefined) {
124
+ return;
125
+ }
126
+ const dataIndex = (2 * closestPointIndex - voronoiRef.current[seriesId].startIndex) / 2;
127
+ if (voronoiMaxRadius !== undefined) {
128
+ const pointX = voronoiRef.current.delauney.points[2 * closestPointIndex];
129
+ const pointY = voronoiRef.current.delauney.points[2 * closestPointIndex + 1];
130
+ const dist2 = (pointX - svgPoint.x) ** 2 + (pointY - svgPoint.y) ** 2;
131
+ if (dist2 > voronoiMaxRadius ** 2) {
132
+ // The closest point is too far to be considered.
133
+ dispatch({
134
+ type: 'leaveItem',
135
+ data: {
136
+ type: 'scatter',
137
+ seriesId,
138
+ dataIndex
139
+ }
140
+ });
141
+ return;
142
+ }
143
+ }
144
+ dispatch({
145
+ type: 'enterItem',
146
+ data: {
147
+ type: 'scatter',
148
+ seriesId,
149
+ dataIndex
150
+ }
151
+ });
152
+ }
153
+ };
154
+ element.addEventListener('mouseout', handleMouseOut);
155
+ element.addEventListener('mousemove', handleMouseMove);
156
+ return () => {
157
+ element.removeEventListener('mouseout', handleMouseOut);
158
+ element.removeEventListener('mousemove', handleMouseMove);
159
+ };
160
+ }, [svgRef, dispatch, left, width, top, height, yAxis, xAxis, voronoiMaxRadius]);
161
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("g", {}); // Workaround to fix docs scripts
162
+ }
163
+ process.env.NODE_ENV !== "production" ? ChartsVoronoiHandler.propTypes = {
164
+ // ----------------------------- Warning --------------------------------
165
+ // | These PropTypes are generated from the TypeScript type definitions |
166
+ // | To update them edit the TypeScript types and run "yarn proptypes" |
167
+ // ----------------------------------------------------------------------
168
+ /**
169
+ * Defines the maximal distance between a scatter point and the pointer that triggers the interaction.
170
+ * If `undefined`, the radius is assumed to be infinite.
171
+ * @default undefined
172
+ */
173
+ voronoiMaxRadius: _propTypes.default.number
174
+ } : void 0;
@@ -0,0 +1 @@
1
+ export * from './ChartsVoronoiHandler';
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _ChartsVoronoiHandler = require("./ChartsVoronoiHandler");
7
+ Object.keys(_ChartsVoronoiHandler).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _ChartsVoronoiHandler[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _ChartsVoronoiHandler[key];
14
+ }
15
+ });
16
+ });
@@ -0,0 +1,6 @@
1
+ {
2
+ "sideEffects": false,
3
+ "module": "../esm/ChartsVoronoiHandler/index.js",
4
+ "main": "./index.js",
5
+ "types": "./index.d.ts"
6
+ }
@@ -17,9 +17,10 @@ var _DrawingProvider = require("../context/DrawingProvider");
17
17
  var _useTicks = _interopRequireDefault(require("../hooks/useTicks"));
18
18
  var _axisClasses = require("../ChartsAxis/axisClasses");
19
19
  var _AxisSharedComponents = require("../internals/components/AxisSharedComponents");
20
- var _ChartsText = require("../internals/components/ChartsText");
20
+ var _ChartsText = require("../ChartsText");
21
21
  var _geometry = require("../internals/geometry");
22
22
  var _useMounted = require("../hooks/useMounted");
23
+ var _getWordsByLines = require("../internals/getWordsByLines");
23
24
  var _jsxRuntime = require("react/jsx-runtime");
24
25
  const _excluded = ["scale", "tickNumber"];
25
26
  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); }
@@ -51,7 +52,7 @@ function addLabelDimension(xTicks, {
51
52
  height: 0
52
53
  });
53
54
  }
54
- const tickSizes = (0, _ChartsText.getWordsByLines)({
55
+ const tickSizes = (0, _getWordsByLines.getWordsByLines)({
55
56
  style,
56
57
  needsComputation: true,
57
58
  text: tick.formattedValue
@@ -16,7 +16,7 @@ var _CartesianContextProvider = require("../context/CartesianContextProvider");
16
16
  var _DrawingProvider = require("../context/DrawingProvider");
17
17
  var _useTicks = _interopRequireDefault(require("../hooks/useTicks"));
18
18
  var _AxisSharedComponents = require("../internals/components/AxisSharedComponents");
19
- var _ChartsText = require("../internals/components/ChartsText");
19
+ var _ChartsText = require("../ChartsText");
20
20
  var _axisClasses = require("../ChartsAxis/axisClasses");
21
21
  var _jsxRuntime = require("react/jsx-runtime");
22
22
  const _excluded = ["scale", "tickNumber"];
@@ -15,6 +15,7 @@ var _CartesianContextProvider = require("../context/CartesianContextProvider");
15
15
  var _AreaElement = require("./AreaElement");
16
16
  var _useScale = require("../hooks/useScale");
17
17
  var _getCurve = _interopRequireDefault(require("../internals/getCurve"));
18
+ var _constants = require("../constants");
18
19
  var _jsxRuntime = require("react/jsx-runtime");
19
20
  const _excluded = ["slots", "slotProps"];
20
21
  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); }
@@ -70,10 +71,10 @@ function AreaPlot(props) {
70
71
  const xData = xAxis[xAxisKey].data;
71
72
  if (process.env.NODE_ENV !== 'production') {
72
73
  if (xData === undefined) {
73
- throw new Error(`Axis of id "${xAxisKey}" should have data property to be able to display a line plot.`);
74
+ throw new Error(`MUI-X-Charts: ${xAxisKey === _constants.DEFAULT_X_AXIS_KEY ? 'The first `xAxis`' : `The x-axis with id "${xAxisKey}"`} should have data property to be able to display a line plot.`);
74
75
  }
75
76
  if (xData.length < stackedData.length) {
76
- throw new Error(`MUI: data length of the x axis (${xData.length} items) is lower than the length of series (${stackedData.length} items)`);
77
+ throw new Error(`MUI-X-Charts: The data length of the x axis (${xData.length} items) is lower than the length of series (${stackedData.length} items)`);
77
78
  }
78
79
  }
79
80
  const areaPath = (0, _d3Shape.area)().x(d => xScale(d.x)).defined((_, i) => connectNulls || data[i] != null).y0(d => d.y && yScale(d.y[0])).y1(d => d.y && yScale(d.y[1]));
@@ -14,6 +14,7 @@ var _CartesianContextProvider = require("../context/CartesianContextProvider");
14
14
  var _LineHighlightElement = require("./LineHighlightElement");
15
15
  var _useScale = require("../hooks/useScale");
16
16
  var _InteractionProvider = require("../context/InteractionProvider");
17
+ var _constants = require("../constants");
17
18
  var _jsxRuntime = require("react/jsx-runtime");
18
19
  const _excluded = ["slots", "slotProps"];
19
20
  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); }
@@ -78,7 +79,7 @@ function LineHighlightPlot(props) {
78
79
  const yScale = yAxis[yAxisKey].scale;
79
80
  const xData = xAxis[xAxisKey].data;
80
81
  if (xData === undefined) {
81
- throw new Error(`Axis of id "${xAxisKey}" should have data property to be able to display a line plot.`);
82
+ throw new Error(`MUI-X-Charts: ${xAxisKey === _constants.DEFAULT_X_AXIS_KEY ? 'The first `xAxis`' : `The x-axis with id "${xAxisKey}"`} should have data property to be able to display a line plot.`);
82
83
  }
83
84
  const x = xScale(xData[highlightedIndex]);
84
85
  const y = yScale(stackedData[highlightedIndex][1]); // This should not be undefined since y should not be a band scale
@@ -15,6 +15,7 @@ var _CartesianContextProvider = require("../context/CartesianContextProvider");
15
15
  var _LineElement = require("./LineElement");
16
16
  var _useScale = require("../hooks/useScale");
17
17
  var _getCurve = _interopRequireDefault(require("../internals/getCurve"));
18
+ var _constants = require("../constants");
18
19
  var _jsxRuntime = require("react/jsx-runtime");
19
20
  const _excluded = ["slots", "slotProps"];
20
21
  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); }
@@ -69,10 +70,10 @@ function LinePlot(props) {
69
70
  const xData = xAxis[xAxisKey].data;
70
71
  if (process.env.NODE_ENV !== 'production') {
71
72
  if (xData === undefined) {
72
- throw new Error(`Axis of id "${xAxisKey}" should have data property to be able to display a line plot`);
73
+ throw new Error(`MUI-X-Charts: ${xAxisKey === _constants.DEFAULT_X_AXIS_KEY ? 'The first `xAxis`' : `The x-axis with id "${xAxisKey}"`} should have data property to be able to display a line plot`);
73
74
  }
74
75
  if (xData.length < stackedData.length) {
75
- throw new Error(`MUI: data length of the x axis (${xData.length} items) is lower than the length of series (${stackedData.length} items)`);
76
+ throw new Error(`MUI-X-Charts: The data length of the x axis (${xData.length} items) is lower than the length of series (${stackedData.length} items)`);
76
77
  }
77
78
  }
78
79
  const linePath = (0, _d3Shape.line)().x(d => xScale(d.x)).defined((_, i) => connectNulls || data[i] != null).y(d => yScale(d.y[1]));
@@ -13,6 +13,7 @@ var _SeriesContextProvider = require("../context/SeriesContextProvider");
13
13
  var _CartesianContextProvider = require("../context/CartesianContextProvider");
14
14
  var _MarkElement = require("./MarkElement");
15
15
  var _useScale = require("../hooks/useScale");
16
+ var _constants = require("../constants");
16
17
  var _jsxRuntime = require("react/jsx-runtime");
17
18
  const _excluded = ["slots", "slotProps"];
18
19
  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); }
@@ -84,7 +85,7 @@ function MarkPlot(props) {
84
85
  return true;
85
86
  };
86
87
  if (xData === undefined) {
87
- throw new Error(`Axis of id "${xAxisKey}" should have data property to be able to display a line plot`);
88
+ throw new Error(`MUI-X-Charts: ${xAxisKey === _constants.DEFAULT_X_AXIS_KEY ? 'The first `xAxis`' : `The x-axis with id "${xAxisKey}"`} should have data property to be able to display a line plot`);
88
89
  }
89
90
  return xData?.map((x, index) => {
90
91
  const value = data[index] == null ? null : stackedData[index][1];
@@ -9,6 +9,8 @@ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")
9
9
  var _d3Shape = require("d3-shape");
10
10
  var _stackSeries = require("../internals/stackSeries");
11
11
  var _defaultizeValueFormatter = _interopRequireDefault(require("../internals/defaultizeValueFormatter"));
12
+ let warnedOnce = false;
13
+
12
14
  // For now it's a copy past of bar charts formatter, but maybe will diverge later
13
15
  const formatter = (params, dataset) => {
14
16
  const {
@@ -32,7 +34,7 @@ const formatter = (params, dataset) => {
32
34
  }
33
35
  });
34
36
  } else if (dataset === undefined && process.env.NODE_ENV !== 'production') {
35
- throw new Error([`MUI: line series with id='${id}' has no data.`, 'Either provide a data property to the series or use the dataset prop.'].join('\n'));
37
+ throw new Error([`MUI-X-Charts: line series with id='${id}' has no data.`, 'Either provide a data property to the series or use the dataset prop.'].join('\n'));
36
38
  }
37
39
  });
38
40
  const completedSeries = {};
@@ -52,7 +54,17 @@ const formatter = (params, dataset) => {
52
54
  ids.forEach((id, index) => {
53
55
  const dataKey = series[id].dataKey;
54
56
  completedSeries[id] = (0, _extends2.default)({}, series[id], {
55
- data: dataKey ? dataset.map(d => d[dataKey]) : series[id].data,
57
+ data: dataKey ? dataset.map(data => {
58
+ const value = data[dataKey];
59
+ if (typeof value !== 'number') {
60
+ if (process.env.NODE_ENV !== 'production' && !warnedOnce && value !== null) {
61
+ warnedOnce = true;
62
+ console.error([`MUI-X charts: your dataset key "${dataKey}" is used for plotting line, but contains nonnumerical elements.`, 'Line plots only support numbers and null values.']);
63
+ }
64
+ return 0;
65
+ }
66
+ return value;
67
+ }) : series[id].data,
56
68
  stackedData: stackedSeries[index].map(([a, b]) => [a, b])
57
69
  });
58
70
  });
@@ -1,14 +1,13 @@
1
1
  import * as React from 'react';
2
- import { DefaultizedPieSeriesType } from '../models/seriesType/pie';
2
+ import { ComputedPieRadius, DefaultizedPieSeriesType } from '../models/seriesType/pie';
3
3
  import { PieArcLabelProps } from './PieArcLabel';
4
- import { DefaultizedProps } from '../models/helpers';
5
4
  export interface PieArcLabelPlotSlots {
6
5
  pieArcLabel?: React.JSXElementConstructor<PieArcLabelProps>;
7
6
  }
8
7
  export interface PieArcLabelPlotSlotProps {
9
8
  pieArcLabel?: Partial<PieArcLabelProps>;
10
9
  }
11
- export interface PieArcLabelPlotProps extends DefaultizedProps<Pick<DefaultizedPieSeriesType, 'data' | 'faded' | 'highlighted' | 'innerRadius' | 'outerRadius' | 'cornerRadius' | 'paddingAngle' | 'arcLabel' | 'arcLabelMinAngle' | 'id' | 'highlightScope'>, 'outerRadius'> {
10
+ export interface PieArcLabelPlotProps extends Pick<DefaultizedPieSeriesType, 'data' | 'faded' | 'highlighted' | 'cornerRadius' | 'paddingAngle' | 'arcLabel' | 'arcLabelMinAngle' | 'id' | 'highlightScope'>, ComputedPieRadius {
12
11
  /**
13
12
  * Overridable component slots.
14
13
  * @default {}
@@ -161,7 +161,6 @@ process.env.NODE_ENV !== "production" ? PieArcLabelPlot.propTypes = {
161
161
  innerRadius: _propTypes.default.number,
162
162
  /**
163
163
  * The radius between circle center and the end of the arc.
164
- * @default R_max The maximal radius that fit into the drawing area.
165
164
  */
166
165
  outerRadius: _propTypes.default.number.isRequired,
167
166
  /**
@@ -1,14 +1,13 @@
1
1
  import * as React from 'react';
2
2
  import { PieArcProps } from './PieArc';
3
- import { DefaultizedPieSeriesType, DefaultizedPieValueType, PieItemIdentifier } from '../models/seriesType/pie';
4
- import { DefaultizedProps } from '../models/helpers';
3
+ import { ComputedPieRadius, DefaultizedPieSeriesType, DefaultizedPieValueType, PieItemIdentifier } from '../models/seriesType/pie';
5
4
  export interface PieArcPlotSlots {
6
5
  pieArc?: React.JSXElementConstructor<PieArcProps>;
7
6
  }
8
7
  export interface PieArcPlotSlotProps {
9
8
  pieArc?: Partial<PieArcProps>;
10
9
  }
11
- export interface PieArcPlotProps extends DefaultizedProps<Pick<DefaultizedPieSeriesType, 'data' | 'faded' | 'highlighted' | 'innerRadius' | 'outerRadius' | 'cornerRadius' | 'paddingAngle' | 'id' | 'highlightScope'>, 'outerRadius'> {
10
+ export interface PieArcPlotProps extends Pick<DefaultizedPieSeriesType, 'data' | 'faded' | 'highlighted' | 'cornerRadius' | 'paddingAngle' | 'id' | 'highlightScope'>, ComputedPieRadius {
12
11
  /**
13
12
  * Overridable component slots.
14
13
  * @default {}
@@ -153,7 +153,6 @@ process.env.NODE_ENV !== "production" ? PieArcPlot.propTypes = {
153
153
  onClick: _propTypes.default.func,
154
154
  /**
155
155
  * The radius between circle center and the end of the arc.
156
- * @default R_max The maximal radius that fit into the drawing area.
157
156
  */
158
157
  outerRadius: _propTypes.default.number.isRequired,
159
158
  /**
@@ -248,8 +248,8 @@ process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
248
248
  arcLabelMinAngle: _propTypes.default.number,
249
249
  color: _propTypes.default.string,
250
250
  cornerRadius: _propTypes.default.number,
251
- cx: _propTypes.default.number,
252
- cy: _propTypes.default.number,
251
+ cx: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]),
252
+ cy: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]),
253
253
  data: _propTypes.default.arrayOf(_propTypes.default.shape({
254
254
  color: _propTypes.default.string,
255
255
  id: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]),
@@ -278,8 +278,8 @@ process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
278
278
  highlighted: _propTypes.default.oneOf(['item', 'none', 'series'])
279
279
  }),
280
280
  id: _propTypes.default.string,
281
- innerRadius: _propTypes.default.number,
282
- outerRadius: _propTypes.default.number,
281
+ innerRadius: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]),
282
+ outerRadius: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]),
283
283
  paddingAngle: _propTypes.default.number,
284
284
  sortingValues: _propTypes.default.oneOfType([_propTypes.default.oneOf(['asc', 'desc', 'none']), _propTypes.default.func]),
285
285
  startAngle: _propTypes.default.number,
@@ -11,6 +11,7 @@ var _SeriesContextProvider = require("../context/SeriesContextProvider");
11
11
  var _DrawingProvider = require("../context/DrawingProvider");
12
12
  var _PieArcPlot = require("./PieArcPlot");
13
13
  var _PieArcLabelPlot = require("./PieArcLabelPlot");
14
+ var _utils = require("../internals/utils");
14
15
  var _jsxRuntime = require("react/jsx-runtime");
15
16
  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); }
16
17
  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; }
@@ -42,10 +43,6 @@ function PiePlot(props) {
42
43
  return null;
43
44
  }
44
45
  const availableRadius = Math.min(width, height) / 2;
45
- const center = {
46
- x: left + width / 2,
47
- y: top + height / 2
48
- };
49
46
  const {
50
47
  series,
51
48
  seriesOrder
@@ -53,22 +50,26 @@ function PiePlot(props) {
53
50
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)("g", {
54
51
  children: [seriesOrder.map(seriesId => {
55
52
  const {
56
- innerRadius,
57
- outerRadius,
53
+ innerRadius: innerRadiusParam,
54
+ outerRadius: outerRadiusParam,
58
55
  cornerRadius,
59
56
  paddingAngle,
60
57
  data,
61
- cx,
62
- cy,
58
+ cx: cxParam,
59
+ cy: cyParam,
63
60
  highlighted,
64
61
  faded,
65
62
  highlightScope
66
63
  } = series[seriesId];
64
+ const outerRadius = (0, _utils.getPercentageValue)(outerRadiusParam ?? availableRadius, availableRadius);
65
+ const innerRadius = (0, _utils.getPercentageValue)(innerRadiusParam ?? 0, availableRadius);
66
+ const cx = (0, _utils.getPercentageValue)(cxParam ?? '50%', width);
67
+ const cy = (0, _utils.getPercentageValue)(cyParam ?? '50%', height);
67
68
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("g", {
68
- transform: `translate(${cx === undefined ? center.x : left + cx}, ${cy === undefined ? center.y : top + cy})`,
69
+ transform: `translate(${left + cx}, ${top + cy})`,
69
70
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_PieArcPlot.PieArcPlot, {
70
71
  innerRadius: innerRadius,
71
- outerRadius: outerRadius ?? availableRadius,
72
+ outerRadius: outerRadius,
72
73
  cornerRadius: cornerRadius,
73
74
  paddingAngle: paddingAngle,
74
75
  id: seriesId,
@@ -84,19 +85,23 @@ function PiePlot(props) {
84
85
  }, seriesId);
85
86
  }), seriesOrder.map(seriesId => {
86
87
  const {
87
- innerRadius,
88
- outerRadius,
88
+ innerRadius: innerRadiusParam,
89
+ outerRadius: outerRadiusParam,
89
90
  cornerRadius,
90
91
  paddingAngle,
91
92
  arcLabel,
92
93
  arcLabelMinAngle,
93
94
  data,
94
- cx,
95
- cy,
95
+ cx: cxParam,
96
+ cy: cyParam,
96
97
  highlightScope
97
98
  } = series[seriesId];
99
+ const outerRadius = (0, _utils.getPercentageValue)(outerRadiusParam ?? availableRadius, availableRadius);
100
+ const innerRadius = (0, _utils.getPercentageValue)(innerRadiusParam ?? 0, availableRadius);
101
+ const cx = (0, _utils.getPercentageValue)(cxParam ?? '50%', width);
102
+ const cy = (0, _utils.getPercentageValue)(cyParam ?? '50%', height);
98
103
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("g", {
99
- transform: `translate(${cx === undefined ? center.x : left + cx}, ${cy === undefined ? center.y : top + cy})`,
104
+ transform: `translate(${left + cx}, ${top + cy})`,
100
105
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_PieArcLabelPlot.PieArcLabelPlot, {
101
106
  innerRadius: innerRadius,
102
107
  outerRadius: outerRadius ?? availableRadius,