@mui/x-charts 6.18.2 → 6.18.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 (190) hide show
  1. package/BarChart/BarElement.d.ts +5 -1
  2. package/BarChart/BarElement.js +24 -1
  3. package/BarChart/BarPlot.js +7 -6
  4. package/BarChart/formatter.js +15 -3
  5. package/BarChart/index.d.ts +3 -2
  6. package/BarChart/index.js +31 -12
  7. package/CHANGELOG.md +192 -1
  8. package/ChartsAxis/ChartsAxis.js +4 -4
  9. package/ChartsLegend/ChartsLegend.d.ts +1 -1
  10. package/ChartsLegend/ChartsLegend.js +3 -2
  11. package/ChartsLegend/index.d.ts +1 -0
  12. package/ChartsLegend/index.js +11 -0
  13. package/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
  14. package/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
  15. package/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
  16. package/ChartsReferenceLine/common.d.ts +1 -1
  17. package/ChartsText/ChartsText.d.ts +17 -0
  18. package/{internals/components → ChartsText}/ChartsText.js +32 -17
  19. package/ChartsText/index.d.ts +3 -0
  20. package/ChartsText/index.js +12 -0
  21. package/ChartsText/package.json +6 -0
  22. package/ChartsTooltip/ChartsAxisTooltipContent.d.ts +5 -2
  23. package/ChartsTooltip/ChartsAxisTooltipContent.js +93 -73
  24. package/ChartsTooltip/ChartsItemTooltipContent.d.ts +5 -2
  25. package/ChartsTooltip/ChartsItemTooltipContent.js +38 -57
  26. package/ChartsTooltip/DefaultChartsAxisTooltipContent.d.ts +7 -0
  27. package/ChartsTooltip/DefaultChartsAxisTooltipContent.js +174 -0
  28. package/ChartsTooltip/DefaultChartsItemTooltipContent.d.ts +8 -0
  29. package/ChartsTooltip/DefaultChartsItemTooltipContent.js +99 -0
  30. package/ChartsTooltip/index.d.ts +4 -0
  31. package/ChartsTooltip/index.js +44 -0
  32. package/ChartsXAxis/ChartsXAxis.js +3 -2
  33. package/ChartsYAxis/ChartsYAxis.js +7 -5
  34. package/LineChart/AreaPlot.js +3 -2
  35. package/LineChart/LineHighlightPlot.js +2 -1
  36. package/LineChart/LinePlot.js +3 -2
  37. package/LineChart/MarkPlot.js +2 -1
  38. package/LineChart/extremums.js +25 -8
  39. package/LineChart/formatter.js +14 -2
  40. package/LineChart/index.d.ts +5 -5
  41. package/LineChart/index.js +50 -41
  42. package/PieChart/PieArcLabelPlot.d.ts +7 -4
  43. package/PieChart/PieArcLabelPlot.js +88 -1
  44. package/PieChart/PieArcPlot.d.ts +7 -4
  45. package/PieChart/PieArcPlot.js +87 -1
  46. package/PieChart/PieChart.js +4 -4
  47. package/PieChart/PiePlot.js +20 -15
  48. package/PieChart/dataTransform/useTransformData.d.ts +2 -3
  49. package/PieChart/index.d.ts +6 -6
  50. package/PieChart/index.js +60 -46
  51. package/ResponsiveChartContainer/index.js +2 -2
  52. package/ScatterChart/Scatter.js +1 -1
  53. package/ScatterChart/index.d.ts +3 -3
  54. package/ScatterChart/index.js +31 -19
  55. package/context/CartesianContextProvider.js +2 -2
  56. package/context/SeriesContextProvider.js +1 -1
  57. package/esm/BarChart/BarElement.js +26 -2
  58. package/esm/BarChart/BarPlot.js +7 -5
  59. package/esm/BarChart/formatter.js +20 -4
  60. package/esm/BarChart/index.js +3 -2
  61. package/esm/ChartsAxis/ChartsAxis.js +4 -4
  62. package/esm/ChartsLegend/ChartsLegend.js +2 -1
  63. package/esm/ChartsLegend/index.js +2 -1
  64. package/esm/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
  65. package/esm/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
  66. package/esm/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
  67. package/esm/{internals/components → ChartsText}/ChartsText.js +33 -16
  68. package/esm/ChartsText/index.js +1 -0
  69. package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +95 -75
  70. package/esm/ChartsTooltip/ChartsItemTooltipContent.js +40 -58
  71. package/esm/ChartsTooltip/DefaultChartsAxisTooltipContent.js +168 -0
  72. package/esm/ChartsTooltip/DefaultChartsItemTooltipContent.js +92 -0
  73. package/esm/ChartsTooltip/index.js +5 -1
  74. package/esm/ChartsXAxis/ChartsXAxis.js +2 -1
  75. package/esm/ChartsYAxis/ChartsYAxis.js +7 -5
  76. package/esm/LineChart/AreaPlot.js +3 -2
  77. package/esm/LineChart/LineHighlightPlot.js +2 -1
  78. package/esm/LineChart/LinePlot.js +3 -2
  79. package/esm/LineChart/MarkPlot.js +2 -1
  80. package/esm/LineChart/extremums.js +25 -8
  81. package/esm/LineChart/formatter.js +16 -3
  82. package/esm/LineChart/index.js +5 -5
  83. package/esm/PieChart/PieArcLabelPlot.js +90 -2
  84. package/esm/PieChart/PieArcPlot.js +89 -2
  85. package/esm/PieChart/PieChart.js +4 -4
  86. package/esm/PieChart/PiePlot.js +20 -15
  87. package/esm/PieChart/index.js +6 -4
  88. package/esm/ResponsiveChartContainer/index.js +2 -2
  89. package/esm/ScatterChart/Scatter.js +1 -1
  90. package/esm/ScatterChart/index.js +3 -3
  91. package/esm/context/CartesianContextProvider.js +2 -2
  92. package/esm/context/SeriesContextProvider.js +1 -1
  93. package/esm/index.js +1 -0
  94. package/esm/internals/defaultizeValueFormatter.js +4 -3
  95. package/esm/internals/getWordsByLines.js +14 -0
  96. package/esm/internals/utils.js +40 -0
  97. package/index.d.ts +1 -0
  98. package/index.js +12 -1
  99. package/internals/defaultizeColor.d.ts +4 -4
  100. package/internals/defaultizeValueFormatter.d.ts +3 -1
  101. package/internals/defaultizeValueFormatter.js +3 -3
  102. package/internals/{components/ChartsText.d.ts → getWordsByLines.d.ts} +2 -11
  103. package/internals/getWordsByLines.js +21 -0
  104. package/internals/utils.d.ts +13 -0
  105. package/internals/utils.js +42 -0
  106. package/legacy/BarChart/BarElement.js +26 -2
  107. package/legacy/BarChart/BarPlot.js +7 -5
  108. package/legacy/BarChart/formatter.js +23 -9
  109. package/legacy/BarChart/index.js +3 -2
  110. package/legacy/ChartsAxis/ChartsAxis.js +4 -4
  111. package/legacy/ChartsLegend/ChartsLegend.js +2 -1
  112. package/legacy/ChartsLegend/index.js +2 -1
  113. package/legacy/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
  114. package/legacy/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
  115. package/legacy/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
  116. package/legacy/{internals/components → ChartsText}/ChartsText.js +38 -22
  117. package/legacy/ChartsText/index.js +1 -0
  118. package/legacy/ChartsTooltip/ChartsAxisTooltipContent.js +95 -74
  119. package/legacy/ChartsTooltip/ChartsItemTooltipContent.js +40 -55
  120. package/legacy/ChartsTooltip/DefaultChartsAxisTooltipContent.js +167 -0
  121. package/legacy/ChartsTooltip/DefaultChartsItemTooltipContent.js +89 -0
  122. package/legacy/ChartsTooltip/index.js +5 -1
  123. package/legacy/ChartsXAxis/ChartsXAxis.js +2 -1
  124. package/legacy/ChartsYAxis/ChartsYAxis.js +7 -5
  125. package/legacy/LineChart/AreaPlot.js +3 -2
  126. package/legacy/LineChart/LineHighlightPlot.js +2 -1
  127. package/legacy/LineChart/LinePlot.js +3 -2
  128. package/legacy/LineChart/MarkPlot.js +2 -1
  129. package/legacy/LineChart/extremums.js +29 -14
  130. package/legacy/LineChart/formatter.js +19 -8
  131. package/legacy/LineChart/index.js +5 -5
  132. package/legacy/PieChart/PieArcLabelPlot.js +90 -2
  133. package/legacy/PieChart/PieArcPlot.js +89 -2
  134. package/legacy/PieChart/PieChart.js +4 -4
  135. package/legacy/PieChart/PiePlot.js +20 -15
  136. package/legacy/PieChart/index.js +6 -4
  137. package/legacy/ResponsiveChartContainer/index.js +2 -2
  138. package/legacy/ScatterChart/Scatter.js +1 -1
  139. package/legacy/ScatterChart/index.js +3 -3
  140. package/legacy/context/CartesianContextProvider.js +2 -2
  141. package/legacy/context/SeriesContextProvider.js +1 -1
  142. package/legacy/index.js +2 -1
  143. package/legacy/internals/defaultizeValueFormatter.js +4 -3
  144. package/legacy/internals/getWordsByLines.js +15 -0
  145. package/legacy/internals/utils.js +40 -0
  146. package/models/axis.d.ts +1 -1
  147. package/models/seriesType/config.d.ts +9 -4
  148. package/models/seriesType/pie.d.ts +29 -7
  149. package/models/seriesType/scatter.d.ts +1 -1
  150. package/modern/BarChart/BarElement.js +26 -2
  151. package/modern/BarChart/BarPlot.js +7 -5
  152. package/modern/BarChart/formatter.js +15 -3
  153. package/modern/BarChart/index.js +3 -2
  154. package/modern/ChartsAxis/ChartsAxis.js +4 -4
  155. package/modern/ChartsLegend/ChartsLegend.js +2 -1
  156. package/modern/ChartsLegend/index.js +2 -1
  157. package/modern/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
  158. package/modern/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
  159. package/modern/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
  160. package/modern/{internals/components → ChartsText}/ChartsText.js +33 -16
  161. package/modern/ChartsText/index.js +1 -0
  162. package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +95 -74
  163. package/modern/ChartsTooltip/ChartsItemTooltipContent.js +40 -58
  164. package/modern/ChartsTooltip/DefaultChartsAxisTooltipContent.js +167 -0
  165. package/modern/ChartsTooltip/DefaultChartsItemTooltipContent.js +92 -0
  166. package/modern/ChartsTooltip/index.js +5 -1
  167. package/modern/ChartsXAxis/ChartsXAxis.js +2 -1
  168. package/modern/ChartsYAxis/ChartsYAxis.js +7 -5
  169. package/modern/LineChart/AreaPlot.js +3 -2
  170. package/modern/LineChart/LineHighlightPlot.js +2 -1
  171. package/modern/LineChart/LinePlot.js +3 -2
  172. package/modern/LineChart/MarkPlot.js +2 -1
  173. package/modern/LineChart/extremums.js +25 -8
  174. package/modern/LineChart/formatter.js +14 -2
  175. package/modern/LineChart/index.js +5 -5
  176. package/modern/PieChart/PieArcLabelPlot.js +90 -2
  177. package/modern/PieChart/PieArcPlot.js +89 -2
  178. package/modern/PieChart/PieChart.js +4 -4
  179. package/modern/PieChart/PiePlot.js +20 -15
  180. package/modern/PieChart/index.js +6 -4
  181. package/modern/ResponsiveChartContainer/index.js +2 -2
  182. package/modern/ScatterChart/Scatter.js +1 -1
  183. package/modern/ScatterChart/index.js +3 -3
  184. package/modern/context/CartesianContextProvider.js +2 -2
  185. package/modern/context/SeriesContextProvider.js +1 -1
  186. package/modern/index.js +2 -1
  187. package/modern/internals/defaultizeValueFormatter.js +3 -3
  188. package/modern/internals/getWordsByLines.js +14 -0
  189. package/modern/internals/utils.js +40 -0
  190. package/package.json +1 -1
