graph subroutine