@mui/x-charts 6.0.0-alpha.5 → 6.0.0-alpha.7

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 (163) hide show
  1. package/BarChart/BarChart.d.ts +18 -2
  2. package/BarChart/BarChart.js +74 -17
  3. package/BarChart/BarElement.d.ts +22 -0
  4. package/BarChart/BarElement.js +21 -10
  5. package/BarChart/BarPlot.d.ts +14 -1
  6. package/BarChart/BarPlot.js +23 -4
  7. package/BarChart/formatter.js +23 -12
  8. package/CHANGELOG.md +154 -0
  9. package/ChartContainer/index.js +3 -0
  10. package/ChartsAxis/ChartsAxis.d.ts +11 -1
  11. package/ChartsAxis/ChartsAxis.js +51 -6
  12. package/ChartsLegend/ChartsLegend.d.ts +25 -2
  13. package/ChartsLegend/ChartsLegend.js +49 -17
  14. package/ChartsTooltip/ChartsAxisTooltipContent.js +1 -1
  15. package/ChartsTooltip/ChartsTooltipTable.d.ts +2 -9
  16. package/ChartsXAxis/ChartsXAxis.js +44 -9
  17. package/ChartsYAxis/ChartsYAxis.js +44 -9
  18. package/LineChart/AreaElement.d.ts +22 -0
  19. package/LineChart/AreaElement.js +31 -11
  20. package/LineChart/AreaPlot.d.ts +14 -1
  21. package/LineChart/AreaPlot.js +32 -5
  22. package/LineChart/LineChart.d.ts +20 -2
  23. package/LineChart/LineChart.js +76 -16
  24. package/LineChart/LineElement.d.ts +22 -0
  25. package/LineChart/LineElement.js +31 -10
  26. package/LineChart/LinePlot.d.ts +14 -1
  27. package/LineChart/LinePlot.js +38 -6
  28. package/LineChart/MarkElement.js +1 -1
  29. package/LineChart/MarkPlot.d.ts +24 -1
  30. package/LineChart/MarkPlot.js +30 -6
  31. package/LineChart/formatter.js +23 -12
  32. package/PieChart/PieArcLabel.js +0 -1
  33. package/PieChart/PieChart.d.ts +14 -2
  34. package/PieChart/PieChart.js +60 -13
  35. package/PieChart/PiePlot.d.ts +27 -1
  36. package/PieChart/PiePlot.js +29 -6
  37. package/ScatterChart/ScatterChart.d.ts +18 -2
  38. package/ScatterChart/ScatterChart.js +64 -13
  39. package/ScatterChart/ScatterPlot.d.ts +24 -1
  40. package/ScatterChart/ScatterPlot.js +28 -4
  41. package/SparkLineChart/SparkLineChart.d.ts +73 -0
  42. package/SparkLineChart/SparkLineChart.js +218 -0
  43. package/SparkLineChart/index.d.ts +1 -0
  44. package/SparkLineChart/index.js +12 -0
  45. package/SparkLineChart/package.json +6 -0
  46. package/colorPalettes/colorPalettes.js +2 -2
  47. package/context/CartesianContextProvider.d.ts +3 -1
  48. package/context/CartesianContextProvider.js +50 -14
  49. package/context/SeriesContextProvider.d.ts +3 -2
  50. package/context/SeriesContextProvider.js +5 -3
  51. package/esm/BarChart/BarChart.js +77 -17
  52. package/esm/BarChart/BarElement.js +21 -11
  53. package/esm/BarChart/BarPlot.js +23 -4
  54. package/esm/BarChart/formatter.js +23 -12
  55. package/esm/ChartContainer/index.js +3 -0
  56. package/esm/ChartsAxis/ChartsAxis.js +51 -6
  57. package/esm/ChartsLegend/ChartsLegend.js +47 -14
  58. package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +1 -1
  59. package/esm/ChartsXAxis/ChartsXAxis.js +45 -9
  60. package/esm/ChartsYAxis/ChartsYAxis.js +45 -9
  61. package/esm/LineChart/AreaElement.js +31 -11
  62. package/esm/LineChart/AreaPlot.js +33 -5
  63. package/esm/LineChart/LineChart.js +79 -16
  64. package/esm/LineChart/LineElement.js +31 -11
  65. package/esm/LineChart/LinePlot.js +45 -9
  66. package/esm/LineChart/MarkElement.js +1 -1
  67. package/esm/LineChart/MarkPlot.js +31 -6
  68. package/esm/LineChart/formatter.js +23 -13
  69. package/esm/PieChart/PieArcLabel.js +0 -1
  70. package/esm/PieChart/PieChart.js +60 -13
  71. package/esm/PieChart/PiePlot.js +31 -6
  72. package/esm/ScatterChart/ScatterChart.js +64 -13
  73. package/esm/ScatterChart/ScatterPlot.js +29 -4
  74. package/esm/SparkLineChart/SparkLineChart.js +210 -0
  75. package/esm/SparkLineChart/index.js +1 -0
  76. package/esm/colorPalettes/colorPalettes.js +2 -2
  77. package/esm/context/CartesianContextProvider.js +50 -14
  78. package/esm/context/SeriesContextProvider.js +5 -3
  79. package/esm/hooks/useTicks.js +9 -6
  80. package/esm/index.js +1 -0
  81. package/esm/internals/components/AxisSharedComponents.js +10 -10
  82. package/esm/models/index.js +3 -1
  83. package/hooks/useTicks.d.ts +20 -5
  84. package/hooks/useTicks.js +9 -6
  85. package/index.d.ts +1 -0
  86. package/index.js +12 -1
  87. package/internals/components/AxisSharedComponents.d.ts +4 -4
  88. package/internals/components/AxisSharedComponents.js +15 -15
  89. package/internals/defaultizeColor.d.ts +4 -2
  90. package/legacy/BarChart/BarChart.js +75 -17
  91. package/legacy/BarChart/BarElement.js +20 -10
  92. package/legacy/BarChart/BarPlot.js +23 -4
  93. package/legacy/BarChart/formatter.js +23 -10
  94. package/legacy/ChartContainer/index.js +3 -0
  95. package/legacy/ChartsAxis/ChartsAxis.js +51 -6
  96. package/legacy/ChartsLegend/ChartsLegend.js +46 -15
  97. package/legacy/ChartsTooltip/ChartsAxisTooltipContent.js +1 -1
  98. package/legacy/ChartsXAxis/ChartsXAxis.js +45 -9
  99. package/legacy/ChartsYAxis/ChartsYAxis.js +45 -9
  100. package/legacy/LineChart/AreaElement.js +30 -10
  101. package/legacy/LineChart/AreaPlot.js +31 -5
  102. package/legacy/LineChart/LineChart.js +77 -16
  103. package/legacy/LineChart/LineElement.js +30 -10
  104. package/legacy/LineChart/LinePlot.js +38 -6
  105. package/legacy/LineChart/MarkElement.js +1 -1
  106. package/legacy/LineChart/MarkPlot.js +29 -6
  107. package/legacy/LineChart/formatter.js +23 -11
  108. package/legacy/PieChart/PieArcLabel.js +0 -1
  109. package/legacy/PieChart/PieChart.js +60 -13
  110. package/legacy/PieChart/PiePlot.js +29 -6
  111. package/legacy/ScatterChart/ScatterChart.js +64 -13
  112. package/legacy/ScatterChart/ScatterPlot.js +27 -4
  113. package/legacy/SparkLineChart/SparkLineChart.js +214 -0
  114. package/legacy/SparkLineChart/index.js +1 -0
  115. package/legacy/colorPalettes/colorPalettes.js +2 -2
  116. package/legacy/context/CartesianContextProvider.js +59 -15
  117. package/legacy/context/SeriesContextProvider.js +6 -4
  118. package/legacy/hooks/useTicks.js +9 -9
  119. package/legacy/index.js +2 -1
  120. package/legacy/internals/components/AxisSharedComponents.js +10 -10
  121. package/legacy/models/index.js +3 -1
  122. package/models/axis.d.ts +34 -3
  123. package/models/index.d.ts +2 -0
  124. package/models/index.js +11 -0
  125. package/models/seriesType/bar.d.ts +8 -1
  126. package/models/seriesType/common.d.ts +2 -2
  127. package/models/seriesType/config.d.ts +4 -1
  128. package/models/seriesType/line.d.ts +8 -1
  129. package/modern/BarChart/BarChart.js +74 -17
  130. package/modern/BarChart/BarElement.js +20 -11
  131. package/modern/BarChart/BarPlot.js +23 -4
  132. package/modern/BarChart/formatter.js +23 -12
  133. package/modern/ChartContainer/index.js +3 -0
  134. package/modern/ChartsAxis/ChartsAxis.js +51 -6
  135. package/modern/ChartsLegend/ChartsLegend.js +46 -14
  136. package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +1 -1
  137. package/modern/ChartsXAxis/ChartsXAxis.js +44 -9
  138. package/modern/ChartsYAxis/ChartsYAxis.js +44 -9
  139. package/modern/LineChart/AreaElement.js +30 -11
  140. package/modern/LineChart/AreaPlot.js +33 -5
  141. package/modern/LineChart/LineChart.js +76 -16
  142. package/modern/LineChart/LineElement.js +30 -11
  143. package/modern/LineChart/LinePlot.js +39 -6
  144. package/modern/LineChart/MarkElement.js +1 -1
  145. package/modern/LineChart/MarkPlot.js +30 -6
  146. package/modern/LineChart/formatter.js +23 -13
  147. package/modern/PieChart/PieArcLabel.js +0 -1
  148. package/modern/PieChart/PieChart.js +60 -13
  149. package/modern/PieChart/PiePlot.js +30 -6
  150. package/modern/ScatterChart/ScatterChart.js +64 -13
  151. package/modern/ScatterChart/ScatterPlot.js +28 -4
  152. package/modern/SparkLineChart/SparkLineChart.js +210 -0
  153. package/modern/SparkLineChart/index.js +1 -0
  154. package/modern/colorPalettes/colorPalettes.js +2 -2
  155. package/modern/context/CartesianContextProvider.js +50 -14
  156. package/modern/context/SeriesContextProvider.js +5 -3
  157. package/modern/hooks/useTicks.js +9 -6
  158. package/modern/index.js +2 -1
  159. package/modern/internals/components/AxisSharedComponents.js +10 -10
  160. package/modern/models/index.js +3 -1
  161. package/package.json +4 -2
  162. package/themeAugmentation/components.d.ts +0 -10
  163. package/themeAugmentation/overrides.d.ts +0 -2
