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