@mui/x-charts 8.0.0-alpha.0 → 8.0.0-alpha.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/AnimatedBarElement.d.ts +15 -0
- package/BarChart/AnimatedBarElement.js +21 -0
- package/BarChart/BarChart.d.ts +4 -9
- package/BarChart/BarChart.js +3 -31
- package/BarChart/BarElement.d.ts +5 -1342
- package/BarChart/BarElement.js +10 -20
- package/BarChart/BarPlot.js +12 -2
- package/BarChart/useBarChartProps.d.ts +0 -2
- package/BarChart/useBarChartProps.js +2 -8
- package/CHANGELOG.md +429 -5
- package/ChartContainer/ChartContainer.d.ts +2 -19
- package/ChartContainer/ChartContainer.js +10 -20
- package/ChartContainer/ResizableContainer.d.ts +17 -4
- package/ChartContainer/ResizableContainer.js +36 -2
- package/ChartContainer/useChartContainerProps.d.ts +6 -7
- package/ChartContainer/useChartContainerProps.js +14 -28
- package/ChartsAxisHighlight/ChartsAxisHighlight.d.ts +1 -17
- package/ChartsAxisHighlight/ChartsAxisHighlight.js +10 -96
- package/ChartsAxisHighlight/ChartsAxisHighlight.types.d.ts +5 -0
- package/ChartsAxisHighlight/ChartsAxisHighlight.types.js +1 -0
- package/ChartsAxisHighlight/ChartsAxisHighlightPath.d.ts +6 -0
- package/ChartsAxisHighlight/ChartsAxisHighlightPath.js +34 -0
- package/ChartsAxisHighlight/ChartsXAxisHighlight.d.ts +10 -0
- package/ChartsAxisHighlight/ChartsXAxisHighlight.js +53 -0
- package/ChartsAxisHighlight/ChartsYAxisHighlight.d.ts +10 -0
- package/ChartsAxisHighlight/ChartsYAxisHighlight.js +53 -0
- package/ChartsAxisHighlight/chartsAxisHighlightClasses.d.ts +7 -0
- package/ChartsAxisHighlight/chartsAxisHighlightClasses.js +6 -0
- package/ChartsAxisHighlight/index.d.ts +3 -0
- package/ChartsAxisHighlight/index.js +4 -1
- package/ChartsGrid/ChartsGrid.js +1 -1
- package/ChartsGrid/ChartsHorizontalGrid.d.ts +2 -2
- package/ChartsGrid/ChartsHorizontalGrid.js +3 -3
- package/ChartsGrid/ChartsVerticalGrid.d.ts +2 -2
- package/ChartsGrid/ChartsVerticalGrid.js +3 -3
- package/ChartsLegend/LegendPerItem.d.ts +2 -2
- package/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +9 -7
- package/ChartsSurface/ChartsSurface.d.ts +0 -15
- package/ChartsSurface/ChartsSurface.js +35 -34
- package/ChartsTooltip/ChartTooltip.types.d.ts +15 -0
- package/ChartsTooltip/ChartTooltip.types.js +1 -0
- package/ChartsTooltip/ChartsAxisTooltipContent.d.ts +7 -39
- package/ChartsTooltip/ChartsAxisTooltipContent.js +83 -72
- package/ChartsTooltip/ChartsItemTooltipContent.d.ts +5 -28
- package/ChartsTooltip/ChartsItemTooltipContent.js +54 -44
- package/ChartsTooltip/ChartsTooltip.d.ts +3 -69
- package/ChartsTooltip/ChartsTooltip.js +161 -145
- package/ChartsTooltip/ChartsTooltipContainer.d.ts +33 -0
- package/ChartsTooltip/ChartsTooltipContainer.js +298 -0
- package/ChartsTooltip/chartsTooltipClasses.d.ts +1 -0
- package/ChartsTooltip/chartsTooltipClasses.js +18 -2
- package/ChartsTooltip/index.d.ts +3 -3
- package/ChartsTooltip/index.js +2 -3
- package/ChartsTooltip/useAxisTooltip.d.ts +2 -2
- package/ChartsTooltip/useAxisTooltip.js +19 -19
- package/ChartsTooltip/useItemTooltip.d.ts +1 -1
- package/ChartsTooltip/useItemTooltip.js +5 -4
- package/ChartsTooltip/utils.d.ts +0 -3
- package/ChartsTooltip/utils.js +0 -8
- package/ChartsVoronoiHandler/ChartsVoronoiHandler.js +47 -34
- package/Gauge/Gauge.d.ts +1 -1
- package/Gauge/Gauge.js +0 -6
- package/Gauge/GaugeContainer.d.ts +3 -3
- package/Gauge/GaugeContainer.js +60 -61
- package/LineChart/AnimatedArea.d.ts +0 -1333
- package/LineChart/AnimatedArea.js +9 -18
- package/LineChart/AnimatedLine.d.ts +0 -1333
- package/LineChart/AnimatedLine.js +9 -20
- package/LineChart/AreaPlot.js +12 -2
- package/LineChart/CircleMarkElement.js +6 -5
- package/LineChart/LineChart.d.ts +4 -10
- package/LineChart/LineChart.js +3 -32
- package/LineChart/LineHighlightPlot.js +6 -5
- package/LineChart/LinePlot.js +12 -2
- package/LineChart/MarkElement.js +6 -5
- package/LineChart/useLineChartProps.d.ts +0 -2
- package/LineChart/useLineChartProps.js +2 -8
- package/PieChart/PieChart.d.ts +3 -9
- package/PieChart/PieChart.js +5 -37
- package/PieChart/PiePlot.js +2 -2
- package/PieChart/getPieCoordinates.d.ts +2 -2
- package/README.md +2 -2
- package/ScatterChart/Scatter.js +6 -5
- package/ScatterChart/ScatterChart.d.ts +4 -10
- package/ScatterChart/ScatterChart.js +5 -32
- package/ScatterChart/useScatterChartProps.d.ts +0 -2
- package/ScatterChart/useScatterChartProps.js +1 -9
- package/SparkLineChart/SparkLineChart.d.ts +3 -4
- package/SparkLineChart/SparkLineChart.js +4 -31
- package/context/ChartDataProvider/ChartDataProvider.d.ts +9 -19
- package/context/ChartDataProvider/ChartDataProvider.js +30 -43
- package/context/ChartDataProvider/useChartDataProviderProps.d.ts +7 -10
- package/context/ChartDataProvider/useChartDataProviderProps.js +22 -42
- package/context/{DrawingProvider.d.ts → DrawingAreaProvider/DrawingArea.types.d.ts} +3 -14
- package/context/DrawingAreaProvider/DrawingArea.types.js +1 -0
- package/context/DrawingAreaProvider/DrawingAreaContext.d.ts +8 -0
- package/context/DrawingAreaProvider/DrawingAreaContext.js +16 -0
- package/context/DrawingAreaProvider/DrawingAreaProvider.d.ts +3 -0
- package/context/{DrawingProvider.js → DrawingAreaProvider/DrawingAreaProvider.js} +11 -41
- package/context/DrawingAreaProvider/index.d.ts +3 -0
- package/context/DrawingAreaProvider/index.js +3 -0
- package/context/InteractionProvider.d.ts +5 -48
- package/context/InteractionProvider.js +8 -64
- package/context/InteractionSelectors.d.ts +359 -0
- package/context/InteractionSelectors.js +12 -0
- package/context/SizeProvider/Size.types.d.ts +30 -0
- package/context/SizeProvider/Size.types.js +1 -0
- package/context/SizeProvider/SizeContext.d.ts +4 -0
- package/context/SizeProvider/SizeContext.js +13 -0
- package/context/SizeProvider/SizeProvider.d.ts +11 -0
- package/context/SizeProvider/SizeProvider.js +26 -0
- package/context/SizeProvider/index.d.ts +4 -0
- package/context/SizeProvider/index.js +4 -0
- package/{ChartContainer → context/SizeProvider}/useChartContainerDimensions.d.ts +4 -1
- package/{modern/ChartContainer → context/SizeProvider}/useChartContainerDimensions.js +11 -5
- package/context/SizeProvider/useSize.d.ts +5 -0
- package/context/SizeProvider/useSize.js +13 -0
- package/context/SvgRefProvider/SvgRef.types.d.ts +8 -0
- package/context/SvgRefProvider/SvgRef.types.js +1 -0
- package/context/SvgRefProvider/SvgRefContext.d.ts +4 -0
- package/context/SvgRefProvider/SvgRefContext.js +17 -0
- package/context/SvgRefProvider/SvgRefProvider.d.ts +3 -0
- package/context/SvgRefProvider/SvgRefProvider.js +24 -0
- package/context/SvgRefProvider/index.d.ts +4 -0
- package/context/SvgRefProvider/index.js +4 -0
- package/context/SvgRefProvider/useSurfaceRef.d.ts +2 -0
- package/context/SvgRefProvider/useSurfaceRef.js +14 -0
- package/context/index.d.ts +2 -0
- package/context/index.js +2 -1
- package/hooks/useAxisEvents.js +32 -19
- package/hooks/useChartId.js +2 -2
- package/hooks/useDrawingArea.d.ts +2 -2
- package/hooks/useDrawingArea.js +2 -2
- package/hooks/useInteractionItemProps.js +19 -12
- package/hooks/useSvgRef.js +3 -3
- package/index.js +1 -1
- package/internals/components/ChartsAxesGradients/ChartsAxesGradients.d.ts +1 -1
- package/internals/components/ChartsAxesGradients/ChartsAxesGradients.js +9 -4
- package/internals/computeAxisValue.d.ts +2 -2
- package/internals/index.d.ts +3 -2
- package/internals/index.js +3 -2
- package/internals/plugins/models/index.d.ts +35 -0
- package/internals/plugins/models/index.js +1 -0
- package/internals/plugins/utils/ChartStore.d.ts +12 -0
- package/internals/plugins/utils/ChartStore.js +26 -0
- package/internals/plugins/utils/ChartsStore.d.ts +12 -0
- package/internals/plugins/utils/ChartsStore.js +26 -0
- package/internals/plugins/utils/selectors.d.ts +9 -0
- package/internals/plugins/utils/selectors.js +37 -0
- package/internals/useCharts.d.ts +6 -0
- package/internals/useCharts.js +29 -0
- package/internals/useSelector.d.ts +4 -0
- package/internals/useSelector.js +6 -0
- package/internals/useStore.d.ts +2 -0
- package/internals/useStore.js +17 -0
- package/modern/BarChart/AnimatedBarElement.js +21 -0
- package/modern/BarChart/BarChart.js +3 -31
- package/modern/BarChart/BarElement.js +10 -20
- package/modern/BarChart/BarPlot.js +12 -2
- package/modern/BarChart/useBarChartProps.js +2 -8
- package/modern/ChartContainer/ChartContainer.js +10 -20
- package/modern/ChartContainer/ResizableContainer.js +36 -2
- package/modern/ChartContainer/useChartContainerProps.js +14 -28
- package/modern/ChartsAxisHighlight/ChartsAxisHighlight.js +10 -96
- package/modern/ChartsAxisHighlight/ChartsAxisHighlight.types.js +1 -0
- package/modern/ChartsAxisHighlight/ChartsAxisHighlightPath.js +34 -0
- package/modern/ChartsAxisHighlight/ChartsXAxisHighlight.js +53 -0
- package/modern/ChartsAxisHighlight/ChartsYAxisHighlight.js +53 -0
- package/modern/ChartsAxisHighlight/chartsAxisHighlightClasses.js +6 -0
- package/modern/ChartsAxisHighlight/index.js +4 -1
- package/modern/ChartsGrid/ChartsGrid.js +1 -1
- package/modern/ChartsGrid/ChartsHorizontalGrid.js +3 -3
- package/modern/ChartsGrid/ChartsVerticalGrid.js +3 -3
- package/modern/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +9 -7
- package/modern/ChartsSurface/ChartsSurface.js +35 -34
- package/modern/ChartsTooltip/ChartTooltip.types.js +1 -0
- package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +83 -72
- package/modern/ChartsTooltip/ChartsItemTooltipContent.js +54 -44
- package/modern/ChartsTooltip/ChartsTooltip.js +161 -145
- package/modern/ChartsTooltip/ChartsTooltipContainer.js +298 -0
- package/modern/ChartsTooltip/chartsTooltipClasses.js +18 -2
- package/modern/ChartsTooltip/index.js +2 -3
- package/modern/ChartsTooltip/useAxisTooltip.js +19 -19
- package/modern/ChartsTooltip/useItemTooltip.js +5 -4
- package/modern/ChartsTooltip/utils.js +0 -8
- package/modern/ChartsVoronoiHandler/ChartsVoronoiHandler.js +47 -34
- package/modern/Gauge/Gauge.js +0 -6
- package/modern/Gauge/GaugeContainer.js +60 -61
- package/modern/LineChart/AnimatedArea.js +9 -18
- package/modern/LineChart/AnimatedLine.js +9 -20
- package/modern/LineChart/AreaPlot.js +12 -2
- package/modern/LineChart/CircleMarkElement.js +6 -5
- package/modern/LineChart/LineChart.js +3 -32
- package/modern/LineChart/LineHighlightPlot.js +6 -5
- package/modern/LineChart/LinePlot.js +12 -2
- package/modern/LineChart/MarkElement.js +6 -5
- package/modern/LineChart/useLineChartProps.js +2 -8
- package/modern/PieChart/PieChart.js +5 -37
- package/modern/PieChart/PiePlot.js +2 -2
- package/modern/ScatterChart/Scatter.js +6 -5
- package/modern/ScatterChart/ScatterChart.js +5 -32
- package/modern/ScatterChart/useScatterChartProps.js +1 -9
- package/modern/SparkLineChart/SparkLineChart.js +4 -31
- package/modern/context/ChartDataProvider/ChartDataProvider.js +30 -43
- package/modern/context/ChartDataProvider/useChartDataProviderProps.js +22 -42
- package/modern/context/DrawingAreaProvider/DrawingArea.types.js +1 -0
- package/modern/context/DrawingAreaProvider/DrawingAreaContext.js +16 -0
- package/modern/context/{DrawingProvider.js → DrawingAreaProvider/DrawingAreaProvider.js} +11 -41
- package/modern/context/DrawingAreaProvider/index.js +3 -0
- package/modern/context/InteractionProvider.js +8 -64
- package/modern/context/InteractionSelectors.js +12 -0
- package/modern/context/SizeProvider/Size.types.js +1 -0
- package/modern/context/SizeProvider/SizeContext.js +13 -0
- package/modern/context/SizeProvider/SizeProvider.js +26 -0
- package/modern/context/SizeProvider/index.js +4 -0
- package/{ChartContainer → modern/context/SizeProvider}/useChartContainerDimensions.js +11 -5
- package/modern/context/SizeProvider/useSize.js +13 -0
- package/modern/context/SvgRefProvider/SvgRef.types.js +1 -0
- package/modern/context/SvgRefProvider/SvgRefContext.js +17 -0
- package/modern/context/SvgRefProvider/SvgRefProvider.js +24 -0
- package/modern/context/SvgRefProvider/index.js +4 -0
- package/modern/context/SvgRefProvider/useSurfaceRef.js +14 -0
- package/modern/context/index.js +2 -1
- package/modern/hooks/useAxisEvents.js +32 -19
- package/modern/hooks/useChartId.js +2 -2
- package/modern/hooks/useDrawingArea.js +2 -2
- package/modern/hooks/useInteractionItemProps.js +19 -12
- package/modern/hooks/useSvgRef.js +3 -3
- package/modern/index.js +1 -1
- package/modern/internals/components/ChartsAxesGradients/ChartsAxesGradients.js +9 -4
- package/modern/internals/index.js +3 -2
- package/modern/internals/plugins/models/index.js +1 -0
- package/modern/internals/plugins/utils/ChartStore.js +26 -0
- package/modern/internals/plugins/utils/ChartsStore.js +26 -0
- package/modern/internals/plugins/utils/selectors.js +37 -0
- package/modern/internals/useCharts.js +29 -0
- package/modern/internals/useSelector.js +6 -0
- package/modern/internals/useStore.js +17 -0
- package/node/BarChart/AnimatedBarElement.js +28 -0
- package/node/BarChart/BarChart.js +3 -31
- package/node/BarChart/BarElement.js +11 -21
- package/node/BarChart/BarPlot.js +11 -1
- package/node/BarChart/useBarChartProps.js +2 -8
- package/node/ChartContainer/ChartContainer.js +10 -20
- package/node/ChartContainer/ResizableContainer.js +39 -3
- package/node/ChartContainer/useChartContainerProps.js +14 -28
- package/node/ChartsAxisHighlight/ChartsAxisHighlight.js +12 -100
- package/node/ChartsAxisHighlight/ChartsAxisHighlight.types.js +5 -0
- package/node/ChartsAxisHighlight/ChartsAxisHighlightPath.js +40 -0
- package/node/ChartsAxisHighlight/ChartsXAxisHighlight.js +57 -0
- package/node/ChartsAxisHighlight/ChartsYAxisHighlight.js +57 -0
- package/node/ChartsAxisHighlight/chartsAxisHighlightClasses.js +14 -0
- package/node/ChartsAxisHighlight/index.js +33 -0
- package/node/ChartsGrid/ChartsGrid.js +2 -2
- package/node/ChartsGrid/ChartsHorizontalGrid.js +4 -4
- package/node/ChartsGrid/ChartsVerticalGrid.js +4 -4
- package/node/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +9 -7
- package/node/ChartsSurface/ChartsSurface.js +35 -34
- package/node/ChartsTooltip/ChartTooltip.types.js +5 -0
- package/node/ChartsTooltip/ChartsAxisTooltipContent.js +83 -73
- package/node/ChartsTooltip/ChartsItemTooltipContent.js +54 -45
- package/node/ChartsTooltip/ChartsTooltip.js +160 -144
- package/node/ChartsTooltip/ChartsTooltipContainer.js +304 -0
- package/node/ChartsTooltip/chartsTooltipClasses.js +22 -3
- package/node/ChartsTooltip/index.js +19 -28
- package/node/ChartsTooltip/useAxisTooltip.js +19 -19
- package/node/ChartsTooltip/useItemTooltip.js +5 -4
- package/node/ChartsTooltip/utils.js +0 -9
- package/node/ChartsVoronoiHandler/ChartsVoronoiHandler.js +48 -35
- package/node/Gauge/Gauge.js +0 -6
- package/node/Gauge/GaugeContainer.js +60 -61
- package/node/LineChart/AnimatedArea.js +9 -19
- package/node/LineChart/AnimatedLine.js +9 -21
- package/node/LineChart/AreaPlot.js +11 -1
- package/node/LineChart/CircleMarkElement.js +6 -5
- package/node/LineChart/LineChart.js +3 -32
- package/node/LineChart/LineHighlightPlot.js +6 -5
- package/node/LineChart/LinePlot.js +11 -1
- package/node/LineChart/MarkElement.js +6 -5
- package/node/LineChart/useLineChartProps.js +2 -8
- package/node/PieChart/PieChart.js +5 -37
- package/node/PieChart/PiePlot.js +2 -2
- package/node/ScatterChart/Scatter.js +6 -5
- package/node/ScatterChart/ScatterChart.js +5 -32
- package/node/ScatterChart/useScatterChartProps.js +1 -9
- package/node/SparkLineChart/SparkLineChart.js +4 -31
- package/node/context/ChartDataProvider/ChartDataProvider.js +30 -43
- package/node/context/ChartDataProvider/useChartDataProviderProps.js +22 -44
- package/node/context/DrawingAreaProvider/DrawingArea.types.js +5 -0
- package/node/context/DrawingAreaProvider/DrawingAreaContext.js +22 -0
- package/node/context/{DrawingProvider.js → DrawingAreaProvider/DrawingAreaProvider.js} +12 -44
- package/node/context/DrawingAreaProvider/index.js +38 -0
- package/node/context/InteractionProvider.js +9 -66
- package/node/context/InteractionSelectors.js +18 -0
- package/node/context/SizeProvider/Size.types.js +5 -0
- package/node/context/SizeProvider/SizeContext.js +20 -0
- package/node/context/SizeProvider/SizeProvider.js +29 -0
- package/node/context/SizeProvider/index.js +49 -0
- package/node/{ChartContainer → context/SizeProvider}/useChartContainerDimensions.js +11 -5
- package/node/context/SizeProvider/useSize.js +20 -0
- package/node/context/SvgRefProvider/SvgRef.types.js +5 -0
- package/node/context/SvgRefProvider/SvgRefContext.js +23 -0
- package/node/context/SvgRefProvider/SvgRefProvider.js +31 -0
- package/node/context/SvgRefProvider/index.js +49 -0
- package/node/context/SvgRefProvider/useSurfaceRef.js +20 -0
- package/node/context/index.js +10 -2
- package/node/hooks/useAxisEvents.js +33 -19
- package/node/hooks/useChartId.js +2 -2
- package/node/hooks/useDrawingArea.js +2 -2
- package/node/hooks/useInteractionItemProps.js +20 -13
- package/node/hooks/useSvgRef.js +3 -3
- package/node/index.js +1 -1
- package/node/internals/components/ChartsAxesGradients/ChartsAxesGradients.js +9 -4
- package/node/internals/index.js +28 -16
- package/node/internals/plugins/models/index.js +5 -0
- package/node/internals/plugins/utils/ChartStore.js +33 -0
- package/node/internals/plugins/utils/ChartsStore.js +33 -0
- package/node/internals/plugins/utils/selectors.js +44 -0
- package/node/internals/useCharts.js +36 -0
- package/node/internals/useSelector.js +13 -0
- package/node/internals/useStore.js +24 -0
- package/package.json +7 -5
- package/themeAugmentation/props.d.ts +1 -2
- package/ChartsTooltip/DefaultChartsAxisTooltipContent.d.ts +0 -7
- package/ChartsTooltip/DefaultChartsAxisTooltipContent.js +0 -123
- package/ChartsTooltip/DefaultChartsItemTooltipContent.d.ts +0 -8
- package/ChartsTooltip/DefaultChartsItemTooltipContent.js +0 -92
- package/modern/ChartsTooltip/DefaultChartsAxisTooltipContent.js +0 -123
- package/modern/ChartsTooltip/DefaultChartsItemTooltipContent.js +0 -92
- package/node/ChartsTooltip/DefaultChartsAxisTooltipContent.js +0 -129
- package/node/ChartsTooltip/DefaultChartsItemTooltipContent.js +0 -98
- /package/ChartsGrid/{styledCommonents.d.ts → styledComponents.d.ts} +0 -0
- /package/ChartsGrid/{styledCommonents.js → styledComponents.js} +0 -0
- /package/modern/ChartsGrid/{styledCommonents.js → styledComponents.js} +0 -0
- /package/node/ChartsGrid/{styledCommonents.js → styledComponents.js} +0 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { SizeContext } from "./SizeContext.js";
|
|
5
|
+
import { useChartContainerDimensions } from "./useChartContainerDimensions.js";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The size provider.
|
|
9
|
+
*
|
|
10
|
+
* This differs from the DrawingProvider in that it provides the full size of the container.
|
|
11
|
+
*
|
|
12
|
+
* This provider is also responsible for resolving the size of the container before rendering and if the parent size changes.
|
|
13
|
+
*/
|
|
14
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
15
|
+
function SizeProvider(props) {
|
|
16
|
+
const dimensions = useChartContainerDimensions(props.width, props.height);
|
|
17
|
+
const value = React.useMemo(() => ({
|
|
18
|
+
isInitialized: true,
|
|
19
|
+
data: dimensions
|
|
20
|
+
}), [dimensions]);
|
|
21
|
+
return /*#__PURE__*/_jsx(SizeContext.Provider, {
|
|
22
|
+
value: value,
|
|
23
|
+
children: props.children
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
export { SizeProvider };
|
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
|
|
6
6
|
import ownerWindow from '@mui/utils/ownerWindow';
|
|
7
|
-
|
|
7
|
+
const MAX_COMPUTE_RUN = 10;
|
|
8
|
+
export const useChartContainerDimensions = (inWidth, inHeight) => {
|
|
8
9
|
const hasInSize = inWidth !== undefined && inHeight !== undefined;
|
|
9
10
|
const stateRef = React.useRef({
|
|
10
11
|
displayError: false,
|
|
@@ -42,7 +43,7 @@ export const useChartContainerDimensions = (inWidth, inHeight, resolveSizeBefore
|
|
|
42
43
|
// https://github.com/mui/mui-x/issues/13477#issuecomment-2336634785
|
|
43
44
|
useEnhancedEffect(() => {
|
|
44
45
|
// computeRun is used to avoid infinite loops.
|
|
45
|
-
if (hasInSize || !
|
|
46
|
+
if (hasInSize || !stateRef.current.initialCompute || stateRef.current.computeRun > MAX_COMPUTE_RUN) {
|
|
46
47
|
return;
|
|
47
48
|
}
|
|
48
49
|
const computedSize = computeSize();
|
|
@@ -51,7 +52,7 @@ export const useChartContainerDimensions = (inWidth, inHeight, resolveSizeBefore
|
|
|
51
52
|
} else if (stateRef.current.initialCompute) {
|
|
52
53
|
stateRef.current.initialCompute = false;
|
|
53
54
|
}
|
|
54
|
-
}, [width, height, computeSize,
|
|
55
|
+
}, [width, height, computeSize, hasInSize]);
|
|
55
56
|
useEnhancedEffect(() => {
|
|
56
57
|
if (hasInSize) {
|
|
57
58
|
return () => {};
|
|
@@ -90,9 +91,14 @@ export const useChartContainerDimensions = (inWidth, inHeight, resolveSizeBefore
|
|
|
90
91
|
stateRef.current.displayError = false;
|
|
91
92
|
}
|
|
92
93
|
}
|
|
94
|
+
const finalWidth = inWidth ?? width;
|
|
95
|
+
const finalHeight = inHeight ?? height;
|
|
93
96
|
return {
|
|
94
97
|
containerRef: rootRef,
|
|
95
|
-
width:
|
|
96
|
-
height:
|
|
98
|
+
width: finalWidth,
|
|
99
|
+
height: finalHeight,
|
|
100
|
+
hasIntrinsicSize: finalWidth > 0 && finalHeight > 0,
|
|
101
|
+
inWidth,
|
|
102
|
+
inHeight
|
|
97
103
|
};
|
|
98
104
|
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { SizeContext } from "./SizeContext.js";
|
|
5
|
+
/**
|
|
6
|
+
* Returns the size of the chart. And the ref of the container element that the chart is rendered in.
|
|
7
|
+
*/
|
|
8
|
+
export const useSize = () => {
|
|
9
|
+
const {
|
|
10
|
+
data
|
|
11
|
+
} = React.useContext(SizeContext);
|
|
12
|
+
return data;
|
|
13
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
export const SvgRefContext = /*#__PURE__*/React.createContext({
|
|
5
|
+
isInitialized: false,
|
|
6
|
+
data: {
|
|
7
|
+
svgRef: {
|
|
8
|
+
current: null
|
|
9
|
+
},
|
|
10
|
+
surfaceRef: {
|
|
11
|
+
current: null
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
16
|
+
SvgRefContext.displayName = 'SvgRefContext';
|
|
17
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import useForkRef from '@mui/utils/useForkRef';
|
|
5
|
+
import { SvgRefContext } from "./SvgRefContext.js";
|
|
6
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
7
|
+
export function SvgRefProvider(props) {
|
|
8
|
+
const {
|
|
9
|
+
children
|
|
10
|
+
} = props;
|
|
11
|
+
const svgRef = React.useRef(null);
|
|
12
|
+
const surfaceRef = useForkRef(svgRef);
|
|
13
|
+
const refValue = React.useMemo(() => ({
|
|
14
|
+
isInitialized: true,
|
|
15
|
+
data: {
|
|
16
|
+
svgRef,
|
|
17
|
+
surfaceRef
|
|
18
|
+
}
|
|
19
|
+
}), [svgRef, surfaceRef]);
|
|
20
|
+
return /*#__PURE__*/_jsx(SvgRefContext.Provider, {
|
|
21
|
+
value: refValue,
|
|
22
|
+
children: children
|
|
23
|
+
});
|
|
24
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { SvgRefContext } from "./SvgRefContext.js";
|
|
5
|
+
export function useSurfaceRef() {
|
|
6
|
+
const {
|
|
7
|
+
isInitialized,
|
|
8
|
+
data
|
|
9
|
+
} = React.useContext(SvgRefContext);
|
|
10
|
+
if (!isInitialized) {
|
|
11
|
+
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'));
|
|
12
|
+
}
|
|
13
|
+
return data.surfaceRef;
|
|
14
|
+
}
|
package/modern/context/index.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
3
4
|
import * as React from 'react';
|
|
4
|
-
import { InteractionContext } from "../context/InteractionProvider.js";
|
|
5
5
|
import { useCartesianContext } from "../context/CartesianProvider/index.js";
|
|
6
6
|
import { isBandScale } from "../internals/isBandScale.js";
|
|
7
7
|
import { getSVGPoint } from "../internals/getSVGPoint.js";
|
|
8
8
|
import { useSvgRef } from "./useSvgRef.js";
|
|
9
9
|
import { useDrawingArea } from "./useDrawingArea.js";
|
|
10
|
+
import { useStore } from "../internals/useStore.js";
|
|
10
11
|
function getAsANumber(value) {
|
|
11
12
|
return value instanceof Date ? value.getTime() : value;
|
|
12
13
|
}
|
|
@@ -19,9 +20,7 @@ export const useAxisEvents = disableAxisListener => {
|
|
|
19
20
|
xAxisIds,
|
|
20
21
|
yAxisIds
|
|
21
22
|
} = useCartesianContext();
|
|
22
|
-
const
|
|
23
|
-
dispatch
|
|
24
|
-
} = React.useContext(InteractionContext);
|
|
23
|
+
const store = useStore(disableAxisListener);
|
|
25
24
|
const usedXAxis = xAxisIds[0];
|
|
26
25
|
const usedYAxis = yAxisIds[0];
|
|
27
26
|
|
|
@@ -33,7 +32,7 @@ export const useAxisEvents = disableAxisListener => {
|
|
|
33
32
|
});
|
|
34
33
|
React.useEffect(() => {
|
|
35
34
|
const element = svgRef.current;
|
|
36
|
-
if (element === null || disableAxisListener) {
|
|
35
|
+
if (element === null || disableAxisListener || !store) {
|
|
37
36
|
return () => {};
|
|
38
37
|
}
|
|
39
38
|
function getNewAxisState(axisConfig, mouseValue) {
|
|
@@ -92,9 +91,15 @@ export const useAxisEvents = disableAxisListener => {
|
|
|
92
91
|
x: -1,
|
|
93
92
|
y: -1
|
|
94
93
|
};
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
94
|
+
store.update(prev => _extends({}, prev, {
|
|
95
|
+
interaction: {
|
|
96
|
+
item: null,
|
|
97
|
+
axis: {
|
|
98
|
+
x: null,
|
|
99
|
+
y: null
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}));
|
|
98
103
|
};
|
|
99
104
|
const handleMove = event => {
|
|
100
105
|
const target = 'targetTouches' in event ? event.targetTouches[0] : event;
|
|
@@ -105,9 +110,15 @@ export const useAxisEvents = disableAxisListener => {
|
|
|
105
110
|
targetElement: event.target
|
|
106
111
|
})) {
|
|
107
112
|
if (mousePosition.current.isInChart) {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
113
|
+
store.update(prev => _extends({}, prev, {
|
|
114
|
+
interaction: {
|
|
115
|
+
item: null,
|
|
116
|
+
axis: {
|
|
117
|
+
x: null,
|
|
118
|
+
y: null
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}));
|
|
111
122
|
mousePosition.current.isInChart = false;
|
|
112
123
|
}
|
|
113
124
|
return;
|
|
@@ -115,13 +126,15 @@ export const useAxisEvents = disableAxisListener => {
|
|
|
115
126
|
mousePosition.current.isInChart = true;
|
|
116
127
|
const newStateX = getNewAxisState(xAxis[usedXAxis], svgPoint.x);
|
|
117
128
|
const newStateY = getNewAxisState(yAxis[usedYAxis], svgPoint.y);
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
129
|
+
store.update(prev => _extends({}, prev, {
|
|
130
|
+
interaction: _extends({}, prev.interaction, {
|
|
131
|
+
axis: _extends({}, prev.interaction.axis, prev.interaction.axis.x?.index !== newStateX?.index || prev.interaction.axis.x?.value !== newStateX?.value ? {
|
|
132
|
+
x: newStateX
|
|
133
|
+
} : {}, prev.interaction.axis.y?.index !== newStateY?.index || prev.interaction.axis.y?.value !== newStateY?.value ? {
|
|
134
|
+
y: newStateY
|
|
135
|
+
} : {})
|
|
136
|
+
})
|
|
137
|
+
}));
|
|
125
138
|
};
|
|
126
139
|
const handleDown = event => {
|
|
127
140
|
const target = event.currentTarget;
|
|
@@ -144,5 +157,5 @@ export const useAxisEvents = disableAxisListener => {
|
|
|
144
157
|
element.removeEventListener('pointercancel', handleOut);
|
|
145
158
|
element.removeEventListener('pointerleave', handleOut);
|
|
146
159
|
};
|
|
147
|
-
}, [svgRef,
|
|
160
|
+
}, [svgRef, store, usedYAxis, yAxis, usedXAxis, xAxis, disableAxisListener, drawingArea]);
|
|
148
161
|
};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import * as React from 'react';
|
|
4
|
-
import {
|
|
4
|
+
import { DrawingAreaContext } from "../context/DrawingAreaProvider/index.js";
|
|
5
5
|
export function useChartId() {
|
|
6
6
|
const {
|
|
7
7
|
chartId
|
|
8
|
-
} = React.useContext(
|
|
8
|
+
} = React.useContext(DrawingAreaContext);
|
|
9
9
|
return React.useMemo(() => chartId, [chartId]);
|
|
10
10
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import * as React from 'react';
|
|
4
|
-
import {
|
|
4
|
+
import { DrawingAreaContext } from "../context/DrawingAreaProvider/index.js";
|
|
5
5
|
export function useDrawingArea() {
|
|
6
6
|
const {
|
|
7
7
|
left,
|
|
@@ -11,7 +11,7 @@ export function useDrawingArea() {
|
|
|
11
11
|
bottom,
|
|
12
12
|
right,
|
|
13
13
|
isPointInside
|
|
14
|
-
} = React.useContext(
|
|
14
|
+
} = React.useContext(DrawingAreaContext);
|
|
15
15
|
return React.useMemo(() => ({
|
|
16
16
|
left,
|
|
17
17
|
top,
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import
|
|
4
|
-
import { InteractionContext } from "../context/InteractionProvider.js";
|
|
3
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
5
4
|
import { useHighlighted } from "../context/index.js";
|
|
5
|
+
import { useStore } from "../internals/useStore.js";
|
|
6
6
|
export const useInteractionItemProps = skip => {
|
|
7
|
-
const
|
|
8
|
-
dispatch: dispatchInteraction
|
|
9
|
-
} = React.useContext(InteractionContext);
|
|
7
|
+
const store = useStore();
|
|
10
8
|
const {
|
|
11
9
|
setHighlighted,
|
|
12
10
|
clearHighlighted
|
|
@@ -21,10 +19,11 @@ export const useInteractionItemProps = skip => {
|
|
|
21
19
|
}
|
|
22
20
|
};
|
|
23
21
|
const onPointerEnter = () => {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
22
|
+
store.update(prev => _extends({}, prev, {
|
|
23
|
+
interaction: _extends({}, prev.interaction, {
|
|
24
|
+
item: data
|
|
25
|
+
})
|
|
26
|
+
}));
|
|
28
27
|
setHighlighted({
|
|
29
28
|
seriesId: data.seriesId,
|
|
30
29
|
dataIndex: data.dataIndex
|
|
@@ -32,9 +31,17 @@ export const useInteractionItemProps = skip => {
|
|
|
32
31
|
};
|
|
33
32
|
const onPointerLeave = event => {
|
|
34
33
|
event.currentTarget.releasePointerCapture(event.pointerId);
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
data
|
|
34
|
+
store.update(prev => {
|
|
35
|
+
const prevItem = prev.interaction.item;
|
|
36
|
+
if (prevItem === null || Object.keys(data).some(key => data[key] !== prevItem[key])) {
|
|
37
|
+
// The item is already something else, no need to clean it.
|
|
38
|
+
return prev;
|
|
39
|
+
}
|
|
40
|
+
return _extends({}, prev, {
|
|
41
|
+
interaction: _extends({}, prev.interaction, {
|
|
42
|
+
item: null
|
|
43
|
+
})
|
|
44
|
+
});
|
|
38
45
|
});
|
|
39
46
|
clearHighlighted();
|
|
40
47
|
};
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import * as React from 'react';
|
|
4
|
-
import {
|
|
4
|
+
import { SvgRefContext } from "../context/SvgRefProvider/index.js";
|
|
5
5
|
export function useSvgRef() {
|
|
6
6
|
const {
|
|
7
7
|
isInitialized,
|
|
8
8
|
data
|
|
9
|
-
} = React.useContext(
|
|
9
|
+
} = React.useContext(SvgRefContext);
|
|
10
10
|
if (!isInitialized) {
|
|
11
11
|
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'));
|
|
12
12
|
}
|
|
13
|
-
return data;
|
|
13
|
+
return data.svgRef;
|
|
14
14
|
}
|
package/modern/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { useCartesianContext } from "../../../context/CartesianProvider/index.js";
|
|
3
|
-
import {
|
|
3
|
+
import { DrawingAreaContext } from "../../../context/DrawingAreaProvider/index.js";
|
|
4
4
|
import { useDrawingArea } from "../../../hooks/index.js";
|
|
5
5
|
import ChartsPiecewiseGradient from "./ChartsPiecewiseGradient.js";
|
|
6
6
|
import ChartsContinuousGradient from "./ChartsContinuousGradient.js";
|
|
@@ -8,7 +8,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
8
8
|
export function useChartGradient() {
|
|
9
9
|
const {
|
|
10
10
|
chartId
|
|
11
|
-
} = React.useContext(
|
|
11
|
+
} = React.useContext(DrawingAreaContext);
|
|
12
12
|
return React.useCallback((axisId, direction) => `${chartId}-gradient-${direction}-${axisId}`, [chartId]);
|
|
13
13
|
}
|
|
14
14
|
export function ChartsAxesGradients() {
|
|
@@ -29,8 +29,13 @@ export function ChartsAxesGradients() {
|
|
|
29
29
|
yAxisIds,
|
|
30
30
|
yAxis
|
|
31
31
|
} = useCartesianContext();
|
|
32
|
+
const filteredYAxisIds = yAxisIds.filter(axisId => yAxis[axisId].colorMap !== undefined);
|
|
33
|
+
const filteredXAxisIds = xAxisIds.filter(axisId => xAxis[axisId].colorMap !== undefined);
|
|
34
|
+
if (filteredYAxisIds.length === 0 && filteredXAxisIds.length === 0) {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
32
37
|
return /*#__PURE__*/_jsxs("defs", {
|
|
33
|
-
children: [
|
|
38
|
+
children: [filteredYAxisIds.map(axisId => {
|
|
34
39
|
const gradientId = getGradientId(axisId, 'y');
|
|
35
40
|
const {
|
|
36
41
|
colorMap,
|
|
@@ -60,7 +65,7 @@ export function ChartsAxesGradients() {
|
|
|
60
65
|
}, gradientId);
|
|
61
66
|
}
|
|
62
67
|
return null;
|
|
63
|
-
}),
|
|
68
|
+
}), filteredXAxisIds.map(axisId => {
|
|
64
69
|
const gradientId = getGradientId(axisId, 'x');
|
|
65
70
|
const {
|
|
66
71
|
colorMap,
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
// Components
|
|
2
2
|
export * from "./components/ChartsAxesGradients/index.js";
|
|
3
|
-
export * from "../ChartContainer/useChartContainerDimensions.js";
|
|
4
3
|
export * from "../ChartContainer/ResizableContainer.js";
|
|
5
4
|
|
|
6
5
|
// hooks
|
|
@@ -26,7 +25,7 @@ export * from "./computeAxisValue.js";
|
|
|
26
25
|
// contexts
|
|
27
26
|
|
|
28
27
|
export * from "../context/CartesianProvider/index.js";
|
|
29
|
-
export * from "../context/
|
|
28
|
+
export * from "../context/DrawingAreaProvider/index.js";
|
|
30
29
|
export * from "../context/InteractionProvider.js";
|
|
31
30
|
export * from "../context/SeriesProvider/index.js";
|
|
32
31
|
export * from "../context/ZAxisContextProvider.js";
|
|
@@ -34,6 +33,8 @@ export * from "../context/PluginProvider/index.js";
|
|
|
34
33
|
export * from "../context/AnimationProvider/index.js";
|
|
35
34
|
export { getAxisExtremum } from "../context/CartesianProvider/getAxisExtremum.js";
|
|
36
35
|
export * from "../context/ChartDataProvider/index.js";
|
|
36
|
+
export * from "../context/SizeProvider/index.js";
|
|
37
|
+
export * from "../context/SvgRefProvider/index.js";
|
|
37
38
|
|
|
38
39
|
// series configuration
|
|
39
40
|
export * from "../models/seriesType/config.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// For now this is fixed. Will need to support generic if we add plugins
|
|
2
|
+
|
|
3
|
+
export class ChartStore {
|
|
4
|
+
constructor(value) {
|
|
5
|
+
this.value = void 0;
|
|
6
|
+
this.listeners = void 0;
|
|
7
|
+
this.subscribe = fn => {
|
|
8
|
+
this.listeners.add(fn);
|
|
9
|
+
return () => {
|
|
10
|
+
this.listeners.delete(fn);
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
this.getSnapshot = () => {
|
|
14
|
+
return this.value;
|
|
15
|
+
};
|
|
16
|
+
this.update = updater => {
|
|
17
|
+
const newState = updater(this.value);
|
|
18
|
+
if (newState !== this.value) {
|
|
19
|
+
this.value = newState;
|
|
20
|
+
this.listeners.forEach(l => l(newState));
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
this.value = value;
|
|
24
|
+
this.listeners = new Set();
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// For now this is fixed. Will need to support generic if we add plugins
|
|
2
|
+
|
|
3
|
+
export class ChartsStore {
|
|
4
|
+
constructor(value) {
|
|
5
|
+
this.value = void 0;
|
|
6
|
+
this.listeners = void 0;
|
|
7
|
+
this.subscribe = fn => {
|
|
8
|
+
this.listeners.add(fn);
|
|
9
|
+
return () => {
|
|
10
|
+
this.listeners.delete(fn);
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
this.getSnapshot = () => {
|
|
14
|
+
return this.value;
|
|
15
|
+
};
|
|
16
|
+
this.update = updater => {
|
|
17
|
+
const newState = updater(this.value);
|
|
18
|
+
if (newState !== this.value) {
|
|
19
|
+
this.value = newState;
|
|
20
|
+
this.listeners.forEach(l => l(newState));
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
this.value = value;
|
|
24
|
+
this.listeners = new Set();
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { lruMemoize, createSelectorCreator } from 'reselect';
|
|
2
|
+
const reselectCreateSelector = createSelectorCreator({
|
|
3
|
+
memoize: lruMemoize,
|
|
4
|
+
memoizeOptions: {
|
|
5
|
+
maxSize: 1,
|
|
6
|
+
equalityCheck: Object.is
|
|
7
|
+
}
|
|
8
|
+
});
|
|
9
|
+
const cache = new WeakMap();
|
|
10
|
+
/**
|
|
11
|
+
* Method wrapping reselect's createSelector to provide caching for chart instances.
|
|
12
|
+
*
|
|
13
|
+
*/
|
|
14
|
+
export const createSelector = (...createSelectorArgs) => {
|
|
15
|
+
const selector = (state, selectorArgs) => {
|
|
16
|
+
const cacheKey = state.cacheKey;
|
|
17
|
+
|
|
18
|
+
// If there is no cache for the current chart instance, create one.
|
|
19
|
+
let cacheForCurrentChartInstance = cache.get(cacheKey);
|
|
20
|
+
if (!cacheForCurrentChartInstance) {
|
|
21
|
+
cacheForCurrentChartInstance = new Map();
|
|
22
|
+
cache.set(cacheKey, cacheForCurrentChartInstance);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// If there is a cached selector, execute it.
|
|
26
|
+
const cachedSelector = cacheForCurrentChartInstance.get(createSelectorArgs);
|
|
27
|
+
if (cachedSelector) {
|
|
28
|
+
return cachedSelector(state, selectorArgs);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Otherwise, create a new selector and cache it and execute it.
|
|
32
|
+
const fn = reselectCreateSelector(...createSelectorArgs);
|
|
33
|
+
cacheForCurrentChartInstance.set(createSelectorArgs, fn);
|
|
34
|
+
return fn(state, selectorArgs);
|
|
35
|
+
};
|
|
36
|
+
return selector;
|
|
37
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { ChartStore } from "./plugins/utils/ChartStore.js";
|
|
3
|
+
let globalId = 0;
|
|
4
|
+
export function useCharts() {
|
|
5
|
+
const storeRef = React.useRef(null);
|
|
6
|
+
if (storeRef.current == null) {
|
|
7
|
+
// eslint-disable-next-line react-compiler/react-compiler
|
|
8
|
+
globalId += 1;
|
|
9
|
+
const initialState = {
|
|
10
|
+
interaction: {
|
|
11
|
+
item: null,
|
|
12
|
+
axis: {
|
|
13
|
+
x: null,
|
|
14
|
+
y: null
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
cacheKey: {
|
|
18
|
+
id: globalId
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
storeRef.current = new ChartStore(initialState);
|
|
22
|
+
}
|
|
23
|
+
const contextValue = React.useMemo(() => ({
|
|
24
|
+
store: storeRef.current
|
|
25
|
+
}), []);
|
|
26
|
+
return {
|
|
27
|
+
contextValue
|
|
28
|
+
};
|
|
29
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { useSyncExternalStoreWithSelector } from 'use-sync-external-store/with-selector';
|
|
2
|
+
const defaultCompare = Object.is;
|
|
3
|
+
export const useSelector = (store, selector, args = undefined, equals = defaultCompare) => {
|
|
4
|
+
const selectorWithArgs = state => selector(state, args);
|
|
5
|
+
return useSyncExternalStoreWithSelector(store.subscribe, store.getSnapshot, store.getSnapshot, selectorWithArgs, equals);
|
|
6
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { ChartsContext } from "../context/InteractionProvider.js";
|
|
3
|
+
export function useStore(skipError) {
|
|
4
|
+
const charts = React.useContext(ChartsContext);
|
|
5
|
+
if (skipError) {
|
|
6
|
+
// TODO: Remove once store is used by all charts.
|
|
7
|
+
// This line is only for `useAxisEvents` which is in the surface of the Gauge.
|
|
8
|
+
// But the Gauge don't have store yet because it does not need the interaction provider.
|
|
9
|
+
// Will be fixed when every thing move to the store since every component will have access to it.
|
|
10
|
+
// @ts-ignore
|
|
11
|
+
return charts?.store;
|
|
12
|
+
}
|
|
13
|
+
if (!charts) {
|
|
14
|
+
throw new Error(['MUI X: Could not find the charts context.', 'It looks like you rendered your component outside of a ChartsContainer parent component.'].join('\n'));
|
|
15
|
+
}
|
|
16
|
+
return charts.store;
|
|
17
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
'use client';
|
|
3
|
+
|
|
4
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
5
|
+
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
6
|
+
Object.defineProperty(exports, "__esModule", {
|
|
7
|
+
value: true
|
|
8
|
+
});
|
|
9
|
+
exports.AnimatedBarElement = AnimatedBarElement;
|
|
10
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
11
|
+
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
|
|
12
|
+
var React = _interopRequireWildcard(require("react"));
|
|
13
|
+
var _web = require("@react-spring/web");
|
|
14
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
15
|
+
const _excluded = ["ownerState"];
|
|
16
|
+
/**
|
|
17
|
+
* @ignore - internal component.
|
|
18
|
+
*/
|
|
19
|
+
function AnimatedBarElement(props) {
|
|
20
|
+
const {
|
|
21
|
+
ownerState
|
|
22
|
+
} = props,
|
|
23
|
+
other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
|
|
24
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_web.animated.rect, (0, _extends2.default)({}, other, {
|
|
25
|
+
filter: ownerState.isHighlighted ? 'brightness(120%)' : undefined,
|
|
26
|
+
opacity: ownerState.isFaded ? 0.3 : 1
|
|
27
|
+
}));
|
|
28
|
+
}
|