This project was fun. The javascript library d3.js provides a very useful way of binding data to html/svg elements, and to manipulate and animate them,
See this link.
The javascript source is easily inspected from the page, it’s all in one file (though structure and comments are weak).