moved d3 code into method