Refactor graph data handling

The graph.js class is overloaded. Move all the data handling stuff that only interacts with the graph data in its own data handling module.