@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.
- package/BarChart/BarChart.js +21 -104
- package/BarChart/BarLabel/BarLabelPlot.d.ts +0 -3
- package/BarChart/BarLabel/BarLabelPlot.js +1 -24
- package/BarChart/BarPlot.js +2 -2
- package/BarChart/checkScaleErrors.d.ts +5 -9
- package/BarChart/types.d.ts +2 -2
- package/BarChart/useBarChartProps.d.ts +102 -0
- package/BarChart/useBarChartProps.js +143 -0
- package/CHANGELOG.md +82 -0
- package/ChartContainer/ChartContainer.d.ts +1 -1
- package/ChartContainer/ChartContainer.js +6 -10
- package/ChartContainer/useChartContainerHooks.d.ts +11 -0
- package/ChartContainer/useChartContainerHooks.js +34 -0
- package/ChartContainer/usePluginsMerge.d.ts +1 -2
- package/ChartsAxis/ChartsAxis.js +2 -2
- package/ChartsAxisHighlight/ChartsAxisHighlight.js +2 -2
- package/ChartsGrid/ChartsGrid.js +2 -2
- package/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +2 -2
- package/ChartsTooltip/ChartsAxisTooltipContent.js +2 -2
- package/ChartsTooltip/ChartsItemTooltipContent.js +2 -2
- package/ChartsVoronoiHandler/ChartsVoronoiHandler.js +2 -2
- package/ChartsXAxis/ChartsXAxis.js +2 -2
- package/ChartsYAxis/ChartsYAxis.js +2 -2
- package/LineChart/AreaPlot.js +2 -2
- package/LineChart/LineChart.js +24 -106
- package/LineChart/LineHighlightPlot.js +2 -2
- package/LineChart/LinePlot.js +2 -2
- package/LineChart/MarkPlot.js +2 -2
- package/LineChart/useLineChartProps.d.ts +117 -0
- package/LineChart/useLineChartProps.js +152 -0
- package/ScatterChart/ScatterChart.js +20 -75
- package/ScatterChart/ScatterPlot.js +2 -2
- package/ScatterChart/useScatterChartProps.d.ts +86 -0
- package/ScatterChart/useScatterChartProps.js +116 -0
- package/context/CartesianProvider/CartesianContext.d.ts +25 -0
- package/context/CartesianProvider/CartesianContext.js +21 -0
- package/context/CartesianProvider/CartesianProvider.d.ts +34 -0
- package/context/CartesianProvider/CartesianProvider.js +44 -0
- package/context/CartesianProvider/computeValue.d.ts +19 -0
- package/context/CartesianProvider/computeValue.js +89 -0
- package/context/CartesianProvider/getAxisExtremum.d.ts +4 -0
- package/context/CartesianProvider/getAxisExtremum.js +28 -0
- package/context/CartesianProvider/index.d.ts +9 -0
- package/context/CartesianProvider/index.js +51 -0
- package/context/CartesianProvider/normalizeAxis.d.ts +5 -0
- package/context/CartesianProvider/normalizeAxis.js +23 -0
- package/context/CartesianProvider/useCartesianContext.d.ts +2 -0
- package/context/CartesianProvider/useCartesianContext.js +17 -0
- package/context/ColorProvider.d.ts +2 -2
- package/esm/BarChart/BarChart.js +21 -104
- package/esm/BarChart/BarLabel/BarLabelPlot.js +0 -23
- package/esm/BarChart/BarPlot.js +2 -2
- package/esm/BarChart/useBarChartProps.js +136 -0
- package/esm/ChartContainer/ChartContainer.js +5 -9
- package/esm/ChartContainer/useChartContainerHooks.js +24 -0
- package/esm/ChartsAxis/ChartsAxis.js +2 -2
- package/esm/ChartsAxisHighlight/ChartsAxisHighlight.js +2 -2
- package/esm/ChartsGrid/ChartsGrid.js +2 -2
- package/esm/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +2 -2
- package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +2 -2
- package/esm/ChartsTooltip/ChartsItemTooltipContent.js +2 -2
- package/esm/ChartsVoronoiHandler/ChartsVoronoiHandler.js +2 -2
- package/esm/ChartsXAxis/ChartsXAxis.js +2 -2
- package/esm/ChartsYAxis/ChartsYAxis.js +2 -2
- package/esm/LineChart/AreaPlot.js +2 -2
- package/esm/LineChart/LineChart.js +24 -106
- package/esm/LineChart/LineHighlightPlot.js +2 -2
- package/esm/LineChart/LinePlot.js +2 -2
- package/esm/LineChart/MarkPlot.js +2 -2
- package/esm/LineChart/useLineChartProps.js +144 -0
- package/esm/ScatterChart/ScatterChart.js +20 -75
- package/esm/ScatterChart/ScatterPlot.js +2 -2
- package/esm/ScatterChart/useScatterChartProps.js +108 -0
- package/esm/context/CartesianProvider/CartesianContext.js +13 -0
- package/esm/context/CartesianProvider/CartesianProvider.js +37 -0
- package/esm/context/CartesianProvider/computeValue.js +82 -0
- package/esm/context/CartesianProvider/getAxisExtremum.js +21 -0
- package/esm/context/CartesianProvider/index.js +10 -0
- package/esm/context/CartesianProvider/normalizeAxis.js +15 -0
- package/esm/context/CartesianProvider/useCartesianContext.js +8 -0
- package/esm/hooks/useAxisEvents.js +2 -2
- package/esm/hooks/useColorScale.js +3 -3
- package/esm/hooks/useScale.js +3 -4
- package/esm/internals/components/ChartsAxesGradients/ChartsAxesGradients.js +2 -2
- package/esm/internals/index.js +6 -2
- package/hooks/useAxisEvents.js +2 -2
- package/hooks/useColorScale.js +3 -3
- package/hooks/useDrawingArea.d.ts +2 -8
- package/hooks/useScale.js +3 -6
- package/index.js +1 -1
- package/internals/components/ChartsAxesGradients/ChartsAxesGradients.d.ts +2 -1
- package/internals/components/ChartsAxesGradients/ChartsAxesGradients.js +2 -2
- package/internals/index.d.ts +7 -1
- package/internals/index.js +49 -5
- package/models/plugin.d.ts +4 -1
- package/modern/BarChart/BarChart.js +21 -104
- package/modern/BarChart/BarLabel/BarLabelPlot.js +0 -23
- package/modern/BarChart/BarPlot.js +2 -2
- package/modern/BarChart/useBarChartProps.js +136 -0
- package/modern/ChartContainer/ChartContainer.js +5 -9
- package/modern/ChartContainer/useChartContainerHooks.js +24 -0
- package/modern/ChartsAxis/ChartsAxis.js +2 -2
- package/modern/ChartsAxisHighlight/ChartsAxisHighlight.js +2 -2
- package/modern/ChartsGrid/ChartsGrid.js +2 -2
- package/modern/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +2 -2
- package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +2 -2
- package/modern/ChartsTooltip/ChartsItemTooltipContent.js +2 -2
- package/modern/ChartsVoronoiHandler/ChartsVoronoiHandler.js +2 -2
- package/modern/ChartsXAxis/ChartsXAxis.js +2 -2
- package/modern/ChartsYAxis/ChartsYAxis.js +2 -2
- package/modern/LineChart/AreaPlot.js +2 -2
- package/modern/LineChart/LineChart.js +24 -106
- package/modern/LineChart/LineHighlightPlot.js +2 -2
- package/modern/LineChart/LinePlot.js +2 -2
- package/modern/LineChart/MarkPlot.js +2 -2
- package/modern/LineChart/useLineChartProps.js +144 -0
- package/modern/ScatterChart/ScatterChart.js +20 -75
- package/modern/ScatterChart/ScatterPlot.js +2 -2
- package/modern/ScatterChart/useScatterChartProps.js +108 -0
- package/modern/context/CartesianProvider/CartesianContext.js +13 -0
- package/modern/context/CartesianProvider/CartesianProvider.js +37 -0
- package/modern/context/CartesianProvider/computeValue.js +82 -0
- package/modern/context/CartesianProvider/getAxisExtremum.js +21 -0
- package/modern/context/CartesianProvider/index.js +10 -0
- package/modern/context/CartesianProvider/normalizeAxis.js +15 -0
- package/modern/context/CartesianProvider/useCartesianContext.js +8 -0
- package/modern/hooks/useAxisEvents.js +2 -2
- package/modern/hooks/useColorScale.js +3 -3
- package/modern/hooks/useScale.js +3 -4
- package/modern/index.js +1 -1
- package/modern/internals/components/ChartsAxesGradients/ChartsAxesGradients.js +2 -2
- package/modern/internals/index.js +6 -2
- package/package.json +3 -3
- package/context/CartesianContextProvider.d.ts +0 -61
- package/context/CartesianContextProvider.js +0 -220
- package/esm/context/CartesianContextProvider.js +0 -211
- package/modern/context/CartesianContextProvider.js +0 -211
package/models/plugin.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ChartSeriesType, ExtremumGetter, Formatter } from './seriesType/config';
|
|
1
|
+
import { CartesianChartSeriesType, ChartSeriesType, ExtremumGetter, Formatter } from './seriesType/config';
|
|
2
2
|
import { AxisDefaultized } from './axis';
|
|
3
3
|
import { DefaultizedSeriesType } from './seriesType';
|
|
4
4
|
import { ZAxisDefaultized } from './z-axis';
|
|
@@ -13,4 +13,7 @@ export type ChartsPluginType<T> = T extends ChartSeriesType ? {
|
|
|
13
13
|
xExtremumGetter?: ExtremumGetter<T>;
|
|
14
14
|
yExtremumGetter?: ExtremumGetter<T>;
|
|
15
15
|
} : never;
|
|
16
|
+
export type ExtremumGettersConfig<T extends ChartSeriesType = CartesianChartSeriesType> = {
|
|
17
|
+
[K in T]?: ExtremumGetter<K>;
|
|
18
|
+
};
|
|
16
19
|
export {};
|
|
@@ -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
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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 {
|
|
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 =
|
|
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/
|
|
8
|
+
import { CartesianContextProvider } from '../context/CartesianProvider';
|
|
11
9
|
import { ChartsAxesGradients } from '../internals/components/ChartsAxesGradients';
|
|
12
10
|
import { HighlightedProvider, ZAxisContextProvider } from '../context';
|
|
13
|
-
import {
|
|
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
|
-
} =
|
|
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
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import PropTypes from 'prop-types';
|
|
4
|
-
import {
|
|
4
|
+
import { useCartesianContext } from '../context/CartesianProvider';
|
|
5
5
|
import { ChartsXAxis } from '../ChartsXAxis';
|
|
6
6
|
import { ChartsYAxis } from '../ChartsYAxis';
|
|
7
7
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
@@ -47,7 +47,7 @@ function ChartsAxis(props) {
|
|
|
47
47
|
xAxisIds,
|
|
48
48
|
yAxis,
|
|
49
49
|
yAxisIds
|
|
50
|
-
} =
|
|
50
|
+
} = useCartesianContext();
|
|
51
51
|
|
|
52
52
|
// TODO: use for plotting line without ticks or any thing
|
|
53
53
|
// const drawingArea = React.useContext(DrawingContext);
|
|
@@ -6,7 +6,7 @@ import generateUtilityClass from '@mui/utils/generateUtilityClass';
|
|
|
6
6
|
import generateUtilityClasses from '@mui/utils/generateUtilityClasses';
|
|
7
7
|
import { styled } from '@mui/material/styles';
|
|
8
8
|
import { InteractionContext } from '../context/InteractionProvider';
|
|
9
|
-
import {
|
|
9
|
+
import { useCartesianContext } from '../context/CartesianProvider';
|
|
10
10
|
import { getValueToPositionMapper } from '../hooks/useScale';
|
|
11
11
|
import { isBandScale } from '../internals/isBandScale';
|
|
12
12
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
@@ -55,7 +55,7 @@ function ChartsAxisHighlight(props) {
|
|
|
55
55
|
xAxis,
|
|
56
56
|
yAxisIds,
|
|
57
57
|
yAxis
|
|
58
|
-
} =
|
|
58
|
+
} = useCartesianContext();
|
|
59
59
|
const classes = useUtilityClasses();
|
|
60
60
|
const USED_X_AXIS_ID = xAxisIds[0];
|
|
61
61
|
const USED_Y_AXIS_ID = yAxisIds[0];
|
|
@@ -5,7 +5,7 @@ import * as React from 'react';
|
|
|
5
5
|
import PropTypes from 'prop-types';
|
|
6
6
|
import composeClasses from '@mui/utils/composeClasses';
|
|
7
7
|
import { styled, useThemeProps } from '@mui/material/styles';
|
|
8
|
-
import {
|
|
8
|
+
import { useCartesianContext } from '../context/CartesianProvider';
|
|
9
9
|
import { useTicks } from '../hooks/useTicks';
|
|
10
10
|
import { getChartsGridUtilityClass, chartsGridClasses } from './chartsGridClasses';
|
|
11
11
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
@@ -63,7 +63,7 @@ function ChartsGrid(props) {
|
|
|
63
63
|
xAxisIds,
|
|
64
64
|
yAxis,
|
|
65
65
|
yAxisIds
|
|
66
|
-
} =
|
|
66
|
+
} = useCartesianContext();
|
|
67
67
|
const classes = useUtilityClasses(themeProps);
|
|
68
68
|
const horizontalAxisId = yAxisIds[0];
|
|
69
69
|
const verticalAxisId = xAxisIds[0];
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
3
|
import { InteractionContext } from '../context/InteractionProvider';
|
|
4
|
-
import { CartesianContext } from '../context/CartesianContextProvider';
|
|
5
4
|
import { useSeries } from '../hooks/useSeries';
|
|
6
5
|
import { useSvgRef } from '../hooks';
|
|
6
|
+
import { useCartesianContext } from '../context/CartesianProvider';
|
|
7
7
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
8
|
function ChartsOnAxisClickHandler(props) {
|
|
9
9
|
const {
|
|
@@ -19,7 +19,7 @@ function ChartsOnAxisClickHandler(props) {
|
|
|
19
19
|
xAxis,
|
|
20
20
|
yAxisIds,
|
|
21
21
|
yAxis
|
|
22
|
-
} =
|
|
22
|
+
} = useCartesianContext();
|
|
23
23
|
React.useEffect(() => {
|
|
24
24
|
const element = svgRef.current;
|
|
25
25
|
if (element === null || !onAxisClick) {
|
|
@@ -2,7 +2,7 @@ import _extends from "@babel/runtime/helpers/esm/extends";
|
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import PropTypes from 'prop-types';
|
|
4
4
|
import { useSlotProps } from '@mui/base/utils';
|
|
5
|
-
import {
|
|
5
|
+
import { useCartesianContext } from '../context/CartesianProvider';
|
|
6
6
|
import { DefaultChartsAxisTooltipContent } from './DefaultChartsAxisTooltipContent';
|
|
7
7
|
import { ZAxisContext } from '../context/ZAxisContextProvider';
|
|
8
8
|
import { useColorProcessor } from '../hooks/useColor';
|
|
@@ -25,7 +25,7 @@ function ChartsAxisTooltipContent(props) {
|
|
|
25
25
|
xAxis,
|
|
26
26
|
yAxisIds,
|
|
27
27
|
yAxis
|
|
28
|
-
} =
|
|
28
|
+
} = useCartesianContext();
|
|
29
29
|
const {
|
|
30
30
|
zAxisIds,
|
|
31
31
|
zAxis
|
|
@@ -3,7 +3,7 @@ import * as React from 'react';
|
|
|
3
3
|
import PropTypes from 'prop-types';
|
|
4
4
|
import { useSlotProps } from '@mui/base/utils';
|
|
5
5
|
import { DefaultChartsItemTooltipContent } from './DefaultChartsItemTooltipContent';
|
|
6
|
-
import {
|
|
6
|
+
import { useCartesianContext } from '../context/CartesianProvider';
|
|
7
7
|
import { ZAxisContext } from '../context/ZAxisContextProvider';
|
|
8
8
|
import { useColorProcessor } from '../hooks/useColor';
|
|
9
9
|
import { useSeries } from '../hooks/useSeries';
|
|
@@ -22,7 +22,7 @@ function ChartsItemTooltipContent(props) {
|
|
|
22
22
|
yAxis,
|
|
23
23
|
xAxisIds,
|
|
24
24
|
yAxisIds
|
|
25
|
-
} =
|
|
25
|
+
} = useCartesianContext();
|
|
26
26
|
const {
|
|
27
27
|
zAxis,
|
|
28
28
|
zAxisIds
|
|
@@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
|
|
|
3
3
|
import { Delaunay } from 'd3-delaunay';
|
|
4
4
|
import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
|
|
5
5
|
import { InteractionContext } from '../context/InteractionProvider';
|
|
6
|
-
import {
|
|
6
|
+
import { useCartesianContext } from '../context/CartesianProvider';
|
|
7
7
|
import { getValueToPositionMapper } from '../hooks/useScale';
|
|
8
8
|
import { getSVGPoint } from '../internals/utils';
|
|
9
9
|
import { useDrawingArea, useSvgRef } from '../hooks';
|
|
@@ -27,7 +27,7 @@ function ChartsVoronoiHandler(props) {
|
|
|
27
27
|
yAxis,
|
|
28
28
|
xAxisIds,
|
|
29
29
|
yAxisIds
|
|
30
|
-
} =
|
|
30
|
+
} = useCartesianContext();
|
|
31
31
|
const {
|
|
32
32
|
dispatch
|
|
33
33
|
} = React.useContext(InteractionContext);
|
|
@@ -6,7 +6,7 @@ import PropTypes from 'prop-types';
|
|
|
6
6
|
import { useSlotProps } from '@mui/base/utils';
|
|
7
7
|
import { unstable_composeClasses as composeClasses } from '@mui/utils';
|
|
8
8
|
import { useThemeProps, useTheme } from '@mui/material/styles';
|
|
9
|
-
import {
|
|
9
|
+
import { useCartesianContext } from '../context/CartesianProvider';
|
|
10
10
|
import { useTicks } from '../hooks/useTicks';
|
|
11
11
|
import { getAxisUtilityClass } from '../ChartsAxis/axisClasses';
|
|
12
12
|
import { AxisRoot } from '../internals/components/AxisSharedComponents';
|
|
@@ -107,7 +107,7 @@ function ChartsXAxis(inProps) {
|
|
|
107
107
|
const {
|
|
108
108
|
xAxisIds,
|
|
109
109
|
xAxis
|
|
110
|
-
} =
|
|
110
|
+
} = useCartesianContext();
|
|
111
111
|
const _xAxis = xAxis[inProps.axisId ?? xAxisIds[0]],
|
|
112
112
|
{
|
|
113
113
|
scale: xScale,
|
|
@@ -6,7 +6,7 @@ import PropTypes from 'prop-types';
|
|
|
6
6
|
import { useSlotProps } from '@mui/base/utils';
|
|
7
7
|
import { unstable_composeClasses as composeClasses } from '@mui/utils';
|
|
8
8
|
import { useThemeProps, useTheme } from '@mui/material/styles';
|
|
9
|
-
import {
|
|
9
|
+
import { useCartesianContext } from '../context/CartesianProvider';
|
|
10
10
|
import { useTicks } from '../hooks/useTicks';
|
|
11
11
|
import { useDrawingArea } from '../hooks/useDrawingArea';
|
|
12
12
|
import { AxisRoot } from '../internals/components/AxisSharedComponents';
|
|
@@ -50,7 +50,7 @@ function ChartsYAxis(inProps) {
|
|
|
50
50
|
const {
|
|
51
51
|
yAxisIds,
|
|
52
52
|
yAxis
|
|
53
|
-
} =
|
|
53
|
+
} = useCartesianContext();
|
|
54
54
|
const _yAxis = yAxis[inProps.axisId ?? yAxisIds[0]],
|
|
55
55
|
{
|
|
56
56
|
scale: yScale,
|
|
@@ -4,7 +4,7 @@ const _excluded = ["slots", "slotProps", "onItemClick", "skipAnimation"];
|
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import PropTypes from 'prop-types';
|
|
6
6
|
import { area as d3Area } from 'd3-shape';
|
|
7
|
-
import {
|
|
7
|
+
import { useCartesianContext } from '../context/CartesianProvider';
|
|
8
8
|
import { AreaElement } from './AreaElement';
|
|
9
9
|
import { getValueToPositionMapper } from '../hooks/useScale';
|
|
10
10
|
import getCurveFactory from '../internals/getCurve';
|
|
@@ -14,7 +14,7 @@ import { useLineSeries } from '../hooks/useSeries';
|
|
|
14
14
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
15
15
|
const useAggregatedData = () => {
|
|
16
16
|
const seriesData = useLineSeries();
|
|
17
|
-
const axisData =
|
|
17
|
+
const axisData = useCartesianContext();
|
|
18
18
|
if (seriesData === undefined) {
|
|
19
19
|
return [];
|
|
20
20
|
}
|