index.html
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.6/d3.min.js" charset="utf-8"></script>
<title></title>
</head>
<body>
<style type="text/css">
.title{
font: 20px Verdana; font-weight: bold;
}
.text1{
font: 10px Verdana; font-weight: normal; color: blue;
}
.node {
//stroke: #fff;
//stroke-width: 1.5px;
stroke: #333;
stroke-width: 1.5px;
}
.link {
stroke: black;
stroke-width: 1px;
stroke-opacity: 1;
fill:none;
}
text {
font: 10px sans-serif;
pointer-events: none;
text-shadow: 0 1px 0 #fff, 1px 0 0 #fff, 0 -1px 0 #fff, -1px 0 0 #fff;
}
div.tooltip {
position: absolute; text-align: center; width: 120px;
height: 100px; padding: 2px; font: 12px sans-serif;
background: lightsteelblue; border: 0px; border-radius: 8px;
pointer-events: none;
}
</style>
<p class="title">rRNATagger pipeline - for 16S/18S/ITS amplicons</p>
<p class="text1">By Julien Tremblay - jtremblay514@gmail.com</p>
<p class="text1">Version 0.1</p>
<script type="text/javascript">
var w = 1700;
var h = 800;
var radius = 6;
var dataset;
var nodes = [];
var links = [];
var svg = d3.select("body")
.append("svg")
.attr("width", w)
.attr("height", h)
var div = d3.select("body").append("div")
.attr("class", "tooltip")
.style("opacity", 0);
d3.json("pipeline.json", function(error, json) {
if (error) return console.warn(error);
dataset = json;
console.log(json)
update();
});
function update() {
var force = d3.layout.force()
.nodes(dataset.nodes)
.links(dataset.links)
.size([w, h])
.linkDistance(30)
.charge(-300)
.start();
var color = d3.scale.category20();
svg.append("defs").selectAll("marker")
.data(["next"])
.enter().append("marker")
.attr("id", function(d) { return d; })
.attr("viewBox", "0 -5 10 10")
.attr("refX", 15)
.attr("refY", -1.5)
.attr("markerWidth", 6)
.attr("markerHeight", 6)
.attr("orient", "auto")
.append("path")
.attr("d", "M0, -5L10,0L0,5");
edges = svg.selectAll(".link")
.data(dataset.links)
.enter()
.append("path")
.attr("marker-end", function(d) { return "url(#next)"; })
.attr("class", "link");
nodes = svg.selectAll(".node")
.data(dataset.nodes)
.enter()
.append("circle")
.attr('r', function(d) { if(d.value == 1){ return 5; }else{ return d.value; } })
.attr("class", "node")
.attr("group_name", function(d) { return d.group; })
.attr("selected", function(d){ return "false"; })
.style("fill", function(d) { return color(d.group); })
.on("click", click)
.call(force.drag);
nodes.on("mouseover", function(d) {
console.log(d);
div.transition()
.duration(200)
.style("opacity", .9)
div.html("<br>" + d.desc + "<br>")
.style("left", (d3.event.pageX) + "px")
.style("top", (d3.event.pageY - 28) + "px");
})
.on("mouseout", function(d) {
div.transition()
.duration(500)
.style("opacity", 0);
});
var text = svg.selectAll("text")
.data(force.nodes())
.enter().append("text")
.attr("x", 8)
.attr("y", ".31em")
.text(function (d) {
return d.name;
});
force.on("tick", function () {
edges.attr("d", linkArc);
nodes.attr("cx", function(d) { return d.x = Math.max(radius, Math.min(w - radius, d.x)); })
.attr("cy", function(d) { return d.y = Math.max(radius, Math.min(h - radius, d.y)); });
text.attr("transform", transform);
});
function click(d) {
if (!d3.event.defaultPrevented) {
var curr_selection = d3.selectAll("circle[group_name=" + d.group + "]")
var curr_group = curr_selection.transition()
.duration(700)
.ease("bounce")
.attr({
r: function(d) {
currRadius = d3.select(this).attr("r");
if(d3.select(this).attr('selected') == "false"){
console.log("was selected: " + d3.select(this).attr('selected'))
console.log("currRadius: " + currRadius)
return (currRadius * 2);
}else{
console.log("was not selected: " + d3.select(this).attr('selected'))
console.log("currRadius: " + currRadius)
return (currRadius / 2);
}
},
selected: function(d){
if(d3.select(this).attr('selected') == "false"){
return "true";
}else{
return "false";
}
}
})
console.log(curr_group)
console.log(new_selection)
}
}
function linkArc(d) {
var dx = d.target.x - d.source.x;
var dy = d.target.y - d.source.y;
var 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;
}
function transform(d) {
return "translate(" + d.x + "," + d.y + ")";
}
}
</script>
</body>
</html>