Skip to content

[charts] Unify tooltip item position getter and selector into a single selector API#23041

Merged
alexfauquette merged 19 commits into
mui:masterfrom
alexfauquette:charts/unify-tooltip-item-position-selector
Jul 6, 2026
Merged

[charts] Unify tooltip item position getter and selector into a single selector API#23041
alexfauquette merged 19 commits into
mui:masterfrom
alexfauquette:charts/unify-tooltip-item-position-selector

Conversation

@alexfauquette

Copy link
Copy Markdown
Member

Follow-up from #23011. Closes #23033.

Problem

The series config carried two shapes for positioning an item tooltip:

  • tooltipItemPositionGetter — a getter that received a resolved { series, axesConfig, drawingArea, seriesLayout, identifier, placement } bundle, dispatched centrally by the core selectorChartsTooltipItemPosition selector.
  • selectorTooltipItemPosition — a plain selector reading the chart state directly (introduced for the map series so d3-geo stays out of the core bundle).

Maintaining both is redundant, as noted in #23011 (comment).

Change

Every series type now positions its item tooltip through a single selectorTooltipItemPosition selector. Each selector reads only the state it needs (the relevant axes, the series layout, the geo projection, …) instead of receiving the one-size-fits-all bundle, so:

  • there is a single shape to maintain in ChartSeriesTypeConfig;
  • ChartsTooltipContainer picks the selector uniformly and falls back to pointer-following when a series type provides none;
  • the generic selectorChartsTooltipItemPosition dispatcher, the TooltipItemPositionGetter type and its TooltipPositionGetterAxesConfig helper are removed.

The position math is unchanged — only the way each series reads its inputs.

Commits

One commit per series type so the conversion is easy to review, then a final commit that drops the getter API:

  • bar, line, scatter, pie, radar (@mui/x-charts)
  • funnel, sankey, heatmap (@mui/x-charts-pro)
  • rangeBar, ohlc, radialBar, radialLine (@mui/x-charts-premium)
  • final: drop the tooltipItemPositionGetter type, config field and core dispatcher

The map series already used the selector API and is unchanged.

Testing

  • typescript passes for @mui/x-charts, @mui/x-charts-pro, @mui/x-charts-premium.
  • ChartsTooltip unit tests pass (jsdom + browser).
  • ESLint clean on the changed files.

🤖 Generated with Claude Code

alexfauquette and others added 13 commits July 2, 2026 14:46
… selector

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
All series types now compute their item tooltip position through a
`selectorTooltipItemPosition` selector, so the parallel
`tooltipItemPositionGetter` shape and the generic dispatcher that read it
are no longer needed. Remove the getter type, its config field and the
core `selectorChartsTooltipItemPosition` dispatcher, and fall back to
pointer-following when a series type provides no selector.

Closes mui#23033

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@alexfauquette
alexfauquette requested a review from JCQuintas as a code owner July 2, 2026 13:25
Comment on lines +15 to +18
export type TooltipItemPositionSelector = (
state: ChartState<
[UseChartCartesianAxisSignature, UseChartInteractionSignature, UseChartTooltipSignature]
>,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we make this generic like the old getter signature? To accept SeriesType extends ChartSeriesType

Suggested change
export type TooltipItemPositionSelector = (
state: ChartState<
[UseChartCartesianAxisSignature, UseChartInteractionSignature, UseChartTooltipSignature]
>,
export type TooltipItemPositionSelector<SeriesType extends ChartSeriesType> = (
state: ChartState<
[UseChartCartesianAxisSignature<SeriesType>, UseChartInteractionSignature, UseChartTooltipSignature<SeriesType>]
>,

@github-actions github-actions Bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Jul 2, 2026
@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions github-actions Bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label Jul 2, 2026
@code-infra-dashboard

code-infra-dashboard Bot commented Jul 2, 2026

Copy link
Copy Markdown

Deploy preview

https://deploy-preview-23041--material-ui-x.netlify.app/
QR code for https://deploy-preview-23041--material-ui-x.netlify.app/

Bundle size

Bundle Parsed size Gzip size
@mui/x-data-grid 0B(0.00%) 0B(0.00%)
@mui/x-data-grid-pro 0B(0.00%) 0B(0.00%)
@mui/x-data-grid-premium 0B(0.00%) 0B(0.00%)
@mui/x-charts ▼-400B(-0.10%) ▼-108B(-0.09%)
@mui/x-charts-pro ▼-260B(-0.05%) 🔺+20B(+0.01%)
@mui/x-charts-premium ▼-106B(-0.02%) ▼-11B(-0.01%)
@mui/x-date-pickers 0B(0.00%) 0B(0.00%)
@mui/x-date-pickers-pro 0B(0.00%) 0B(0.00%)
@mui/x-tree-view 0B(0.00%) 0B(0.00%)
@mui/x-tree-view-pro 0B(0.00%) 0B(0.00%)
@mui/x-scheduler 0B(0.00%) 0B(0.00%)
@mui/x-scheduler-premium 0B(0.00%) 0B(0.00%)
@mui/x-chat 0B(0.00%) 0B(0.00%)
@mui/x-license 0B(0.00%) 0B(0.00%)

Details of bundle changes

Performance

Total duration: 2,165.21 ms +86.06 ms(+4.1%) | Renders: 63 (+0)

Test Duration Renders
ScatterChartPremium with big data amount (webgl renderer) 102.87 ms 🔺+20.50 ms(+24.9%) 5 (+0)
LineChart with big data amount (with marks) 97.25 ms 🔺+19.28 ms(+24.7%) 2 (+0)
ScatterChartPro with big data amount (batch renderer) 10.71 ms 🔺+3.27 ms(+43.9%) 2 (+0)
FunnelChart with big data amount 5.71 ms 🔺+0.97 ms(+20.5%) 2 (+0)
BarChartPro with big data amount 37.43 ms ▼-10.65 ms(-22.2%) 2 (+0)

…and 2 more (+19 within noise) — details

Metric alarms

Test Metric Change
ScatterChartPremium with big data amount (webgl renderer) bench:paint 🔺 +17.45 ms
LineChart with big data amount (with marks) bench:paint 🔺 +26.88 ms
ScatterChartPro with big data amount (batch renderer) bench:paint 🔺 +4.56 ms

Check out the code infra dashboard for more information about this PR.

@alexfauquette alexfauquette added type: enhancement It’s an improvement, but we can’t make up our mind whether it's a bug fix or a new feature. scope: charts Changes related to the charts. labels Jul 2, 2026
@alexfauquette
alexfauquette requested a review from JCQuintas July 2, 2026 15:12
Comment on lines +38 to +39
const xAxisId = itemSeries.xAxisId ?? xAxes.axisIds[0];
const yAxisId = itemSeries.yAxisId ?? yAxes.axisIds[0];

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we still check if y/x axes exist? In case user provides wrong id?

@alexfauquette
alexfauquette enabled auto-merge (squash) July 6, 2026 08:08
@alexfauquette
alexfauquette merged commit 4256b15 into mui:master Jul 6, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope: charts Changes related to the charts. type: enhancement It’s an improvement, but we can’t make up our mind whether it's a bug fix or a new feature.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[charts] Unify tooltip item position getter and selector into a single selector API

2 participants