Created
June 4, 2012 03:58
-
-
Save davidfischer/2866246 to your computer and use it in GitHub Desktop.
How Social is Your Code?
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
When one says "social coding" I ask "how social"? One measure of social-ness is the number of distinct collaborators. | |
The data is from the github.timeline dataset. The visualization uses D3 and is adapted from the Sunburst example. | |
Click http://bl.ocks.org/2866246 to view it in all its glory. |
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> | |
<html> | |
<head> | |
<meta http-equiv="content-type" content="text/html;charset=utf-8"> | |
<script type="text/javascript" src="http://d3js.org/d3.v2.js"></script> | |
<style type="text/css"> | |
label { | |
display: block; | |
float: left; | |
width: 100px; | |
text-align: right; | |
font-weight: bold; | |
padding-right: 10px; | |
} | |
#tooltip p { | |
clear: both; | |
margin: 4px 0; | |
} | |
</style> | |
</head> | |
<body> | |
<div id="chart"></div> | |
<script type="text/javascript"> | |
var width = 960, | |
height = 500, | |
radius = Math.min(width, height) / 2, | |
color = d3.scale.category20c(); | |
var vis = d3.select("#chart").append("svg") | |
.attr("width", width) | |
.attr("height", height) | |
.append("g") | |
.attr("transform", "translate(" + width / 2 + "," + height / 2 + ")"); | |
var tooltip = d3.select("body").append("div") | |
.attr("id", "tooltip") | |
.style("display", "none") | |
.style("background-color", "rgba(242, 242, 242, .6)") | |
.style("border", "1px solid #666") | |
.style("padding", "5px") | |
.style("position", "absolute"); | |
var partition = d3.layout.partition() | |
.sort(null) | |
.size([2 * Math.PI, radius * radius]) | |
.value(function(d) { return d.collaborators; }); | |
var arc = d3.svg.arc() | |
.startAngle(function(d) { return d.x; }) | |
.endAngle(function(d) { return d.x + d.dx; }) | |
.innerRadius(function(d) { return 50; }) | |
.outerRadius(function(d) { return Math.sqrt(d.y + d.dy); }); | |
d3.csv("social.csv", function(data) { | |
var path = vis.data([format_data(data)]).selectAll("path") | |
.data(partition.nodes) | |
.enter().append("path") | |
.text(function(d) { return d.name ? d.name : ""; }) | |
.attr("display", function(d) { return d.name ? "none" : null; }) // hide inner rings | |
.attr("d", arc) | |
.attr("fill-rule", "evenodd") | |
.style("stroke", "#fff") | |
.style("fill", function(d) { return color(d.name ? d.name : d.repository_language); }) | |
.on("mouseover", function(d) { | |
if(!d.repository_name) { return; } | |
var m = d3.mouse(d3.select("body").node()); | |
tooltip.style("display", null) | |
.style("left", m[0] + 30 + "px") | |
.style("top", m[1] - 20 + "px") | |
.html(["<p><label>Project:</label>" + d.repository_name + "</p>", | |
"<p><label>Collaborators:</label>" + d.collaborators + "</p>", | |
"<p><label>Language:</label>" + d.repository_language + "</p>"].join("")); | |
}) | |
.on("mouseout", function(d) { | |
tooltip.style("display", "none"); | |
}); | |
}); | |
function format_data(data) { | |
// convert CSV to hierarchical format that d3 expects | |
var json = {"name": "Social Code", "children": []}; | |
for(var i = 0; i < data.length; i += 1) { | |
var index = -1; | |
for(var j = 0; j < json['children'].length; j += 1) { | |
if(json['children'][j]['name'] == data[i]['repository_language']) { | |
index = j; | |
break; | |
} | |
} | |
if(index == -1) { | |
json['children'].push({ | |
"name": data[i]['repository_language'], | |
"children": [] | |
}); | |
index = json['children'].length - 1; | |
} | |
json['children'][index]['children'].push(data[i]); | |
} | |
return json; | |
} | |
</script> | |
</body> | |
</html> |
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
SELECT repository_name, | |
repository_language, | |
COUNT(actor) AS collaborators | |
FROM ( | |
SELECT repository_name, | |
repository_language, | |
actor | |
FROM [githubarchive:github.timeline] | |
GROUP BY repository_name, | |
repository_language, | |
actor | |
) AS t | |
WHERE repository_language != '' | |
GROUP BY repository_name, | |
repository_language | |
HAVING collaborators > 250 | |
ORDER BY collaborators DESC |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment