Skip to content

Instantly share code, notes, and snippets.

@aht
Forked from mbostock/.block
Last active August 29, 2015 14:05
Show Gist options
  • Save aht/496aa2e3537e41062537 to your computer and use it in GitHub Desktop.
Save aht/496aa2e3537e41062537 to your computer and use it in GitHub Desktop.

Adatao stuff.

{"nodes":[{"name":10120,"group":1},{"name":106088,"group":1},{"name":10705,"group":1},{"name":118,"group":1},{"name":11801,"group":1},{"name":1265,"group":1},{"name":12770,"group":1},{"name":13336,"group":1},{"name":136720,"group":1},{"name":137933,"group":1},{"name":142457,"group":1},{"name":14313,"group":1},{"name":143483,"group":1},{"name":146890,"group":1},{"name":14960,"group":1},{"name":151566,"group":1},{"name":153655,"group":1},{"name":15785,"group":1},{"name":16,"group":1},{"name":170120,"group":1},{"name":171022,"group":1},{"name":18149,"group":1},{"name":18212,"group":1},{"name":187,"group":1},{"name":190199,"group":1},{"name":191,"group":1},{"name":19209,"group":1},{"name":19560,"group":1},{"name":19810,"group":1},{"name":199767,"group":1},{"name":200011,"group":1},{"name":20377,"group":1},{"name":206497,"group":1},{"name":20782,"group":1},{"name":219799,"group":1},{"name":221716,"group":1},{"name":22760,"group":1},{"name":22874,"group":1},{"name":23,"group":1},{"name":24588,"group":1},{"name":252170,"group":1},{"name":26971,"group":1},{"name":273417,"group":1},{"name":275381,"group":1},{"name":284655,"group":1},{"name":28495,"group":1},{"name":29264,"group":1},{"name":29430,"group":1},{"name":301680,"group":1},{"name":30282,"group":1},{"name":311182,"group":1},{"name":311542,"group":1},{"name":31797,"group":1},{"name":32125,"group":1},{"name":322356,"group":1},{"name":32380,"group":1},{"name":33,"group":1},{"name":3407,"group":1},{"name":34757,"group":1},{"name":35241,"group":1},{"name":373422,"group":1},{"name":38,"group":1},{"name":381600,"group":1},{"name":38279,"group":1},{"name":38899,"group":1},{"name":392929,"group":1},{"name":39418,"group":1},{"name":416813,"group":1},{"name":416878,"group":1},{"name":425125,"group":1},{"name":43786,"group":1},{"name":4435,"group":1},{"name":445233,"group":1},{"name":452635,"group":1},{"name":4625,"group":1},{"name":464721,"group":1},{"name":46744,"group":1},{"name":47298,"group":1},{"name":47694,"group":1},{"name":481277,"group":1},{"name":48357,"group":1},{"name":48519,"group":1},{"name":498,"group":1},{"name":515294,"group":1},{"name":515572,"group":1},{"name":51840,"group":1},{"name":522308,"group":1},{"name":523,"group":1},{"name":52965,"group":1},{"name":52972,"group":1},{"name":535228,"group":1},{"name":53575,"group":1},{"name":536416,"group":1},{"name":540667,"group":1},{"name":543525,"group":1},{"name":544400,"group":1},{"name":57414,"group":1},{"name":574875,"group":1},{"name":580320,"group":1},{"name":59,"group":1},{"name":60037,"group":1},{"name":607830,"group":1},{"name":615631,"group":1},{"name":619513,"group":1},{"name":620834,"group":1},{"name":623514,"group":1},{"name":633407,"group":1},{"name":634652,"group":1},{"name":640057,"group":1},{"name":650,"group":1},{"name":65241,"group":1},{"name":657032,"group":1},{"name":659442,"group":1},{"name":660717,"group":1},{"name":66791,"group":1},{"name":672571,"group":1},{"name":675460,"group":1},{"name":676155,"group":1},{"name":6831,"group":1},{"name":694620,"group":1},{"name":702463,"group":1},{"name":70381,"group":1},{"name":72437,"group":1},{"name":73709,"group":1},{"name":752541,"group":1},{"name":7669,"group":1},{"name":768433,"group":1},{"name":77580,"group":1},{"name":78052,"group":1},{"name":781267,"group":1},{"name":782661,"group":1},{"name":782907,"group":1},{"name":80446,"group":1},{"name":805177,"group":1},{"name":81188,"group":1},{"name":831771,"group":1},{"name":83577,"group":1},{"name":837404,"group":1},{"name":837529,"group":1},{"name":83804,"group":1},{"name":841060,"group":1},{"name":844962,"group":1},{"name":847713,"group":1},{"name":86569,"group":1},{"name":866428,"group":1},{"name":8668,"group":1},{"name":902579,"group":1},{"name":911294,"group":1},{"name":97,"group":1},{"name":9729,"group":1},{"name":9842,"group":1}],"links":[{"source":18,"target":18,"value":0.94},{"source":18,"target":3,"value":1.45546226},{"source":18,"target":51,"value":1.07},{"source":18,"target":18,"value":0.01},{"source":18,"target":84,"value":3},{"source":18,"target":69,"value":0.64},{"source":18,"target":16,"value":18},{"source":18,"target":20,"value":0.01},{"source":18,"target":10,"value":1},{"source":18,"target":18,"value":0.04},{"source":18,"target":18,"value":0.01313605},{"source":18,"target":97,"value":37},{"source":18,"target":125,"value":10},{"source":18,"target":18,"value":0.01},{"source":18,"target":140,"value":4},{"source":18,"target":115,"value":1.5},{"source":18,"target":135,"value":1},{"source":18,"target":149,"value":15},{"source":18,"target":18,"value":49},{"source":18,"target":61,"value":13},{"source":18,"target":91,"value":0.01},{"source":18,"target":2,"value":18},{"source":18,"target":82,"value":1},{"source":18,"target":72,"value":20},{"source":18,"target":114,"value":10},{"source":18,"target":88,"value":1},{"source":18,"target":101,"value":6},{"source":18,"target":18,"value":0.01065834},{"source":18,"target":111,"value":3},{"source":18,"target":117,"value":0.01},{"source":18,"target":99,"value":1},{"source":18,"target":147,"value":20},{"source":18,"target":37,"value":40.03},{"source":18,"target":18,"value":0.01037047},{"source":18,"target":80,"value":5},{"source":18,"target":138,"value":10},{"source":18,"target":22,"value":5},{"source":18,"target":55,"value":3},{"source":18,"target":87,"value":11.25},{"source":18,"target":142,"value":0.01},{"source":18,"target":18,"value":0.01},{"source":18,"target":92,"value":4},{"source":18,"target":44,"value":2},{"source":18,"target":18,"value":0.02054066},{"source":18,"target":54,"value":6},{"source":18,"target":134,"value":20},{"source":18,"target":5,"value":1},{"source":18,"target":137,"value":0.23},{"source":18,"target":18,"value":0.01},{"source":18,"target":45,"value":5.43},{"source":18,"target":60,"value":3.68},{"source":18,"target":18,"value":0.01},{"source":18,"target":4,"value":2.3},{"source":18,"target":104,"value":0.01},{"source":18,"target":18,"value":0.02553463},{"source":18,"target":119,"value":1.8},{"source":18,"target":34,"value":2.37},{"source":18,"target":127,"value":1.59},{"source":18,"target":27,"value":7.09},{"source":18,"target":47,"value":0.01},{"source":18,"target":23,"value":2},{"source":18,"target":18,"value":0.01},{"source":18,"target":106,"value":1},{"source":18,"target":73,"value":0.04},{"source":18,"target":75,"value":0.15},{"source":18,"target":9,"value":20},{"source":18,"target":63,"value":5},{"source":18,"target":18,"value":0.1},{"source":18,"target":43,"value":150},{"source":18,"target":18,"value":0.01},{"source":18,"target":30,"value":11.73},{"source":18,"target":18,"value":0.01},{"source":18,"target":81,"value":0.01},{"source":18,"target":38,"value":0.17},{"source":18,"target":7,"value":1},{"source":18,"target":1,"value":700},{"source":18,"target":18,"value":0.01},{"source":18,"target":26,"value":3},{"source":18,"target":18,"value":0.01573214},{"source":18,"target":33,"value":1},{"source":18,"target":93,"value":3},{"source":18,"target":136,"value":0.0155535},{"source":18,"target":74,"value":2},{"source":18,"target":18,"value":0.24},{"source":18,"target":113,"value":15},{"source":18,"target":133,"value":35},{"source":18,"target":38,"value":8.3},{"source":18,"target":18,"value":0.01},{"source":18,"target":42,"value":655},{"source":18,"target":48,"value":345},{"source":18,"target":23,"value":1},{"source":18,"target":29,"value":6.74},{"source":18,"target":18,"value":0.01},{"source":18,"target":32,"value":1},{"source":17,"target":109,"value":0.01069402},{"source":17,"target":41,"value":48.80429478},{"source":18,"target":25,"value":0.84},{"source":18,"target":18,"value":0.03},{"source":18,"target":38,"value":1},{"source":18,"target":12,"value":1},{"source":18,"target":18,"value":0.01070376},{"source":18,"target":83,"value":1},{"source":18,"target":102,"value":1},{"source":18,"target":50,"value":0.01},{"source":18,"target":31,"value":3.83},{"source":18,"target":6,"value":4.82},{"source":18,"target":18,"value":0.01039788},{"source":18,"target":18,"value":0.01},{"source":18,"target":11,"value":1.02},{"source":18,"target":18,"value":0.01},{"source":18,"target":49,"value":19.08},{"source":18,"target":129,"value":1},{"source":18,"target":18,"value":0.0119506},{"source":18,"target":96,"value":1.27},{"source":18,"target":78,"value":3.09},{"source":18,"target":146,"value":0.01033115},{"source":18,"target":67,"value":1},{"source":18,"target":36,"value":6.58},{"source":18,"target":70,"value":0.36},{"source":18,"target":18,"value":0.05},{"source":18,"target":130,"value":1},{"source":18,"target":57,"value":5.01},{"source":18,"target":18,"value":0.01},{"source":18,"target":144,"value":10},{"source":18,"target":15,"value":150},{"source":18,"target":66,"value":300},{"source":18,"target":18,"value":0.18},{"source":18,"target":21,"value":0.31},{"source":18,"target":46,"value":0.01},{"source":18,"target":71,"value":35},{"source":18,"target":90,"value":1.5},{"source":18,"target":18,"value":0.01},{"source":18,"target":94,"value":1},{"source":18,"target":18,"value":0.01396244},{"source":18,"target":120,"value":1},{"source":18,"target":35,"value":2},{"source":18,"target":123,"value":2.953},{"source":18,"target":145,"value":0.01},{"source":18,"target":0,"value":0.87},{"source":18,"target":74,"value":2},{"source":18,"target":18,"value":0.01},{"source":18,"target":34,"value":10},{"source":18,"target":18,"value":0.01},{"source":18,"target":110,"value":0.01},{"source":18,"target":53,"value":0.11},{"source":18,"target":118,"value":19.87},{"source":18,"target":40,"value":1},{"source":18,"target":18,"value":0.09},{"source":18,"target":18,"value":0.01568967},{"source":18,"target":98,"value":1},{"source":18,"target":76,"value":1.71},{"source":18,"target":18,"value":0.01},{"source":18,"target":28,"value":15},{"source":18,"target":68,"value":2},{"source":18,"target":19,"value":5},{"source":18,"target":18,"value":0.01},{"source":18,"target":141,"value":2},{"source":18,"target":100,"value":0.01060211},{"source":18,"target":121,"value":1},{"source":18,"target":107,"value":2},{"source":18,"target":124,"value":12.5},{"source":18,"target":135,"value":2.88},{"source":18,"target":150,"value":0.06},{"source":18,"target":65,"value":0.01},{"source":18,"target":103,"value":6},{"source":18,"target":99,"value":0.1},{"source":18,"target":105,"value":0.05},{"source":18,"target":18,"value":0.14},{"source":18,"target":122,"value":5.78},{"source":18,"target":18,"value":0.05},{"source":18,"target":126,"value":2},{"source":18,"target":36,"value":7.35},{"source":18,"target":18,"value":0.01},{"source":18,"target":108,"value":10},{"source":18,"target":58,"value":3},{"source":18,"target":18,"value":0.01},{"source":18,"target":14,"value":10},{"source":18,"target":89,"value":0.28},{"source":18,"target":18,"value":0.01},{"source":18,"target":132,"value":4.01},{"source":18,"target":18,"value":0.01},{"source":18,"target":24,"value":16.75},{"source":18,"target":18,"value":0.01},{"source":18,"target":131,"value":1},{"source":17,"target":109,"value":0.01069402},{"source":17,"target":41,"value":48.80429478},{"source":52,"target":79,"value":4.57},{"source":52,"target":39,"value":0.13},{"source":116,"target":148,"value":5},{"source":116,"target":139,"value":45.01},{"source":13,"target":128,"value":1.12},{"source":13,"target":38,"value":1.08830464},{"source":85,"target":64,"value":0.05},{"source":85,"target":77,"value":298.05},{"source":8,"target":86,"value":22.209},{"source":8,"target":56,"value":1},{"source":95,"target":59,"value":1.09},{"source":95,"target":112,"value":47.87},{"source":52,"target":62,"value":33.78},{"source":52,"target":143,"value":0.01}]}
nodemap = {}; graph.nodes.forEach(function(node, i) { nodemap[node.name] = i; });
for(i = 0; i< graph.links.length; i++) { o = graph.links[i]; graph.links[i].source = nodemap[o.source]; graph.links[i].target = nodemap[o.target]; }
<!DOCTYPE html>
<meta charset="utf-8">
<style>
.node {
stroke: #fff;
stroke-width: 1.5px;
}
.link {
fill: none;
stroke: #bbb;
}
</style>
<body>
<script src="http://d3js.org/d3.v3.js"></script>
<script>
var width = 620,
height = 400;
var color = d3.scale.category20();
var force = d3.layout.force()
.linkDistance(10)
.linkStrength(2)
.size([width, height]);
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
d3.json("data.json", function(error, graph) {
var nodes = graph.nodes.slice(),
links = [],
bilinks = [];
graph.links.forEach(function(link) {
var s = nodes[link.source],
t = nodes[link.target],
i = {}; // intermediate node
if ((typeof s != 'undefined') || (typeof s != 'undefined')) {
nodes.push(i);
links.push({source: s, target: i}, {source: i, target: t});
bilinks.push([s, i, t]);
} else {
console.log("bad link: ", link);
}
});
console.log(nodes);
console.log(links);
force
.nodes(nodes)
.links(links)
.start();
var link = svg.selectAll(".link")
.data(bilinks)
.enter().append("path")
.attr("class", "link");
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("d", function(d) {
return "M" + d[0].x + "," + d[0].y
+ "S" + d[1].x + "," + d[1].y
+ " " + d[2].x + "," + d[2].y;
});
node.attr("transform", function(d) {
return "translate(" + d.x + "," + d.y + ")";
});
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment