optimization in graph/table code. moved common code to calculations.js