@mui/x-charts 7.12.1 → 7.14.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 (128) hide show
  1. package/BarChart/BarChart.js +2 -0
  2. package/BarChart/BarPlot.js +4 -3
  3. package/BarChart/extremums.js +46 -9
  4. package/CHANGELOG.md +162 -1
  5. package/ChartContainer/ChartContainer.d.ts +3 -3
  6. package/ChartContainer/ChartContainer.js +4 -2
  7. package/ChartContainer/useChartContainerProps.d.ts +4 -2
  8. package/ChartContainer/useChartContainerProps.js +3 -3
  9. package/ChartContainer/useDefaultizeAxis.d.ts +3 -1
  10. package/ChartContainer/useDefaultizeAxis.js +16 -5
  11. package/ChartsAxisHighlight/ChartsAxisHighlight.js +23 -9
  12. package/ChartsGrid/ChartsGrid.js +6 -4
  13. package/ChartsTooltip/utils.js +4 -2
  14. package/ChartsXAxis/ChartsXAxis.js +25 -8
  15. package/ChartsYAxis/ChartsYAxis.js +19 -7
  16. package/LineChart/AreaPlot.js +11 -1
  17. package/LineChart/LineChart.js +2 -0
  18. package/LineChart/extremums.js +23 -18
  19. package/PieChart/PieChart.js +2 -0
  20. package/ResponsiveChartContainer/ResponsiveChartContainer.js +2 -0
  21. package/ResponsiveChartContainer/useResponsiveChartContainerProps.d.ts +1 -1
  22. package/ScatterChart/ScatterChart.js +2 -0
  23. package/ScatterChart/extremums.js +30 -22
  24. package/SparkLineChart/SparkLineChart.js +2 -0
  25. package/context/CartesianProvider/Cartesian.types.d.ts +59 -0
  26. package/context/CartesianProvider/Cartesian.types.js +5 -0
  27. package/context/CartesianProvider/CartesianContext.d.ts +1 -22
  28. package/context/CartesianProvider/CartesianProvider.d.ts +3 -23
  29. package/context/CartesianProvider/CartesianProvider.js +4 -7
  30. package/context/CartesianProvider/computeValue.d.ts +18 -31
  31. package/context/CartesianProvider/computeValue.js +20 -23
  32. package/context/CartesianProvider/defaultizeAxis.d.ts +1 -0
  33. package/context/CartesianProvider/getAxisExtremum.d.ts +3 -2
  34. package/context/CartesianProvider/getAxisExtremum.js +10 -11
  35. package/context/CartesianProvider/index.d.ts +1 -0
  36. package/context/CartesianProvider/index.js +12 -0
  37. package/context/CartesianProvider/useCartesianContext.d.ts +1 -1
  38. package/context/CartesianProvider/zoom.d.ts +10 -0
  39. package/context/CartesianProvider/zoom.js +26 -0
  40. package/context/DrawingProvider.d.ts +7 -2
  41. package/context/DrawingProvider.js +11 -3
  42. package/context/PluginProvider/ExtremumGetter.types.d.ts +12 -2
  43. package/esm/BarChart/BarChart.js +2 -0
  44. package/esm/BarChart/BarPlot.js +4 -3
  45. package/esm/BarChart/extremums.js +46 -9
  46. package/esm/ChartContainer/ChartContainer.js +5 -3
  47. package/esm/ChartContainer/useChartContainerProps.js +3 -3
  48. package/esm/ChartContainer/useDefaultizeAxis.js +16 -5
  49. package/esm/ChartsAxisHighlight/ChartsAxisHighlight.js +23 -9
  50. package/esm/ChartsGrid/ChartsGrid.js +6 -4
  51. package/esm/ChartsTooltip/utils.js +4 -2
  52. package/esm/ChartsXAxis/ChartsXAxis.js +25 -8
  53. package/esm/ChartsYAxis/ChartsYAxis.js +19 -7
  54. package/esm/LineChart/AreaPlot.js +11 -1
  55. package/esm/LineChart/LineChart.js +2 -0
  56. package/esm/LineChart/extremums.js +23 -18
  57. package/esm/PieChart/PieChart.js +2 -0
  58. package/esm/ResponsiveChartContainer/ResponsiveChartContainer.js +2 -0
  59. package/esm/ScatterChart/ScatterChart.js +2 -0
  60. package/esm/ScatterChart/extremums.js +30 -22
  61. package/esm/SparkLineChart/SparkLineChart.js +2 -0
  62. package/esm/context/CartesianProvider/Cartesian.types.js +1 -0
  63. package/esm/context/CartesianProvider/CartesianProvider.js +4 -7
  64. package/esm/context/CartesianProvider/computeValue.js +20 -23
  65. package/esm/context/CartesianProvider/getAxisExtremum.js +10 -11
  66. package/esm/context/CartesianProvider/index.js +1 -0
  67. package/esm/context/CartesianProvider/zoom.js +19 -0
  68. package/esm/context/DrawingProvider.js +11 -3
  69. package/esm/hooks/useAxisEvents.js +3 -1
  70. package/esm/hooks/useTicks.js +5 -2
  71. package/esm/internals/domUtils.js +16 -3
  72. package/esm/internals/index.js +3 -0
  73. package/esm/internals/isInfinity.js +3 -0
  74. package/esm/models/axis.js +5 -0
  75. package/esm/tests/firePointerEvent.js +35 -0
  76. package/hooks/useAxisEvents.js +3 -1
  77. package/hooks/useTicks.js +5 -2
  78. package/index.js +1 -1
  79. package/internals/defaultizeColor.d.ts +1 -0
  80. package/internals/domUtils.d.ts +2 -0
  81. package/internals/domUtils.js +19 -5
  82. package/internals/index.d.ts +2 -0
  83. package/internals/index.js +17 -1
  84. package/internals/isInfinity.d.ts +1 -0
  85. package/internals/isInfinity.js +9 -0
  86. package/models/axis.d.ts +6 -0
  87. package/models/axis.js +5 -0
  88. package/models/seriesType/line.d.ts +10 -0
  89. package/modern/BarChart/BarChart.js +2 -0
  90. package/modern/BarChart/BarPlot.js +4 -3
  91. package/modern/BarChart/extremums.js +46 -9
  92. package/modern/ChartContainer/ChartContainer.js +5 -3
  93. package/modern/ChartContainer/useChartContainerProps.js +3 -3
  94. package/modern/ChartContainer/useDefaultizeAxis.js +16 -5
  95. package/modern/ChartsAxisHighlight/ChartsAxisHighlight.js +23 -9
  96. package/modern/ChartsGrid/ChartsGrid.js +6 -4
  97. package/modern/ChartsTooltip/utils.js +4 -2
  98. package/modern/ChartsXAxis/ChartsXAxis.js +25 -8
  99. package/modern/ChartsYAxis/ChartsYAxis.js +19 -7
  100. package/modern/LineChart/AreaPlot.js +11 -1
  101. package/modern/LineChart/LineChart.js +2 -0
  102. package/modern/LineChart/extremums.js +23 -18
  103. package/modern/PieChart/PieChart.js +2 -0
  104. package/modern/ResponsiveChartContainer/ResponsiveChartContainer.js +2 -0
  105. package/modern/ScatterChart/ScatterChart.js +2 -0
  106. package/modern/ScatterChart/extremums.js +30 -22
  107. package/modern/SparkLineChart/SparkLineChart.js +2 -0
  108. package/modern/context/CartesianProvider/Cartesian.types.js +1 -0
  109. package/modern/context/CartesianProvider/CartesianProvider.js +4 -7
  110. package/modern/context/CartesianProvider/computeValue.js +20 -23
  111. package/modern/context/CartesianProvider/getAxisExtremum.js +10 -11
  112. package/modern/context/CartesianProvider/index.js +1 -0
  113. package/modern/context/CartesianProvider/zoom.js +19 -0
  114. package/modern/context/DrawingProvider.js +11 -3
  115. package/modern/hooks/useAxisEvents.js +3 -1
  116. package/modern/hooks/useTicks.js +5 -2
  117. package/modern/index.js +1 -1
  118. package/modern/internals/domUtils.js +16 -3
  119. package/modern/internals/index.js +3 -0
  120. package/modern/internals/isInfinity.js +3 -0
  121. package/modern/models/axis.js +5 -0
  122. package/modern/tests/firePointerEvent.js +35 -0
  123. package/package.json +4 -4
  124. package/tests/firePointerEvent.js +42 -0
  125. package/context/CartesianProvider/normalizeAxis.d.ts +0 -5
  126. package/context/CartesianProvider/normalizeAxis.js +0 -23
  127. package/esm/context/CartesianProvider/normalizeAxis.js +0 -15
  128. package/modern/context/CartesianProvider/normalizeAxis.js +0 -15
@@ -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);
@@ -20,7 +20,7 @@ const SPAN_STYLE = {
20
20
  whiteSpace: 'pre'
21
21
  };
22
22
  const STYLE_LIST = ['minWidth', 'maxWidth', 'width', 'minHeight', 'maxHeight', 'height', 'top', 'left', 'fontSize', 'padding', 'margin', 'paddingLeft', 'paddingRight', 'paddingTop', 'paddingBottom', 'marginLeft', 'marginRight', 'marginTop', 'marginBottom'];
23
- const MEASUREMENT_SPAN_ID = 'mui_measurement_span';
23
+ export const MEASUREMENT_SPAN_ID = 'mui_measurement_span';
24
24
 
25
25
  /**
26
26
  *
@@ -57,7 +57,7 @@ function camelToMiddleLine(text) {
57
57
  * @returns CSS styling string
58
58
  */
59
59
  export const getStyleString = style => Object.keys(style).sort().reduce((result, s) => `${result}${camelToMiddleLine(s)}:${autoCompleteStyle(s, style[s])};`, '');
60
-
60
+ let domCleanTimeout;
61
61
  /**
62
62
  *
63
63
  * @param text The string to estimate
@@ -105,6 +105,13 @@ export const getStringSize = (text, style = {}) => {
105
105
  } else {
106
106
  stringCache.cacheCount += 1;
107
107
  }
108
+ if (domCleanTimeout) {
109
+ clearTimeout(domCleanTimeout);
110
+ }
111
+ domCleanTimeout = setTimeout(() => {
112
+ // Limit node cleaning to once per render cycle
113
+ measurementSpan.textContent = '';
114
+ }, 0);
108
115
  return result;
109
116
  } catch (e) {
110
117
  return {
@@ -112,4 +119,10 @@ export const getStringSize = (text, style = {}) => {
112
119
  height: 0
113
120
  };
114
121
  }
115
- };
122
+ };
123
+
124
+ // eslint-disable-next-line @typescript-eslint/naming-convention
125
+ export function unstable_cleanupDOM() {
126
+ // const measurementSpan = document.getElementById(MEASUREMENT_SPAN_ID);
127
+ // measurementSpan?.remove();
128
+ }
@@ -20,6 +20,7 @@ export * from './configInit';
20
20
  export * from './getLabel';
21
21
  export * from './getSVGPoint';
22
22
  export * from './isDefined';
23
+ export { unstable_cleanupDOM } from './domUtils';
23
24
 
24
25
  // contexts
25
26
 
@@ -29,6 +30,8 @@ export * from '../context/InteractionProvider';
29
30
  export * from '../context/SeriesProvider';
30
31
  export * from '../context/ZAxisContextProvider';
31
32
  export * from '../context/PluginProvider';
33
+ export { getAxisExtremum } from '../context/CartesianProvider/getAxisExtremum';
34
+
32
35
  // series configuration
33
36
  export * from '../models/seriesType/config';
34
37
  export * from '../models/seriesType/common';
@@ -0,0 +1,3 @@
1
+ export function isInfinity(v) {
2
+ return typeof v === 'number' && !Number.isFinite(v);
3
+ }
@@ -1,3 +1,8 @@
1
+ /**
2
+ * Use this type instead of `AxisScaleConfig` when the values
3
+ * shouldn't be provided by the user.
4
+ */
5
+
1
6
  export function isBandScaleConfig(scaleConfig) {
2
7
  return scaleConfig.scaleType === 'band';
3
8
  }
