@mui/x-charts 8.19.0 → 8.20.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/CHANGELOG.md +62 -0
- package/ChartsGrid/ChartsHorizontalGrid.js +5 -1
- package/ChartsGrid/ChartsVerticalGrid.js +5 -1
- package/ChartsTooltip/ChartsTooltipContainer.js +1 -1
- package/RadarChart/RadarSeriesPlot/RadarSeriesArea.js +2 -2
- package/RadarChart/RadarSeriesPlot/RadarSeriesPlot.js +2 -2
- package/RadarChart/RadarSeriesPlot/useInteractionAllItemProps.d.ts +7 -0
- package/RadarChart/RadarSeriesPlot/useInteractionAllItemProps.js +26 -0
- package/esm/ChartsGrid/ChartsHorizontalGrid.js +5 -1
- package/esm/ChartsGrid/ChartsVerticalGrid.js +5 -1
- package/esm/ChartsTooltip/ChartsTooltipContainer.js +1 -1
- package/esm/RadarChart/RadarSeriesPlot/RadarSeriesArea.js +1 -1
- package/esm/RadarChart/RadarSeriesPlot/RadarSeriesPlot.js +1 -1
- package/esm/RadarChart/RadarSeriesPlot/useInteractionAllItemProps.d.ts +7 -0
- package/esm/RadarChart/RadarSeriesPlot/useInteractionAllItemProps.js +18 -0
- package/esm/hooks/useInteractionItemProps.d.ts +0 -5
- package/esm/hooks/useInteractionItemProps.js +0 -11
- package/esm/hooks/useTicks.js +12 -3
- package/esm/index.js +1 -1
- package/esm/internals/plugins/corePlugins/useChartSeries/processSeries.d.ts +16 -10
- package/esm/internals/plugins/corePlugins/useChartSeries/processSeries.js +20 -12
- package/esm/internals/plugins/corePlugins/useChartSeries/useChartSeries.js +5 -7
- package/esm/internals/plugins/corePlugins/useChartSeries/useChartSeries.selectors.d.ts +11 -4
- package/esm/internals/plugins/corePlugins/useChartSeries/useChartSeries.selectors.js +13 -4
- package/esm/internals/plugins/corePlugins/useChartSeries/useChartSeries.types.d.ts +3 -2
- package/esm/internals/plugins/featurePlugins/useChartHighlight/useChartHighlight.js +16 -12
- package/esm/internals/plugins/featurePlugins/useChartHighlight/useChartHighlight.selectors.js +5 -5
- package/esm/internals/plugins/featurePlugins/useChartHighlight/useChartHighlight.types.d.ts +4 -0
- package/esm/internals/plugins/featurePlugins/useChartInteraction/useChartTooltip.selectors.d.ts +1 -1
- package/esm/internals/plugins/featurePlugins/useChartInteraction/useChartTooltip.selectors.js +1 -1
- package/esm/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.js +15 -10
- package/esm/internals/seriesSelectorOfType.d.ts +1 -1
- package/hooks/useInteractionItemProps.d.ts +0 -5
- package/hooks/useInteractionItemProps.js +1 -13
- package/hooks/useTicks.js +12 -3
- package/index.js +1 -1
- package/internals/plugins/corePlugins/useChartSeries/processSeries.d.ts +16 -10
- package/internals/plugins/corePlugins/useChartSeries/processSeries.js +23 -14
- package/internals/plugins/corePlugins/useChartSeries/useChartSeries.js +4 -6
- package/internals/plugins/corePlugins/useChartSeries/useChartSeries.selectors.d.ts +11 -4
- package/internals/plugins/corePlugins/useChartSeries/useChartSeries.selectors.js +13 -4
- package/internals/plugins/corePlugins/useChartSeries/useChartSeries.types.d.ts +3 -2
- package/internals/plugins/featurePlugins/useChartHighlight/useChartHighlight.js +16 -12
- package/internals/plugins/featurePlugins/useChartHighlight/useChartHighlight.selectors.js +5 -5
- package/internals/plugins/featurePlugins/useChartHighlight/useChartHighlight.types.d.ts +4 -0
- package/internals/plugins/featurePlugins/useChartInteraction/useChartTooltip.selectors.d.ts +1 -1
- package/internals/plugins/featurePlugins/useChartInteraction/useChartTooltip.selectors.js +1 -1
- package/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.js +15 -10
- package/internals/seriesSelectorOfType.d.ts +1 -1
- package/package.json +3 -3
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import { warnOnce } from '@mui/x-internals/warning';
|
|
2
3
|
import { useAssertModelConsistency } from '@mui/x-internals/useAssertModelConsistency';
|
|
3
4
|
import useEventCallback from '@mui/utils/useEventCallback';
|
|
4
5
|
import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
|
|
@@ -20,27 +21,34 @@ export const useChartHighlight = ({
|
|
|
20
21
|
item: params.highlightedItem
|
|
21
22
|
}));
|
|
22
23
|
}
|
|
24
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
25
|
+
if (params.highlightedItem !== undefined && !store.state.highlight.isControlled) {
|
|
26
|
+
warnOnce(['MUI X Charts: The `highlightedItem` switched between controlled and uncontrolled state.', 'To remove the highlight when using controlled state, you must provide `null` to the `highlightedItem` prop instead of `undefined`.'].join('\n'));
|
|
27
|
+
}
|
|
28
|
+
}
|
|
23
29
|
}, [store, params.highlightedItem]);
|
|
24
30
|
const clearHighlight = useEventCallback(() => {
|
|
25
31
|
params.onHighlightChange?.(null);
|
|
26
|
-
const
|
|
27
|
-
if (
|
|
32
|
+
const prevHighlight = store.getSnapshot().highlight;
|
|
33
|
+
if (prevHighlight.item === null || prevHighlight.isControlled) {
|
|
28
34
|
return;
|
|
29
35
|
}
|
|
30
36
|
store.set('highlight', {
|
|
31
37
|
item: null,
|
|
32
|
-
lastUpdate: 'pointer'
|
|
38
|
+
lastUpdate: 'pointer',
|
|
39
|
+
isControlled: false
|
|
33
40
|
});
|
|
34
41
|
});
|
|
35
42
|
const setHighlight = useEventCallback(newItem => {
|
|
36
|
-
const
|
|
37
|
-
if (fastObjectShallowCompare(
|
|
43
|
+
const prevHighlight = store.getSnapshot().highlight;
|
|
44
|
+
if (prevHighlight.isControlled || fastObjectShallowCompare(prevHighlight.item, newItem)) {
|
|
38
45
|
return;
|
|
39
46
|
}
|
|
40
47
|
params.onHighlightChange?.(newItem);
|
|
41
48
|
store.set('highlight', {
|
|
42
49
|
item: newItem,
|
|
43
|
-
lastUpdate: 'pointer'
|
|
50
|
+
lastUpdate: 'pointer',
|
|
51
|
+
isControlled: false
|
|
44
52
|
});
|
|
45
53
|
});
|
|
46
54
|
return {
|
|
@@ -50,15 +58,11 @@ export const useChartHighlight = ({
|
|
|
50
58
|
}
|
|
51
59
|
};
|
|
52
60
|
};
|
|
53
|
-
useChartHighlight.getDefaultizedParams = ({
|
|
54
|
-
params
|
|
55
|
-
}) => _extends({}, params, {
|
|
56
|
-
highlightedItem: params.highlightedItem ?? null
|
|
57
|
-
});
|
|
58
61
|
useChartHighlight.getInitialState = params => ({
|
|
59
62
|
highlight: {
|
|
60
63
|
item: params.highlightedItem,
|
|
61
|
-
lastUpdate: 'pointer'
|
|
64
|
+
lastUpdate: 'pointer',
|
|
65
|
+
isControlled: params.highlightedItem !== undefined
|
|
62
66
|
}
|
|
63
67
|
});
|
|
64
68
|
useChartHighlight.params = {
|
package/esm/internals/plugins/featurePlugins/useChartHighlight/useChartHighlight.selectors.js
CHANGED
|
@@ -3,12 +3,12 @@ import { createIsHighlighted } from "./createIsHighlighted.js";
|
|
|
3
3
|
import { createIsFaded } from "./createIsFaded.js";
|
|
4
4
|
import { getSeriesHighlightedItem, getSeriesUnfadedItem, isSeriesFaded, isSeriesHighlighted } from "./highlightStates.js";
|
|
5
5
|
import { selectorChartsKeyboardItem } from "../useChartKeyboardNavigation/index.js";
|
|
6
|
+
import { selectorChartSeriesProcessed } from "../../corePlugins/useChartSeries/useChartSeries.selectors.js";
|
|
6
7
|
const selectHighlight = state => state.highlight;
|
|
7
|
-
const
|
|
8
|
-
export const selectorChartsHighlightScopePerSeriesId = createSelector(selectSeries, series => {
|
|
8
|
+
export const selectorChartsHighlightScopePerSeriesId = createSelector(selectorChartSeriesProcessed, processedSeries => {
|
|
9
9
|
const map = new Map();
|
|
10
|
-
Object.keys(
|
|
11
|
-
const seriesData =
|
|
10
|
+
Object.keys(processedSeries).forEach(seriesType => {
|
|
11
|
+
const seriesData = processedSeries[seriesType];
|
|
12
12
|
seriesData?.seriesOrder?.forEach(seriesId => {
|
|
13
13
|
const seriesItem = seriesData?.series[seriesId];
|
|
14
14
|
map.set(seriesId, seriesItem?.highlightScope);
|
|
@@ -17,7 +17,7 @@ export const selectorChartsHighlightScopePerSeriesId = createSelector(selectSeri
|
|
|
17
17
|
return map;
|
|
18
18
|
});
|
|
19
19
|
export const selectorChartsHighlightedItem = createSelectorMemoized(selectHighlight, selectorChartsKeyboardItem, function selectorChartsHighlightedItem(highlight, keyboardItem) {
|
|
20
|
-
return highlight.lastUpdate === 'pointer' ? highlight.item : keyboardItem;
|
|
20
|
+
return highlight.isControlled || highlight.lastUpdate === 'pointer' ? highlight.item : keyboardItem;
|
|
21
21
|
});
|
|
22
22
|
export const selectorChartsHighlightScope = createSelector(selectorChartsHighlightScopePerSeriesId, selectorChartsHighlightedItem, function selectorChartsHighlightScope(seriesIdToHighlightScope, highlightedItem) {
|
|
23
23
|
if (!highlightedItem) {
|
|
@@ -56,6 +56,10 @@ export interface UseChartHighlightParameters {
|
|
|
56
56
|
export type UseChartHighlightDefaultizedParameters = DefaultizedProps<UseChartHighlightParameters, 'highlightedItem'>;
|
|
57
57
|
export interface UseChartHighlightState {
|
|
58
58
|
highlight: {
|
|
59
|
+
/**
|
|
60
|
+
* Indicates if the highlighted item is controlled.
|
|
61
|
+
*/
|
|
62
|
+
isControlled: boolean;
|
|
59
63
|
/**
|
|
60
64
|
* The item currently highlighted.
|
|
61
65
|
*/
|
package/esm/internals/plugins/featurePlugins/useChartInteraction/useChartTooltip.selectors.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export declare const selectorChartsTooltipItemIsDefined: (args_0: import("../../
|
|
|
6
6
|
}) => boolean;
|
|
7
7
|
export declare const selectorChartsTooltipItemPosition: (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.types.js").UseChartInteractionState> & {
|
|
8
8
|
cacheKey: import("../../models/index.js").ChartStateCacheKey;
|
|
9
|
-
}) => {
|
|
9
|
+
}, placement?: "bottom" | "left" | "right" | "top" | undefined) => {
|
|
10
10
|
x: number;
|
|
11
11
|
y: number;
|
|
12
12
|
} | null;
|
package/esm/internals/plugins/featurePlugins/useChartInteraction/useChartTooltip.selectors.js
CHANGED
|
@@ -7,7 +7,7 @@ import { selectorChartDrawingArea } from "../../corePlugins/useChartDimensions/u
|
|
|
7
7
|
import { isCartesianSeries } from "../../../isCartesian.js";
|
|
8
8
|
export const selectorChartsTooltipItem = createSelector(selectorChartsLastInteraction, selectorChartsInteractionItem, selectorChartsKeyboardItem, (lastInteraction, interactionItem, keyboardItem) => lastInteraction === 'keyboard' ? keyboardItem : interactionItem ?? null);
|
|
9
9
|
export const selectorChartsTooltipItemIsDefined = createSelector(selectorChartsLastInteraction, selectorChartsInteractionItemIsDefined, selectorChartsKeyboardItemIsDefined, (lastInteraction, interactionItemIsDefined, keyboardItemIsDefined) => lastInteraction === 'keyboard' ? keyboardItemIsDefined : interactionItemIsDefined);
|
|
10
|
-
export const selectorChartsTooltipItemPosition = createSelector(selectorChartsTooltipItem, selectorChartDrawingArea, selectorChartSeriesConfig, selectorChartXAxis, selectorChartYAxis, selectorChartSeriesProcessed,
|
|
10
|
+
export const selectorChartsTooltipItemPosition = createSelector(selectorChartsTooltipItem, selectorChartDrawingArea, selectorChartSeriesConfig, selectorChartXAxis, selectorChartYAxis, selectorChartSeriesProcessed, function selectorChartsTooltipItemPosition(identifier, drawingArea, seriesConfig, {
|
|
11
11
|
axis: xAxis,
|
|
12
12
|
axisIds: xAxisIds
|
|
13
13
|
}, {
|
|
@@ -5,22 +5,24 @@ import * as React from 'react';
|
|
|
5
5
|
import useEventCallback from '@mui/utils/useEventCallback';
|
|
6
6
|
import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
|
|
7
7
|
import { getNextSeriesWithData, getPreviousSeriesWithData, seriesHasData } from "./useChartKeyboardNavigation.helpers.js";
|
|
8
|
+
import { selectorChartSeriesProcessed } from "../../corePlugins/useChartSeries/useChartSeries.selectors.js";
|
|
8
9
|
function getNextIndexFocusedItem(state) {
|
|
10
|
+
const processedSeries = selectorChartSeriesProcessed(state);
|
|
9
11
|
let {
|
|
10
12
|
type,
|
|
11
13
|
seriesId
|
|
12
14
|
} = state.keyboardNavigation.item ?? {};
|
|
13
15
|
if (type === undefined ||
|
|
14
16
|
// @ts-ignore sankey is not in MIT version
|
|
15
|
-
type === 'sankey' || seriesId === undefined || !seriesHasData(
|
|
16
|
-
const nextSeries = getNextSeriesWithData(
|
|
17
|
+
type === 'sankey' || seriesId === undefined || !seriesHasData(processedSeries, type, seriesId)) {
|
|
18
|
+
const nextSeries = getNextSeriesWithData(processedSeries, type, seriesId);
|
|
17
19
|
if (nextSeries === null) {
|
|
18
20
|
return null;
|
|
19
21
|
}
|
|
20
22
|
type = nextSeries.type;
|
|
21
23
|
seriesId = nextSeries.seriesId;
|
|
22
24
|
}
|
|
23
|
-
const dataLength =
|
|
25
|
+
const dataLength = processedSeries[type].series[seriesId].data.length;
|
|
24
26
|
return {
|
|
25
27
|
type,
|
|
26
28
|
seriesId,
|
|
@@ -28,21 +30,22 @@ function getNextIndexFocusedItem(state) {
|
|
|
28
30
|
};
|
|
29
31
|
}
|
|
30
32
|
function getPreviousIndexFocusedItem(state) {
|
|
33
|
+
const processedSeries = selectorChartSeriesProcessed(state);
|
|
31
34
|
let {
|
|
32
35
|
type,
|
|
33
36
|
seriesId
|
|
34
37
|
} = state.keyboardNavigation.item ?? {};
|
|
35
38
|
if (type === undefined ||
|
|
36
39
|
// @ts-ignore sankey is not in MIT version
|
|
37
|
-
type === 'sankey' || seriesId === undefined || !seriesHasData(
|
|
38
|
-
const previousSeries = getPreviousSeriesWithData(
|
|
40
|
+
type === 'sankey' || seriesId === undefined || !seriesHasData(processedSeries, type, seriesId)) {
|
|
41
|
+
const previousSeries = getPreviousSeriesWithData(processedSeries, type, seriesId);
|
|
39
42
|
if (previousSeries === null) {
|
|
40
43
|
return null;
|
|
41
44
|
}
|
|
42
45
|
type = previousSeries.type;
|
|
43
46
|
seriesId = previousSeries.seriesId;
|
|
44
47
|
}
|
|
45
|
-
const dataLength =
|
|
48
|
+
const dataLength = processedSeries[type].series[seriesId].data.length;
|
|
46
49
|
return {
|
|
47
50
|
type,
|
|
48
51
|
seriesId,
|
|
@@ -50,17 +53,18 @@ function getPreviousIndexFocusedItem(state) {
|
|
|
50
53
|
};
|
|
51
54
|
}
|
|
52
55
|
function getNextSeriesFocusedItem(state) {
|
|
56
|
+
const processedSeries = selectorChartSeriesProcessed(state);
|
|
53
57
|
let {
|
|
54
58
|
type,
|
|
55
59
|
seriesId
|
|
56
60
|
} = state.keyboardNavigation.item ?? {};
|
|
57
|
-
const nextSeries = getNextSeriesWithData(
|
|
61
|
+
const nextSeries = getNextSeriesWithData(processedSeries, type, seriesId);
|
|
58
62
|
if (nextSeries === null) {
|
|
59
63
|
return null; // No series to move the focus to.
|
|
60
64
|
}
|
|
61
65
|
type = nextSeries.type;
|
|
62
66
|
seriesId = nextSeries.seriesId;
|
|
63
|
-
const dataLength =
|
|
67
|
+
const dataLength = processedSeries[type].series[seriesId].data.length;
|
|
64
68
|
return {
|
|
65
69
|
type,
|
|
66
70
|
seriesId,
|
|
@@ -68,17 +72,18 @@ function getNextSeriesFocusedItem(state) {
|
|
|
68
72
|
};
|
|
69
73
|
}
|
|
70
74
|
function getPreviousSeriesFocusedItem(state) {
|
|
75
|
+
const processedSeries = selectorChartSeriesProcessed(state);
|
|
71
76
|
let {
|
|
72
77
|
type,
|
|
73
78
|
seriesId
|
|
74
79
|
} = state.keyboardNavigation.item ?? {};
|
|
75
|
-
const previousSeries = getPreviousSeriesWithData(
|
|
80
|
+
const previousSeries = getPreviousSeriesWithData(processedSeries, type, seriesId);
|
|
76
81
|
if (previousSeries === null) {
|
|
77
82
|
return null; // No series to move the focus to.
|
|
78
83
|
}
|
|
79
84
|
type = previousSeries.type;
|
|
80
85
|
seriesId = previousSeries.seriesId;
|
|
81
|
-
const dataLength =
|
|
86
|
+
const dataLength = processedSeries[type].series[seriesId].data.length;
|
|
82
87
|
return {
|
|
83
88
|
type,
|
|
84
89
|
seriesId,
|
|
@@ -15,6 +15,6 @@ export declare const selectorAllSeriesOfType: (args_0: import("./plugins/corePlu
|
|
|
15
15
|
} | undefined;
|
|
16
16
|
export declare const selectorSeriesOfType: (args_0: import("./plugins/corePlugins/useChartId/useChartId.types.js").UseChartIdState & import("./plugins/corePlugins/useChartExperimentalFeature/useChartExperimentalFeature.types.js").UseChartExperimentalFeaturesState & import("./plugins/corePlugins/useChartDimensions/useChartDimensions.types.js").UseChartDimensionsState & import("./plugins/corePlugins/useChartSeries/useChartSeries.types.js").UseChartSeriesState<keyof ChartsSeriesConfig> & import("./plugins/corePlugins/useChartAnimation/useChartAnimation.types.js").UseChartAnimationState & import("./index.js").UseChartInteractionListenerState & Partial<{}> & {
|
|
17
17
|
cacheKey: import("./index.js").ChartStateCacheKey;
|
|
18
|
-
}, seriesType: keyof ChartsSeriesConfig, ids?: SeriesId | SeriesId[] | undefined) => import("../index.js").
|
|
18
|
+
}, seriesType: keyof ChartsSeriesConfig, ids?: SeriesId | SeriesId[] | undefined) => import("../index.js").DefaultizedRadarSeriesType | import("../index.js").DefaultizedLineSeriesType | import("../index.js").DefaultizedBarSeriesType | import("../index.js").DefaultizedScatterSeriesType | import("../index.js").DefaultizedPieSeriesType | (import("../index.js").DefaultizedRadarSeriesType | import("../index.js").DefaultizedLineSeriesType | import("../index.js").DefaultizedBarSeriesType | import("../index.js").DefaultizedScatterSeriesType | import("../index.js").DefaultizedPieSeriesType | undefined)[] | undefined;
|
|
19
19
|
export declare const useAllSeriesOfType: <T extends keyof ChartsSeriesConfig>(seriesType: T) => ProcessedSeries[T];
|
|
20
20
|
export declare const useSeriesOfType: <T extends keyof ChartsSeriesConfig>(seriesType: T, seriesId?: SeriesId | SeriesId[]) => ChartSeriesDefaultized<T> | ChartSeriesDefaultized<T>[] | undefined;
|
|
@@ -9,11 +9,6 @@ export declare const useInteractionItemProps: (data: SeriesItemIdentifierWithDat
|
|
|
9
9
|
onPointerLeave?: () => void;
|
|
10
10
|
onPointerDown?: (event: React.PointerEvent) => void;
|
|
11
11
|
};
|
|
12
|
-
export declare const useInteractionAllItemProps: (data: SeriesItemIdentifierWithData[], skip?: boolean) => {
|
|
13
|
-
onPointerEnter?: () => void;
|
|
14
|
-
onPointerLeave?: () => void;
|
|
15
|
-
onPointerDown?: (event: React.PointerEvent) => void;
|
|
16
|
-
}[];
|
|
17
12
|
export declare function getInteractionItemProps(instance: ChartInstance<[UseChartInteractionSignature, UseChartHighlightSignature]>, item: ChartItemIdentifierWithData<ChartSeriesType>): {
|
|
18
13
|
onPointerEnter?: () => void;
|
|
19
14
|
onPointerLeave?: () => void;
|
|
@@ -7,7 +7,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
value: true
|
|
8
8
|
});
|
|
9
9
|
exports.getInteractionItemProps = getInteractionItemProps;
|
|
10
|
-
exports.useInteractionItemProps =
|
|
10
|
+
exports.useInteractionItemProps = void 0;
|
|
11
11
|
var React = _interopRequireWildcard(require("react"));
|
|
12
12
|
var _useEventCallback = _interopRequireDefault(require("@mui/utils/useEventCallback"));
|
|
13
13
|
var _ChartProvider = require("../context/ChartProvider");
|
|
@@ -48,18 +48,6 @@ const useInteractionItemProps = (data, skip) => {
|
|
|
48
48
|
}, [skip, onPointerEnter, onPointerLeave]);
|
|
49
49
|
};
|
|
50
50
|
exports.useInteractionItemProps = useInteractionItemProps;
|
|
51
|
-
const useInteractionAllItemProps = (data, skip) => {
|
|
52
|
-
const {
|
|
53
|
-
instance
|
|
54
|
-
} = (0, _ChartProvider.useChartContext)();
|
|
55
|
-
const results = React.useMemo(() => {
|
|
56
|
-
return data.map(item => {
|
|
57
|
-
return skip ? {} : getInteractionItemProps(instance, item);
|
|
58
|
-
});
|
|
59
|
-
}, [data, instance, skip]);
|
|
60
|
-
return results;
|
|
61
|
-
};
|
|
62
|
-
exports.useInteractionAllItemProps = useInteractionAllItemProps;
|
|
63
51
|
function getInteractionItemProps(instance, item) {
|
|
64
52
|
function onPointerEnter() {
|
|
65
53
|
if (!item) {
|
package/hooks/useTicks.js
CHANGED
|
@@ -17,6 +17,9 @@ const offsetRatio = {
|
|
|
17
17
|
end: 1,
|
|
18
18
|
middle: 0.5
|
|
19
19
|
};
|
|
20
|
+
function getTickPosition(scale, value, placement) {
|
|
21
|
+
return scale(value) - (scale.step() - scale.bandwidth()) / 2 + offsetRatio[placement] * scale.step();
|
|
22
|
+
}
|
|
20
23
|
function getTicks(options) {
|
|
21
24
|
const {
|
|
22
25
|
scale,
|
|
@@ -35,7 +38,13 @@ function getTicks(options) {
|
|
|
35
38
|
if (scale.bandwidth() > 0) {
|
|
36
39
|
// scale type = 'band'
|
|
37
40
|
const filteredDomain = typeof tickInterval === 'function' && domain.filter(tickInterval) || typeof tickInterval === 'object' && tickInterval || domain;
|
|
38
|
-
|
|
41
|
+
const isReversed = scale.range()[0] > scale.range()[1];
|
|
42
|
+
// Indexes are inclusive regarding the entire band.
|
|
43
|
+
const startIndex = filteredDomain.findIndex(value => {
|
|
44
|
+
return isInside(getTickPosition(scale, value, isReversed ? 'start' : 'end'));
|
|
45
|
+
});
|
|
46
|
+
const endIndex = filteredDomain.findLastIndex(value => isInside(getTickPosition(scale, value, isReversed ? 'end' : 'start')));
|
|
47
|
+
return [...filteredDomain.slice(startIndex, endIndex + 1).map(value => {
|
|
39
48
|
const defaultTickLabel = `${value}`;
|
|
40
49
|
return {
|
|
41
50
|
value,
|
|
@@ -45,10 +54,10 @@ function getTicks(options) {
|
|
|
45
54
|
tickNumber,
|
|
46
55
|
defaultTickLabel
|
|
47
56
|
}) ?? defaultTickLabel,
|
|
48
|
-
offset:
|
|
57
|
+
offset: getTickPosition(scale, value, tickPlacement),
|
|
49
58
|
labelOffset: tickLabelPlacement === 'tick' ? 0 : scale.step() * (offsetRatio[tickLabelPlacement] - offsetRatio[tickPlacement])
|
|
50
59
|
};
|
|
51
|
-
}), ...(tickPlacement === 'extremities' ? [{
|
|
60
|
+
}), ...(tickPlacement === 'extremities' && endIndex === domain.length - 1 && isInside(scale.range()[1]) ? [{
|
|
52
61
|
formattedValue: undefined,
|
|
53
62
|
offset: scale.range()[1],
|
|
54
63
|
labelOffset: 0
|
package/index.js
CHANGED
|
@@ -1,23 +1,29 @@
|
|
|
1
1
|
import { AllSeriesType } from "../../../../models/seriesType/index.js";
|
|
2
2
|
import { ChartSeriesType, DatasetType } from "../../../../models/seriesType/config.js";
|
|
3
3
|
import { ChartSeriesConfig } from "../../models/seriesConfig/index.js";
|
|
4
|
-
import {
|
|
4
|
+
import { DefaultizedSeriesGroups, ProcessedSeries } from "./useChartSeries.types.js";
|
|
5
5
|
/**
|
|
6
|
-
* This
|
|
7
|
-
*
|
|
8
|
-
* It also add defaultized values such as the ids, colors
|
|
6
|
+
* This method groups series by type and adds defaultized values such as the ids and colors.
|
|
7
|
+
* It does NOT apply the series processors - that happens in a selector.
|
|
9
8
|
* @param series The array of series provided by the developer
|
|
10
9
|
* @param colors The color palette used to defaultize series colors
|
|
11
|
-
* @returns An object structuring all the series by type.
|
|
10
|
+
* @returns An object structuring all the series by type with default values.
|
|
12
11
|
*/
|
|
13
|
-
export declare const
|
|
12
|
+
export declare const defaultizeSeries: <TSeriesType extends ChartSeriesType>({
|
|
14
13
|
series,
|
|
15
14
|
colors,
|
|
16
|
-
seriesConfig
|
|
17
|
-
dataset
|
|
15
|
+
seriesConfig
|
|
18
16
|
}: {
|
|
19
17
|
series: Readonly<AllSeriesType<TSeriesType>[]>;
|
|
20
18
|
colors: readonly string[];
|
|
21
19
|
seriesConfig: ChartSeriesConfig<TSeriesType>;
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
}) => DefaultizedSeriesGroups<TSeriesType>;
|
|
21
|
+
/**
|
|
22
|
+
* Applies series processors to the defaultized series groups.
|
|
23
|
+
* This should be called in a selector to compute processed series on-demand.
|
|
24
|
+
* @param defaultizedSeries The defaultized series groups
|
|
25
|
+
* @param seriesConfig The series configuration
|
|
26
|
+
* @param dataset The optional dataset
|
|
27
|
+
* @returns Processed series with all transformations applied
|
|
28
|
+
*/
|
|
29
|
+
export declare const applySeriesProcessors: <TSeriesType extends ChartSeriesType>(defaultizedSeries: DefaultizedSeriesGroups<TSeriesType>, seriesConfig: ChartSeriesConfig<TSeriesType>, dataset?: Readonly<DatasetType>) => ProcessedSeries<TSeriesType>;
|
|
@@ -3,26 +3,21 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.defaultizeSeries = exports.applySeriesProcessors = void 0;
|
|
7
7
|
/**
|
|
8
|
-
* This
|
|
9
|
-
*
|
|
10
|
-
* It also add defaultized values such as the ids, colors
|
|
8
|
+
* This method groups series by type and adds defaultized values such as the ids and colors.
|
|
9
|
+
* It does NOT apply the series processors - that happens in a selector.
|
|
11
10
|
* @param series The array of series provided by the developer
|
|
12
11
|
* @param colors The color palette used to defaultize series colors
|
|
13
|
-
* @returns An object structuring all the series by type.
|
|
12
|
+
* @returns An object structuring all the series by type with default values.
|
|
14
13
|
*/
|
|
15
|
-
const
|
|
14
|
+
const defaultizeSeries = ({
|
|
16
15
|
series,
|
|
17
16
|
colors,
|
|
18
|
-
seriesConfig
|
|
19
|
-
dataset
|
|
17
|
+
seriesConfig
|
|
20
18
|
}) => {
|
|
21
19
|
// Group series by type
|
|
22
20
|
const seriesGroups = {};
|
|
23
|
-
// Notice the line about uses `ChartSeriesType` instead of TSeriesType.
|
|
24
|
-
// That's probably because the series.type is not propagated from the generic but hardcoded in the config.
|
|
25
|
-
|
|
26
21
|
series.forEach((seriesData, seriesIndex) => {
|
|
27
22
|
const seriesWithDefaultValues = seriesConfig[seriesData.type].getSeriesWithDefaultValues(seriesData, seriesIndex, colors);
|
|
28
23
|
const id = seriesWithDefaultValues.id;
|
|
@@ -38,14 +33,28 @@ const preprocessSeries = ({
|
|
|
38
33
|
seriesGroups[seriesData.type].series[id] = seriesWithDefaultValues;
|
|
39
34
|
seriesGroups[seriesData.type].seriesOrder.push(id);
|
|
40
35
|
});
|
|
36
|
+
return seriesGroups;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Applies series processors to the defaultized series groups.
|
|
41
|
+
* This should be called in a selector to compute processed series on-demand.
|
|
42
|
+
* @param defaultizedSeries The defaultized series groups
|
|
43
|
+
* @param seriesConfig The series configuration
|
|
44
|
+
* @param dataset The optional dataset
|
|
45
|
+
* @returns Processed series with all transformations applied
|
|
46
|
+
*/
|
|
47
|
+
exports.defaultizeSeries = defaultizeSeries;
|
|
48
|
+
const applySeriesProcessors = (defaultizedSeries, seriesConfig, dataset) => {
|
|
41
49
|
const processedSeries = {};
|
|
50
|
+
|
|
42
51
|
// Apply formatter on a type group
|
|
43
52
|
Object.keys(seriesConfig).forEach(type => {
|
|
44
|
-
const group =
|
|
53
|
+
const group = defaultizedSeries[type];
|
|
45
54
|
if (group !== undefined) {
|
|
46
|
-
processedSeries[type] = seriesConfig[type]?.seriesProcessor?.(group, dataset) ??
|
|
55
|
+
processedSeries[type] = seriesConfig[type]?.seriesProcessor?.(group, dataset) ?? group;
|
|
47
56
|
}
|
|
48
57
|
});
|
|
49
58
|
return processedSeries;
|
|
50
59
|
};
|
|
51
|
-
exports.
|
|
60
|
+
exports.applySeriesProcessors = applySeriesProcessors;
|
|
@@ -32,11 +32,10 @@ const useChartSeries = ({
|
|
|
32
32
|
return;
|
|
33
33
|
}
|
|
34
34
|
store.set('series', (0, _extends2.default)({}, store.state.series, {
|
|
35
|
-
|
|
35
|
+
defaultizedSeries: (0, _processSeries.defaultizeSeries)({
|
|
36
36
|
series,
|
|
37
37
|
colors: typeof colors === 'function' ? colors(theme) : colors,
|
|
38
|
-
seriesConfig
|
|
39
|
-
dataset
|
|
38
|
+
seriesConfig
|
|
40
39
|
}),
|
|
41
40
|
dataset
|
|
42
41
|
}));
|
|
@@ -67,11 +66,10 @@ useChartSeries.getInitialState = ({
|
|
|
67
66
|
return {
|
|
68
67
|
series: {
|
|
69
68
|
seriesConfig,
|
|
70
|
-
|
|
69
|
+
defaultizedSeries: (0, _processSeries.defaultizeSeries)({
|
|
71
70
|
series,
|
|
72
71
|
colors: typeof colors === 'function' ? colors(theme) : colors,
|
|
73
|
-
seriesConfig
|
|
74
|
-
dataset
|
|
72
|
+
seriesConfig
|
|
75
73
|
}),
|
|
76
74
|
dataset
|
|
77
75
|
}
|
|
@@ -1,17 +1,24 @@
|
|
|
1
1
|
import { ChartRootSelector } from "../../utils/selectors.js";
|
|
2
2
|
import { UseChartSeriesSignature } from "./useChartSeries.types.js";
|
|
3
3
|
export declare const selectorChartSeriesState: ChartRootSelector<UseChartSeriesSignature>;
|
|
4
|
-
export declare const
|
|
4
|
+
export declare const selectorChartDefaultizedSeries: (args_0: import("../useChartId/useChartId.types.js").UseChartIdState & import("../useChartExperimentalFeature/useChartExperimentalFeature.types.js").UseChartExperimentalFeaturesState & import("../useChartDimensions/useChartDimensions.types.js").UseChartDimensionsState & import("./useChartSeries.types.js").UseChartSeriesState<keyof import("../../../index.js").ChartsSeriesConfig> & import("../useChartAnimation/useChartAnimation.types.js").UseChartAnimationState & import("../useChartInteractionListener/index.js").UseChartInteractionListenerState & Partial<{}> & {
|
|
5
5
|
cacheKey: import("../../models/index.js").ChartStateCacheKey;
|
|
6
|
-
}) => import("./useChartSeries.types.js").
|
|
6
|
+
}) => import("./useChartSeries.types.js").DefaultizedSeriesGroups<keyof import("../../../index.js").ChartsSeriesConfig>;
|
|
7
7
|
export declare const selectorChartSeriesConfig: (args_0: import("../useChartId/useChartId.types.js").UseChartIdState & import("../useChartExperimentalFeature/useChartExperimentalFeature.types.js").UseChartExperimentalFeaturesState & import("../useChartDimensions/useChartDimensions.types.js").UseChartDimensionsState & import("./useChartSeries.types.js").UseChartSeriesState<keyof import("../../../index.js").ChartsSeriesConfig> & import("../useChartAnimation/useChartAnimation.types.js").UseChartAnimationState & import("../useChartInteractionListener/index.js").UseChartInteractionListenerState & Partial<{}> & {
|
|
8
8
|
cacheKey: import("../../models/index.js").ChartStateCacheKey;
|
|
9
9
|
}) => import("../../models/index.js").ChartSeriesConfig<keyof import("../../../index.js").ChartsSeriesConfig>;
|
|
10
10
|
/**
|
|
11
11
|
* Get the dataset from the series state.
|
|
12
|
-
* @param {ChartState<[UseChartSeriesSignature]>} state The state of the chart.
|
|
13
12
|
* @returns {DatasetType | undefined} The dataset.
|
|
14
13
|
*/
|
|
15
14
|
export declare const selectorChartDataset: (args_0: import("../useChartId/useChartId.types.js").UseChartIdState & import("../useChartExperimentalFeature/useChartExperimentalFeature.types.js").UseChartExperimentalFeaturesState & import("../useChartDimensions/useChartDimensions.types.js").UseChartDimensionsState & import("./useChartSeries.types.js").UseChartSeriesState<keyof import("../../../index.js").ChartsSeriesConfig> & import("../useChartAnimation/useChartAnimation.types.js").UseChartAnimationState & import("../useChartInteractionListener/index.js").UseChartInteractionListenerState & Partial<{}> & {
|
|
16
15
|
cacheKey: import("../../models/index.js").ChartStateCacheKey;
|
|
17
|
-
}) => readonly import("../../../index.js").DatasetElementType<unknown>[] | undefined;
|
|
16
|
+
}) => readonly import("../../../index.js").DatasetElementType<unknown>[] | undefined;
|
|
17
|
+
/**
|
|
18
|
+
* Get the processed series after applying series processors.
|
|
19
|
+
* This selector computes the processed series on-demand from the defaultized series.
|
|
20
|
+
* @returns {ProcessedSeries} The processed series.
|
|
21
|
+
*/
|
|
22
|
+
export declare const selectorChartSeriesProcessed: (args_0: import("../useChartId/useChartId.types.js").UseChartIdState & import("../useChartExperimentalFeature/useChartExperimentalFeature.types.js").UseChartExperimentalFeaturesState & import("../useChartDimensions/useChartDimensions.types.js").UseChartDimensionsState & import("./useChartSeries.types.js").UseChartSeriesState<keyof import("../../../index.js").ChartsSeriesConfig> & import("../useChartAnimation/useChartAnimation.types.js").UseChartAnimationState & import("../useChartInteractionListener/index.js").UseChartInteractionListenerState & Partial<{}> & {
|
|
23
|
+
cacheKey: import("../../models/index.js").ChartStateCacheKey;
|
|
24
|
+
}) => import("./useChartSeries.types.js").ProcessedSeries<keyof import("../../../index.js").ChartsSeriesConfig>;
|
|
@@ -3,16 +3,25 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.selectorChartSeriesState = exports.selectorChartSeriesProcessed = exports.selectorChartSeriesConfig = exports.selectorChartDataset = void 0;
|
|
6
|
+
exports.selectorChartSeriesState = exports.selectorChartSeriesProcessed = exports.selectorChartSeriesConfig = exports.selectorChartDefaultizedSeries = exports.selectorChartDataset = void 0;
|
|
7
7
|
var _store = require("@mui/x-internals/store");
|
|
8
|
+
var _processSeries = require("./processSeries");
|
|
8
9
|
const selectorChartSeriesState = state => state.series;
|
|
9
10
|
exports.selectorChartSeriesState = selectorChartSeriesState;
|
|
10
|
-
const
|
|
11
|
+
const selectorChartDefaultizedSeries = exports.selectorChartDefaultizedSeries = (0, _store.createSelector)(selectorChartSeriesState, seriesState => seriesState.defaultizedSeries);
|
|
11
12
|
const selectorChartSeriesConfig = exports.selectorChartSeriesConfig = (0, _store.createSelector)(selectorChartSeriesState, seriesState => seriesState.seriesConfig);
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
15
|
* Get the dataset from the series state.
|
|
15
|
-
* @param {ChartState<[UseChartSeriesSignature]>} state The state of the chart.
|
|
16
16
|
* @returns {DatasetType | undefined} The dataset.
|
|
17
17
|
*/
|
|
18
|
-
const selectorChartDataset = exports.selectorChartDataset = (0, _store.createSelector)(selectorChartSeriesState, seriesState => seriesState.dataset);
|
|
18
|
+
const selectorChartDataset = exports.selectorChartDataset = (0, _store.createSelector)(selectorChartSeriesState, seriesState => seriesState.dataset);
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Get the processed series after applying series processors.
|
|
22
|
+
* This selector computes the processed series on-demand from the defaultized series.
|
|
23
|
+
* @returns {ProcessedSeries} The processed series.
|
|
24
|
+
*/
|
|
25
|
+
const selectorChartSeriesProcessed = exports.selectorChartSeriesProcessed = (0, _store.createSelectorMemoized)(selectorChartDefaultizedSeries, selectorChartSeriesConfig, selectorChartDataset, function selectorChartSeriesProcessed(defaultizedSeries, seriesConfig, dataset) {
|
|
26
|
+
return (0, _processSeries.applySeriesProcessors)(defaultizedSeries, seriesConfig, dataset);
|
|
27
|
+
});
|
|
@@ -2,7 +2,7 @@ import { AllSeriesType } from "../../../../models/seriesType/index.js";
|
|
|
2
2
|
import { ChartsColorPalette } from "../../../../colorPalettes/index.js";
|
|
3
3
|
import { ChartPluginSignature, ChartSeriesConfig } from "../../models/index.js";
|
|
4
4
|
import { ChartSeriesType, DatasetType } from "../../../../models/seriesType/config.js";
|
|
5
|
-
import { SeriesProcessorResult } from "../../models/seriesConfig/seriesProcessor.types.js";
|
|
5
|
+
import { SeriesProcessorParams, SeriesProcessorResult } from "../../models/seriesConfig/seriesProcessor.types.js";
|
|
6
6
|
export interface UseChartSeriesParameters<T extends ChartSeriesType = ChartSeriesType> {
|
|
7
7
|
/**
|
|
8
8
|
* An array of objects that can be used to populate series and axes data using their `dataKey` property.
|
|
@@ -36,9 +36,10 @@ export type UseChartSeriesDefaultizedParameters<T extends ChartSeriesType = Char
|
|
|
36
36
|
theme: 'light' | 'dark';
|
|
37
37
|
};
|
|
38
38
|
export type ProcessedSeries<TSeriesTypes extends ChartSeriesType = ChartSeriesType> = { [type in TSeriesTypes]?: SeriesProcessorResult<type> };
|
|
39
|
+
export type DefaultizedSeriesGroups<TSeriesTypes extends ChartSeriesType = ChartSeriesType> = { [type in TSeriesTypes]?: SeriesProcessorParams<type> };
|
|
39
40
|
export interface UseChartSeriesState<T extends ChartSeriesType = ChartSeriesType> {
|
|
40
41
|
series: {
|
|
41
|
-
|
|
42
|
+
defaultizedSeries: DefaultizedSeriesGroups<T>;
|
|
42
43
|
seriesConfig: ChartSeriesConfig<T>;
|
|
43
44
|
dataset?: Readonly<DatasetType>;
|
|
44
45
|
};
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.useChartHighlight = void 0;
|
|
8
8
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
9
|
+
var _warning = require("@mui/x-internals/warning");
|
|
9
10
|
var _useAssertModelConsistency = require("@mui/x-internals/useAssertModelConsistency");
|
|
10
11
|
var _useEventCallback = _interopRequireDefault(require("@mui/utils/useEventCallback"));
|
|
11
12
|
var _useEnhancedEffect = _interopRequireDefault(require("@mui/utils/useEnhancedEffect"));
|
|
@@ -27,27 +28,34 @@ const useChartHighlight = ({
|
|
|
27
28
|
item: params.highlightedItem
|
|
28
29
|
}));
|
|
29
30
|
}
|
|
31
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
32
|
+
if (params.highlightedItem !== undefined && !store.state.highlight.isControlled) {
|
|
33
|
+
(0, _warning.warnOnce)(['MUI X Charts: The `highlightedItem` switched between controlled and uncontrolled state.', 'To remove the highlight when using controlled state, you must provide `null` to the `highlightedItem` prop instead of `undefined`.'].join('\n'));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
30
36
|
}, [store, params.highlightedItem]);
|
|
31
37
|
const clearHighlight = (0, _useEventCallback.default)(() => {
|
|
32
38
|
params.onHighlightChange?.(null);
|
|
33
|
-
const
|
|
34
|
-
if (
|
|
39
|
+
const prevHighlight = store.getSnapshot().highlight;
|
|
40
|
+
if (prevHighlight.item === null || prevHighlight.isControlled) {
|
|
35
41
|
return;
|
|
36
42
|
}
|
|
37
43
|
store.set('highlight', {
|
|
38
44
|
item: null,
|
|
39
|
-
lastUpdate: 'pointer'
|
|
45
|
+
lastUpdate: 'pointer',
|
|
46
|
+
isControlled: false
|
|
40
47
|
});
|
|
41
48
|
});
|
|
42
49
|
const setHighlight = (0, _useEventCallback.default)(newItem => {
|
|
43
|
-
const
|
|
44
|
-
if ((0, _fastObjectShallowCompare.fastObjectShallowCompare)(
|
|
50
|
+
const prevHighlight = store.getSnapshot().highlight;
|
|
51
|
+
if (prevHighlight.isControlled || (0, _fastObjectShallowCompare.fastObjectShallowCompare)(prevHighlight.item, newItem)) {
|
|
45
52
|
return;
|
|
46
53
|
}
|
|
47
54
|
params.onHighlightChange?.(newItem);
|
|
48
55
|
store.set('highlight', {
|
|
49
56
|
item: newItem,
|
|
50
|
-
lastUpdate: 'pointer'
|
|
57
|
+
lastUpdate: 'pointer',
|
|
58
|
+
isControlled: false
|
|
51
59
|
});
|
|
52
60
|
});
|
|
53
61
|
return {
|
|
@@ -58,15 +66,11 @@ const useChartHighlight = ({
|
|
|
58
66
|
};
|
|
59
67
|
};
|
|
60
68
|
exports.useChartHighlight = useChartHighlight;
|
|
61
|
-
useChartHighlight.getDefaultizedParams = ({
|
|
62
|
-
params
|
|
63
|
-
}) => (0, _extends2.default)({}, params, {
|
|
64
|
-
highlightedItem: params.highlightedItem ?? null
|
|
65
|
-
});
|
|
66
69
|
useChartHighlight.getInitialState = params => ({
|
|
67
70
|
highlight: {
|
|
68
71
|
item: params.highlightedItem,
|
|
69
|
-
lastUpdate: 'pointer'
|
|
72
|
+
lastUpdate: 'pointer',
|
|
73
|
+
isControlled: params.highlightedItem !== undefined
|
|
70
74
|
}
|
|
71
75
|
});
|
|
72
76
|
useChartHighlight.params = {
|