Skip to content

Commit 45baf17

Browse files
[charts] Use directly selector from @mui/x-internals (#20365)
1 parent e65b94a commit 45baf17

File tree

23 files changed

+275
-312
lines changed

23 files changed

+275
-312
lines changed

packages/x-charts-pro/src/FunnelChart/funnelAxisPlugin/useChartFunnelAxisRendering.selectors.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { createSelectorMemoized } from '@mui/x-internals/store';
1+
import { createSelector, createSelectorMemoized } from '@mui/x-internals/store';
22
import {
3-
createSelector,
43
selectorChartSeriesConfig,
54
selectorChartSeriesProcessed,
65
selectorChartDrawingArea,
@@ -14,7 +13,7 @@ import { UseChartFunnelAxisSignature } from './useChartFunnelAxis.types';
1413
export const selectorFunnel = (state: ChartState<[], [UseChartFunnelAxisSignature]>) =>
1514
state.funnel;
1615

17-
export const selectorFunnelGap = createSelector([selectorFunnel], (funnel) => funnel?.gap ?? 0);
16+
export const selectorFunnelGap = createSelector(selectorFunnel, (funnel) => funnel?.gap ?? 0);
1817

1918
export const selectorChartXAxis = createSelectorMemoized(
2019
selectorChartRawXAxis,

packages/x-charts-pro/src/SankeyChart/plugins/useSankeyHighlight.selectors.ts

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
import {
2-
createSelector,
3-
type ChartRootSelector,
4-
type UseChartSeriesSignature,
5-
} from '@mui/x-charts/internals';
1+
import { createSelector } from '@mui/x-internals/store';
2+
import { type ChartRootSelector, type UseChartSeriesSignature } from '@mui/x-charts/internals';
63
import type { UseSankeyHighlightSignature } from './useSankeyHighlight.types';
74
import type { SankeyLayoutLink, SankeyNodeId } from '../sankey.types';
85
import type {
@@ -17,7 +14,7 @@ const selectorSankeyHighlight = (state: UseSankeyHighlightSignature['state']) =>
1714
const selectSeries: ChartRootSelector<UseChartSeriesSignature> = (state) => state.series;
1815

1916
const selectorSankeySeries = createSelector(
20-
[selectSeries],
17+
selectSeries,
2118
(series) =>
2219
series.processedSeries.sankey?.series[series.processedSeries.sankey?.seriesOrder[0]] || null,
2320
);
@@ -31,7 +28,7 @@ const DEFAULT_FADE: SankeyNodeFade & SankeyLinkFade = 'none';
3128
* Defaults to 'nodes' if not specified.
3229
*/
3330
export const selectorNodeHighlightConfig = createSelector(
34-
[selectorSankeySeries],
31+
selectorSankeySeries,
3532
(series): SankeyNodeHighlight => series?.nodeOptions?.highlight ?? DEFAULT_NODE_HIGHLIGHT,
3633
);
3734

@@ -40,7 +37,7 @@ export const selectorNodeHighlightConfig = createSelector(
4037
* Defaults to 'none' if not specified.
4138
*/
4239
export const selectorNodeFadeConfig = createSelector(
43-
[selectorSankeySeries],
40+
selectorSankeySeries,
4441
(series): SankeyNodeFade => series?.nodeOptions?.fade ?? DEFAULT_FADE,
4542
);
4643

@@ -49,7 +46,7 @@ export const selectorNodeFadeConfig = createSelector(
4946
* Defaults to 'links' if not specified.
5047
*/
5148
export const selectorLinkHighlightConfig = createSelector(
52-
[selectorSankeySeries],
49+
selectorSankeySeries,
5350
(series): SankeyLinkHighlight => series?.linkOptions?.highlight ?? DEFAULT_LINK_HIGHLIGHT,
5451
);
5552

@@ -58,7 +55,7 @@ export const selectorLinkHighlightConfig = createSelector(
5855
* Defaults to 'none' if not specified.
5956
*/
6057
export const selectorLinkFadeConfig = createSelector(
61-
[selectorSankeySeries],
58+
selectorSankeySeries,
6259
(series): SankeyLinkFade => series?.linkOptions?.fade ?? DEFAULT_FADE,
6360
);
6461

@@ -68,7 +65,7 @@ export const selectorLinkFadeConfig = createSelector(
6865
* @returns {SankeyItemIdentifier | null} The highlighted item identifier or null.
6966
*/
7067
export const selectorSankeyHighlightedItem = createSelector(
71-
[selectorSankeyHighlight],
68+
selectorSankeyHighlight,
7269
(highlight) => highlight.item,
7370
);
7471

@@ -79,7 +76,9 @@ export const selectorSankeyHighlightedItem = createSelector(
7976
* - It's connected to a highlighted link (based on linkOptions.highlight)
8077
*/
8178
export const selectorIsNodeHighlighted = createSelector(
82-
[selectorSankeyHighlightedItem, selectorNodeHighlightConfig, selectorLinkHighlightConfig],
79+
selectorSankeyHighlightedItem,
80+
selectorNodeHighlightConfig,
81+
selectorLinkHighlightConfig,
8382
(highlightedItem, nodeHighlight, linkHighlight, nodeId: SankeyNodeId): boolean => {
8483
if (!highlightedItem) {
8584
return false;
@@ -119,7 +118,9 @@ export const selectorIsNodeHighlighted = createSelector(
119118
* - It's connected to a highlighted node (based on nodeOptions.highlight)
120119
*/
121120
export const selectorIsLinkHighlighted = createSelector(
122-
[selectorSankeyHighlightedItem, selectorNodeHighlightConfig, selectorLinkHighlightConfig],
121+
selectorSankeyHighlightedItem,
122+
selectorNodeHighlightConfig,
123+
selectorLinkHighlightConfig,
123124
(highlightedItem, nodeHighlight, linkHighlight, link: SankeyLayoutLink): boolean => {
124125
if (!highlightedItem) {
125126
return false;
@@ -164,7 +165,9 @@ export const selectorIsLinkHighlighted = createSelector(
164165
* - The fade mode is 'global' for the highlighted element type
165166
*/
166167
export const selectorIsSankeyItemFaded = createSelector(
167-
[selectorSankeyHighlightedItem, selectorNodeFadeConfig, selectorLinkFadeConfig],
168+
selectorSankeyHighlightedItem,
169+
selectorNodeFadeConfig,
170+
selectorLinkFadeConfig,
168171
(highlightedItem, nodeFade, linkFade, isHighlighted: boolean): boolean => {
169172
if (!highlightedItem || isHighlighted) {
170173
return false;
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
1-
import { createSelector, selectorChartZoomOptionsLookup } from '@mui/x-charts/internals';
1+
import { createSelector } from '@mui/x-internals/store';
2+
import { selectorChartZoomOptionsLookup } from '@mui/x-charts/internals';
23
import { selectorChartZoomState } from './useChartProZoom.selectors';
34
import type { ZoomInteractionName, PanInteractionName } from './ZoomInteractionConfig.types';
45

56
export const selectorZoomInteractionConfig = createSelector(
6-
[selectorChartZoomState],
7+
selectorChartZoomState,
78
(zoomState, interactionName: ZoomInteractionName) =>
89
zoomState.zoomInteractionConfig.zoom[interactionName] ?? null,
910
);
1011

1112
export const selectorPanInteractionConfig = createSelector(
12-
[selectorChartZoomState],
13+
selectorChartZoomState,
1314
(zoomState, interactionName: PanInteractionName) =>
1415
zoomState.zoomInteractionConfig.pan[interactionName] ?? null,
1516
);
1617

1718
export const selectorIsZoomBrushEnabled = createSelector(
18-
[selectorChartZoomOptionsLookup, (state) => selectorZoomInteractionConfig(state, 'brush')],
19+
selectorChartZoomOptionsLookup,
20+
(state) => selectorZoomInteractionConfig(state, 'brush'),
1921
(zoomOptions, zoomInteractionConfig) =>
2022
(Object.keys(zoomOptions).length > 0 && zoomInteractionConfig) || false,
2123
);

packages/x-charts-pro/src/internals/plugins/useChartProZoom/useChartProZoom.selectors.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
import { createSelector } from '@mui/x-internals/store';
12
import {
23
AxisId,
34
ChartRootSelector,
4-
createSelector,
55
selectorChartZoomMap,
66
selectorChartZoomOptionsLookup,
77
} from '@mui/x-charts/internals';
@@ -12,22 +12,23 @@ export const selectorChartZoomState: ChartRootSelector<UseChartProZoomSignature,
1212
) => state.zoom;
1313

1414
export const selectorChartZoomIsInteracting = createSelector(
15-
[selectorChartZoomState],
15+
selectorChartZoomState,
1616
(zoom) => zoom.isInteracting,
1717
);
1818

1919
export const selectorChartZoomIsEnabled = createSelector(
20-
[selectorChartZoomOptionsLookup],
20+
selectorChartZoomOptionsLookup,
2121
(optionsLookup) => Object.keys(optionsLookup).length > 0,
2222
);
2323

2424
export const selectorChartAxisZoomData = createSelector(
25-
[selectorChartZoomMap],
25+
selectorChartZoomMap,
2626
(zoomMap, axisId: AxisId) => zoomMap?.get(axisId),
2727
);
2828

2929
export const selectorChartCanZoomOut = createSelector(
30-
[selectorChartZoomState, selectorChartZoomOptionsLookup],
30+
selectorChartZoomState,
31+
selectorChartZoomOptionsLookup,
3132
(zoomState, zoomOptions) => {
3233
return zoomState.zoomData.every((zoomData) => {
3334
const span = zoomData.end - zoomData.start;
@@ -41,7 +42,8 @@ export const selectorChartCanZoomOut = createSelector(
4142
);
4243

4344
export const selectorChartCanZoomIn = createSelector(
44-
[selectorChartZoomState, selectorChartZoomOptionsLookup],
45+
selectorChartZoomState,
46+
selectorChartZoomOptionsLookup,
4547
(zoomState, zoomOptions) => {
4648
return zoomState.zoomData.every((zoomData) => {
4749
const span = zoomData.end - zoomData.start;
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import { ChartRootSelector, createSelector } from '../../utils/selectors';
1+
import { createSelector } from '@mui/x-internals/store';
2+
import { ChartRootSelector } from '../../utils/selectors';
23
import type { UseChartAnimationSignature } from './useChartAnimation.types';
34

45
const selectorChartAnimationState: ChartRootSelector<UseChartAnimationSignature> = (state) =>
56
state.animation;
67

78
export const selectorChartSkipAnimation = createSelector(
8-
[selectorChartAnimationState],
9+
selectorChartAnimationState,
910
(state) => state.skip || state.skipAnimationRequests > 0,
1011
);

packages/x-charts/src/internals/plugins/corePlugins/useChartDimensions/useChartDimensions.selectors.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { createSelectorMemoized } from '@mui/x-internals/store';
2-
import { ChartRootSelector, createSelector } from '../../utils/selectors';
1+
import { createSelector, createSelectorMemoized } from '@mui/x-internals/store';
2+
import { ChartRootSelector } from '../../utils/selectors';
33
import type { UseChartDimensionsSignature } from './useChartDimensions.types';
44
import { selectorChartAxisSizes } from '../../featurePlugins/useChartCartesianAxis/useChartAxisSize.selectors';
55
import { ChartState } from '../../models/chart';
@@ -32,21 +32,21 @@ export const selectorChartDrawingArea = createSelectorMemoized(
3232
);
3333

3434
export const selectorChartSvgWidth = createSelector(
35-
[selectorChartDimensionsState],
35+
selectorChartDimensionsState,
3636
(dimensionsState) => dimensionsState.width,
3737
);
3838

3939
export const selectorChartSvgHeight = createSelector(
40-
[selectorChartDimensionsState],
40+
selectorChartDimensionsState,
4141
(dimensionsState) => dimensionsState.height,
4242
);
4343

4444
export const selectorChartPropsWidth = createSelector(
45-
[selectorChartDimensionsState],
45+
selectorChartDimensionsState,
4646
(dimensionsState) => dimensionsState.propsWidth,
4747
);
4848

4949
export const selectorChartPropsHeight = createSelector(
50-
[selectorChartDimensionsState],
50+
selectorChartDimensionsState,
5151
(dimensionsState) => dimensionsState.propsHeight,
5252
);
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import { ChartRootSelector, createSelector } from '../../utils/selectors';
1+
import { createSelector } from '@mui/x-internals/store';
2+
import { ChartRootSelector } from '../../utils/selectors';
23
import type { UseChartExperimentalFeaturesSignature } from './useChartExperimentalFeature.types';
34

45
export const selectorChartExperimentalFeaturesState: ChartRootSelector<
56
UseChartExperimentalFeaturesSignature
67
> = (state) => state.experimentalFeatures;
78

89
export const selectorPreferStrictDomainInLineCharts = createSelector(
9-
[selectorChartExperimentalFeaturesState],
10+
selectorChartExperimentalFeaturesState,
1011
(features) => Boolean(features?.preferStrictDomainInLineCharts),
1112
);
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { createSelector, ChartRootSelector } from '../../utils/selectors';
1+
import { createSelector } from '@mui/x-internals/store';
2+
import { ChartRootSelector } from '../../utils/selectors';
23
import { UseChartIdSignature } from './useChartId.types';
34

45
const selectorChartIdState: ChartRootSelector<UseChartIdSignature> = (state) => state.id;
@@ -8,4 +9,4 @@ const selectorChartIdState: ChartRootSelector<UseChartIdSignature> = (state) =>
89
* @param {ChartState<[UseChartIdSignature]>} state The state of the chart.
910
* @returns {string} The id attribute of the chart.
1011
*/
11-
export const selectorChartId = createSelector([selectorChartIdState], (idState) => idState.chartId);
12+
export const selectorChartId = createSelector(selectorChartIdState, (idState) => idState.chartId);
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
import { ChartRootSelector, createSelector } from '../../utils/selectors';
1+
import { createSelector } from '@mui/x-internals/store';
2+
import { ChartRootSelector } from '../../utils/selectors';
23
import { UseChartSeriesSignature } from './useChartSeries.types';
34

45
export const selectorChartSeriesState: ChartRootSelector<UseChartSeriesSignature> = (state) =>
56
state.series;
67

78
export const selectorChartSeriesProcessed = createSelector(
8-
[selectorChartSeriesState],
9+
selectorChartSeriesState,
910
(seriesState) => seriesState.processedSeries,
1011
);
1112

1213
export const selectorChartSeriesConfig = createSelector(
13-
[selectorChartSeriesState],
14+
selectorChartSeriesState,
1415
(seriesState) => seriesState.seriesConfig,
1516
);
1617

@@ -20,6 +21,6 @@ export const selectorChartSeriesConfig = createSelector(
2021
* @returns {DatasetType | undefined} The dataset.
2122
*/
2223
export const selectorChartDataset = createSelector(
23-
[selectorChartSeriesState],
24+
selectorChartSeriesState,
2425
(seriesState) => seriesState.dataset,
2526
);

0 commit comments

Comments
 (0)