@mui/x-charts 7.6.2 → 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.d.ts +1 -1
- 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 +163 -0
- package/ChartContainer/ChartContainer.d.ts +4 -4
- package/ChartContainer/ChartContainer.js +64 -31
- 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/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 +8 -14
- package/ChartsTooltip/ChartsItemTooltipContent.js +8 -18
- package/ChartsTooltip/DefaultChartsAxisTooltipContent.js +3 -3
- package/ChartsTooltip/DefaultChartsItemTooltipContent.js +1 -1
- 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.d.ts +2 -2
- package/LineChart/LineChart.js +25 -107
- 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/PieChart/PieChart.d.ts +2 -2
- package/PieChart/PieChart.js +1 -1
- package/ResponsiveChartContainer/ResizableContainer.d.ts +10 -0
- package/ResponsiveChartContainer/ResizableContainer.js +32 -0
- package/ResponsiveChartContainer/ResponsiveChartContainer.js +25 -22
- package/ScatterChart/ScatterChart.d.ts +1 -1
- package/ScatterChart/ScatterChart.js +21 -76
- package/ScatterChart/ScatterPlot.js +2 -2
- package/ScatterChart/useScatterChartProps.d.ts +86 -0
- package/ScatterChart/useScatterChartProps.js +116 -0
- package/SparkLineChart/SparkLineChart.d.ts +8 -3
- package/SparkLineChart/SparkLineChart.js +57 -1
- 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 +12 -0
- package/context/ColorProvider.js +25 -0
- 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 +65 -32
- 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/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 +3 -3
- package/esm/ChartsTooltip/DefaultChartsItemTooltipContent.js +1 -1
- 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 +25 -107
- 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/PieChart/PieChart.js +1 -1
- package/esm/ResponsiveChartContainer/ResizableContainer.js +26 -0
- package/esm/ResponsiveChartContainer/ResponsiveChartContainer.js +24 -21
- package/esm/ScatterChart/ScatterChart.js +21 -76
- package/esm/ScatterChart/ScatterPlot.js +2 -2
- package/esm/ScatterChart/useScatterChartProps.js +108 -0
- package/esm/SparkLineChart/SparkLineChart.js +57 -1
- 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/context/ColorProvider.js +16 -0
- package/esm/hooks/index.js +1 -0
- package/esm/hooks/useAxisEvents.js +2 -2
- package/esm/hooks/useColor.js +9 -0
- package/esm/hooks/useColorScale.js +27 -0
- package/esm/hooks/useReducedMotion.js +7 -0
- package/esm/hooks/useScale.js +3 -4
- package/esm/internals/components/ChartsAxesGradients/ChartsAxesGradients.js +2 -2
- package/esm/internals/index.js +31 -1
- package/esm/internals/warning.js +13 -0
- package/hooks/index.d.ts +1 -0
- package/hooks/index.js +12 -0
- package/hooks/useAxisEvents.js +2 -2
- 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/useDrawingArea.d.ts +2 -8
- package/hooks/useReducedMotion.js +7 -0
- 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/defaultizeColor.d.ts +8 -8
- package/internals/index.d.ts +22 -0
- package/internals/index.js +231 -0
- package/internals/warning.d.ts +1 -0
- package/internals/warning.js +19 -0
- package/models/axis.d.ts +1 -2
- 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 +65 -32
- 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/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 +3 -3
- package/modern/ChartsTooltip/DefaultChartsItemTooltipContent.js +1 -1
- 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 +25 -107
- 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/PieChart/PieChart.js +1 -1
- package/modern/ResponsiveChartContainer/ResizableContainer.js +26 -0
- package/modern/ResponsiveChartContainer/ResponsiveChartContainer.js +24 -21
- package/modern/ScatterChart/ScatterChart.js +21 -76
- package/modern/ScatterChart/ScatterPlot.js +2 -2
- package/modern/ScatterChart/useScatterChartProps.js +108 -0
- package/modern/SparkLineChart/SparkLineChart.js +57 -1
- 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/context/ColorProvider.js +16 -0
- package/modern/hooks/index.js +1 -0
- package/modern/hooks/useAxisEvents.js +2 -2
- package/modern/hooks/useColor.js +9 -0
- package/modern/hooks/useColorScale.js +27 -0
- package/modern/hooks/useReducedMotion.js +7 -0
- 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 +31 -1
- package/modern/internals/warning.js +13 -0
- package/package.json +4 -4
- package/themeAugmentation/components.d.ts +12 -12
- package/context/CartesianContextProvider.d.ts +0 -53
- package/context/CartesianContextProvider.js +0 -233
- package/esm/context/CartesianContextProvider.js +0 -224
- package/esm/internals/colorGetter.js +0 -22
- package/internals/colorGetter.d.ts +0 -7
- package/internals/colorGetter.js +0 -29
- package/modern/context/CartesianContextProvider.js +0 -224
- package/modern/internals/colorGetter.js +0 -22
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
/**
|
|
3
|
+
* A helper function that extracts ScatterChartProps from the input props
|
|
4
|
+
* and returns an object with props for the children components of ScatterChart.
|
|
5
|
+
*
|
|
6
|
+
* @param props The input props for ScatterChart
|
|
7
|
+
* @returns An object with props for the children components of ScatterChart
|
|
8
|
+
*/
|
|
9
|
+
export const useScatterChartProps = props => {
|
|
10
|
+
const {
|
|
11
|
+
xAxis,
|
|
12
|
+
yAxis,
|
|
13
|
+
zAxis,
|
|
14
|
+
series,
|
|
15
|
+
tooltip,
|
|
16
|
+
axisHighlight,
|
|
17
|
+
voronoiMaxRadius,
|
|
18
|
+
disableVoronoi,
|
|
19
|
+
legend,
|
|
20
|
+
width,
|
|
21
|
+
height,
|
|
22
|
+
margin,
|
|
23
|
+
colors,
|
|
24
|
+
sx,
|
|
25
|
+
grid,
|
|
26
|
+
topAxis,
|
|
27
|
+
leftAxis,
|
|
28
|
+
rightAxis,
|
|
29
|
+
bottomAxis,
|
|
30
|
+
onItemClick,
|
|
31
|
+
children,
|
|
32
|
+
slots,
|
|
33
|
+
slotProps,
|
|
34
|
+
loading,
|
|
35
|
+
highlightedItem,
|
|
36
|
+
onHighlightChange
|
|
37
|
+
} = props;
|
|
38
|
+
const chartContainerProps = {
|
|
39
|
+
series: series.map(s => _extends({
|
|
40
|
+
type: 'scatter'
|
|
41
|
+
}, s)),
|
|
42
|
+
width,
|
|
43
|
+
height,
|
|
44
|
+
margin,
|
|
45
|
+
colors,
|
|
46
|
+
xAxis,
|
|
47
|
+
yAxis,
|
|
48
|
+
sx,
|
|
49
|
+
highlightedItem,
|
|
50
|
+
onHighlightChange
|
|
51
|
+
};
|
|
52
|
+
const zAxisProps = {
|
|
53
|
+
zAxis
|
|
54
|
+
};
|
|
55
|
+
const voronoiHandlerProps = {
|
|
56
|
+
voronoiMaxRadius,
|
|
57
|
+
onItemClick: onItemClick
|
|
58
|
+
};
|
|
59
|
+
const chartsAxisProps = {
|
|
60
|
+
topAxis,
|
|
61
|
+
leftAxis,
|
|
62
|
+
rightAxis,
|
|
63
|
+
bottomAxis,
|
|
64
|
+
slots,
|
|
65
|
+
slotProps
|
|
66
|
+
};
|
|
67
|
+
const gridProps = {
|
|
68
|
+
vertical: grid?.vertical,
|
|
69
|
+
horizontal: grid?.horizontal
|
|
70
|
+
};
|
|
71
|
+
const scatterPlotProps = {
|
|
72
|
+
onItemClick: disableVoronoi ? onItemClick : undefined,
|
|
73
|
+
slots,
|
|
74
|
+
slotProps
|
|
75
|
+
};
|
|
76
|
+
const overlayProps = {
|
|
77
|
+
loading,
|
|
78
|
+
slots,
|
|
79
|
+
slotProps
|
|
80
|
+
};
|
|
81
|
+
const legendProps = _extends({}, legend, {
|
|
82
|
+
slots,
|
|
83
|
+
slotProps
|
|
84
|
+
});
|
|
85
|
+
const axisHighlightProps = _extends({
|
|
86
|
+
y: 'none',
|
|
87
|
+
x: 'none'
|
|
88
|
+
}, axisHighlight);
|
|
89
|
+
const tooltipProps = _extends({
|
|
90
|
+
trigger: 'item'
|
|
91
|
+
}, tooltip, {
|
|
92
|
+
slots,
|
|
93
|
+
slotProps
|
|
94
|
+
});
|
|
95
|
+
return {
|
|
96
|
+
chartContainerProps,
|
|
97
|
+
zAxisProps,
|
|
98
|
+
voronoiHandlerProps,
|
|
99
|
+
chartsAxisProps,
|
|
100
|
+
gridProps,
|
|
101
|
+
scatterPlotProps,
|
|
102
|
+
overlayProps,
|
|
103
|
+
legendProps,
|
|
104
|
+
axisHighlightProps,
|
|
105
|
+
tooltipProps,
|
|
106
|
+
children
|
|
107
|
+
};
|
|
108
|
+
};
|
|
@@ -27,6 +27,7 @@ const SPARKLINE_DEFAULT_MARGIN = {
|
|
|
27
27
|
const SparkLineChart = /*#__PURE__*/React.forwardRef(function SparkLineChart(props, ref) {
|
|
28
28
|
const {
|
|
29
29
|
xAxis,
|
|
30
|
+
yAxis,
|
|
30
31
|
width,
|
|
31
32
|
height,
|
|
32
33
|
margin = SPARKLINE_DEFAULT_MARGIN,
|
|
@@ -73,6 +74,9 @@ const SparkLineChart = /*#__PURE__*/React.forwardRef(function SparkLineChart(pro
|
|
|
73
74
|
}, (_, index) => index),
|
|
74
75
|
hideTooltip: xAxis === undefined
|
|
75
76
|
}, xAxis)],
|
|
77
|
+
yAxis: [_extends({
|
|
78
|
+
id: DEFAULT_X_AXIS_KEY
|
|
79
|
+
}, yAxis)],
|
|
76
80
|
colors: colors,
|
|
77
81
|
sx: sx,
|
|
78
82
|
disableAxisListener: (!showTooltip || tooltip?.trigger !== 'axis') && axisHighlight?.x === 'none' && axisHighlight?.y === 'none',
|
|
@@ -233,7 +237,7 @@ process.env.NODE_ENV !== "production" ? SparkLineChart.propTypes = {
|
|
|
233
237
|
width: PropTypes.number,
|
|
234
238
|
/**
|
|
235
239
|
* The xAxis configuration.
|
|
236
|
-
* Notice it is a single
|
|
240
|
+
* Notice it is a single [[AxisConfig]] object, not an array of configuration.
|
|
237
241
|
*/
|
|
238
242
|
xAxis: PropTypes.shape({
|
|
239
243
|
axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
@@ -282,6 +286,58 @@ process.env.NODE_ENV !== "production" ? SparkLineChart.propTypes = {
|
|
|
282
286
|
tickPlacement: PropTypes.oneOf(['end', 'extremities', 'middle', 'start']),
|
|
283
287
|
tickSize: PropTypes.number,
|
|
284
288
|
valueFormatter: PropTypes.func
|
|
289
|
+
}),
|
|
290
|
+
/**
|
|
291
|
+
* The yAxis configuration.
|
|
292
|
+
* Notice it is a single [[AxisConfig]] object, not an array of configuration.
|
|
293
|
+
*/
|
|
294
|
+
yAxis: PropTypes.shape({
|
|
295
|
+
axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
296
|
+
classes: PropTypes.object,
|
|
297
|
+
colorMap: PropTypes.oneOfType([PropTypes.shape({
|
|
298
|
+
colors: PropTypes.arrayOf(PropTypes.string).isRequired,
|
|
299
|
+
type: PropTypes.oneOf(['ordinal']).isRequired,
|
|
300
|
+
unknownColor: PropTypes.string,
|
|
301
|
+
values: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired)
|
|
302
|
+
}), PropTypes.shape({
|
|
303
|
+
color: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string.isRequired), PropTypes.func]).isRequired,
|
|
304
|
+
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
305
|
+
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
306
|
+
type: PropTypes.oneOf(['continuous']).isRequired
|
|
307
|
+
}), PropTypes.shape({
|
|
308
|
+
colors: PropTypes.arrayOf(PropTypes.string).isRequired,
|
|
309
|
+
thresholds: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired).isRequired,
|
|
310
|
+
type: PropTypes.oneOf(['piecewise']).isRequired
|
|
311
|
+
})]),
|
|
312
|
+
data: PropTypes.array,
|
|
313
|
+
dataKey: PropTypes.string,
|
|
314
|
+
disableLine: PropTypes.bool,
|
|
315
|
+
disableTicks: PropTypes.bool,
|
|
316
|
+
fill: PropTypes.string,
|
|
317
|
+
hideTooltip: PropTypes.bool,
|
|
318
|
+
id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
319
|
+
label: PropTypes.string,
|
|
320
|
+
labelFontSize: PropTypes.number,
|
|
321
|
+
labelStyle: PropTypes.object,
|
|
322
|
+
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
323
|
+
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
324
|
+
position: PropTypes.oneOf(['left', 'right']),
|
|
325
|
+
reverse: PropTypes.bool,
|
|
326
|
+
scaleType: PropTypes.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
|
|
327
|
+
slotProps: PropTypes.object,
|
|
328
|
+
slots: PropTypes.object,
|
|
329
|
+
stroke: PropTypes.string,
|
|
330
|
+
tickFontSize: PropTypes.number,
|
|
331
|
+
tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
|
|
332
|
+
tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
|
|
333
|
+
tickLabelPlacement: PropTypes.oneOf(['middle', 'tick']),
|
|
334
|
+
tickLabelStyle: PropTypes.object,
|
|
335
|
+
tickMaxStep: PropTypes.number,
|
|
336
|
+
tickMinStep: PropTypes.number,
|
|
337
|
+
tickNumber: PropTypes.number,
|
|
338
|
+
tickPlacement: PropTypes.oneOf(['end', 'extremities', 'middle', 'start']),
|
|
339
|
+
tickSize: PropTypes.number,
|
|
340
|
+
valueFormatter: PropTypes.func
|
|
285
341
|
})
|
|
286
342
|
} : void 0;
|
|
287
343
|
export { SparkLineChart };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
export const CartesianContext = /*#__PURE__*/React.createContext({
|
|
3
|
+
isInitialized: false,
|
|
4
|
+
data: {
|
|
5
|
+
xAxis: {},
|
|
6
|
+
yAxis: {},
|
|
7
|
+
xAxisIds: [],
|
|
8
|
+
yAxisIds: []
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
12
|
+
CartesianContext.displayName = 'CartesianContext';
|
|
13
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { useDrawingArea } from '../../hooks/useDrawingArea';
|
|
3
|
+
import { useSeries } from '../../hooks/useSeries';
|
|
4
|
+
import { CartesianContext } from './CartesianContext';
|
|
5
|
+
import { normalizeAxis } from './normalizeAxis';
|
|
6
|
+
import { computeValue } from './computeValue';
|
|
7
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
|
+
function CartesianContextProvider(props) {
|
|
9
|
+
const {
|
|
10
|
+
xAxis: inXAxis,
|
|
11
|
+
yAxis: inYAxis,
|
|
12
|
+
dataset,
|
|
13
|
+
xExtremumGetters,
|
|
14
|
+
yExtremumGetters,
|
|
15
|
+
children
|
|
16
|
+
} = props;
|
|
17
|
+
const formattedSeries = useSeries();
|
|
18
|
+
const drawingArea = useDrawingArea();
|
|
19
|
+
const xAxis = React.useMemo(() => normalizeAxis(inXAxis, dataset, 'x'), [inXAxis, dataset]);
|
|
20
|
+
const yAxis = React.useMemo(() => normalizeAxis(inYAxis, dataset, 'y'), [inYAxis, dataset]);
|
|
21
|
+
const xValues = React.useMemo(() => computeValue(drawingArea, formattedSeries, xAxis, xExtremumGetters, 'x'), [drawingArea, formattedSeries, xAxis, xExtremumGetters]);
|
|
22
|
+
const yValues = React.useMemo(() => computeValue(drawingArea, formattedSeries, yAxis, yExtremumGetters, 'y'), [drawingArea, formattedSeries, yAxis, yExtremumGetters]);
|
|
23
|
+
const value = React.useMemo(() => ({
|
|
24
|
+
isInitialized: true,
|
|
25
|
+
data: {
|
|
26
|
+
xAxis: xValues.axis,
|
|
27
|
+
yAxis: yValues.axis,
|
|
28
|
+
xAxisIds: xValues.axisIds,
|
|
29
|
+
yAxisIds: yValues.axisIds
|
|
30
|
+
}
|
|
31
|
+
}), [xValues, yValues]);
|
|
32
|
+
return /*#__PURE__*/_jsx(CartesianContext.Provider, {
|
|
33
|
+
value: value,
|
|
34
|
+
children: children
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
export { CartesianContextProvider };
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import { scaleBand, scalePoint } from 'd3-scale';
|
|
3
|
+
import { DEFAULT_X_AXIS_KEY, DEFAULT_Y_AXIS_KEY } from '../../constants';
|
|
4
|
+
import { isBandScaleConfig, isPointScaleConfig } from '../../models/axis';
|
|
5
|
+
import { getColorScale, getOrdinalColorScale } from '../../internals/colorScale';
|
|
6
|
+
import { getTickNumber } from '../../hooks/useTicks';
|
|
7
|
+
import { getScale } from '../../internals/getScale';
|
|
8
|
+
import { getAxisExtremum } from './getAxisExtremum';
|
|
9
|
+
const getRange = (drawingArea, axisName, isReverse) => {
|
|
10
|
+
const range = axisName === 'x' ? [drawingArea.left, drawingArea.left + drawingArea.width] : [drawingArea.top + drawingArea.height, drawingArea.top];
|
|
11
|
+
return isReverse ? range.reverse() : range;
|
|
12
|
+
};
|
|
13
|
+
const DEFAULT_CATEGORY_GAP_RATIO = 0.2;
|
|
14
|
+
const DEFAULT_BAR_GAP_RATIO = 0.1;
|
|
15
|
+
export function computeValue(drawingArea, formattedSeries, inAxis, extremumGetters, axisName) {
|
|
16
|
+
const DEFAULT_AXIS_KEY = axisName === 'x' ? DEFAULT_X_AXIS_KEY : DEFAULT_Y_AXIS_KEY;
|
|
17
|
+
const allAxis = [...(inAxis?.map((axis, index) => _extends({
|
|
18
|
+
id: `defaultized-${axisName}-axis-${index}`
|
|
19
|
+
}, axis)) ?? []), ...(inAxis === undefined || inAxis.findIndex(({
|
|
20
|
+
id
|
|
21
|
+
}) => id === DEFAULT_AXIS_KEY) === -1 ? [{
|
|
22
|
+
id: DEFAULT_AXIS_KEY,
|
|
23
|
+
scaleType: 'linear'
|
|
24
|
+
}] : [])];
|
|
25
|
+
const completeAxis = {};
|
|
26
|
+
allAxis.forEach((axis, axisIndex) => {
|
|
27
|
+
const isDefaultAxis = axisIndex === 0;
|
|
28
|
+
const [minData, maxData] = getAxisExtremum(axis, extremumGetters, isDefaultAxis, formattedSeries);
|
|
29
|
+
const range = getRange(drawingArea, axisName, axis.reverse);
|
|
30
|
+
if (isBandScaleConfig(axis)) {
|
|
31
|
+
const categoryGapRatio = axis.categoryGapRatio ?? DEFAULT_CATEGORY_GAP_RATIO;
|
|
32
|
+
const barGapRatio = axis.barGapRatio ?? DEFAULT_BAR_GAP_RATIO;
|
|
33
|
+
// Reverse range because ordinal scales are presented from top to bottom on y-axis
|
|
34
|
+
const scaleRange = axisName === 'x' ? range : [range[1], range[0]];
|
|
35
|
+
completeAxis[axis.id] = _extends({
|
|
36
|
+
categoryGapRatio,
|
|
37
|
+
barGapRatio
|
|
38
|
+
}, axis, {
|
|
39
|
+
scale: scaleBand(axis.data, scaleRange).paddingInner(categoryGapRatio).paddingOuter(categoryGapRatio / 2),
|
|
40
|
+
tickNumber: axis.data.length,
|
|
41
|
+
colorScale: axis.colorMap && (axis.colorMap.type === 'ordinal' ? getOrdinalColorScale(_extends({
|
|
42
|
+
values: axis.data
|
|
43
|
+
}, axis.colorMap)) : getColorScale(axis.colorMap))
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
if (isPointScaleConfig(axis)) {
|
|
47
|
+
const scaleRange = axisName === 'x' ? range : [...range].reverse();
|
|
48
|
+
completeAxis[axis.id] = _extends({}, axis, {
|
|
49
|
+
scale: scalePoint(axis.data, scaleRange),
|
|
50
|
+
tickNumber: axis.data.length,
|
|
51
|
+
colorScale: axis.colorMap && (axis.colorMap.type === 'ordinal' ? getOrdinalColorScale(_extends({
|
|
52
|
+
values: axis.data
|
|
53
|
+
}, axis.colorMap)) : getColorScale(axis.colorMap))
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
if (axis.scaleType === 'band' || axis.scaleType === 'point') {
|
|
57
|
+
// Could be merged with the two previous "if conditions" but then TS does not get that `axis.scaleType` can't be `band` or `point`.
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const scaleType = axis.scaleType ?? 'linear';
|
|
61
|
+
const extremums = [axis.min ?? minData, axis.max ?? maxData];
|
|
62
|
+
const tickNumber = getTickNumber(_extends({}, axis, {
|
|
63
|
+
range,
|
|
64
|
+
domain: extremums
|
|
65
|
+
}));
|
|
66
|
+
const scale = getScale(scaleType, extremums, range).nice(tickNumber);
|
|
67
|
+
const [minDomain, maxDomain] = scale.domain();
|
|
68
|
+
const domain = [axis.min ?? minDomain, axis.max ?? maxDomain];
|
|
69
|
+
completeAxis[axis.id] = _extends({}, axis, {
|
|
70
|
+
scaleType: scaleType,
|
|
71
|
+
scale: scale.domain(domain),
|
|
72
|
+
tickNumber,
|
|
73
|
+
colorScale: axis.colorMap && getColorScale(axis.colorMap)
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
return {
|
|
77
|
+
axis: completeAxis,
|
|
78
|
+
axisIds: allAxis.map(({
|
|
79
|
+
id
|
|
80
|
+
}) => id)
|
|
81
|
+
};
|
|
82
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const axisExtremumCallback = (acc, chartType, axis, getters, isDefaultAxis, formattedSeries) => {
|
|
2
|
+
const getter = getters[chartType];
|
|
3
|
+
const series = formattedSeries[chartType]?.series ?? {};
|
|
4
|
+
const [minChartTypeData, maxChartTypeData] = getter?.({
|
|
5
|
+
series,
|
|
6
|
+
axis,
|
|
7
|
+
isDefaultAxis
|
|
8
|
+
}) ?? [null, null];
|
|
9
|
+
const [minData, maxData] = acc;
|
|
10
|
+
if (minData === null || maxData === null) {
|
|
11
|
+
return [minChartTypeData, maxChartTypeData];
|
|
12
|
+
}
|
|
13
|
+
if (minChartTypeData === null || maxChartTypeData === null) {
|
|
14
|
+
return [minData, maxData];
|
|
15
|
+
}
|
|
16
|
+
return [Math.min(minChartTypeData, minData), Math.max(maxChartTypeData, maxData)];
|
|
17
|
+
};
|
|
18
|
+
export const getAxisExtremum = (axis, getters, isDefaultAxis, formattedSeries) => {
|
|
19
|
+
const charTypes = Object.keys(getters);
|
|
20
|
+
return charTypes.reduce((acc, charType) => axisExtremumCallback(acc, charType, axis, getters, isDefaultAxis, formattedSeries), [null, null]);
|
|
21
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { computeValue } from './computeValue';
|
|
2
|
+
import { normalizeAxis } from './normalizeAxis';
|
|
3
|
+
export * from './CartesianProvider';
|
|
4
|
+
export * from './CartesianContext';
|
|
5
|
+
export * from './useCartesianContext';
|
|
6
|
+
const cartesianProviderUtils = {
|
|
7
|
+
computeValue,
|
|
8
|
+
normalizeAxis
|
|
9
|
+
};
|
|
10
|
+
export { cartesianProviderUtils };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
export const normalizeAxis = (axis, dataset, axisName) => {
|
|
3
|
+
return axis?.map(axisConfig => {
|
|
4
|
+
const dataKey = axisConfig.dataKey;
|
|
5
|
+
if (dataKey === undefined || axisConfig.data !== undefined) {
|
|
6
|
+
return axisConfig;
|
|
7
|
+
}
|
|
8
|
+
if (dataset === undefined) {
|
|
9
|
+
throw Error(`MUI X Charts: ${axisName}-axis uses \`dataKey\` but no \`dataset\` is provided.`);
|
|
10
|
+
}
|
|
11
|
+
return _extends({}, axisConfig, {
|
|
12
|
+
data: dataset.map(d => d[dataKey])
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
export const ColorContext = /*#__PURE__*/React.createContext({});
|
|
4
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
5
|
+
ColorContext.displayName = 'ColorContext';
|
|
6
|
+
}
|
|
7
|
+
export function ColorProvider(props) {
|
|
8
|
+
const {
|
|
9
|
+
colorProcessors,
|
|
10
|
+
children
|
|
11
|
+
} = props;
|
|
12
|
+
return /*#__PURE__*/_jsx(ColorContext.Provider, {
|
|
13
|
+
value: colorProcessors,
|
|
14
|
+
children: children
|
|
15
|
+
});
|
|
16
|
+
}
|
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';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { InteractionContext } from '../context/InteractionProvider';
|
|
3
|
-
import {
|
|
3
|
+
import { useCartesianContext } from '../context/CartesianProvider';
|
|
4
4
|
import { isBandScale } from '../internals/isBandScale';
|
|
5
5
|
import { getSVGPoint } from '../internals/utils';
|
|
6
6
|
import { useSvgRef } from './useSvgRef';
|
|
@@ -21,7 +21,7 @@ export const useAxisEvents = disableAxisListener => {
|
|
|
21
21
|
yAxis,
|
|
22
22
|
xAxisIds,
|
|
23
23
|
yAxisIds
|
|
24
|
-
} =
|
|
24
|
+
} = useCartesianContext();
|
|
25
25
|
const {
|
|
26
26
|
dispatch
|
|
27
27
|
} = React.useContext(InteractionContext);
|
|
@@ -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 { useCartesianContext } from '../context/CartesianProvider';
|
|
3
|
+
import { ZAxisContext } from '../context/ZAxisContextProvider';
|
|
4
|
+
export function useXColorScale(identifier) {
|
|
5
|
+
const {
|
|
6
|
+
xAxis,
|
|
7
|
+
xAxisIds
|
|
8
|
+
} = useCartesianContext();
|
|
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
|
+
} = useCartesianContext();
|
|
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
|
+
}
|
|
@@ -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({
|
package/modern/hooks/useScale.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { CartesianContext } from '../context/CartesianContextProvider';
|
|
1
|
+
import { useCartesianContext } from '../context/CartesianProvider';
|
|
3
2
|
import { isBandScale } from '../internals/isBandScale';
|
|
4
3
|
/**
|
|
5
4
|
* For a given scale return a function that map value to their position.
|
|
@@ -17,7 +16,7 @@ export function useXScale(identifier) {
|
|
|
17
16
|
const {
|
|
18
17
|
xAxis,
|
|
19
18
|
xAxisIds
|
|
20
|
-
} =
|
|
19
|
+
} = useCartesianContext();
|
|
21
20
|
const id = typeof identifier === 'string' ? identifier : xAxisIds[identifier ?? 0];
|
|
22
21
|
return xAxis[id].scale;
|
|
23
22
|
}
|
|
@@ -25,7 +24,7 @@ export function useYScale(identifier) {
|
|
|
25
24
|
const {
|
|
26
25
|
yAxis,
|
|
27
26
|
yAxisIds
|
|
28
|
-
} =
|
|
27
|
+
} = useCartesianContext();
|
|
29
28
|
const id = typeof identifier === 'string' ? identifier : yAxisIds[identifier ?? 0];
|
|
30
29
|
return yAxis[id].scale;
|
|
31
30
|
}
|
package/modern/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { useCartesianContext } from '../../../context/CartesianProvider';
|
|
3
3
|
import { DrawingContext } from '../../../context/DrawingProvider';
|
|
4
4
|
import { useDrawingArea } from '../../../hooks';
|
|
5
5
|
import ChartsPiecewiseGradient from './ChartsPiecewiseGradient';
|
|
@@ -28,7 +28,7 @@ export function ChartsAxesGradients() {
|
|
|
28
28
|
xAxis,
|
|
29
29
|
yAxisIds,
|
|
30
30
|
yAxis
|
|
31
|
-
} =
|
|
31
|
+
} = useCartesianContext();
|
|
32
32
|
return /*#__PURE__*/_jsxs("defs", {
|
|
33
33
|
children: [yAxisIds.filter(axisId => yAxis[axisId].colorMap !== undefined).map(axisId => {
|
|
34
34
|
const gradientId = getGradientId(axisId, 'y');
|
|
@@ -1 +1,31 @@
|
|
|
1
|
-
|
|
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
|
+
export { useChartContainerHooks } from '../ChartContainer/useChartContainerHooks';
|
|
10
|
+
export { useScatterChartProps } from '../ScatterChart/useScatterChartProps';
|
|
11
|
+
export { useLineChartProps } from '../LineChart/useLineChartProps';
|
|
12
|
+
export { useBarChartProps } from '../BarChart/useBarChartProps';
|
|
13
|
+
|
|
14
|
+
// utils
|
|
15
|
+
export * from './defaultizeValueFormatter';
|
|
16
|
+
export * from './configInit';
|
|
17
|
+
|
|
18
|
+
// contexts
|
|
19
|
+
|
|
20
|
+
export * from '../context/CartesianProvider';
|
|
21
|
+
export * from '../context/DrawingProvider';
|
|
22
|
+
export * from '../context/ColorProvider';
|
|
23
|
+
export * from '../context/InteractionProvider';
|
|
24
|
+
export * from '../context/SeriesContextProvider';
|
|
25
|
+
export * from '../context/ZAxisContextProvider';
|
|
26
|
+
// series configuration
|
|
27
|
+
export * from '../models/seriesType/config';
|
|
28
|
+
export * from '../models/seriesType/common';
|
|
29
|
+
export * from '../models/helpers';
|
|
30
|
+
export * from '../models/z-axis';
|
|
31
|
+
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mui/x-charts",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.7.1",
|
|
4
4
|
"description": "The community edition of the Charts components (MUI X).",
|
|
5
5
|
"author": "MUI Team",
|
|
6
6
|
"main": "./index.js",
|
|
@@ -29,10 +29,10 @@
|
|
|
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
|
-
"@mui/system": "^5.15.
|
|
35
|
-
"@mui/utils": "^5.15.
|
|
34
|
+
"@mui/system": "^5.15.20",
|
|
35
|
+
"@mui/utils": "^5.15.20",
|
|
36
36
|
"@react-spring/rafz": "^9.7.3",
|
|
37
37
|
"@react-spring/web": "^9.7.3",
|
|
38
38
|
"clsx": "^2.1.1",
|