@@ -0,0 +1,214 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
3
+ import * as React from 'react';
4
+ import PropTypes from 'prop-types';
5
+ import { styled } from '@mui/material/styles';
6
+ import { BarPlot } from '../BarChart';
7
+ import { LinePlot, MarkPlot, AreaPlot, markElementClasses } from '../LineChart';
8
+ import { ResponsiveChartContainer } from '../ResponsiveChartContainer';
9
+ import { DEFAULT_X_AXIS_KEY } from '../constants';
10
+ import { ChartsTooltip } from '../ChartsTooltip';
11
+ import { ChartsAxisHighlight } from '../ChartsAxisHighlight';
12
+ import { jsx as _jsx } from "react/jsx-runtime";
13
+ import { jsxs as _jsxs } from "react/jsx-runtime";
14
+ var SparkLineMarkPlot = styled(MarkPlot)(_defineProperty({}, "& .".concat(markElementClasses.root), _defineProperty({
15
+ display: 'none'
16
+ }, "&.".concat(markElementClasses.highlighted), {
17
+ display: 'inherit'
18
+ })));
19
+ var SPARKLINE_DEFAULT_MARGIN = {
20
+ top: 5,
21
+ bottom: 5,
22
+ left: 5,
23
+ right: 5
24
+ };
25
+ var SparkLineChart = /*#__PURE__*/React.forwardRef(function SparkLineChart(props, ref) {
26
+ var xAxis = props.xAxis,
27
+ width = props.width,
28
+ height = props.height,
29
+ _props$margin = props.margin,
30
+ margin = _props$margin === void 0 ? SPARKLINE_DEFAULT_MARGIN : _props$margin,
31
+ colors = props.colors,
32
+ sx = props.sx,
33
+ showTooltip = props.showTooltip,
34
+ tooltip = props.tooltip,
35
+ showHighlight = props.showHighlight,
36
+ inAxisHighlight = props.axisHighlight,
37
+ children = props.children,
38
+ slots = props.slots,
39
+ slotProps = props.slotProps,
40
+ data = props.data,
41
+ _props$plotType = props.plotType,
42
+ plotType = _props$plotType === void 0 ? 'line' : _props$plotType,
43
+ _props$valueFormatter = props.valueFormatter,
44
+ valueFormatter = _props$valueFormatter === void 0 ? function (v) {
45
+ return v.toString();
46
+ } : _props$valueFormatter,
47
+ area = props.area,
48
+ _props$curve = props.curve,
49
+ curve = _props$curve === void 0 ? 'linear' : _props$curve;
50
+ var defaultXHighlight = showHighlight && plotType === 'bar' ? {
51
+ x: 'band'
52
+ } : {
53
+ x: 'none'
54
+ };
55
+ var axisHighlight = _extends({}, defaultXHighlight, inAxisHighlight);
56
+ return /*#__PURE__*/_jsxs(ResponsiveChartContainer, {
57
+ ref: ref,
58
+ series: [_extends({
59
+ type: plotType,
60
+ data: data,
61
+ valueFormatter: valueFormatter
62
+ }, plotType === 'bar' ? {} : {
63
+ area: area,
64
+ curve: curve
65
+ })],
66
+ width: width,
67
+ height: height,
68
+ margin: margin,
69
+ xAxis: [_extends({
70
+ id: DEFAULT_X_AXIS_KEY,
71
+ scaleType: plotType === 'bar' ? 'band' : 'linear',
72
+ data: Array.from({
73
+ length: data.length
74
+ }, function (_, index) {
75
+ return index;
76
+ }),
77
+ hideTooltip: xAxis === undefined
78
+ }, xAxis)],
79
+ colors: colors,
80
+ sx: sx,
81
+ disableAxisListener: (!showTooltip || (tooltip == null ? void 0 : tooltip.trigger) !== 'axis') && (axisHighlight == null ? void 0 : axisHighlight.x) === 'none' && (axisHighlight == null ? void 0 : axisHighlight.y) === 'none',
82
+ children: [plotType === 'bar' && /*#__PURE__*/_jsx(BarPlot, {
83
+ slots: slots,
84
+ slotProps: slotProps
85
+ }), plotType === 'line' && /*#__PURE__*/_jsxs(React.Fragment, {
86
+ children: [/*#__PURE__*/_jsx(AreaPlot, {
87
+ slots: slots,
88
+ slotProps: slotProps
89
+ }), /*#__PURE__*/_jsx(LinePlot, {
90
+ slots: slots,
91
+ slotProps: slotProps
92
+ }), showHighlight && /*#__PURE__*/_jsx(SparkLineMarkPlot, {})]
93
+ }), /*#__PURE__*/_jsx(ChartsAxisHighlight, _extends({}, axisHighlight)), showTooltip && /*#__PURE__*/_jsx(ChartsTooltip, _extends({}, tooltip)), children]
94
+ });
95
+ });
96
+ process.env.NODE_ENV !== "production" ? SparkLineChart.propTypes = {
97
+ // ----------------------------- Warning --------------------------------
98
+ // | These PropTypes are generated from the TypeScript type definitions |
99
+ // | To update them edit the TypeScript types and run "yarn proptypes" |
100
+ // ----------------------------------------------------------------------
101
+ /**
102
+ * Set to `true` to fill spark line area.
103
+ * Has no effect if plotType='bar'.
104
+ * @default false
105
+ */
106
+ area: PropTypes.bool,
107
+ axisHighlight: PropTypes.shape({
108
+ x: PropTypes.oneOf(['band', 'line', 'none']),
109
+ y: PropTypes.oneOf(['line', 'none'])
110
+ }),
111
+ children: PropTypes.node,
112
+ className: PropTypes.string,
113
+ /**
114
+ * Color palette used to colorize multiple series.
115
+ */
116
+ colors: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string), PropTypes.func]),
117
+ /**
118
+ * @default 'linear'
119
+ */
120
+ curve: PropTypes.oneOf(['catmullRom', 'linear', 'monotoneX', 'monotoneY', 'natural', 'step', 'stepAfter', 'stepBefore']),
121
+ /**
122
+ * Data to plot.
123
+ */
124
+ data: PropTypes.arrayOf(PropTypes.number).isRequired,
125
+ dataset: PropTypes.arrayOf(PropTypes.object),
126
+ desc: PropTypes.string,
127
+ disableAxisListener: PropTypes.bool,
128
+ height: PropTypes.number,
129
+ margin: PropTypes.shape({
130
+ bottom: PropTypes.number,
131
+ left: PropTypes.number,
132
+ right: PropTypes.number,
133
+ top: PropTypes.number
134
+ }),
135
+ /**
136
+ * Type of plot used.
137
+ * @default 'line'
138
+ */
139
+ plotType: PropTypes.oneOf(['bar', 'line']),
140
+ /**
141
+ * Set to `true` to highlight the value.
142
+ * With line, it shows a point.
143
+ * With bar, it shows a highlight band.
144
+ * @default false
145
+ */
146
+ showHighlight: PropTypes.bool,
147
+ /**
148
+ * Set to `true` to enable the tooltip in the sparkline.
149
+ * @default false
150
+ */
151
+ showTooltip: PropTypes.bool,
152
+ /**
153
+ * The props used for each component slot.
154
+ * @default {}
155
+ */
156
+ slotProps: PropTypes.object,
157
+ /**
158
+ * Overridable component slots.
159
+ * @default {}
160
+ */
161
+ slots: PropTypes.object,
162
+ sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
163
+ title: PropTypes.string,
164
+ tooltip: PropTypes.shape({
165
+ axisContent: PropTypes.elementType,
166
+ classes: PropTypes.object,
167
+ itemContent: PropTypes.elementType,
168
+ trigger: PropTypes.oneOf(['axis', 'item', 'none'])
169
+ }),
170
+ /**
171
+ * Formatter used by the tooltip.
172
+ * @param {number} value The value to format.
173
+ * @returns {string} the formatted value.
174
+ */
175
+ valueFormatter: PropTypes.func,
176
+ viewBox: PropTypes.shape({
177
+ height: PropTypes.number,
178
+ width: PropTypes.number,
179
+ x: PropTypes.number,
180
+ y: PropTypes.number
181
+ }),
182
+ width: PropTypes.number,
183
+ /**
184
+ * The xAxis configuration.
185
+ * Notice it is a single configuration object, not an array of configuration.
186
+ */
187
+ xAxis: PropTypes.shape({
188
+ axisId: PropTypes.string,
189
+ classes: PropTypes.object,
190
+ data: PropTypes.array,
191
+ dataKey: PropTypes.string,
192
+ disableLine: PropTypes.bool,
193
+ disableTicks: PropTypes.bool,
194
+ fill: PropTypes.string,
195
+ hideTooltip: PropTypes.bool,
196
+ id: PropTypes.string,
197
+ label: PropTypes.string,
198
+ labelFontSize: PropTypes.number,
199
+ max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
200
+ min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
201
+ position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
202
+ scaleType: PropTypes.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
203
+ slotProps: PropTypes.object,
204
+ slots: PropTypes.object,
205
+ stroke: PropTypes.string,
206
+ tickFontSize: PropTypes.number,
207
+ tickMaxStep: PropTypes.number,
208
+ tickMinStep: PropTypes.number,
209
+ tickNumber: PropTypes.number,
210
+ tickSize: PropTypes.number,
211
+ valueFormatter: PropTypes.func
212
+ })
213
+ } : void 0;
214
+ export { SparkLineChart };
@@ -0,0 +1 @@
1
+ export { SparkLineChart } from './SparkLineChart';
@@ -8,8 +8,8 @@ export var mangoFusionPaletteDark = ['#41698F', '#19D0CD', '#DE196B', '#FC5F5C',
8
8
  export var mangoFusionPalette = function mangoFusionPalette(mode) {
9
9
  return mode === 'dark' ? mangoFusionPaletteDark : mangoFusionPaletteLight;
10
10
  };
11
- export var cheerfulFiestaPaletteDark = ['#0072E6', '#66B2FF', '#FFB017', '#1F94AD', '#FF3143', '#FF6C63'];
12
- export var cheerfulFiestaPaletteLight = ['#0059B2', '#2E96FF', '#EA8C00', '#1F94AD', '#C82634', '#FF3143'];
11
+ export var cheerfulFiestaPaletteDark = ['#0059B2', '#2E96FF', '#FFC24C', '#FF9F0E', '#F38200', '#2ABFDE', '#1F94AD', '#BD2C38', '#FF3143', '#FF8282'];
12
+ export var cheerfulFiestaPaletteLight = ['#003A75', '#007FFF', '#FFC24C', '#FF9D09', '#CA6C00', '#127D94', '#1F94AD', '#C82634', '#FF3143', '#FF7E7E'];
13
13
  export var cheerfulFiestaPalette = function cheerfulFiestaPalette(mode) {
14
14
  return mode === 'dark' ? cheerfulFiestaPaletteDark : cheerfulFiestaPaletteLight;
15
15
  };
@@ -1,6 +1,6 @@
1
- import _extends from "@babel/runtime/helpers/esm/extends";
2
1
  import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
3
2
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
+ import _extends from "@babel/runtime/helpers/esm/extends";
4
4
  import * as React from 'react';
5
5
  import { scaleBand, scalePoint } from 'd3-scale';
6
6
  import PropTypes from 'prop-types';
@@ -34,11 +34,44 @@ export var CartesianContext = /*#__PURE__*/React.createContext({
34
34
  yAxisIds: []
35
35
  });
36
36
  function CartesianContextProvider(_ref) {
37
- var xAxis = _ref.xAxis,
38
- yAxis = _ref.yAxis,
37
+ var inXAxis = _ref.xAxis,
38
+ inYAxis = _ref.yAxis,
39
+ dataset = _ref.dataset,
39
40
  children = _ref.children;
40
41
  var formattedSeries = React.useContext(SeriesContext);
41
42
  var drawingArea = React.useContext(DrawingContext);
43
+ var xAxis = React.useMemo(function () {
44
+ return inXAxis == null ? void 0 : inXAxis.map(function (axisConfig) {
45
+ var dataKey = axisConfig.dataKey;
46
+ if (dataKey === undefined || axisConfig.data !== undefined) {
47
+ return axisConfig;
48
+ }
49
+ if (dataset === undefined) {
50
+ throw Error('MUI: x-axis uses `dataKey` but no `dataset` is provided.');
51
+ }
52
+ return _extends({}, axisConfig, {
53
+ data: dataset.map(function (d) {
54
+ return d[dataKey];
55
+ })
56
+ });
57
+ });
58
+ }, [inXAxis, dataset]);
59
+ var yAxis = React.useMemo(function () {
60
+ return inYAxis == null ? void 0 : inYAxis.map(function (axisConfig) {
61
+ var dataKey = axisConfig.dataKey;
62
+ if (dataKey === undefined || axisConfig.data !== undefined) {
63
+ return axisConfig;
64
+ }
65
+ if (dataset === undefined) {
66
+ throw Error('MUI: y-axis uses `dataKey` but no `dataset` is provided.');
67
+ }
68
+ return _extends({}, axisConfig, {
69
+ data: dataset.map(function (d) {
70
+ return d[dataKey];
71
+ })
72
+ });
73
+ });
74
+ }, [inYAxis, dataset]);
42
75
  var value = React.useMemo(function () {
43
76
  var _xAxis$map, _yAxis$map;
44
77
  var axisExtremumCallback = function axisExtremumCallback(acc, chartType, axis, getters, isDefaultAxis) {
@@ -114,7 +147,8 @@ function CartesianContextProvider(_ref) {
114
147
  var scaleType = (_axis$scaleType = axis.scaleType) != null ? _axis$scaleType : 'linear';
115
148
  var extremums = [(_axis$min = axis.min) != null ? _axis$min : minData, (_axis$max = axis.max) != null ? _axis$max : maxData];
116
149
  var ticksNumber = getTicksNumber(_extends({}, axis, {
117
- range: range
150
+ range: range,
151
+ domain: extremums
118
152
  }));
119
153
  var niceScale = getScale(scaleType, extremums, range).nice(ticksNumber);
120
154
  var niceDomain = niceScale.domain();
@@ -169,7 +203,8 @@ function CartesianContextProvider(_ref) {
169
203
  var scaleType = (_axis$scaleType2 = axis.scaleType) != null ? _axis$scaleType2 : 'linear';
170
204
  var extremums = [(_axis$min3 = axis.min) != null ? _axis$min3 : minData, (_axis$max3 = axis.max) != null ? _axis$max3 : maxData];
171
205
  var ticksNumber = getTicksNumber(_extends({}, axis, {
172
- range: range
206
+ range: range,
207
+ domain: extremums
173
208
  }));
174
209
  var niceScale = getScale(scaleType, extremums, range).nice(ticksNumber);
175
210
  var niceDomain = niceScale.domain();
@@ -206,48 +241,57 @@ process.env.NODE_ENV !== "production" ? CartesianContextProvider.propTypes = {
206
241
  // | To update them edit the TypeScript types and run "yarn proptypes" |
207
242
  // ----------------------------------------------------------------------
208
243
  children: PropTypes.node,
244
+ dataset: PropTypes.arrayOf(PropTypes.object),
209
245
  xAxis: PropTypes.arrayOf(PropTypes.shape({
210
246
  axisId: PropTypes.string,
211
247
  classes: PropTypes.object,
212
248
  data: PropTypes.array,
249
+ dataKey: PropTypes.string,
213
250
  disableLine: PropTypes.bool,
214
251
  disableTicks: PropTypes.bool,
215
252
  fill: PropTypes.string,
253
+ hideTooltip: PropTypes.bool,
216
254
  id: PropTypes.string,
217
255
  label: PropTypes.string,
218
256
  labelFontSize: PropTypes.number,
219
- max: PropTypes.number,
220
- maxTicks: PropTypes.number,
221
- min: PropTypes.number,
222
- minTicks: PropTypes.number,
257
+ max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
258
+ min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
223
259
  position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
224
260
  scaleType: PropTypes.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
261
+ slotProps: PropTypes.object,
262
+ slots: PropTypes.object,
225
263
  stroke: PropTypes.string,
226
264
  tickFontSize: PropTypes.number,
265
+ tickMaxStep: PropTypes.number,
266
+ tickMinStep: PropTypes.number,
267
+ tickNumber: PropTypes.number,
227
268
  tickSize: PropTypes.number,
228
- tickSpacing: PropTypes.number,
229
269
  valueFormatter: PropTypes.func
230
270
  })),
231
271
  yAxis: PropTypes.arrayOf(PropTypes.shape({
232
272
  axisId: PropTypes.string,
233
273
  classes: PropTypes.object,
234
274
  data: PropTypes.array,
275
+ dataKey: PropTypes.string,
235
276
  disableLine: PropTypes.bool,
236
277
  disableTicks: PropTypes.bool,
237
278
  fill: PropTypes.string,
279
+ hideTooltip: PropTypes.bool,
238
280
  id: PropTypes.string,
239
281
  label: PropTypes.string,
240
282
  labelFontSize: PropTypes.number,
241
- max: PropTypes.number,
242
- maxTicks: PropTypes.number,
243
- min: PropTypes.number,
244
- minTicks: PropTypes.number,
283
+ max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
284
+ min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
245
285
  position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
246
286
  scaleType: PropTypes.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
287
+ slotProps: PropTypes.object,
288
+ slots: PropTypes.object,
247
289
  stroke: PropTypes.string,
248
290
  tickFontSize: PropTypes.number,
291
+ tickMaxStep: PropTypes.number,
292
+ tickMinStep: PropTypes.number,
293
+ tickNumber: PropTypes.number,
249
294
  tickSize: PropTypes.number,
250
- tickSpacing: PropTypes.number,
251
295
  valueFormatter: PropTypes.func
252
296
  }))
253
297
  } : void 0;
@@ -15,6 +15,7 @@ var seriesTypeFormatter = {
15
15
  line: lineSeriesFormatter,
16
16
  pie: pieSeriesFormatter
17
17
  };
18
+
18
19
  /**
19
20
  * This methods is the interface between what the developer is providing and what components receives
20
21
  * To simplify the components behaviors, it groups series by type, such that LinePlots props are not updated if some line data are modified
@@ -23,7 +24,7 @@ var seriesTypeFormatter = {
23
24
  * @param colors The color palette used to defaultize series colors
24
25
  * @returns An object structuring all the series by type.
25
26
  */
26
- var formatSeries = function formatSeries(series, colors) {
27
+ var formatSeries = function formatSeries(series, colors, dataset) {
27
28
  // Group series by type
28
29
  var seriesGroups = {};
29
30
  series.forEach(function (seriesData, seriesIndex) {
@@ -50,20 +51,21 @@ var formatSeries = function formatSeries(series, colors) {
50
51
  Object.keys(seriesTypeFormatter).forEach(function (type) {
51
52
  if (seriesGroups[type] !== undefined) {
52
53
  var _seriesTypeFormatter$, _seriesTypeFormatter$2;
53
- formattedSeries[type] = (_seriesTypeFormatter$ = (_seriesTypeFormatter$2 = seriesTypeFormatter[type]) == null ? void 0 : _seriesTypeFormatter$2.call(seriesTypeFormatter, seriesGroups[type])) != null ? _seriesTypeFormatter$ : seriesGroups[type];
54
+ formattedSeries[type] = (_seriesTypeFormatter$ = (_seriesTypeFormatter$2 = seriesTypeFormatter[type]) == null ? void 0 : _seriesTypeFormatter$2.call(seriesTypeFormatter, seriesGroups[type], dataset)) != null ? _seriesTypeFormatter$ : seriesGroups[type];
54
55
  }
55
56
  });
56
57
  return formattedSeries;
57
58
  };
58
59
  export function SeriesContextProvider(_ref) {
59
60
  var series = _ref.series,
61
+ dataset = _ref.dataset,
60
62
  _ref$colors = _ref.colors,
61
63
  colors = _ref$colors === void 0 ? blueberryTwilightPalette : _ref$colors,
62
64
  children = _ref.children;
63
65
  var theme = useTheme();
64
66
  var formattedSeries = React.useMemo(function () {
65
- return formatSeries(series, typeof colors === 'function' ? colors(theme.palette.mode) : colors);
66
- }, [series, colors, theme.palette.mode]);
67
+ return formatSeries(series, typeof colors === 'function' ? colors(theme.palette.mode) : colors, dataset);
68
+ }, [series, colors, theme.palette.mode, dataset]);
67
69
  return /*#__PURE__*/_jsx(SeriesContext.Provider, {
68
70
  value: formattedSeries,
69
71
  children: children
@@ -2,15 +2,15 @@ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
2
  import * as React from 'react';
3
3
  import { isBandScale } from '../internals/isBandScale';
4
4
  export function getTicksNumber(params) {
5
- var _params$maxTicks = params.maxTicks,
6
- maxTicks = _params$maxTicks === void 0 ? 999 : _params$maxTicks,
7
- _params$minTicks = params.minTicks,
8
- minTicks = _params$minTicks === void 0 ? 2 : _params$minTicks,
9
- _params$tickSpacing = params.tickSpacing,
10
- tickSpacing = _params$tickSpacing === void 0 ? 50 : _params$tickSpacing,
11
- range = params.range;
12
- var estimatedTickNumber = Math.floor(Math.abs(range[1] - range[0]) / tickSpacing);
13
- return Math.min(maxTicks, Math.max(minTicks, estimatedTickNumber));
5
+ var tickMaxStep = params.tickMaxStep,
6
+ tickMinStep = params.tickMinStep,
7
+ tickNumber = params.tickNumber,
8
+ range = params.range,
9
+ domain = params.domain;
10
+ var maxTicks = tickMinStep === undefined ? 999 : Math.floor(Math.abs(domain[1] - domain[0]) / tickMinStep);
11
+ var minTicks = tickMaxStep === undefined ? 2 : Math.ceil(Math.abs(domain[1] - domain[0]) / tickMaxStep);
12
+ var defaultizedTickNumber = tickNumber != null ? tickNumber : Math.floor(Math.abs(range[1] - range[0]) / 50);
13
+ return Math.min(maxTicks, Math.max(minTicks, defaultizedTickNumber));
14
14
  }
15
15
  function useTicks(options) {
16
16
  var scale = options.scale,
package/legacy/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-charts v6.0.0-alpha.5
2
+ * @mui/x-charts v6.0.0-alpha.7
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
@@ -20,5 +20,6 @@ export * from './BarChart';
20
20
  export * from './LineChart';
21
21
  export * from './PieChart';
22
22
  export * from './ScatterChart';
23
+ export * from './SparkLineChart';
23
24
  export * from './ChartContainer';
24
25
  export * from './ResponsiveChartContainer';
@@ -10,24 +10,24 @@ export var AxisRoot = styled('g', {
10
10
  return styles.root;
11
11
  }
12
12
  })((_styled = {}, _defineProperty(_styled, "&.".concat(axisClasses.directionY), (_$concat = {}, _defineProperty(_$concat, ".".concat(axisClasses.tickLabel), {
13
- alignmentBaseline: 'middle'
13
+ dominantBaseline: 'middle'
14
14
  }), _defineProperty(_$concat, ".".concat(axisClasses.label), {
15
- alignmentBaseline: 'baseline',
15
+ dominantBaseline: 'auto',
16
16
  textAnchor: 'middle'
17
17
  }), _$concat)), _defineProperty(_styled, "&.".concat(axisClasses.left), _defineProperty({}, ".".concat(axisClasses.tickLabel), {
18
- alignmentBaseline: 'central',
18
+ dominantBaseline: 'central',
19
19
  textAnchor: 'end'
20
20
  })), _defineProperty(_styled, "&.".concat(axisClasses.right), _defineProperty({}, ".".concat(axisClasses.tickLabel), {
21
- alignmentBaseline: 'central',
21
+ dominantBaseline: 'central',
22
22
  textAnchor: 'start'
23
23
  })), _defineProperty(_styled, "&.".concat(axisClasses.bottom), _defineProperty({}, ".".concat(axisClasses.tickLabel, ", .").concat(axisClasses.label), {
24
- alignmentBaseline: 'hanging',
24
+ dominantBaseline: 'hanging',
25
25
  textAnchor: 'middle'
26
26
  })), _defineProperty(_styled, "&.".concat(axisClasses.top), _defineProperty({}, ".".concat(axisClasses.tickLabel, ", .").concat(axisClasses.label), {
27
- alignmentBaseline: 'baseline',
27
+ dominantBaseline: 'baseline',
28
28
  textAnchor: 'middle'
29
29
  })), _styled));
30
- export var Line = styled('line', {
30
+ export var ChartsLine = styled('line', {
31
31
  name: 'MuiChartsAxis',
32
32
  slot: 'Line',
33
33
  overridesResolver: function overridesResolver(props, styles) {
@@ -41,7 +41,7 @@ export var Line = styled('line', {
41
41
  strokeWidth: 1
42
42
  };
43
43
  });
44
- export var Tick = styled('line', {
44
+ export var ChartsTick = styled('line', {
45
45
  name: 'MuiChartsAxis',
46
46
  slot: 'Tick',
47
47
  overridesResolver: function overridesResolver(props, styles) {
@@ -54,7 +54,7 @@ export var Tick = styled('line', {
54
54
  shapeRendering: 'crispEdges'
55
55
  };
56
56
  });
57
- export var TickLabel = styled('text', {
57
+ export var ChartsTickLabel = styled('text', {
58
58
  name: 'MuiChartsAxis',
59
59
  slot: 'TickLabel',
60
60
  overridesResolver: function overridesResolver(props, styles) {
@@ -66,7 +66,7 @@ export var TickLabel = styled('text', {
66
66
  fill: theme.palette.text.primary
67
67
  });
68
68
  });
69
- export var Label = styled('text', {
69
+ export var ChartsLabel = styled('text', {
70
70
  name: 'MuiChartsAxis',
71
71
  slot: 'Label',
72
72
  overridesResolver: function overridesResolver(props, styles) {
@@ -1 +1,3 @@
1
- export * from './seriesType';
1
+ export * from './seriesType';
2
+ export * from './layout';
3
+ export {};
package/models/axis.d.ts CHANGED
@@ -1,9 +1,22 @@
1
+ /// <reference types="react" />
1
2
  import type { ScaleBand, ScaleLogarithmic, ScalePower, ScaleTime, ScaleLinear, ScalePoint } from 'd3-scale';
2
3
  import { ChartsAxisClasses } from '../ChartsAxis/axisClasses';
3
4
  import type { TickParams } from '../hooks/useTicks';
4
5
  export type D3Scale = ScaleBand<any> | ScaleLogarithmic<any, any> | ScalePoint<any> | ScalePower<any, any> | ScaleTime<any, any> | ScaleLinear<any, any>;
5
6
  export type D3ContinuouseScale = ScaleLogarithmic<any, any> | ScalePower<any, any> | ScaleTime<any, any> | ScaleLinear<any, any>;
6
- export interface ChartsAxisProps {
7
+ export interface ChartsAxisSlotsComponent {
8
+ axisLine?: React.JSXElementConstructor<React.SVGAttributes<SVGPathElement>>;
9
+ axisTick?: React.JSXElementConstructor<React.SVGAttributes<SVGPathElement>>;
10
+ axisTickLabel?: React.JSXElementConstructor<React.SVGAttributes<SVGTextElement>>;
11
+ axisLabel?: React.JSXElementConstructor<React.SVGAttributes<SVGTextElement>>;
12
+ }
13
+ export interface ChartsAxisSlotComponentProps {
14
+ axisLine?: Partial<React.SVGAttributes<SVGPathElement>>;
15
+ axisTick?: Partial<React.SVGAttributes<SVGPathElement>>;
16
+ axisTickLabel?: Partial<React.SVGAttributes<SVGTextElement>>;
17
+ axisLabel?: Partial<React.SVGAttributes<SVGTextElement>>;
18
+ }
19
+ export interface ChartsAxisProps extends TickParams {
7
20
  /**
8
21
  * Id of the axis to render.
9
22
  */
@@ -51,6 +64,16 @@ export interface ChartsAxisProps {
51
64
  * Override or extend the styles applied to the component.
52
65
  */
53
66
  classes?: Partial<ChartsAxisClasses>;
67
+ /**
68
+ * Overridable component slots.
69
+ * @default {}
70
+ */
71
+ slots?: Partial<ChartsAxisSlotsComponent>;
72
+ /**
73
+ * The props used for each component slot.
74
+ * @default {}
75
+ */
76
+ slotProps?: Partial<ChartsAxisSlotComponentProps>;
54
77
  }
55
78
  export interface ChartsYAxisProps extends ChartsAxisProps {
56
79
  /**
@@ -114,10 +137,18 @@ interface AxisScaleConfig {
114
137
  }
115
138
  export type AxisConfig<S extends ScaleName = ScaleName, V = any> = {
116
139
  id: string;
117
- min?: number;
118
- max?: number;
140
+ min?: number | Date;
141
+ max?: number | Date;
119
142
  data?: V[];
143
+ /**
144
+ * The key used to retrieve data from the dataset prop.
145
+ */
146
+ dataKey?: string;
120
147
  valueFormatter?: (value: V) => string;
148
+ /**
149
+ * If `true`, hide this value in the tooltip
150
+ */
151
+ hideTooltip?: boolean;
121
152
  } & Partial<ChartsXAxisProps | ChartsYAxisProps> & Partial<Omit<AxisScaleConfig[S], 'scale'>> & TickParams;
122
153
  export type AxisDefaultized<S extends ScaleName = ScaleName, V = any> = Omit<AxisConfig<S, V>, 'scaleType'> & AxisScaleConfig[S] & {
123
154
  ticksNumber: number;
package/models/index.d.ts CHANGED
@@ -1 +1,3 @@
1
1
  export * from './seriesType';
2
+ export * from './layout';
3
+ export type { AxisConfig, ChartsYAxisProps, ChartsXAxisProps, ScaleName, ContinuouseScaleName, } from './axis';
package/models/index.js CHANGED
@@ -13,4 +13,15 @@ Object.keys(_seriesType).forEach(function (key) {
13
13
  return _seriesType[key];
14
14
  }
15
15
  });
16
+ });
17
+ var _layout = require("./layout");
18
+ Object.keys(_layout).forEach(function (key) {
19
+ if (key === "default" || key === "__esModule") return;
20
+ if (key in exports && exports[key] === _layout[key]) return;
21
+ Object.defineProperty(exports, key, {
22
+ enumerable: true,
23
+ get: function () {
24
+ return _layout[key];
25
+ }
26
+ });
16
27
  });
@@ -2,7 +2,14 @@ import { DefaultizedProps } from '../helpers';
2
2
  import { CartesianSeriesType, CommonSeriesType, CommonDefaultizedProps, StackableSeriesType } from './common';
3
3
  export interface BarSeriesType extends CommonSeriesType<number>, CartesianSeriesType, StackableSeriesType {
4
4
  type: 'bar';
5
- data: number[];
5
+ /**
6
+ * Data associated to each bar.
7
+ */
8
+ data?: number[];
9
+ /**
10
+ * The key used to retrive data from the dataset.
11
+ */
12
+ dataKey?: string;
6
13
  label?: string;
7
14
  }
8
15
  /**
@@ -1,4 +1,4 @@
1
- import type { HighlightScope } from '@mui/x-charts/context/HighlightProvider';
1
+ import type { HighlightScope } from '../../context/HighlightProvider';
2
2
  import type { StackOffset, StackOrder } from '../../internals/stackSeries';
3
3
  export type CommonSeriesType<TValue> = {
4
4
  id?: string;
@@ -11,7 +11,7 @@ export type CommonSeriesType<TValue> = {
11
11
  valueFormatter?: (value: TValue) => string;
12
12
  highlightScope?: Partial<HighlightScope>;
13
13
  };
14
- export type CommonDefaultizedProps = 'id' | 'valueFormatter';
14
+ export type CommonDefaultizedProps = 'id' | 'valueFormatter' | 'data';
15
15
  export type CartesianSeriesType = {
16
16
  xAxisKey?: string;
17
17
  yAxisKey?: string;
@@ -73,7 +73,10 @@ export type FormatterResult<T extends ChartSeriesType> = {
73
73
  } ? {
74
74
  stackingGroups: StackingGroupsType;
75
75
  } : {});
76
- export type Formatter<T extends ChartSeriesType> = (params: FormatterParams<T>) => FormatterResult<T>;
76
+ export type DatasetType<T extends number | string | Date = number | string | Date> = {
77
+ [key: string]: T;
78
+ }[];
79
+ export type Formatter<T extends ChartSeriesType> = (params: FormatterParams<T>, dataset?: DatasetType<number>) => FormatterResult<T>;
77
80
  export type LegendParams = {
78
81
  /**
79
82
  * The color used in the legend
@@ -3,7 +3,14 @@ import { CartesianSeriesType, CommonDefaultizedProps, CommonSeriesType, Stackabl
3
3
  export type CurveType = 'catmullRom' | 'linear' | 'monotoneX' | 'monotoneY' | 'natural' | 'step' | 'stepBefore' | 'stepAfter';
4
4
  export interface LineSeriesType extends CommonSeriesType<number>, CartesianSeriesType, StackableSeriesType {
5
5
  type: 'line';
6
- data: number[];
6
+ /**
7
+ * Data associated to the line.
8
+ */
9
+ data?: number[];
10
+ /**
11
+ * The key used to retrive data from the dataset.
12
+ */
13
+ dataKey?: string;
7
14
  stack?: string;
8
15
  area?: boolean;
9
16
  label?: string;