This is the obvious step. My template then just grabs the viz.json and reads some basic information from it, including username and tablename.
Okay, this was a bit of guessql. So, it creates the grid and measures all the points in each cell. It then selects the most dense cells that account for the first 60% of records. It then uses those to create the bounding box for the map :)
SELECT the_geom