I feel like this bit would probably be a bit cleaner with d3 bindings, but, it's not a ton of code so it's probably not strictly necessary to invest the time to port it over.