Skip to content

Instantly share code, notes, and snippets.

@ryanpitts
Created March 19, 2014 00:00
Show Gist options
  • Save ryanpitts/9632711 to your computer and use it in GitHub Desktop.
Save ryanpitts/9632711 to your computer and use it in GitHub Desktop.
hover stuff
chart.mousemove = function() {
var mouseTop = d3.mouse(this)[1],
mouseLeft = d3.mouse(this)[0],
bufferTop = chart.screenPosition.top + mouseTop - chart.hovercard.dimensions.height,
bufferRight = browserWidth - (chart.screenPosition.left + mouseLeft + chart.hovercard.dimensions.width);
chart.hovercard.position = {
top: (bufferTop < 10) ? mouseTop + 5 : mouseTop - chart.hovercard.dimensions.height - 5,
left: (bufferRight < 10) ? mouseLeft - chart.hovercard.dimensions.width - 5 : mouseLeft + 5
}
chart.hovercard
.style("left", (chart.hovercard.position.left) + "px")
.style("top", (chart.hovercard.position.top) + "px");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment