writing graph code