Skip to content

Instantly share code, notes, and snippets.

@emepyc
Last active October 10, 2018 08:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emepyc/55b45c2b0b58aac771d8 to your computer and use it in GitHub Desktop.
Save emepyc/55b45c2b0b58aac771d8 to your computer and use it in GitHub Desktop.
Mouseover tooltip

Example of TnT Tooltip showing on mouseover information.

<!DOCTYPE html>
<head>
<script src="http://d3js.org/d3.v5.min.js" charset="utf-8"></script>
<link rel="stylesheet" href="http://tntvis.github.io/tnt.tooltip/build/tnt.tooltip.css" type="text/css"/>
<script src="http://tntvis.github.io/tnt.tooltip/build/tnt.tooltip.min.js"></script>
<style>
.tnt_tooltip {
pointer-events : none;
}
</style>
</head>
<body>
<div id="container" style="padding:30px; position:relative" ></div>
<script>
var hover_tooltip;
var t = function (data) {
var obj = {};
obj.header = "";
obj.body=data.name;
hover_tooltip = tooltip.plain()
.width(180)
.show_closer(false)
.call (this, obj);
};
var svg = d3.select("#container")
.append("svg")
.attr("width", 300)
.attr("height", 300);
svg
.append("circle")
.datum({name:"big and red circle"})
.attr("cx", 150)
.attr("cy", 150)
.attr("r", 50)
.attr("fill", "red")
.on("mouseover", t)
.on("mouseout", function () {
hover_tooltip.close();
})
svg
.append("circle")
.datum({name: "small and blue circle"})
.attr("cx", 80)
.attr("cy", 55)
.attr("r", 10)
.attr("fill", "steelblue")
.on("mouseover", t)
.on("mouseout", function () {
hover_tooltip.close();
})
svg
.append("rect")
.datum({name: "medium and green rectangle"})
.attr("x", 210)
.attr("y", 80)
.attr("width", 90)
.attr("height", 20)
.attr("fill", "green")
.on("mouseover", t)
.on("mouseout", function () {
hover_tooltip.close();
})
</script>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment