Skip to content

Instantly share code, notes, and snippets.

@jeffweiss
Last active December 11, 2015 22:58
Show Gist options
  • Save jeffweiss/4672962 to your computer and use it in GitHub Desktop.
Save jeffweiss/4672962 to your computer and use it in GitHub Desktop.
Commit Calendar View Incantation
<!DOCTYPE html>
<meta charset="utf-8">
<link type="text/css" rel="stylesheet" href="colorbrewer.css"/>
<style>
body {
font: 10px sans-serif;
shape-rendering: crispEdges;
}
.day {
fill: #fff;
stroke: #ccc;
}
.month {
fill: none;
stroke: #000;
stroke-width: 2px;
}
</style>
<body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script>
var width = 960,
height = 136,
cellSize = 17; // cell size
var day = d3.time.format("%w"),
week = d3.time.format("%U"),
percent = d3.format("d"),
format = d3.time.format("%Y-%m-%d");
var quantile = d3.scale.quantile()
.domain([0, 1000]);
var color = quantile
.range(d3.range(4).map(function(d) { return "q" + (parseInt(d) + 5) + "-9"; }));
var svg = d3.select("body").selectAll("svg")
.data(d3.range(2011, 2014))
.enter().append("svg")
.attr("width", width)
.attr("height", height)
.attr("class", "Greens")
.append("g")
.attr("transform", "translate(" + ((width - cellSize * 53) / 2) + "," + (height - cellSize * 7 - 1) + ")");
svg.append("text")
.attr("transform", "translate(-6," + cellSize * 3.5 + ")rotate(-90)")
.style("text-anchor", "middle")
.text(function(d) { return d; });
var rect = svg.selectAll(".day")
.data(function(d) { return d3.time.days(new Date(d, 0, 1), new Date(d + 1, 0, 1)); })
.enter().append("rect")
.attr("class", "day")
.attr("width", cellSize)
.attr("height", cellSize)
.attr("x", function(d) { return week(d) * cellSize; })
.attr("y", function(d) { return day(d) * cellSize; })
.datum(format);
rect.append("title")
.text(function(d) { return d; });
svg.selectAll(".month")
.data(function(d) { return d3.time.months(new Date(d, 0, 1), new Date(d + 1, 0, 1)); })
.enter().append("path")
.attr("class", "month")
.attr("d", monthPath);
d3.csv("diffstats.csv", function(error, csv) {
var data = d3.nest()
.key(function(d) { return d.Date; })
.rollup(function(d) { return (parseInt(d[0].Inserts) + parseInt(d[0].Deletes)); })
.map(csv);
rect.filter(function(d) { return d in data; })
.attr("class", function(d) { return "day " + color(data[d]); })
.select("title")
.text(function(d) { return d + ": " + percent(data[d]); });
});
d3.select("body").append("text").text(quantile.quantiles());
function monthPath(t0) {
var t1 = new Date(t0.getFullYear(), t0.getMonth() + 1, 0),
d0 = +day(t0), w0 = +week(t0),
d1 = +day(t1), w1 = +week(t1);
return "M" + (w0 + 1) * cellSize + "," + d0 * cellSize
+ "H" + w0 * cellSize + "V" + 7 * cellSize
+ "H" + w1 * cellSize + "V" + (d1 + 1) * cellSize
+ "H" + (w1 + 1) * cellSize + "V" + 0
+ "H" + (w0 + 1) * cellSize + "Z";
}
d3.select(self.frameElement).style("height", "2910px");
</script>
#!/bin/bash
git fetch upstream
git log --pretty=format:"%cd" --date=short --date-order --no-merges --shortstat upstream/2.7.x..upstream/3.1.x lib > diffstats.data
file = File.read "diffstats.data"
dates = {}
mydate = nil
mydiff = nil
file.lines.each do |line|
line = line.strip
if line =~ /\d+-\d+-\d+/
mydate = line
elsif matcher = /(\d+) file/.match(line)
mydiff = { :files => 0, :inserts => 0, :deletes => 0 }
dates[mydate] = mydiff unless dates[mydate]
dates[mydate][:files] += matcher[1].to_i
matcher = /(\d+) insert/.match(line)
dates[mydate][:inserts] += matcher[1].to_i if matcher
matcher = /(\d+) delet/.match(line)
dates[mydate][:deletes] += matcher[1].to_i if matcher
else
mydate = nil
mydiff = nil
end
end
puts "Date,Files,Inserts,Deletes"
dates.sort.each do |mydate,hash|
puts "#{mydate},#{hash[:files]},#{hash[:inserts]},#{hash[:deletes]}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment