moved graph code to directive