Fork of https://gist.github.com/mbostock/3885211