Built with blockbuilder.org
Last active
May 5, 2018 04:05
-
-
Save GerardoFurtado/30cb90cc9eb4f239f59b323bbdfe4293 to your computer and use it in GitHub Desktop.
fresh block
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
license: mit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<head> | |
<meta charset="utf-8"> | |
<script src="https://d3js.org/d3.v5.min.js"></script> | |
</head> | |
<body> | |
<svg id="svg" width="960" height="500" viewBox="-480 -250 960 500"> | |
<circle r="20" stroke="steelblue" stroke-opacity="0.5" fill="none"></circle> | |
<circle r="100" stroke="brown" stroke-opacity="0.5" fill="none"></circle> | |
<circle r="240" stroke="green" stroke-opacity="0.5" fill="none"></circle> | |
</svg> | |
<script> | |
var svg = d3.select("svg"); | |
var width = svg.attr("width"); | |
var height = svg.attr("height"); | |
//alert(width+"-"+height) | |
var simulation = d3.forceSimulation(); | |
var promises = [d3.csv("nodes.csv"), d3.csv("links.csv")]; | |
Promise.all(promises).then(function(data) { | |
var links = data[1]; | |
var nodes = data[0]; | |
console.log(links) | |
simulation | |
.force("link", d3.forceLink().id(function(d) { | |
return d.node; | |
})) | |
.nodes(nodes) | |
.force("collide", d3.forceCollide().radius(10)) | |
.force("r", d3.forceRadial(function(d) { | |
// console.log(d); | |
if (d.group === "compound") { | |
return 240; | |
} else { | |
return d.group === "annotation" ? 0 : 100; | |
} | |
})); | |
// Create the link lines. | |
var link = svg.append("g") | |
.attr("class", "links") | |
.selectAll("line") | |
.data(links) | |
.enter().append("line") | |
.attr("stroke", "black") | |
.attr("stroke-width", 4) | |
.attr("class", function(d) { | |
return "link " + d.type; | |
}); | |
/*var link = svg.append("g") | |
.data(links) | |
.enter().append("line") | |
.attr("class", "links")*/ | |
// Create the node circles. | |
var node = svg.append("g") | |
.attr("class", "node") | |
.selectAll("circle") | |
.data(nodes) | |
.enter().append("circle") | |
.attr("r", 8) | |
.attr("class", function(d) { | |
return d.group; | |
}); | |
//console.log(node); | |
//add the words | |
/*node.append("text") | |
.attr("dx", 12) | |
.attr("dy", ".35em") | |
.text(function(d) { return d.node }); */ | |
simulation.force("link").links(links); | |
simulation.on("tick", ticked); | |
function ticked() { | |
node | |
.attr("cx", function(d) { | |
return d.x; | |
}) | |
.attr("cy", function(d) { | |
return d.y; | |
}); | |
link.attr("x1", function(d) { | |
return d.source.x; | |
}) | |
.attr("y1", function(d) { | |
return d.source.y; | |
}) | |
.attr("x2", function(d) { | |
return d.target.x; | |
}) | |
.attr("y2", function(d) { | |
return d.target.y; | |
}); | |
} | |
}); | |
function id(d) { | |
return d.id; | |
} | |
</script> | |
</body> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source | target | type | |
---|---|---|---|
T24871 | PF05257 | annotation | |
T27222 | PF05257 | annotation | |
T33516 | PF01529 | annotation | |
T33516 | PF05257 | annotation | |
T33516 | PF11669 | annotation | |
T33937 | PF05257 | annotation | |
T24871 | C561727 | bioactivity | |
T24871 | C337527 | bioactivity | |
T24871 | C585910 | bioactivity |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
node | group | |
---|---|---|
C236103 | compound | |
C327961 | compound | |
C337527 | compound | |
C376038 | compound | |
C543486 | compound | |
C561727 | compound | |
C585910 | compound | |
T24871 | target | |
T27222 | target | |
T33516 | target | |
T33937 | target | |
OG5_135897 | annotation | |
PF01529 | annotation | |
PF05257 | annotation | |
PF11669 | annotation |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment