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

[ML] Fix chart tooltip positioning for new K7 navigation #32563

Merged
Merged
Changes from 1 commit
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
Expand Up @@ -32,30 +32,23 @@ mlChartTooltipService.show = function (contents, target, offset = { x: 0, y: 0 }
this.element.html(contents);

// side bar width
const navOffset = $('.kbnGlobalNav').width() || 0;
const contentWidth = $('body').width() - navOffset - 10;
const navOffset = $('.euiNavDrawer').width() || 0; // Offset by width of side navbar
const contentWidth = $('body').width() - navOffset;
const tooltipWidth = this.element.width();
const scrollTop = (window.pageYOffset || doc.scrollTop) - (doc.clientTop || 0);

const pos = target.getBoundingClientRect();
const x = (pos.left + (offset.x) + 4) - navOffset;
const y = pos.top + (offset.y) + scrollTop;

if (x + tooltipWidth > contentWidth) {
let left = (pos.left + (offset.x) + 4) - navOffset;
if (left + tooltipWidth > contentWidth) {
// the tooltip is hanging off the side of the page,
// so move it to the other side of the target
this.element.css({
left: x - (tooltipWidth + offset.x + 22),
top: (y - 28)
});
} else {
this.element.css({
left: x,
top: (y - 28)
});
left = left - (tooltipWidth + offset.x + 22);
}
const top = pos.top + (offset.y) + scrollTop - 75; // Subtract 75 to adjust for height of top nav
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of using the comment for clarifying, this refactor might be an opportunity to first assign the raw number to a more self explanatory variable (see https://github.com/elastic/kibana/blob/master/style_guides/js_style_guide.md#magic-numbersstrings). Could also be done for the 22 two lines above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call. I've moved those two numbers into variables


this.element.css({
left,
top,
opacity: '0.9',
display: 'block'
});
Expand Down