adjusted function so that it works with the d3 graph