Last active
August 29, 2015 14:21
-
-
Save michaelcolenso/b71dddf6aa0f6df2e80a to your computer and use it in GitHub Desktop.
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
<!DOCTYPE html> | |
<meta charset="utf-8"> | |
<link href='http://fonts.googleapis.com/css?family=Permanent+Marker' rel='stylesheet' type='text/css'> | |
<style> | |
body { | |
text-align: center; | |
margin: 0 auto; | |
} | |
h1 { | |
font-family: 'Permanent Marker'; | |
} | |
.node { | |
font-size: 11px; | |
font-family: 'Permanent Marker'; | |
} | |
.link { | |
fill: none; | |
stroke: rgba(0,0,0,0.2); | |
stroke-width: .5px; | |
} | |
</style> | |
<h1>Top 50 Hashtags on Periscope between May 7, 2015 and May 11, 2015</br><small>(with top users for each)</small></h1> | |
<div id="dendrogram"></div> | |
<script src="http://d3js.org/d3.v3.min.js"></script> | |
<script> | |
var root; | |
var radius = 960 / 2; | |
var cluster = d3.layout.cluster() | |
.size([360, radius - 20 ]); | |
var diagonal = d3.svg.diagonal.radial() | |
.projection(function(d) { return [d.y, d.x / 180 * Math.PI]; }); | |
var svg = d3.select("#dendrogram").append("svg") | |
.attr("width", radius * 2) | |
.attr("height", radius * 2) | |
.append("g") | |
.attr("transform", "translate(" + radius + "," + radius + ")"); | |
d3.json("https://gist.githubusercontent.com/michaelcolenso/f2a6b45a43e9fff8e06b/raw/24ec248db890565d45e0b5b28784f77346aad95d/-", function(error, json) { | |
root = createChildNodes(json); | |
var nodes = cluster.nodes(root); | |
var link = svg.selectAll("path.link") | |
.data(cluster.links(nodes)) | |
.enter().append("path") | |
.attr("class", "link") | |
// .attr("stroke-width", function(d) { return d.source.doc_count/d.target.doc_count/1000}) | |
.attr("d", diagonal); | |
var node = svg.selectAll("g.node") | |
.data(nodes) | |
.enter().append("g") | |
.attr("class", "node") | |
.attr("transform", function(d) { return "rotate(" + (d.x - 90) + ")translate(" + d.y + ")"; }) | |
node.append("text") | |
.attr("dy", ".25em") | |
.attr("text-anchor", function(d) { return d.x < 180 ? "end" : "start"; }) | |
.attr("transform", function(d) { return d.x < 180 ? "translate(-5)" : "rotate(180)translate(5)"; }) | |
.style("font-size", function(d) { return d.children ? "2em" : ".8em"; }) | |
.style("font-family", function(d) { return d.children ? "inherit" : "Helvetica"; }) | |
.style("fill", function(d) { return d.children ? "#000" : "#999"; }) | |
.style("display", function(d) { return d.depth < 2 ? "none" : "initial"; }) | |
.text(function(d) { return d.key; }); | |
}); | |
d3.select(self.frameElement).style("height", radius + "px"); | |
function createChildNodes(dataObj) { | |
var root = {}; | |
root.key = "Periscope"; | |
root.children = dataObj.aggregations.app.buckets; | |
root.children.forEach(function (d) { d.children = d.hashtags.buckets; }); | |
root.children.forEach(function (d) { | |
d.children.forEach(function (d) { | |
d.children = d.user.buckets; | |
}); | |
}); | |
return root; | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment