-
Notifications
You must be signed in to change notification settings - Fork 11.9k
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
Tooltip xAlign miscalculated when yAlign set to 'center' via options #5693
Comments
I understand this may be an edge-case (no pun intended) but a workable solution for me would be to put those functions used by |
I ended up fixing this for my project be copying over the entire code for |
still happens: https://codepen.io/kurkle/pen/BaQGEdK |
Did some investigation into this. It's due to https://github.com/chartjs/Chart.js/blob/master/src/plugins/plugin.tooltip.js#L266-L267 where the option alignments are only considered at the end. There seem to be 4 possible cases:
I would advocate that we keep try and keep this logic small. It'll be easy to make it very complex, but with the full scriptable options users can supply their own methods to determine the alignment based on the data. |
According to the alignment calculation code the tooltip will automatically align itself to bottom if it sticks out of the bottom of the graph. However, when using
yAlign = 'center'
in your tooltip config then the test is not correct because the final y-position of the tooltip is altered later here.This test should include this alteration.
My case:
Result:
The tooltip will be y-aligned to center but the xAlign behaves as if the yAlign is set to 'bottom'.
When yAlign is set to 'center' the tooltip should have an xAlign of only 'left' or 'right', but when the mentioned test 'corrects' the yAlign to 'bottom' then the xAlign will become
center
and hover over the tooltip-ed value.I can't write a full reproduction/fiddle right now but here are some settings I use in my situation:
Positioner:
And then for data I have something along the lines of:
When you have a vertically small graph (say 200px) then you can easily find a dataset count where the tooltip fits on the screen but xAlign misbehaves.
Screenshots
The text was updated successfully, but these errors were encountered: