index.html 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <head>
  2. <style> body { margin: 0; } </style>
  3. <script src="//bundle.run/@yarnpkg/lockfile"></script>
  4. <script src="//unpkg.com/dat.gui"></script>
  5. <script src="//unpkg.com/d3-octree"></script>
  6. <script src="//unpkg.com/d3-force-3d"></script>
  7. <script src="//unpkg.com/three"></script>
  8. <script src="//unpkg.com/three-spritetext"></script>
  9. <script src="//unpkg.com/3d-force-graph"></script>
  10. <!--<script src="../../dist/3d-force-graph.js"></script>-->
  11. </head>
  12. <body>
  13. <div id="graph"></div>
  14. <script>
  15. // controls
  16. const controls = { 'DAG Orientation': 'lr'};
  17. const gui = new dat.GUI();
  18. gui.add(controls, 'DAG Orientation', ['lr', 'td', 'zout', 'radialout', null])
  19. .onChange(orientation => graph && graph.dagMode(orientation));
  20. // graph config
  21. const graph = ForceGraph3D()
  22. .backgroundColor('#101020')
  23. .linkColor(() => 'rgba(255, 255, 255, 0.2)')
  24. .dagMode('lr')
  25. .onDagError(() => false)
  26. .dagLevelDistance(180)
  27. .nodeId('package')
  28. .linkCurvature(0.07)
  29. .nodeThreeObject(node => {
  30. const sprite = new SpriteText(node.package);
  31. sprite.material.depthWrite = false;
  32. sprite.color = 'lightsteelblue';
  33. sprite.textHeight = 8;
  34. return sprite;
  35. })
  36. .d3Force('collide', d3.forceCollide(13))
  37. .d3AlphaDecay(0.02)
  38. .d3VelocityDecay(0.3);
  39. fetch('../../yarn.lock')
  40. .then(r => r.text())
  41. .then(text => {
  42. const yarnlock = _yarnpkg_lockfile.parse(text);
  43. if (yarnlock.type !== 'success') throw new Error('invalid yarn.lock');
  44. return yarnlock.object;
  45. })
  46. .then(yarnlock => {
  47. const nodes = [];
  48. const links = [];
  49. Object.entries(yarnlock).forEach(([package, details]) => {
  50. nodes.push({
  51. package,
  52. version: details.version
  53. });
  54. if (details.dependencies) {
  55. Object.entries(details.dependencies).forEach(([dep, version]) => {
  56. links.push({source: package, target: `${dep}@${version}`});
  57. });
  58. }
  59. });
  60. graph(document.getElementById('graph'))
  61. .graphData({ nodes, links });
  62. });
  63. </script>
  64. </body>