@mui/x-charts 7.6.1 → 7.7.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.
- package/BarChart/BarChart.d.ts +1 -1
- package/BarChart/BarChart.js +2 -2
- package/BarChart/BarPlot.js +2 -2
- package/BarChart/formatter.js +2 -2
- package/BarChart/getColor.d.ts +1 -1
- package/BarChart/getColor.js +4 -4
- package/BarChart/plugin.d.ts +2 -0
- package/BarChart/plugin.js +17 -0
- package/CHANGELOG.md +147 -0
- package/ChartContainer/ChartContainer.d.ts +15 -3
- package/ChartContainer/ChartContainer.js +70 -22
- package/ChartContainer/defaultPlugins.d.ts +2 -0
- package/ChartContainer/defaultPlugins.js +11 -0
- package/ChartContainer/usePluginsMerge.d.ts +10 -0
- package/ChartContainer/usePluginsMerge.js +39 -0
- package/ChartsLegend/ChartsLegend.js +2 -2
- package/ChartsLegend/utils.js +4 -1
- package/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +4 -4
- package/ChartsOverlay/index.d.ts +1 -0
- package/ChartsReferenceLine/ChartsXReferenceLine.js +3 -5
- package/ChartsReferenceLine/ChartsYReferenceLine.js +3 -5
- package/ChartsText/ChartsText.js +1 -3
- package/ChartsTooltip/ChartsAxisTooltipContent.js +9 -15
- package/ChartsTooltip/ChartsItemTooltipContent.js +8 -18
- package/ChartsTooltip/DefaultChartsAxisTooltipContent.js +5 -4
- package/ChartsTooltip/DefaultChartsItemTooltipContent.js +1 -1
- package/ChartsTooltip/utils.d.ts +1 -7
- package/ChartsTooltip/utils.js +2 -10
- package/ChartsVoronoiHandler/ChartsVoronoiHandler.js +2 -2
- package/ChartsXAxis/ChartsXAxis.js +17 -19
- package/ChartsYAxis/ChartsYAxis.js +17 -19
- package/LineChart/AreaPlot.js +2 -2
- package/LineChart/LineChart.d.ts +2 -2
- package/LineChart/LineChart.js +3 -3
- package/LineChart/LineHighlightPlot.js +2 -2
- package/LineChart/LinePlot.js +2 -2
- package/LineChart/MarkPlot.js +2 -2
- package/LineChart/formatter.js +2 -2
- package/LineChart/getColor.d.ts +1 -1
- package/LineChart/getColor.js +2 -2
- package/LineChart/plugin.d.ts +2 -0
- package/LineChart/plugin.js +17 -0
- package/PieChart/PieChart.d.ts +2 -2
- package/PieChart/PieChart.js +3 -3
- package/PieChart/PiePlot.js +2 -2
- package/PieChart/plugin.d.ts +2 -0
- package/PieChart/plugin.js +14 -0
- package/ResponsiveChartContainer/ResizableContainer.d.ts +10 -0
- package/ResponsiveChartContainer/ResizableContainer.js +32 -0
- package/ResponsiveChartContainer/ResponsiveChartContainer.js +32 -24
- package/ScatterChart/ScatterChart.d.ts +2 -2
- package/ScatterChart/ScatterChart.js +3 -3
- package/ScatterChart/ScatterPlot.js +2 -2
- package/ScatterChart/formatter.js +2 -3
- package/ScatterChart/getColor.d.ts +1 -1
- package/ScatterChart/getColor.js +2 -2
- package/ScatterChart/plugin.d.ts +2 -0
- package/ScatterChart/plugin.js +17 -0
- package/SparkLineChart/SparkLineChart.d.ts +9 -4
- package/SparkLineChart/SparkLineChart.js +58 -2
- package/context/CartesianContextProvider.d.ts +21 -10
- package/context/CartesianContextProvider.js +7 -20
- package/context/ColorProvider.d.ts +12 -0
- package/context/ColorProvider.js +25 -0
- package/context/DrawingProvider.d.ts +3 -1
- package/context/DrawingProvider.js +9 -2
- package/context/HighlightedProvider/HighlightedContext.d.ts +2 -1
- package/context/HighlightedProvider/HighlightedContext.js +8 -5
- package/context/HighlightedProvider/HighlightedProvider.js +15 -12
- package/context/HighlightedProvider/useHighlighted.js +6 -3
- package/context/HighlightedProvider/useItemHighlighted.js +2 -8
- package/context/SeriesContextProvider.d.ts +16 -5
- package/context/SeriesContextProvider.js +14 -17
- package/context/context.types.d.ts +4 -0
- package/context/context.types.js +5 -0
- package/esm/BarChart/BarChart.js +2 -2
- package/esm/BarChart/BarPlot.js +2 -2
- package/esm/BarChart/formatter.js +1 -1
- package/esm/BarChart/getColor.js +4 -4
- package/esm/BarChart/plugin.js +10 -0
- package/esm/ChartContainer/ChartContainer.js +71 -23
- package/esm/ChartContainer/defaultPlugins.js +5 -0
- package/esm/ChartContainer/usePluginsMerge.js +31 -0
- package/esm/ChartsLegend/ChartsLegend.js +2 -2
- package/esm/ChartsLegend/utils.js +4 -1
- package/esm/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +4 -4
- package/esm/ChartsReferenceLine/ChartsXReferenceLine.js +3 -5
- package/esm/ChartsReferenceLine/ChartsYReferenceLine.js +3 -5
- package/esm/ChartsText/ChartsText.js +1 -3
- package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +8 -14
- package/esm/ChartsTooltip/ChartsItemTooltipContent.js +8 -18
- package/esm/ChartsTooltip/DefaultChartsAxisTooltipContent.js +5 -4
- package/esm/ChartsTooltip/DefaultChartsItemTooltipContent.js +1 -1
- package/esm/ChartsTooltip/utils.js +2 -8
- package/esm/ChartsVoronoiHandler/ChartsVoronoiHandler.js +2 -2
- package/esm/ChartsXAxis/ChartsXAxis.js +17 -19
- package/esm/ChartsYAxis/ChartsYAxis.js +17 -19
- package/esm/LineChart/AreaPlot.js +2 -2
- package/esm/LineChart/LineChart.js +3 -3
- package/esm/LineChart/LineHighlightPlot.js +2 -2
- package/esm/LineChart/LinePlot.js +2 -2
- package/esm/LineChart/MarkPlot.js +2 -2
- package/esm/LineChart/formatter.js +1 -1
- package/esm/LineChart/getColor.js +2 -2
- package/esm/LineChart/plugin.js +10 -0
- package/esm/PieChart/PieChart.js +3 -3
- package/esm/PieChart/PiePlot.js +2 -2
- package/esm/PieChart/plugin.js +7 -0
- package/esm/ResponsiveChartContainer/ResizableContainer.js +26 -0
- package/esm/ResponsiveChartContainer/ResponsiveChartContainer.js +31 -23
- package/esm/ScatterChart/ScatterChart.js +3 -3
- package/esm/ScatterChart/ScatterPlot.js +2 -2
- package/esm/ScatterChart/formatter.js +1 -1
- package/esm/ScatterChart/getColor.js +2 -2
- package/esm/ScatterChart/plugin.js +10 -0
- package/esm/SparkLineChart/SparkLineChart.js +58 -2
- package/esm/context/CartesianContextProvider.js +7 -20
- package/esm/context/ColorProvider.js +16 -0
- package/esm/context/DrawingProvider.js +9 -2
- package/esm/context/HighlightedProvider/HighlightedContext.js +8 -5
- package/esm/context/HighlightedProvider/HighlightedProvider.js +15 -12
- package/esm/context/HighlightedProvider/useHighlighted.js +6 -3
- package/esm/context/HighlightedProvider/useItemHighlighted.js +2 -6
- package/esm/context/SeriesContextProvider.js +14 -17
- package/esm/context/context.types.js +1 -0
- package/esm/hooks/index.js +1 -0
- package/esm/hooks/useColor.js +9 -0
- package/esm/hooks/useColorScale.js +27 -0
- package/esm/hooks/useInteractionItemProps.js +2 -2
- package/esm/hooks/useReducedMotion.js +7 -0
- package/esm/hooks/useSeries.js +6 -3
- package/esm/hooks/useSvgRef.js +6 -3
- package/esm/internals/configInit.js +20 -0
- package/esm/internals/defaultizeValueFormatter.js +2 -3
- package/esm/internals/index.js +27 -0
- package/esm/internals/isCartesian.js +7 -0
- package/esm/internals/warning.js +13 -0
- package/esm/models/index.js +1 -0
- package/esm/models/plugin.js +1 -0
- package/esm/models/seriesType/index.js +6 -0
- package/hooks/index.d.ts +1 -0
- package/hooks/index.js +12 -0
- package/hooks/useColor.d.ts +4 -0
- package/hooks/useColor.js +17 -0
- package/hooks/useColorScale.d.ts +4 -0
- package/hooks/useColorScale.js +37 -0
- package/hooks/useInteractionItemProps.js +1 -1
- package/hooks/useReducedMotion.js +7 -0
- package/hooks/useSeries.d.ts +6 -11
- package/hooks/useSeries.js +6 -3
- package/hooks/useSvgRef.js +6 -3
- package/hooks/useTicks.d.ts +4 -2
- package/index.js +1 -1
- package/internals/configInit.d.ts +9 -0
- package/internals/configInit.js +26 -0
- package/internals/defaultizeColor.d.ts +8 -8
- package/internals/defaultizeValueFormatter.d.ts +1 -2
- package/internals/defaultizeValueFormatter.js +2 -3
- package/internals/index.d.ts +17 -0
- package/internals/index.js +203 -0
- package/internals/isCartesian.d.ts +7 -0
- package/internals/isCartesian.js +14 -0
- package/internals/package.json +6 -0
- package/internals/warning.d.ts +1 -0
- package/internals/warning.js +19 -0
- package/models/axis.d.ts +4 -5
- package/models/index.d.ts +1 -0
- package/models/index.js +11 -0
- package/models/plugin.d.ts +16 -0
- package/models/plugin.js +5 -0
- package/models/seriesType/config.d.ts +30 -5
- package/models/seriesType/index.d.ts +8 -11
- package/models/seriesType/index.js +6 -0
- package/modern/BarChart/BarChart.js +2 -2
- package/modern/BarChart/BarPlot.js +2 -2
- package/modern/BarChart/formatter.js +1 -1
- package/modern/BarChart/getColor.js +4 -4
- package/modern/BarChart/plugin.js +10 -0
- package/modern/ChartContainer/ChartContainer.js +71 -23
- package/modern/ChartContainer/defaultPlugins.js +5 -0
- package/modern/ChartContainer/usePluginsMerge.js +31 -0
- package/modern/ChartsLegend/ChartsLegend.js +2 -2
- package/modern/ChartsLegend/utils.js +4 -1
- package/modern/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +4 -4
- package/modern/ChartsReferenceLine/ChartsXReferenceLine.js +3 -5
- package/modern/ChartsReferenceLine/ChartsYReferenceLine.js +3 -5
- package/modern/ChartsText/ChartsText.js +1 -3
- package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +8 -14
- package/modern/ChartsTooltip/ChartsItemTooltipContent.js +8 -18
- package/modern/ChartsTooltip/DefaultChartsAxisTooltipContent.js +5 -4
- package/modern/ChartsTooltip/DefaultChartsItemTooltipContent.js +1 -1
- package/modern/ChartsTooltip/utils.js +2 -8
- package/modern/ChartsVoronoiHandler/ChartsVoronoiHandler.js +2 -2
- package/modern/ChartsXAxis/ChartsXAxis.js +17 -19
- package/modern/ChartsYAxis/ChartsYAxis.js +17 -19
- package/modern/LineChart/AreaPlot.js +2 -2
- package/modern/LineChart/LineChart.js +3 -3
- package/modern/LineChart/LineHighlightPlot.js +2 -2
- package/modern/LineChart/LinePlot.js +2 -2
- package/modern/LineChart/MarkPlot.js +2 -2
- package/modern/LineChart/formatter.js +1 -1
- package/modern/LineChart/getColor.js +2 -2
- package/modern/LineChart/plugin.js +10 -0
- package/modern/PieChart/PieChart.js +3 -3
- package/modern/PieChart/PiePlot.js +2 -2
- package/modern/PieChart/plugin.js +7 -0
- package/modern/ResponsiveChartContainer/ResizableContainer.js +26 -0
- package/modern/ResponsiveChartContainer/ResponsiveChartContainer.js +31 -23
- package/modern/ScatterChart/ScatterChart.js +3 -3
- package/modern/ScatterChart/ScatterPlot.js +2 -2
- package/modern/ScatterChart/formatter.js +1 -1
- package/modern/ScatterChart/getColor.js +2 -2
- package/modern/ScatterChart/plugin.js +10 -0
- package/modern/SparkLineChart/SparkLineChart.js +58 -2
- package/modern/context/CartesianContextProvider.js +7 -20
- package/modern/context/ColorProvider.js +16 -0
- package/modern/context/DrawingProvider.js +9 -2
- package/modern/context/HighlightedProvider/HighlightedContext.js +8 -5
- package/modern/context/HighlightedProvider/HighlightedProvider.js +15 -12
- package/modern/context/HighlightedProvider/useHighlighted.js +6 -3
- package/modern/context/HighlightedProvider/useItemHighlighted.js +2 -6
- package/modern/context/SeriesContextProvider.js +14 -17
- package/modern/context/context.types.js +1 -0
- package/modern/hooks/index.js +1 -0
- package/modern/hooks/useColor.js +9 -0
- package/modern/hooks/useColorScale.js +27 -0
- package/modern/hooks/useInteractionItemProps.js +2 -2
- package/modern/hooks/useReducedMotion.js +7 -0
- package/modern/hooks/useSeries.js +6 -3
- package/modern/hooks/useSvgRef.js +6 -3
- package/modern/index.js +1 -1
- package/modern/internals/configInit.js +20 -0
- package/modern/internals/defaultizeValueFormatter.js +2 -3
- package/modern/internals/index.js +27 -0
- package/modern/internals/isCartesian.js +7 -0
- package/modern/internals/warning.js +13 -0
- package/modern/models/index.js +1 -0
- package/modern/models/plugin.js +1 -0
- package/modern/models/seriesType/index.js +6 -0
- package/package.json +2 -2
- package/themeAugmentation/components.d.ts +12 -12
- package/esm/internals/colorGetter.js +0 -22
- package/internals/colorGetter.d.ts +0 -7
- package/internals/colorGetter.js +0 -29
- package/modern/internals/colorGetter.js +0 -22
|
@@ -47,18 +47,21 @@ function HighlightedProvider({
|
|
|
47
47
|
const highlightScope = highlightedItem && highlightedItem.seriesId ? seriesById.get(highlightedItem.seriesId) ?? undefined : undefined;
|
|
48
48
|
const providerValue = React.useMemo(() => {
|
|
49
49
|
return {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
50
|
+
isInitialized: true,
|
|
51
|
+
data: {
|
|
52
|
+
highlightScope,
|
|
53
|
+
highlightedItem,
|
|
54
|
+
setHighlighted: itemData => {
|
|
55
|
+
setHighlightedItem(itemData);
|
|
56
|
+
onHighlightChange?.(itemData);
|
|
57
|
+
},
|
|
58
|
+
clearHighlighted: () => {
|
|
59
|
+
setHighlightedItem(null);
|
|
60
|
+
onHighlightChange?.(null);
|
|
61
|
+
},
|
|
62
|
+
isHighlighted: createIsHighlighted(highlightScope, highlightedItem),
|
|
63
|
+
isFaded: createIsFaded(highlightScope, highlightedItem)
|
|
64
|
+
}
|
|
62
65
|
};
|
|
63
66
|
}, [highlightedItem, highlightScope, setHighlightedItem, onHighlightChange]);
|
|
64
67
|
return /*#__PURE__*/_jsx(HighlightedContext.Provider, {
|
|
@@ -9,9 +9,12 @@ import { HighlightedContext } from './HighlightedContext';
|
|
|
9
9
|
* @returns {HighlightedState} the state of the chart
|
|
10
10
|
*/
|
|
11
11
|
export function useHighlighted() {
|
|
12
|
-
const
|
|
13
|
-
|
|
12
|
+
const {
|
|
13
|
+
isInitialized,
|
|
14
|
+
data
|
|
15
|
+
} = React.useContext(HighlightedContext);
|
|
16
|
+
if (!isInitialized) {
|
|
14
17
|
throw new Error(['MUI X: Could not find the highlighted ref context.', 'It looks like you rendered your component outside of a ChartsContainer parent component.'].join('\n'));
|
|
15
18
|
}
|
|
16
|
-
return
|
|
19
|
+
return data;
|
|
17
20
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { HighlightedContext } from './HighlightedContext';
|
|
1
|
+
import { useHighlighted } from './useHighlighted';
|
|
3
2
|
/**
|
|
4
3
|
* A hook to check the highlighted state of the item.
|
|
5
4
|
* This function already calculates that an item is not faded if it is highlighted.
|
|
@@ -10,10 +9,7 @@ import { HighlightedContext } from './HighlightedContext';
|
|
|
10
9
|
* @returns {ItemHighlightedState} the state of the item
|
|
11
10
|
*/
|
|
12
11
|
export function useItemHighlighted(item) {
|
|
13
|
-
const highlighted =
|
|
14
|
-
if (highlighted === undefined) {
|
|
15
|
-
throw new Error(['MUI X: Could not find the highlighted ref context.', 'It looks like you rendered your component outside of a ChartsContainer parent component.'].join('\n'));
|
|
16
|
-
}
|
|
12
|
+
const highlighted = useHighlighted();
|
|
17
13
|
if (!item) {
|
|
18
14
|
return {
|
|
19
15
|
isHighlighted: false,
|
|
@@ -1,24 +1,16 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import { useTheme } from '@mui/material/styles';
|
|
4
|
-
import barSeriesFormatter from '../BarChart/formatter';
|
|
5
|
-
import scatterSeriesFormatter from '../ScatterChart/formatter';
|
|
6
|
-
import lineSeriesFormatter from '../LineChart/formatter';
|
|
7
|
-
import pieSeriesFormatter from '../PieChart/formatter';
|
|
8
4
|
import { defaultizeColor } from '../internals/defaultizeColor';
|
|
9
5
|
import { blueberryTwilightPalette } from '../colorPalettes';
|
|
10
6
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
|
-
export const SeriesContext = /*#__PURE__*/React.createContext({
|
|
7
|
+
export const SeriesContext = /*#__PURE__*/React.createContext({
|
|
8
|
+
isInitialized: false,
|
|
9
|
+
data: {}
|
|
10
|
+
});
|
|
12
11
|
if (process.env.NODE_ENV !== 'production') {
|
|
13
12
|
SeriesContext.displayName = 'SeriesContext';
|
|
14
13
|
}
|
|
15
|
-
const seriesTypeFormatter = {
|
|
16
|
-
bar: barSeriesFormatter,
|
|
17
|
-
scatter: scatterSeriesFormatter,
|
|
18
|
-
line: lineSeriesFormatter,
|
|
19
|
-
pie: pieSeriesFormatter
|
|
20
|
-
};
|
|
21
|
-
|
|
22
14
|
/**
|
|
23
15
|
* This methods is the interface between what the developer is providing and what components receives
|
|
24
16
|
* To simplify the components behaviors, it groups series by type, such that LinePlots props are not updated if some line data are modified
|
|
@@ -27,7 +19,7 @@ const seriesTypeFormatter = {
|
|
|
27
19
|
* @param colors The color palette used to defaultize series colors
|
|
28
20
|
* @returns An object structuring all the series by type.
|
|
29
21
|
*/
|
|
30
|
-
const
|
|
22
|
+
const preprocessSeries = (series, colors, seriesFormatters, dataset) => {
|
|
31
23
|
// Group series by type
|
|
32
24
|
const seriesGroups = {};
|
|
33
25
|
series.forEach((seriesData, seriesIndex) => {
|
|
@@ -51,9 +43,10 @@ const formatSeries = (series, colors, dataset) => {
|
|
|
51
43
|
});
|
|
52
44
|
const formattedSeries = {};
|
|
53
45
|
// Apply formatter on a type group
|
|
54
|
-
Object.keys(
|
|
55
|
-
|
|
56
|
-
|
|
46
|
+
Object.keys(seriesFormatters).forEach(type => {
|
|
47
|
+
const group = seriesGroups[type];
|
|
48
|
+
if (group !== undefined) {
|
|
49
|
+
formattedSeries[type] = seriesFormatters[type]?.(group, dataset) ?? seriesGroups[type];
|
|
57
50
|
}
|
|
58
51
|
});
|
|
59
52
|
return formattedSeries;
|
|
@@ -63,10 +56,14 @@ function SeriesContextProvider(props) {
|
|
|
63
56
|
series,
|
|
64
57
|
dataset,
|
|
65
58
|
colors = blueberryTwilightPalette,
|
|
59
|
+
seriesFormatters,
|
|
66
60
|
children
|
|
67
61
|
} = props;
|
|
68
62
|
const theme = useTheme();
|
|
69
|
-
const formattedSeries = React.useMemo(() =>
|
|
63
|
+
const formattedSeries = React.useMemo(() => ({
|
|
64
|
+
isInitialized: true,
|
|
65
|
+
data: preprocessSeries(series, typeof colors === 'function' ? colors(theme.palette.mode) : colors, seriesFormatters, dataset)
|
|
66
|
+
}), [series, colors, theme.palette.mode, seriesFormatters, dataset]);
|
|
70
67
|
return /*#__PURE__*/_jsx(SeriesContext.Provider, {
|
|
71
68
|
value: formattedSeries,
|
|
72
69
|
children: children
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/modern/hooks/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export * from './useDrawingArea';
|
|
2
2
|
export * from './useChartId';
|
|
3
3
|
export * from './useScale';
|
|
4
|
+
export * from './useColorScale';
|
|
4
5
|
export * from './useSvgRef';
|
|
5
6
|
export { useSeries as unstable_useSeries, usePieSeries as unstable_usePieSeries, useLineSeries as unstable_useLineSeries, useBarSeries as unstable_useBarSeries, useScatterSeries as unstable_useScatterSeries } from './useSeries';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { ColorContext } from '../context/ColorProvider';
|
|
3
|
+
export function useColorProcessor(seriesType) {
|
|
4
|
+
const colorProcessors = React.useContext(ColorContext);
|
|
5
|
+
if (!seriesType) {
|
|
6
|
+
return colorProcessors;
|
|
7
|
+
}
|
|
8
|
+
return colorProcessors[seriesType];
|
|
9
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { CartesianContext } from '../context/CartesianContextProvider';
|
|
3
|
+
import { ZAxisContext } from '../context/ZAxisContextProvider';
|
|
4
|
+
export function useXColorScale(identifier) {
|
|
5
|
+
const {
|
|
6
|
+
xAxis,
|
|
7
|
+
xAxisIds
|
|
8
|
+
} = React.useContext(CartesianContext);
|
|
9
|
+
const id = typeof identifier === 'string' ? identifier : xAxisIds[identifier ?? 0];
|
|
10
|
+
return xAxis[id].colorScale;
|
|
11
|
+
}
|
|
12
|
+
export function useYColorScale(identifier) {
|
|
13
|
+
const {
|
|
14
|
+
yAxis,
|
|
15
|
+
yAxisIds
|
|
16
|
+
} = React.useContext(CartesianContext);
|
|
17
|
+
const id = typeof identifier === 'string' ? identifier : yAxisIds[identifier ?? 0];
|
|
18
|
+
return yAxis[id].colorScale;
|
|
19
|
+
}
|
|
20
|
+
export function useZColorScale(identifier) {
|
|
21
|
+
const {
|
|
22
|
+
zAxis,
|
|
23
|
+
zAxisIds
|
|
24
|
+
} = React.useContext(ZAxisContext);
|
|
25
|
+
const id = typeof identifier === 'string' ? identifier : zAxisIds[identifier ?? 0];
|
|
26
|
+
return zAxis[id]?.colorScale;
|
|
27
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { InteractionContext } from '../context/InteractionProvider';
|
|
3
|
-
import {
|
|
3
|
+
import { useHighlighted } from '../context';
|
|
4
4
|
export const useInteractionItemProps = skip => {
|
|
5
5
|
const {
|
|
6
6
|
dispatch: dispatchInteraction
|
|
@@ -8,7 +8,7 @@ export const useInteractionItemProps = skip => {
|
|
|
8
8
|
const {
|
|
9
9
|
setHighlighted,
|
|
10
10
|
clearHighlighted
|
|
11
|
-
} =
|
|
11
|
+
} = useHighlighted();
|
|
12
12
|
if (skip) {
|
|
13
13
|
return () => ({});
|
|
14
14
|
}
|
|
@@ -11,6 +11,13 @@ export const useReducedMotion = () => {
|
|
|
11
11
|
// Taken from: https://github.com/pmndrs/react-spring/blob/02ec877bbfab0df46da0e4a47d5f68d3e731206a/packages/shared/src/hooks/useReducedMotion.ts#L13
|
|
12
12
|
|
|
13
13
|
useIsomorphicLayoutEffect(() => {
|
|
14
|
+
if (!window.matchMedia) {
|
|
15
|
+
// skip animation in environments where `window.matchMedia` would not be available (i.e. test/jsdom)
|
|
16
|
+
Globals.assign({
|
|
17
|
+
skipAnimation: true
|
|
18
|
+
});
|
|
19
|
+
return () => {};
|
|
20
|
+
}
|
|
14
21
|
const mql = window.matchMedia('(prefers-reduced-motion)');
|
|
15
22
|
const handleMediaChange = e => {
|
|
16
23
|
Globals.assign({
|
|
@@ -8,11 +8,14 @@ import { SeriesContext } from '../context/SeriesContextProvider';
|
|
|
8
8
|
* @returns FormattedSeries series
|
|
9
9
|
*/
|
|
10
10
|
export function useSeries() {
|
|
11
|
-
const
|
|
12
|
-
|
|
11
|
+
const {
|
|
12
|
+
isInitialized,
|
|
13
|
+
data
|
|
14
|
+
} = React.useContext(SeriesContext);
|
|
15
|
+
if (!isInitialized) {
|
|
13
16
|
throw new Error(['MUI X: Could not find the series ref context.', 'It looks like you rendered your component outside of a ChartsContainer parent component.'].join('\n'));
|
|
14
17
|
}
|
|
15
|
-
return
|
|
18
|
+
return data;
|
|
16
19
|
}
|
|
17
20
|
|
|
18
21
|
/**
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { SvgContext } from '../context/DrawingProvider';
|
|
3
3
|
export function useSvgRef() {
|
|
4
|
-
const
|
|
5
|
-
|
|
4
|
+
const {
|
|
5
|
+
isInitialized,
|
|
6
|
+
data
|
|
7
|
+
} = React.useContext(SvgContext);
|
|
8
|
+
if (!isInitialized) {
|
|
6
9
|
throw new Error(['MUI X: Could not find the svg ref context.', 'It looks like you rendered your component outside of a ChartsContainer parent component.'].join('\n'));
|
|
7
10
|
}
|
|
8
|
-
return
|
|
11
|
+
return data;
|
|
9
12
|
}
|
package/modern/index.js
CHANGED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
let instance;
|
|
2
|
+
class CartesianSeriesTypes {
|
|
3
|
+
constructor() {
|
|
4
|
+
this.types = new Set();
|
|
5
|
+
if (instance) {
|
|
6
|
+
throw new Error('You can only create one instance!');
|
|
7
|
+
}
|
|
8
|
+
instance = this.types;
|
|
9
|
+
}
|
|
10
|
+
addType(value) {
|
|
11
|
+
this.types.add(value);
|
|
12
|
+
}
|
|
13
|
+
getTypes() {
|
|
14
|
+
return this.types;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export const cartesianSeriesTypes = new CartesianSeriesTypes();
|
|
18
|
+
cartesianSeriesTypes.addType('bar');
|
|
19
|
+
cartesianSeriesTypes.addType('line');
|
|
20
|
+
cartesianSeriesTypes.addType('scatter');
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
-
function defaultizeValueFormatter(series, defaultValueFormatter) {
|
|
2
|
+
export function defaultizeValueFormatter(series, defaultValueFormatter) {
|
|
3
3
|
const defaultizedSeries = {};
|
|
4
4
|
Object.keys(series).forEach(seriesId => {
|
|
5
5
|
defaultizedSeries[seriesId] = _extends({}, series[seriesId], {
|
|
@@ -7,5 +7,4 @@ function defaultizeValueFormatter(series, defaultValueFormatter) {
|
|
|
7
7
|
});
|
|
8
8
|
});
|
|
9
9
|
return defaultizedSeries;
|
|
10
|
-
}
|
|
11
|
-
export default defaultizeValueFormatter;
|
|
10
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// Components
|
|
2
|
+
export * from './components/ChartsAxesGradients';
|
|
3
|
+
export * from '../ResponsiveChartContainer/useChartContainerDimensions';
|
|
4
|
+
export * from '../ResponsiveChartContainer/ResizableContainer';
|
|
5
|
+
|
|
6
|
+
// hooks
|
|
7
|
+
export { useReducedMotion } from '../hooks/useReducedMotion';
|
|
8
|
+
export { useSeries } from '../hooks/useSeries';
|
|
9
|
+
|
|
10
|
+
// utils
|
|
11
|
+
export * from './defaultizeValueFormatter';
|
|
12
|
+
export * from './configInit';
|
|
13
|
+
|
|
14
|
+
// contexts
|
|
15
|
+
|
|
16
|
+
export * from '../context/CartesianContextProvider';
|
|
17
|
+
export * from '../context/DrawingProvider';
|
|
18
|
+
export * from '../context/InteractionProvider';
|
|
19
|
+
export * from '../context/SeriesContextProvider';
|
|
20
|
+
export * from '../context/ZAxisContextProvider';
|
|
21
|
+
|
|
22
|
+
// series configuration
|
|
23
|
+
export * from '../models/seriesType/config';
|
|
24
|
+
export * from '../models/seriesType/common';
|
|
25
|
+
export * from '../models/helpers';
|
|
26
|
+
export * from '../models/z-axis';
|
|
27
|
+
export * from '../models/axis';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export function buildWarning(message, gravity = 'warning') {
|
|
2
|
+
let alreadyWarned = false;
|
|
3
|
+
return (...args) => {
|
|
4
|
+
if (!alreadyWarned) {
|
|
5
|
+
alreadyWarned = true;
|
|
6
|
+
if (gravity === 'error') {
|
|
7
|
+
console.error(message(...args));
|
|
8
|
+
} else {
|
|
9
|
+
console.warn(message(...args));
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
}
|
package/modern/models/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,7 +1,13 @@
|
|
|
1
|
+
// Series definition
|
|
2
|
+
|
|
3
|
+
// item identifier
|
|
4
|
+
|
|
1
5
|
export * from './line';
|
|
2
6
|
export * from './bar';
|
|
3
7
|
export * from './scatter';
|
|
4
8
|
export * from './pie';
|
|
9
|
+
// Helpers
|
|
10
|
+
|
|
5
11
|
export function isDefaultizedBarSeries(series) {
|
|
6
12
|
return series.type === 'bar';
|
|
7
13
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mui/x-charts",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.7.0",
|
|
4
4
|
"description": "The community edition of the Charts components (MUI X).",
|
|
5
5
|
"author": "MUI Team",
|
|
6
6
|
"main": "./index.js",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"directory": "packages/x-charts"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@babel/runtime": "^7.24.
|
|
32
|
+
"@babel/runtime": "^7.24.7",
|
|
33
33
|
"@mui/base": "^5.0.0-beta.40",
|
|
34
34
|
"@mui/system": "^5.15.15",
|
|
35
35
|
"@mui/utils": "^5.15.14",
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { ComponentsProps, ComponentsOverrides } from '@mui/material/styles';
|
|
2
2
|
|
|
3
|
-
export interface ChartsComponents {
|
|
3
|
+
export interface ChartsComponents<Theme = unknown> {
|
|
4
4
|
MuiChartsAxis?: {
|
|
5
5
|
defaultProps?: ComponentsProps['MuiChartsAxis'];
|
|
6
|
-
styleOverrides?: ComponentsOverrides['MuiChartsAxis'];
|
|
6
|
+
styleOverrides?: ComponentsOverrides<Theme>['MuiChartsAxis'];
|
|
7
7
|
};
|
|
8
8
|
MuiChartsXAxis?: {
|
|
9
9
|
defaultProps?: ComponentsProps['MuiChartsXAxis'];
|
|
@@ -13,22 +13,22 @@ export interface ChartsComponents {
|
|
|
13
13
|
};
|
|
14
14
|
MuiChartsAxisHighlight?: {
|
|
15
15
|
defaultProps?: ComponentsProps['MuiChartsAxisHighlight'];
|
|
16
|
-
styleOverrides?: ComponentsOverrides['MuiChartsAxisHighlight'];
|
|
16
|
+
styleOverrides?: ComponentsOverrides<Theme>['MuiChartsAxisHighlight'];
|
|
17
17
|
};
|
|
18
18
|
MuiChartsClipPath?: {
|
|
19
19
|
defaultProps?: ComponentsProps['MuiChartsClipPath'];
|
|
20
20
|
};
|
|
21
21
|
MuiChartsGrid?: {
|
|
22
22
|
defaultProps?: ComponentsProps['MuiChartsGrid'];
|
|
23
|
-
styleOverrides?: ComponentsOverrides['MuiChartsGrid'];
|
|
23
|
+
styleOverrides?: ComponentsOverrides<Theme>['MuiChartsGrid'];
|
|
24
24
|
};
|
|
25
25
|
MuiChartsLegend?: {
|
|
26
26
|
defaultProps?: ComponentsProps['MuiChartsLegend'];
|
|
27
|
-
styleOverrides?: ComponentsOverrides['MuiChartsLegend'];
|
|
27
|
+
styleOverrides?: ComponentsOverrides<Theme>['MuiChartsLegend'];
|
|
28
28
|
};
|
|
29
29
|
MuiChartsTooltip?: {
|
|
30
30
|
defaultProps?: ComponentsProps['MuiChartsTooltip'];
|
|
31
|
-
styleOverrides?: ComponentsOverrides['MuiChartsTooltip'];
|
|
31
|
+
styleOverrides?: ComponentsOverrides<Theme>['MuiChartsTooltip'];
|
|
32
32
|
};
|
|
33
33
|
MuiChartsSurface?: {
|
|
34
34
|
defaultProps?: ComponentsProps['MuiChartsSurface'];
|
|
@@ -38,26 +38,26 @@ export interface ChartsComponents {
|
|
|
38
38
|
};
|
|
39
39
|
MuiBarElement?: {
|
|
40
40
|
defaultProps?: ComponentsProps['MuiBarElement'];
|
|
41
|
-
styleOverrides?: ComponentsOverrides['MuiBarElement'];
|
|
41
|
+
styleOverrides?: ComponentsOverrides<Theme>['MuiBarElement'];
|
|
42
42
|
};
|
|
43
43
|
MuiBarLabel?: {
|
|
44
44
|
defaultProps?: ComponentsProps['MuiBarLabel'];
|
|
45
|
-
styleOverrides?: ComponentsOverrides['MuiBarLabel'];
|
|
45
|
+
styleOverrides?: ComponentsOverrides<Theme>['MuiBarLabel'];
|
|
46
46
|
};
|
|
47
47
|
MuiLineChart?: {
|
|
48
48
|
defaultProps?: ComponentsProps['MuiLineChart'];
|
|
49
49
|
};
|
|
50
50
|
MuiAreaElement?: {
|
|
51
51
|
defaultProps?: ComponentsProps['MuiAreaElement'];
|
|
52
|
-
styleOverrides?: ComponentsOverrides['MuiAreaElement'];
|
|
52
|
+
styleOverrides?: ComponentsOverrides<Theme>['MuiAreaElement'];
|
|
53
53
|
};
|
|
54
54
|
MuiLineElement?: {
|
|
55
55
|
defaultProps?: ComponentsProps['MuiLineElement'];
|
|
56
|
-
styleOverrides?: ComponentsOverrides['MuiLineElement'];
|
|
56
|
+
styleOverrides?: ComponentsOverrides<Theme>['MuiLineElement'];
|
|
57
57
|
};
|
|
58
58
|
MuiMarkElement?: {
|
|
59
59
|
defaultProps?: ComponentsProps['MuiMarkElement'];
|
|
60
|
-
styleOverrides?: ComponentsOverrides['MuiMarkElement'];
|
|
60
|
+
styleOverrides?: ComponentsOverrides<Theme>['MuiMarkElement'];
|
|
61
61
|
};
|
|
62
62
|
MuiScatterChart?: {
|
|
63
63
|
defaultProps?: ComponentsProps['MuiScatterChart'];
|
|
@@ -68,5 +68,5 @@ export interface ChartsComponents {
|
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
declare module '@mui/material/styles' {
|
|
71
|
-
interface Components extends ChartsComponents {}
|
|
71
|
+
interface Components<Theme = unknown> extends ChartsComponents<Theme> {}
|
|
72
72
|
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import getBarColor from '../BarChart/getColor';
|
|
2
|
-
import getLineColor from '../LineChart/getColor';
|
|
3
|
-
import getScatterColor from '../ScatterChart/getColor';
|
|
4
|
-
import getPieColor from '../PieChart/getColor';
|
|
5
|
-
function getColor(series, xAxis, yAxis, zAxis) {
|
|
6
|
-
if (xAxis !== undefined && yAxis !== undefined) {
|
|
7
|
-
if (series.type === 'bar') {
|
|
8
|
-
return getBarColor(series, xAxis, yAxis);
|
|
9
|
-
}
|
|
10
|
-
if (series.type === 'line') {
|
|
11
|
-
return getLineColor(series, xAxis, yAxis);
|
|
12
|
-
}
|
|
13
|
-
if (series.type === 'scatter') {
|
|
14
|
-
return getScatterColor(series, xAxis, yAxis, zAxis);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
if (series.type === 'pie') {
|
|
18
|
-
return getPieColor(series);
|
|
19
|
-
}
|
|
20
|
-
throw Error(`MUI X Charts: getColor called with unexpected arguments for series with id "${series.id}"`);
|
|
21
|
-
}
|
|
22
|
-
export default getColor;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { DefaultizedBarSeriesType, DefaultizedLineSeriesType, DefaultizedPieSeriesType, DefaultizedScatterSeriesType } from '../models';
|
|
2
|
-
import { AxisDefaultized } from '../models/axis';
|
|
3
|
-
import { ZAxisDefaultized } from '../models/z-axis';
|
|
4
|
-
declare function getColor(series: DefaultizedPieSeriesType): (dataIndex: number) => string;
|
|
5
|
-
declare function getColor(series: DefaultizedBarSeriesType | DefaultizedLineSeriesType, xAxis: AxisDefaultized, yAxis: AxisDefaultized): (dataIndex: number) => string;
|
|
6
|
-
declare function getColor(series: DefaultizedScatterSeriesType, xAxis: AxisDefaultized, yAxis: AxisDefaultized, zAxis?: ZAxisDefaultized): (dataIndex: number) => string;
|
|
7
|
-
export default getColor;
|
package/internals/colorGetter.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.default = void 0;
|
|
8
|
-
var _getColor = _interopRequireDefault(require("../BarChart/getColor"));
|
|
9
|
-
var _getColor2 = _interopRequireDefault(require("../LineChart/getColor"));
|
|
10
|
-
var _getColor3 = _interopRequireDefault(require("../ScatterChart/getColor"));
|
|
11
|
-
var _getColor4 = _interopRequireDefault(require("../PieChart/getColor"));
|
|
12
|
-
function getColor(series, xAxis, yAxis, zAxis) {
|
|
13
|
-
if (xAxis !== undefined && yAxis !== undefined) {
|
|
14
|
-
if (series.type === 'bar') {
|
|
15
|
-
return (0, _getColor.default)(series, xAxis, yAxis);
|
|
16
|
-
}
|
|
17
|
-
if (series.type === 'line') {
|
|
18
|
-
return (0, _getColor2.default)(series, xAxis, yAxis);
|
|
19
|
-
}
|
|
20
|
-
if (series.type === 'scatter') {
|
|
21
|
-
return (0, _getColor3.default)(series, xAxis, yAxis, zAxis);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
if (series.type === 'pie') {
|
|
25
|
-
return (0, _getColor4.default)(series);
|
|
26
|
-
}
|
|
27
|
-
throw Error(`MUI X Charts: getColor called with unexpected arguments for series with id "${series.id}"`);
|
|
28
|
-
}
|
|
29
|
-
var _default = exports.default = getColor;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import getBarColor from '../BarChart/getColor';
|
|
2
|
-
import getLineColor from '../LineChart/getColor';
|
|
3
|
-
import getScatterColor from '../ScatterChart/getColor';
|
|
4
|
-
import getPieColor from '../PieChart/getColor';
|
|
5
|
-
function getColor(series, xAxis, yAxis, zAxis) {
|
|
6
|
-
if (xAxis !== undefined && yAxis !== undefined) {
|
|
7
|
-
if (series.type === 'bar') {
|
|
8
|
-
return getBarColor(series, xAxis, yAxis);
|
|
9
|
-
}
|
|
10
|
-
if (series.type === 'line') {
|
|
11
|
-
return getLineColor(series, xAxis, yAxis);
|
|
12
|
-
}
|
|
13
|
-
if (series.type === 'scatter') {
|
|
14
|
-
return getScatterColor(series, xAxis, yAxis, zAxis);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
if (series.type === 'pie') {
|
|
18
|
-
return getPieColor(series);
|
|
19
|
-
}
|
|
20
|
-
throw Error(`MUI X Charts: getColor called with unexpected arguments for series with id "${series.id}"`);
|
|
21
|
-
}
|
|
22
|
-
export default getColor;
|