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

how can I pin a tooltip in a chart #4387

Open
Marg1na1 opened this issue Apr 4, 2024 · 8 comments
Open

how can I pin a tooltip in a chart #4387

Marg1na1 opened this issue Apr 4, 2024 · 8 comments
Labels
enhancement Enhancement to a current API Tooltip Issues that deal with the Tooltip content, its behaviour, and bugs.

Comments

@Marg1na1
Copy link

Marg1na1 commented Apr 4, 2024

I need to be able to click on the stick and the tooltip stops moving and is fixed to its coordinates, and when the cursor moves, other tooltips are shown to me. When you click on the same coordinates to which the tooltip is currently attached, it should unpin.

@ckifer
Copy link
Member

ckifer commented Apr 4, 2024

This is currently only partially possible. Click and stick is easy enough using the "active" and "defaultIndex" props, but it is impossible to have more than one instance of Tooltip show at once at this point.

https://codesandbox.io/s/l68jc7

@ckifer ckifer added enhancement Enhancement to a current API Tooltip Issues that deal with the Tooltip content, its behaviour, and bugs. question Issue that is a question about recharts rather than a bug or a feature request labels Apr 4, 2024
@relaxtmeee
Copy link

@ckifer
Tow instance of tooltip would solve this problem. Each of them had a different behavior (One reacts to a click, the other to a hover)

@ckifer
Copy link
Member

ckifer commented Apr 4, 2024

sure, but this doesn't work at the moment because recharts prevents multiple instances of Tooltip. You might be able to get it to work with a custom Tooltip component where you remember the clicked Tooltip's position and always render it there if its set. Otherwise, you render the hovered position as normal.

@relaxtmeee
Copy link

@ckifer
It doesn't work as expected, you need to show two tooltips at the same time - clicked (fixed position) and hovered.

I already realized that this cannot be done using reacharts native means.

Thank you for the quick feedback)

@ckifer
Copy link
Member

ckifer commented Apr 4, 2024

Yep agreed. Just trying to give ideas to unblock.

Labelled as an enhancement and something we'll need to add in the future. If someone wants to contribute feel free.

@ckifer
Copy link
Member

ckifer commented Apr 4, 2024

https://master--63da8268a0da9970db6992aa.chromatic.com/?path=/story/examples-tooltip--locked-by-click

This does work to "lock" the tooltip though, it just won't show a second instance when hovering

@ckifer ckifer removed the question Issue that is a question about recharts rather than a bug or a feature request label Apr 4, 2024
@nicogreenarry
Copy link

nicogreenarry commented Apr 16, 2024

This feature is important to me as well. Right now I'm considering a non-native workaround, like when the user pins a point, record the coordinates and use non-Recharts code to render a fake tooltip there.

I suspect it would be difficult or impossible to get the manually-rendered "tooltips" to stay in the correct location if the chart is resized, but I can probably live with that.

But I'd much prefer a native solution to this.

Update:
On second thought, there are some UX issues around having multiple tooltips displayed at the same time (e.g. tooltips will obscure data points and will overlap each other), and I no longer think I'd want this feature. I still want a user to be able to pin certain data points, but I'd prefer to display those pinned data points in a grid or table adjacent to the chart.

@PavelVanecek
Copy link
Collaborator

PavelVanecek commented Apr 17, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Enhancement to a current API Tooltip Issues that deal with the Tooltip content, its behaviour, and bugs.
Projects
None yet
Development

No branches or pull requests

5 participants