index.html 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <head>
  2. <style> body { margin: 0; } </style>
  3. <script src="//unpkg.com/3d-force-graph"></script>
  4. <!--<script src="../../dist/3d-force-graph.js"></script>-->
  5. </head>
  6. <body>
  7. <div id="3d-graph"></div>
  8. <script>
  9. // Random tree
  10. const N = 300;
  11. const gData = {
  12. nodes: [...Array(N).keys()].map(i => ({ id: i })),
  13. links: [...Array(N).keys()]
  14. .filter(id => id)
  15. .map(id => ({
  16. source: id,
  17. target: Math.round(Math.random() * (id-1))
  18. }))
  19. };
  20. const distance = 1400;
  21. const Graph = ForceGraph3D()
  22. (document.getElementById('3d-graph'))
  23. .enableNodeDrag(false)
  24. .enableNavigationControls(false)
  25. .showNavInfo(false)
  26. .cameraPosition({ z: distance })
  27. .graphData(gData);
  28. // camera orbit
  29. let angle = 0;
  30. setInterval(() => {
  31. Graph.cameraPosition({
  32. x: distance * Math.sin(angle),
  33. z: distance * Math.cos(angle)
  34. });
  35. angle += Math.PI / 300;
  36. }, 10);
  37. </script>
  38. </body>