Example code from Scott Murray's D3 Book and my modifications to it