Refactor D3 integration into a service