Last active
August 29, 2015 14:26
-
-
Save arnicas/c911d0abfe9819305660 to your computer and use it in GitHub Desktop.
HTML/CSS tooltip in D3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<!-- Updated code from Christophe Viau for a d3 tooltip in the old days: | |
https://gist.github.com/biovisualize/1016860 --> | |
<html > | |
<head> | |
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/d3/3.5.6/d3.min.js"></script> | |
</head> | |
<body> | |
<div class="example_div"></div> | |
<script type="text/javascript"> | |
var tooltip = d3.select("body") | |
.append("div") | |
.style("position", "absolute") | |
.style("z-index", "10") | |
.style("visibility", "hidden") | |
.text("a simple tooltip"); | |
var sampleSVG = d3.select(".example_div") | |
.append("svg") | |
.attr("class", "sample") | |
.attr("width", 300) | |
.attr("height", 300); | |
d3.select(".example_div svg") | |
.append("circle") | |
.attr("stroke", "black") | |
.attr("fill", "aliceblue") | |
.attr("r", 50) | |
.attr("cx", 52) | |
.attr("cy", 52) | |
.on("mouseover", function(){return tooltip.style("visibility", "visible");}) | |
.on("mousemove", function(){return tooltip.style("top", (event.pageY-10)+"px").style("left",(event.pageX+10)+"px");}) | |
.on("mouseout", function(){return tooltip.style("visibility", "hidden");}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment