@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
@@ -0,0 +1,167 @@
1
+ import * as React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import clsx from 'clsx';
4
+ import Typography from '@mui/material/Typography';
5
+ import { ChartsTooltipCell, ChartsTooltipPaper, ChartsTooltipTable, ChartsTooltipMark, ChartsTooltipRow } from './ChartsTooltipTable';
6
+ import { jsx as _jsx } from "react/jsx-runtime";
7
+ import { jsxs as _jsxs } from "react/jsx-runtime";
8
+ function DefaultChartsAxisTooltipContent(props) {
9
+ const {
10
+ series,
11
+ axis,
12
+ dataIndex,
13
+ axisValue,
14
+ sx,
15
+ classes
16
+ } = props;
17
+ if (dataIndex == null) {
18
+ return null;
19
+ }
20
+ const axisFormatter = axis.valueFormatter ?? (v => v.toLocaleString());
21
+ return /*#__PURE__*/_jsx(ChartsTooltipPaper, {
22
+ sx: sx,
23
+ className: classes.root,
24
+ children: /*#__PURE__*/_jsxs(ChartsTooltipTable, {
25
+ className: classes.table,
26
+ children: [axisValue != null && !axis.hideTooltip && /*#__PURE__*/_jsx("thead", {
27
+ children: /*#__PURE__*/_jsx(ChartsTooltipRow, {
28
+ children: /*#__PURE__*/_jsx(ChartsTooltipCell, {
29
+ colSpan: 3,
30
+ children: /*#__PURE__*/_jsx(Typography, {
31
+ children: axisFormatter(axisValue)
32
+ })
33
+ })
34
+ })
35
+ }), /*#__PURE__*/_jsx("tbody", {
36
+ children: series.map(({
37
+ color,
38
+ id,
39
+ label,
40
+ valueFormatter,
41
+ data
42
+ }) => {
43
+ const formattedValue = valueFormatter(data[dataIndex]);
44
+ if (formattedValue == null) {
45
+ return null;
46
+ }
47
+ return /*#__PURE__*/_jsxs(ChartsTooltipRow, {
48
+ className: classes.row,
49
+ children: [/*#__PURE__*/_jsx(ChartsTooltipCell, {
50
+ className: clsx(classes.markCell, classes.cell),
51
+ children: /*#__PURE__*/_jsx(ChartsTooltipMark, {
52
+ ownerState: {
53
+ color
54
+ },
55
+ boxShadow: 1,
56
+ className: classes.mark
57
+ })
58
+ }), /*#__PURE__*/_jsx(ChartsTooltipCell, {
59
+ className: clsx(classes.labelCell, classes.cell),
60
+ children: label ? /*#__PURE__*/_jsx(Typography, {
61
+ children: label
62
+ }) : null
63
+ }), /*#__PURE__*/_jsx(ChartsTooltipCell, {
64
+ className: clsx(classes.valueCell, classes.cell),
65
+ children: /*#__PURE__*/_jsx(Typography, {
66
+ children: formattedValue
67
+ })
68
+ })]
69
+ }, id);
70
+ })
71
+ })]
72
+ })
73
+ });
74
+ }
75
+ process.env.NODE_ENV !== "production" ? DefaultChartsAxisTooltipContent.propTypes = {
76
+ // ----------------------------- Warning --------------------------------
77
+ // | These PropTypes are generated from the TypeScript type definitions |
78
+ // | To update them edit the TypeScript types and run "yarn proptypes" |
79
+ // ----------------------------------------------------------------------
80
+ /**
81
+ * The properties of the triggered axis.
82
+ */
83
+ axis: PropTypes.shape({
84
+ axisId: PropTypes.string,
85
+ classes: PropTypes.object,
86
+ data: PropTypes.array,
87
+ dataKey: PropTypes.string,
88
+ disableLine: PropTypes.bool,
89
+ disableTicks: PropTypes.bool,
90
+ fill: PropTypes.string,
91
+ hideTooltip: PropTypes.bool,
92
+ id: PropTypes.string.isRequired,
93
+ label: PropTypes.string,
94
+ labelFontSize: PropTypes.number,
95
+ labelStyle: PropTypes.object,
96
+ max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
97
+ min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
98
+ position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
99
+ scale: PropTypes.func.isRequired,
100
+ scaleType: PropTypes.oneOf(['time']).isRequired,
101
+ slotProps: PropTypes.object,
102
+ slots: PropTypes.object,
103
+ stroke: PropTypes.string,
104
+ tickFontSize: PropTypes.number,
105
+ tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
106
+ tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
107
+ tickLabelStyle: PropTypes.object,
108
+ tickMaxStep: PropTypes.number,
109
+ tickMinStep: PropTypes.number,
110
+ tickNumber: PropTypes.number.isRequired,
111
+ tickSize: PropTypes.number,
112
+ valueFormatter: PropTypes.func
113
+ }).isRequired,
114
+ /**
115
+ * Data identifying the triggered axis.
116
+ */
117
+ axisData: PropTypes.shape({
118
+ x: PropTypes.shape({
119
+ index: PropTypes.number,
120
+ value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired
121
+ }),
122
+ y: PropTypes.shape({
123
+ index: PropTypes.number,
124
+ value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired
125
+ })
126
+ }).isRequired,
127
+ /**
128
+ * The value associated to the current mouse position.
129
+ */
130
+ axisValue: PropTypes.any.isRequired,
131
+ /**
132
+ * Override or extend the styles applied to the component.
133
+ */
134
+ classes: PropTypes.object.isRequired,
135
+ /**
136
+ * The index of the data item triggered.
137
+ */
138
+ dataIndex: PropTypes.number,
139
+ /**
140
+ * The series linked to the triggered axis.
141
+ */
142
+ series: PropTypes.arrayOf(PropTypes.shape({
143
+ area: PropTypes.bool,
144
+ color: PropTypes.string.isRequired,
145
+ connectNulls: PropTypes.bool,
146
+ curve: PropTypes.oneOf(['catmullRom', 'linear', 'monotoneX', 'monotoneY', 'natural', 'step', 'stepAfter', 'stepBefore']),
147
+ data: PropTypes.arrayOf(PropTypes.number).isRequired,
148
+ dataKey: PropTypes.string,
149
+ disableHighlight: PropTypes.bool,
150
+ highlightScope: PropTypes.shape({
151
+ faded: PropTypes.oneOf(['global', 'none', 'series']),
152
+ highlighted: PropTypes.oneOf(['item', 'none', 'series'])
153
+ }),
154
+ id: PropTypes.string.isRequired,
155
+ label: PropTypes.string,
156
+ showMark: PropTypes.oneOfType([PropTypes.func, PropTypes.bool]),
157
+ stack: PropTypes.string,
158
+ stackOffset: PropTypes.oneOf(['diverging', 'expand', 'none', 'silhouette', 'wiggle']),
159
+ stackOrder: PropTypes.oneOf(['appearance', 'ascending', 'descending', 'insideOut', 'none', 'reverse']),
160
+ type: PropTypes.oneOf(['line']).isRequired,
161
+ valueFormatter: PropTypes.func.isRequired,
162
+ xAxisKey: PropTypes.string,
163
+ yAxisKey: PropTypes.string
164
+ })).isRequired,
165
+ sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
166
+ } : void 0;
167
+ export { DefaultChartsAxisTooltipContent };
@@ -0,0 +1,92 @@
1
+ import * as React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import clsx from 'clsx';
4
+ import { ChartsTooltipTable, ChartsTooltipCell, ChartsTooltipMark, ChartsTooltipPaper, ChartsTooltipRow } from './ChartsTooltipTable';
5
+ import { jsx as _jsx } from "react/jsx-runtime";
6
+ import { jsxs as _jsxs } from "react/jsx-runtime";
7
+ function DefaultChartsItemTooltipContent(props) {
8
+ const {
9
+ series,
10
+ itemData,
11
+ sx,
12
+ classes
13
+ } = props;
14
+ if (itemData.dataIndex === undefined) {
15
+ return null;
16
+ }
17
+ const {
18
+ displayedLabel,
19
+ color
20
+ } = series.type === 'pie' ? {
21
+ color: series.data[itemData.dataIndex].color,
22
+ displayedLabel: series.data[itemData.dataIndex].label
23
+ } : {
24
+ color: series.color,
25
+ displayedLabel: series.label
26
+ };
27
+
28
+ // TODO: Manage to let TS understand series.data and series.valueFormatter are coherent
29
+ // @ts-ignore
30
+ const formattedValue = series.valueFormatter(series.data[itemData.dataIndex]);
31
+ return /*#__PURE__*/_jsx(ChartsTooltipPaper, {
32
+ sx: sx,
33
+ className: classes.root,
34
+ children: /*#__PURE__*/_jsx(ChartsTooltipTable, {
35
+ className: classes.table,
36
+ children: /*#__PURE__*/_jsx("tbody", {
37
+ children: /*#__PURE__*/_jsxs(ChartsTooltipRow, {
38
+ className: classes.row,
39
+ children: [/*#__PURE__*/_jsx(ChartsTooltipCell, {
40
+ className: clsx(classes.markCell, classes.cell),
41
+ children: /*#__PURE__*/_jsx(ChartsTooltipMark, {
42
+ ownerState: {
43
+ color
44
+ },
45
+ className: classes.mark
46
+ })
47
+ }), /*#__PURE__*/_jsx(ChartsTooltipCell, {
48
+ className: clsx(classes.labelCell, classes.cell),
49
+ children: displayedLabel
50
+ }), /*#__PURE__*/_jsx(ChartsTooltipCell, {
51
+ className: clsx(classes.valueCell, classes.cell),
52
+ children: formattedValue
53
+ })]
54
+ })
55
+ })
56
+ })
57
+ });
58
+ }
59
+ process.env.NODE_ENV !== "production" ? DefaultChartsItemTooltipContent.propTypes = {
60
+ // ----------------------------- Warning --------------------------------
61
+ // | These PropTypes are generated from the TypeScript type definitions |
62
+ // | To update them edit the TypeScript types and run "yarn proptypes" |
63
+ // ----------------------------------------------------------------------
64
+ /**
65
+ * Override or extend the styles applied to the component.
66
+ */
67
+ classes: PropTypes.object.isRequired,
68
+ /**
69
+ * The data used to identify the triggered item.
70
+ */
71
+ itemData: PropTypes.shape({
72
+ dataIndex: PropTypes.number,
73
+ seriesId: PropTypes.string.isRequired,
74
+ type: PropTypes.oneOf(['bar', 'line', 'pie', 'scatter']).isRequired
75
+ }).isRequired,
76
+ /**
77
+ * The series linked to the triggered axis.
78
+ */
79
+ series: PropTypes.shape({
80
+ color: PropTypes.string,
81
+ data: PropTypes.arrayOf(PropTypes.number).isRequired,
82
+ highlightScope: PropTypes.shape({
83
+ faded: PropTypes.oneOf(['global', 'none', 'series']),
84
+ highlighted: PropTypes.oneOf(['item', 'none', 'series'])
85
+ }),
86
+ id: PropTypes.string.isRequired,
87
+ type: PropTypes.oneOf(['bar', 'line', 'pie', 'scatter']).isRequired,
88
+ valueFormatter: PropTypes.func.isRequired
89
+ }).isRequired,
90
+ sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
91
+ } : void 0;
92
+ export { DefaultChartsItemTooltipContent };
@@ -1,2 +1,6 @@
1
1
  export * from './ChartsTooltip';
2
- export * from './chartsTooltipClasses';
2
+ export * from './chartsTooltipClasses';
3
+ export * from './ChartsAxisTooltipContent';
4
+ export * from './ChartsItemTooltipContent';
5
+ export * from './DefaultChartsAxisTooltipContent';
6
+ export * from './DefaultChartsItemTooltipContent';
@@ -0,0 +1,166 @@
1
+ import * as React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import { Delaunay } from 'd3-delaunay';
4
+ import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
5
+ import { InteractionContext } from '../context/InteractionProvider';
6
+ import { CartesianContext } from '../context/CartesianContextProvider';
7
+ import { SVGContext, DrawingContext } from '../context/DrawingProvider';
8
+ import { SeriesContext } from '../context/SeriesContextProvider';
9
+ import { getValueToPositionMapper } from '../hooks/useScale';
10
+ import { getSVGPoint } from '../internals/utils';
11
+ import { jsx as _jsx } from "react/jsx-runtime";
12
+ function ChartsVoronoiHandler(props) {
13
+ const {
14
+ voronoiMaxRadius
15
+ } = props;
16
+ const svgRef = React.useContext(SVGContext);
17
+ const {
18
+ width,
19
+ height,
20
+ top,
21
+ left
22
+ } = React.useContext(DrawingContext);
23
+ const {
24
+ xAxis,
25
+ yAxis,
26
+ xAxisIds,
27
+ yAxisIds
28
+ } = React.useContext(CartesianContext);
29
+ const {
30
+ dispatch
31
+ } = React.useContext(InteractionContext);
32
+ const {
33
+ series,
34
+ seriesOrder
35
+ } = React.useContext(SeriesContext).scatter ?? {};
36
+ const voronoiRef = React.useRef({});
37
+ const defaultXAxisId = xAxisIds[0];
38
+ const defaultYAxisId = yAxisIds[0];
39
+ useEnhancedEffect(() => {
40
+ dispatch({
41
+ type: 'updateVoronoiUsage',
42
+ useVoronoiInteraction: true
43
+ });
44
+ return () => {
45
+ dispatch({
46
+ type: 'updateVoronoiUsage',
47
+ useVoronoiInteraction: false
48
+ });
49
+ };
50
+ }, [dispatch]);
51
+ useEnhancedEffect(() => {
52
+ if (seriesOrder === undefined || series === undefined) {
53
+ // If there is no scatter chart series
54
+ return;
55
+ }
56
+ voronoiRef.current = {};
57
+ let points = [];
58
+ seriesOrder.forEach(seriesId => {
59
+ const {
60
+ data,
61
+ xAxisKey,
62
+ yAxisKey
63
+ } = series[seriesId];
64
+ const xScale = xAxis[xAxisKey ?? defaultXAxisId].scale;
65
+ const yScale = yAxis[yAxisKey ?? defaultYAxisId].scale;
66
+ const getXPosition = getValueToPositionMapper(xScale);
67
+ const getYPosition = getValueToPositionMapper(yScale);
68
+ const seriesPoints = data.flatMap(({
69
+ x,
70
+ y
71
+ }) => [getXPosition(x), getYPosition(y)]);
72
+ voronoiRef.current[seriesId] = {
73
+ startIndex: points.length,
74
+ endIndex: points.length + seriesPoints.length
75
+ };
76
+ points = points.concat(seriesPoints);
77
+ });
78
+ voronoiRef.current.delauney = new Delaunay(points);
79
+ }, [defaultXAxisId, defaultYAxisId, series, seriesOrder, xAxis, yAxis]);
80
+ React.useEffect(() => {
81
+ const element = svgRef.current;
82
+ if (element === null) {
83
+ return undefined;
84
+ }
85
+ const handleMouseOut = () => {
86
+ dispatch({
87
+ type: 'exitChart'
88
+ });
89
+ };
90
+
91
+ // TODO: A perf optimisation of voronoi could be to use the last point as the intial point for the next search.
92
+ const handleMouseMove = event => {
93
+ // Get mouse coordinate in global SVG space
94
+ const svgPoint = getSVGPoint(svgRef.current, event);
95
+ const outsideX = svgPoint.x < left || svgPoint.x > left + width;
96
+ const outsideY = svgPoint.y < top || svgPoint.y > top + height;
97
+ if (outsideX || outsideY) {
98
+ dispatch({
99
+ type: 'exitChart'
100
+ });
101
+ return;
102
+ }
103
+ if (!voronoiRef.current.delauney) {
104
+ return;
105
+ }
106
+ const closestPointIndex = voronoiRef.current.delauney?.find(svgPoint.x, svgPoint.y);
107
+ if (closestPointIndex !== undefined) {
108
+ const seriesId = Object.keys(voronoiRef.current).find(id => {
109
+ if (id === 'delauney') {
110
+ return false;
111
+ }
112
+ return 2 * closestPointIndex >= voronoiRef.current[id].startIndex && 2 * closestPointIndex < voronoiRef.current[id].endIndex;
113
+ });
114
+ if (seriesId === undefined) {
115
+ return;
116
+ }
117
+ const dataIndex = (2 * closestPointIndex - voronoiRef.current[seriesId].startIndex) / 2;
118
+ if (voronoiMaxRadius !== undefined) {
119
+ const pointX = voronoiRef.current.delauney.points[2 * closestPointIndex];
120
+ const pointY = voronoiRef.current.delauney.points[2 * closestPointIndex + 1];
121
+ const dist2 = (pointX - svgPoint.x) ** 2 + (pointY - svgPoint.y) ** 2;
122
+ if (dist2 > voronoiMaxRadius ** 2) {
123
+ // The closest point is too far to be considered.
124
+ dispatch({
125
+ type: 'leaveItem',
126
+ data: {
127
+ type: 'scatter',
128
+ seriesId,
129
+ dataIndex
130
+ }
131
+ });
132
+ return;
133
+ }
134
+ }
135
+ dispatch({
136
+ type: 'enterItem',
137
+ data: {
138
+ type: 'scatter',
139
+ seriesId,
140
+ dataIndex
141
+ }
142
+ });
143
+ }
144
+ };
145
+ element.addEventListener('mouseout', handleMouseOut);
146
+ element.addEventListener('mousemove', handleMouseMove);
147
+ return () => {
148
+ element.removeEventListener('mouseout', handleMouseOut);
149
+ element.removeEventListener('mousemove', handleMouseMove);
150
+ };
151
+ }, [svgRef, dispatch, left, width, top, height, yAxis, xAxis, voronoiMaxRadius]);
152
+ return /*#__PURE__*/_jsx("g", {}); // Workaround to fix docs scripts
153
+ }
154
+ process.env.NODE_ENV !== "production" ? ChartsVoronoiHandler.propTypes = {
155
+ // ----------------------------- Warning --------------------------------
156
+ // | These PropTypes are generated from the TypeScript type definitions |
157
+ // | To update them edit the TypeScript types and run "yarn proptypes" |
158
+ // ----------------------------------------------------------------------
159
+ /**
160
+ * Defines the maximal distance between a scatter point and the pointer that triggers the interaction.
161
+ * If `undefined`, the radius is assumed to be infinite.
162
+ * @default undefined
163
+ */
164
+ voronoiMaxRadius: PropTypes.number
165
+ } : void 0;
166
+ export { ChartsVoronoiHandler };
@@ -0,0 +1 @@
1
+ export * from './ChartsVoronoiHandler';
@@ -74,6 +74,8 @@ function ChartsYAxis(inProps) {
74
74
  tickFontSize,
75
75
  label,
76
76
  labelFontSize,
77
+ labelStyle,
78
+ tickLabelStyle,
77
79
  tickSize: tickSizeProp,
78
80
  valueFormatter,
79
81
  slots,
@@ -108,11 +110,11 @@ function ChartsYAxis(inProps) {
108
110
  elementType: TickLabel,
109
111
  externalSlotProps: slotProps?.axisTickLabel,
110
112
  additionalProps: {
111
- style: {
113
+ style: _extends({
112
114
  fontSize: tickFontSize,
113
115
  textAnchor: position === 'right' ? 'start' : 'end',
114
116
  dominantBaseline: 'central'
115
- },
117
+ }, tickLabelStyle),
116
118
  className: classes.tickLabel
117
119
  },
118
120
  ownerState: {}
@@ -121,12 +123,12 @@ function ChartsYAxis(inProps) {
121
123
  elementType: Label,
122
124
  externalSlotProps: slotProps?.axisLabel,
123
125
  additionalProps: {
124
- style: {
126
+ style: _extends({
125
127
  fontSize: labelFontSize,
126
128
  angle: positionSign * 90,
127
129
  textAnchor: 'middle',
128
130
  dominantBaseline: 'auto'
129
- }
131
+ }, labelStyle)
130
132
  },
131
133
  ownerState: {}
132
134
  });
@@ -6,6 +6,18 @@ export const getExtremumX = params => {
6
6
  const maxX = Math.max(...(axis.data ?? []));
7
7
  return [minX, maxX];
8
8
  };
9
+ function getSeriesExtremums(getValues, stackedData) {
10
+ if (stackedData.length === 0) {
11
+ return [null, null];
12
+ }
13
+ return stackedData.reduce((seriesAcc, stackedValue) => {
14
+ const [base, value] = getValues(stackedValue);
15
+ if (seriesAcc[0] === null) {
16
+ return [Math.min(base, value), Math.max(base, value)];
17
+ }
18
+ return [Math.min(base, value, seriesAcc[0]), Math.max(base, value, seriesAcc[1])];
19
+ }, getValues(stackedData[0]));
20
+ }
9
21
  export const getExtremumY = params => {
10
22
  const {
11
23
  series,
@@ -13,16 +25,21 @@ export const getExtremumY = params => {
13
25
  isDefaultAxis
14
26
  } = params;
15
27
  return Object.keys(series).filter(seriesId => series[seriesId].yAxisKey === axis.id || isDefaultAxis && series[seriesId].yAxisKey === undefined).reduce((acc, seriesId) => {
16
- const isArea = series[seriesId].area !== undefined;
17
- const getValues = isArea ? d => d : d => [d[1], d[1]]; // Id area should go from bottom to top, without area should only consider the top
28
+ const {
29
+ area,
30
+ stackedData
31
+ } = series[seriesId];
32
+ const isArea = area !== undefined;
33
+ const getValues = isArea ? d => d : d => [d[1], d[1]]; // Since this series is not used to display an area, we do not consider the base (the d[0]).
18
34
 
19
- const [seriesMin, seriesMax] = series[seriesId].stackedData.reduce((seriesAcc, stackedValue) => {
20
- const [base, value] = getValues(stackedValue);
21
- return [Math.min(base, value, seriesAcc[0]), Math.max(base, value, seriesAcc[1])];
22
- }, getValues(series[seriesId].stackedData[0]));
23
- if (acc[0] === null || acc[1] === null) {
24
- return [seriesMin, seriesMax];
35
+ const seriesExtremums = getSeriesExtremums(getValues, stackedData);
36
+ if (acc[0] === null) {
37
+ return seriesExtremums;
38
+ }
39
+ if (seriesExtremums[0] === null) {
40
+ return acc;
25
41
  }
42
+ const [seriesMin, seriesMax] = seriesExtremums;
26
43
  return [Math.min(seriesMin, acc[0]), Math.max(seriesMax, acc[1])];
27
44
  }, [null, null]);
28
45
  };
@@ -1,8 +1,8 @@
1
+ export * from './LineChart';
1
2
  export * from './LinePlot';
2
3
  export * from './AreaPlot';
3
4
  export * from './MarkPlot';
4
5
  export * from './LineHighlightPlot';
5
- export * from './LineChart';
6
6
  export * from './AreaElement';
7
7
  export * from './LineElement';
8
8
  export * from './MarkElement';
@@ -2,6 +2,7 @@ import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
3
  const _excluded = ["id", "dataIndex", "classes", "color", "highlightScope", "onClick", "isFaded", "isHighlighted", "startAngle", "endAngle", "paddingAngle", "innerRadius", "outerRadius", "cornerRadius"];
4
4
  import * as React from 'react';
5
+ import PropTypes from 'prop-types';
5
6
  import { arc as d3Arc } from 'd3-shape';
6
7
  import { animated, to } from '@react-spring/web';
7
8
  import composeClasses from '@mui/utils/composeClasses';
@@ -37,7 +38,7 @@ const PieArcRoot = styled(animated.path, {
37
38
  strokeWidth: 1,
38
39
  strokeLinejoin: 'round'
39
40
  }));
40
- export default function PieArc(props) {
41
+ function PieArc(props) {
41
42
  const {
42
43
  id,
43
44
  dataIndex,
@@ -82,4 +83,19 @@ export default function PieArc(props) {
82
83
  seriesId: id,
83
84
  dataIndex
84
85
  })));
85
- }
86
+ }
87
+ process.env.NODE_ENV !== "production" ? PieArc.propTypes = {
88
+ // ----------------------------- Warning --------------------------------
89
+ // | These PropTypes are generated from the TypeScript type definitions |
90
+ // | To update them edit the TypeScript types and run "yarn proptypes" |
91
+ // ----------------------------------------------------------------------
92
+ classes: PropTypes.object,
93
+ dataIndex: PropTypes.number.isRequired,
94
+ highlightScope: PropTypes.shape({
95
+ faded: PropTypes.oneOf(['global', 'none', 'series']),
96
+ highlighted: PropTypes.oneOf(['item', 'none', 'series'])
97
+ }),
98
+ isFaded: PropTypes.bool.isRequired,
99
+ isHighlighted: PropTypes.bool.isRequired
100
+ } : void 0;
101
+ export { PieArc };
@@ -2,9 +2,9 @@ import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
3
  const _excluded = ["id", "classes", "color", "startAngle", "endAngle", "paddingAngle", "innerRadius", "outerRadius", "cornerRadius", "formattedArcLabel", "isHighlighted", "isFaded", "style"];
4
4
  import * as React from 'react';
5
+ import PropTypes from 'prop-types';
5
6
  import { animated, to } from '@react-spring/web';
6
7
  import { arc as d3Arc } from 'd3-shape';
7
- import PropTypes from 'prop-types';
8
8
  import composeClasses from '@mui/utils/composeClasses';
9
9
  import generateUtilityClass from '@mui/utils/generateUtilityClass';
10
10
  import { styled } from '@mui/material/styles';
@@ -57,7 +57,7 @@ const getLabelPosition = (formattedArcLabel, variable) => (startAngle, endAngle,
57
57
  }
58
58
  return y;
59
59
  };
60
- export default function PieArcLabel(props) {
60
+ function PieArcLabel(props) {
61
61
  const {
62
62
  id,
63
63
  classes: innerClasses,
@@ -98,12 +98,8 @@ process.env.NODE_ENV !== "production" ? PieArcLabel.propTypes = {
98
98
  // | To update them edit the TypeScript types and run "yarn proptypes" |
99
99
  // ----------------------------------------------------------------------
100
100
  classes: PropTypes.object,
101
- cornerRadius: PropTypes.number,
102
- dataIndex: PropTypes.number.isRequired,
103
- highlightScope: PropTypes.shape({
104
- faded: PropTypes.oneOf(['global', 'none', 'series']),
105
- highlighted: PropTypes.oneOf(['item', 'none', 'series'])
106
- }),
107
- innerRadius: PropTypes.number,
108
- outerRadius: PropTypes.number.isRequired
109
- } : void 0;
101
+ formattedArcLabel: PropTypes.string,
102
+ isFaded: PropTypes.bool.isRequired,
103
+ isHighlighted: PropTypes.bool.isRequired
104
+ } : void 0;
105
+ export { PieArcLabel };