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