Skip to content

Instantly share code, notes, and snippets.

@GitNoise
Last active January 12, 2016 20:52
Show Gist options
  • Save GitNoise/637c5f418d49348cb30f to your computer and use it in GitHub Desktop.
Save GitNoise/637c5f418d49348cb30f to your computer and use it in GitHub Desktop.
Workers of the world unite!
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script>
<script src="https://raw.githubusercontent.com/Caged/d3-tip/master/index.js"></script>
<link rel="stylesheet" href="//rawgithub.com/Caged/d3-tip/master/examples/example-styles.css">
<style>
body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; }
svg { width:100%; height: 100% }
</style>
</head>
<body>
<script>
// Feel free to change or delete any of the code you see!
var svg = d3.select("body").append("svg")
var data = ["Workers", "of", "the", "world", "unite!"]
tip = d3.tip().attr('class', 'd3-tip').html(function(d) { return d; });
/* Invoke the tip in the context of your visualization */
svg.call(tip);
var orgOpacity = 0.1;
svg.selectAll(".worker").data(data).enter()
.append("svg:image")
.classed("worker", true)
.attr("xlink:href", "http://www.clker.com/cliparts/5/e/b/1/12620180711782779235workerwithraisedarm.svg")
.attr("width", 100)
.attr("height", 100)
.attr("x", function(d,i) { return 100 + 100 * i; })
.attr("y",100)
.style("opacity", orgOpacity)
.on('mouseover', function(d) {
d3.select(this)
.transition().duration(800)
.style("opacity","1");
tip.show(d); })
.on('mouseout', function(d) {
d3.select(this)
.transition().delay(300).duration(500)
.style("opacity", orgOpacity)
tip.hide(d); });
</script>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment