Skip to content
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

[charts] Allow multiple axes in the tooltip #17058

Open
wants to merge 25 commits into
base: master
Choose a base branch
from

Conversation

alexfauquette
Copy link
Member

@alexfauquette alexfauquette commented Mar 20, 2025

This is the followup of #17039

The issue

The current behavior of Tooltip with trigger="axis" is handcrafted. The main idea was

If the default x-axis has some data we display the tooltip for it. Otherwise we look at the default y-axis

This does not scale anymore with:

  1. The request to control the tooltip
  2. The request to show multiple axes values in a tooltip
  3. The support of rotation and radius axes.

Proposed aproach

  • axes are responsible to say if they trigger the tooltip or not with triggerTooltip paprameter.
  • the default value of this parameter is defined by the seriesConfig. For now bar and line set heirs x/y axies as triggering the tooltip according to their direction
  • Knowing it the tooltip with axis trigger is open now resumes to look at all axes with triggerTooltip=true and test if the current point position corresponds to a value.

Needed refinement before merging

  • The default render of the tooltip is not exactly the same now that we can have multiple axes. Will need to go deeper in https://www.w3.org/WAI/tutorials/tables/multi-level/
  • The hook for axis tooltip signature is not the same anymore. We could add a parameter allowMultipleAxes. If this parameter is false or undefined we only return the first axis. Otherwise we return the array of axes.

Changelog

Breaking change

The tooltip DOM structure is modified to improve accessibility.
If you relied on it to apply some style or run tests, you might be impacted by this modification.

The axis tooltip displays a table per axis with the axis value in a caption.
Cells containing the series label are now th cells instead of td.

The item tooltip content is a simple p component with a span for series label and item value.

@alexfauquette alexfauquette added enhancement This is not a bug, nor a new feature component: charts This is the name of the generic UI component, not the React module! labels Mar 20, 2025
Copy link

Thanks for adding a type label to the PR! 👍

@mui-bot
Copy link

mui-bot commented Mar 20, 2025

Copy link

codspeed-hq bot commented Mar 20, 2025

CodSpeed Performance Report

Merging #17058 will not alter performance

Comparing alexfauquette:update-tooltip-axis (1acb72a) with master (d4c087c)

Summary

✅ 8 untouched benchmarks

export interface UseChartInteractionState {
interaction: {
/**
* The item currently interacting.
*/
item: null | ChartItemIdentifier<ChartSeriesType>;
/**
* The x- and y-axes currently interacting.
* The x/y SVG coordinate of the "main" pointer
Copy link
Member

Choose a reason for hiding this comment

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

What is the "main" pointer?

Copy link
Member Author

Choose a reason for hiding this comment

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

I thaught about multip pointer interaction. Since we only store one point, it's the main one. How to handle this multi-point is an open quesiton

Copy link

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

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Mar 24, 2025
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Mar 24, 2025
Comment on lines 34 to 38
/**
* If `true`, the hook returns an array with an object per active axis.
* @deprecated In future version, the `multipleAxes=true` will be the unique behavior
*/
multipleAxes?: boolean;
Copy link
Member

Choose a reason for hiding this comment

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

Instead of overloading useAxisTooltip would it make sense to create a useAxesTooltips instead and deprecate this useAxisTooltip?

I suppose it would make it easier to identify the deprecated code, as well as writing a codemod. Plus, the hook name would more closely follow what's happening: we're obtaining the tooltip content of all axes.

Copy link
Member Author

Choose a reason for hiding this comment

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

I tried to do it without breaking changes, And then realised I had to modify the tooltip content.

Based on your comment, I created useAxesTooltips(params) = useAxisTooltips({...params, multipleAxies: true}) to avoid having similar logic in tow files. In next major we will be able to merge the two file together.

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Mar 26, 2025
Copy link

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 Mar 27, 2025
index === null || value === null ? null : { index, value },
);
/**
* Know if tooltip is active for y-axis
Copy link
Member

Choose a reason for hiding this comment

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

Is this comment accurate? It's preceding a selector called selectorChartsInteractionTooltipXAxes, which leads me to believe that something is off.

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Mar 28, 2025
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change component: charts This is the name of the generic UI component, not the React module! enhancement This is not a bug, nor a new feature PR: out-of-date The pull request has merge conflicts and can't be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants