@mui/x-charts 8.23.0 → 8.24.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.js +39 -0
- package/BarChart/BarChart.plugins.d.ts +2 -1
- package/BarChart/BarChart.plugins.js +2 -1
- package/BarChart/BarLabel/BarLabel.d.ts +2 -0
- package/BarChart/BarLabel/BarLabel.js +8 -3
- package/BarChart/BarLabel/BarLabelItem.d.ts +2 -0
- package/BarChart/BarLabel/BarLabelItem.js +4 -2
- package/BarChart/BarPlot.d.ts +12 -2
- package/BarChart/BarPlot.js +29 -86
- package/BarChart/BatchBarPlot/BarGroup.d.ts +15 -0
- package/BarChart/BatchBarPlot/BarGroup.js +142 -0
- package/BarChart/BatchBarPlot/BatchBarPlot.d.ts +12 -0
- package/BarChart/BatchBarPlot/BatchBarPlot.js +140 -0
- package/BarChart/BatchBarPlot/index.d.ts +1 -0
- package/BarChart/BatchBarPlot/index.js +12 -0
- package/BarChart/BatchBarPlot/useCreateBarPaths.d.ts +8 -0
- package/BarChart/BatchBarPlot/useCreateBarPaths.js +53 -0
- package/BarChart/FocusedBar.js +5 -1
- package/BarChart/IndividualBarPlot.d.ts +21 -0
- package/BarChart/IndividualBarPlot.js +106 -0
- package/BarChart/seriesConfig/bar/getSeriesWithDefaultValues.d.ts +1 -1
- package/BarChart/seriesConfig/bar/legend.js +1 -0
- package/BarChart/seriesConfig/index.js +3 -1
- package/BarChart/types.d.ts +2 -0
- package/BarChart/useBarChartProps.d.ts +6 -2
- package/BarChart/useBarChartProps.js +4 -2
- package/BarChart/useBarPlotData.d.ts +1 -1
- package/BarChart/useBarPlotData.js +23 -4
- package/BarChart/useRegisterItemClickHandlers.d.ts +6 -0
- package/BarChart/useRegisterItemClickHandlers.js +72 -0
- package/CHANGELOG.md +111 -1
- package/ChartContainer/ChartContainer.js +34 -0
- package/ChartContainer/useChartContainerProps.js +6 -2
- package/ChartsLegend/ChartsLegend.js +2 -2
- package/ChartsLegend/legendContext.types.d.ts +12 -0
- package/ChartsLegend/onClickContextBuilder.js +2 -1
- package/ChartsOverlay/ChartsLoadingOverlay.js +4 -1
- package/ChartsOverlay/ChartsNoDataOverlay.js +4 -1
- package/ChartsReferenceLine/common.d.ts +1 -1
- package/ChartsReferenceLine/common.js +4 -1
- package/ChartsTooltip/ChartsTooltipContainer.js +25 -21
- package/Gauge/GaugeContainer.js +4 -1
- package/LineChart/AnimatedLine.js +7 -3
- package/LineChart/AppearingMask.js +4 -1
- package/LineChart/CircleMarkElement.d.ts +5 -0
- package/LineChart/CircleMarkElement.js +13 -5
- package/LineChart/FocusedLineMark.js +5 -1
- package/LineChart/LineChart.js +30 -0
- package/LineChart/LineChart.plugins.d.ts +2 -1
- package/LineChart/LineChart.plugins.js +2 -1
- package/LineChart/LineElement.d.ts +4 -0
- package/LineChart/LineElement.js +7 -3
- package/LineChart/MarkElement.d.ts +5 -0
- package/LineChart/MarkElement.js +17 -10
- package/LineChart/markElementClasses.d.ts +0 -1
- package/LineChart/seriesConfig/index.js +3 -1
- package/LineChart/seriesConfig/legend.js +1 -0
- package/PieChart/FocusedPieArc.js +5 -2
- package/PieChart/PieArcLabel.d.ts +2 -0
- package/PieChart/PieArcLabel.js +5 -2
- package/PieChart/PieChart.js +35 -5
- package/PieChart/PieChart.plugins.d.ts +2 -1
- package/PieChart/PieChart.plugins.js +2 -1
- package/PieChart/seriesConfig/index.js +3 -1
- package/PieChart/seriesConfig/legend.js +6 -3
- package/RadarChart/RadarChart.js +30 -0
- package/RadarChart/RadarChart.plugins.d.ts +3 -2
- package/RadarChart/RadarChart.plugins.js +2 -1
- package/RadarChart/seriesConfig/index.js +3 -1
- package/RadarChart/seriesConfig/legend.js +1 -0
- package/ScatterChart/BatchScatter.js +8 -14
- package/ScatterChart/ScatterChart.js +30 -0
- package/ScatterChart/ScatterChart.plugins.d.ts +2 -1
- package/ScatterChart/ScatterChart.plugins.js +2 -1
- package/ScatterChart/seriesConfig/index.js +3 -1
- package/ScatterChart/seriesConfig/legend.js +1 -0
- package/SparkLineChart/SparkLineChart.js +46 -0
- package/esm/BarChart/BarChart.js +39 -0
- package/esm/BarChart/BarChart.plugins.d.ts +2 -1
- package/esm/BarChart/BarChart.plugins.js +2 -1
- package/esm/BarChart/BarLabel/BarLabel.d.ts +2 -0
- package/esm/BarChart/BarLabel/BarLabel.js +8 -3
- package/esm/BarChart/BarLabel/BarLabelItem.d.ts +2 -0
- package/esm/BarChart/BarLabel/BarLabelItem.js +4 -2
- package/esm/BarChart/BarPlot.d.ts +12 -2
- package/esm/BarChart/BarPlot.js +29 -86
- package/esm/BarChart/BatchBarPlot/BarGroup.d.ts +15 -0
- package/esm/BarChart/BatchBarPlot/BarGroup.js +134 -0
- package/esm/BarChart/BatchBarPlot/BatchBarPlot.d.ts +12 -0
- package/esm/BarChart/BatchBarPlot/BatchBarPlot.js +133 -0
- package/esm/BarChart/BatchBarPlot/index.d.ts +1 -0
- package/esm/BarChart/BatchBarPlot/index.js +1 -0
- package/esm/BarChart/BatchBarPlot/useCreateBarPaths.d.ts +8 -0
- package/esm/BarChart/BatchBarPlot/useCreateBarPaths.js +46 -0
- package/esm/BarChart/FocusedBar.js +5 -1
- package/esm/BarChart/IndividualBarPlot.d.ts +21 -0
- package/esm/BarChart/IndividualBarPlot.js +98 -0
- package/esm/BarChart/seriesConfig/bar/getSeriesWithDefaultValues.d.ts +1 -1
- package/esm/BarChart/seriesConfig/bar/legend.js +1 -0
- package/esm/BarChart/seriesConfig/index.js +3 -1
- package/esm/BarChart/types.d.ts +2 -0
- package/esm/BarChart/useBarChartProps.d.ts +6 -2
- package/esm/BarChart/useBarChartProps.js +4 -3
- package/esm/BarChart/useBarPlotData.d.ts +1 -1
- package/esm/BarChart/useBarPlotData.js +20 -1
- package/esm/BarChart/useRegisterItemClickHandlers.d.ts +6 -0
- package/esm/BarChart/useRegisterItemClickHandlers.js +67 -0
- package/esm/ChartContainer/ChartContainer.js +34 -0
- package/esm/ChartContainer/useChartContainerProps.js +6 -2
- package/esm/ChartsLegend/ChartsLegend.js +2 -2
- package/esm/ChartsLegend/legendContext.types.d.ts +12 -0
- package/esm/ChartsLegend/onClickContextBuilder.js +2 -1
- package/esm/ChartsOverlay/ChartsLoadingOverlay.js +4 -1
- package/esm/ChartsOverlay/ChartsNoDataOverlay.js +4 -1
- package/esm/ChartsReferenceLine/common.d.ts +1 -1
- package/esm/ChartsReferenceLine/common.js +4 -1
- package/esm/ChartsTooltip/ChartsTooltipContainer.js +26 -22
- package/esm/Gauge/GaugeContainer.js +4 -1
- package/esm/LineChart/AnimatedLine.js +7 -3
- package/esm/LineChart/AppearingMask.js +4 -1
- package/esm/LineChart/CircleMarkElement.d.ts +5 -0
- package/esm/LineChart/CircleMarkElement.js +13 -5
- package/esm/LineChart/FocusedLineMark.js +5 -1
- package/esm/LineChart/LineChart.js +30 -0
- package/esm/LineChart/LineChart.plugins.d.ts +2 -1
- package/esm/LineChart/LineChart.plugins.js +2 -1
- package/esm/LineChart/LineElement.d.ts +4 -0
- package/esm/LineChart/LineElement.js +7 -3
- package/esm/LineChart/MarkElement.d.ts +5 -0
- package/esm/LineChart/MarkElement.js +17 -10
- package/esm/LineChart/markElementClasses.d.ts +0 -1
- package/esm/LineChart/seriesConfig/index.js +3 -1
- package/esm/LineChart/seriesConfig/legend.js +1 -0
- package/esm/PieChart/FocusedPieArc.js +4 -1
- package/esm/PieChart/PieArcLabel.d.ts +2 -0
- package/esm/PieChart/PieArcLabel.js +5 -2
- package/esm/PieChart/PieChart.js +35 -5
- package/esm/PieChart/PieChart.plugins.d.ts +2 -1
- package/esm/PieChart/PieChart.plugins.js +2 -1
- package/esm/PieChart/seriesConfig/index.js +3 -1
- package/esm/PieChart/seriesConfig/legend.js +6 -3
- package/esm/RadarChart/RadarChart.js +30 -0
- package/esm/RadarChart/RadarChart.plugins.d.ts +3 -2
- package/esm/RadarChart/RadarChart.plugins.js +2 -1
- package/esm/RadarChart/seriesConfig/index.js +3 -1
- package/esm/RadarChart/seriesConfig/legend.js +1 -0
- package/esm/ScatterChart/BatchScatter.js +5 -11
- package/esm/ScatterChart/ScatterChart.js +30 -0
- package/esm/ScatterChart/ScatterChart.plugins.d.ts +2 -1
- package/esm/ScatterChart/ScatterChart.plugins.js +2 -1
- package/esm/ScatterChart/seriesConfig/index.js +3 -1
- package/esm/ScatterChart/seriesConfig/legend.js +1 -0
- package/esm/SparkLineChart/SparkLineChart.js +46 -0
- package/esm/index.js +1 -1
- package/esm/internals/appendAtKey.d.ts +8 -0
- package/esm/internals/appendAtKey.js +17 -0
- package/esm/internals/commonNextFocusItem.js +12 -8
- package/esm/internals/getBarDimensions.d.ts +1 -2
- package/esm/internals/identifierSerializer.d.ts +9 -0
- package/esm/internals/identifierSerializer.js +6 -0
- package/esm/internals/index.d.ts +6 -2
- package/esm/internals/index.js +6 -2
- package/esm/internals/invertScale.d.ts +6 -2
- package/esm/internals/invertScale.js +9 -1
- package/esm/internals/plugins/allPlugins.d.ts +4 -3
- package/esm/internals/plugins/allPlugins.js +2 -1
- package/esm/internals/plugins/corePlugins/useChartSeries/serializeIdentifier.d.ts +14 -0
- package/esm/internals/plugins/corePlugins/useChartSeries/serializeIdentifier.js +18 -0
- package/esm/internals/plugins/corePlugins/useChartSeries/useChartSeries.js +8 -1
- package/esm/internals/plugins/corePlugins/useChartSeries/useChartSeries.types.d.ts +12 -1
- package/esm/internals/plugins/featurePlugins/shared/useRegisterPointerInteractions.d.ts +11 -0
- package/esm/internals/plugins/featurePlugins/shared/useRegisterPointerInteractions.js +74 -0
- package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/computeAxisValue.js +20 -3
- package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxis.js +10 -3
- package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisPosition.selectors.d.ts +4 -0
- package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisPosition.selectors.js +83 -0
- package/esm/internals/plugins/featurePlugins/useChartKeyboardNavigation/utils/getMaxSeriesLength.d.ts +3 -0
- package/esm/internals/plugins/featurePlugins/useChartKeyboardNavigation/utils/getMaxSeriesLength.js +6 -0
- package/esm/internals/plugins/featurePlugins/useChartKeyboardNavigation/utils/getNextNonEmptySeries.js +7 -34
- package/esm/internals/plugins/featurePlugins/useChartKeyboardNavigation/utils/getNonEmptySeriesArray.d.ts +7 -0
- package/esm/internals/plugins/featurePlugins/useChartKeyboardNavigation/utils/getNonEmptySeriesArray.js +9 -0
- package/esm/internals/plugins/featurePlugins/useChartKeyboardNavigation/utils/getPreviousNonEmptySeries.js +10 -32
- package/esm/internals/plugins/featurePlugins/useChartTooltip/useChartTooltip.selectors.d.ts +2 -2
- package/esm/internals/plugins/featurePlugins/useChartVisibilityManager/index.d.ts +3 -0
- package/esm/internals/plugins/featurePlugins/useChartVisibilityManager/index.js +3 -0
- package/esm/internals/plugins/featurePlugins/useChartVisibilityManager/isIdentifierVisible.d.ts +4 -0
- package/esm/internals/plugins/featurePlugins/useChartVisibilityManager/isIdentifierVisible.js +5 -0
- package/esm/internals/plugins/featurePlugins/useChartVisibilityManager/useChartVisibilityManager.d.ts +3 -0
- package/esm/internals/plugins/featurePlugins/useChartVisibilityManager/useChartVisibilityManager.js +78 -0
- package/esm/internals/plugins/featurePlugins/useChartVisibilityManager/useChartVisibilityManager.selectors.d.ts +16 -0
- package/esm/internals/plugins/featurePlugins/useChartVisibilityManager/useChartVisibilityManager.selectors.js +19 -0
- package/esm/internals/plugins/featurePlugins/useChartVisibilityManager/useChartVisibilityManager.types.d.ts +90 -0
- package/esm/internals/plugins/featurePlugins/useChartVisibilityManager/useChartVisibilityManager.types.js +1 -0
- package/esm/internals/plugins/featurePlugins/useChartVisibilityManager/visibilityParamToMap.d.ts +4 -0
- package/esm/internals/plugins/featurePlugins/useChartVisibilityManager/visibilityParamToMap.js +11 -0
- package/esm/internals/plugins/models/seriesConfig/identifierSerializer.types.d.ts +2 -0
- package/esm/internals/plugins/models/seriesConfig/identifierSerializer.types.js +1 -0
- package/esm/internals/plugins/models/seriesConfig/index.d.ts +2 -1
- package/esm/internals/plugins/models/seriesConfig/index.js +2 -1
- package/esm/internals/plugins/models/seriesConfig/seriesConfig.types.d.ts +7 -0
- package/esm/models/axis.d.ts +5 -4
- package/esm/models/featureFlags.d.ts +1 -0
- package/esm/models/featureFlags.js +1 -0
- package/esm/models/index.d.ts +1 -0
- package/esm/models/index.js +1 -0
- package/esm/moduleAugmentation/barChartBatchRendererOnItemClick.d.ts +13 -0
- package/esm/moduleAugmentation/barChartBatchRendererOnItemClick.js +1 -0
- package/index.js +1 -1
- package/internals/appendAtKey.d.ts +8 -0
- package/internals/appendAtKey.js +23 -0
- package/internals/commonNextFocusItem.js +12 -8
- package/internals/getBarDimensions.d.ts +1 -2
- package/internals/identifierSerializer.d.ts +9 -0
- package/internals/identifierSerializer.js +16 -0
- package/internals/index.d.ts +6 -2
- package/internals/index.js +51 -7
- package/internals/invertScale.d.ts +6 -2
- package/internals/invertScale.js +10 -1
- package/internals/plugins/allPlugins.d.ts +4 -3
- package/internals/plugins/allPlugins.js +2 -1
- package/internals/plugins/corePlugins/useChartSeries/serializeIdentifier.d.ts +14 -0
- package/internals/plugins/corePlugins/useChartSeries/serializeIdentifier.js +25 -0
- package/internals/plugins/corePlugins/useChartSeries/useChartSeries.js +8 -1
- package/internals/plugins/corePlugins/useChartSeries/useChartSeries.types.d.ts +12 -1
- package/internals/plugins/featurePlugins/shared/useRegisterPointerInteractions.d.ts +11 -0
- package/internals/plugins/featurePlugins/shared/useRegisterPointerInteractions.js +81 -0
- package/internals/plugins/featurePlugins/useChartCartesianAxis/computeAxisValue.js +20 -3
- package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxis.js +10 -3
- package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisPosition.selectors.d.ts +4 -0
- package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisPosition.selectors.js +89 -0
- package/internals/plugins/featurePlugins/useChartKeyboardNavigation/utils/getMaxSeriesLength.d.ts +3 -0
- package/internals/plugins/featurePlugins/useChartKeyboardNavigation/utils/getMaxSeriesLength.js +12 -0
- package/internals/plugins/featurePlugins/useChartKeyboardNavigation/utils/getNextNonEmptySeries.js +6 -34
- package/internals/plugins/featurePlugins/useChartKeyboardNavigation/utils/getNonEmptySeriesArray.d.ts +7 -0
- package/internals/plugins/featurePlugins/useChartKeyboardNavigation/utils/getNonEmptySeriesArray.js +15 -0
- package/internals/plugins/featurePlugins/useChartKeyboardNavigation/utils/getPreviousNonEmptySeries.js +9 -32
- package/internals/plugins/featurePlugins/useChartTooltip/useChartTooltip.selectors.d.ts +2 -2
- package/internals/plugins/featurePlugins/useChartVisibilityManager/index.d.ts +3 -0
- package/internals/plugins/featurePlugins/useChartVisibilityManager/index.js +39 -0
- package/internals/plugins/featurePlugins/useChartVisibilityManager/isIdentifierVisible.d.ts +4 -0
- package/internals/plugins/featurePlugins/useChartVisibilityManager/isIdentifierVisible.js +12 -0
- package/internals/plugins/featurePlugins/useChartVisibilityManager/useChartVisibilityManager.d.ts +3 -0
- package/internals/plugins/featurePlugins/useChartVisibilityManager/useChartVisibilityManager.js +85 -0
- package/internals/plugins/featurePlugins/useChartVisibilityManager/useChartVisibilityManager.selectors.d.ts +16 -0
- package/internals/plugins/featurePlugins/useChartVisibilityManager/useChartVisibilityManager.selectors.js +25 -0
- package/internals/plugins/featurePlugins/useChartVisibilityManager/useChartVisibilityManager.types.d.ts +90 -0
- package/internals/plugins/featurePlugins/useChartVisibilityManager/useChartVisibilityManager.types.js +5 -0
- package/internals/plugins/featurePlugins/useChartVisibilityManager/visibilityParamToMap.d.ts +4 -0
- package/internals/plugins/featurePlugins/useChartVisibilityManager/visibilityParamToMap.js +18 -0
- package/internals/plugins/models/seriesConfig/identifierSerializer.types.d.ts +2 -0
- package/internals/plugins/models/seriesConfig/identifierSerializer.types.js +5 -0
- package/internals/plugins/models/seriesConfig/index.d.ts +2 -1
- package/internals/plugins/models/seriesConfig/index.js +11 -0
- package/internals/plugins/models/seriesConfig/seriesConfig.types.d.ts +7 -0
- package/models/axis.d.ts +5 -4
- package/models/featureFlags.d.ts +1 -0
- package/models/featureFlags.js +5 -0
- package/models/index.d.ts +1 -0
- package/models/index.js +11 -0
- package/moduleAugmentation/barChartBatchRendererOnItemClick.d.ts +13 -0
- package/moduleAugmentation/barChartBatchRendererOnItemClick.js +5 -0
- package/package.json +13 -3
|
@@ -45,7 +45,18 @@ export interface UseChartSeriesState<T extends ChartSeriesType = ChartSeriesType
|
|
|
45
45
|
dataset?: Readonly<DatasetType>;
|
|
46
46
|
};
|
|
47
47
|
}
|
|
48
|
-
export
|
|
48
|
+
export type SerializeIdentifierFunction = <T extends {
|
|
49
|
+
type: ChartSeriesType;
|
|
50
|
+
}>(identifier: T) => string;
|
|
51
|
+
export interface UseChartSeriesInstance {
|
|
52
|
+
/**
|
|
53
|
+
* Function to serialize a series item identifier into a unique string.
|
|
54
|
+
*
|
|
55
|
+
* @param identifier The identifier to serialize.
|
|
56
|
+
* @returns A unique string representing the identifier.
|
|
57
|
+
*/
|
|
58
|
+
serializeIdentifier: SerializeIdentifierFunction;
|
|
59
|
+
}
|
|
49
60
|
export type UseChartSeriesSignature<SeriesType extends ChartSeriesType = ChartSeriesType> = ChartPluginSignature<{
|
|
50
61
|
params: UseChartSeriesParameters;
|
|
51
62
|
defaultizedParams: UseChartSeriesDefaultizedParameters<SeriesType>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type SeriesItemIdentifier } from "../../../../models/seriesType/index.js";
|
|
2
|
+
import { type UseChartHighlightSignature } from "../useChartHighlight/index.js";
|
|
3
|
+
import { type UseChartCartesianAxisSignature } from "../useChartCartesianAxis/index.js";
|
|
4
|
+
import { type ChartState } from "../../models/index.js";
|
|
5
|
+
/**
|
|
6
|
+
* Hook to get pointer interaction props for chart items.
|
|
7
|
+
*/
|
|
8
|
+
export declare function useRegisterPointerInteractions(getItemAtPosition: (state: ChartState<[UseChartCartesianAxisSignature, UseChartHighlightSignature]>, point: {
|
|
9
|
+
x: number;
|
|
10
|
+
y: number;
|
|
11
|
+
}) => SeriesItemIdentifier | undefined, onItemEnter?: () => void, onItemLeave?: () => void): void;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import useEventCallback from '@mui/utils/useEventCallback';
|
|
5
|
+
import { useSvgRef } from "../../../../hooks/index.js";
|
|
6
|
+
import { useStore } from "../../../store/useStore.js";
|
|
7
|
+
import { useChartContext } from "../../../../context/ChartProvider/index.js";
|
|
8
|
+
import { getSVGPoint } from "../../../getSVGPoint.js";
|
|
9
|
+
/**
|
|
10
|
+
* Hook to get pointer interaction props for chart items.
|
|
11
|
+
*/
|
|
12
|
+
export function useRegisterPointerInteractions(getItemAtPosition, onItemEnter, onItemLeave) {
|
|
13
|
+
const {
|
|
14
|
+
instance
|
|
15
|
+
} = useChartContext();
|
|
16
|
+
const svgRef = useSvgRef();
|
|
17
|
+
const store = useStore();
|
|
18
|
+
const interactionActive = React.useRef(false);
|
|
19
|
+
const lastItemRef = React.useRef(undefined);
|
|
20
|
+
const onItemEnterRef = useEventCallback(() => onItemEnter?.());
|
|
21
|
+
const onItemLeaveRef = useEventCallback(() => onItemLeave?.());
|
|
22
|
+
React.useEffect(() => {
|
|
23
|
+
const svg = svgRef.current;
|
|
24
|
+
if (!svg) {
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
function onPointerEnter() {
|
|
28
|
+
interactionActive.current = true;
|
|
29
|
+
}
|
|
30
|
+
function reset() {
|
|
31
|
+
const lastItem = lastItemRef.current;
|
|
32
|
+
if (lastItem) {
|
|
33
|
+
lastItemRef.current = undefined;
|
|
34
|
+
instance.removeTooltipItem(lastItem);
|
|
35
|
+
instance.clearHighlight();
|
|
36
|
+
onItemLeaveRef();
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function onPointerLeave() {
|
|
40
|
+
interactionActive.current = false;
|
|
41
|
+
reset();
|
|
42
|
+
}
|
|
43
|
+
const onPointerMove = function onPointerMove(event) {
|
|
44
|
+
const svgPoint = getSVGPoint(svg, event);
|
|
45
|
+
if (!instance.isPointInside(svgPoint.x, svgPoint.y)) {
|
|
46
|
+
reset();
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const item = getItemAtPosition(store.state, svgPoint);
|
|
50
|
+
if (item) {
|
|
51
|
+
instance.setLastUpdateSource('pointer');
|
|
52
|
+
instance.setTooltipItem(item);
|
|
53
|
+
instance.setHighlight(item);
|
|
54
|
+
onItemEnterRef();
|
|
55
|
+
lastItemRef.current = item;
|
|
56
|
+
} else {
|
|
57
|
+
reset();
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
svg.addEventListener('pointerleave', onPointerLeave);
|
|
61
|
+
svg.addEventListener('pointermove', onPointerMove);
|
|
62
|
+
svg.addEventListener('pointerenter', onPointerEnter);
|
|
63
|
+
return () => {
|
|
64
|
+
svg.removeEventListener('pointerenter', onPointerEnter);
|
|
65
|
+
svg.removeEventListener('pointermove', onPointerMove);
|
|
66
|
+
svg.removeEventListener('pointerleave', onPointerLeave);
|
|
67
|
+
|
|
68
|
+
/* Clean up state if this item is unmounted while active. */
|
|
69
|
+
if (interactionActive.current) {
|
|
70
|
+
onPointerLeave();
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
}, [getItemAtPosition, instance, onItemEnterRef, onItemLeaveRef, store, svgRef]);
|
|
74
|
+
}
|
|
@@ -13,6 +13,16 @@ reverse) {
|
|
|
13
13
|
const range = axisDirection === 'x' ? [drawingArea.left, drawingArea.left + drawingArea.width] : [drawingArea.top + drawingArea.height, drawingArea.top];
|
|
14
14
|
return reverse ? [range[1], range[0]] : range;
|
|
15
15
|
}
|
|
16
|
+
function shouldIgnoreGapRatios(scale, categoryGapRatio) {
|
|
17
|
+
const step = scale.step();
|
|
18
|
+
const paddingPx = step * categoryGapRatio;
|
|
19
|
+
|
|
20
|
+
/* If the padding is less than 0.1px, we consider it negligible and ignore it.
|
|
21
|
+
* This prevents issues where very small gaps cause rendering artifacts or unexpected layouts.
|
|
22
|
+
* A threshold of 0.1px is chosen as it's generally below the perceptible limit for most displays.
|
|
23
|
+
*/
|
|
24
|
+
return paddingPx < 0.1;
|
|
25
|
+
}
|
|
16
26
|
const DEFAULT_CATEGORY_GAP_RATIO = 0.2;
|
|
17
27
|
const DEFAULT_BAR_GAP_RATIO = 0.1;
|
|
18
28
|
export function computeAxisValue({
|
|
@@ -47,8 +57,10 @@ export function computeAxisValue({
|
|
|
47
57
|
// Reverse range because ordinal scales are presented from top to bottom on y-axis
|
|
48
58
|
const scaleRange = axisDirection === 'y' ? [range[1], range[0]] : range;
|
|
49
59
|
if (isBandScale(scale) && isBandScaleConfig(axis)) {
|
|
50
|
-
const
|
|
51
|
-
const
|
|
60
|
+
const desiredCategoryGapRatio = axis.categoryGapRatio ?? DEFAULT_CATEGORY_GAP_RATIO;
|
|
61
|
+
const ignoreGapRatios = shouldIgnoreGapRatios(scale, desiredCategoryGapRatio);
|
|
62
|
+
const categoryGapRatio = ignoreGapRatios ? 0 : desiredCategoryGapRatio;
|
|
63
|
+
const barGapRatio = ignoreGapRatios ? 0 : axis.barGapRatio ?? DEFAULT_BAR_GAP_RATIO;
|
|
52
64
|
completeAxis[axis.id] = _extends({
|
|
53
65
|
offset: 0,
|
|
54
66
|
height: 0,
|
|
@@ -57,7 +69,12 @@ export function computeAxisValue({
|
|
|
57
69
|
triggerTooltip
|
|
58
70
|
}, axis, {
|
|
59
71
|
data,
|
|
60
|
-
|
|
72
|
+
/* Doing this here is technically wrong, but acceptable in practice.
|
|
73
|
+
* In theory, this should be done in the normalized scale selector, but then we'd need that selector to depend
|
|
74
|
+
* on the zoom range, which would void its goal (which is to be independent of zoom).
|
|
75
|
+
* Since we only ignore gap ratios when they're practically invisible, the small errors caused by this
|
|
76
|
+
* discrepancy will hopefully not be noticeable. */
|
|
77
|
+
scale: ignoreGapRatios ? scale.copy().padding(0) : scale,
|
|
61
78
|
tickNumber,
|
|
62
79
|
colorScale: axis.colorMap && (axis.colorMap.type === 'ordinal' ? getOrdinalColorScale(_extends({
|
|
63
80
|
values: axis.data
|
|
@@ -16,6 +16,7 @@ import { getSVGPoint } from "../../../getSVGPoint.js";
|
|
|
16
16
|
import { selectorChartsInteractionIsInitialized } from "../useChartInteraction/index.js";
|
|
17
17
|
import { selectorChartAxisInteraction } from "./useChartCartesianInteraction.selectors.js";
|
|
18
18
|
import { checkHasInteractionPlugin } from "../useChartInteraction/checkHasInteractionPlugin.js";
|
|
19
|
+
const AXIS_CLICK_SERIES_TYPES = new Set(['bar', 'rangeBar', 'line']);
|
|
19
20
|
export const useChartCartesianAxis = ({
|
|
20
21
|
params,
|
|
21
22
|
store,
|
|
@@ -165,13 +166,19 @@ export const useChartCartesianAxis = ({
|
|
|
165
166
|
// The .data exist because otherwise the dataIndex would be null or -1.
|
|
166
167
|
const axisValue = (isXAxis ? xAxisWithScale : yAxisWithScale)[USED_AXIS_ID].data[dataIndex];
|
|
167
168
|
const seriesValues = {};
|
|
168
|
-
Object.keys(processedSeries).filter(seriesType =>
|
|
169
|
-
|
|
170
|
-
|
|
169
|
+
Object.keys(processedSeries).filter(seriesType => AXIS_CLICK_SERIES_TYPES.has(seriesType)).forEach(seriesType => {
|
|
170
|
+
// @ts-ignore
|
|
171
|
+
const seriesTypeConfig = processedSeries[seriesType];
|
|
172
|
+
seriesTypeConfig?.seriesOrder.forEach(seriesId => {
|
|
173
|
+
const seriesItem = seriesTypeConfig.series[seriesId];
|
|
171
174
|
const providedXAxisId = seriesItem.xAxisId;
|
|
172
175
|
const providedYAxisId = seriesItem.yAxisId;
|
|
173
176
|
const axisKey = isXAxis ? providedXAxisId : providedYAxisId;
|
|
174
177
|
if (axisKey === undefined || axisKey === USED_AXIS_ID) {
|
|
178
|
+
// @ts-ignore This is safe because users need to opt in to use range bar series.
|
|
179
|
+
// In that case, they should import the module augmentation from `x-charts-pro/moduleAugmentation/rangeBarOnClick`
|
|
180
|
+
// Which adds the proper type to the series data.
|
|
181
|
+
// TODO(v9): Remove this ts-ignore when we can make the breaking change to ChartsAxisData.
|
|
175
182
|
seriesValues[seriesId] = seriesItem.data[dataIndex];
|
|
176
183
|
}
|
|
177
184
|
});
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type BarItemIdentifier } from "../../../../models/index.js";
|
|
2
|
+
export declare const selectorBarItemAtPosition: (args_0: import("../../corePlugins/useChartId/useChartId.types.js").UseChartIdState & import("../../corePlugins/useChartExperimentalFeature/useChartExperimentalFeature.types.js").UseChartExperimentalFeaturesState & import("../../corePlugins/useChartDimensions/useChartDimensions.types.js").UseChartDimensionsState & import("../../corePlugins/useChartSeries/useChartSeries.types.js").UseChartSeriesState<keyof import("../../../index.js").ChartsSeriesConfig> & import("../../corePlugins/useChartAnimation/useChartAnimation.types.js").UseChartAnimationState & import("../../../index.js").UseChartInteractionListenerState & Partial<{}> & {
|
|
3
|
+
cacheKey: import("../../models/index.js").ChartStateCacheKey;
|
|
4
|
+
}, svgPoint: Pick<DOMPoint, "x" | "y">) => BarItemIdentifier | undefined;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { createSelector } from '@mui/x-internals/store';
|
|
2
|
+
import { selectorChartXAxis, selectorChartYAxis } from "./useChartCartesianAxisRendering.selectors.js";
|
|
3
|
+
import { selectorChartSeriesProcessed } from "../../corePlugins/useChartSeries/index.js";
|
|
4
|
+
import { getBandSize } from "../../../getBandSize.js";
|
|
5
|
+
import { isBandScale } from "../../../scaleGuards.js";
|
|
6
|
+
import { getDataIndexForOrdinalScaleValue } from "../../../invertScale.js";
|
|
7
|
+
export const selectorBarItemAtPosition = createSelector(selectorChartXAxis, selectorChartYAxis, selectorChartSeriesProcessed, function selectorBarItemAtPosition({
|
|
8
|
+
axis: xAxes,
|
|
9
|
+
axisIds: xAxisIds
|
|
10
|
+
}, {
|
|
11
|
+
axis: yAxes,
|
|
12
|
+
axisIds: yAxisIds
|
|
13
|
+
}, processedSeries, svgPoint) {
|
|
14
|
+
const {
|
|
15
|
+
series,
|
|
16
|
+
stackingGroups = []
|
|
17
|
+
} = processedSeries?.bar ?? {};
|
|
18
|
+
const defaultXAxisId = xAxisIds[0];
|
|
19
|
+
const defaultYAxisId = yAxisIds[0];
|
|
20
|
+
let item = undefined;
|
|
21
|
+
for (let stackIndex = 0; stackIndex < stackingGroups.length; stackIndex += 1) {
|
|
22
|
+
const group = stackingGroups[stackIndex];
|
|
23
|
+
const seriesIds = group.ids;
|
|
24
|
+
for (const seriesId of seriesIds) {
|
|
25
|
+
const aSeries = (series ?? {})[seriesId];
|
|
26
|
+
const xAxisId = aSeries.xAxisId ?? defaultXAxisId;
|
|
27
|
+
const yAxisId = aSeries.yAxisId ?? defaultYAxisId;
|
|
28
|
+
const xAxis = xAxes[xAxisId];
|
|
29
|
+
const yAxis = yAxes[yAxisId];
|
|
30
|
+
const bandAxis = aSeries.layout === 'horizontal' ? yAxis : xAxis;
|
|
31
|
+
const continuousAxis = aSeries.layout === 'horizontal' ? xAxis : yAxis;
|
|
32
|
+
const bandScale = bandAxis.scale;
|
|
33
|
+
const svgPointBandCoordinate = aSeries.layout === 'horizontal' ? svgPoint.y : svgPoint.x;
|
|
34
|
+
if (!isBandScale(bandScale)) {
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
const dataIndex = getDataIndexForOrdinalScaleValue(bandScale, svgPointBandCoordinate);
|
|
38
|
+
const {
|
|
39
|
+
barWidth,
|
|
40
|
+
offset
|
|
41
|
+
} = getBandSize(bandScale.bandwidth(), stackingGroups.length, bandAxis.barGapRatio);
|
|
42
|
+
const barOffset = stackIndex * (barWidth + offset);
|
|
43
|
+
const bandValue = bandAxis.data?.[dataIndex];
|
|
44
|
+
if (bandValue == null) {
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
const bandStart = bandScale(bandValue);
|
|
48
|
+
if (bandStart == null) {
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
const bandBarStart = bandStart + barOffset;
|
|
52
|
+
const bandBarEnd = bandBarStart + barWidth;
|
|
53
|
+
const bandBarMin = Math.min(bandBarStart, bandBarEnd);
|
|
54
|
+
const bandBarMax = Math.max(bandBarStart, bandBarEnd);
|
|
55
|
+
if (svgPointBandCoordinate >= bandBarMin && svgPointBandCoordinate <= bandBarMax) {
|
|
56
|
+
// The point is inside the band for this series
|
|
57
|
+
const svgPointContinuousCoordinate = aSeries.layout === 'horizontal' ? svgPoint.x : svgPoint.y;
|
|
58
|
+
const bar = aSeries.stackedData[dataIndex];
|
|
59
|
+
const start = continuousAxis.scale(bar[0]);
|
|
60
|
+
const end = continuousAxis.scale(bar[1]);
|
|
61
|
+
if (start == null || end == null) {
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
const continuousMin = Math.min(start, end);
|
|
65
|
+
const continuousMax = Math.max(start, end);
|
|
66
|
+
if (svgPointContinuousCoordinate >= continuousMin && svgPointContinuousCoordinate <= continuousMax) {
|
|
67
|
+
item = {
|
|
68
|
+
seriesId,
|
|
69
|
+
dataIndex
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (item) {
|
|
76
|
+
return {
|
|
77
|
+
type: 'bar',
|
|
78
|
+
seriesId: item.seriesId,
|
|
79
|
+
dataIndex: item.dataIndex
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
return undefined;
|
|
83
|
+
});
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { ChartSeriesType } from "../../../../../models/seriesType/config.js";
|
|
2
|
+
import type { ProcessedSeries } from "../../../corePlugins/useChartSeries/useChartSeries.types.js";
|
|
3
|
+
export declare function getMaxSeriesLength<OutSeriesType extends Exclude<ChartSeriesType, 'sankey'>>(series: ProcessedSeries<ChartSeriesType>, availableSeriesTypes: Set<OutSeriesType>): number;
|
package/esm/internals/plugins/featurePlugins/useChartKeyboardNavigation/utils/getMaxSeriesLength.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export function getMaxSeriesLength(series, availableSeriesTypes) {
|
|
2
|
+
return Object.keys(series).filter(type => availableSeriesTypes.has(type)).flatMap(type => {
|
|
3
|
+
const seriesOfType = series[type];
|
|
4
|
+
return seriesOfType.seriesOrder.filter(seriesId => seriesOfType.series[seriesId].data.length > 0 && seriesOfType.series[seriesId].data.some(value => value != null)).map(seriesId => seriesOfType.series[seriesId].data.length);
|
|
5
|
+
}).reduce((maxLengths, length) => Math.max(maxLengths, length), 0);
|
|
6
|
+
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { getNonEmptySeriesArray } from "./getNonEmptySeriesArray.js";
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Returns the next series type and id that contains some data.
|
|
3
5
|
* Returns `null` if no other series have data.
|
|
@@ -7,39 +9,10 @@
|
|
|
7
9
|
* @param seriesId - The current series id.
|
|
8
10
|
*/
|
|
9
11
|
export function getNextNonEmptySeries(series, availableSeriesTypes, type, seriesId) {
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const startingTypeIndex = type !== undefined && series[type] ? typesAvailable.indexOf(type) : 0;
|
|
14
|
-
|
|
15
|
-
// Loop over all series types starting with the current seriesType
|
|
16
|
-
for (let typeGap = 0; typeGap < typesAvailable.length; typeGap += 1) {
|
|
17
|
-
const typeIndex = (startingTypeIndex + typeGap) % typesAvailable.length;
|
|
18
|
-
const seriesOfType = series[typesAvailable[typeIndex]];
|
|
19
|
-
|
|
20
|
-
// Edge case for the current series type: we don't loop on previous series of the same type.
|
|
21
|
-
const startingSeriesIndex = typeGap === 0 ? currentSeriesIndex + 1 : 0;
|
|
22
|
-
for (let seriesIndex = startingSeriesIndex; seriesIndex < seriesOfType.seriesOrder.length; seriesIndex += 1) {
|
|
23
|
-
if (seriesOfType.series[seriesOfType.seriesOrder[seriesIndex]].data.length > 0) {
|
|
24
|
-
return {
|
|
25
|
-
type: typesAvailable[typeIndex],
|
|
26
|
-
seriesId: seriesOfType.seriesOrder[seriesIndex]
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// End looping on the initial type up to the initial series (excluded)
|
|
33
|
-
const typeIndex = startingTypeIndex;
|
|
34
|
-
const seriesOfType = series[typesAvailable[typeIndex]];
|
|
35
|
-
const endingSeriesIndex = currentSeriesIndex;
|
|
36
|
-
for (let seriesIndex = 0; seriesIndex < endingSeriesIndex; seriesIndex += 1) {
|
|
37
|
-
if (seriesOfType.series[seriesOfType.seriesOrder[seriesIndex]].data.length > 0) {
|
|
38
|
-
return {
|
|
39
|
-
type: typesAvailable[typeIndex],
|
|
40
|
-
seriesId: seriesOfType.seriesOrder[seriesIndex]
|
|
41
|
-
};
|
|
42
|
-
}
|
|
12
|
+
const nonEmptySeries = getNonEmptySeriesArray(series, availableSeriesTypes);
|
|
13
|
+
if (nonEmptySeries.length === 0) {
|
|
14
|
+
return null;
|
|
43
15
|
}
|
|
44
|
-
|
|
16
|
+
const currentSeriesIndex = type !== undefined && seriesId !== undefined ? nonEmptySeries.findIndex(seriesItem => seriesItem.type === type && seriesItem.seriesId === seriesId) : -1;
|
|
17
|
+
return nonEmptySeries[(currentSeriesIndex + 1) % nonEmptySeries.length];
|
|
45
18
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { SeriesId } from "../../../../../models/seriesType/common.js";
|
|
2
|
+
import type { ChartSeriesType } from "../../../../../models/seriesType/config.js";
|
|
3
|
+
import type { ProcessedSeries } from "../../../corePlugins/useChartSeries/useChartSeries.types.js";
|
|
4
|
+
export declare function getNonEmptySeriesArray<OutSeriesType extends Exclude<ChartSeriesType, 'sankey'>>(series: ProcessedSeries<ChartSeriesType>, availableSeriesTypes: Set<OutSeriesType>): {
|
|
5
|
+
seriesId: SeriesId;
|
|
6
|
+
type: OutSeriesType;
|
|
7
|
+
}[];
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export function getNonEmptySeriesArray(series, availableSeriesTypes) {
|
|
2
|
+
return Object.keys(series).filter(type => availableSeriesTypes.has(type)).flatMap(type => {
|
|
3
|
+
const seriesOfType = series[type];
|
|
4
|
+
return seriesOfType.seriesOrder.filter(seriesId => seriesOfType.series[seriesId].data.length > 0 && seriesOfType.series[seriesId].data.some(value => value != null)).map(seriesId => ({
|
|
5
|
+
type,
|
|
6
|
+
seriesId
|
|
7
|
+
}));
|
|
8
|
+
});
|
|
9
|
+
}
|
|
@@ -1,40 +1,18 @@
|
|
|
1
|
+
import { getNonEmptySeriesArray } from "./getNonEmptySeriesArray.js";
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Returns the previous series type and id that contains some data.
|
|
3
5
|
* Returns `null` if no other series have data.
|
|
4
6
|
*/
|
|
5
7
|
export function getPreviousNonEmptySeries(series, availableSeriesTypes, type, seriesId) {
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const startingTypeIndex = type !== undefined && series[type] ? typesAvailable.indexOf(type) : 0;
|
|
10
|
-
|
|
11
|
-
// Loop over all series types starting with the current seriesType
|
|
12
|
-
for (let typeGap = 0; typeGap < typesAvailable.length; typeGap += 1) {
|
|
13
|
-
const typeIndex = (typesAvailable.length + startingTypeIndex - typeGap) % typesAvailable.length;
|
|
14
|
-
const seriesOfType = series[typesAvailable[typeIndex]];
|
|
15
|
-
const maxGap = typeGap === 0 ? startingSeriesIndex + 1 : seriesOfType.seriesOrder.length;
|
|
16
|
-
for (let seriesGap = 1; seriesGap < maxGap; seriesGap += 1) {
|
|
17
|
-
const seriesIndex = (seriesOfType.seriesOrder.length + startingSeriesIndex - seriesGap) % seriesOfType.seriesOrder.length;
|
|
18
|
-
if (seriesOfType.series[seriesOfType.seriesOrder[seriesIndex]].data.length > 0) {
|
|
19
|
-
return {
|
|
20
|
-
type: typesAvailable[typeIndex],
|
|
21
|
-
seriesId: seriesOfType.seriesOrder[seriesIndex]
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
}
|
|
8
|
+
const nonEmptySeries = getNonEmptySeriesArray(series, availableSeriesTypes);
|
|
9
|
+
if (nonEmptySeries.length === 0) {
|
|
10
|
+
return null;
|
|
25
11
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const availableSeriesIds = seriesOfType.seriesOrder;
|
|
31
|
-
for (let seriesIndex = availableSeriesIds.length - 1; seriesIndex > startingSeriesIndex; seriesIndex -= 1) {
|
|
32
|
-
if (seriesOfType.series[seriesOfType.seriesOrder[seriesIndex]].data.length > 0) {
|
|
33
|
-
return {
|
|
34
|
-
type: typesAvailable[typeIndex],
|
|
35
|
-
seriesId: seriesOfType.seriesOrder[seriesIndex]
|
|
36
|
-
};
|
|
37
|
-
}
|
|
12
|
+
const currentSeriesIndex = type !== undefined && seriesId !== undefined ? nonEmptySeries.findIndex(seriesItem => seriesItem.type === type && seriesItem.seriesId === seriesId) : -1;
|
|
13
|
+
if (currentSeriesIndex <= 0) {
|
|
14
|
+
// If no current series, or if it's the first series
|
|
15
|
+
return nonEmptySeries[nonEmptySeries.length - 1];
|
|
38
16
|
}
|
|
39
|
-
return
|
|
17
|
+
return nonEmptySeries[(currentSeriesIndex - 1 + nonEmptySeries.length) % nonEmptySeries.length];
|
|
40
18
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
export declare const selectorChartsTooltipPointerItem: (args_0: import("../../corePlugins/useChartId/useChartId.types.js").UseChartIdState & import("../../corePlugins/useChartExperimentalFeature/useChartExperimentalFeature.types.js").UseChartExperimentalFeaturesState & import("../../corePlugins/useChartDimensions/useChartDimensions.types.js").UseChartDimensionsState & import("../../corePlugins/useChartSeries/useChartSeries.types.js").UseChartSeriesState<keyof import("../../../index.js").ChartsSeriesConfig> & import("../../corePlugins/useChartAnimation/useChartAnimation.types.js").UseChartAnimationState & import("../../../index.js").UseChartInteractionListenerState & Partial<import("./useChartTooltip.types.js").UseChartTooltipState> & {
|
|
2
2
|
cacheKey: import("../../models/index.js").ChartStateCacheKey;
|
|
3
|
-
}) => import("../../../../index.js").
|
|
3
|
+
}) => import("../../../../index.js").LineItemIdentifier | import("../../../../index.js").BarItemIdentifier | import("../../../../index.js").ScatterItemIdentifier | import("../../../../index.js").PieItemIdentifier | import("../../../../index.js").RadarItemIdentifier | null;
|
|
4
4
|
export declare const selectorChartsTooltipPointerItemIsDefined: (args_0: import("../../corePlugins/useChartId/useChartId.types.js").UseChartIdState & import("../../corePlugins/useChartExperimentalFeature/useChartExperimentalFeature.types.js").UseChartExperimentalFeaturesState & import("../../corePlugins/useChartDimensions/useChartDimensions.types.js").UseChartDimensionsState & import("../../corePlugins/useChartSeries/useChartSeries.types.js").UseChartSeriesState<keyof import("../../../index.js").ChartsSeriesConfig> & import("../../corePlugins/useChartAnimation/useChartAnimation.types.js").UseChartAnimationState & import("../../../index.js").UseChartInteractionListenerState & Partial<import("./useChartTooltip.types.js").UseChartTooltipState> & {
|
|
5
5
|
cacheKey: import("../../models/index.js").ChartStateCacheKey;
|
|
6
6
|
}) => boolean;
|
|
7
7
|
export declare const selectorChartsTooltipItem: (args_0: import("../../corePlugins/useChartId/useChartId.types.js").UseChartIdState & import("../../corePlugins/useChartExperimentalFeature/useChartExperimentalFeature.types.js").UseChartExperimentalFeaturesState & import("../../corePlugins/useChartDimensions/useChartDimensions.types.js").UseChartDimensionsState & import("../../corePlugins/useChartSeries/useChartSeries.types.js").UseChartSeriesState<keyof import("../../../index.js").ChartsSeriesConfig> & import("../../corePlugins/useChartAnimation/useChartAnimation.types.js").UseChartAnimationState & import("../../../index.js").UseChartInteractionListenerState & Partial<import("../useChartInteraction/useChartInteraction.types.js").UseChartInteractionState> & {
|
|
8
8
|
cacheKey: import("../../models/index.js").ChartStateCacheKey;
|
|
9
|
-
}) => import("../../../../index.js").
|
|
9
|
+
}) => import("../../../../index.js").LineItemIdentifier | import("../../../../index.js").BarItemIdentifier | import("../../../../index.js").ScatterItemIdentifier | import("../../../../index.js").PieItemIdentifier | import("../../../../index.js").RadarItemIdentifier | null;
|
|
10
10
|
export declare const selectorChartsTooltipItemIsDefined: (args_0: import("../../corePlugins/useChartId/useChartId.types.js").UseChartIdState & import("../../corePlugins/useChartExperimentalFeature/useChartExperimentalFeature.types.js").UseChartExperimentalFeaturesState & import("../../corePlugins/useChartDimensions/useChartDimensions.types.js").UseChartDimensionsState & import("../../corePlugins/useChartSeries/useChartSeries.types.js").UseChartSeriesState<keyof import("../../../index.js").ChartsSeriesConfig> & import("../../corePlugins/useChartAnimation/useChartAnimation.types.js").UseChartAnimationState & import("../../../index.js").UseChartInteractionListenerState & Partial<import("../useChartInteraction/useChartInteraction.types.js").UseChartInteractionState> & {
|
|
11
11
|
cacheKey: import("../../models/index.js").ChartStateCacheKey;
|
|
12
12
|
}) => boolean;
|
package/esm/internals/plugins/featurePlugins/useChartVisibilityManager/isIdentifierVisible.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ChartSeriesType } from "../../../../models/seriesType/config.js";
|
|
2
|
+
import type { ChartSeriesConfig } from "../../models/index.js";
|
|
3
|
+
import type { VisibilityIdentifier, VisibilityMap } from "./useChartVisibilityManager.types.js";
|
|
4
|
+
export declare const isIdentifierVisible: (visibilityMap: VisibilityMap, identifier: VisibilityIdentifier, seriesConfig: ChartSeriesConfig<ChartSeriesType>) => boolean;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { serializeIdentifier } from "../../corePlugins/useChartSeries/serializeIdentifier.js";
|
|
2
|
+
export const isIdentifierVisible = (visibilityMap, identifier, seriesConfig) => {
|
|
3
|
+
const uniqueId = serializeIdentifier(seriesConfig, identifier);
|
|
4
|
+
return !visibilityMap.has(uniqueId);
|
|
5
|
+
};
|
package/esm/internals/plugins/featurePlugins/useChartVisibilityManager/useChartVisibilityManager.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
4
|
+
import useEventCallback from '@mui/utils/useEventCallback';
|
|
5
|
+
import { useEffectAfterFirstRender } from '@mui/x-internals/useEffectAfterFirstRender';
|
|
6
|
+
import { EMPTY_VISIBILITY_MAP } from "./useChartVisibilityManager.selectors.js";
|
|
7
|
+
import { visibilityParamToMap } from "./visibilityParamToMap.js";
|
|
8
|
+
export const useChartVisibilityManager = ({
|
|
9
|
+
store,
|
|
10
|
+
params,
|
|
11
|
+
seriesConfig,
|
|
12
|
+
instance
|
|
13
|
+
}) => {
|
|
14
|
+
// Manage controlled state
|
|
15
|
+
useEffectAfterFirstRender(() => {
|
|
16
|
+
if (params.hiddenItems === undefined) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
if (process.env.NODE_ENV !== 'production' && !store.state.visibilityManager.isControlled) {
|
|
20
|
+
console.error([`MUI X Charts: A chart component is changing the \`hiddenItems\` from uncontrolled to controlled.`, 'Elements should not switch from uncontrolled to controlled (or vice versa).', 'Decide between using a controlled or uncontrolled for the lifetime of the component.', "The nature of the state is determined during the first render. It's considered controlled if the value is not `undefined`.", 'More info: https://fb.me/react-controlled-components'].join('\n'));
|
|
21
|
+
}
|
|
22
|
+
store.set('visibilityManager', _extends({}, store.state.visibilityManager, {
|
|
23
|
+
visibilityMap: visibilityParamToMap(params.hiddenItems, seriesConfig)
|
|
24
|
+
}));
|
|
25
|
+
}, [store, params.hiddenItems, seriesConfig]);
|
|
26
|
+
const hideItem = useEventCallback(identifier => {
|
|
27
|
+
const visibilityMap = store.state.visibilityManager.visibilityMap;
|
|
28
|
+
const id = instance.serializeIdentifier(identifier);
|
|
29
|
+
if (visibilityMap.has(id)) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const newVisibilityMap = new Map(visibilityMap);
|
|
33
|
+
newVisibilityMap.set(id, identifier);
|
|
34
|
+
store.set('visibilityManager', _extends({}, store.state.visibilityManager, {
|
|
35
|
+
visibilityMap: newVisibilityMap
|
|
36
|
+
}));
|
|
37
|
+
params.onHiddenItemsChange?.(Array.from(newVisibilityMap.values()));
|
|
38
|
+
});
|
|
39
|
+
const showItem = useEventCallback(identifier => {
|
|
40
|
+
const visibilityMap = store.state.visibilityManager.visibilityMap;
|
|
41
|
+
const id = instance.serializeIdentifier(identifier);
|
|
42
|
+
if (!visibilityMap.has(id)) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const newVisibilityMap = new Map(visibilityMap);
|
|
46
|
+
newVisibilityMap.delete(id);
|
|
47
|
+
store.set('visibilityManager', _extends({}, store.state.visibilityManager, {
|
|
48
|
+
visibilityMap: newVisibilityMap
|
|
49
|
+
}));
|
|
50
|
+
params.onHiddenItemsChange?.(Array.from(newVisibilityMap.values()));
|
|
51
|
+
});
|
|
52
|
+
const toggleItem = useEventCallback(identifier => {
|
|
53
|
+
const visibilityMap = store.state.visibilityManager.visibilityMap;
|
|
54
|
+
const id = instance.serializeIdentifier(identifier);
|
|
55
|
+
if (visibilityMap.has(id)) {
|
|
56
|
+
showItem(identifier);
|
|
57
|
+
} else {
|
|
58
|
+
hideItem(identifier);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
return {
|
|
62
|
+
instance: {
|
|
63
|
+
hideItem,
|
|
64
|
+
showItem,
|
|
65
|
+
toggleItemVisibility: toggleItem
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
useChartVisibilityManager.getInitialState = (params, _, seriesConfig) => ({
|
|
70
|
+
visibilityManager: {
|
|
71
|
+
visibilityMap: params.hiddenItems ? visibilityParamToMap(params.hiddenItems, seriesConfig) : EMPTY_VISIBILITY_MAP,
|
|
72
|
+
isControlled: params.hiddenItems !== undefined
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
useChartVisibilityManager.params = {
|
|
76
|
+
onHiddenItemsChange: true,
|
|
77
|
+
hiddenItems: true
|
|
78
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { VisibilityIdentifier } from "./useChartVisibilityManager.types.js";
|
|
2
|
+
import type { ChartSeriesConfig } from "../../models/index.js";
|
|
3
|
+
import type { ChartSeriesType } from "../../../../models/seriesType/config.js";
|
|
4
|
+
export declare const EMPTY_VISIBILITY_MAP: Map<any, any>;
|
|
5
|
+
/**
|
|
6
|
+
* Selector to get the hidden identifiers from the visibility manager.
|
|
7
|
+
*/
|
|
8
|
+
export declare const selectorVisibilityMap: (args_0: import("../../corePlugins/useChartId/useChartId.types.js").UseChartIdState & import("../../corePlugins/useChartExperimentalFeature/useChartExperimentalFeature.types.js").UseChartExperimentalFeaturesState & import("../../corePlugins/useChartDimensions/useChartDimensions.types.js").UseChartDimensionsState & import("../../corePlugins/useChartSeries/useChartSeries.types.js").UseChartSeriesState<keyof import("../../../index.js").ChartsSeriesConfig> & import("../../corePlugins/useChartAnimation/useChartAnimation.types.js").UseChartAnimationState & import("../../../index.js").UseChartInteractionListenerState & Partial<import("./useChartVisibilityManager.types.js").UseChartVisibilityManagerState> & {
|
|
9
|
+
cacheKey: import("../../models/index.js").ChartStateCacheKey;
|
|
10
|
+
}) => Map<any, any>;
|
|
11
|
+
/**
|
|
12
|
+
* Selector that returns a function which returns whether an item is visible.
|
|
13
|
+
*/
|
|
14
|
+
export declare const selectorIsItemVisibleGetter: (args_0: import("../../corePlugins/useChartId/useChartId.types.js").UseChartIdState & import("../../corePlugins/useChartExperimentalFeature/useChartExperimentalFeature.types.js").UseChartExperimentalFeaturesState & import("../../corePlugins/useChartDimensions/useChartDimensions.types.js").UseChartDimensionsState & import("../../corePlugins/useChartSeries/useChartSeries.types.js").UseChartSeriesState<keyof import("../../../index.js").ChartsSeriesConfig> & import("../../corePlugins/useChartAnimation/useChartAnimation.types.js").UseChartAnimationState & import("../../../index.js").UseChartInteractionListenerState & Partial<import("./useChartVisibilityManager.types.js").UseChartVisibilityManagerState> & {
|
|
15
|
+
cacheKey: import("../../models/index.js").ChartStateCacheKey;
|
|
16
|
+
}) => (seriesConfig: ChartSeriesConfig<ChartSeriesType>, identifier: VisibilityIdentifier) => boolean;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { createSelector, createSelectorMemoized } from '@mui/x-internals/store';
|
|
2
|
+
import { isIdentifierVisible } from "./isIdentifierVisible.js";
|
|
3
|
+
/**
|
|
4
|
+
* Selector to get the visibility manager state.
|
|
5
|
+
*/
|
|
6
|
+
const selectVisibilityManager = state => state.visibilityManager;
|
|
7
|
+
export const EMPTY_VISIBILITY_MAP = new Map();
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Selector to get the hidden identifiers from the visibility manager.
|
|
11
|
+
*/
|
|
12
|
+
export const selectorVisibilityMap = createSelector(selectVisibilityManager, visibilityManager => visibilityManager?.visibilityMap ?? EMPTY_VISIBILITY_MAP);
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Selector that returns a function which returns whether an item is visible.
|
|
16
|
+
*/
|
|
17
|
+
export const selectorIsItemVisibleGetter = createSelectorMemoized(selectorVisibilityMap, visibilityMap => {
|
|
18
|
+
return (seriesConfig, identifier) => isIdentifierVisible(visibilityMap, identifier, seriesConfig);
|
|
19
|
+
});
|