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