@@ -0,0 +1,35 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import { fireEvent } from '@mui/internal-test-utils';
3
+ export function firePointerEvent(target, type, options) {
4
+ const originalGetBoundingClientRect = target.getBoundingClientRect;
5
+ target.getBoundingClientRect = () => ({
6
+ x: 0,
7
+ y: 0,
8
+ bottom: 0,
9
+ height: 0,
10
+ left: 0,
11
+ right: 0,
12
+ top: 0,
13
+ width: 0,
14
+ toJSON() {
15
+ return {
16
+ x: 0,
17
+ y: 0,
18
+ bottom: 0,
19
+ height: 0,
20
+ left: 0,
21
+ right: 0,
22
+ top: 0,
23
+ width: 0
24
+ };
25
+ }
26
+ });
27
+ const event = new window.PointerEvent(type, _extends({
28
+ bubbles: true,
29
+ cancelable: true,
30
+ composed: true,
31
+ isPrimary: true
32
+ }, options));
33
+ fireEvent(target, event);
34
+ target.getBoundingClientRect = originalGetBoundingClientRect;
35
+ }
@@ -106,7 +106,9 @@ const useAxisEvents = disableAxisListener => {
106
106
  const svgPoint = (0, _getSVGPoint.getSVGPoint)(element, target);
107
107
  mousePosition.current.x = svgPoint.x;
108
108
  mousePosition.current.y = svgPoint.y;
109
- if (!drawingArea.isPointInside(svgPoint, event.target)) {
109
+ if (!drawingArea.isPointInside(svgPoint, {
110
+ targetElement: event.target
111
+ })) {
110
112
  if (mousePosition.current.isInChart) {
111
113
  dispatch({
112
114
  type: 'exitChart'
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.1
2
+ * @mui/x-charts v7.14.0
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
@@ -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;
@@ -1,3 +1,4 @@
1
+ export declare const MEASUREMENT_SPAN_ID = "mui_measurement_span";
1
2
  /**
2
3
  *
3
4
  * @param style React style object
@@ -11,3 +12,4 @@ export declare const getStyleString: (style: React.CSSProperties) => string;
11
12
  * @returns width and height of the text
12
13
  */
13
14
  export declare const getStringSize: (text: string | number, style?: React.CSSProperties) => any;
15
+ export declare function unstable_cleanupDOM(): void;
@@ -4,7 +4,8 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.getStyleString = exports.getStringSize = void 0;
7
+ exports.getStyleString = exports.getStringSize = exports.MEASUREMENT_SPAN_ID = void 0;
8
+ exports.unstable_cleanupDOM = unstable_cleanupDOM;
8
9
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
10
  // DOM utils taken from
10
11
  // https://github.com/recharts/recharts/blob/master/src/util/DOMUtils.ts
@@ -27,7 +28,7 @@ const SPAN_STYLE = {
27
28
  whiteSpace: 'pre'
28
29
  };
29
30
  const STYLE_LIST = ['minWidth', 'maxWidth', 'width', 'minHeight', 'maxHeight', 'height', 'top', 'left', 'fontSize', 'padding', 'margin', 'paddingLeft', 'paddingRight', 'paddingTop', 'paddingBottom', 'marginLeft', 'marginRight', 'marginTop', 'marginBottom'];
30
- const MEASUREMENT_SPAN_ID = 'mui_measurement_span';
31
+ const MEASUREMENT_SPAN_ID = exports.MEASUREMENT_SPAN_ID = 'mui_measurement_span';
31
32
 
32
33
  /**
33
34
  *
@@ -64,14 +65,14 @@ function camelToMiddleLine(text) {
64
65
  * @returns CSS styling string
65
66
  */
66
67
  const getStyleString = style => Object.keys(style).sort().reduce((result, s) => `${result}${camelToMiddleLine(s)}:${autoCompleteStyle(s, style[s])};`, '');
67
-
68
+ exports.getStyleString = getStyleString;
69
+ let domCleanTimeout;
68
70
  /**
69
71
  *
70
72
  * @param text The string to estimate
71
73
  * @param style The style applied
72
74
  * @returns width and height of the text
73
75
  */
74
- exports.getStyleString = getStyleString;
75
76
  const getStringSize = (text, style = {}) => {
76
77
  if (text === undefined || text === null || isSsr()) {
77
78
  return {
@@ -113,6 +114,13 @@ const getStringSize = (text, style = {}) => {
113
114
  } else {
114
115
  stringCache.cacheCount += 1;
115
116
  }
117
+ if (domCleanTimeout) {
118
+ clearTimeout(domCleanTimeout);
119
+ }
120
+ domCleanTimeout = setTimeout(() => {
121
+ // Limit node cleaning to once per render cycle
122
+ measurementSpan.textContent = '';
123
+ }, 0);
116
124
  return result;
117
125
  } catch (e) {
118
126
  return {
@@ -121,4 +129,10 @@ const getStringSize = (text, style = {}) => {
121
129
  };
122
130
  }
123
131
  };
124
- exports.getStringSize = getStringSize;
132
+
133
+ // eslint-disable-next-line @typescript-eslint/naming-convention
134
+ exports.getStringSize = getStringSize;
135
+ function unstable_cleanupDOM() {
136
+ // const measurementSpan = document.getElementById(MEASUREMENT_SPAN_ID);
137
+ // measurementSpan?.remove();
138
+ }
@@ -15,6 +15,7 @@ export * from './configInit';
15
15
  export * from './getLabel';
16
16
  export * from './getSVGPoint';
17
17
  export * from './isDefined';
18
+ export { unstable_cleanupDOM } from './domUtils';
18
19
  export * from '../context/CartesianProvider';
19
20
  export * from '../context/DrawingProvider';
20
21
  export * from '../context/InteractionProvider';
@@ -22,6 +23,7 @@ export * from '../context/SeriesProvider';
22
23
  export * from '../context/ZAxisContextProvider';
23
24
  export * from '../context/PluginProvider';
24
25
  export type * from '../context/context.types';
26
+ export { getAxisExtremum } from '../context/CartesianProvider/getAxisExtremum';
25
27
  export * from '../models/seriesType/config';
26
28
  export * from '../models/seriesType/common';
27
29
  export * from '../models/helpers';
@@ -12,8 +12,22 @@ var _exportNames = {
12
12
  useLineChartProps: true,
13
13
  useBarChartProps: true,
14
14
  useResponsiveChartContainerProps: true,
15
- useChartContainerProps: true
15
+ useChartContainerProps: true,
16
+ unstable_cleanupDOM: true,
17
+ getAxisExtremum: true
16
18
  };
19
+ Object.defineProperty(exports, "getAxisExtremum", {
20
+ enumerable: true,
21
+ get: function () {
22
+ return _getAxisExtremum.getAxisExtremum;
23
+ }
24
+ });
25
+ Object.defineProperty(exports, "unstable_cleanupDOM", {
26
+ enumerable: true,
27
+ get: function () {
28
+ return _domUtils.unstable_cleanupDOM;
29
+ }
30
+ });
17
31
  Object.defineProperty(exports, "useBarChartProps", {
18
32
  enumerable: true,
19
33
  get: function () {
@@ -173,6 +187,7 @@ Object.keys(_isDefined).forEach(function (key) {
173
187
  }
174
188
  });
175
189
  });
190
+ var _domUtils = require("./domUtils");
176
191
  var _CartesianProvider = require("../context/CartesianProvider");
177
192
  Object.keys(_CartesianProvider).forEach(function (key) {
178
193
  if (key === "default" || key === "__esModule") return;
@@ -245,6 +260,7 @@ Object.keys(_PluginProvider).forEach(function (key) {
245
260
  }
246
261
  });
247
262
  });
263
+ var _getAxisExtremum = require("../context/CartesianProvider/getAxisExtremum");
248
264
  var _config = require("../models/seriesType/config");
249
265
  Object.keys(_config).forEach(function (key) {
250
266
  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
  /**
@@ -181,6 +183,10 @@ export interface AxisScaleConfig {
181
183
  colorMap?: ContinuousColorConfig | PiecewiseColorConfig;
182
184
  };
183
185
  }
186
+ /**
187
+ * Use this type instead of `AxisScaleConfig` when the values
188
+ * shouldn't be provided by the user.
189
+ */
184
190
  export interface AxisScaleComputedConfig {
185
191
  band: {
186
192
  colorScale?: ScaleOrdinal<string | number | Date, string, string | null> | ScaleOrdinal<number, string, string | null> | ScaleSequential<string, string | null> | ScaleThreshold<number | Date, string | null>;
package/models/axis.js CHANGED
@@ -5,6 +5,11 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.isBandScaleConfig = isBandScaleConfig;
7
7
  exports.isPointScaleConfig = isPointScaleConfig;
8
+ /**
9
+ * Use this type instead of `AxisScaleConfig` when the values
10
+ * shouldn't be provided by the user.
11
+ */
12
+
8
13
  function isBandScaleConfig(scaleConfig) {
9
14
  return scaleConfig.scaleType === 'band';
10
15
  }
@@ -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]),
@@ -191,6 +191,7 @@ function BarPlot(props) {
191
191
  barLabel
192
192
  } = props,
193
193
  other = _objectWithoutPropertiesLoose(props, _excluded);
194
+ const withoutBorderRadius = !borderRadius || borderRadius <= 0;
194
195
  const transition = useTransition(completedData, {
195
196
  keys: bar => `${bar.seriesId}-${bar.dataIndex}`,
196
197
  from: leaveStyle,
@@ -199,7 +200,7 @@ function BarPlot(props) {
199
200
  update: enterStyle,
200
201
  immediate: skipAnimation
201
202
  });
202
- const maskTransition = useTransition(masksData, {
203
+ const maskTransition = useTransition(withoutBorderRadius ? [] : masksData, {
203
204
  keys: v => v.id,
204
205
  from: leaveStyle,
205
206
  leave: leaveStyle,
@@ -208,7 +209,7 @@ function BarPlot(props) {
208
209
  immediate: skipAnimation
209
210
  });
210
211
  return /*#__PURE__*/_jsxs(React.Fragment, {
211
- children: [maskTransition((style, {
212
+ children: [!withoutBorderRadius && maskTransition((style, {
212
213
  id,
213
214
  hasPositive,
214
215
  hasNegative,
@@ -242,7 +243,7 @@ function BarPlot(props) {
242
243
  }),
243
244
  style: style
244
245
  }));
245
- if (!borderRadius || borderRadius <= 0) {
246
+ if (withoutBorderRadius) {
246
247
  return barElement;
247
248
  }
248
249
  return /*#__PURE__*/_jsx("g", {
@@ -1,31 +1,68 @@
1
+ const createResult = (data, direction) => {
2
+ if (direction === 'x') {
3
+ return {
4
+ x: data,
5
+ y: null
6
+ };
7
+ }
8
+ return {
9
+ x: null,
10
+ y: data
11
+ };
12
+ };
1
13
  const getBaseExtremum = params => {
2
14
  const {
3
- axis
15
+ axis,
16
+ getFilters,
17
+ isDefaultAxis
4
18
  } = params;
5
- const minX = Math.min(...(axis.data ?? []));
6
- const maxX = Math.max(...(axis.data ?? []));
19
+ const filter = getFilters?.({
20
+ currentAxisId: axis.id,
21
+ isDefaultAxis
22
+ });
23
+ const data = filter ? axis.data?.filter((_, i) => filter({
24
+ x: null,
25
+ y: null
26
+ }, i)) : axis.data;
27
+ const minX = Math.min(...(data ?? []));
28
+ const maxX = Math.max(...(data ?? []));
7
29
  return [minX, maxX];
8
30
  };
9
- const getValueExtremum = params => {
31
+ const getValueExtremum = direction => params => {
10
32
  const {
11
33
  series,
12
34
  axis,
35
+ getFilters,
13
36
  isDefaultAxis
14
37
  } = params;
15
38
  return Object.keys(series).filter(seriesId => {
16
39
  const yAxisId = series[seriesId].yAxisId ?? series[seriesId].yAxisKey;
17
40
  return yAxisId === axis.id || isDefaultAxis && yAxisId === undefined;
18
41
  }).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]);
42
+ const {
43
+ stackedData
44
+ } = series[seriesId];
45
+ const filter = getFilters?.({
46
+ currentAxisId: axis.id,
47
+ isDefaultAxis,
48
+ seriesXAxisId: series[seriesId].xAxisId ?? series[seriesId].xAxisKey,
49
+ seriesYAxisId: series[seriesId].yAxisId ?? series[seriesId].yAxisKey
50
+ });
51
+ const [seriesMin, seriesMax] = stackedData?.reduce((seriesAcc, values, index) => {
52
+ if (filter && (!filter(createResult(values[0], direction), index) || !filter(createResult(values[1], direction), index))) {
53
+ return seriesAcc;
54
+ }
55
+ return [Math.min(...values, seriesAcc[0]), Math.max(...values, seriesAcc[1])];
56
+ }, [Infinity, -Infinity]) ?? [Infinity, -Infinity];
57
+ return [Math.min(seriesMin, acc[0]), Math.max(seriesMax, acc[1])];
58
+ }, [Infinity, -Infinity]);
22
59
  };
23
60
  export const getExtremumX = params => {
24
61
  // Notice that bar should be all horizontal or all vertical.
25
62
  // Don't think it's a problem for now
26
63
  const isHorizontal = Object.keys(params.series).some(seriesId => params.series[seriesId].layout === 'horizontal');
27
64
  if (isHorizontal) {
28
- return getValueExtremum(params);
65
+ return getValueExtremum('x')(params);
29
66
  }
30
67
  return getBaseExtremum(params);
31
68
  };
@@ -34,5 +71,5 @@ export const getExtremumY = params => {
34
71
  if (isHorizontal) {
35
72
  return getBaseExtremum(params);
36
73
  }
37
- return getValueExtremum(params);
74
+ return getValueExtremum('y')(params);
38
75
  };
@@ -5,7 +5,7 @@ import { DrawingProvider } from '../context/DrawingProvider';
5
5
  import { SeriesProvider } from '../context/SeriesProvider';
6
6
  import { InteractionProvider } from '../context/InteractionProvider';
7
7
  import { ChartsSurface } from '../ChartsSurface';
8
- import { CartesianContextProvider } from '../context/CartesianProvider';
8
+ import { CartesianProvider } from '../context/CartesianProvider';
9
9
  import { ChartsAxesGradients } from '../internals/components/ChartsAxesGradients';
10
10
  import { HighlightedProvider, ZAxisContextProvider } from '../context';
11
11
  import { PluginProvider } from '../context/PluginProvider';
@@ -16,7 +16,7 @@ const ChartContainer = /*#__PURE__*/React.forwardRef(function ChartContainer(pro
16
16
  children,
17
17
  drawingProviderProps,
18
18
  seriesProviderProps,
19
- cartesianContextProps,
19
+ cartesianProviderProps,
20
20
  zAxisContextProps,
21
21
  highlightedProviderProps,
22
22
  chartsSurfaceProps,
@@ -25,7 +25,7 @@ const ChartContainer = /*#__PURE__*/React.forwardRef(function ChartContainer(pro
25
25
  return /*#__PURE__*/_jsx(DrawingProvider, _extends({}, drawingProviderProps, {
26
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]),
@@ -30,7 +30,7 @@ export const useChartContainerProps = (props, ref) => {
30
30
  const chartSurfaceRef = useForkRef(ref, svgRef);
31
31
  useReducedMotion(); // a11y reduce motion (see: https://react-spring.dev/docs/utilities/use-reduced-motion)
32
32
 
33
- const [defaultizedXAxis, defaultizedYAxis] = useDefaultizeAxis(xAxis, yAxis);
33
+ const [defaultizedXAxis, defaultizedYAxis] = useDefaultizeAxis(xAxis, yAxis, dataset);
34
34
  const drawingProviderProps = {
35
35
  width,
36
36
  height,
@@ -45,7 +45,7 @@ export const useChartContainerProps = (props, ref) => {
45
45
  colors,
46
46
  dataset
47
47
  };
48
- const cartesianContextProps = {
48
+ const cartesianProviderProps = {
49
49
  xAxis: defaultizedXAxis,
50
50
  yAxis: defaultizedYAxis,
51
51
  dataset
@@ -71,7 +71,7 @@ export const useChartContainerProps = (props, ref) => {
71
71
  children,
72
72
  drawingProviderProps,
73
73
  seriesProviderProps,
74
- cartesianContextProps,
74
+ cartesianProviderProps,
75
75
  zAxisContextProps,
76
76
  highlightedProviderProps,
77
77
  chartsSurfaceProps,
@@ -1,7 +1,7 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import * as React from 'react';
3
3
  import { DEFAULT_X_AXIS_KEY, DEFAULT_Y_AXIS_KEY } from '../constants';
4
- const defaultizeAxis = (inAxis, axisName) => {
4
+ const defaultizeAxis = (inAxis, dataset, axisName) => {
5
5
  const DEFAULT_AXIS_KEY = axisName === 'x' ? DEFAULT_X_AXIS_KEY : DEFAULT_Y_AXIS_KEY;
6
6
  return [...(inAxis?.map((axis, index) => _extends({
7
7
  id: `defaultized-${axisName}-axis-${index}`
@@ -10,10 +10,21 @@ const defaultizeAxis = (inAxis, axisName) => {
10
10
  }) => id === DEFAULT_AXIS_KEY) === -1 ? [{
11
11
  id: DEFAULT_AXIS_KEY,
12
12
  scaleType: 'linear'
13
- }] : [])];
13
+ }] : [])].map(axisConfig => {
14
+ const dataKey = axisConfig.dataKey;
15
+ if (dataKey === undefined || axisConfig.data !== undefined) {
16
+ return axisConfig;
17
+ }
18
+ if (dataset === undefined) {
19
+ throw Error(`MUI X: ${axisName}-axis uses \`dataKey\` but no \`dataset\` is provided.`);
20
+ }
21
+ return _extends({}, axisConfig, {
22
+ data: dataset.map(d => d[dataKey])
23
+ });
24
+ });
14
25
  };
15
- export const useDefaultizeAxis = (inXAxis, inYAxis) => {
16
- const xAxis = React.useMemo(() => defaultizeAxis(inXAxis, 'x'), [inXAxis]);
17
- const yAxis = React.useMemo(() => defaultizeAxis(inYAxis, 'y'), [inYAxis]);
26
+ export const useDefaultizeAxis = (inXAxis, inYAxis, dataset) => {
27
+ const xAxis = React.useMemo(() => defaultizeAxis(inXAxis, dataset, 'x'), [inXAxis, dataset]);
28
+ const yAxis = React.useMemo(() => defaultizeAxis(inYAxis, dataset, 'y'), [inYAxis, dataset]);
18
29
  return [xAxis, yAxis];
19
30
  };