diff --git a/R/interact_tooltip.R b/R/interact_tooltip.R index 7def1477..ffc64526 100644 --- a/R/interact_tooltip.R +++ b/R/interact_tooltip.R @@ -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) { diff --git a/inst/www/ggvis/js/shiny-ggvis.js b/inst/www/ggvis/js/shiny-ggvis.js index ba30a9d6..4926ba57 100644 --- a/inst/www/ggvis/js/shiny-ggvis.js +++ b/inst/www/ggvis/js/shiny-ggvis.js @@ -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) {