@mui/x-charts 7.12.0 → 7.13.0

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 (196) hide show
  1. package/BarChart/BarChart.js +2 -0
  2. package/BarChart/BarPlot.js +2 -2
  3. package/BarChart/extremums.d.ts +1 -1
  4. package/BarChart/extremums.js +5 -3
  5. package/BarChart/formatter.d.ts +2 -2
  6. package/BarChart/getColor.d.ts +3 -3
  7. package/BarChart/getColor.js +4 -3
  8. package/BarChart/legend.d.ts +1 -1
  9. package/BarChart/plugin.d.ts +2 -2
  10. package/CHANGELOG.md +151 -2
  11. package/ChartContainer/ChartContainer.d.ts +4 -15
  12. package/ChartContainer/ChartContainer.js +8 -6
  13. package/ChartContainer/useChartContainerProps.d.ts +10 -7
  14. package/ChartContainer/useChartContainerProps.js +16 -19
  15. package/ChartContainer/useDefaultizeAxis.d.ts +2 -1
  16. package/ChartsTooltip/ChartsAxisTooltipContent.js +2 -2
  17. package/ChartsTooltip/ChartsItemTooltipContent.js +2 -2
  18. package/ChartsTooltip/utils.js +4 -2
  19. package/ChartsXAxis/ChartsXAxis.js +11 -5
  20. package/ChartsYAxis/ChartsYAxis.js +11 -5
  21. package/LineChart/AreaPlot.js +11 -1
  22. package/LineChart/LineChart.js +2 -0
  23. package/LineChart/extremums.d.ts +1 -1
  24. package/LineChart/extremums.js +4 -15
  25. package/LineChart/formatter.d.ts +2 -2
  26. package/LineChart/getColor.d.ts +3 -3
  27. package/LineChart/getColor.js +4 -3
  28. package/LineChart/legend.d.ts +1 -1
  29. package/LineChart/plugin.d.ts +2 -2
  30. package/PieChart/PieChart.js +2 -0
  31. package/PieChart/formatter.d.ts +2 -2
  32. package/PieChart/getColor.d.ts +3 -2
  33. package/PieChart/getColor.js +4 -3
  34. package/PieChart/legend.d.ts +1 -1
  35. package/PieChart/plugin.d.ts +2 -2
  36. package/ResponsiveChartContainer/ResponsiveChartContainer.js +2 -0
  37. package/ResponsiveChartContainer/useResponsiveChartContainerProps.d.ts +1 -2
  38. package/ScatterChart/ScatterChart.js +2 -0
  39. package/ScatterChart/extremums.d.ts +1 -1
  40. package/ScatterChart/extremums.js +6 -14
  41. package/ScatterChart/formatter.d.ts +2 -2
  42. package/ScatterChart/getColor.d.ts +3 -4
  43. package/ScatterChart/getColor.js +4 -3
  44. package/ScatterChart/legend.d.ts +1 -1
  45. package/ScatterChart/plugin.d.ts +2 -2
  46. package/SparkLineChart/SparkLineChart.js +2 -0
  47. package/context/CartesianProvider/CartesianProvider.d.ts +3 -12
  48. package/context/CartesianProvider/CartesianProvider.js +6 -4
  49. package/context/CartesianProvider/computeValue.d.ts +2 -1
  50. package/context/CartesianProvider/defaultizeAxis.d.ts +2 -1
  51. package/context/CartesianProvider/getAxisExtremum.d.ts +2 -2
  52. package/context/CartesianProvider/getAxisExtremum.js +3 -10
  53. package/context/PluginProvider/ColorProcessor.types.d.ts +8 -0
  54. package/context/PluginProvider/ExtremumGetter.types.d.ts +14 -0
  55. package/context/PluginProvider/ExtremumGetter.types.js +5 -0
  56. package/context/PluginProvider/Plugin.types.d.ts +25 -0
  57. package/context/PluginProvider/Plugin.types.js +5 -0
  58. package/context/PluginProvider/PluginContext.d.ts +4 -0
  59. package/{hooks/useColor.js → context/PluginProvider/PluginContext.js} +11 -7
  60. package/context/PluginProvider/PluginProvider.d.ts +4 -0
  61. package/context/{ColorProvider.js → PluginProvider/PluginProvider.js} +12 -11
  62. package/context/PluginProvider/SeriesFormatter.types.d.ts +21 -0
  63. package/context/PluginProvider/SeriesFormatter.types.js +5 -0
  64. package/context/PluginProvider/index.d.ts +10 -0
  65. package/context/PluginProvider/index.js +115 -0
  66. package/context/PluginProvider/mergePlugins.d.ts +36 -0
  67. package/context/PluginProvider/mergePlugins.js +37 -0
  68. package/context/PluginProvider/useColorProcessor.d.ts +4 -0
  69. package/context/PluginProvider/useColorProcessor.js +23 -0
  70. package/context/PluginProvider/useSeriesFormatter.d.ts +4 -0
  71. package/context/PluginProvider/useSeriesFormatter.js +23 -0
  72. package/context/PluginProvider/useXExtremumGetter.d.ts +4 -0
  73. package/context/PluginProvider/useXExtremumGetter.js +23 -0
  74. package/context/PluginProvider/useYExtremumGetter.d.ts +4 -0
  75. package/context/PluginProvider/useYExtremumGetter.js +23 -0
  76. package/context/SeriesProvider/Series.types.d.ts +4 -10
  77. package/context/SeriesProvider/SeriesProvider.js +2 -1
  78. package/context/SeriesProvider/index.d.ts +1 -1
  79. package/context/SeriesProvider/processSeries.d.ts +2 -1
  80. package/esm/BarChart/BarChart.js +2 -0
  81. package/esm/BarChart/BarPlot.js +1 -2
  82. package/esm/BarChart/extremums.js +5 -3
  83. package/esm/BarChart/getColor.js +3 -2
  84. package/esm/ChartContainer/ChartContainer.js +9 -7
  85. package/esm/ChartContainer/useChartContainerProps.js +14 -19
  86. package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +1 -1
  87. package/esm/ChartsTooltip/ChartsItemTooltipContent.js +1 -1
  88. package/esm/ChartsTooltip/utils.js +4 -2
  89. package/esm/ChartsXAxis/ChartsXAxis.js +11 -5
  90. package/esm/ChartsYAxis/ChartsYAxis.js +11 -5
  91. package/esm/LineChart/AreaPlot.js +11 -1
  92. package/esm/LineChart/LineChart.js +2 -0
  93. package/esm/LineChart/extremums.js +4 -15
  94. package/esm/LineChart/getColor.js +3 -2
  95. package/esm/PieChart/PieChart.js +2 -0
  96. package/esm/PieChart/getColor.js +3 -2
  97. package/esm/ResponsiveChartContainer/ResponsiveChartContainer.js +2 -0
  98. package/esm/ScatterChart/ScatterChart.js +2 -0
  99. package/esm/ScatterChart/extremums.js +6 -14
  100. package/esm/ScatterChart/getColor.js +3 -2
  101. package/esm/SparkLineChart/SparkLineChart.js +2 -0
  102. package/esm/context/CartesianProvider/CartesianProvider.js +6 -4
  103. package/esm/context/CartesianProvider/getAxisExtremum.js +3 -10
  104. package/esm/context/PluginProvider/Plugin.types.js +1 -0
  105. package/esm/context/PluginProvider/PluginContext.js +13 -0
  106. package/esm/context/PluginProvider/PluginProvider.js +19 -0
  107. package/esm/context/PluginProvider/SeriesFormatter.types.js +1 -0
  108. package/esm/context/PluginProvider/index.js +10 -0
  109. package/esm/context/PluginProvider/mergePlugins.js +30 -0
  110. package/esm/context/PluginProvider/useColorProcessor.js +15 -0
  111. package/esm/context/PluginProvider/useSeriesFormatter.js +15 -0
  112. package/esm/context/PluginProvider/useXExtremumGetter.js +15 -0
  113. package/esm/context/PluginProvider/useYExtremumGetter.js +15 -0
  114. package/esm/context/SeriesProvider/SeriesProvider.js +2 -1
  115. package/esm/hooks/useTicks.js +5 -2
  116. package/esm/internals/index.js +1 -1
  117. package/esm/internals/isInfinity.js +3 -0
  118. package/esm/models/index.js +0 -1
  119. package/hooks/useTicks.js +5 -2
  120. package/index.js +1 -1
  121. package/internals/colorScale.d.ts +1 -1
  122. package/internals/defaultizeColor.d.ts +1 -0
  123. package/internals/index.d.ts +1 -1
  124. package/internals/index.js +12 -12
  125. package/internals/isInfinity.d.ts +1 -0
  126. package/internals/isInfinity.js +9 -0
  127. package/models/axis.d.ts +2 -0
  128. package/models/index.d.ts +0 -1
  129. package/models/index.js +0 -11
  130. package/models/seriesType/config.d.ts +0 -26
  131. package/models/seriesType/line.d.ts +10 -0
  132. package/modern/BarChart/BarChart.js +2 -0
  133. package/modern/BarChart/BarPlot.js +1 -2
  134. package/modern/BarChart/extremums.js +5 -3
  135. package/modern/BarChart/getColor.js +3 -2
  136. package/modern/ChartContainer/ChartContainer.js +9 -7
  137. package/modern/ChartContainer/useChartContainerProps.js +14 -19
  138. package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +1 -1
  139. package/modern/ChartsTooltip/ChartsItemTooltipContent.js +1 -1
  140. package/modern/ChartsTooltip/utils.js +4 -2
  141. package/modern/ChartsXAxis/ChartsXAxis.js +11 -5
  142. package/modern/ChartsYAxis/ChartsYAxis.js +11 -5
  143. package/modern/LineChart/AreaPlot.js +11 -1
  144. package/modern/LineChart/LineChart.js +2 -0
  145. package/modern/LineChart/extremums.js +4 -15
  146. package/modern/LineChart/getColor.js +3 -2
  147. package/modern/PieChart/PieChart.js +2 -0
  148. package/modern/PieChart/getColor.js +3 -2
  149. package/modern/ResponsiveChartContainer/ResponsiveChartContainer.js +2 -0
  150. package/modern/ScatterChart/ScatterChart.js +2 -0
  151. package/modern/ScatterChart/extremums.js +6 -14
  152. package/modern/ScatterChart/getColor.js +3 -2
  153. package/modern/SparkLineChart/SparkLineChart.js +2 -0
  154. package/modern/context/CartesianProvider/CartesianProvider.js +6 -4
  155. package/modern/context/CartesianProvider/getAxisExtremum.js +3 -10
  156. package/modern/context/PluginProvider/ColorProcessor.types.js +1 -0
  157. package/modern/context/PluginProvider/ExtremumGetter.types.js +1 -0
  158. package/modern/context/PluginProvider/Plugin.types.js +1 -0
  159. package/modern/context/PluginProvider/PluginContext.js +13 -0
  160. package/modern/context/PluginProvider/PluginProvider.js +19 -0
  161. package/modern/context/PluginProvider/SeriesFormatter.types.js +1 -0
  162. package/modern/context/PluginProvider/index.js +10 -0
  163. package/modern/context/PluginProvider/mergePlugins.js +30 -0
  164. package/modern/context/PluginProvider/useColorProcessor.js +15 -0
  165. package/modern/context/PluginProvider/useSeriesFormatter.js +15 -0
  166. package/modern/context/PluginProvider/useXExtremumGetter.js +15 -0
  167. package/modern/context/PluginProvider/useYExtremumGetter.js +15 -0
  168. package/modern/context/SeriesProvider/SeriesProvider.js +2 -1
  169. package/modern/hooks/useTicks.js +5 -2
  170. package/modern/index.js +1 -1
  171. package/modern/internals/index.js +1 -1
  172. package/modern/internals/isInfinity.js +3 -0
  173. package/modern/models/index.js +0 -1
  174. package/package.json +2 -2
  175. package/ChartContainer/defaultPlugins.d.ts +0 -2
  176. package/ChartContainer/defaultPlugins.js +0 -11
  177. package/ChartContainer/useChartContainerHooks.d.ts +0 -11
  178. package/ChartContainer/useChartContainerHooks.js +0 -34
  179. package/ChartContainer/usePluginsMerge.d.ts +0 -9
  180. package/ChartContainer/usePluginsMerge.js +0 -39
  181. package/context/ColorProvider.d.ts +0 -12
  182. package/esm/ChartContainer/defaultPlugins.js +0 -5
  183. package/esm/ChartContainer/useChartContainerHooks.js +0 -24
  184. package/esm/ChartContainer/usePluginsMerge.js +0 -31
  185. package/esm/context/ColorProvider.js +0 -16
  186. package/esm/hooks/useColor.js +0 -9
  187. package/hooks/useColor.d.ts +0 -4
  188. package/models/plugin.d.ts +0 -19
  189. package/modern/ChartContainer/defaultPlugins.js +0 -5
  190. package/modern/ChartContainer/useChartContainerHooks.js +0 -24
  191. package/modern/ChartContainer/usePluginsMerge.js +0 -31
  192. package/modern/context/ColorProvider.js +0 -16
  193. package/modern/hooks/useColor.js +0 -9
  194. /package/{models/plugin.js → context/PluginProvider/ColorProcessor.types.js} +0 -0
  195. /package/esm/{models/plugin.js → context/PluginProvider/ColorProcessor.types.js} +0 -0
  196. /package/{modern/models/plugin.js → esm/context/PluginProvider/ExtremumGetter.types.js} +0 -0
@@ -0,0 +1,15 @@
1
+ import * as React from 'react';
2
+ import { PluginContext } from './PluginContext';
3
+ export function useSeriesFormatter(seriesType) {
4
+ const {
5
+ isInitialized,
6
+ data
7
+ } = React.useContext(PluginContext);
8
+ if (!isInitialized) {
9
+ throw new Error(['MUI X: Could not find the plugin context.', 'It looks like you rendered your component outside of a ChartsContainer parent component.'].join('\n'));
10
+ }
11
+ if (!seriesType) {
12
+ return data.seriesFormatters;
13
+ }
14
+ return data.seriesFormatters[seriesType];
15
+ }
@@ -0,0 +1,15 @@
1
+ import * as React from 'react';
2
+ import { PluginContext } from './PluginContext';
3
+ export function useXExtremumGetter(seriesType) {
4
+ const {
5
+ isInitialized,
6
+ data
7
+ } = React.useContext(PluginContext);
8
+ if (!isInitialized) {
9
+ throw new Error(['MUI X: Could not find the plugin context.', 'It looks like you rendered your component outside of a ChartsContainer parent component.'].join('\n'));
10
+ }
11
+ if (!seriesType) {
12
+ return data.xExtremumGetters;
13
+ }
14
+ return data.xExtremumGetters[seriesType];
15
+ }
@@ -0,0 +1,15 @@
1
+ import * as React from 'react';
2
+ import { PluginContext } from './PluginContext';
3
+ export function useYExtremumGetter(seriesType) {
4
+ const {
5
+ isInitialized,
6
+ data
7
+ } = React.useContext(PluginContext);
8
+ if (!isInitialized) {
9
+ throw new Error(['MUI X: Could not find the plugin context.', 'It looks like you rendered your component outside of a ChartsContainer parent component.'].join('\n'));
10
+ }
11
+ if (!seriesType) {
12
+ return data.yExtremumGetters;
13
+ }
14
+ return data.yExtremumGetters[seriesType];
15
+ }
@@ -3,15 +3,16 @@ import { useTheme } from '@mui/material/styles';
3
3
  import { blueberryTwilightPalette } from '../../colorPalettes';
4
4
  import { SeriesContext } from './SeriesContext';
5
5
  import { preprocessSeries } from './processSeries';
6
+ import { useSeriesFormatter } from '../PluginProvider';
6
7
  import { jsx as _jsx } from "react/jsx-runtime";
7
8
  function SeriesProvider(props) {
8
9
  const {
9
10
  series,
10
11
  dataset,
11
12
  colors = blueberryTwilightPalette,
12
- seriesFormatters,
13
13
  children
14
14
  } = props;
15
+ const seriesFormatters = useSeriesFormatter();
15
16
  const theme = useTheme();
16
17
  const formattedSeries = React.useMemo(() => ({
17
18
  isInitialized: true,
@@ -1,5 +1,6 @@
1
1
  import * as React from 'react';
2
2
  import { isBandScale } from '../internals/isBandScale';
3
+ import { isInfinity } from '../internals/isInfinity';
3
4
  export function getTickNumber(params) {
4
5
  const {
5
6
  tickMaxStep,
@@ -60,8 +61,10 @@ export function useTicks(options) {
60
61
  labelOffset: 0
61
62
  }));
62
63
  }
63
- if (scale.domain().length === 0 || scale.domain()[0] === scale.domain()[1]) {
64
- // The axis should not be visible, so ticks should also be hidden.
64
+ const domain = scale.domain();
65
+ // Skip axis rendering if no data is available
66
+ // - The domains contains Infinity for continuous scales.
67
+ if (domain.some(isInfinity)) {
65
68
  return [];
66
69
  }
67
70
  const ticks = typeof tickInterval === 'object' ? tickInterval : scale.ticks(tickNumber);
@@ -25,10 +25,10 @@ export * from './isDefined';
25
25
 
26
26
  export * from '../context/CartesianProvider';
27
27
  export * from '../context/DrawingProvider';
28
- export * from '../context/ColorProvider';
29
28
  export * from '../context/InteractionProvider';
30
29
  export * from '../context/SeriesProvider';
31
30
  export * from '../context/ZAxisContextProvider';
31
+ export * from '../context/PluginProvider';
32
32
  // series configuration
33
33
  export * from '../models/seriesType/config';
34
34
  export * from '../models/seriesType/common';
@@ -0,0 +1,3 @@
1
+ export function isInfinity(v) {
2
+ return typeof v === 'number' && !Number.isFinite(v);
3
+ }
@@ -1,5 +1,4 @@
1
1
  export * from './seriesType';
2
2
  export * from './layout';
3
3
  export * from './stacking';
4
- export * from './plugin';
5
4
  export {};
package/hooks/useTicks.js CHANGED
@@ -7,6 +7,7 @@ exports.getTickNumber = getTickNumber;
7
7
  exports.useTicks = useTicks;
8
8
  var React = _interopRequireWildcard(require("react"));
9
9
  var _isBandScale = require("../internals/isBandScale");
10
+ var _isInfinity = require("../internals/isInfinity");
10
11
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
11
12
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
12
13
  function getTickNumber(params) {
@@ -69,8 +70,10 @@ function useTicks(options) {
69
70
  labelOffset: 0
70
71
  }));
71
72
  }
72
- if (scale.domain().length === 0 || scale.domain()[0] === scale.domain()[1]) {
73
- // The axis should not be visible, so ticks should also be hidden.
73
+ const domain = scale.domain();
74
+ // Skip axis rendering if no data is available
75
+ // - The domains contains Infinity for continuous scales.
76
+ if (domain.some(_isInfinity.isInfinity)) {
74
77
  return [];
75
78
  }
76
79
  const ticks = typeof tickInterval === 'object' ? tickInterval : scale.ticks(tickNumber);
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-charts v7.12.0
2
+ * @mui/x-charts v7.13.0
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
@@ -2,4 +2,4 @@ import { ScaleOrdinal } from '@mui/x-charts-vendor/d3-scale';
2
2
  import { ContinuousColorConfig, PiecewiseColorConfig, OrdinalColorConfig } from '../models/colorMapping';
3
3
  export declare function getSequentialColorScale<Value extends number | Date>(config: ContinuousColorConfig<Value> | PiecewiseColorConfig<Value>): import("@mui/x-charts-vendor/d3-scale").ScaleThreshold<Value, string, never> | import("@mui/x-charts-vendor/d3-scale").ScaleSequential<string, never>;
4
4
  export declare function getOrdinalColorScale<Value extends number | Date | string>(config: OrdinalColorConfig<Value>): ScaleOrdinal<Value, string, null | string> | ScaleOrdinal<number, string, null | string>;
5
- export declare function getColorScale(config: ContinuousColorConfig | PiecewiseColorConfig | OrdinalColorConfig): import("@mui/x-charts-vendor/d3-scale").ScaleSequential<string, never> | ScaleOrdinal<number, string, string | null> | ScaleOrdinal<string | number | Date, string, string | null> | import("@mui/x-charts-vendor/d3-scale").ScaleThreshold<number | Date, string, never>;
5
+ export declare function getColorScale(config: ContinuousColorConfig | PiecewiseColorConfig | OrdinalColorConfig): ScaleOrdinal<string | number | Date, string, string | null> | ScaleOrdinal<number, string, string | null> | import("@mui/x-charts-vendor/d3-scale").ScaleSequential<string, never> | import("@mui/x-charts-vendor/d3-scale").ScaleThreshold<number | Date, string, never>;
@@ -72,6 +72,7 @@ export declare function defaultizeColor(series: AllSeriesType, seriesIndex: numb
72
72
  disableHighlight?: boolean;
73
73
  connectNulls?: boolean;
74
74
  stackOffset?: import("..").StackOffsetType;
75
+ baseline?: number | "min" | "max";
75
76
  id?: import(".").SeriesId;
76
77
  color: string;
77
78
  valueFormatter?: import(".").SeriesValueFormatter<number | null> | undefined;
@@ -17,10 +17,10 @@ export * from './getSVGPoint';
17
17
  export * from './isDefined';
18
18
  export * from '../context/CartesianProvider';
19
19
  export * from '../context/DrawingProvider';
20
- export * from '../context/ColorProvider';
21
20
  export * from '../context/InteractionProvider';
22
21
  export * from '../context/SeriesProvider';
23
22
  export * from '../context/ZAxisContextProvider';
23
+ export * from '../context/PluginProvider';
24
24
  export type * from '../context/context.types';
25
25
  export * from '../models/seriesType/config';
26
26
  export * from '../models/seriesType/common';
@@ -197,18 +197,6 @@ Object.keys(_DrawingProvider).forEach(function (key) {
197
197
  }
198
198
  });
199
199
  });
200
- var _ColorProvider = require("../context/ColorProvider");
201
- Object.keys(_ColorProvider).forEach(function (key) {
202
- if (key === "default" || key === "__esModule") return;
203
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
204
- if (key in exports && exports[key] === _ColorProvider[key]) return;
205
- Object.defineProperty(exports, key, {
206
- enumerable: true,
207
- get: function () {
208
- return _ColorProvider[key];
209
- }
210
- });
211
- });
212
200
  var _InteractionProvider = require("../context/InteractionProvider");
213
201
  Object.keys(_InteractionProvider).forEach(function (key) {
214
202
  if (key === "default" || key === "__esModule") return;
@@ -245,6 +233,18 @@ Object.keys(_ZAxisContextProvider).forEach(function (key) {
245
233
  }
246
234
  });
247
235
  });
236
+ var _PluginProvider = require("../context/PluginProvider");
237
+ Object.keys(_PluginProvider).forEach(function (key) {
238
+ if (key === "default" || key === "__esModule") return;
239
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
240
+ if (key in exports && exports[key] === _PluginProvider[key]) return;
241
+ Object.defineProperty(exports, key, {
242
+ enumerable: true,
243
+ get: function () {
244
+ return _PluginProvider[key];
245
+ }
246
+ });
247
+ });
248
248
  var _config = require("../models/seriesType/config");
249
249
  Object.keys(_config).forEach(function (key) {
250
250
  if (key === "default" || key === "__esModule") return;
@@ -0,0 +1 @@
1
+ export declare function isInfinity(v: any): v is number;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.isInfinity = isInfinity;
7
+ function isInfinity(v) {
8
+ return typeof v === 'number' && !Number.isFinite(v);
9
+ }
package/models/axis.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import type { ScaleBand, ScaleLogarithmic, ScalePower, ScaleTime, ScaleLinear, ScalePoint, ScaleOrdinal, ScaleSequential, ScaleThreshold } from '@mui/x-charts-vendor/d3-scale';
2
+ import { SxProps } from '@mui/system';
2
3
  import { ChartsAxisClasses } from '../ChartsAxis/axisClasses';
3
4
  import type { TickParams } from '../hooks/useTicks';
4
5
  import { ChartsTextProps } from '../ChartsText';
@@ -112,6 +113,7 @@ export interface ChartsAxisProps extends TickParams {
112
113
  * @default {}
113
114
  */
114
115
  slotProps?: Partial<ChartsAxisSlotProps>;
116
+ sx?: SxProps;
115
117
  }
116
118
  export interface ChartsYAxisProps extends ChartsAxisProps {
117
119
  /**
package/models/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  export * from './seriesType';
2
2
  export * from './layout';
3
3
  export * from './stacking';
4
- export * from './plugin';
5
4
  export type { AxisConfig, ChartsYAxisProps, ChartsXAxisProps, ScaleName, ContinuousScaleName, } from './axis';
package/models/index.js CHANGED
@@ -35,15 +35,4 @@ Object.keys(_stacking).forEach(function (key) {
35
35
  return _stacking[key];
36
36
  }
37
37
  });
38
- });
39
- var _plugin = require("./plugin");
40
- Object.keys(_plugin).forEach(function (key) {
41
- if (key === "default" || key === "__esModule") return;
42
- if (key in exports && exports[key] === _plugin[key]) return;
43
- Object.defineProperty(exports, key, {
44
- enumerable: true,
45
- get: function () {
46
- return _plugin[key];
47
- }
48
- });
49
38
  });
@@ -2,11 +2,7 @@ import { ScatterSeriesType, DefaultizedScatterSeriesType, ScatterItemIdentifier
2
2
  import { LineSeriesType, DefaultizedLineSeriesType, LineItemIdentifier } from './line';
3
3
  import { BarItemIdentifier, BarSeriesType, DefaultizedBarSeriesType } from './bar';
4
4
  import { PieSeriesType, DefaultizedPieSeriesType, PieItemIdentifier, PieValueType } from './pie';
5
- import { AxisConfig } from '../axis';
6
5
  import { DefaultizedProps, MakeOptional } from '../helpers';
7
- import { StackingGroupsType } from '../../internals/stackSeries';
8
- import { SeriesId } from './common';
9
- import { LegendItemParams } from '../../ChartsLegend/chartsLegend.types';
10
6
  export interface ChartsSeriesConfig {
11
7
  bar: {
12
8
  /**
@@ -79,29 +75,7 @@ export type ChartSeriesDefaultized<T extends ChartSeriesType> = ChartsSeriesConf
79
75
  stackedData: [number, number][];
80
76
  } : ChartsSeriesConfig[T]['series'];
81
77
  export type ChartItemIdentifier<T extends ChartSeriesType> = ChartsSeriesConfig[T]['itemIdentifier'];
82
- type ExtremumGetterParams<T extends ChartSeriesType> = {
83
- series: Record<SeriesId, ChartSeries<T>>;
84
- axis: AxisConfig;
85
- isDefaultAxis: boolean;
86
- };
87
- export type ExtremumGetterResult = [number, number] | [null, null];
88
- export type ExtremumGetter<T extends ChartSeriesType> = (params: ExtremumGetterParams<T>) => ExtremumGetterResult;
89
- export type FormatterParams<T extends ChartSeriesType> = {
90
- series: Record<SeriesId, ChartsSeriesConfig[T]['seriesInput']>;
91
- seriesOrder: SeriesId[];
92
- };
93
- export type FormatterResult<T extends ChartSeriesType> = {
94
- series: Record<SeriesId, ChartSeriesDefaultized<T>>;
95
- seriesOrder: SeriesId[];
96
- } & (ChartsSeriesConfig[T] extends {
97
- canBeStacked: true;
98
- } ? {
99
- stackingGroups: StackingGroupsType;
100
- } : {});
101
78
  export type DatasetElementType<T> = {
102
79
  [key: string]: T;
103
80
  };
104
81
  export type DatasetType<T = number | string | Date | null | undefined> = DatasetElementType<T>[];
105
- export type Formatter<T extends ChartSeriesType> = (params: FormatterParams<T>, dataset?: DatasetType) => FormatterResult<T>;
106
- export type LegendGetter<T extends ChartSeriesType> = (series: FormatterResult<T>) => LegendItemParams[];
107
- export {};
@@ -62,6 +62,16 @@ export interface LineSeriesType extends CommonSeriesType<number | null>, Cartesi
62
62
  * @default 'none'
63
63
  */
64
64
  stackOffset?: StackOffsetType;
65
+ /**
66
+ * The value of the line at the base of the series area.
67
+ *
68
+ * - `'min'` the area will fill the space **under** the line.
69
+ * - `'max'` the area will fill the space **above** the line.
70
+ * - `number` the area will fill the space between this value and the line
71
+ *
72
+ * @default 0
73
+ */
74
+ baseline?: number | 'min' | 'max';
65
75
  }
66
76
  /**
67
77
  * An object that allows to identify a single line.
@@ -273,6 +273,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
273
273
  slotProps: PropTypes.object,
274
274
  slots: PropTypes.object,
275
275
  stroke: PropTypes.string,
276
+ sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
276
277
  tickFontSize: PropTypes.number,
277
278
  tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
278
279
  tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
@@ -325,6 +326,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
325
326
  slotProps: PropTypes.object,
326
327
  slots: PropTypes.object,
327
328
  stroke: PropTypes.string,
329
+ sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
328
330
  tickFontSize: PropTypes.number,
329
331
  tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
330
332
  tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
@@ -12,7 +12,7 @@ import { BarClipPath } from './BarClipPath';
12
12
  import { BarLabelPlot } from './BarLabel/BarLabelPlot';
13
13
  import { checkScaleErrors } from './checkScaleErrors';
14
14
  import { useBarSeries } from '../hooks/useSeries';
15
-
15
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
16
16
  /**
17
17
  * Solution of the equations
18
18
  * W = barWidth * N + offset * (N-1)
@@ -22,7 +22,6 @@ import { useBarSeries } from '../hooks/useSeries';
22
22
  * @param gapRatio The ratio of the gap between bars over the bar width.
23
23
  * @returns The bar width and the offset between bars.
24
24
  */
25
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
26
25
  function getBandSize({
27
26
  bandWidth: W,
28
27
  numberOfGroups: N,
@@ -16,9 +16,11 @@ const getValueExtremum = params => {
16
16
  const yAxisId = series[seriesId].yAxisId ?? series[seriesId].yAxisKey;
17
17
  return yAxisId === axis.id || isDefaultAxis && yAxisId === undefined;
18
18
  }).reduce((acc, seriesId) => {
19
- const [seriesMin, seriesMax] = series[seriesId].stackedData?.reduce((seriesAcc, values) => [Math.min(...values, ...(seriesAcc[0] === null ? [] : [seriesAcc[0]])), Math.max(...values, ...(seriesAcc[1] === null ? [] : [seriesAcc[1]]))], series[seriesId].stackedData[0]) ?? [null, null];
20
- return [acc[0] === null ? seriesMin : Math.min(seriesMin, acc[0]), acc[1] === null ? seriesMax : Math.max(seriesMax, acc[1])];
21
- }, [null, null]);
19
+ const [seriesMin, seriesMax] = series[seriesId].stackedData?.reduce((seriesAcc, values) => {
20
+ return [Math.min(...values, seriesAcc[0]), Math.max(...values, seriesAcc[1])];
21
+ }, [Infinity, -Infinity]) ?? [Infinity, -Infinity];
22
+ return [Math.min(seriesMin, acc[0]), Math.max(seriesMax, acc[1])];
23
+ }, [Infinity, -Infinity]);
22
24
  };
23
25
  export const getExtremumX = params => {
24
26
  // Notice that bar should be all horizontal or all vertical.
@@ -1,4 +1,4 @@
1
- export default function getColor(series, xAxis, yAxis) {
1
+ const getColor = (series, xAxis, yAxis) => {
2
2
  const verticalLayout = series.layout === 'vertical';
3
3
  const bandColorScale = verticalLayout ? xAxis?.colorScale : yAxis?.colorScale;
4
4
  const valueColorScale = verticalLayout ? yAxis?.colorScale : xAxis?.colorScale;
@@ -24,4 +24,5 @@ export default function getColor(series, xAxis, yAxis) {
24
24
  };
25
25
  }
26
26
  return () => series.color;
27
- }
27
+ };
28
+ export default getColor;
@@ -4,28 +4,28 @@ import PropTypes from 'prop-types';
4
4
  import { DrawingProvider } from '../context/DrawingProvider';
5
5
  import { SeriesProvider } from '../context/SeriesProvider';
6
6
  import { InteractionProvider } from '../context/InteractionProvider';
7
- import { ColorProvider } from '../context/ColorProvider';
8
7
  import { ChartsSurface } from '../ChartsSurface';
9
- import { CartesianContextProvider } from '../context/CartesianProvider';
8
+ import { CartesianProvider } from '../context/CartesianProvider';
10
9
  import { ChartsAxesGradients } from '../internals/components/ChartsAxesGradients';
11
10
  import { HighlightedProvider, ZAxisContextProvider } from '../context';
11
+ import { PluginProvider } from '../context/PluginProvider';
12
12
  import { useChartContainerProps } from './useChartContainerProps';
13
13
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
14
14
  const ChartContainer = /*#__PURE__*/React.forwardRef(function ChartContainer(props, ref) {
15
15
  const {
16
16
  children,
17
17
  drawingProviderProps,
18
- colorProviderProps,
19
18
  seriesProviderProps,
20
- cartesianContextProps,
19
+ cartesianProviderProps,
21
20
  zAxisContextProps,
22
21
  highlightedProviderProps,
23
- chartsSurfaceProps
22
+ chartsSurfaceProps,
23
+ pluginProviderProps
24
24
  } = useChartContainerProps(props, ref);
25
25
  return /*#__PURE__*/_jsx(DrawingProvider, _extends({}, drawingProviderProps, {
26
- children: /*#__PURE__*/_jsx(ColorProvider, _extends({}, colorProviderProps, {
26
+ children: /*#__PURE__*/_jsx(PluginProvider, _extends({}, pluginProviderProps, {
27
27
  children: /*#__PURE__*/_jsx(SeriesProvider, _extends({}, seriesProviderProps, {
28
- children: /*#__PURE__*/_jsx(CartesianContextProvider, _extends({}, cartesianContextProps, {
28
+ children: /*#__PURE__*/_jsx(CartesianProvider, _extends({}, cartesianProviderProps, {
29
29
  children: /*#__PURE__*/_jsx(ZAxisContextProvider, _extends({}, zAxisContextProps, {
30
30
  children: /*#__PURE__*/_jsx(InteractionProvider, {
31
31
  children: /*#__PURE__*/_jsx(HighlightedProvider, _extends({}, highlightedProviderProps, {
@@ -155,6 +155,7 @@ process.env.NODE_ENV !== "production" ? ChartContainer.propTypes = {
155
155
  slotProps: PropTypes.object,
156
156
  slots: PropTypes.object,
157
157
  stroke: PropTypes.string,
158
+ sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
158
159
  tickFontSize: PropTypes.number,
159
160
  tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
160
161
  tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
@@ -207,6 +208,7 @@ process.env.NODE_ENV !== "production" ? ChartContainer.propTypes = {
207
208
  slotProps: PropTypes.object,
208
209
  slots: PropTypes.object,
209
210
  stroke: PropTypes.string,
211
+ sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
210
212
  tickFontSize: PropTypes.number,
211
213
  tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
212
214
  tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
@@ -1,8 +1,10 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
3
  const _excluded = ["width", "height", "series", "margin", "xAxis", "yAxis", "zAxis", "colors", "dataset", "sx", "title", "desc", "disableAxisListener", "highlightedItem", "onHighlightChange", "plugins", "children"];
4
- import { useChartContainerHooks } from './useChartContainerHooks';
4
+ import * as React from 'react';
5
+ import useForkRef from '@mui/utils/useForkRef';
5
6
  import { useDefaultizeAxis } from './useDefaultizeAxis';
7
+ import { useReducedMotion } from '../hooks/useReducedMotion';
6
8
  export const useChartContainerProps = (props, ref) => {
7
9
  const {
8
10
  width,
@@ -24,14 +26,10 @@ export const useChartContainerProps = (props, ref) => {
24
26
  children
25
27
  } = props,
26
28
  other = _objectWithoutPropertiesLoose(props, _excluded);
27
- const {
28
- svgRef,
29
- chartSurfaceRef,
30
- xExtremumGetters,
31
- yExtremumGetters,
32
- seriesFormatters,
33
- colorProcessors
34
- } = useChartContainerHooks(ref, plugins);
29
+ const svgRef = React.useRef(null);
30
+ const chartSurfaceRef = useForkRef(ref, svgRef);
31
+ useReducedMotion(); // a11y reduce motion (see: https://react-spring.dev/docs/utilities/use-reduced-motion)
32
+
35
33
  const [defaultizedXAxis, defaultizedYAxis] = useDefaultizeAxis(xAxis, yAxis);
36
34
  const drawingProviderProps = {
37
35
  width,
@@ -39,21 +37,18 @@ export const useChartContainerProps = (props, ref) => {
39
37
  margin,
40
38
  svgRef
41
39
  };
42
- const colorProviderProps = {
43
- colorProcessors
40
+ const pluginProviderProps = {
41
+ plugins
44
42
  };
45
43
  const seriesProviderProps = {
46
44
  series,
47
45
  colors,
48
- dataset,
49
- seriesFormatters
46
+ dataset
50
47
  };
51
- const cartesianContextProps = {
48
+ const cartesianProviderProps = {
52
49
  xAxis: defaultizedXAxis,
53
50
  yAxis: defaultizedYAxis,
54
- dataset,
55
- xExtremumGetters,
56
- yExtremumGetters
51
+ dataset
57
52
  };
58
53
  const zAxisContextProps = {
59
54
  zAxis,
@@ -75,12 +70,12 @@ export const useChartContainerProps = (props, ref) => {
75
70
  return {
76
71
  children,
77
72
  drawingProviderProps,
78
- colorProviderProps,
79
73
  seriesProviderProps,
80
- cartesianContextProps,
74
+ cartesianProviderProps,
81
75
  zAxisContextProps,
82
76
  highlightedProviderProps,
83
77
  chartsSurfaceProps,
78
+ pluginProviderProps,
84
79
  xAxis: defaultizedXAxis,
85
80
  yAxis: defaultizedYAxis
86
81
  };
@@ -4,7 +4,7 @@ import useSlotProps from '@mui/utils/useSlotProps';
4
4
  import { useCartesianContext } from '../context/CartesianProvider';
5
5
  import { DefaultChartsAxisTooltipContent } from './DefaultChartsAxisTooltipContent';
6
6
  import { ZAxisContext } from '../context/ZAxisContextProvider';
7
- import { useColorProcessor } from '../hooks/useColor';
7
+ import { useColorProcessor } from '../context/PluginProvider/useColorProcessor';
8
8
  import { isCartesianSeriesType } from '../internals/isCartesian';
9
9
  import { useSeries } from '../hooks/useSeries';
10
10
  import { jsx as _jsx } from "react/jsx-runtime";
@@ -4,7 +4,7 @@ import useSlotProps from '@mui/utils/useSlotProps';
4
4
  import { DefaultChartsItemTooltipContent } from './DefaultChartsItemTooltipContent';
5
5
  import { useCartesianContext } from '../context/CartesianProvider';
6
6
  import { ZAxisContext } from '../context/ZAxisContextProvider';
7
- import { useColorProcessor } from '../hooks/useColor';
7
+ import { useColorProcessor } from '../context/PluginProvider/useColorProcessor';
8
8
  import { useSeries } from '../hooks/useSeries';
9
9
  import { jsx as _jsx } from "react/jsx-runtime";
10
10
  /**
@@ -47,8 +47,10 @@ export function useMouseTracker() {
47
47
  if (element === null) {
48
48
  return () => {};
49
49
  }
50
- const handleOut = () => {
51
- setMousePosition(null);
50
+ const handleOut = event => {
51
+ if (event.pointerType !== 'mouse') {
52
+ setMousePosition(null);
53
+ }
52
54
  };
53
55
  const handleMove = event => {
54
56
  setMousePosition({
@@ -15,6 +15,8 @@ import { getMinXTranslation } from '../internals/geometry';
15
15
  import { useMounted } from '../hooks/useMounted';
16
16
  import { useDrawingArea } from '../hooks/useDrawingArea';
17
17
  import { getWordsByLines } from '../internals/getWordsByLines';
18
+ import { isInfinity } from '../internals/isInfinity';
19
+ import { isBandScale } from '../internals/isBandScale';
18
20
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
19
21
  const useUtilityClasses = ownerState => {
20
22
  const {
@@ -137,7 +139,8 @@ function ChartsXAxis(inProps) {
137
139
  tickInterval,
138
140
  tickLabelInterval,
139
141
  tickPlacement,
140
- tickLabelPlacement
142
+ tickLabelPlacement,
143
+ sx
141
144
  } = defaultizedProps;
142
145
  const theme = useTheme();
143
146
  const classes = useUtilityClasses(_extends({}, defaultizedProps, {
@@ -199,15 +202,17 @@ function ChartsXAxis(inProps) {
199
202
  ownerState: {}
200
203
  });
201
204
  const domain = xScale.domain();
202
- if (domain.length === 0 || domain[0] === domain[1]) {
203
- // Skip axis rendering if
204
- // - the data is empty (for band and point axis)
205
- // - No data is associated to the axis (other scale types)
205
+ const ordinalAxis = isBandScale(xScale);
206
+ // Skip axis rendering if no data is available
207
+ // - The domain is an empty array for band/point scales.
208
+ // - The domains contains Infinity for continuous scales.
209
+ if (ordinalAxis && domain.length === 0 || !ordinalAxis && domain.some(isInfinity)) {
206
210
  return null;
207
211
  }
208
212
  return /*#__PURE__*/_jsxs(AxisRoot, {
209
213
  transform: `translate(0, ${position === 'bottom' ? top + height : top})`,
210
214
  className: classes.root,
215
+ sx: sx,
211
216
  children: [!disableLine && /*#__PURE__*/_jsx(Line, _extends({
212
217
  x1: left,
213
218
  x2: left + width,
@@ -305,6 +310,7 @@ process.env.NODE_ENV !== "production" ? ChartsXAxis.propTypes = {
305
310
  * @default 'currentColor'
306
311
  */
307
312
  stroke: PropTypes.string,
313
+ sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
308
314
  /**
309
315
  * The font size of the axis ticks text.
310
316
  * @default 12