this iteration centers the network on the page for more pleasant full-screen viewing. it also converts the code to ES2015 in the Airbnb style
a fork of alexmacy's Blocks Graph - w/thumbnails
README.md
This is an attempt to add thumbnail images to Mike Bostock](twitter.com/mbostock)'s version of Micah Stubbs' block. The tooltip also utilizes some code from the tooltip on Daniel Overstreet's Beijing Air Quality 3.
Hovering over a node loads that block's thumbnail in a tooltip. There are a couple issues that need fixing:
forked from mbostock's block: Blocks Graph
I added some CSS in the head for the tooltip and then defined the tooltip @ line 36:
var tooltip = d3.select("body")
.append("div")
.attr("class", "tooltip")
.style("position", "absolute")
.style("z-index", "10")
.style("visibility", "hidden");
Also made a function for fetching and displaying the image @ line 126:
function loadTooltipThumb(d) {
tooltip.select('*').remove();
var thumbnailURL = 'https://bl.ocks.org/' + (d.user ? d.user + "/" : "") + 'raw/' + d.id + '/thumbnail.png';
var top = d3.event.pageY - 150;
tooltip.style("top", top + "px")
.style("left", d3.event.pageX + 40 + "px")
.style("visibility", "visible")
.append('img')
.attr('src', thumbnailURL)
}
...which gets called in the 'mousemoved' event @ line 98
There's also something in the logic at line 93 and shrunk the searchRadius @ line 26 to hide the tooltip when not hovering over a node.
xxxxxxxxxx
<meta charset='utf-8'>
<style>
.tooltip {
width: 230px;
height: 120px;
background-color: #ffffff;
padding: 3px 12px;
font-family: sans-serif;
border: 1px solid #bbbbbb;
box-shadow: 1px 1px 4px #bbbbbb;
}
img {
max-width: 230px;
max-height: 120px;
}
#canvas-container {
width: 100%;
text-align:center;
}
canvas {
display: inline;
}
</style>
<a target='_blank' style='outline:none;'>
<div id='canvas-container'>
<canvas width='960' height='960'>Your browser does not support canvas</canvas>
</div>
</a>
<script src='https://cdnjs.cloudflare.com/ajax/libs/d3/4.10.0/d3.js'></script>
<script src='vis.js'></script>
https://cdnjs.cloudflare.com/ajax/libs/d3/4.10.0/d3.js