Perhaps you have a dagre attempt, the JS library for DAG graphs.
If you want to use d3 for any reason, check out dagre-d3
For a higher-level approach, take a look at this project using all of the libraries above.
If d3 is optional, also see other graphics libraries .;)
Update
'dagre' was discontinued in 2015, and further development by the author of this project will not be continued. However, I still think this is the best DAG in JS that you can get at the time of writing.
Use 'dagre' with the newer version of d3, it is still possible if all shift changes starting from d3 v3 are fixed on their own.
source share