Skip to content
This repository has been archived by the owner on Feb 9, 2024. It is now read-only.

Fix tooltip positioning to keep it from going off page. #392

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion R/interact_tooltip.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ add_tooltip <- function(vis, html, on = c("hover", "click")) {
if (is.null(html)) {
hide_tooltip(session)
} else {
show_tooltip(session, location$x + 5, location$y + 5, html)
show_tooltip(session, location$x, location$y, html)
}
}
hide_tooltip2 <- function(session) {
Expand Down
20 changes: 16 additions & 4 deletions inst/www/ggvis/js/shiny-ggvis.js
Original file line number Diff line number Diff line change
Expand Up @@ -445,10 +445,22 @@ $(function(){ //DOM Ready
.appendTo('body');

$el.html(data.html);
$el.css({
left: data.pagex,
top: data.pagey
});
// Adjust horizontal position
if ($(window).width() < (data.pagex + $el.width() + 10)) {
$el
.css("left", (data.pagex - $el.outerWidth() - 5) + "px");
} else {
$el
.css("left", (data.pagex + 5) + "px");
}
// Adjust vertical position
if ($(window).height() < (data.pagey + $el.height() + 10)) {
$el
.css("top", (data.pagey - $el.outerHeight() - 5) + "px");
} else {
$el
.css("top", (data.pagey + 5) + "px");
}
});

ggvis.messages.addHandler("hide_tooltip", function(data, id) {
Expand Down