@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
@@ -21,6 +21,8 @@ var _geometry = require("../internals/geometry");
21
21
  var _useMounted = require("../hooks/useMounted");
22
22
  var _useDrawingArea = require("../hooks/useDrawingArea");
23
23
  var _getWordsByLines = require("../internals/getWordsByLines");
24
+ var _isInfinity = require("../internals/isInfinity");
25
+ var _isBandScale = require("../internals/isBandScale");
24
26
  var _jsxRuntime = require("react/jsx-runtime");
25
27
  const _excluded = ["scale", "tickNumber", "reverse"];
26
28
  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); }
@@ -146,7 +148,8 @@ function ChartsXAxis(inProps) {
146
148
  tickInterval,
147
149
  tickLabelInterval,
148
150
  tickPlacement,
149
- tickLabelPlacement
151
+ tickLabelPlacement,
152
+ sx
150
153
  } = defaultizedProps;
151
154
  const theme = (0, _styles.useTheme)();
152
155
  const classes = useUtilityClasses((0, _extends2.default)({}, defaultizedProps, {
@@ -156,7 +159,8 @@ function ChartsXAxis(inProps) {
156
159
  left,
157
160
  top,
158
161
  width,
159
- height
162
+ height,
163
+ isPointInside
160
164
  } = (0, _useDrawingArea.useDrawingArea)();
161
165
  const tickSize = disableTicks ? 4 : tickSizeProp;
162
166
  const positionSign = position === 'bottom' ? 1 : -1;
@@ -208,15 +212,17 @@ function ChartsXAxis(inProps) {
208
212
  ownerState: {}
209
213
  });
210
214
  const domain = xScale.domain();
211
- if (domain.length === 0 || domain[0] === domain[1]) {
212
- // Skip axis rendering if
213
- // - the data is empty (for band and point axis)
214
- // - No data is associated to the axis (other scale types)
215
+ const ordinalAxis = (0, _isBandScale.isBandScale)(xScale);
216
+ // Skip axis rendering if no data is available
217
+ // - The domain is an empty array for band/point scales.
218
+ // - The domains contains Infinity for continuous scales.
219
+ if (ordinalAxis && domain.length === 0 || !ordinalAxis && domain.some(_isInfinity.isInfinity)) {
215
220
  return null;
216
221
  }
217
222
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_AxisSharedComponents.AxisRoot, {
218
223
  transform: `translate(0, ${position === 'bottom' ? top + height : top})`,
219
224
  className: classes.root,
225
+ sx: sx,
220
226
  children: [!disableLine && /*#__PURE__*/(0, _jsxRuntime.jsx)(Line, (0, _extends2.default)({
221
227
  x1: left,
222
228
  x2: left + width,
@@ -229,8 +235,18 @@ function ChartsXAxis(inProps) {
229
235
  }, index) => {
230
236
  const xTickLabel = labelOffset ?? 0;
231
237
  const yTickLabel = positionSign * (tickSize + 3);
232
- const showTick = offset >= left - 1 && offset <= left + width + 1;
233
- const showTickLabel = offset + xTickLabel >= left - 1 && offset + xTickLabel <= left + width + 1;
238
+ const showTick = isPointInside({
239
+ x: offset,
240
+ y: -1
241
+ }, {
242
+ direction: 'x'
243
+ });
244
+ const showTickLabel = isPointInside({
245
+ x: offset + xTickLabel,
246
+ y: -1
247
+ }, {
248
+ direction: 'x'
249
+ });
234
250
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)("g", {
235
251
  transform: `translate(${offset}, 0)`,
236
252
  className: classes.tickContainer,
@@ -314,6 +330,7 @@ process.env.NODE_ENV !== "production" ? ChartsXAxis.propTypes = {
314
330
  * @default 'currentColor'
315
331
  */
316
332
  stroke: _propTypes.default.string,
333
+ sx: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.object, _propTypes.default.bool])), _propTypes.default.func, _propTypes.default.object]),
317
334
  /**
318
335
  * The font size of the axis ticks text.
319
336
  * @default 12
@@ -18,6 +18,8 @@ var _useDrawingArea = require("../hooks/useDrawingArea");
18
18
  var _AxisSharedComponents = require("../internals/components/AxisSharedComponents");
19
19
  var _ChartsText = require("../ChartsText");
20
20
  var _axisClasses = require("../ChartsAxis/axisClasses");
21
+ var _isInfinity = require("../internals/isInfinity");
22
+ var _isBandScale = require("../internals/isBandScale");
21
23
  var _jsxRuntime = require("react/jsx-runtime");
22
24
  const _excluded = ["scale", "tickNumber"];
23
25
  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); }
@@ -87,7 +89,8 @@ function ChartsYAxis(inProps) {
87
89
  tickPlacement,
88
90
  tickLabelPlacement,
89
91
  tickInterval,
90
- tickLabelInterval
92
+ tickLabelInterval,
93
+ sx
91
94
  } = defaultizedProps;
92
95
  const theme = (0, _styles.useTheme)();
93
96
  const isRTL = theme.direction === 'rtl';
@@ -98,7 +101,8 @@ function ChartsYAxis(inProps) {
98
101
  left,
99
102
  top,
100
103
  width,
101
- height
104
+ height,
105
+ isPointInside
102
106
  } = (0, _useDrawingArea.useDrawingArea)();
103
107
  const tickSize = disableTicks ? 4 : tickSizeProp;
104
108
  const yTicks = (0, _useTicks.useTicks)({
@@ -154,15 +158,17 @@ function ChartsYAxis(inProps) {
154
158
  ownerState: {}
155
159
  });
156
160
  const domain = yScale.domain();
157
- if (domain.length === 0 || domain[0] === domain[1]) {
158
- // Skip axis rendering if
159
- // - the data is empty (for band and point axis)
160
- // - No data is associated to the axis (other scale types)
161
+ const ordinalAxis = (0, _isBandScale.isBandScale)(yScale);
162
+ // Skip axis rendering if no data is available
163
+ // - The domain is an empty array for band/point scales.
164
+ // - The domains contains Infinity for continuous scales.
165
+ if (ordinalAxis && domain.length === 0 || !ordinalAxis && domain.some(_isInfinity.isInfinity)) {
161
166
  return null;
162
167
  }
163
168
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_AxisSharedComponents.AxisRoot, {
164
169
  transform: `translate(${position === 'right' ? left + width : left}, 0)`,
165
170
  className: classes.root,
171
+ sx: sx,
166
172
  children: [!disableLine && /*#__PURE__*/(0, _jsxRuntime.jsx)(Line, (0, _extends2.default)({
167
173
  y1: top,
168
174
  y2: top + height,
@@ -176,7 +182,12 @@ function ChartsYAxis(inProps) {
176
182
  const xTickLabel = positionSign * (tickSize + 2);
177
183
  const yTickLabel = labelOffset;
178
184
  const skipLabel = typeof tickLabelInterval === 'function' && !tickLabelInterval?.(value, index);
179
- const showLabel = offset >= top - 1 && offset <= height + top + 1;
185
+ const showLabel = isPointInside({
186
+ x: -1,
187
+ y: offset
188
+ }, {
189
+ direction: 'y'
190
+ });
180
191
  if (!showLabel) {
181
192
  return null;
182
193
  }
@@ -262,6 +273,7 @@ process.env.NODE_ENV !== "production" ? ChartsYAxis.propTypes = {
262
273
  * @default 'currentColor'
263
274
  */
264
275
  stroke: _propTypes.default.string,
276
+ sx: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.object, _propTypes.default.bool])), _propTypes.default.func, _propTypes.default.object]),
265
277
  /**
266
278
  * The font size of the axis ticks text.
267
279
  * @default 12
@@ -51,7 +51,8 @@ const useAggregatedData = () => {
51
51
  yAxisKey = defaultYAxisId,
52
52
  stackedData,
53
53
  data,
54
- connectNulls
54
+ connectNulls,
55
+ baseline
55
56
  } = series[seriesId];
56
57
  const xAxisId = xAxisIdProp ?? xAxisKey;
57
58
  const yAxisId = yAxisIdProp ?? yAxisKey;
@@ -68,6 +69,15 @@ const useAggregatedData = () => {
68
69
  }
69
70
  }
70
71
  const areaPath = (0, _d3Shape.area)().x(d => xScale(d.x)).defined((_, i) => connectNulls || data[i] != null).y0(d => {
72
+ if (typeof baseline === 'number') {
73
+ return yScale(baseline);
74
+ }
75
+ if (baseline === 'max') {
76
+ return yScale.range()[1];
77
+ }
78
+ if (baseline === 'min') {
79
+ return yScale.range()[0];
80
+ }
71
81
  const value = d.y && yScale(d.y[0]);
72
82
  if (Number.isNaN(value)) {
73
83
  return yScale.range()[0];
@@ -283,6 +283,7 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
283
283
  slotProps: _propTypes.default.object,
284
284
  slots: _propTypes.default.object,
285
285
  stroke: _propTypes.default.string,
286
+ sx: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.object, _propTypes.default.bool])), _propTypes.default.func, _propTypes.default.object]),
286
287
  tickFontSize: _propTypes.default.number,
287
288
  tickInterval: _propTypes.default.oneOfType([_propTypes.default.oneOf(['auto']), _propTypes.default.array, _propTypes.default.func]),
288
289
  tickLabelInterval: _propTypes.default.oneOfType([_propTypes.default.oneOf(['auto']), _propTypes.default.func]),
@@ -335,6 +336,7 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
335
336
  slotProps: _propTypes.default.object,
336
337
  slots: _propTypes.default.object,
337
338
  stroke: _propTypes.default.string,
339
+ sx: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.object, _propTypes.default.bool])), _propTypes.default.func, _propTypes.default.object]),
338
340
  tickFontSize: _propTypes.default.number,
339
341
  tickInterval: _propTypes.default.oneOfType([_propTypes.default.oneOf(['auto']), _propTypes.default.array, _propTypes.default.func]),
340
342
  tickLabelInterval: _propTypes.default.oneOfType([_propTypes.default.oneOf(['auto']), _propTypes.default.func]),
@@ -13,23 +13,27 @@ const getExtremumX = params => {
13
13
  return [minX, maxX];
14
14
  };
15
15
  exports.getExtremumX = getExtremumX;
16
- function getSeriesExtremums(getValues, stackedData) {
17
- if (stackedData.length === 0) {
18
- return [null, null];
19
- }
20
- return stackedData.reduce((seriesAcc, stackedValue) => {
16
+ function getSeriesExtremums(getValues, stackedData, filter) {
17
+ return stackedData.reduce((seriesAcc, stackedValue, index) => {
21
18
  const [base, value] = getValues(stackedValue);
22
- if (seriesAcc[0] === null) {
23
- return [Math.min(base, value), Math.max(base, value)];
19
+ if (filter && (!filter({
20
+ y: base,
21
+ x: null
22
+ }, index) || !filter({
23
+ y: value,
24
+ x: null
25
+ }, index))) {
26
+ return seriesAcc;
24
27
  }
25
28
  return [Math.min(base, value, seriesAcc[0]), Math.max(base, value, seriesAcc[1])];
26
- }, getValues(stackedData[0]));
29
+ }, [Infinity, -Infinity]);
27
30
  }
28
31
  const getExtremumY = params => {
29
32
  const {
30
33
  series,
31
34
  axis,
32
- isDefaultAxis
35
+ isDefaultAxis,
36
+ getFilters
33
37
  } = params;
34
38
  return Object.keys(series).filter(seriesId => {
35
39
  const yAxisId = series[seriesId].yAxisId ?? series[seriesId].yAxisKey;
@@ -40,17 +44,18 @@ const getExtremumY = params => {
40
44
  stackedData
41
45
  } = series[seriesId];
42
46
  const isArea = area !== undefined;
43
- const getValues = isArea && axis.scaleType !== 'log' ? d => d : d => [d[1], d[1]]; // Since this series is not used to display an area, we do not consider the base (the d[0]).
47
+ const filter = getFilters?.({
48
+ currentAxisId: axis.id,
49
+ isDefaultAxis,
50
+ seriesXAxisId: series[seriesId].xAxisId ?? series[seriesId].xAxisKey,
51
+ seriesYAxisId: series[seriesId].yAxisId ?? series[seriesId].yAxisKey
52
+ });
44
53
 
45
- const seriesExtremums = getSeriesExtremums(getValues, stackedData);
46
- if (acc[0] === null) {
47
- return seriesExtremums;
48
- }
49
- if (seriesExtremums[0] === null) {
50
- return acc;
51
- }
54
+ // Since this series is not used to display an area, we do not consider the base (the d[0]).
55
+ const getValues = isArea && axis.scaleType !== 'log' && typeof series[seriesId].baseline !== 'string' ? d => d : d => [d[1], d[1]];
56
+ const seriesExtremums = getSeriesExtremums(getValues, stackedData, filter);
52
57
  const [seriesMin, seriesMax] = seriesExtremums;
53
58
  return [Math.min(seriesMin, acc[0]), Math.max(seriesMax, acc[1])];
54
- }, [null, null]);
59
+ }, [Infinity, -Infinity]);
55
60
  };
56
61
  exports.getExtremumY = getExtremumY;
@@ -327,6 +327,7 @@ process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
327
327
  slotProps: _propTypes.default.object,
328
328
  slots: _propTypes.default.object,
329
329
  stroke: _propTypes.default.string,
330
+ sx: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.object, _propTypes.default.bool])), _propTypes.default.func, _propTypes.default.object]),
330
331
  tickFontSize: _propTypes.default.number,
331
332
  tickInterval: _propTypes.default.oneOfType([_propTypes.default.oneOf(['auto']), _propTypes.default.array, _propTypes.default.func]),
332
333
  tickLabelInterval: _propTypes.default.oneOfType([_propTypes.default.oneOf(['auto']), _propTypes.default.func]),
@@ -379,6 +380,7 @@ process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
379
380
  slotProps: _propTypes.default.object,
380
381
  slots: _propTypes.default.object,
381
382
  stroke: _propTypes.default.string,
383
+ sx: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.object, _propTypes.default.bool])), _propTypes.default.func, _propTypes.default.object]),
382
384
  tickFontSize: _propTypes.default.number,
383
385
  tickInterval: _propTypes.default.oneOfType([_propTypes.default.oneOf(['auto']), _propTypes.default.array, _propTypes.default.func]),
384
386
  tickLabelInterval: _propTypes.default.oneOfType([_propTypes.default.oneOf(['auto']), _propTypes.default.func]),
@@ -139,6 +139,7 @@ process.env.NODE_ENV !== "production" ? ResponsiveChartContainer.propTypes = {
139
139
  slotProps: _propTypes.default.object,
140
140
  slots: _propTypes.default.object,
141
141
  stroke: _propTypes.default.string,
142
+ sx: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.object, _propTypes.default.bool])), _propTypes.default.func, _propTypes.default.object]),
142
143
  tickFontSize: _propTypes.default.number,
143
144
  tickInterval: _propTypes.default.oneOfType([_propTypes.default.oneOf(['auto']), _propTypes.default.array, _propTypes.default.func]),
144
145
  tickLabelInterval: _propTypes.default.oneOfType([_propTypes.default.oneOf(['auto']), _propTypes.default.func]),
@@ -191,6 +192,7 @@ process.env.NODE_ENV !== "production" ? ResponsiveChartContainer.propTypes = {
191
192
  slotProps: _propTypes.default.object,
192
193
  slots: _propTypes.default.object,
193
194
  stroke: _propTypes.default.string,
195
+ sx: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.object, _propTypes.default.bool])), _propTypes.default.func, _propTypes.default.object]),
194
196
  tickFontSize: _propTypes.default.number,
195
197
  tickInterval: _propTypes.default.oneOfType([_propTypes.default.oneOf(['auto']), _propTypes.default.array, _propTypes.default.func]),
196
198
  tickLabelInterval: _propTypes.default.oneOfType([_propTypes.default.oneOf(['auto']), _propTypes.default.func]),
@@ -1,7 +1,7 @@
1
1
  import type { ResponsiveChartContainerProps } from './ResponsiveChartContainer';
2
2
  export declare const useResponsiveChartContainerProps: (props: ResponsiveChartContainerProps, ref: React.ForwardedRef<unknown>) => {
3
3
  hasIntrinsicSize: number;
4
- chartContainerProps: Omit<import("..").ChartsSurfaceProps & Omit<import("../internals").SeriesProviderProps, "seriesFormatters"> & Omit<import("../internals").DrawingProviderProps, "svgRef"> & Pick<import("../internals").CartesianContextProviderProps, "dataset"> & import("..").ZAxisContextProviderProps & import("..").HighlightedProviderProps & import("../internals").PluginProviderProps, "children"> & {
4
+ chartContainerProps: Omit<import("..").ChartsSurfaceProps & Omit<import("../internals").SeriesProviderProps, "seriesFormatters"> & Omit<import("../internals").DrawingProviderProps, "svgRef"> & Pick<import("../internals").CartesianProviderProps, "dataset"> & import("..").ZAxisContextProviderProps & import("..").HighlightedProviderProps & import("../internals").PluginProviderProps, "children"> & {
5
5
  xAxis?: import("../internals").MakeOptional<import("..").AxisConfig<import("..").ScaleName, any, import("..").ChartsXAxisProps>, "id">[];
6
6
  yAxis?: import("../internals").MakeOptional<import("..").AxisConfig<import("..").ScaleName, any, import("..").ChartsYAxisProps>, "id">[];
7
7
  children?: import("react").ReactNode;
@@ -264,6 +264,7 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
264
264
  slotProps: _propTypes.default.object,
265
265
  slots: _propTypes.default.object,
266
266
  stroke: _propTypes.default.string,
267
+ sx: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.object, _propTypes.default.bool])), _propTypes.default.func, _propTypes.default.object]),
267
268
  tickFontSize: _propTypes.default.number,
268
269
  tickInterval: _propTypes.default.oneOfType([_propTypes.default.oneOf(['auto']), _propTypes.default.array, _propTypes.default.func]),
269
270
  tickLabelInterval: _propTypes.default.oneOfType([_propTypes.default.oneOf(['auto']), _propTypes.default.func]),
@@ -316,6 +317,7 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
316
317
  slotProps: _propTypes.default.object,
317
318
  slots: _propTypes.default.object,
318
319
  stroke: _propTypes.default.string,
320
+ sx: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.object, _propTypes.default.bool])), _propTypes.default.func, _propTypes.default.object]),
319
321
  tickFontSize: _propTypes.default.number,
320
322
  tickInterval: _propTypes.default.oneOfType([_propTypes.default.oneOf(['auto']), _propTypes.default.array, _propTypes.default.func]),
321
323
  tickLabelInterval: _propTypes.default.oneOfType([_propTypes.default.oneOf(['auto']), _propTypes.default.func]),
@@ -5,51 +5,59 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.getExtremumY = exports.getExtremumX = void 0;
7
7
  const mergeMinMax = (acc, val) => {
8
- if (acc[0] === null || acc[1] === null) {
9
- return val;
10
- }
11
- if (val[0] === null || val[1] === null) {
12
- return acc;
13
- }
14
8
  return [Math.min(acc[0], val[0]), Math.max(acc[1], val[1])];
15
9
  };
16
10
  const getExtremumX = params => {
17
11
  const {
18
12
  series,
19
13
  axis,
20
- isDefaultAxis
14
+ isDefaultAxis,
15
+ getFilters
21
16
  } = params;
22
17
  return Object.keys(series).filter(seriesId => {
23
18
  const axisId = series[seriesId].xAxisId ?? series[seriesId].xAxisKey;
24
19
  return axisId === axis.id || axisId === undefined && isDefaultAxis;
25
20
  }).reduce((acc, seriesId) => {
26
- const seriesMinMax = series[seriesId].data.reduce((accSeries, {
27
- x
28
- }) => {
29
- const val = [x, x];
30
- return mergeMinMax(accSeries, val);
31
- }, [null, null]);
21
+ const filter = getFilters?.({
22
+ currentAxisId: axis.id,
23
+ isDefaultAxis,
24
+ seriesXAxisId: series[seriesId].xAxisId ?? series[seriesId].xAxisKey,
25
+ seriesYAxisId: series[seriesId].yAxisId ?? series[seriesId].yAxisKey
26
+ });
27
+ const seriesMinMax = series[seriesId].data.reduce((accSeries, d, dataIndex) => {
28
+ if (filter && !filter(d, dataIndex)) {
29
+ return accSeries;
30
+ }
31
+ return mergeMinMax(accSeries, [d.x, d.x]);
32
+ }, [Infinity, -Infinity]);
32
33
  return mergeMinMax(acc, seriesMinMax);
33
- }, [null, null]);
34
+ }, [Infinity, -Infinity]);
34
35
  };
35
36
  exports.getExtremumX = getExtremumX;
36
37
  const getExtremumY = params => {
37
38
  const {
38
39
  series,
39
40
  axis,
40
- isDefaultAxis
41
+ isDefaultAxis,
42
+ getFilters
41
43
  } = params;
42
44
  return Object.keys(series).filter(seriesId => {
43
45
  const axisId = series[seriesId].yAxisId ?? series[seriesId].yAxisKey;
44
46
  return axisId === axis.id || axisId === undefined && isDefaultAxis;
45
47
  }).reduce((acc, seriesId) => {
46
- const seriesMinMax = series[seriesId].data.reduce((accSeries, {
47
- y
48
- }) => {
49
- const val = [y, y];
50
- return mergeMinMax(accSeries, val);
51
- }, [null, null]);
48
+ const filter = getFilters?.({
49
+ currentAxisId: axis.id,
50
+ isDefaultAxis,
51
+ seriesXAxisId: series[seriesId].xAxisId ?? series[seriesId].xAxisKey,
52
+ seriesYAxisId: series[seriesId].yAxisId ?? series[seriesId].yAxisKey
53
+ });
54
+ const seriesMinMax = series[seriesId].data.reduce((accSeries, d, dataIndex) => {
55
+ if (filter && !filter(d, dataIndex)) {
56
+ return accSeries;
57
+ }
58
+ return mergeMinMax(accSeries, [d.y, d.y]);
59
+ }, [Infinity, -Infinity]);
52
60
  return mergeMinMax(acc, seriesMinMax);
53
- }, [null, null]);
61
+ }, [Infinity, -Infinity]);
54
62
  };
55
63
  exports.getExtremumY = getExtremumY;
@@ -288,6 +288,7 @@ process.env.NODE_ENV !== "production" ? SparkLineChart.propTypes = {
288
288
  slotProps: _propTypes.default.object,
289
289
  slots: _propTypes.default.object,
290
290
  stroke: _propTypes.default.string,
291
+ sx: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.object, _propTypes.default.bool])), _propTypes.default.func, _propTypes.default.object]),
291
292
  tickFontSize: _propTypes.default.number,
292
293
  tickInterval: _propTypes.default.oneOfType([_propTypes.default.oneOf(['auto']), _propTypes.default.array, _propTypes.default.func]),
293
294
  tickLabelInterval: _propTypes.default.oneOfType([_propTypes.default.oneOf(['auto']), _propTypes.default.func]),
@@ -339,6 +340,7 @@ process.env.NODE_ENV !== "production" ? SparkLineChart.propTypes = {
339
340
  slotProps: _propTypes.default.object,
340
341
  slots: _propTypes.default.object,
341
342
  stroke: _propTypes.default.string,
343
+ sx: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.object, _propTypes.default.bool])), _propTypes.default.func, _propTypes.default.object]),
342
344
  tickFontSize: _propTypes.default.number,
343
345
  tickInterval: _propTypes.default.oneOfType([_propTypes.default.oneOf(['auto']), _propTypes.default.array, _propTypes.default.func]),
344
346
  tickLabelInterval: _propTypes.default.oneOfType([_propTypes.default.oneOf(['auto']), _propTypes.default.func]),
@@ -0,0 +1,59 @@
1
+ import { DatasetType } from '../../models/seriesType/config';
2
+ import { AxisDefaultized, ScaleName, ChartsXAxisProps, ChartsYAxisProps, AxisId, AxisConfig } from '../../models/axis';
3
+ import { ExtremumFilter } from '../PluginProvider';
4
+ export type CartesianProviderProps = {
5
+ /**
6
+ * The configuration of the x-axes.
7
+ * If not provided, a default axis config is used.
8
+ * An array of [[AxisConfig]] objects.
9
+ */
10
+ xAxis: AxisConfig<ScaleName, any, ChartsXAxisProps>[];
11
+ /**
12
+ * The configuration of the y-axes.
13
+ * If not provided, a default axis config is used.
14
+ * An array of [[AxisConfig]] objects.
15
+ */
16
+ yAxis: AxisConfig<ScaleName, any, ChartsYAxisProps>[];
17
+ /**
18
+ * An array of objects that can be used to populate series and axes data using their `dataKey` property.
19
+ */
20
+ dataset?: DatasetType;
21
+ children: React.ReactNode;
22
+ };
23
+ export type DefaultizedAxisConfig<AxisProps> = {
24
+ [axisId: AxisId]: AxisDefaultized<ScaleName, any, AxisProps>;
25
+ };
26
+ export type CartesianContextState = {
27
+ /**
28
+ * Mapping from x-axis key to scaling configuration.
29
+ */
30
+ xAxis: DefaultizedAxisConfig<ChartsXAxisProps>;
31
+ /**
32
+ * Mapping from y-axis key to scaling configuration.
33
+ */
34
+ yAxis: DefaultizedAxisConfig<ChartsYAxisProps>;
35
+ /**
36
+ * The x-axes IDs sorted by order they got provided.
37
+ */
38
+ xAxisIds: AxisId[];
39
+ /**
40
+ * The y-axes IDs sorted by order they got provided.
41
+ */
42
+ yAxisIds: AxisId[];
43
+ };
44
+ export type ZoomData = {
45
+ axisId: AxisId;
46
+ start: number;
47
+ end: number;
48
+ };
49
+ export type ZoomFilterMode = 'keep' | 'discard' | 'empty';
50
+ export type ZoomOptions = Record<AxisId, {
51
+ filterMode: ZoomFilterMode;
52
+ }>;
53
+ export type ZoomAxisFilters = Record<AxisId, ExtremumFilter>;
54
+ export type GetZoomAxisFilters = (params: {
55
+ currentAxisId: AxisId | undefined;
56
+ seriesXAxisId?: AxisId;
57
+ seriesYAxisId?: AxisId;
58
+ isDefaultAxis: boolean;
59
+ }) => ExtremumFilter;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -1,25 +1,4 @@
1
1
  import * as React from 'react';
2
2
  import { Initializable } from '../context.types';
3
- import { AxisDefaultized, ScaleName, ChartsXAxisProps, ChartsYAxisProps, AxisId } from '../../models/axis';
4
- export type DefaultizedAxisConfig<AxisProps> = {
5
- [axisId: AxisId]: AxisDefaultized<ScaleName, any, AxisProps>;
6
- };
7
- export type CartesianContextState = {
8
- /**
9
- * Mapping from x-axis key to scaling configuration.
10
- */
11
- xAxis: DefaultizedAxisConfig<ChartsXAxisProps>;
12
- /**
13
- * Mapping from y-axis key to scaling configuration.
14
- */
15
- yAxis: DefaultizedAxisConfig<ChartsYAxisProps>;
16
- /**
17
- * The x-axes IDs sorted by order they got provided.
18
- */
19
- xAxisIds: AxisId[];
20
- /**
21
- * The y-axes IDs sorted by order they got provided.
22
- */
23
- yAxisIds: AxisId[];
24
- };
3
+ import { CartesianContextState } from './Cartesian.types';
25
4
  export declare const CartesianContext: React.Context<Initializable<CartesianContextState>>;
@@ -1,24 +1,4 @@
1
1
  import * as React from 'react';
2
- import { AxisConfig, ChartsXAxisProps, ChartsYAxisProps, ScaleName } from '../../models/axis';
3
- import { DatasetType } from '../../models/seriesType/config';
4
- export type CartesianContextProviderProps = {
5
- /**
6
- * The configuration of the x-axes.
7
- * If not provided, a default axis config is used.
8
- * An array of [[AxisConfig]] objects.
9
- */
10
- xAxis: AxisConfig<ScaleName, any, ChartsXAxisProps>[];
11
- /**
12
- * The configuration of the y-axes.
13
- * If not provided, a default axis config is used.
14
- * An array of [[AxisConfig]] objects.
15
- */
16
- yAxis: AxisConfig<ScaleName, any, ChartsYAxisProps>[];
17
- /**
18
- * An array of objects that can be used to populate series and axes data using their `dataKey` property.
19
- */
20
- dataset?: DatasetType;
21
- children: React.ReactNode;
22
- };
23
- declare function CartesianContextProvider(props: CartesianContextProviderProps): React.JSX.Element;
24
- export { CartesianContextProvider };
2
+ import { CartesianProviderProps } from './Cartesian.types';
3
+ declare function CartesianProvider(props: CartesianProviderProps): React.JSX.Element;
4
+ export { CartesianProvider };
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.CartesianContextProvider = CartesianContextProvider;
6
+ exports.CartesianProvider = CartesianProvider;
7
7
  var React = _interopRequireWildcard(require("react"));
8
8
  var _useDrawingArea = require("../../hooks/useDrawingArea");
9
9
  var _useSeries = require("../../hooks/useSeries");
@@ -14,11 +14,10 @@ var _PluginProvider = require("../PluginProvider");
14
14
  var _jsxRuntime = require("react/jsx-runtime");
15
15
  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); }
16
16
  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; }
17
- function CartesianContextProvider(props) {
17
+ function CartesianProvider(props) {
18
18
  const {
19
19
  xAxis,
20
20
  yAxis,
21
- dataset,
22
21
  children
23
22
  } = props;
24
23
  const formattedSeries = (0, _useSeries.useSeries)();
@@ -30,17 +29,15 @@ function CartesianContextProvider(props) {
30
29
  formattedSeries,
31
30
  axis: xAxis,
32
31
  extremumGetters: xExtremumGetters,
33
- dataset,
34
32
  axisDirection: 'x'
35
- }), [drawingArea, formattedSeries, xAxis, xExtremumGetters, dataset]);
33
+ }), [drawingArea, formattedSeries, xAxis, xExtremumGetters]);
36
34
  const yValues = React.useMemo(() => (0, _computeValue.computeValue)({
37
35
  drawingArea,
38
36
  formattedSeries,
39
37
  axis: yAxis,
40
38
  extremumGetters: yExtremumGetters,
41
- dataset,
42
39
  axisDirection: 'y'
43
- }), [drawingArea, formattedSeries, yAxis, yExtremumGetters, dataset]);
40
+ }), [drawingArea, formattedSeries, yAxis, yExtremumGetters]);
44
41
  const value = React.useMemo(() => ({
45
42
  isInitialized: true,
46
43
  data: {
@@ -1,43 +1,30 @@
1
1
  import { AxisConfig, ScaleName } from '../../models';
2
- import { ChartsXAxisProps, ChartsAxisProps, ChartsYAxisProps, AxisId } from '../../models/axis';
3
- import { CartesianChartSeriesType, DatasetType } from '../../models/seriesType/config';
4
- import { DefaultizedAxisConfig } from './CartesianContext';
2
+ import { ChartsXAxisProps, ChartsAxisProps, ChartsYAxisProps } from '../../models/axis';
3
+ import { CartesianChartSeriesType } from '../../models/seriesType/config';
5
4
  import { DrawingArea } from '../DrawingProvider';
6
5
  import { FormattedSeries } from '../SeriesProvider';
7
6
  import { ExtremumGetter } from '../PluginProvider';
8
- export declare function computeValue(options: {
9
- drawingArea: DrawingArea;
10
- formattedSeries: FormattedSeries;
11
- axis: AxisConfig<ScaleName, any, ChartsYAxisProps>[] | undefined;
12
- extremumGetters: {
13
- [K in CartesianChartSeriesType]?: ExtremumGetter<K>;
14
- };
15
- axisDirection: 'y';
16
- dataset: DatasetType | undefined;
17
- zoomData?: {
18
- axisId: AxisId;
19
- start: number;
20
- end: number;
21
- }[];
22
- }): {
23
- axis: DefaultizedAxisConfig<ChartsYAxisProps>;
7
+ import { DefaultizedAxisConfig, ZoomData, ZoomOptions, GetZoomAxisFilters } from './Cartesian.types';
8
+ type ComputeResult<T extends ChartsAxisProps> = {
9
+ axis: DefaultizedAxisConfig<T>;
24
10
  axisIds: string[];
25
11
  };
26
- export declare function computeValue(options: {
12
+ type ComputeCommonParams = {
27
13
  drawingArea: DrawingArea;
28
14
  formattedSeries: FormattedSeries;
29
- axis: AxisConfig<ScaleName, any, ChartsXAxisProps>[] | undefined;
30
15
  extremumGetters: {
31
16
  [K in CartesianChartSeriesType]?: ExtremumGetter<K>;
32
17
  };
33
- axisDirection: 'x';
34
- dataset: DatasetType | undefined;
35
- zoomData?: {
36
- axisId: AxisId;
37
- start: number;
38
- end: number;
39
- }[];
40
- }): {
41
- axis: DefaultizedAxisConfig<ChartsAxisProps>;
42
- axisIds: string[];
18
+ zoomData?: ZoomData[];
19
+ zoomOptions?: ZoomOptions;
20
+ getFilters?: GetZoomAxisFilters;
43
21
  };
22
+ export declare function computeValue(options: ComputeCommonParams & {
23
+ axis: AxisConfig<ScaleName, any, ChartsYAxisProps>[];
24
+ axisDirection: 'y';
25
+ }): ComputeResult<ChartsYAxisProps>;
26
+ export declare function computeValue(options: ComputeCommonParams & {
27
+ axis: AxisConfig<ScaleName, any, ChartsXAxisProps>[];
28
+ axisDirection: 'x';
29
+ }): ComputeResult<ChartsAxisProps>;
30
+ export {};