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