@mui/x-charts 7.7.0 → 7.7.1

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 (137) hide show
  1. package/BarChart/BarChart.js +21 -104
  2. package/BarChart/BarLabel/BarLabelPlot.d.ts +0 -3
  3. package/BarChart/BarLabel/BarLabelPlot.js +1 -24
  4. package/BarChart/BarPlot.js +2 -2
  5. package/BarChart/checkScaleErrors.d.ts +5 -9
  6. package/BarChart/types.d.ts +2 -2
  7. package/BarChart/useBarChartProps.d.ts +102 -0
  8. package/BarChart/useBarChartProps.js +143 -0
  9. package/CHANGELOG.md +82 -0
  10. package/ChartContainer/ChartContainer.d.ts +1 -1
  11. package/ChartContainer/ChartContainer.js +6 -10
  12. package/ChartContainer/useChartContainerHooks.d.ts +11 -0
  13. package/ChartContainer/useChartContainerHooks.js +34 -0
  14. package/ChartContainer/usePluginsMerge.d.ts +1 -2
  15. package/ChartsAxis/ChartsAxis.js +2 -2
  16. package/ChartsAxisHighlight/ChartsAxisHighlight.js +2 -2
  17. package/ChartsGrid/ChartsGrid.js +2 -2
  18. package/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +2 -2
  19. package/ChartsTooltip/ChartsAxisTooltipContent.js +2 -2
  20. package/ChartsTooltip/ChartsItemTooltipContent.js +2 -2
  21. package/ChartsVoronoiHandler/ChartsVoronoiHandler.js +2 -2
  22. package/ChartsXAxis/ChartsXAxis.js +2 -2
  23. package/ChartsYAxis/ChartsYAxis.js +2 -2
  24. package/LineChart/AreaPlot.js +2 -2
  25. package/LineChart/LineChart.js +24 -106
  26. package/LineChart/LineHighlightPlot.js +2 -2
  27. package/LineChart/LinePlot.js +2 -2
  28. package/LineChart/MarkPlot.js +2 -2
  29. package/LineChart/useLineChartProps.d.ts +117 -0
  30. package/LineChart/useLineChartProps.js +152 -0
  31. package/ScatterChart/ScatterChart.js +20 -75
  32. package/ScatterChart/ScatterPlot.js +2 -2
  33. package/ScatterChart/useScatterChartProps.d.ts +86 -0
  34. package/ScatterChart/useScatterChartProps.js +116 -0
  35. package/context/CartesianProvider/CartesianContext.d.ts +25 -0
  36. package/context/CartesianProvider/CartesianContext.js +21 -0
  37. package/context/CartesianProvider/CartesianProvider.d.ts +34 -0
  38. package/context/CartesianProvider/CartesianProvider.js +44 -0
  39. package/context/CartesianProvider/computeValue.d.ts +19 -0
  40. package/context/CartesianProvider/computeValue.js +89 -0
  41. package/context/CartesianProvider/getAxisExtremum.d.ts +4 -0
  42. package/context/CartesianProvider/getAxisExtremum.js +28 -0
  43. package/context/CartesianProvider/index.d.ts +9 -0
  44. package/context/CartesianProvider/index.js +51 -0
  45. package/context/CartesianProvider/normalizeAxis.d.ts +5 -0
  46. package/context/CartesianProvider/normalizeAxis.js +23 -0
  47. package/context/CartesianProvider/useCartesianContext.d.ts +2 -0
  48. package/context/CartesianProvider/useCartesianContext.js +17 -0
  49. package/context/ColorProvider.d.ts +2 -2
  50. package/esm/BarChart/BarChart.js +21 -104
  51. package/esm/BarChart/BarLabel/BarLabelPlot.js +0 -23
  52. package/esm/BarChart/BarPlot.js +2 -2
  53. package/esm/BarChart/useBarChartProps.js +136 -0
  54. package/esm/ChartContainer/ChartContainer.js +5 -9
  55. package/esm/ChartContainer/useChartContainerHooks.js +24 -0
  56. package/esm/ChartsAxis/ChartsAxis.js +2 -2
  57. package/esm/ChartsAxisHighlight/ChartsAxisHighlight.js +2 -2
  58. package/esm/ChartsGrid/ChartsGrid.js +2 -2
  59. package/esm/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +2 -2
  60. package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +2 -2
  61. package/esm/ChartsTooltip/ChartsItemTooltipContent.js +2 -2
  62. package/esm/ChartsVoronoiHandler/ChartsVoronoiHandler.js +2 -2
  63. package/esm/ChartsXAxis/ChartsXAxis.js +2 -2
  64. package/esm/ChartsYAxis/ChartsYAxis.js +2 -2
  65. package/esm/LineChart/AreaPlot.js +2 -2
  66. package/esm/LineChart/LineChart.js +24 -106
  67. package/esm/LineChart/LineHighlightPlot.js +2 -2
  68. package/esm/LineChart/LinePlot.js +2 -2
  69. package/esm/LineChart/MarkPlot.js +2 -2
  70. package/esm/LineChart/useLineChartProps.js +144 -0
  71. package/esm/ScatterChart/ScatterChart.js +20 -75
  72. package/esm/ScatterChart/ScatterPlot.js +2 -2
  73. package/esm/ScatterChart/useScatterChartProps.js +108 -0
  74. package/esm/context/CartesianProvider/CartesianContext.js +13 -0
  75. package/esm/context/CartesianProvider/CartesianProvider.js +37 -0
  76. package/esm/context/CartesianProvider/computeValue.js +82 -0
  77. package/esm/context/CartesianProvider/getAxisExtremum.js +21 -0
  78. package/esm/context/CartesianProvider/index.js +10 -0
  79. package/esm/context/CartesianProvider/normalizeAxis.js +15 -0
  80. package/esm/context/CartesianProvider/useCartesianContext.js +8 -0
  81. package/esm/hooks/useAxisEvents.js +2 -2
  82. package/esm/hooks/useColorScale.js +3 -3
  83. package/esm/hooks/useScale.js +3 -4
  84. package/esm/internals/components/ChartsAxesGradients/ChartsAxesGradients.js +2 -2
  85. package/esm/internals/index.js +6 -2
  86. package/hooks/useAxisEvents.js +2 -2
  87. package/hooks/useColorScale.js +3 -3
  88. package/hooks/useDrawingArea.d.ts +2 -8
  89. package/hooks/useScale.js +3 -6
  90. package/index.js +1 -1
  91. package/internals/components/ChartsAxesGradients/ChartsAxesGradients.d.ts +2 -1
  92. package/internals/components/ChartsAxesGradients/ChartsAxesGradients.js +2 -2
  93. package/internals/index.d.ts +7 -1
  94. package/internals/index.js +49 -5
  95. package/models/plugin.d.ts +4 -1
  96. package/modern/BarChart/BarChart.js +21 -104
  97. package/modern/BarChart/BarLabel/BarLabelPlot.js +0 -23
  98. package/modern/BarChart/BarPlot.js +2 -2
  99. package/modern/BarChart/useBarChartProps.js +136 -0
  100. package/modern/ChartContainer/ChartContainer.js +5 -9
  101. package/modern/ChartContainer/useChartContainerHooks.js +24 -0
  102. package/modern/ChartsAxis/ChartsAxis.js +2 -2
  103. package/modern/ChartsAxisHighlight/ChartsAxisHighlight.js +2 -2
  104. package/modern/ChartsGrid/ChartsGrid.js +2 -2
  105. package/modern/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +2 -2
  106. package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +2 -2
  107. package/modern/ChartsTooltip/ChartsItemTooltipContent.js +2 -2
  108. package/modern/ChartsVoronoiHandler/ChartsVoronoiHandler.js +2 -2
  109. package/modern/ChartsXAxis/ChartsXAxis.js +2 -2
  110. package/modern/ChartsYAxis/ChartsYAxis.js +2 -2
  111. package/modern/LineChart/AreaPlot.js +2 -2
  112. package/modern/LineChart/LineChart.js +24 -106
  113. package/modern/LineChart/LineHighlightPlot.js +2 -2
  114. package/modern/LineChart/LinePlot.js +2 -2
  115. package/modern/LineChart/MarkPlot.js +2 -2
  116. package/modern/LineChart/useLineChartProps.js +144 -0
  117. package/modern/ScatterChart/ScatterChart.js +20 -75
  118. package/modern/ScatterChart/ScatterPlot.js +2 -2
  119. package/modern/ScatterChart/useScatterChartProps.js +108 -0
  120. package/modern/context/CartesianProvider/CartesianContext.js +13 -0
  121. package/modern/context/CartesianProvider/CartesianProvider.js +37 -0
  122. package/modern/context/CartesianProvider/computeValue.js +82 -0
  123. package/modern/context/CartesianProvider/getAxisExtremum.js +21 -0
  124. package/modern/context/CartesianProvider/index.js +10 -0
  125. package/modern/context/CartesianProvider/normalizeAxis.js +15 -0
  126. package/modern/context/CartesianProvider/useCartesianContext.js +8 -0
  127. package/modern/hooks/useAxisEvents.js +2 -2
  128. package/modern/hooks/useColorScale.js +3 -3
  129. package/modern/hooks/useScale.js +3 -4
  130. package/modern/index.js +1 -1
  131. package/modern/internals/components/ChartsAxesGradients/ChartsAxesGradients.js +2 -2
  132. package/modern/internals/index.js +6 -2
  133. package/package.json +3 -3
  134. package/context/CartesianContextProvider.d.ts +0 -61
  135. package/context/CartesianContextProvider.js +0 -220
  136. package/esm/context/CartesianContextProvider.js +0 -211
  137. package/modern/context/CartesianContextProvider.js +0 -211
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.computeValue = computeValue;
8
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
+ var _d3Scale = require("d3-scale");
10
+ var _constants = require("../../constants");
11
+ var _axis = require("../../models/axis");
12
+ var _colorScale = require("../../internals/colorScale");
13
+ var _useTicks = require("../../hooks/useTicks");
14
+ var _getScale = require("../../internals/getScale");
15
+ var _getAxisExtremum = require("./getAxisExtremum");
16
+ const getRange = (drawingArea, axisName, isReverse) => {
17
+ const range = axisName === 'x' ? [drawingArea.left, drawingArea.left + drawingArea.width] : [drawingArea.top + drawingArea.height, drawingArea.top];
18
+ return isReverse ? range.reverse() : range;
19
+ };
20
+ const DEFAULT_CATEGORY_GAP_RATIO = 0.2;
21
+ const DEFAULT_BAR_GAP_RATIO = 0.1;
22
+ function computeValue(drawingArea, formattedSeries, inAxis, extremumGetters, axisName) {
23
+ const DEFAULT_AXIS_KEY = axisName === 'x' ? _constants.DEFAULT_X_AXIS_KEY : _constants.DEFAULT_Y_AXIS_KEY;
24
+ const allAxis = [...(inAxis?.map((axis, index) => (0, _extends2.default)({
25
+ id: `defaultized-${axisName}-axis-${index}`
26
+ }, axis)) ?? []), ...(inAxis === undefined || inAxis.findIndex(({
27
+ id
28
+ }) => id === DEFAULT_AXIS_KEY) === -1 ? [{
29
+ id: DEFAULT_AXIS_KEY,
30
+ scaleType: 'linear'
31
+ }] : [])];
32
+ const completeAxis = {};
33
+ allAxis.forEach((axis, axisIndex) => {
34
+ const isDefaultAxis = axisIndex === 0;
35
+ const [minData, maxData] = (0, _getAxisExtremum.getAxisExtremum)(axis, extremumGetters, isDefaultAxis, formattedSeries);
36
+ const range = getRange(drawingArea, axisName, axis.reverse);
37
+ if ((0, _axis.isBandScaleConfig)(axis)) {
38
+ const categoryGapRatio = axis.categoryGapRatio ?? DEFAULT_CATEGORY_GAP_RATIO;
39
+ const barGapRatio = axis.barGapRatio ?? DEFAULT_BAR_GAP_RATIO;
40
+ // Reverse range because ordinal scales are presented from top to bottom on y-axis
41
+ const scaleRange = axisName === 'x' ? range : [range[1], range[0]];
42
+ completeAxis[axis.id] = (0, _extends2.default)({
43
+ categoryGapRatio,
44
+ barGapRatio
45
+ }, axis, {
46
+ scale: (0, _d3Scale.scaleBand)(axis.data, scaleRange).paddingInner(categoryGapRatio).paddingOuter(categoryGapRatio / 2),
47
+ tickNumber: axis.data.length,
48
+ colorScale: axis.colorMap && (axis.colorMap.type === 'ordinal' ? (0, _colorScale.getOrdinalColorScale)((0, _extends2.default)({
49
+ values: axis.data
50
+ }, axis.colorMap)) : (0, _colorScale.getColorScale)(axis.colorMap))
51
+ });
52
+ }
53
+ if ((0, _axis.isPointScaleConfig)(axis)) {
54
+ const scaleRange = axisName === 'x' ? range : [...range].reverse();
55
+ completeAxis[axis.id] = (0, _extends2.default)({}, axis, {
56
+ scale: (0, _d3Scale.scalePoint)(axis.data, scaleRange),
57
+ tickNumber: axis.data.length,
58
+ colorScale: axis.colorMap && (axis.colorMap.type === 'ordinal' ? (0, _colorScale.getOrdinalColorScale)((0, _extends2.default)({
59
+ values: axis.data
60
+ }, axis.colorMap)) : (0, _colorScale.getColorScale)(axis.colorMap))
61
+ });
62
+ }
63
+ if (axis.scaleType === 'band' || axis.scaleType === 'point') {
64
+ // Could be merged with the two previous "if conditions" but then TS does not get that `axis.scaleType` can't be `band` or `point`.
65
+ return;
66
+ }
67
+ const scaleType = axis.scaleType ?? 'linear';
68
+ const extremums = [axis.min ?? minData, axis.max ?? maxData];
69
+ const tickNumber = (0, _useTicks.getTickNumber)((0, _extends2.default)({}, axis, {
70
+ range,
71
+ domain: extremums
72
+ }));
73
+ const scale = (0, _getScale.getScale)(scaleType, extremums, range).nice(tickNumber);
74
+ const [minDomain, maxDomain] = scale.domain();
75
+ const domain = [axis.min ?? minDomain, axis.max ?? maxDomain];
76
+ completeAxis[axis.id] = (0, _extends2.default)({}, axis, {
77
+ scaleType: scaleType,
78
+ scale: scale.domain(domain),
79
+ tickNumber,
80
+ colorScale: axis.colorMap && (0, _colorScale.getColorScale)(axis.colorMap)
81
+ });
82
+ });
83
+ return {
84
+ axis: completeAxis,
85
+ axisIds: allAxis.map(({
86
+ id
87
+ }) => id)
88
+ };
89
+ }
@@ -0,0 +1,4 @@
1
+ import { AxisConfig, ExtremumGettersConfig } from '../../models';
2
+ import { ExtremumGetterResult } from '../../models/seriesType/config';
3
+ import { FormattedSeries } from '../SeriesContextProvider';
4
+ export declare const getAxisExtremum: (axis: AxisConfig, getters: ExtremumGettersConfig, isDefaultAxis: boolean, formattedSeries: FormattedSeries) => ExtremumGetterResult;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getAxisExtremum = void 0;
7
+ const axisExtremumCallback = (acc, chartType, axis, getters, isDefaultAxis, formattedSeries) => {
8
+ const getter = getters[chartType];
9
+ const series = formattedSeries[chartType]?.series ?? {};
10
+ const [minChartTypeData, maxChartTypeData] = getter?.({
11
+ series,
12
+ axis,
13
+ isDefaultAxis
14
+ }) ?? [null, null];
15
+ const [minData, maxData] = acc;
16
+ if (minData === null || maxData === null) {
17
+ return [minChartTypeData, maxChartTypeData];
18
+ }
19
+ if (minChartTypeData === null || maxChartTypeData === null) {
20
+ return [minData, maxData];
21
+ }
22
+ return [Math.min(minChartTypeData, minData), Math.max(maxChartTypeData, maxData)];
23
+ };
24
+ const getAxisExtremum = (axis, getters, isDefaultAxis, formattedSeries) => {
25
+ const charTypes = Object.keys(getters);
26
+ return charTypes.reduce((acc, charType) => axisExtremumCallback(acc, charType, axis, getters, isDefaultAxis, formattedSeries), [null, null]);
27
+ };
28
+ exports.getAxisExtremum = getAxisExtremum;
@@ -0,0 +1,9 @@
1
+ import { computeValue } from './computeValue';
2
+ export * from './CartesianProvider';
3
+ export * from './CartesianContext';
4
+ export * from './useCartesianContext';
5
+ declare const cartesianProviderUtils: {
6
+ computeValue: typeof computeValue;
7
+ normalizeAxis: <T extends import("../../internals").ChartsAxisProps, R extends import("../../internals").MakeOptional<import("../..").AxisConfig<import("../..").ScaleName, any, T>, "id">>(axis: R[] | undefined, dataset: import("../../internals").DatasetType | undefined, axisName: "x" | "y") => R[] | undefined;
8
+ };
9
+ export { cartesianProviderUtils };
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _exportNames = {
7
+ cartesianProviderUtils: true
8
+ };
9
+ exports.cartesianProviderUtils = void 0;
10
+ var _computeValue = require("./computeValue");
11
+ var _normalizeAxis = require("./normalizeAxis");
12
+ var _CartesianProvider = require("./CartesianProvider");
13
+ Object.keys(_CartesianProvider).forEach(function (key) {
14
+ if (key === "default" || key === "__esModule") return;
15
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
16
+ if (key in exports && exports[key] === _CartesianProvider[key]) return;
17
+ Object.defineProperty(exports, key, {
18
+ enumerable: true,
19
+ get: function () {
20
+ return _CartesianProvider[key];
21
+ }
22
+ });
23
+ });
24
+ var _CartesianContext = require("./CartesianContext");
25
+ Object.keys(_CartesianContext).forEach(function (key) {
26
+ if (key === "default" || key === "__esModule") return;
27
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
28
+ if (key in exports && exports[key] === _CartesianContext[key]) return;
29
+ Object.defineProperty(exports, key, {
30
+ enumerable: true,
31
+ get: function () {
32
+ return _CartesianContext[key];
33
+ }
34
+ });
35
+ });
36
+ var _useCartesianContext = require("./useCartesianContext");
37
+ Object.keys(_useCartesianContext).forEach(function (key) {
38
+ if (key === "default" || key === "__esModule") return;
39
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
40
+ if (key in exports && exports[key] === _useCartesianContext[key]) return;
41
+ Object.defineProperty(exports, key, {
42
+ enumerable: true,
43
+ get: function () {
44
+ return _useCartesianContext[key];
45
+ }
46
+ });
47
+ });
48
+ const cartesianProviderUtils = exports.cartesianProviderUtils = {
49
+ computeValue: _computeValue.computeValue,
50
+ normalizeAxis: _normalizeAxis.normalizeAxis
51
+ };
@@ -0,0 +1,5 @@
1
+ import type { AxisConfig, ScaleName } from '../../models';
2
+ import { ChartsAxisProps } from '../../models/axis';
3
+ import { MakeOptional } from '../../models/helpers';
4
+ import { DatasetType } from '../../models/seriesType/config';
5
+ export declare const normalizeAxis: <T extends ChartsAxisProps, R extends MakeOptional<AxisConfig<ScaleName, any, T>, "id">>(axis: R[] | undefined, dataset: DatasetType | undefined, axisName: 'x' | 'y') => R[] | undefined;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.normalizeAxis = void 0;
8
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
+ const normalizeAxis = (axis, dataset, axisName) => {
10
+ return axis?.map(axisConfig => {
11
+ const dataKey = axisConfig.dataKey;
12
+ if (dataKey === undefined || axisConfig.data !== undefined) {
13
+ return axisConfig;
14
+ }
15
+ if (dataset === undefined) {
16
+ throw Error(`MUI X Charts: ${axisName}-axis uses \`dataKey\` but no \`dataset\` is provided.`);
17
+ }
18
+ return (0, _extends2.default)({}, axisConfig, {
19
+ data: dataset.map(d => d[dataKey])
20
+ });
21
+ });
22
+ };
23
+ exports.normalizeAxis = normalizeAxis;
@@ -0,0 +1,2 @@
1
+ import { CartesianContextState } from './CartesianContext';
2
+ export declare const useCartesianContext: () => CartesianContextState;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useCartesianContext = void 0;
7
+ var React = _interopRequireWildcard(require("react"));
8
+ var _CartesianContext = require("./CartesianContext");
9
+ 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); }
10
+ 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; }
11
+ const useCartesianContext = () => {
12
+ const {
13
+ data
14
+ } = React.useContext(_CartesianContext.CartesianContext);
15
+ return data;
16
+ };
17
+ exports.useCartesianContext = useCartesianContext;
@@ -1,6 +1,6 @@
1
1
  import * as React from 'react';
2
2
  import { ColorProcessorsConfig } from '../models';
3
- import { ChartSeriesType } from '../internals';
3
+ import { ChartSeriesType } from '../models/seriesType/config';
4
4
  export interface ColorProviderProps {
5
5
  children: React.ReactNode;
6
6
  /**
@@ -8,5 +8,5 @@ export interface ColorProviderProps {
8
8
  */
9
9
  colorProcessors: ColorProcessorsConfig<ChartSeriesType>;
10
10
  }
11
- export declare const ColorContext: React.Context<ColorProcessorsConfig<keyof import("../internals").ChartsSeriesConfig>>;
11
+ export declare const ColorContext: React.Context<ColorProcessorsConfig<keyof import("../models/seriesType/config").ChartsSeriesConfig>>;
12
12
  export declare function ColorProvider(props: ColorProviderProps): React.JSX.Element;
@@ -1,11 +1,9 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import * as React from 'react';
3
- import useId from '@mui/utils/useId';
4
3
  import PropTypes from 'prop-types';
5
4
  import { BarPlot } from './BarPlot';
6
5
  import { ResponsiveChartContainer } from '../ResponsiveChartContainer';
7
6
  import { ChartsAxis } from '../ChartsAxis';
8
- import { DEFAULT_X_AXIS_KEY, DEFAULT_Y_AXIS_KEY } from '../constants';
9
7
  import { ChartsTooltip } from '../ChartsTooltip';
10
8
  import { ChartsLegend } from '../ChartsLegend';
11
9
  import { ChartsAxisHighlight } from '../ChartsAxisHighlight';
@@ -13,6 +11,7 @@ import { ChartsClipPath } from '../ChartsClipPath';
13
11
  import { ChartsGrid } from '../ChartsGrid';
14
12
  import { ChartsOnAxisClickHandler } from '../ChartsOnAxisClickHandler';
15
13
  import { ChartsOverlay } from '../ChartsOverlay/ChartsOverlay';
14
+ import { useBarChartProps } from './useBarChartProps';
16
15
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
17
16
  /**
18
17
  * Demos:
@@ -27,108 +26,26 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
27
26
  */
28
27
  const BarChart = /*#__PURE__*/React.forwardRef(function BarChart(props, ref) {
29
28
  const {
30
- xAxis,
31
- yAxis,
32
- series,
33
- width,
34
- height,
35
- margin,
36
- colors,
37
- dataset,
38
- sx,
39
- layout,
40
- tooltip,
41
- axisHighlight,
42
- legend,
43
- grid,
44
- topAxis,
45
- leftAxis,
46
- rightAxis,
47
- bottomAxis,
48
- skipAnimation,
49
- borderRadius,
50
- onItemClick,
51
- onAxisClick,
52
- children,
53
- slots,
54
- slotProps,
55
- loading,
56
- barLabel,
57
- highlightedItem,
58
- onHighlightChange
59
- } = props;
60
- const id = useId();
61
- const clipPathId = `${id}-clip-path`;
62
- const hasHorizontalSeries = layout === 'horizontal' || layout === undefined && series.some(item => item.layout === 'horizontal');
63
- const defaultAxisConfig = {
64
- scaleType: 'band',
65
- data: Array.from({
66
- length: Math.max(...series.map(s => (s.data ?? dataset ?? []).length))
67
- }, (_, index) => index)
68
- };
69
- const defaultizedAxisHighlight = _extends({}, hasHorizontalSeries ? {
70
- y: 'band'
71
- } : {
72
- x: 'band'
73
- }, axisHighlight);
74
- return /*#__PURE__*/_jsxs(ResponsiveChartContainer, {
75
- ref: ref,
76
- series: series.map(s => _extends({
77
- type: 'bar'
78
- }, s, {
79
- layout: hasHorizontalSeries ? 'horizontal' : 'vertical'
80
- })),
81
- width: width,
82
- height: height,
83
- margin: margin,
84
- xAxis: xAxis ?? (hasHorizontalSeries ? undefined : [_extends({
85
- id: DEFAULT_X_AXIS_KEY
86
- }, defaultAxisConfig)]),
87
- yAxis: yAxis ?? (hasHorizontalSeries ? [_extends({
88
- id: DEFAULT_Y_AXIS_KEY
89
- }, defaultAxisConfig)] : undefined),
90
- colors: colors,
91
- dataset: dataset,
92
- sx: sx,
93
- disableAxisListener: tooltip?.trigger !== 'axis' && axisHighlight?.x === 'none' && axisHighlight?.y === 'none' && !onAxisClick,
94
- highlightedItem: highlightedItem,
95
- onHighlightChange: onHighlightChange,
96
- children: [onAxisClick && /*#__PURE__*/_jsx(ChartsOnAxisClickHandler, {
97
- onAxisClick: onAxisClick
98
- }), grid && /*#__PURE__*/_jsx(ChartsGrid, {
99
- vertical: grid.vertical,
100
- horizontal: grid.horizontal
101
- }), /*#__PURE__*/_jsxs("g", {
102
- clipPath: `url(#${clipPathId})`,
103
- children: [/*#__PURE__*/_jsx(BarPlot, {
104
- slots: slots,
105
- slotProps: slotProps,
106
- skipAnimation: skipAnimation,
107
- onItemClick: onItemClick,
108
- borderRadius: borderRadius,
109
- barLabel: barLabel
110
- }), /*#__PURE__*/_jsx(ChartsOverlay, {
111
- loading: loading,
112
- slots: slots,
113
- slotProps: slotProps
114
- })]
115
- }), /*#__PURE__*/_jsx(ChartsAxis, {
116
- topAxis: topAxis,
117
- leftAxis: leftAxis,
118
- rightAxis: rightAxis,
119
- bottomAxis: bottomAxis,
120
- slots: slots,
121
- slotProps: slotProps
122
- }), /*#__PURE__*/_jsx(ChartsLegend, _extends({}, legend, {
123
- slots: slots,
124
- slotProps: slotProps
125
- })), /*#__PURE__*/_jsx(ChartsAxisHighlight, _extends({}, defaultizedAxisHighlight)), !loading && /*#__PURE__*/_jsx(ChartsTooltip, _extends({}, tooltip, {
126
- slots: slots,
127
- slotProps: slotProps
128
- })), /*#__PURE__*/_jsx(ChartsClipPath, {
129
- id: clipPathId
130
- }), children]
131
- });
29
+ chartContainerProps,
30
+ barPlotProps,
31
+ axisClickHandlerProps,
32
+ gridProps,
33
+ clipPathProps,
34
+ clipPathGroupProps,
35
+ overlayProps,
36
+ chartsAxisProps,
37
+ axisHighlightProps,
38
+ legendProps,
39
+ tooltipProps,
40
+ children
41
+ } = useBarChartProps(props);
42
+ return /*#__PURE__*/_jsxs(ResponsiveChartContainer, _extends({
43
+ ref: ref
44
+ }, chartContainerProps, {
45
+ children: [props.onAxisClick && /*#__PURE__*/_jsx(ChartsOnAxisClickHandler, _extends({}, axisClickHandlerProps)), props.grid && /*#__PURE__*/_jsx(ChartsGrid, _extends({}, gridProps)), /*#__PURE__*/_jsxs("g", _extends({}, clipPathGroupProps, {
46
+ children: [/*#__PURE__*/_jsx(BarPlot, _extends({}, barPlotProps)), /*#__PURE__*/_jsx(ChartsOverlay, _extends({}, overlayProps))]
47
+ })), /*#__PURE__*/_jsx(ChartsAxis, _extends({}, chartsAxisProps)), /*#__PURE__*/_jsx(ChartsLegend, _extends({}, legendProps)), /*#__PURE__*/_jsx(ChartsAxisHighlight, _extends({}, axisHighlightProps)), !props.loading && /*#__PURE__*/_jsx(ChartsTooltip, _extends({}, tooltipProps)), /*#__PURE__*/_jsx(ChartsClipPath, _extends({}, clipPathProps)), children]
48
+ }));
132
49
  });
133
50
  process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
134
51
  // ----------------------------- Warning --------------------------------
@@ -2,7 +2,6 @@ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWith
2
2
  import _extends from "@babel/runtime/helpers/esm/extends";
3
3
  const _excluded = ["bars", "skipAnimation"];
4
4
  import * as React from 'react';
5
- import PropTypes from 'prop-types';
6
5
  import { useTransition } from '@react-spring/web';
7
6
  import { BarLabelItem } from './BarLabelItem';
8
7
  import { jsx as _jsx } from "react/jsx-runtime";
@@ -73,26 +72,4 @@ function BarLabelPlot(props) {
73
72
  })))
74
73
  });
75
74
  }
76
- process.env.NODE_ENV !== "production" ? BarLabelPlot.propTypes = {
77
- // ----------------------------- Warning --------------------------------
78
- // | These PropTypes are generated from the TypeScript type definitions |
79
- // | To update them edit the TypeScript types and run "pnpm proptypes" |
80
- // ----------------------------------------------------------------------
81
- barLabel: PropTypes.oneOfType([PropTypes.oneOf(['value']), PropTypes.func]),
82
- bars: PropTypes.arrayOf(PropTypes.shape({
83
- color: PropTypes.string.isRequired,
84
- dataIndex: PropTypes.number.isRequired,
85
- height: PropTypes.number.isRequired,
86
- layout: PropTypes.oneOf(['horizontal', 'vertical']),
87
- maskId: PropTypes.string.isRequired,
88
- seriesId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
89
- value: PropTypes.number,
90
- width: PropTypes.number.isRequired,
91
- x: PropTypes.number.isRequired,
92
- xOrigin: PropTypes.number.isRequired,
93
- y: PropTypes.number.isRequired,
94
- yOrigin: PropTypes.number.isRequired
95
- })).isRequired,
96
- skipAnimation: PropTypes.bool
97
- } : void 0;
98
75
  export { BarLabelPlot };
@@ -4,7 +4,7 @@ const _excluded = ["skipAnimation", "onItemClick", "borderRadius", "barLabel"];
4
4
  import * as React from 'react';
5
5
  import PropTypes from 'prop-types';
6
6
  import { useTransition } from '@react-spring/web';
7
- import { CartesianContext } from '../context/CartesianContextProvider';
7
+ import { useCartesianContext } from '../context/CartesianProvider';
8
8
  import { BarElement } from './BarElement';
9
9
  import getColor from './getColor';
10
10
  import { useChartId } from '../hooks';
@@ -47,7 +47,7 @@ const useAggregatedData = () => {
47
47
  stackingGroups: [],
48
48
  seriesOrder: []
49
49
  };
50
- const axisData = React.useContext(CartesianContext);
50
+ const axisData = useCartesianContext();
51
51
  const chartId = useChartId();
52
52
  const {
53
53
  series,
@@ -0,0 +1,136 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import useId from '@mui/utils/useId';
3
+ import { DEFAULT_X_AXIS_KEY, DEFAULT_Y_AXIS_KEY } from '../constants';
4
+
5
+ /**
6
+ * A helper function that extracts BarChartProps from the input props
7
+ * and returns an object with props for the children components of BarChart.
8
+ *
9
+ * @param props The input props for BarChart
10
+ * @returns An object with props for the children components of BarChart
11
+ */
12
+ export const useBarChartProps = props => {
13
+ const {
14
+ xAxis,
15
+ yAxis,
16
+ series,
17
+ width,
18
+ height,
19
+ margin,
20
+ colors,
21
+ dataset,
22
+ sx,
23
+ tooltip,
24
+ onAxisClick,
25
+ axisHighlight,
26
+ legend,
27
+ grid,
28
+ topAxis,
29
+ leftAxis,
30
+ rightAxis,
31
+ bottomAxis,
32
+ children,
33
+ slots,
34
+ slotProps,
35
+ skipAnimation,
36
+ loading,
37
+ layout,
38
+ onItemClick,
39
+ highlightedItem,
40
+ onHighlightChange,
41
+ borderRadius,
42
+ barLabel
43
+ } = props;
44
+ const id = useId();
45
+ const clipPathId = `${id}-clip-path`;
46
+ const hasHorizontalSeries = layout === 'horizontal' || layout === undefined && series.some(item => item.layout === 'horizontal');
47
+ const defaultAxisConfig = {
48
+ scaleType: 'band',
49
+ data: Array.from({
50
+ length: Math.max(...series.map(s => (s.data ?? dataset ?? []).length))
51
+ }, (_, index) => index)
52
+ };
53
+ const chartContainerProps = {
54
+ series: series.map(s => _extends({
55
+ type: 'bar'
56
+ }, s, {
57
+ layout: hasHorizontalSeries ? 'horizontal' : 'vertical'
58
+ })),
59
+ width,
60
+ height,
61
+ margin,
62
+ colors,
63
+ dataset,
64
+ xAxis: xAxis ?? (hasHorizontalSeries ? undefined : [_extends({
65
+ id: DEFAULT_X_AXIS_KEY
66
+ }, defaultAxisConfig)]),
67
+ yAxis: yAxis ?? (hasHorizontalSeries ? [_extends({
68
+ id: DEFAULT_Y_AXIS_KEY
69
+ }, defaultAxisConfig)] : undefined),
70
+ sx,
71
+ highlightedItem,
72
+ onHighlightChange,
73
+ disableAxisListener: tooltip?.trigger !== 'axis' && axisHighlight?.x === 'none' && axisHighlight?.y === 'none' && !onAxisClick
74
+ };
75
+ const barPlotProps = {
76
+ onItemClick,
77
+ slots,
78
+ slotProps,
79
+ skipAnimation,
80
+ borderRadius,
81
+ barLabel
82
+ };
83
+ const axisClickHandlerProps = {
84
+ onAxisClick
85
+ };
86
+ const gridProps = {
87
+ vertical: grid?.vertical,
88
+ horizontal: grid?.horizontal
89
+ };
90
+ const clipPathGroupProps = {
91
+ clipPath: `url(#${clipPathId})`
92
+ };
93
+ const clipPathProps = {
94
+ id: clipPathId
95
+ };
96
+ const overlayProps = {
97
+ slots,
98
+ slotProps,
99
+ loading
100
+ };
101
+ const chartsAxisProps = {
102
+ topAxis,
103
+ leftAxis,
104
+ rightAxis,
105
+ bottomAxis,
106
+ slots,
107
+ slotProps
108
+ };
109
+ const axisHighlightProps = _extends({}, hasHorizontalSeries ? {
110
+ y: 'band'
111
+ } : {
112
+ x: 'band'
113
+ }, axisHighlight);
114
+ const legendProps = _extends({}, legend, {
115
+ slots,
116
+ slotProps
117
+ });
118
+ const tooltipProps = _extends({}, tooltip, {
119
+ slots,
120
+ slotProps
121
+ });
122
+ return {
123
+ chartContainerProps,
124
+ barPlotProps,
125
+ axisClickHandlerProps,
126
+ gridProps,
127
+ clipPathProps,
128
+ clipPathGroupProps,
129
+ overlayProps,
130
+ chartsAxisProps,
131
+ axisHighlightProps,
132
+ legendProps,
133
+ tooltipProps,
134
+ children
135
+ };
136
+ };
@@ -1,16 +1,14 @@
1
1
  import * as React from 'react';
2
2
  import PropTypes from 'prop-types';
3
- import useForkRef from '@mui/utils/useForkRef';
4
3
  import { DrawingProvider } from '../context/DrawingProvider';
5
4
  import { SeriesContextProvider } from '../context/SeriesContextProvider';
6
5
  import { InteractionProvider } from '../context/InteractionProvider';
7
6
  import { ColorProvider } from '../context/ColorProvider';
8
- import { useReducedMotion } from '../hooks/useReducedMotion';
9
7
  import { ChartsSurface } from '../ChartsSurface';
10
- import { CartesianContextProvider } from '../context/CartesianContextProvider';
8
+ import { CartesianContextProvider } from '../context/CartesianProvider';
11
9
  import { ChartsAxesGradients } from '../internals/components/ChartsAxesGradients';
12
10
  import { HighlightedProvider, ZAxisContextProvider } from '../context';
13
- import { usePluginsMerge } from './usePluginsMerge';
11
+ import { useChartContainerHooks } from './useChartContainerHooks';
14
12
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
15
13
  const ChartContainer = /*#__PURE__*/React.forwardRef(function ChartContainer(props, ref) {
16
14
  const {
@@ -32,16 +30,14 @@ const ChartContainer = /*#__PURE__*/React.forwardRef(function ChartContainer(pro
32
30
  plugins,
33
31
  children
34
32
  } = props;
35
- const svgRef = React.useRef(null);
36
- const handleRef = useForkRef(ref, svgRef);
37
33
  const {
34
+ svgRef,
35
+ handleRef,
38
36
  xExtremumGetters,
39
37
  yExtremumGetters,
40
38
  seriesFormatters,
41
39
  colorProcessors
42
- } = usePluginsMerge(plugins);
43
- useReducedMotion(); // a11y reduce motion (see: https://react-spring.dev/docs/utilities/use-reduced-motion)
44
-
40
+ } = useChartContainerHooks(ref, plugins);
45
41
  return /*#__PURE__*/_jsx(DrawingProvider, {
46
42
  width: width,
47
43
  height: height,
@@ -0,0 +1,24 @@
1
+ import useForkRef from '@mui/utils/useForkRef';
2
+ import * as React from 'react';
3
+ import { usePluginsMerge } from './usePluginsMerge';
4
+ import { useReducedMotion } from '../hooks/useReducedMotion';
5
+ export const useChartContainerHooks = (ref, plugins) => {
6
+ const svgRef = React.useRef(null);
7
+ const handleRef = useForkRef(ref, svgRef);
8
+ const {
9
+ xExtremumGetters,
10
+ yExtremumGetters,
11
+ seriesFormatters,
12
+ colorProcessors
13
+ } = usePluginsMerge(plugins);
14
+ useReducedMotion(); // a11y reduce motion (see: https://react-spring.dev/docs/utilities/use-reduced-motion)
15
+
16
+ return {
17
+ svgRef,
18
+ handleRef,
19
+ xExtremumGetters,
20
+ yExtremumGetters,
21
+ seriesFormatters,
22
+ colorProcessors
23
+ };
24
+ };