Skip to content

Instantly share code, notes, and snippets.

@arfon
Created January 31, 2014 03:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arfon/8726302 to your computer and use it in GitHub Desktop.
Save arfon/8726302 to your computer and use it in GitHub Desktop.
Spine
<!DOCTYPE html>
<meta charset="utf-8">
<style>
body {
font: 12px sans-serif;
}
.axis path,
.axis line {
fill: none;
stroke: #000;
shape-rendering: crispEdges;
}
.dot {
stroke: red;
fill: red;
}
h1{
padding-left:25px;
}
</style>
<body>
<script src="http://d3js.org/d3.v3.js"></script>
<script>
var margin = {top: 20, right: 20, bottom: 30, left: 50},
width = 960 - margin.left - margin.right,
height = 500 - margin.top - margin.bottom;
var parseDate = d3.time.format("%Y-%m-%d").parse;
var x = d3.time.scale()
.range([0, width]);
var y = d3.scale.linear()
.range([height, 0]);
var xAxis = d3.svg.axis()
.scale(x)
.orient("bottom");
var yAxis = d3.svg.axis()
.scale(y)
.orient("left");
var svg = d3.select("body").append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
d3.tsv("spine_collaborative_fraction.tsv", function(error, data) {
data.forEach(function(d) {
d.date = parseDate(d.date);
d.unix_date = +d.unix_date;
d.collab_count = +d.collab_count;
d.not_collab_count = +d.not_collab_count;
d.count = +d.count;
d.collab_fraction = +d.collab_fraction;
});
x.domain(d3.extent(data, function(d) { return d.date; }));
y.domain(d3.extent(data, function(d) { return d.collab_fraction; }));
svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(xAxis);
svg.append("g")
.attr("class", "y axis")
.call(yAxis)
.append("text")
.attr("transform", "rotate(-90)")
.attr("y", 6)
.attr("dy", ".71em")
.style("text-anchor", "end")
.text("Collaborative fraction");
svg.selectAll(".dot")
.data(data)
.enter().append("circle")
.attr("class", "dot")
.attr("r", 3.5)
.attr("cx", function(d) { return x(d.date); })
.attr("cy", function(d) { return y(d.collab_fraction); });
});
</script>
date unix_date collab_count not_collab_count count collab_fraction
2011-04-01 1301616000000 1 5 6 0.16666666666666666
2011-05-01 1304208000000 2 12 14 0.14285714285714285
2011-06-01 1306886400000 1 7 8 0.125
2011-07-01 1309478400000 3 9 12 0.25
2011-08-01 1312156800000 2 6 8 0.25
2011-09-01 1314835200000 2 4 6 0.3333333333333333
2011-10-01 1317427200000 1 5 6 0.16666666666666666
2011-11-01 1320105600000 3 7 10 0.3
2011-12-01 1322697600000 8 5 13 0.6153846153846154
2012-01-01 1325376000000 0 7 7 0.0
2012-02-01 1328054400000 1 3 4 0.25
2012-03-01 1330560000000 6 13 19 0.3157894736842105
2012-04-01 1333238400000 5 7 12 0.4166666666666667
2012-05-01 1335830400000 10 8 18 0.5555555555555556
2012-06-01 1338508800000 2 15 17 0.11764705882352941
2012-07-01 1341100800000 2 1 3 0.6666666666666666
2012-08-01 1343779200000 2 6 8 0.25
2012-09-01 1346457600000 4 3 7 0.5714285714285714
2012-11-01 1351728000000 0 3 3 0.0
2012-12-01 1354320000000 0 3 3 0.0
2013-01-01 1356998400000 1 3 4 0.25
2013-02-01 1359676800000 2 4 6 0.3333333333333333
2013-03-01 1362096000000 6 8 14 0.42857142857142855
2013-04-01 1364774400000 5 8 13 0.38461538461538464
2013-05-01 1367366400000 3 0 3 1.0
2013-06-01 1370044800000 5 3 8 0.625
2013-07-01 1372636800000 4 5 9 0.4444444444444444
2013-08-01 1375315200000 1 2 3 0.3333333333333333
2013-10-01 1380585600000 3 1 4 0.75
2013-12-01 1385856000000 0 3 3 0.0
2014-01-01 1388534400000 1 2 3 0.3333333333333333
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment