Created
February 24, 2016 17:59
-
-
Save eMahtab/fd4cdb64c9b383ab9354 to your computer and use it in GitHub Desktop.
Uncompressed Invite Gist
This file contains hidden or 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
var width = 1300, | |
height = 645 | |
var svg = d3.select("body").append("svg") | |
.attr("width", width) | |
.attr("height", height); | |
var colorScale=d3.scale.linear().range(["green","darkgreen"]) | |
var force = d3.layout.force() | |
.gravity(0.05) | |
.charge(-1000) | |
.linkDistance(200) | |
.size([width, height]); | |
d3.json("party.json", function(error, json) { | |
if (error) throw error; | |
force | |
.nodes(json.nodes) | |
.links(json.links) | |
.start(); | |
var link = svg.selectAll(".link") | |
.data(json.links) | |
.enter().append("line") | |
.attr("class", "link") ; | |
var node = svg.selectAll(".node") | |
.data(json.nodes) | |
.enter().append("g") | |
.attr("class", "node") | |
.call(force.drag); | |
node.append("image") | |
.attr("class", "circle") | |
.attr("xlink:href", function(d){ | |
if(d.name=="Divya"){ | |
return "Divya.png"; | |
} | |
else if(d.name=="Deepthi"){ | |
return "deepthi.png" | |
} | |
else if(d.name=="Prasoon"){ | |
return "prasoon.png" | |
} | |
else if(d.name=="Sreerekha"){ | |
return "sree.png" | |
} | |
else if(d.name=="Awanish"){ | |
return "awanish.jpg" | |
} | |
else if(d.name=="Vardhan"){ | |
return "vardhan.PNG" | |
} | |
else if(d.name=="Pritish"){ | |
return "pritish.png" | |
} | |
else if(d.name=="Sharvari"){ | |
return "sharvari.png" | |
} | |
else if(d.name=="Pradeepa"){ | |
return "pradeepa.jpg" | |
} | |
else if(d.name=="Harshita"){ | |
return "harshita.png" | |
} | |
else{ | |
return ""; | |
} | |
} | |
) | |
.attr("x", "-10px") | |
.attr("y", "-5px") | |
.attr("width", "100px") | |
.attr("height", "100px"); | |
node.append("title") | |
.text(function(d) { return d.name; }); | |
force.on("tick", function() { | |
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; }) | |
.attr("stroke",function(d){ return colorScale(Math.random());}) | |
.attr("stroke-width",2); | |
node.attr("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; }); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment