Graph building in JS and canvas