Skip to content

Instantly share code, notes, and snippets.

@EfratVil

EfratVil/Readme.md

Last active Jul 22, 2016
Embed
What would you like to do?
Force-Directed Network Graph

This is a Force-Directed Graph based on mbostock's example: http://bl.ocks.org/mbostock/4062045 The data in the graph was taken from http://snap.stanford.edu/data/p2p-Gnutella08.html and contains A sequence of snapshots of the Gnutella peer-to-peer file sharing network from August 2002. 

The graph is showing only the first few hundred connections. That is why some of the points are left alone, because it is a partial picture of the data. The data was divided into ~10 groups of close by points. Each group is shown with different colors.

{
"nodes":[
{"name":"1","group":0},
{"name":"2","group":0},
{"name":"3","group":0},
{"name":"4","group":0},
{"name":"5","group":0},
{"name":"6","group":0},
{"name":"7","group":0},
{"name":"8","group":0},
{"name":"9","group":0},
{"name":"10","group":0},
{"name":"11","group":0},
{"name":"12","group":0},
{"name":"21","group":0},
{"name":"22","group":0},
{"name":"23","group":0},
{"name":"31","group":0},
{"name":"32","group":0},
{"name":"33","group":0},
{"name":"34","group":0},
{"name":"35","group":0},
{"name":"36","group":0},
{"name":"37","group":0},
{"name":"38","group":0},
{"name":"39","group":0},
{"name":"40","group":0},
{"name":"41","group":7},
{"name":"42","group":7},
{"name":"43","group":7},
{"name":"44","group":7},
{"name":"45","group":7},
{"name":"46","group":7},
{"name":"47","group":7},
{"name":"50","group":7},
{"name":"51","group":7},
{"name":"52","group":7},
{"name":"60","group":7},
{"name":"61","group":7},
{"name":"62","group":7},
{"name":"63","group":7},
{"name":"64","group":7},
{"name":"65","group":7},
{"name":"66","group":7},
{"name":"67","group":7},
{"name":"68","group":7},
{"name":"69","group":7},
{"name":"70","group":11},
{"name":"71","group":11},
{"name":"72","group":11},
{"name":"73","group":11},
{"name":"74","group":11},
{"name":"75","group":11},
{"name":"76","group":11},
{"name":"77","group":11},
{"name":"78","group":11},
{"name":"79","group":11},
{"name":"81","group":11},
{"name":"82","group":11},
{"name":"83","group":11},
{"name":"84","group":11},
{"name":"85","group":11},
{"name":"86","group":11},
{"name":"87","group":11},
{"name":"88","group":11},
{"name":"89","group":11},
{"name":"90","group":11},
{"name":"91","group":11},
{"name":"101","group":22},
{"name":"102","group":22},
{"name":"103","group":22},
{"name":"104","group":22},
{"name":"105","group":22},
{"name":"106","group":22},
{"name":"107","group":22},
{"name":"111","group":22},
{"name":"121","group":22},
{"name":"122","group":22},
{"name":"123","group":22},
{"name":"124","group":22},
{"name":"125","group":22},
{"name":"126","group":22},
{"name":"127","group":22},
{"name":"128","group":22},
{"name":"129","group":22},
{"name":"130","group":22},
{"name":"132","group":22},
{"name":"133","group":22},
{"name":"142","group":22},
{"name":"145","group":22},
{"name":"148","group":39},
{"name":"149","group":39},
{"name":"150","group":39},
{"name":"151","group":39},
{"name":"152","group":39},
{"name":"153","group":39},
{"name":"154","group":39},
{"name":"155","group":39},
{"name":"156","group":39},
{"name":"157","group":39},
{"name":"158","group":39},
{"name":"159","group":39},
{"name":"160","group":39},
{"name":"168","group":39},
{"name":"177","group":39},
{"name":"178","group":39},
{"name":"179","group":39},
{"name":"180","group":39},
{"name":"181","group":39},
{"name":"182","group":39},
{"name":"183","group":39},
{"name":"184","group":39},
{"name":"185","group":39},
{"name":"186","group":39},
{"name":"187","group":39},
{"name":"188","group":39},
{"name":"189","group":39},
{"name":"190","group":39},
{"name":"191","group":39},
{"name":"192","group":39},
{"name":"193","group":39},
{"name":"194","group":39},
{"name":"195","group":39},
{"name":"196","group":39},
{"name":"197","group":39},
{"name":"206","group":39},
{"name":"226","group":39},
{"name":"227","group":68},
{"name":"228","group":68},
{"name":"229","group":68},
{"name":"230","group":68},
{"name":"231","group":68},
{"name":"232","group":68},
{"name":"233","group":68},
{"name":"234","group":68},
{"name":"235","group":68},
{"name":"236","group":68},
{"name":"237","group":68},
{"name":"245","group":68},
{"name":"246","group":68},
{"name":"247","group":68},
{"name":"248","group":68},
{"name":"249","group":68},
{"name":"250","group":68},
{"name":"251","group":68},
{"name":"252","group":68},
{"name":"253","group":68},
{"name":"254","group":68},
{"name":"264","group":68},
{"name":"292","group":68},
{"name":"293","group":68},
{"name":"294","group":68},
{"name":"302","group":68},
{"name":"312","group":68},
{"name":"313","group":68},
{"name":"314","group":68},
{"name":"315","group":68},
{"name":"316","group":68},
{"name":"317","group":68},
{"name":"318","group":68},
{"name":"319","group":68},
{"name":"320","group":68},
{"name":"321","group":68},
{"name":"322","group":68},
{"name":"323","group":68},
{"name":"324","group":68},
{"name":"332","group":68},
{"name":"333","group":68},
{"name":"334","group":68},
{"name":"335","group":68},
{"name":"342","group":68},
{"name":"352","group":68},
{"name":"353","group":68},
{"name":"354","group":68},
{"name":"362","group":68},
{"name":"363","group":68},
{"name":"364","group":68},
{"name":"365","group":68},
{"name":"366","group":68},
{"name":"367","group":68},
{"name":"368","group":68},
{"name":"369","group":68},
{"name":"370","group":68},
{"name":"371","group":68},
{"name":"372","group":68},
{"name":"373","group":68},
{"name":"390","group":98},
{"name":"391","group":98},
{"name":"392","group":98},
{"name":"393","group":98},
{"name":"394","group":98},
{"name":"395","group":98},
{"name":"396","group":98},
{"name":"397","group":98},
{"name":"400","group":98},
{"name":"401","group":98},
{"name":"402","group":98},
{"name":"403","group":98},
{"name":"404","group":98},
{"name":"405","group":98},
{"name":"406","group":98},
{"name":"407","group":98},
{"name":"408","group":98},
{"name":"409","group":98},
{"name":"410","group":98},
{"name":"411","group":98},
{"name":"420","group":98},
{"name":"425","group":98},
{"name":"426","group":98},
{"name":"427","group":98},
{"name":"428","group":98},
{"name":"429","group":98},
{"name":"430","group":98},
{"name":"431","group":98},
{"name":"432","group":98},
{"name":"433","group":98},
{"name":"434","group":98},
{"name":"436","group":109},
{"name":"437","group":109},
{"name":"438","group":109},
{"name":"439","group":109},
{"name":"440","group":109},
{"name":"441","group":109},
{"name":"442","group":109},
{"name":"443","group":109},
{"name":"444","group":109},
{"name":"452","group":109},
{"name":"453","group":109},
{"name":"462","group":109},
{"name":"463","group":109},
{"name":"472","group":109},
{"name":"473","group":109},
{"name":"474","group":109},
{"name":"475","group":109},
{"name":"476","group":109},
{"name":"477","group":109},
{"name":"478","group":109},
{"name":"479","group":109},
{"name":"480","group":109},
{"name":"481","group":109},
{"name":"511","group":109},
{"name":"512","group":109},
{"name":"513","group":109},
{"name":"514","group":109},
{"name":"515","group":109},
{"name":"516","group":109},
{"name":"517","group":109},
{"name":"518","group":109},
{"name":"521","group":109},
{"name":"531","group":123},
{"name":"532","group":123},
{"name":"533","group":123},
{"name":"534","group":123},
{"name":"535","group":123},
{"name":"536","group":123},
{"name":"537","group":123},
{"name":"538","group":123},
{"name":"539","group":123},
{"name":"540","group":123},
{"name":"541","group":123},
{"name":"542","group":123},
{"name":"551","group":123},
{"name":"552","group":123},
{"name":"553","group":123},
{"name":"554","group":123},
{"name":"555","group":123},
{"name":"556","group":123},
{"name":"557","group":123},
{"name":"558","group":123},
{"name":"559","group":123},
{"name":"560","group":123}
],
"links":[
{"source":0,"target":1,"value":1},
{"source":0,"target":2,"value":1},
{"source":0,"target":3,"value":1},
{"source":0,"target":4,"value":1},
{"source":0,"target":5,"value":1},
{"source":0,"target":6,"value":1},
{"source":0,"target":7,"value":1},
{"source":0,"target":8,"value":1},
{"source":0,"target":9,"value":1},
{"source":0,"target":10,"value":1},
{"source":4,"target":144,"value":1},
{"source":5,"target":121,"value":1},
{"source":5,"target":127,"value":1},
{"source":5,"target":128,"value":1},
{"source":5,"target":179,"value":1},
{"source":7,"target":145,"value":1},
{"source":7,"target":176,"value":1},
{"source":7,"target":177,"value":1},
{"source":9,"target":124,"value":1},
{"source":9,"target":147,"value":1},
{"source":9,"target":177,"value":1},
{"source":11,"target":12,"value":1},
{"source":11,"target":13,"value":1},
{"source":11,"target":14,"value":1},
{"source":11,"target":15,"value":1},
{"source":11,"target":16,"value":1},
{"source":11,"target":17,"value":1},
{"source":11,"target":18,"value":1},
{"source":11,"target":19,"value":1},
{"source":11,"target":20,"value":1},
{"source":11,"target":21,"value":1},
{"source":15,"target":3,"value":1},
{"source":15,"target":123,"value":1},
{"source":15,"target":129,"value":1},
{"source":15,"target":143,"value":1},
{"source":20,"target":121,"value":1},
{"source":20,"target":147,"value":1},
{"source":21,"target":92,"value":1},
{"source":22,"target":23,"value":1},
{"source":22,"target":24,"value":1},
{"source":22,"target":25,"value":1},
{"source":22,"target":26,"value":1},
{"source":22,"target":27,"value":1},
{"source":22,"target":28,"value":1},
{"source":22,"target":29,"value":1},
{"source":22,"target":30,"value":1},
{"source":22,"target":31,"value":1},
{"source":22,"target":32,"value":1},
{"source":30,"target":3,"value":1},
{"source":30,"target":5,"value":1},
{"source":30,"target":8,"value":1},
{"source":30,"target":121,"value":1},
{"source":30,"target":124,"value":1},
{"source":30,"target":126,"value":1},
{"source":30,"target":145,"value":1},
{"source":30,"target":174,"value":1},
{"source":31,"target":124,"value":1},
{"source":33,"target":34,"value":1},
{"source":33,"target":35,"value":1},
{"source":33,"target":36,"value":1},
{"source":33,"target":37,"value":1},
{"source":33,"target":38,"value":1},
{"source":33,"target":39,"value":1},
{"source":33,"target":40,"value":1},
{"source":33,"target":41,"value":1},
{"source":33,"target":42,"value":1},
{"source":33,"target":43,"value":1},
{"source":36,"target":3,"value":1},
{"source":36,"target":123,"value":1},
{"source":36,"target":126,"value":1},
{"source":36,"target":145,"value":1},
{"source":36,"target":174,"value":1},
{"source":36,"target":179,"value":1},
{"source":44,"target":45,"value":1},
{"source":44,"target":46,"value":1},
{"source":44,"target":47,"value":1},
{"source":44,"target":48,"value":1},
{"source":44,"target":49,"value":1},
{"source":44,"target":50,"value":1},
{"source":44,"target":51,"value":1},
{"source":44,"target":52,"value":1},
{"source":44,"target":53,"value":1},
{"source":44,"target":54,"value":1},
{"source":49,"target":101,"value":1},
{"source":55,"target":56,"value":1},
{"source":55,"target":57,"value":1},
{"source":55,"target":58,"value":1},
{"source":55,"target":59,"value":1},
{"source":55,"target":60,"value":1},
{"source":55,"target":61,"value":1},
{"source":55,"target":62,"value":1},
{"source":55,"target":63,"value":1},
{"source":55,"target":64,"value":1},
{"source":55,"target":65,"value":1},
{"source":64,"target":91,"value":1},
{"source":64,"target":102,"value":1},
{"source":64,"target":106,"value":1},
{"source":65,"target":86,"value":1},
{"source":66,"target":16,"value":1},
{"source":66,"target":67,"value":1},
{"source":66,"target":68,"value":1},
{"source":66,"target":69,"value":1},
{"source":66,"target":70,"value":1},
{"source":66,"target":71,"value":1},
{"source":66,"target":72,"value":1},
{"source":66,"target":73,"value":1},
{"source":66,"target":74,"value":1},
{"source":66,"target":75,"value":1},
{"source":68,"target":152,"value":1},
{"source":75,"target":190,"value":1},
{"source":76,"target":77,"value":1},
{"source":76,"target":78,"value":1},
{"source":76,"target":79,"value":1},
{"source":76,"target":80,"value":1},
{"source":76,"target":81,"value":1},
{"source":76,"target":82,"value":1},
{"source":76,"target":83,"value":1},
{"source":76,"target":84,"value":1},
{"source":76,"target":85,"value":1},
{"source":76,"target":86,"value":1},
{"source":83,"target":7,"value":1},
{"source":83,"target":8,"value":1},
{"source":83,"target":9,"value":1},
{"source":83,"target":148,"value":1},
{"source":87,"target":88,"value":1},
{"source":87,"target":89,"value":1},
{"source":87,"target":90,"value":1},
{"source":87,"target":91,"value":1},
{"source":87,"target":92,"value":1},
{"source":87,"target":93,"value":1},
{"source":87,"target":94,"value":1},
{"source":87,"target":95,"value":1},
{"source":87,"target":96,"value":1},
{"source":87,"target":97,"value":1},
{"source":98,"target":99,"value":1},
{"source":98,"target":100,"value":1},
{"source":98,"target":101,"value":1},
{"source":98,"target":102,"value":1},
{"source":98,"target":103,"value":1},
{"source":98,"target":104,"value":1},
{"source":98,"target":105,"value":1},
{"source":98,"target":106,"value":1},
{"source":98,"target":107,"value":1},
{"source":98,"target":108,"value":1},
{"source":101,"target":143,"value":1},
{"source":101,"target":147,"value":1},
{"source":109,"target":110,"value":1},
{"source":109,"target":111,"value":1},
{"source":109,"target":112,"value":1},
{"source":109,"target":113,"value":1},
{"source":109,"target":114,"value":1},
{"source":109,"target":115,"value":1},
{"source":109,"target":116,"value":1},
{"source":109,"target":117,"value":1},
{"source":109,"target":118,"value":1},
{"source":109,"target":119,"value":1},
{"source":113,"target":17,"value":1},
{"source":113,"target":143,"value":1},
{"source":113,"target":144,"value":1},
{"source":113,"target":145,"value":1},
{"source":113,"target":179,"value":1},
{"source":120,"target":3,"value":1},
{"source":120,"target":121,"value":1},
{"source":120,"target":122,"value":1},
{"source":120,"target":123,"value":1},
{"source":120,"target":124,"value":1},
{"source":120,"target":125,"value":1},
{"source":120,"target":126,"value":1},
{"source":120,"target":127,"value":1},
{"source":120,"target":128,"value":1},
{"source":120,"target":129,"value":1},
{"source":123,"target":3,"value":1},
{"source":123,"target":7,"value":1},
{"source":123,"target":143,"value":1},
{"source":123,"target":145,"value":1},
{"source":123,"target":146,"value":1},
{"source":123,"target":147,"value":1},
{"source":124,"target":122,"value":1},
{"source":124,"target":123,"value":1},
{"source":124,"target":145,"value":1},
{"source":124,"target":147,"value":1},
{"source":124,"target":176,"value":1},
{"source":125,"target":132,"value":1},
{"source":126,"target":127,"value":1},
{"source":127,"target":9,"value":1},
{"source":127,"target":144,"value":1},
{"source":127,"target":175,"value":1},
{"source":127,"target":177,"value":1},
{"source":129,"target":133,"value":1},
{"source":130,"target":131,"value":1},
{"source":130,"target":132,"value":1},
{"source":130,"target":133,"value":1},
{"source":130,"target":134,"value":1},
{"source":130,"target":135,"value":1},
{"source":130,"target":136,"value":1},
{"source":130,"target":137,"value":1},
{"source":130,"target":138,"value":1},
{"source":130,"target":139,"value":1},
{"source":130,"target":140,"value":1},
{"source":131,"target":93,"value":1},
{"source":132,"target":5,"value":1},
{"source":132,"target":9,"value":1},
{"source":132,"target":147,"value":1},
{"source":133,"target":110,"value":1},
{"source":135,"target":34,"value":1},
{"source":135,"target":132,"value":1},
{"source":136,"target":57,"value":1},
{"source":138,"target":23,"value":1},
{"source":141,"target":7,"value":1},
{"source":141,"target":142,"value":1},
{"source":141,"target":143,"value":1},
{"source":141,"target":144,"value":1},
{"source":141,"target":145,"value":1},
{"source":141,"target":146,"value":1},
{"source":141,"target":147,"value":1},
{"source":141,"target":148,"value":1},
{"source":141,"target":149,"value":1},
{"source":141,"target":150,"value":1},
{"source":143,"target":122,"value":1},
{"source":143,"target":124,"value":1},
{"source":143,"target":128,"value":1},
{"source":143,"target":146,"value":1},
{"source":144,"target":8,"value":1},
{"source":144,"target":121,"value":1},
{"source":144,"target":122,"value":1},
{"source":144,"target":125,"value":1},
{"source":144,"target":146,"value":1},
{"source":145,"target":149,"value":1},
{"source":146,"target":7,"value":1},
{"source":147,"target":8,"value":1},
{"source":147,"target":128,"value":1},
{"source":147,"target":176,"value":1},
{"source":147,"target":177,"value":1},
{"source":148,"target":121,"value":1},
{"source":148,"target":122,"value":1},
{"source":148,"target":123,"value":1},
{"source":148,"target":124,"value":1},
{"source":148,"target":176,"value":1},
{"source":149,"target":5,"value":1},
{"source":149,"target":10,"value":1},
{"source":149,"target":128,"value":1},
{"source":149,"target":148,"value":1},
{"source":151,"target":152,"value":1},
{"source":151,"target":153,"value":1},
{"source":151,"target":154,"value":1},
{"source":151,"target":155,"value":1},
{"source":151,"target":156,"value":1},
{"source":151,"target":157,"value":1},
{"source":151,"target":158,"value":1},
{"source":151,"target":159,"value":1},
{"source":151,"target":160,"value":1},
{"source":151,"target":161,"value":1},
{"source":155,"target":5,"value":1},
{"source":155,"target":121,"value":1},
{"source":155,"target":126,"value":1},
{"source":155,"target":128,"value":1},
{"source":155,"target":129,"value":1},
{"source":155,"target":175,"value":1},
{"source":160,"target":13,"value":1},
{"source":162,"target":163,"value":1},
{"source":162,"target":164,"value":1},
{"source":162,"target":165,"value":1},
{"source":162,"target":166,"value":1},
{"source":162,"target":167,"value":1},
{"source":162,"target":168,"value":1},
{"source":162,"target":169,"value":1},
{"source":162,"target":170,"value":1},
{"source":162,"target":171,"value":1},
{"source":162,"target":172,"value":1},
{"source":165,"target":102,"value":1},
{"source":165,"target":108,"value":1},
{"source":167,"target":8,"value":1},
{"source":167,"target":17,"value":1},
{"source":167,"target":121,"value":1},
{"source":167,"target":129,"value":1},
{"source":167,"target":175,"value":1},
{"source":172,"target":127,"value":1},
{"source":172,"target":128,"value":1},
{"source":172,"target":129,"value":1},
{"source":172,"target":145,"value":1},
{"source":172,"target":174,"value":1},
{"source":172,"target":177,"value":1},
{"source":173,"target":124,"value":1},
{"source":173,"target":128,"value":1},
{"source":173,"target":144,"value":1},
{"source":173,"target":174,"value":1},
{"source":173,"target":175,"value":1},
{"source":173,"target":176,"value":1},
{"source":173,"target":177,"value":1},
{"source":173,"target":178,"value":1},
{"source":173,"target":179,"value":1},
{"source":173,"target":180,"value":1},
{"source":174,"target":3,"value":1},
{"source":174,"target":5,"value":1},
{"source":174,"target":7,"value":1},
{"source":174,"target":122,"value":1},
{"source":174,"target":126,"value":1},
{"source":174,"target":142,"value":1},
{"source":174,"target":145,"value":1},
{"source":176,"target":5,"value":1},
{"source":177,"target":143,"value":1},
{"source":177,"target":145,"value":1},
{"source":177,"target":149,"value":1},
{"source":179,"target":4,"value":1},
{"source":179,"target":9,"value":1},
{"source":179,"target":17,"value":1},
{"source":179,"target":31,"value":1},
{"source":179,"target":123,"value":1},
{"source":179,"target":125,"value":1},
{"source":180,"target":3,"value":1},
{"source":181,"target":182,"value":1},
{"source":181,"target":183,"value":1},
{"source":181,"target":184,"value":1},
{"source":181,"target":185,"value":1},
{"source":181,"target":186,"value":1},
{"source":181,"target":187,"value":1},
{"source":181,"target":188,"value":1},
{"source":181,"target":189,"value":1},
{"source":181,"target":190,"value":1},
{"source":181,"target":191,"value":1},
{"source":191,"target":77,"value":1},
{"source":192,"target":38,"value":1},
{"source":192,"target":193,"value":1},
{"source":192,"target":194,"value":1},
{"source":192,"target":195,"value":1},
{"source":192,"target":196,"value":1},
{"source":194,"target":86,"value":1},
{"source":194,"target":139,"value":1},
{"source":195,"target":4,"value":1},
{"source":195,"target":124,"value":1},
{"source":195,"target":143,"value":1},
{"source":195,"target":176,"value":1},
{"source":197,"target":198,"value":1},
{"source":197,"target":199,"value":1},
{"source":197,"target":200,"value":1}
]
}
<!DOCTYPE html>
<meta charset="utf-8">
<style>
.node {
stroke: #fff;
stroke-width: 1.5px;
}
.link {
stroke: #999;
stroke-opacity: .6;
}
</style>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script>
<script>
var width = 960,
height = 600;
var color = d3.scale.category20();
var force = d3.layout.force()
.charge(-30)
.linkDistance(10)
.size([width, height]);
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
d3.json("data.json", function(error, graph) {
if (error) throw error;
force
.nodes(graph.nodes)
.links(graph.links)
.start();
var link = svg.selectAll(".link")
.data(graph.links)
.enter().append("line")
.attr("class", "link")
.style("stroke-width", function(d) { return Math.sqrt(d.value); });
var node = svg.selectAll(".node")
.data(graph.nodes)
.enter().append("circle")
.attr("class", "node")
.attr("r", 5)
.style("fill", function(d) { return color(d.group); })
.call(force.drag);
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; });
node.attr("cx", function(d) { return d.x; })
.attr("cy", function(d) { return d.y; });
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.