@@ -1,64 +1,11 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import * as React from 'react';
3
- import clsx from 'clsx';
3
+ import PropTypes from 'prop-types';
4
4
  import { useSlotProps } from '@mui/base/utils';
5
5
  import { SeriesContext } from '../context/SeriesContextProvider';
6
- import { ChartsTooltipTable, ChartsTooltipCell, ChartsTooltipMark, ChartsTooltipPaper, ChartsTooltipRow } from './ChartsTooltipTable';
6
+ import { DefaultChartsItemTooltipContent } from './DefaultChartsItemTooltipContent';
7
7
  import { jsx as _jsx } from "react/jsx-runtime";
8
- import { jsxs as _jsxs } from "react/jsx-runtime";
9
- export function DefaultChartsItemContent(props) {
10
- const {
11
- series,
12
- itemData,
13
- sx,
14
- classes
15
- } = props;
16
- if (itemData.dataIndex === undefined) {
17
- return null;
18
- }
19
- const {
20
- displayedLabel,
21
- color
22
- } = series.type === 'pie' ? {
23
- color: series.data[itemData.dataIndex].color,
24
- displayedLabel: series.data[itemData.dataIndex].label
25
- } : {
26
- color: series.color,
27
- displayedLabel: series.label
28
- };
29
-
30
- // TODO: Manage to let TS understand series.data and series.valueFormatter are coherent
31
- // @ts-ignore
32
- const formattedValue = series.valueFormatter(series.data[itemData.dataIndex]);
33
- return /*#__PURE__*/_jsx(ChartsTooltipPaper, {
34
- sx: sx,
35
- className: classes.root,
36
- children: /*#__PURE__*/_jsx(ChartsTooltipTable, {
37
- className: classes.table,
38
- children: /*#__PURE__*/_jsx("tbody", {
39
- children: /*#__PURE__*/_jsxs(ChartsTooltipRow, {
40
- className: classes.row,
41
- children: [/*#__PURE__*/_jsx(ChartsTooltipCell, {
42
- className: clsx(classes.markCell, classes.cell),
43
- children: /*#__PURE__*/_jsx(ChartsTooltipMark, {
44
- ownerState: {
45
- color
46
- },
47
- className: classes.mark
48
- })
49
- }), /*#__PURE__*/_jsx(ChartsTooltipCell, {
50
- className: clsx(classes.labelCell, classes.cell),
51
- children: displayedLabel
52
- }), /*#__PURE__*/_jsx(ChartsTooltipCell, {
53
- className: clsx(classes.valueCell, classes.cell),
54
- children: formattedValue
55
- })]
56
- })
57
- })
58
- })
59
- });
60
- }
61
- export function ChartsItemTooltipContent(props) {
8
+ function ChartsItemTooltipContent(props) {
62
9
  const {
63
10
  content,
64
11
  itemData,
@@ -67,7 +14,7 @@ export function ChartsItemTooltipContent(props) {
67
14
  contentProps
68
15
  } = props;
69
16
  const series = React.useContext(SeriesContext)[itemData.type].series[itemData.seriesId];
70
- const Content = content ?? DefaultChartsItemContent;
17
+ const Content = content ?? DefaultChartsItemTooltipContent;
71
18
  const chartTooltipContentProps = useSlotProps({
72
19
  elementType: Content,
73
20
  externalSlotProps: contentProps,
@@ -80,4 +27,39 @@ export function ChartsItemTooltipContent(props) {
80
27
  ownerState: {}
81
28
  });
82
29
  return /*#__PURE__*/_jsx(Content, _extends({}, chartTooltipContentProps));
83
- }
30
+ }
31
+ process.env.NODE_ENV !== "production" ? ChartsItemTooltipContent.propTypes = {
32
+ // ----------------------------- Warning --------------------------------
33
+ // | These PropTypes are generated from the TypeScript type definitions |
34
+ // | To update them edit the TypeScript types and run "yarn proptypes" |
35
+ // ----------------------------------------------------------------------
36
+ classes: PropTypes.object.isRequired,
37
+ content: PropTypes.elementType,
38
+ contentProps: PropTypes.shape({
39
+ classes: PropTypes.object,
40
+ itemData: PropTypes.shape({
41
+ dataIndex: PropTypes.number,
42
+ seriesId: PropTypes.string.isRequired,
43
+ type: PropTypes.oneOf(['bar', 'line', 'pie', 'scatter']).isRequired
44
+ }),
45
+ series: PropTypes.shape({
46
+ color: PropTypes.string,
47
+ data: PropTypes.arrayOf(PropTypes.number).isRequired,
48
+ highlightScope: PropTypes.shape({
49
+ faded: PropTypes.oneOf(['global', 'none', 'series']),
50
+ highlighted: PropTypes.oneOf(['item', 'none', 'series'])
51
+ }),
52
+ id: PropTypes.string.isRequired,
53
+ type: PropTypes.oneOf(['bar', 'line', 'pie', 'scatter']).isRequired,
54
+ valueFormatter: PropTypes.func.isRequired
55
+ }),
56
+ sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
57
+ }),
58
+ itemData: PropTypes.shape({
59
+ dataIndex: PropTypes.number,
60
+ seriesId: PropTypes.string.isRequired,
61
+ type: PropTypes.oneOf(['bar', 'line', 'pie', 'scatter']).isRequired
62
+ }).isRequired,
63
+ sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
64
+ } : void 0;
65
+ export { ChartsItemTooltipContent };
@@ -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';
@@ -11,9 +11,10 @@ import { DrawingContext } from '../context/DrawingProvider';
11
11
  import useTicks from '../hooks/useTicks';
12
12
  import { getAxisUtilityClass } from '../ChartsAxis/axisClasses';
13
13
  import { AxisRoot } from '../internals/components/AxisSharedComponents';
14
- import { ChartsText, getWordsByLines } from '../internals/components/ChartsText';
14
+ import { ChartsText } from '../ChartsText';
15
15
  import { getMinXTranslation } from '../internals/geometry';
16
16
  import { useMounted } from '../hooks/useMounted';
17
+ import { getWordsByLines } from '../internals/getWordsByLines';
17
18
  import { jsx as _jsx } from "react/jsx-runtime";
18
19
  import { jsxs as _jsxs } from "react/jsx-runtime";
19
20
  const useUtilityClasses = ownerState => {
@@ -10,7 +10,7 @@ import { CartesianContext } from '../context/CartesianContextProvider';
10
10
  import { DrawingContext } from '../context/DrawingProvider';
11
11
  import useTicks from '../hooks/useTicks';
12
12
  import { AxisRoot } from '../internals/components/AxisSharedComponents';
13
- import { ChartsText } from '../internals/components/ChartsText';
13
+ import { ChartsText } from '../ChartsText';
14
14
  import { getAxisUtilityClass } from '../ChartsAxis/axisClasses';
15
15
  import { jsx as _jsx } from "react/jsx-runtime";
16
16
  import { jsxs as _jsxs } from "react/jsx-runtime";
@@ -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
  });
@@ -9,6 +9,7 @@ import { CartesianContext } from '../context/CartesianContextProvider';
9
9
  import { AreaElement } from './AreaElement';
10
10
  import { getValueToPositionMapper } from '../hooks/useScale';
11
11
  import getCurveFactory from '../internals/getCurve';
12
+ import { DEFAULT_X_AXIS_KEY } from '../constants';
12
13
  import { jsx as _jsx } from "react/jsx-runtime";
13
14
  /**
14
15
  * Demos:
@@ -61,10 +62,10 @@ function AreaPlot(props) {
61
62
  const xData = xAxis[xAxisKey].data;
62
63
  if (process.env.NODE_ENV !== 'production') {
63
64
  if (xData === undefined) {
64
- throw new Error(`Axis of id "${xAxisKey}" should have data property to be able to display a line plot.`);
65
+ throw new Error(`MUI-X-Charts: ${xAxisKey === 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.`);
65
66
  }
66
67
  if (xData.length < stackedData.length) {
67
- throw new Error(`MUI: data length of the x axis (${xData.length} items) is lower than the length of series (${stackedData.length} items)`);
68
+ 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)`);
68
69
  }
69
70
  }
70
71
  const areaPath = d3Area().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]));
@@ -8,6 +8,7 @@ import { CartesianContext } from '../context/CartesianContextProvider';
8
8
  import { LineHighlightElement } from './LineHighlightElement';
9
9
  import { getValueToPositionMapper } from '../hooks/useScale';
10
10
  import { InteractionContext } from '../context/InteractionProvider';
11
+ import { DEFAULT_X_AXIS_KEY } from '../constants';
11
12
  import { jsx as _jsx } from "react/jsx-runtime";
12
13
  /**
13
14
  * Demos:
@@ -69,7 +70,7 @@ function LineHighlightPlot(props) {
69
70
  const yScale = yAxis[yAxisKey].scale;
70
71
  const xData = xAxis[xAxisKey].data;
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 === 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
  const x = xScale(xData[highlightedIndex]);
75
76
  const y = yScale(stackedData[highlightedIndex][1]); // This should not be undefined since y should not be a band scale
@@ -9,6 +9,7 @@ import { CartesianContext } from '../context/CartesianContextProvider';
9
9
  import { LineElement } from './LineElement';
10
10
  import { getValueToPositionMapper } from '../hooks/useScale';
11
11
  import getCurveFactory from '../internals/getCurve';
12
+ import { DEFAULT_X_AXIS_KEY } from '../constants';
12
13
  import { jsx as _jsx } from "react/jsx-runtime";
13
14
  /**
14
15
  * Demos:
@@ -60,10 +61,10 @@ function LinePlot(props) {
60
61
  const xData = xAxis[xAxisKey].data;
61
62
  if (process.env.NODE_ENV !== 'production') {
62
63
  if (xData === undefined) {
63
- throw new Error(`Axis of id "${xAxisKey}" should have data property to be able to display a line plot`);
64
+ throw new Error(`MUI-X-Charts: ${xAxisKey === 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`);
64
65
  }
65
66
  if (xData.length < stackedData.length) {
66
- throw new Error(`MUI: data length of the x axis (${xData.length} items) is lower than the length of series (${stackedData.length} items)`);
67
+ 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)`);
67
68
  }
68
69
  }
69
70
  const linePath = d3Line().x(d => xScale(d.x)).defined((_, i) => connectNulls || data[i] != null).y(d => yScale(d.y[1]));
@@ -7,6 +7,7 @@ import { SeriesContext } from '../context/SeriesContextProvider';
7
7
  import { CartesianContext } from '../context/CartesianContextProvider';
8
8
  import { MarkElement } from './MarkElement';
9
9
  import { getValueToPositionMapper } from '../hooks/useScale';
10
+ import { DEFAULT_X_AXIS_KEY } from '../constants';
10
11
  import { jsx as _jsx } from "react/jsx-runtime";
11
12
  /**
12
13
  * Demos:
@@ -75,7 +76,7 @@ function MarkPlot(props) {
75
76
  return true;
76
77
  };
77
78
  if (xData === undefined) {
78
- throw new Error(`Axis of id "${xAxisKey}" should have data property to be able to display a line plot`);
79
+ throw new Error(`MUI-X-Charts: ${xAxisKey === 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`);
79
80
  }
80
81
  return xData?.map((x, index) => {
81
82
  const value = data[index] == null ? null : stackedData[index][1];
@@ -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
  };
@@ -2,6 +2,8 @@ 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 warnedOnce = false;
6
+
5
7
  // For now it's a copy past of bar charts formatter, but maybe will diverge later
6
8
  const formatter = (params, dataset) => {
7
9
  const {
@@ -25,7 +27,7 @@ const formatter = (params, dataset) => {
25
27
  }
26
28
  });
27
29
  } else if (dataset === undefined && process.env.NODE_ENV !== 'production') {
28
- 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'));
30
+ 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'));
29
31
  }
30
32
  });
31
33
  const completedSeries = {};
@@ -45,7 +47,17 @@ const formatter = (params, dataset) => {
45
47
  ids.forEach((id, index) => {
46
48
  const dataKey = series[id].dataKey;
47
49
  completedSeries[id] = _extends({}, 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' && !warnedOnce && value !== null) {
54
+ warnedOnce = true;
55
+ 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.']);
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
  });
@@ -1,8 +1,8 @@
1
- export { LinePlot } from './LinePlot';
2
- export { AreaPlot } from './AreaPlot';
3
- export { MarkPlot } from './MarkPlot';
4
- export { LineHighlightPlot } from './LineHighlightPlot';
5
- export { LineChart } from './LineChart';
1
+ export * from './LineChart';
2
+ export * from './LinePlot';
3
+ export * from './AreaPlot';
4
+ export * from './MarkPlot';
5
+ export * from './LineHighlightPlot';
6
6
  export * from './AreaElement';
7
7
  export * from './LineElement';
8
8
  export * from './MarkElement';