build graph and save