@mui/x-charts 7.13.0 → 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 (88) hide show
  1. package/BarChart/BarPlot.js +4 -3
  2. package/BarChart/extremums.js +42 -7
  3. package/CHANGELOG.md +82 -2
  4. package/ChartContainer/useChartContainerProps.js +1 -1
  5. package/ChartContainer/useDefaultizeAxis.d.ts +2 -1
  6. package/ChartContainer/useDefaultizeAxis.js +16 -5
  7. package/ChartsAxisHighlight/ChartsAxisHighlight.js +23 -9
  8. package/ChartsGrid/ChartsGrid.js +6 -4
  9. package/ChartsXAxis/ChartsXAxis.js +14 -3
  10. package/ChartsYAxis/ChartsYAxis.js +8 -2
  11. package/LineChart/extremums.js +20 -4
  12. package/ScatterChart/extremums.js +26 -10
  13. package/context/CartesianProvider/Cartesian.types.d.ts +59 -0
  14. package/context/CartesianProvider/Cartesian.types.js +5 -0
  15. package/context/CartesianProvider/CartesianContext.d.ts +1 -22
  16. package/context/CartesianProvider/CartesianProvider.d.ts +1 -21
  17. package/context/CartesianProvider/CartesianProvider.js +2 -5
  18. package/context/CartesianProvider/computeValue.d.ts +18 -31
  19. package/context/CartesianProvider/computeValue.js +20 -23
  20. package/context/CartesianProvider/getAxisExtremum.d.ts +3 -2
  21. package/context/CartesianProvider/getAxisExtremum.js +11 -5
  22. package/context/CartesianProvider/index.d.ts +1 -0
  23. package/context/CartesianProvider/index.js +12 -0
  24. package/context/CartesianProvider/useCartesianContext.d.ts +1 -1
  25. package/context/CartesianProvider/zoom.d.ts +10 -0
  26. package/context/CartesianProvider/zoom.js +26 -0
  27. package/context/DrawingProvider.d.ts +7 -2
  28. package/context/DrawingProvider.js +11 -3
  29. package/context/PluginProvider/ExtremumGetter.types.d.ts +11 -1
  30. package/esm/BarChart/BarPlot.js +4 -3
  31. package/esm/BarChart/extremums.js +42 -7
  32. package/esm/ChartContainer/useChartContainerProps.js +1 -1
  33. package/esm/ChartContainer/useDefaultizeAxis.js +16 -5
  34. package/esm/ChartsAxisHighlight/ChartsAxisHighlight.js +23 -9
  35. package/esm/ChartsGrid/ChartsGrid.js +6 -4
  36. package/esm/ChartsXAxis/ChartsXAxis.js +14 -3
  37. package/esm/ChartsYAxis/ChartsYAxis.js +8 -2
  38. package/esm/LineChart/extremums.js +20 -4
  39. package/esm/ScatterChart/extremums.js +26 -10
  40. package/esm/context/CartesianProvider/Cartesian.types.js +1 -0
  41. package/esm/context/CartesianProvider/CartesianProvider.js +2 -5
  42. package/esm/context/CartesianProvider/computeValue.js +20 -23
  43. package/esm/context/CartesianProvider/getAxisExtremum.js +11 -5
  44. package/esm/context/CartesianProvider/index.js +1 -0
  45. package/esm/context/CartesianProvider/zoom.js +19 -0
  46. package/esm/context/DrawingProvider.js +11 -3
  47. package/esm/hooks/useAxisEvents.js +3 -1
  48. package/esm/internals/domUtils.js +16 -3
  49. package/esm/internals/index.js +3 -0
  50. package/esm/models/axis.js +5 -0
  51. package/esm/tests/firePointerEvent.js +35 -0
  52. package/hooks/useAxisEvents.js +3 -1
  53. package/index.js +1 -1
  54. package/internals/domUtils.d.ts +2 -0
  55. package/internals/domUtils.js +19 -5
  56. package/internals/index.d.ts +2 -0
  57. package/internals/index.js +17 -1
  58. package/models/axis.d.ts +4 -0
  59. package/models/axis.js +5 -0
  60. package/modern/BarChart/BarPlot.js +4 -3
  61. package/modern/BarChart/extremums.js +42 -7
  62. package/modern/ChartContainer/useChartContainerProps.js +1 -1
  63. package/modern/ChartContainer/useDefaultizeAxis.js +16 -5
  64. package/modern/ChartsAxisHighlight/ChartsAxisHighlight.js +23 -9
  65. package/modern/ChartsGrid/ChartsGrid.js +6 -4
  66. package/modern/ChartsXAxis/ChartsXAxis.js +14 -3
  67. package/modern/ChartsYAxis/ChartsYAxis.js +8 -2
  68. package/modern/LineChart/extremums.js +20 -4
  69. package/modern/ScatterChart/extremums.js +26 -10
  70. package/modern/context/CartesianProvider/Cartesian.types.js +1 -0
  71. package/modern/context/CartesianProvider/CartesianProvider.js +2 -5
  72. package/modern/context/CartesianProvider/computeValue.js +20 -23
  73. package/modern/context/CartesianProvider/getAxisExtremum.js +11 -5
  74. package/modern/context/CartesianProvider/index.js +1 -0
  75. package/modern/context/CartesianProvider/zoom.js +19 -0
  76. package/modern/context/DrawingProvider.js +11 -3
  77. package/modern/hooks/useAxisEvents.js +3 -1
  78. package/modern/index.js +1 -1
  79. package/modern/internals/domUtils.js +16 -3
  80. package/modern/internals/index.js +3 -0
  81. package/modern/models/axis.js +5 -0
  82. package/modern/tests/firePointerEvent.js +35 -0
  83. package/package.json +4 -4
  84. package/tests/firePointerEvent.js +42 -0
  85. package/context/CartesianProvider/normalizeAxis.d.ts +0 -5
  86. package/context/CartesianProvider/normalizeAxis.js +0 -23
  87. package/esm/context/CartesianProvider/normalizeAxis.js +0 -15
  88. package/modern/context/CartesianProvider/normalizeAxis.js +0 -15
@@ -200,6 +200,7 @@ function BarPlot(props) {
200
200
  barLabel
201
201
  } = props,
202
202
  other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
203
+ const withoutBorderRadius = !borderRadius || borderRadius <= 0;
203
204
  const transition = (0, _web.useTransition)(completedData, {
204
205
  keys: bar => `${bar.seriesId}-${bar.dataIndex}`,
205
206
  from: leaveStyle,
@@ -208,7 +209,7 @@ function BarPlot(props) {
208
209
  update: enterStyle,
209
210
  immediate: skipAnimation
210
211
  });
211
- const maskTransition = (0, _web.useTransition)(masksData, {
212
+ const maskTransition = (0, _web.useTransition)(withoutBorderRadius ? [] : masksData, {
212
213
  keys: v => v.id,
213
214
  from: leaveStyle,
214
215
  leave: leaveStyle,
@@ -217,7 +218,7 @@ function BarPlot(props) {
217
218
  immediate: skipAnimation
218
219
  });
219
220
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(React.Fragment, {
220
- children: [maskTransition((style, {
221
+ children: [!withoutBorderRadius && maskTransition((style, {
221
222
  id,
222
223
  hasPositive,
223
224
  hasNegative,
@@ -251,7 +252,7 @@ function BarPlot(props) {
251
252
  }),
252
253
  style: style
253
254
  }));
254
- if (!borderRadius || borderRadius <= 0) {
255
+ if (withoutBorderRadius) {
255
256
  return barElement;
256
257
  }
257
258
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("g", {
@@ -4,25 +4,60 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.getExtremumY = exports.getExtremumX = void 0;
7
+ const createResult = (data, direction) => {
8
+ if (direction === 'x') {
9
+ return {
10
+ x: data,
11
+ y: null
12
+ };
13
+ }
14
+ return {
15
+ x: null,
16
+ y: data
17
+ };
18
+ };
7
19
  const getBaseExtremum = params => {
8
20
  const {
9
- axis
21
+ axis,
22
+ getFilters,
23
+ isDefaultAxis
10
24
  } = params;
11
- const minX = Math.min(...(axis.data ?? []));
12
- const maxX = Math.max(...(axis.data ?? []));
25
+ const filter = getFilters?.({
26
+ currentAxisId: axis.id,
27
+ isDefaultAxis
28
+ });
29
+ const data = filter ? axis.data?.filter((_, i) => filter({
30
+ x: null,
31
+ y: null
32
+ }, i)) : axis.data;
33
+ const minX = Math.min(...(data ?? []));
34
+ const maxX = Math.max(...(data ?? []));
13
35
  return [minX, maxX];
14
36
  };
15
- const getValueExtremum = params => {
37
+ const getValueExtremum = direction => params => {
16
38
  const {
17
39
  series,
18
40
  axis,
41
+ getFilters,
19
42
  isDefaultAxis
20
43
  } = params;
21
44
  return Object.keys(series).filter(seriesId => {
22
45
  const yAxisId = series[seriesId].yAxisId ?? series[seriesId].yAxisKey;
23
46
  return yAxisId === axis.id || isDefaultAxis && yAxisId === undefined;
24
47
  }).reduce((acc, seriesId) => {
25
- const [seriesMin, seriesMax] = series[seriesId].stackedData?.reduce((seriesAcc, values) => {
48
+ const {
49
+ stackedData
50
+ } = series[seriesId];
51
+ const filter = getFilters?.({
52
+ currentAxisId: axis.id,
53
+ isDefaultAxis,
54
+ seriesXAxisId: series[seriesId].xAxisId ?? series[seriesId].xAxisKey,
55
+ seriesYAxisId: series[seriesId].yAxisId ?? series[seriesId].yAxisKey
56
+ });
57
+ const [seriesMin, seriesMax] = stackedData?.reduce((seriesAcc, values, index) => {
58
+ if (filter && (!filter(createResult(values[0], direction), index) || !filter(createResult(values[1], direction), index))) {
59
+ return seriesAcc;
60
+ }
26
61
  return [Math.min(...values, seriesAcc[0]), Math.max(...values, seriesAcc[1])];
27
62
  }, [Infinity, -Infinity]) ?? [Infinity, -Infinity];
28
63
  return [Math.min(seriesMin, acc[0]), Math.max(seriesMax, acc[1])];
@@ -33,7 +68,7 @@ const getExtremumX = params => {
33
68
  // Don't think it's a problem for now
34
69
  const isHorizontal = Object.keys(params.series).some(seriesId => params.series[seriesId].layout === 'horizontal');
35
70
  if (isHorizontal) {
36
- return getValueExtremum(params);
71
+ return getValueExtremum('x')(params);
37
72
  }
38
73
  return getBaseExtremum(params);
39
74
  };
@@ -43,6 +78,6 @@ const getExtremumY = params => {
43
78
  if (isHorizontal) {
44
79
  return getBaseExtremum(params);
45
80
  }
46
- return getValueExtremum(params);
81
+ return getValueExtremum('y')(params);
47
82
  };
48
83
  exports.getExtremumY = getExtremumY;
package/CHANGELOG.md CHANGED
@@ -3,6 +3,86 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## 7.14.0
7
+
8
+ _Aug 23, 2024_
9
+
10
+ We'd like to offer a big thanks to the 14 contributors who made this release possible. Here are some highlights ✨:
11
+
12
+ - 💫 Allow [filtering the axis on zoom](https://mui.com/x/react-charts/zoom-and-pan/#zoom-filtering), making the axis adapt by removing values outside the view.
13
+
14
+ <img width="600" src="https://github.com/user-attachments/assets/e65bbd00-d2a8-4136-81cd-3598f1373c16" alt="filtering the axis on zoom" />
15
+
16
+ - 📊 Improve bar chart performances
17
+ - 🌍 Improve Czech (cs-CZ) and Hebrew (he-IL) locales on the Data Grid
18
+ - 🌍 Improve Chinese (zh-HK), Hebrew (he-IL), and Vietnamese (vi-VN) locales on the Date and Time Pickers
19
+ - 🐞 Bugfixes
20
+
21
+ <!--/ HIGHLIGHT_ABOVE_SEPARATOR /-->
22
+
23
+ ### Data Grid
24
+
25
+ #### `@mui/x-data-grid@7.14.0`
26
+
27
+ - [DataGrid] Use readonly array result for `getTreeDataPath` (#11743) @pcorpet
28
+ - [DataGrid] Use `event.key` for `Tab` and `Escape` keys (#14170) @k-rajat19
29
+ - [DataGrid] Introduce selectors with arguments (#14236) @MBilalShafi
30
+ - [DataGrid] include `api` in `gridCellParams` interface (#14201) @k-rajat19
31
+ - [l10n] Improve Czech (cs-CZ) locale (#14135) @chirimiri22
32
+ - [l10n] Improve Hebrew (he-IL) locale (#14287) @rotembarsela
33
+
34
+ #### `@mui/x-data-grid-pro@7.14.0` [![pro](https://mui.com/r/x-pro-svg)](https://mui.com/r/x-pro-svg-link 'Pro plan')
35
+
36
+ Same changes as in `@mui/x-data-grid@7.14.0`.
37
+
38
+ #### `@mui/x-data-grid-premium@7.14.0` [![premium](https://mui.com/r/x-premium-svg)](https://mui.com/r/x-premium-svg-link 'Premium plan')
39
+
40
+ Same changes as in `@mui/x-data-grid-pro@7.14.0`, plus:
41
+
42
+ - [DataGridPremium] Fix clipboard paste not working for a single cell on non-first page (#14261) @arminmeh
43
+ - [DataGridPremium] Fix `onCellSelectionModelChange` not triggered when additional cell range is selected (#14199) @arminmeh
44
+
45
+ ### Date and Time Pickers
46
+
47
+ #### `@mui/x-date-pickers@7.14.0`
48
+
49
+ - [l10n] Improve Chinese (zh-HK) locale (#13289) @yeeharn
50
+ - [l10n] Improve Hebrew (he-IL) locale (#14287) @rotembarsela
51
+ - [l10n] Improve Vietnamese (vi-VN) locale (#14238) @locnbk2002
52
+ - [TimePicker] Handle `Space` and `Enter` on the `TimeClock` component @arthurbalduini
53
+
54
+ #### `@mui/x-date-pickers-pro@7.14.0` [![pro](https://mui.com/r/x-pro-svg)](https://mui.com/r/x-pro-svg-link 'Pro plan')
55
+
56
+ Same changes as in `@mui/x-date-pickers@7.14.0`.
57
+
58
+ ### Charts
59
+
60
+ #### `@mui/x-charts@7.14.0`
61
+
62
+ - [charts] Fix grid overflow with zooming (#14280) @alexfauquette
63
+ - [charts] Improve bar chart performances (#14278) @alexfauquette
64
+ - [charts] Test pointer events (#14042) @alexfauquette
65
+ - [charts] Use `isPointInside` function for both graphs and axis (#14222) @JCQuintas
66
+
67
+ #### `@mui/x-charts-pro@7.0.0-alpha.2` [![pro](https://mui.com/r/x-pro-svg)](https://mui.com/r/x-pro-svg-link 'Pro plan')
68
+
69
+ Same changes as in `@mui/x-charts@7.14.0`, plus:
70
+
71
+ - [charts-pro] Zoom axis filtering (#14121) @JCQuintas
72
+
73
+ ### Docs
74
+
75
+ - [docs] Consistent use of UTC and timezones (#14250) @oliviertassinari
76
+ - [docs] Fix missing leading slashes in URLs (#14249) @oliviertassinari
77
+ - [docs] Dash usage revision on pickers pages (#14260) @arthurbalduini
78
+
79
+ ### Core
80
+
81
+ - [core] Follow JSDocs convention @oliviertassinari
82
+ - [core] Prepare for material v6 (#14143) @LukasTy
83
+ - [code-infra] Set up `eslint-plugin-testing-library` (#14232) @LukasTy
84
+ - [infra] Updated mui-x roadmap links with new project URL (#14271) @michelengelen
85
+
6
86
  ## 7.13.0
7
87
 
8
88
  _Aug 16, 2024_
@@ -58,7 +138,7 @@ Same changes as in `@mui/x-date-pickers@7.13.0`.
58
138
  - [charts] Rename `CartesianContextProvider` to `CartesianProvider` (#14102) @JCQuintas
59
139
  - [charts] Support axis with the same value for all data points (#14191) @alexfauquette
60
140
 
61
- #### `@mui/x-date-charts-pro@7.0.0-alpha.1` [![pro](https://mui.com/r/x-pro-svg)](https://mui.com/r/x-pro-svg-link 'Pro plan')
141
+ #### `@mui/x-charts-pro@7.0.0-alpha.1` [![pro](https://mui.com/r/x-pro-svg)](https://mui.com/r/x-pro-svg-link 'Pro plan')
62
142
 
63
143
  Same changes as in `@mui/x-charts@7.13.0`.
64
144
 
@@ -132,7 +212,7 @@ Same changes as in `@mui/x-date-pickers@7.12.1`.
132
212
  - [charts] Fix charts vendor publish config (#14073) @JCQuintas
133
213
  - [charts] Move `plugins` to `PluginProvider` (#14056) @JCQuintas
134
214
 
135
- #### `@mui/x-date-charts-pro@7.0.0-alpha.0` [![pro](https://mui.com/r/x-pro-svg)](https://mui.com/r/x-pro-svg-link 'Pro plan')
215
+ #### `@mui/x-charts-pro@7.0.0-alpha.0` [![pro](https://mui.com/r/x-pro-svg)](https://mui.com/r/x-pro-svg-link 'Pro plan')
136
216
 
137
217
  Same changes as in `@mui/x-charts@7.12.1`, plus:
138
218
 
@@ -39,7 +39,7 @@ const useChartContainerProps = (props, ref) => {
39
39
  const chartSurfaceRef = (0, _useForkRef.default)(ref, svgRef);
40
40
  (0, _useReducedMotion.useReducedMotion)(); // a11y reduce motion (see: https://react-spring.dev/docs/utilities/use-reduced-motion)
41
41
 
42
- const [defaultizedXAxis, defaultizedYAxis] = (0, _useDefaultizeAxis.useDefaultizeAxis)(xAxis, yAxis);
42
+ const [defaultizedXAxis, defaultizedYAxis] = (0, _useDefaultizeAxis.useDefaultizeAxis)(xAxis, yAxis, dataset);
43
43
  const drawingProviderProps = {
44
44
  width,
45
45
  height,
@@ -1,7 +1,8 @@
1
1
  import { MakeOptional } from '../models/helpers';
2
2
  import { AxisConfig, ScaleName } from '../models';
3
3
  import { ChartsAxisProps } from '../models/axis';
4
- export declare const useDefaultizeAxis: (inXAxis: MakeOptional<AxisConfig<ScaleName, any, ChartsAxisProps>, "id">[] | undefined, inYAxis: MakeOptional<AxisConfig<ScaleName, any, ChartsAxisProps>, "id">[] | undefined) => {
4
+ import { DatasetType } from '../models/seriesType/config';
5
+ export declare const useDefaultizeAxis: (inXAxis: MakeOptional<AxisConfig<ScaleName, any, ChartsAxisProps>, "id">[] | undefined, inYAxis: MakeOptional<AxisConfig<ScaleName, any, ChartsAxisProps>, "id">[] | undefined, dataset: DatasetType | undefined) => {
5
6
  reverse?: boolean | undefined;
6
7
  fill?: string | undefined;
7
8
  stroke?: string | undefined;
@@ -10,7 +10,7 @@ var React = _interopRequireWildcard(require("react"));
10
10
  var _constants = require("../constants");
11
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); }
12
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; }
13
- const defaultizeAxis = (inAxis, axisName) => {
13
+ const defaultizeAxis = (inAxis, dataset, axisName) => {
14
14
  const DEFAULT_AXIS_KEY = axisName === 'x' ? _constants.DEFAULT_X_AXIS_KEY : _constants.DEFAULT_Y_AXIS_KEY;
15
15
  return [...(inAxis?.map((axis, index) => (0, _extends2.default)({
16
16
  id: `defaultized-${axisName}-axis-${index}`
@@ -19,11 +19,22 @@ const defaultizeAxis = (inAxis, axisName) => {
19
19
  }) => id === DEFAULT_AXIS_KEY) === -1 ? [{
20
20
  id: DEFAULT_AXIS_KEY,
21
21
  scaleType: 'linear'
22
- }] : [])];
22
+ }] : [])].map(axisConfig => {
23
+ const dataKey = axisConfig.dataKey;
24
+ if (dataKey === undefined || axisConfig.data !== undefined) {
25
+ return axisConfig;
26
+ }
27
+ if (dataset === undefined) {
28
+ throw Error(`MUI X: ${axisName}-axis uses \`dataKey\` but no \`dataset\` is provided.`);
29
+ }
30
+ return (0, _extends2.default)({}, axisConfig, {
31
+ data: dataset.map(d => d[dataKey])
32
+ });
33
+ });
23
34
  };
24
- const useDefaultizeAxis = (inXAxis, inYAxis) => {
25
- const xAxis = React.useMemo(() => defaultizeAxis(inXAxis, 'x'), [inXAxis]);
26
- const yAxis = React.useMemo(() => defaultizeAxis(inYAxis, 'y'), [inYAxis]);
35
+ const useDefaultizeAxis = (inXAxis, inYAxis, dataset) => {
36
+ const xAxis = React.useMemo(() => defaultizeAxis(inXAxis, dataset, 'x'), [inXAxis, dataset]);
37
+ const yAxis = React.useMemo(() => defaultizeAxis(inYAxis, dataset, 'y'), [inYAxis, dataset]);
27
38
  return [xAxis, yAxis];
28
39
  };
29
40
  exports.useDefaultizeAxis = useDefaultizeAxis;
@@ -36,16 +36,30 @@ const ChartsAxisHighlightPath = exports.ChartsAxisHighlightPath = (0, _styles.st
36
36
  slot: 'Root',
37
37
  overridesResolver: (_, styles) => styles.root
38
38
  })(({
39
- ownerState,
40
39
  theme
41
- }) => (0, _extends2.default)({
42
- pointerEvents: 'none'
43
- }, ownerState.axisHighlight === 'band' && {
44
- fill: theme.palette.mode === 'light' ? 'gray' : 'white',
45
- fillOpacity: 0.1
46
- }, ownerState.axisHighlight === 'line' && {
47
- strokeDasharray: '5 2',
48
- stroke: theme.palette.mode === 'light' ? '#000000' : '#ffffff'
40
+ }) => ({
41
+ pointerEvents: 'none',
42
+ variants: [{
43
+ props: {
44
+ axisHighlight: 'band'
45
+ },
46
+ style: (0, _extends2.default)({
47
+ fill: 'white',
48
+ fillOpacity: 0.1
49
+ }, theme.applyStyles('light', {
50
+ fill: 'gray'
51
+ }))
52
+ }, {
53
+ props: {
54
+ axisHighlight: 'line'
55
+ },
56
+ style: (0, _extends2.default)({
57
+ strokeDasharray: '5 2',
58
+ stroke: '#ffffff'
59
+ }, theme.applyStyles('light', {
60
+ stroke: '#000000'
61
+ }))
62
+ }]
49
63
  }));
50
64
  /**
51
65
  * Demos:
@@ -14,6 +14,7 @@ var _styles = require("@mui/material/styles");
14
14
  var _CartesianProvider = require("../context/CartesianProvider");
15
15
  var _useTicks = require("../hooks/useTicks");
16
16
  var _chartsGridClasses = require("./chartsGridClasses");
17
+ var _useDrawingArea = require("../hooks/useDrawingArea");
17
18
  var _jsxRuntime = require("react/jsx-runtime");
18
19
  const _excluded = ["vertical", "horizontal"];
19
20
  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); }
@@ -62,6 +63,7 @@ function ChartsGrid(props) {
62
63
  props,
63
64
  name: 'MuiChartsGrid'
64
65
  });
66
+ const drawingArea = (0, _useDrawingArea.useDrawingArea)();
65
67
  const {
66
68
  vertical,
67
69
  horizontal
@@ -102,8 +104,8 @@ function ChartsGrid(props) {
102
104
  formattedValue,
103
105
  offset
104
106
  }) => /*#__PURE__*/(0, _jsxRuntime.jsx)(GridLine, {
105
- y1: yScale.range()[0],
106
- y2: yScale.range()[1],
107
+ y1: drawingArea.top,
108
+ y2: drawingArea.top + drawingArea.height,
107
109
  x1: offset,
108
110
  x2: offset,
109
111
  className: classes.verticalLine
@@ -113,8 +115,8 @@ function ChartsGrid(props) {
113
115
  }) => /*#__PURE__*/(0, _jsxRuntime.jsx)(GridLine, {
114
116
  y1: offset,
115
117
  y2: offset,
116
- x1: xScale.range()[0],
117
- x2: xScale.range()[1],
118
+ x1: drawingArea.left,
119
+ x2: drawingArea.left + drawingArea.width,
118
120
  className: classes.horizontalLine
119
121
  }, `horizontal-${formattedValue}`))]
120
122
  }));
@@ -159,7 +159,8 @@ function ChartsXAxis(inProps) {
159
159
  left,
160
160
  top,
161
161
  width,
162
- height
162
+ height,
163
+ isPointInside
163
164
  } = (0, _useDrawingArea.useDrawingArea)();
164
165
  const tickSize = disableTicks ? 4 : tickSizeProp;
165
166
  const positionSign = position === 'bottom' ? 1 : -1;
@@ -234,8 +235,18 @@ function ChartsXAxis(inProps) {
234
235
  }, index) => {
235
236
  const xTickLabel = labelOffset ?? 0;
236
237
  const yTickLabel = positionSign * (tickSize + 3);
237
- const showTick = offset >= left - 1 && offset <= left + width + 1;
238
- 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
+ });
239
250
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)("g", {
240
251
  transform: `translate(${offset}, 0)`,
241
252
  className: classes.tickContainer,
@@ -101,7 +101,8 @@ function ChartsYAxis(inProps) {
101
101
  left,
102
102
  top,
103
103
  width,
104
- height
104
+ height,
105
+ isPointInside
105
106
  } = (0, _useDrawingArea.useDrawingArea)();
106
107
  const tickSize = disableTicks ? 4 : tickSizeProp;
107
108
  const yTicks = (0, _useTicks.useTicks)({
@@ -181,7 +182,12 @@ function ChartsYAxis(inProps) {
181
182
  const xTickLabel = positionSign * (tickSize + 2);
182
183
  const yTickLabel = labelOffset;
183
184
  const skipLabel = typeof tickLabelInterval === 'function' && !tickLabelInterval?.(value, index);
184
- const showLabel = offset >= top - 1 && offset <= height + top + 1;
185
+ const showLabel = isPointInside({
186
+ x: -1,
187
+ y: offset
188
+ }, {
189
+ direction: 'y'
190
+ });
185
191
  if (!showLabel) {
186
192
  return null;
187
193
  }
@@ -13,9 +13,18 @@ const getExtremumX = params => {
13
13
  return [minX, maxX];
14
14
  };
15
15
  exports.getExtremumX = getExtremumX;
16
- function getSeriesExtremums(getValues, stackedData) {
17
- return stackedData.reduce((seriesAcc, stackedValue) => {
16
+ function getSeriesExtremums(getValues, stackedData, filter) {
17
+ return stackedData.reduce((seriesAcc, stackedValue, index) => {
18
18
  const [base, value] = getValues(stackedValue);
19
+ if (filter && (!filter({
20
+ y: base,
21
+ x: null
22
+ }, index) || !filter({
23
+ y: value,
24
+ x: null
25
+ }, index))) {
26
+ return seriesAcc;
27
+ }
19
28
  return [Math.min(base, value, seriesAcc[0]), Math.max(base, value, seriesAcc[1])];
20
29
  }, [Infinity, -Infinity]);
21
30
  }
@@ -23,7 +32,8 @@ const getExtremumY = params => {
23
32
  const {
24
33
  series,
25
34
  axis,
26
- isDefaultAxis
35
+ isDefaultAxis,
36
+ getFilters
27
37
  } = params;
28
38
  return Object.keys(series).filter(seriesId => {
29
39
  const yAxisId = series[seriesId].yAxisId ?? series[seriesId].yAxisKey;
@@ -34,10 +44,16 @@ const getExtremumY = params => {
34
44
  stackedData
35
45
  } = series[seriesId];
36
46
  const isArea = area !== undefined;
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
+ });
37
53
 
38
54
  // Since this series is not used to display an area, we do not consider the base (the d[0]).
39
55
  const getValues = isArea && axis.scaleType !== 'log' && typeof series[seriesId].baseline !== 'string' ? d => d : d => [d[1], d[1]];
40
- const seriesExtremums = getSeriesExtremums(getValues, stackedData);
56
+ const seriesExtremums = getSeriesExtremums(getValues, stackedData, filter);
41
57
  const [seriesMin, seriesMax] = seriesExtremums;
42
58
  return [Math.min(seriesMin, acc[0]), Math.max(seriesMax, acc[1])];
43
59
  }, [Infinity, -Infinity]);
@@ -11,16 +11,24 @@ const getExtremumX = params => {
11
11
  const {
12
12
  series,
13
13
  axis,
14
- isDefaultAxis
14
+ isDefaultAxis,
15
+ getFilters
15
16
  } = params;
16
17
  return Object.keys(series).filter(seriesId => {
17
18
  const axisId = series[seriesId].xAxisId ?? series[seriesId].xAxisKey;
18
19
  return axisId === axis.id || axisId === undefined && isDefaultAxis;
19
20
  }).reduce((acc, seriesId) => {
20
- const seriesMinMax = series[seriesId].data.reduce((accSeries, {
21
- x
22
- }) => {
23
- return mergeMinMax(accSeries, [x, x]);
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]);
24
32
  }, [Infinity, -Infinity]);
25
33
  return mergeMinMax(acc, seriesMinMax);
26
34
  }, [Infinity, -Infinity]);
@@ -30,16 +38,24 @@ const getExtremumY = params => {
30
38
  const {
31
39
  series,
32
40
  axis,
33
- isDefaultAxis
41
+ isDefaultAxis,
42
+ getFilters
34
43
  } = params;
35
44
  return Object.keys(series).filter(seriesId => {
36
45
  const axisId = series[seriesId].yAxisId ?? series[seriesId].yAxisKey;
37
46
  return axisId === axis.id || axisId === undefined && isDefaultAxis;
38
47
  }).reduce((acc, seriesId) => {
39
- const seriesMinMax = series[seriesId].data.reduce((accSeries, {
40
- y
41
- }) => {
42
- return mergeMinMax(accSeries, [y, y]);
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]);
43
59
  }, [Infinity, -Infinity]);
44
60
  return mergeMinMax(acc, seriesMinMax);
45
61
  }, [Infinity, -Infinity]);
@@ -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 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
- };
2
+ import { CartesianProviderProps } from './Cartesian.types';
23
3
  declare function CartesianProvider(props: CartesianProviderProps): React.JSX.Element;
24
4
  export { CartesianProvider };