This is a visualization of the network formed by the sites selected for a portfolio of clinical trials. The graph serves to highlight the interconnectedness of the sites involved in clinical research.
A single click on any node will highlight it and its label. A double-click will return it to its original format. Names of the trials and the sites are anonymized.
xxxxxxxxxx
<html lang="en">
<head>
<meta charset="utf-8">
<style>
path.link {
fill: none;
stroke: #666;
stroke-width: 1.5px;
}
circle {
fill: #ccc;
stroke: #fff;
stroke-width: 1.5px;
}
text {
fill: #000;
visibility: hidden;
font: 10px sans-serif;
pointer-events: none;
}
section {
margin-left: auto;
margin-right: auto;
}
</style>
</head>
<body>
<script src="https://d3js.org/d3.v3.min.js"></script>
<script>
d3.csv("EdgeList.csv", function (error, links) {
var nodes = {};
// Compute the distinct nodes from the Edge List
links.forEach(function (link) {
link.source = nodes[link.source] ||
(nodes[link.source] = {
name: link.source
});
link.target = nodes[link.target] ||
(nodes[link.target] = {
name: link.target
});
link.value = +link.value;
});
var width = 960,
height = 570,
transitionDuration = 750;
var force = d3.layout.force()
.nodes(d3.values(nodes))
.links(links)
.size([width, height])
.linkDistance(45)
.charge(-300)
.gravity(0.9)
.on("tick", tick)
.start();
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
// build the arrow.
svg.append("svg:defs").selectAll("marker")
.data(["end"]) // Different link/path types can be defined here
.enter().append("svg:marker") // This section adds in the arrows
.attr("id", String)
.attr("viewBox", "0 -5 10 10")
.attr("refX", 15)
.attr("refY", -1.5)
.attr("markerWidth", 6)
.attr("markerHeight", 6)
.attr("orient", "auto")
.append("svg:path")
.attr("d", "M0,-5L10,0L0,5");
// add the links and the arrows
var path = svg.append("svg:g").selectAll("path")
.data(force.links())
.enter().append("svg:path")
.attr("class", "link")
.attr("marker-end", "url(#end)");
// define the nodes
var node = svg.selectAll(".node")
.data(force.nodes())
.enter().append("g")
.attr("class", "node")
.call(force.drag)
.on("click", click)
.on("dblclick", dblclick);
// add the nodes
node.append("circle")
.attr("r", 5);
// add the text
node.append("text")
.attr("x", 12)
.attr("dy", ".35em")
.text(function (d) {
return d.name;
});
// add the curvy lines
function tick() {
path.attr("d", function (d) {
var dx = d.target.x - d.source.x,
dy = d.target.y - d.source.y,
dr = Math.sqrt(dx * dx + dy * dy);
return "M" +
d.source.x + "," +
d.source.y + "A" +
dr + "," + dr + " 0 0,1 " +
d.target.x + "," +
d.target.y;
});
node.attr("transform", function (d) {
return "translate(" + d.x + "," + d.y + ")";
});
}
function click() {
d3.select(this).select("text").transition()
.duration(transitionDuration)
.attr("x", 22)
.style("fill", "steelblue")
.style("stroke", "lightsteelblue")
.style("visibility", "visible")
.style("stroke-width", ".5px")
.style("font", "20px sans-serif");
d3.select(this).select("circle").transition()
.duration(transitionDuration)
.attr("r", 16)
.style("fill", "lightsteelblue");
}
function dblclick() {
d3.select(this).select("circle").transition()
.duration(transitionDuration)
.attr("r", 6)
.style("fill", "#ccc");
d3.select(this).select("text").transition()
.duration(transitionDuration)
.attr("x", 12)
.style("stroke", "none")
.style("fill", "black")
.style("stroke", "none")
.style("visibility", "hidden")
.style("font", "10px sans-serif");
}
});
</script>
</body>
</html>
https://d3js.org/d3.v3.min.js