Skip to content

[charts] Improve axis tooltip performances #17398

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { isDeepEqual } from '@mui/x-internals/isDeepEqual';
import { createSelector } from '../../utils/selectors';
import { AxisId, ChartsAxisProps } from '../../../../models/axis';
import {
Expand Down Expand Up @@ -109,9 +110,22 @@ export const selectorChartsInteractionTooltipXAxes = createSelector(

return axes.axisIds
.filter((id) => axes.axis[id].triggerTooltip)
.map((axisId) => ({ axisId, dataIndex: getAxisIndex(axes.axis[axisId], value) }))
.map(
(axisId): AxisItemIdentifier => ({
axisId,
dataIndex: getAxisIndex(axes.axis[axisId], value),
}),
)
.filter(({ dataIndex }) => dataIndex >= 0);
},
{
memoizeOptions: {
// Keep the same reference if array content is the same.
// If possible, avoid this pattern by creating selectors that
// uses string/number as arguments.
resultEqualityCheck: isDeepEqual,
},
},
);

/**
Expand All @@ -126,9 +140,22 @@ export const selectorChartsInteractionTooltipYAxes = createSelector(

return axes.axisIds
.filter((id) => axes.axis[id].triggerTooltip)
.map((axisId) => ({ axisId, dataIndex: getAxisIndex(axes.axis[axisId], value) }))
.map(
(axisId): AxisItemIdentifier => ({
axisId,
dataIndex: getAxisIndex(axes.axis[axisId], value),
}),
)
.filter(({ dataIndex }) => dataIndex >= 0);
},
{
memoizeOptions: {
// Keep the same reference if array content is the same.
// If possible, avoid this pattern by creating selectors that
// uses string/number as arguments.
resultEqualityCheck: isDeepEqual,
},
},
);

/**
Expand All @@ -138,3 +165,5 @@ export const selectorChartsInteractionAxisTooltip = createSelector(
[selectorChartsInteractionTooltipXAxes, selectorChartsInteractionTooltipYAxes],
(xTooltip, yTooltip) => xTooltip.length > 0 || yTooltip.length > 0,
);

export type AxisItemIdentifier = { axisId: string; dataIndex: number };
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { isDeepEqual } from '@mui/x-internals/isDeepEqual';
import { AxisId, ChartsAxisProps } from '../../../../models/axis';
import { createSelector } from '../../utils/selectors';
import type { AxisItemIdentifier } from '../useChartCartesianAxis/useChartCartesianInteraction.selectors';
import {
selectorChartsInteractionPointerX,
selectorChartsInteractionPointerY,
Expand Down Expand Up @@ -96,9 +98,17 @@ export const selectorChartsInteractionTooltipRotationAxes = createSelector(
}

return axes.axisIds
.map((axisId, axisIndex) => ({ axisId, dataIndex: indexes[axisIndex] }))
.map((axisId, axisIndex): AxisItemIdentifier => ({ axisId, dataIndex: indexes[axisIndex] }))
.filter(({ axisId, dataIndex }) => axes.axis[axisId].triggerTooltip && dataIndex >= 0);
},
{
memoizeOptions: {
// Keep the same reference if array content is the same.
// If possible, avoid this pattern by creating selectors that
// uses string/number as arguments.
resultEqualityCheck: isDeepEqual,
},
},
);

/**
Expand Down